Correct ChangeLog dates for git commit 3f0a5f17d7f
[deliverable/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
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
4d354d8b
TP
126/* Current set of feature bits available (CPU+FPU). Different from
127 selected_cpu + selected_fpu in case of autodetection since the CPU
128 feature bits are then all set. */
e74cfd16 129static arm_feature_set cpu_variant;
4d354d8b
TP
130/* Feature bits used in each execution state. Used to set build attribute
131 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
e74cfd16
PB
132static arm_feature_set arm_arch_used;
133static arm_feature_set thumb_arch_used;
b99bd4ef 134
b99bd4ef 135/* Flags stored in private area of BFD structure. */
c19d1205
ZW
136static int uses_apcs_26 = FALSE;
137static int atpcs = FALSE;
b34976b6
AM
138static int support_interwork = FALSE;
139static int uses_apcs_float = FALSE;
c19d1205 140static int pic_code = FALSE;
845b51d6 141static int fix_v4bx = FALSE;
278df34e
NS
142/* Warn on using deprecated features. */
143static int warn_on_deprecated = TRUE;
144
2e6976a8
DG
145/* Understand CodeComposer Studio assembly syntax. */
146bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
147
148/* Variables that we set while parsing command-line options. Once all
149 options have been read we re-process these values to set the real
150 assembly flags. */
4d354d8b
TP
151
152/* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
153 instead of -mcpu=arm1). */
154static const arm_feature_set *legacy_cpu = NULL;
155static const arm_feature_set *legacy_fpu = NULL;
156
157/* CPU, extension and FPU feature bits selected by -mcpu. */
158static const arm_feature_set *mcpu_cpu_opt = NULL;
159static arm_feature_set *mcpu_ext_opt = NULL;
160static const arm_feature_set *mcpu_fpu_opt = NULL;
161
162/* CPU, extension and FPU feature bits selected by -march. */
163static const arm_feature_set *march_cpu_opt = NULL;
164static arm_feature_set *march_ext_opt = NULL;
165static const arm_feature_set *march_fpu_opt = NULL;
166
167/* Feature bits selected by -mfpu. */
168static const arm_feature_set *mfpu_opt = NULL;
e74cfd16
PB
169
170/* Constants for known architecture features. */
171static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 172static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 173static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
174static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
175static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
176static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
177static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 178#ifdef OBJ_ELF
e74cfd16 179static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 180#endif
e74cfd16
PB
181static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
182
183#ifdef CPU_DEFAULT
184static const arm_feature_set cpu_default = CPU_DEFAULT;
185#endif
186
823d2571 187static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 188static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
189static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
190static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
191static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
192static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
193static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
194static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 195static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
196 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
197static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
198static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
199static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
200static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
201static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
202static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
203static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
823d2571
TG
204static const arm_feature_set arm_ext_v6_notm =
205 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
206static const arm_feature_set arm_ext_v6_dsp =
207 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
208static const arm_feature_set arm_ext_barrier =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
210static const arm_feature_set arm_ext_msr =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
212static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
213static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
214static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
215static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 216#ifdef OBJ_ELF
e7d39ed3 217static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 218#endif
823d2571 219static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 220static const arm_feature_set arm_ext_m =
173205ca 221 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 222 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
223static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
224static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
225static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
226static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
227static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 228static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 229static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
230static const arm_feature_set arm_ext_v8m_main =
231 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
232/* Instructions in ARMv8-M only found in M profile architectures. */
233static const arm_feature_set arm_ext_v8m_m_only =
234 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
235static const arm_feature_set arm_ext_v6t2_v8m =
236 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
237/* Instructions shared between ARMv8-A and ARMv8-M. */
238static const arm_feature_set arm_ext_atomics =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 240#ifdef OBJ_ELF
15afaa63
TP
241/* DSP instructions Tag_DSP_extension refers to. */
242static const arm_feature_set arm_ext_dsp =
243 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 244#endif
4d1464f2
MW
245static const arm_feature_set arm_ext_ras =
246 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
247/* FP16 instructions. */
248static const arm_feature_set arm_ext_fp16 =
249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
01f48020
TC
250static const arm_feature_set arm_ext_fp16_fml =
251 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
dec41383
JW
252static const arm_feature_set arm_ext_v8_2 =
253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
254static const arm_feature_set arm_ext_v8_3 =
255 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
256
257static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 258#ifdef OBJ_ELF
2c6b98ea 259static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 260#endif
f85d59c3 261static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
262static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
263static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
264
2d447fca 265static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 266 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 267static const arm_feature_set arm_cext_iwmmxt =
823d2571 268 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 269static const arm_feature_set arm_cext_xscale =
823d2571 270 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 271static const arm_feature_set arm_cext_maverick =
823d2571
TG
272 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
273static const arm_feature_set fpu_fpa_ext_v1 =
274 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
275static const arm_feature_set fpu_fpa_ext_v2 =
276 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 277static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
278 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
279static const arm_feature_set fpu_vfp_ext_v1 =
280 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
281static const arm_feature_set fpu_vfp_ext_v2 =
282 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
283static const arm_feature_set fpu_vfp_ext_v3xd =
284 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
285static const arm_feature_set fpu_vfp_ext_v3 =
286 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 287static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
288 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
289static const arm_feature_set fpu_neon_ext_v1 =
290 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 291static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 292 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 293#ifdef OBJ_ELF
823d2571
TG
294static const arm_feature_set fpu_vfp_fp16 =
295 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
296static const arm_feature_set fpu_neon_ext_fma =
297 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 298#endif
823d2571
TG
299static const arm_feature_set fpu_vfp_ext_fma =
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 301static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 302 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 303static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 304 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 305static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 306 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 307static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 308 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 309static const arm_feature_set crc_ext_armv8 =
823d2571 310 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 311static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 312 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
313static const arm_feature_set fpu_neon_ext_dotprod =
314 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 315
33a392fb 316static int mfloat_abi_opt = -1;
4d354d8b
TP
317/* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
318 directive. */
319static arm_feature_set selected_arch = ARM_ARCH_NONE;
320/* Extension feature bits selected by the last -mcpu/-march or .arch_extension
321 directive. */
322static arm_feature_set selected_ext = ARM_ARCH_NONE;
323/* Feature bits selected by the last -mcpu/-march or by the combination of the
324 last .cpu/.arch directive .arch_extension directives since that
325 directive. */
e74cfd16 326static arm_feature_set selected_cpu = ARM_ARCH_NONE;
4d354d8b
TP
327/* FPU feature bits selected by the last -mfpu or .fpu directive. */
328static arm_feature_set selected_fpu = FPU_NONE;
329/* Feature bits selected by the last .object_arch directive. */
330static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
ee065d83 331/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 332static char selected_cpu_name[20];
8d67f500 333
aacf0b33
KT
334extern FLONUM_TYPE generic_floating_point_number;
335
8d67f500
NC
336/* Return if no cpu was selected on command-line. */
337static bfd_boolean
338no_cpu_selected (void)
339{
823d2571 340 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
341}
342
7cc69913 343#ifdef OBJ_ELF
deeaaff8
DJ
344# ifdef EABI_DEFAULT
345static int meabi_flags = EABI_DEFAULT;
346# else
d507cf36 347static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 348# endif
e1da3f5b 349
ee3c0378
AS
350static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
351
e1da3f5b 352bfd_boolean
5f4273c7 353arm_is_eabi (void)
e1da3f5b
PB
354{
355 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
356}
7cc69913 357#endif
b99bd4ef 358
b99bd4ef 359#ifdef OBJ_ELF
c19d1205 360/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
361symbolS * GOT_symbol;
362#endif
363
b99bd4ef
NC
364/* 0: assemble for ARM,
365 1: assemble for Thumb,
366 2: assemble for Thumb even though target CPU does not support thumb
367 instructions. */
368static int thumb_mode = 0;
8dc2430f
NC
369/* A value distinct from the possible values for thumb_mode that we
370 can use to record whether thumb_mode has been copied into the
371 tc_frag_data field of a frag. */
372#define MODE_RECORDED (1 << 4)
b99bd4ef 373
e07e6e58
NC
374/* Specifies the intrinsic IT insn behavior mode. */
375enum implicit_it_mode
376{
377 IMPLICIT_IT_MODE_NEVER = 0x00,
378 IMPLICIT_IT_MODE_ARM = 0x01,
379 IMPLICIT_IT_MODE_THUMB = 0x02,
380 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
381};
382static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
383
c19d1205
ZW
384/* If unified_syntax is true, we are processing the new unified
385 ARM/Thumb syntax. Important differences from the old ARM mode:
386
387 - Immediate operands do not require a # prefix.
388 - Conditional affixes always appear at the end of the
389 instruction. (For backward compatibility, those instructions
390 that formerly had them in the middle, continue to accept them
391 there.)
392 - The IT instruction may appear, and if it does is validated
393 against subsequent conditional affixes. It does not generate
394 machine code.
395
396 Important differences from the old Thumb mode:
397
398 - Immediate operands do not require a # prefix.
399 - Most of the V6T2 instructions are only available in unified mode.
400 - The .N and .W suffixes are recognized and honored (it is an error
401 if they cannot be honored).
402 - All instructions set the flags if and only if they have an 's' affix.
403 - Conditional affixes may be used. They are validated against
404 preceding IT instructions. Unlike ARM mode, you cannot use a
405 conditional affix except in the scope of an IT instruction. */
406
407static bfd_boolean unified_syntax = FALSE;
b99bd4ef 408
bacebabc
RM
409/* An immediate operand can start with #, and ld*, st*, pld operands
410 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
411 before a [, which can appear as the first operand for pld.
412 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
413const char arm_symbol_chars[] = "#[]{}";
bacebabc 414
5287ad62
JB
415enum neon_el_type
416{
dcbf9037 417 NT_invtype,
5287ad62
JB
418 NT_untyped,
419 NT_integer,
420 NT_float,
421 NT_poly,
422 NT_signed,
dcbf9037 423 NT_unsigned
5287ad62
JB
424};
425
426struct neon_type_el
427{
428 enum neon_el_type type;
429 unsigned size;
430};
431
432#define NEON_MAX_TYPE_ELS 4
433
434struct neon_type
435{
436 struct neon_type_el el[NEON_MAX_TYPE_ELS];
437 unsigned elems;
438};
439
e07e6e58
NC
440enum it_instruction_type
441{
442 OUTSIDE_IT_INSN,
443 INSIDE_IT_INSN,
444 INSIDE_IT_LAST_INSN,
445 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 446 if inside, should be the last one. */
e07e6e58 447 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 448 i.e. BKPT and NOP. */
e07e6e58
NC
449 IT_INSN /* The IT insn has been parsed. */
450};
451
ad6cec43
MGD
452/* The maximum number of operands we need. */
453#define ARM_IT_MAX_OPERANDS 6
454
b99bd4ef
NC
455struct arm_it
456{
c19d1205 457 const char * error;
b99bd4ef 458 unsigned long instruction;
c19d1205
ZW
459 int size;
460 int size_req;
461 int cond;
037e8744
JB
462 /* "uncond_value" is set to the value in place of the conditional field in
463 unconditional versions of the instruction, or -1 if nothing is
464 appropriate. */
465 int uncond_value;
5287ad62 466 struct neon_type vectype;
88714cb8
DG
467 /* This does not indicate an actual NEON instruction, only that
468 the mnemonic accepts neon-style type suffixes. */
469 int is_neon;
0110f2b8
PB
470 /* Set to the opcode if the instruction needs relaxation.
471 Zero if the instruction is not relaxed. */
472 unsigned long relax;
b99bd4ef
NC
473 struct
474 {
475 bfd_reloc_code_real_type type;
c19d1205
ZW
476 expressionS exp;
477 int pc_rel;
b99bd4ef 478 } reloc;
b99bd4ef 479
e07e6e58
NC
480 enum it_instruction_type it_insn_type;
481
c19d1205
ZW
482 struct
483 {
484 unsigned reg;
ca3f61f7 485 signed int imm;
dcbf9037 486 struct neon_type_el vectype;
ca3f61f7
NC
487 unsigned present : 1; /* Operand present. */
488 unsigned isreg : 1; /* Operand was a register. */
489 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
490 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
491 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 492 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
493 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
494 instructions. This allows us to disambiguate ARM <-> vector insns. */
495 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 496 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 497 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 498 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
499 unsigned hasreloc : 1; /* Operand has relocation suffix. */
500 unsigned writeback : 1; /* Operand has trailing ! */
501 unsigned preind : 1; /* Preindexed address. */
502 unsigned postind : 1; /* Postindexed address. */
503 unsigned negative : 1; /* Index register was negated. */
504 unsigned shifted : 1; /* Shift applied to operation. */
505 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 506 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
507};
508
c19d1205 509static struct arm_it inst;
b99bd4ef
NC
510
511#define NUM_FLOAT_VALS 8
512
05d2d07e 513const char * fp_const[] =
b99bd4ef
NC
514{
515 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
516};
517
c19d1205 518/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
519#define MAX_LITTLENUMS 6
520
521LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
522
523#define FAIL (-1)
524#define SUCCESS (0)
525
526#define SUFF_S 1
527#define SUFF_D 2
528#define SUFF_E 3
529#define SUFF_P 4
530
c19d1205
ZW
531#define CP_T_X 0x00008000
532#define CP_T_Y 0x00400000
b99bd4ef 533
c19d1205
ZW
534#define CONDS_BIT 0x00100000
535#define LOAD_BIT 0x00100000
b99bd4ef
NC
536
537#define DOUBLE_LOAD_FLAG 0x00000001
538
539struct asm_cond
540{
d3ce72d0 541 const char * template_name;
c921be7d 542 unsigned long value;
b99bd4ef
NC
543};
544
c19d1205 545#define COND_ALWAYS 0xE
b99bd4ef 546
b99bd4ef
NC
547struct asm_psr
548{
d3ce72d0 549 const char * template_name;
c921be7d 550 unsigned long field;
b99bd4ef
NC
551};
552
62b3e311
PB
553struct asm_barrier_opt
554{
e797f7e0
MGD
555 const char * template_name;
556 unsigned long value;
557 const arm_feature_set arch;
62b3e311
PB
558};
559
2d2255b5 560/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
561#define SPSR_BIT (1 << 22)
562
c19d1205
ZW
563/* The individual PSR flag bits. */
564#define PSR_c (1 << 16)
565#define PSR_x (1 << 17)
566#define PSR_s (1 << 18)
567#define PSR_f (1 << 19)
b99bd4ef 568
c19d1205 569struct reloc_entry
bfae80f2 570{
0198d5e6 571 const char * name;
c921be7d 572 bfd_reloc_code_real_type reloc;
bfae80f2
RE
573};
574
5287ad62 575enum vfp_reg_pos
bfae80f2 576{
5287ad62
JB
577 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
578 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
579};
580
581enum vfp_ldstm_type
582{
583 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
584};
585
dcbf9037
JB
586/* Bits for DEFINED field in neon_typed_alias. */
587#define NTA_HASTYPE 1
588#define NTA_HASINDEX 2
589
590struct neon_typed_alias
591{
c921be7d
NC
592 unsigned char defined;
593 unsigned char index;
594 struct neon_type_el eltype;
dcbf9037
JB
595};
596
c19d1205 597/* ARM register categories. This includes coprocessor numbers and various
5aa75429
TP
598 architecture extensions' registers. Each entry should have an error message
599 in reg_expected_msgs below. */
c19d1205 600enum arm_reg_type
bfae80f2 601{
c19d1205
ZW
602 REG_TYPE_RN,
603 REG_TYPE_CP,
604 REG_TYPE_CN,
605 REG_TYPE_FN,
606 REG_TYPE_VFS,
607 REG_TYPE_VFD,
5287ad62 608 REG_TYPE_NQ,
037e8744 609 REG_TYPE_VFSD,
5287ad62 610 REG_TYPE_NDQ,
dec41383 611 REG_TYPE_NSD,
037e8744 612 REG_TYPE_NSDQ,
c19d1205
ZW
613 REG_TYPE_VFC,
614 REG_TYPE_MVF,
615 REG_TYPE_MVD,
616 REG_TYPE_MVFX,
617 REG_TYPE_MVDX,
618 REG_TYPE_MVAX,
619 REG_TYPE_DSPSC,
620 REG_TYPE_MMXWR,
621 REG_TYPE_MMXWC,
622 REG_TYPE_MMXWCG,
623 REG_TYPE_XSCALE,
90ec0d68 624 REG_TYPE_RNB
bfae80f2
RE
625};
626
dcbf9037
JB
627/* Structure for a hash table entry for a register.
628 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
629 information which states whether a vector type or index is specified (for a
630 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
631struct reg_entry
632{
c921be7d 633 const char * name;
90ec0d68 634 unsigned int number;
c921be7d
NC
635 unsigned char type;
636 unsigned char builtin;
637 struct neon_typed_alias * neon;
6c43fab6
RE
638};
639
c19d1205 640/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 641const char * const reg_expected_msgs[] =
c19d1205 642{
5aa75429
TP
643 [REG_TYPE_RN] = N_("ARM register expected"),
644 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
645 [REG_TYPE_CN] = N_("co-processor register expected"),
646 [REG_TYPE_FN] = N_("FPA register expected"),
647 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
648 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
649 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
650 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
651 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
652 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
653 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
654 " expected"),
655 [REG_TYPE_VFC] = N_("VFP system register expected"),
656 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
657 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
658 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
659 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
660 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
661 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
662 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
663 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
664 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
665 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
666 [REG_TYPE_RNB] = N_("")
6c43fab6
RE
667};
668
c19d1205 669/* Some well known registers that we refer to directly elsewhere. */
bd340a04 670#define REG_R12 12
c19d1205
ZW
671#define REG_SP 13
672#define REG_LR 14
673#define REG_PC 15
404ff6b5 674
b99bd4ef
NC
675/* ARM instructions take 4bytes in the object file, Thumb instructions
676 take 2: */
c19d1205 677#define INSN_SIZE 4
b99bd4ef
NC
678
679struct asm_opcode
680{
681 /* Basic string to match. */
d3ce72d0 682 const char * template_name;
c19d1205
ZW
683
684 /* Parameters to instruction. */
5be8be5d 685 unsigned int operands[8];
c19d1205
ZW
686
687 /* Conditional tag - see opcode_lookup. */
688 unsigned int tag : 4;
b99bd4ef
NC
689
690 /* Basic instruction code. */
c19d1205 691 unsigned int avalue : 28;
b99bd4ef 692
c19d1205
ZW
693 /* Thumb-format instruction code. */
694 unsigned int tvalue;
b99bd4ef 695
90e4755a 696 /* Which architecture variant provides this instruction. */
c921be7d
NC
697 const arm_feature_set * avariant;
698 const arm_feature_set * tvariant;
c19d1205
ZW
699
700 /* Function to call to encode instruction in ARM format. */
701 void (* aencode) (void);
b99bd4ef 702
c19d1205
ZW
703 /* Function to call to encode instruction in Thumb format. */
704 void (* tencode) (void);
b99bd4ef
NC
705};
706
a737bd4d
NC
707/* Defines for various bits that we will want to toggle. */
708#define INST_IMMEDIATE 0x02000000
709#define OFFSET_REG 0x02000000
c19d1205 710#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
711#define SHIFT_BY_REG 0x00000010
712#define PRE_INDEX 0x01000000
713#define INDEX_UP 0x00800000
714#define WRITE_BACK 0x00200000
715#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 716#define CPSI_MMOD 0x00020000
90e4755a 717
a737bd4d
NC
718#define LITERAL_MASK 0xf000f000
719#define OPCODE_MASK 0xfe1fffff
720#define V4_STR_BIT 0x00000020
8335d6aa 721#define VLDR_VMOV_SAME 0x0040f000
90e4755a 722
efd81785
PB
723#define T2_SUBS_PC_LR 0xf3de8f00
724
a737bd4d 725#define DATA_OP_SHIFT 21
bada4342 726#define SBIT_SHIFT 20
90e4755a 727
ef8d22e6
PB
728#define T2_OPCODE_MASK 0xfe1fffff
729#define T2_DATA_OP_SHIFT 21
bada4342 730#define T2_SBIT_SHIFT 20
ef8d22e6 731
6530b175
NC
732#define A_COND_MASK 0xf0000000
733#define A_PUSH_POP_OP_MASK 0x0fff0000
734
735/* Opcodes for pushing/poping registers to/from the stack. */
736#define A1_OPCODE_PUSH 0x092d0000
737#define A2_OPCODE_PUSH 0x052d0004
738#define A2_OPCODE_POP 0x049d0004
739
a737bd4d
NC
740/* Codes to distinguish the arithmetic instructions. */
741#define OPCODE_AND 0
742#define OPCODE_EOR 1
743#define OPCODE_SUB 2
744#define OPCODE_RSB 3
745#define OPCODE_ADD 4
746#define OPCODE_ADC 5
747#define OPCODE_SBC 6
748#define OPCODE_RSC 7
749#define OPCODE_TST 8
750#define OPCODE_TEQ 9
751#define OPCODE_CMP 10
752#define OPCODE_CMN 11
753#define OPCODE_ORR 12
754#define OPCODE_MOV 13
755#define OPCODE_BIC 14
756#define OPCODE_MVN 15
90e4755a 757
ef8d22e6
PB
758#define T2_OPCODE_AND 0
759#define T2_OPCODE_BIC 1
760#define T2_OPCODE_ORR 2
761#define T2_OPCODE_ORN 3
762#define T2_OPCODE_EOR 4
763#define T2_OPCODE_ADD 8
764#define T2_OPCODE_ADC 10
765#define T2_OPCODE_SBC 11
766#define T2_OPCODE_SUB 13
767#define T2_OPCODE_RSB 14
768
a737bd4d
NC
769#define T_OPCODE_MUL 0x4340
770#define T_OPCODE_TST 0x4200
771#define T_OPCODE_CMN 0x42c0
772#define T_OPCODE_NEG 0x4240
773#define T_OPCODE_MVN 0x43c0
90e4755a 774
a737bd4d
NC
775#define T_OPCODE_ADD_R3 0x1800
776#define T_OPCODE_SUB_R3 0x1a00
777#define T_OPCODE_ADD_HI 0x4400
778#define T_OPCODE_ADD_ST 0xb000
779#define T_OPCODE_SUB_ST 0xb080
780#define T_OPCODE_ADD_SP 0xa800
781#define T_OPCODE_ADD_PC 0xa000
782#define T_OPCODE_ADD_I8 0x3000
783#define T_OPCODE_SUB_I8 0x3800
784#define T_OPCODE_ADD_I3 0x1c00
785#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 786
a737bd4d
NC
787#define T_OPCODE_ASR_R 0x4100
788#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
789#define T_OPCODE_LSR_R 0x40c0
790#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
791#define T_OPCODE_ASR_I 0x1000
792#define T_OPCODE_LSL_I 0x0000
793#define T_OPCODE_LSR_I 0x0800
b99bd4ef 794
a737bd4d
NC
795#define T_OPCODE_MOV_I8 0x2000
796#define T_OPCODE_CMP_I8 0x2800
797#define T_OPCODE_CMP_LR 0x4280
798#define T_OPCODE_MOV_HR 0x4600
799#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 800
a737bd4d
NC
801#define T_OPCODE_LDR_PC 0x4800
802#define T_OPCODE_LDR_SP 0x9800
803#define T_OPCODE_STR_SP 0x9000
804#define T_OPCODE_LDR_IW 0x6800
805#define T_OPCODE_STR_IW 0x6000
806#define T_OPCODE_LDR_IH 0x8800
807#define T_OPCODE_STR_IH 0x8000
808#define T_OPCODE_LDR_IB 0x7800
809#define T_OPCODE_STR_IB 0x7000
810#define T_OPCODE_LDR_RW 0x5800
811#define T_OPCODE_STR_RW 0x5000
812#define T_OPCODE_LDR_RH 0x5a00
813#define T_OPCODE_STR_RH 0x5200
814#define T_OPCODE_LDR_RB 0x5c00
815#define T_OPCODE_STR_RB 0x5400
c9b604bd 816
a737bd4d
NC
817#define T_OPCODE_PUSH 0xb400
818#define T_OPCODE_POP 0xbc00
b99bd4ef 819
2fc8bdac 820#define T_OPCODE_BRANCH 0xe000
b99bd4ef 821
a737bd4d 822#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 823#define THUMB_PP_PC_LR 0x0100
c19d1205 824#define THUMB_LOAD_BIT 0x0800
53365c0d 825#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
826
827#define BAD_ARGS _("bad arguments to instruction")
fdfde340 828#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
829#define BAD_PC _("r15 not allowed here")
830#define BAD_COND _("instruction cannot be conditional")
831#define BAD_OVERLAP _("registers may not be the same")
832#define BAD_HIREG _("lo register required")
833#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 834#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
835#define BAD_BRANCH _("branch must be last instruction in IT block")
836#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 837#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
838#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
839#define BAD_IT_COND _("incorrect condition in IT block")
840#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 841#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
842#define BAD_PC_ADDRESSING \
843 _("cannot use register index with PC-relative addressing")
844#define BAD_PC_WRITEBACK \
845 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
846#define BAD_RANGE _("branch out of range")
847#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 848#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 849#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 850
c921be7d
NC
851static struct hash_control * arm_ops_hsh;
852static struct hash_control * arm_cond_hsh;
853static struct hash_control * arm_shift_hsh;
854static struct hash_control * arm_psr_hsh;
855static struct hash_control * arm_v7m_psr_hsh;
856static struct hash_control * arm_reg_hsh;
857static struct hash_control * arm_reloc_hsh;
858static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 859
b99bd4ef
NC
860/* Stuff needed to resolve the label ambiguity
861 As:
862 ...
863 label: <insn>
864 may differ from:
865 ...
866 label:
5f4273c7 867 <insn> */
b99bd4ef
NC
868
869symbolS * last_label_seen;
b34976b6 870static int label_is_thumb_function_name = FALSE;
e07e6e58 871
3d0c9500
NC
872/* Literal pool structure. Held on a per-section
873 and per-sub-section basis. */
a737bd4d 874
c19d1205 875#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 876typedef struct literal_pool
b99bd4ef 877{
c921be7d
NC
878 expressionS literals [MAX_LITERAL_POOL_SIZE];
879 unsigned int next_free_entry;
880 unsigned int id;
881 symbolS * symbol;
882 segT section;
883 subsegT sub_section;
a8040cf2
NC
884#ifdef OBJ_ELF
885 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
886#endif
c921be7d 887 struct literal_pool * next;
8335d6aa 888 unsigned int alignment;
3d0c9500 889} literal_pool;
b99bd4ef 890
3d0c9500
NC
891/* Pointer to a linked list of literal pools. */
892literal_pool * list_of_pools = NULL;
e27ec89e 893
2e6976a8
DG
894typedef enum asmfunc_states
895{
896 OUTSIDE_ASMFUNC,
897 WAITING_ASMFUNC_NAME,
898 WAITING_ENDASMFUNC
899} asmfunc_states;
900
901static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
902
e07e6e58
NC
903#ifdef OBJ_ELF
904# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
905#else
906static struct current_it now_it;
907#endif
908
909static inline int
910now_it_compatible (int cond)
911{
912 return (cond & ~1) == (now_it.cc & ~1);
913}
914
915static inline int
916conditional_insn (void)
917{
918 return inst.cond != COND_ALWAYS;
919}
920
921static int in_it_block (void);
922
923static int handle_it_state (void);
924
925static void force_automatic_it_block_close (void);
926
c921be7d
NC
927static void it_fsm_post_encode (void);
928
e07e6e58
NC
929#define set_it_insn_type(type) \
930 do \
931 { \
932 inst.it_insn_type = type; \
933 if (handle_it_state () == FAIL) \
477330fc 934 return; \
e07e6e58
NC
935 } \
936 while (0)
937
c921be7d
NC
938#define set_it_insn_type_nonvoid(type, failret) \
939 do \
940 { \
941 inst.it_insn_type = type; \
942 if (handle_it_state () == FAIL) \
477330fc 943 return failret; \
c921be7d
NC
944 } \
945 while(0)
946
e07e6e58
NC
947#define set_it_insn_type_last() \
948 do \
949 { \
950 if (inst.cond == COND_ALWAYS) \
477330fc 951 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 952 else \
477330fc 953 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
954 } \
955 while (0)
956
c19d1205 957/* Pure syntax. */
b99bd4ef 958
c19d1205
ZW
959/* This array holds the chars that always start a comment. If the
960 pre-processor is disabled, these aren't very useful. */
2e6976a8 961char arm_comment_chars[] = "@";
3d0c9500 962
c19d1205
ZW
963/* This array holds the chars that only start a comment at the beginning of
964 a line. If the line seems to have the form '# 123 filename'
965 .line and .file directives will appear in the pre-processed output. */
966/* Note that input_file.c hand checks for '#' at the beginning of the
967 first line of the input file. This is because the compiler outputs
968 #NO_APP at the beginning of its output. */
969/* Also note that comments like this one will always work. */
970const char line_comment_chars[] = "#";
3d0c9500 971
2e6976a8 972char arm_line_separator_chars[] = ";";
b99bd4ef 973
c19d1205
ZW
974/* Chars that can be used to separate mant
975 from exp in floating point numbers. */
976const char EXP_CHARS[] = "eE";
3d0c9500 977
c19d1205
ZW
978/* Chars that mean this number is a floating point constant. */
979/* As in 0f12.456 */
980/* or 0d1.2345e12 */
b99bd4ef 981
c19d1205 982const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 983
c19d1205
ZW
984/* Prefix characters that indicate the start of an immediate
985 value. */
986#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 987
c19d1205
ZW
988/* Separator character handling. */
989
990#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
991
992static inline int
993skip_past_char (char ** str, char c)
994{
8ab8155f
NC
995 /* PR gas/14987: Allow for whitespace before the expected character. */
996 skip_whitespace (*str);
427d0db6 997
c19d1205
ZW
998 if (**str == c)
999 {
1000 (*str)++;
1001 return SUCCESS;
3d0c9500 1002 }
c19d1205
ZW
1003 else
1004 return FAIL;
1005}
c921be7d 1006
c19d1205 1007#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 1008
c19d1205
ZW
1009/* Arithmetic expressions (possibly involving symbols). */
1010
1011/* Return TRUE if anything in the expression is a bignum. */
1012
0198d5e6 1013static bfd_boolean
c19d1205
ZW
1014walk_no_bignums (symbolS * sp)
1015{
1016 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 1017 return TRUE;
c19d1205
ZW
1018
1019 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 1020 {
c19d1205
ZW
1021 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1022 || (symbol_get_value_expression (sp)->X_op_symbol
1023 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
1024 }
1025
0198d5e6 1026 return FALSE;
3d0c9500
NC
1027}
1028
0198d5e6 1029static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1030
1031/* Third argument to my_get_expression. */
1032#define GE_NO_PREFIX 0
1033#define GE_IMM_PREFIX 1
1034#define GE_OPT_PREFIX 2
5287ad62
JB
1035/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1036 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1037#define GE_OPT_PREFIX_BIG 3
a737bd4d 1038
b99bd4ef 1039static int
c19d1205 1040my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1041{
c19d1205
ZW
1042 char * save_in;
1043 segT seg;
b99bd4ef 1044
c19d1205
ZW
1045 /* In unified syntax, all prefixes are optional. */
1046 if (unified_syntax)
5287ad62 1047 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1048 : GE_OPT_PREFIX;
b99bd4ef 1049
c19d1205 1050 switch (prefix_mode)
b99bd4ef 1051 {
c19d1205
ZW
1052 case GE_NO_PREFIX: break;
1053 case GE_IMM_PREFIX:
1054 if (!is_immediate_prefix (**str))
1055 {
1056 inst.error = _("immediate expression requires a # prefix");
1057 return FAIL;
1058 }
1059 (*str)++;
1060 break;
1061 case GE_OPT_PREFIX:
5287ad62 1062 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1063 if (is_immediate_prefix (**str))
1064 (*str)++;
1065 break;
0198d5e6
TC
1066 default:
1067 abort ();
c19d1205 1068 }
b99bd4ef 1069
c19d1205 1070 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1071
c19d1205
ZW
1072 save_in = input_line_pointer;
1073 input_line_pointer = *str;
0198d5e6 1074 in_my_get_expression = TRUE;
c19d1205 1075 seg = expression (ep);
0198d5e6 1076 in_my_get_expression = FALSE;
c19d1205 1077
f86adc07 1078 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1079 {
f86adc07 1080 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1081 *str = input_line_pointer;
1082 input_line_pointer = save_in;
1083 if (inst.error == NULL)
f86adc07
NS
1084 inst.error = (ep->X_op == O_absent
1085 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1086 return 1;
1087 }
b99bd4ef 1088
c19d1205
ZW
1089#ifdef OBJ_AOUT
1090 if (seg != absolute_section
1091 && seg != text_section
1092 && seg != data_section
1093 && seg != bss_section
1094 && seg != undefined_section)
1095 {
1096 inst.error = _("bad segment");
1097 *str = input_line_pointer;
1098 input_line_pointer = save_in;
1099 return 1;
b99bd4ef 1100 }
87975d2a
AM
1101#else
1102 (void) seg;
c19d1205 1103#endif
b99bd4ef 1104
c19d1205
ZW
1105 /* Get rid of any bignums now, so that we don't generate an error for which
1106 we can't establish a line number later on. Big numbers are never valid
1107 in instructions, which is where this routine is always called. */
5287ad62
JB
1108 if (prefix_mode != GE_OPT_PREFIX_BIG
1109 && (ep->X_op == O_big
477330fc 1110 || (ep->X_add_symbol
5287ad62 1111 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1112 || (ep->X_op_symbol
5287ad62 1113 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1114 {
1115 inst.error = _("invalid constant");
1116 *str = input_line_pointer;
1117 input_line_pointer = save_in;
1118 return 1;
1119 }
b99bd4ef 1120
c19d1205
ZW
1121 *str = input_line_pointer;
1122 input_line_pointer = save_in;
0198d5e6 1123 return SUCCESS;
b99bd4ef
NC
1124}
1125
c19d1205
ZW
1126/* Turn a string in input_line_pointer into a floating point constant
1127 of type TYPE, and store the appropriate bytes in *LITP. The number
1128 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1129 returned, or NULL on OK.
b99bd4ef 1130
c19d1205
ZW
1131 Note that fp constants aren't represent in the normal way on the ARM.
1132 In big endian mode, things are as expected. However, in little endian
1133 mode fp constants are big-endian word-wise, and little-endian byte-wise
1134 within the words. For example, (double) 1.1 in big endian mode is
1135 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1136 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1137
c19d1205 1138 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1139
6d4af3c2 1140const char *
c19d1205
ZW
1141md_atof (int type, char * litP, int * sizeP)
1142{
1143 int prec;
1144 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1145 char *t;
1146 int i;
b99bd4ef 1147
c19d1205
ZW
1148 switch (type)
1149 {
1150 case 'f':
1151 case 'F':
1152 case 's':
1153 case 'S':
1154 prec = 2;
1155 break;
b99bd4ef 1156
c19d1205
ZW
1157 case 'd':
1158 case 'D':
1159 case 'r':
1160 case 'R':
1161 prec = 4;
1162 break;
b99bd4ef 1163
c19d1205
ZW
1164 case 'x':
1165 case 'X':
499ac353 1166 prec = 5;
c19d1205 1167 break;
b99bd4ef 1168
c19d1205
ZW
1169 case 'p':
1170 case 'P':
499ac353 1171 prec = 5;
c19d1205 1172 break;
a737bd4d 1173
c19d1205
ZW
1174 default:
1175 *sizeP = 0;
499ac353 1176 return _("Unrecognized or unsupported floating point constant");
c19d1205 1177 }
b99bd4ef 1178
c19d1205
ZW
1179 t = atof_ieee (input_line_pointer, type, words);
1180 if (t)
1181 input_line_pointer = t;
499ac353 1182 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1183
c19d1205
ZW
1184 if (target_big_endian)
1185 {
1186 for (i = 0; i < prec; i++)
1187 {
499ac353
NC
1188 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1189 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1190 }
1191 }
1192 else
1193 {
e74cfd16 1194 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1195 for (i = prec - 1; i >= 0; i--)
1196 {
499ac353
NC
1197 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1198 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1199 }
1200 else
1201 /* For a 4 byte float the order of elements in `words' is 1 0.
1202 For an 8 byte float the order is 1 0 3 2. */
1203 for (i = 0; i < prec; i += 2)
1204 {
499ac353
NC
1205 md_number_to_chars (litP, (valueT) words[i + 1],
1206 sizeof (LITTLENUM_TYPE));
1207 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1208 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1209 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1210 }
1211 }
b99bd4ef 1212
499ac353 1213 return NULL;
c19d1205 1214}
b99bd4ef 1215
c19d1205
ZW
1216/* We handle all bad expressions here, so that we can report the faulty
1217 instruction in the error message. */
0198d5e6 1218
c19d1205 1219void
91d6fa6a 1220md_operand (expressionS * exp)
c19d1205
ZW
1221{
1222 if (in_my_get_expression)
91d6fa6a 1223 exp->X_op = O_illegal;
b99bd4ef
NC
1224}
1225
c19d1205 1226/* Immediate values. */
b99bd4ef 1227
0198d5e6 1228#ifdef OBJ_ELF
c19d1205
ZW
1229/* Generic immediate-value read function for use in directives.
1230 Accepts anything that 'expression' can fold to a constant.
1231 *val receives the number. */
0198d5e6 1232
c19d1205
ZW
1233static int
1234immediate_for_directive (int *val)
b99bd4ef 1235{
c19d1205
ZW
1236 expressionS exp;
1237 exp.X_op = O_illegal;
b99bd4ef 1238
c19d1205
ZW
1239 if (is_immediate_prefix (*input_line_pointer))
1240 {
1241 input_line_pointer++;
1242 expression (&exp);
1243 }
b99bd4ef 1244
c19d1205
ZW
1245 if (exp.X_op != O_constant)
1246 {
1247 as_bad (_("expected #constant"));
1248 ignore_rest_of_line ();
1249 return FAIL;
1250 }
1251 *val = exp.X_add_number;
1252 return SUCCESS;
b99bd4ef 1253}
c19d1205 1254#endif
b99bd4ef 1255
c19d1205 1256/* Register parsing. */
b99bd4ef 1257
c19d1205
ZW
1258/* Generic register parser. CCP points to what should be the
1259 beginning of a register name. If it is indeed a valid register
1260 name, advance CCP over it and return the reg_entry structure;
1261 otherwise return NULL. Does not issue diagnostics. */
1262
1263static struct reg_entry *
1264arm_reg_parse_multi (char **ccp)
b99bd4ef 1265{
c19d1205
ZW
1266 char *start = *ccp;
1267 char *p;
1268 struct reg_entry *reg;
b99bd4ef 1269
477330fc
RM
1270 skip_whitespace (start);
1271
c19d1205
ZW
1272#ifdef REGISTER_PREFIX
1273 if (*start != REGISTER_PREFIX)
01cfc07f 1274 return NULL;
c19d1205
ZW
1275 start++;
1276#endif
1277#ifdef OPTIONAL_REGISTER_PREFIX
1278 if (*start == OPTIONAL_REGISTER_PREFIX)
1279 start++;
1280#endif
b99bd4ef 1281
c19d1205
ZW
1282 p = start;
1283 if (!ISALPHA (*p) || !is_name_beginner (*p))
1284 return NULL;
b99bd4ef 1285
c19d1205
ZW
1286 do
1287 p++;
1288 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1289
1290 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1291
1292 if (!reg)
1293 return NULL;
1294
1295 *ccp = p;
1296 return reg;
b99bd4ef
NC
1297}
1298
1299static int
dcbf9037 1300arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1301 enum arm_reg_type type)
b99bd4ef 1302{
c19d1205
ZW
1303 /* Alternative syntaxes are accepted for a few register classes. */
1304 switch (type)
1305 {
1306 case REG_TYPE_MVF:
1307 case REG_TYPE_MVD:
1308 case REG_TYPE_MVFX:
1309 case REG_TYPE_MVDX:
1310 /* Generic coprocessor register names are allowed for these. */
79134647 1311 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1312 return reg->number;
1313 break;
69b97547 1314
c19d1205
ZW
1315 case REG_TYPE_CP:
1316 /* For backward compatibility, a bare number is valid here. */
1317 {
1318 unsigned long processor = strtoul (start, ccp, 10);
1319 if (*ccp != start && processor <= 15)
1320 return processor;
1321 }
1a0670f3 1322 /* Fall through. */
6057a28f 1323
c19d1205
ZW
1324 case REG_TYPE_MMXWC:
1325 /* WC includes WCG. ??? I'm not sure this is true for all
1326 instructions that take WC registers. */
79134647 1327 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1328 return reg->number;
6057a28f 1329 break;
c19d1205 1330
6057a28f 1331 default:
c19d1205 1332 break;
6057a28f
NC
1333 }
1334
dcbf9037
JB
1335 return FAIL;
1336}
1337
1338/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1339 return value is the register number or FAIL. */
1340
1341static int
1342arm_reg_parse (char **ccp, enum arm_reg_type type)
1343{
1344 char *start = *ccp;
1345 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1346 int ret;
1347
1348 /* Do not allow a scalar (reg+index) to parse as a register. */
1349 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1350 return FAIL;
1351
1352 if (reg && reg->type == type)
1353 return reg->number;
1354
1355 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1356 return ret;
1357
c19d1205
ZW
1358 *ccp = start;
1359 return FAIL;
1360}
69b97547 1361
dcbf9037
JB
1362/* Parse a Neon type specifier. *STR should point at the leading '.'
1363 character. Does no verification at this stage that the type fits the opcode
1364 properly. E.g.,
1365
1366 .i32.i32.s16
1367 .s32.f32
1368 .u16
1369
1370 Can all be legally parsed by this function.
1371
1372 Fills in neon_type struct pointer with parsed information, and updates STR
1373 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1374 type, FAIL if not. */
1375
1376static int
1377parse_neon_type (struct neon_type *type, char **str)
1378{
1379 char *ptr = *str;
1380
1381 if (type)
1382 type->elems = 0;
1383
1384 while (type->elems < NEON_MAX_TYPE_ELS)
1385 {
1386 enum neon_el_type thistype = NT_untyped;
1387 unsigned thissize = -1u;
1388
1389 if (*ptr != '.')
1390 break;
1391
1392 ptr++;
1393
1394 /* Just a size without an explicit type. */
1395 if (ISDIGIT (*ptr))
1396 goto parsesize;
1397
1398 switch (TOLOWER (*ptr))
1399 {
1400 case 'i': thistype = NT_integer; break;
1401 case 'f': thistype = NT_float; break;
1402 case 'p': thistype = NT_poly; break;
1403 case 's': thistype = NT_signed; break;
1404 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1405 case 'd':
1406 thistype = NT_float;
1407 thissize = 64;
1408 ptr++;
1409 goto done;
dcbf9037
JB
1410 default:
1411 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1412 return FAIL;
1413 }
1414
1415 ptr++;
1416
1417 /* .f is an abbreviation for .f32. */
1418 if (thistype == NT_float && !ISDIGIT (*ptr))
1419 thissize = 32;
1420 else
1421 {
1422 parsesize:
1423 thissize = strtoul (ptr, &ptr, 10);
1424
1425 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1426 && thissize != 64)
1427 {
1428 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1429 return FAIL;
1430 }
1431 }
1432
037e8744 1433 done:
dcbf9037 1434 if (type)
477330fc
RM
1435 {
1436 type->el[type->elems].type = thistype;
dcbf9037
JB
1437 type->el[type->elems].size = thissize;
1438 type->elems++;
1439 }
1440 }
1441
1442 /* Empty/missing type is not a successful parse. */
1443 if (type->elems == 0)
1444 return FAIL;
1445
1446 *str = ptr;
1447
1448 return SUCCESS;
1449}
1450
1451/* Errors may be set multiple times during parsing or bit encoding
1452 (particularly in the Neon bits), but usually the earliest error which is set
1453 will be the most meaningful. Avoid overwriting it with later (cascading)
1454 errors by calling this function. */
1455
1456static void
1457first_error (const char *err)
1458{
1459 if (!inst.error)
1460 inst.error = err;
1461}
1462
1463/* Parse a single type, e.g. ".s32", leading period included. */
1464static int
1465parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1466{
1467 char *str = *ccp;
1468 struct neon_type optype;
1469
1470 if (*str == '.')
1471 {
1472 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1473 {
1474 if (optype.elems == 1)
1475 *vectype = optype.el[0];
1476 else
1477 {
1478 first_error (_("only one type should be specified for operand"));
1479 return FAIL;
1480 }
1481 }
dcbf9037 1482 else
477330fc
RM
1483 {
1484 first_error (_("vector type expected"));
1485 return FAIL;
1486 }
dcbf9037
JB
1487 }
1488 else
1489 return FAIL;
5f4273c7 1490
dcbf9037 1491 *ccp = str;
5f4273c7 1492
dcbf9037
JB
1493 return SUCCESS;
1494}
1495
1496/* Special meanings for indices (which have a range of 0-7), which will fit into
1497 a 4-bit integer. */
1498
1499#define NEON_ALL_LANES 15
1500#define NEON_INTERLEAVE_LANES 14
1501
1502/* Parse either a register or a scalar, with an optional type. Return the
1503 register number, and optionally fill in the actual type of the register
1504 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1505 type/index information in *TYPEINFO. */
1506
1507static int
1508parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1509 enum arm_reg_type *rtype,
1510 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1511{
1512 char *str = *ccp;
1513 struct reg_entry *reg = arm_reg_parse_multi (&str);
1514 struct neon_typed_alias atype;
1515 struct neon_type_el parsetype;
1516
1517 atype.defined = 0;
1518 atype.index = -1;
1519 atype.eltype.type = NT_invtype;
1520 atype.eltype.size = -1;
1521
1522 /* Try alternate syntax for some types of register. Note these are mutually
1523 exclusive with the Neon syntax extensions. */
1524 if (reg == NULL)
1525 {
1526 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1527 if (altreg != FAIL)
477330fc 1528 *ccp = str;
dcbf9037 1529 if (typeinfo)
477330fc 1530 *typeinfo = atype;
dcbf9037
JB
1531 return altreg;
1532 }
1533
037e8744
JB
1534 /* Undo polymorphism when a set of register types may be accepted. */
1535 if ((type == REG_TYPE_NDQ
1536 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1537 || (type == REG_TYPE_VFSD
477330fc 1538 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1539 || (type == REG_TYPE_NSDQ
477330fc
RM
1540 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1541 || reg->type == REG_TYPE_NQ))
dec41383
JW
1542 || (type == REG_TYPE_NSD
1543 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1544 || (type == REG_TYPE_MMXWC
1545 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1546 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1547
1548 if (type != reg->type)
1549 return FAIL;
1550
1551 if (reg->neon)
1552 atype = *reg->neon;
5f4273c7 1553
dcbf9037
JB
1554 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1555 {
1556 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1557 {
1558 first_error (_("can't redefine type for operand"));
1559 return FAIL;
1560 }
dcbf9037
JB
1561 atype.defined |= NTA_HASTYPE;
1562 atype.eltype = parsetype;
1563 }
5f4273c7 1564
dcbf9037
JB
1565 if (skip_past_char (&str, '[') == SUCCESS)
1566 {
dec41383
JW
1567 if (type != REG_TYPE_VFD
1568 && !(type == REG_TYPE_VFS
1569 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1570 {
1571 first_error (_("only D registers may be indexed"));
1572 return FAIL;
1573 }
5f4273c7 1574
dcbf9037 1575 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1576 {
1577 first_error (_("can't change index for operand"));
1578 return FAIL;
1579 }
dcbf9037
JB
1580
1581 atype.defined |= NTA_HASINDEX;
1582
1583 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1584 atype.index = NEON_ALL_LANES;
dcbf9037 1585 else
477330fc
RM
1586 {
1587 expressionS exp;
dcbf9037 1588
477330fc 1589 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1590
477330fc
RM
1591 if (exp.X_op != O_constant)
1592 {
1593 first_error (_("constant expression required"));
1594 return FAIL;
1595 }
dcbf9037 1596
477330fc
RM
1597 if (skip_past_char (&str, ']') == FAIL)
1598 return FAIL;
dcbf9037 1599
477330fc
RM
1600 atype.index = exp.X_add_number;
1601 }
dcbf9037 1602 }
5f4273c7 1603
dcbf9037
JB
1604 if (typeinfo)
1605 *typeinfo = atype;
5f4273c7 1606
dcbf9037
JB
1607 if (rtype)
1608 *rtype = type;
5f4273c7 1609
dcbf9037 1610 *ccp = str;
5f4273c7 1611
dcbf9037
JB
1612 return reg->number;
1613}
1614
1615/* Like arm_reg_parse, but allow allow the following extra features:
1616 - If RTYPE is non-zero, return the (possibly restricted) type of the
1617 register (e.g. Neon double or quad reg when either has been requested).
1618 - If this is a Neon vector type with additional type information, fill
1619 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1620 This function will fault on encountering a scalar. */
dcbf9037
JB
1621
1622static int
1623arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1624 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1625{
1626 struct neon_typed_alias atype;
1627 char *str = *ccp;
1628 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1629
1630 if (reg == FAIL)
1631 return FAIL;
1632
0855e32b
NS
1633 /* Do not allow regname(... to parse as a register. */
1634 if (*str == '(')
1635 return FAIL;
1636
dcbf9037
JB
1637 /* Do not allow a scalar (reg+index) to parse as a register. */
1638 if ((atype.defined & NTA_HASINDEX) != 0)
1639 {
1640 first_error (_("register operand expected, but got scalar"));
1641 return FAIL;
1642 }
1643
1644 if (vectype)
1645 *vectype = atype.eltype;
1646
1647 *ccp = str;
1648
1649 return reg;
1650}
1651
1652#define NEON_SCALAR_REG(X) ((X) >> 4)
1653#define NEON_SCALAR_INDEX(X) ((X) & 15)
1654
5287ad62
JB
1655/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1656 have enough information to be able to do a good job bounds-checking. So, we
1657 just do easy checks here, and do further checks later. */
1658
1659static int
dcbf9037 1660parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1661{
dcbf9037 1662 int reg;
5287ad62 1663 char *str = *ccp;
dcbf9037 1664 struct neon_typed_alias atype;
dec41383
JW
1665 enum arm_reg_type reg_type = REG_TYPE_VFD;
1666
1667 if (elsize == 4)
1668 reg_type = REG_TYPE_VFS;
5f4273c7 1669
dec41383 1670 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1671
dcbf9037 1672 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1673 return FAIL;
5f4273c7 1674
dcbf9037 1675 if (atype.index == NEON_ALL_LANES)
5287ad62 1676 {
dcbf9037 1677 first_error (_("scalar must have an index"));
5287ad62
JB
1678 return FAIL;
1679 }
dcbf9037 1680 else if (atype.index >= 64 / elsize)
5287ad62 1681 {
dcbf9037 1682 first_error (_("scalar index out of range"));
5287ad62
JB
1683 return FAIL;
1684 }
5f4273c7 1685
dcbf9037
JB
1686 if (type)
1687 *type = atype.eltype;
5f4273c7 1688
5287ad62 1689 *ccp = str;
5f4273c7 1690
dcbf9037 1691 return reg * 16 + atype.index;
5287ad62
JB
1692}
1693
c19d1205 1694/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1695
c19d1205
ZW
1696static long
1697parse_reg_list (char ** strp)
1698{
1699 char * str = * strp;
1700 long range = 0;
1701 int another_range;
a737bd4d 1702
c19d1205
ZW
1703 /* We come back here if we get ranges concatenated by '+' or '|'. */
1704 do
6057a28f 1705 {
477330fc
RM
1706 skip_whitespace (str);
1707
c19d1205 1708 another_range = 0;
a737bd4d 1709
c19d1205
ZW
1710 if (*str == '{')
1711 {
1712 int in_range = 0;
1713 int cur_reg = -1;
a737bd4d 1714
c19d1205
ZW
1715 str++;
1716 do
1717 {
1718 int reg;
6057a28f 1719
dcbf9037 1720 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1721 {
dcbf9037 1722 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1723 return FAIL;
1724 }
a737bd4d 1725
c19d1205
ZW
1726 if (in_range)
1727 {
1728 int i;
a737bd4d 1729
c19d1205
ZW
1730 if (reg <= cur_reg)
1731 {
dcbf9037 1732 first_error (_("bad range in register list"));
c19d1205
ZW
1733 return FAIL;
1734 }
40a18ebd 1735
c19d1205
ZW
1736 for (i = cur_reg + 1; i < reg; i++)
1737 {
1738 if (range & (1 << i))
1739 as_tsktsk
1740 (_("Warning: duplicated register (r%d) in register list"),
1741 i);
1742 else
1743 range |= 1 << i;
1744 }
1745 in_range = 0;
1746 }
a737bd4d 1747
c19d1205
ZW
1748 if (range & (1 << reg))
1749 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1750 reg);
1751 else if (reg <= cur_reg)
1752 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1753
c19d1205
ZW
1754 range |= 1 << reg;
1755 cur_reg = reg;
1756 }
1757 while (skip_past_comma (&str) != FAIL
1758 || (in_range = 1, *str++ == '-'));
1759 str--;
a737bd4d 1760
d996d970 1761 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1762 {
dcbf9037 1763 first_error (_("missing `}'"));
c19d1205
ZW
1764 return FAIL;
1765 }
1766 }
1767 else
1768 {
91d6fa6a 1769 expressionS exp;
40a18ebd 1770
91d6fa6a 1771 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1772 return FAIL;
40a18ebd 1773
91d6fa6a 1774 if (exp.X_op == O_constant)
c19d1205 1775 {
91d6fa6a
NC
1776 if (exp.X_add_number
1777 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1778 {
1779 inst.error = _("invalid register mask");
1780 return FAIL;
1781 }
a737bd4d 1782
91d6fa6a 1783 if ((range & exp.X_add_number) != 0)
c19d1205 1784 {
91d6fa6a 1785 int regno = range & exp.X_add_number;
a737bd4d 1786
c19d1205
ZW
1787 regno &= -regno;
1788 regno = (1 << regno) - 1;
1789 as_tsktsk
1790 (_("Warning: duplicated register (r%d) in register list"),
1791 regno);
1792 }
a737bd4d 1793
91d6fa6a 1794 range |= exp.X_add_number;
c19d1205
ZW
1795 }
1796 else
1797 {
1798 if (inst.reloc.type != 0)
1799 {
1800 inst.error = _("expression too complex");
1801 return FAIL;
1802 }
a737bd4d 1803
91d6fa6a 1804 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1805 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1806 inst.reloc.pc_rel = 0;
1807 }
1808 }
a737bd4d 1809
c19d1205
ZW
1810 if (*str == '|' || *str == '+')
1811 {
1812 str++;
1813 another_range = 1;
1814 }
a737bd4d 1815 }
c19d1205 1816 while (another_range);
a737bd4d 1817
c19d1205
ZW
1818 *strp = str;
1819 return range;
a737bd4d
NC
1820}
1821
5287ad62
JB
1822/* Types of registers in a list. */
1823
1824enum reg_list_els
1825{
1826 REGLIST_VFP_S,
1827 REGLIST_VFP_D,
1828 REGLIST_NEON_D
1829};
1830
c19d1205
ZW
1831/* Parse a VFP register list. If the string is invalid return FAIL.
1832 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1833 register. Parses registers of type ETYPE.
1834 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1835 - Q registers can be used to specify pairs of D registers
1836 - { } can be omitted from around a singleton register list
477330fc
RM
1837 FIXME: This is not implemented, as it would require backtracking in
1838 some cases, e.g.:
1839 vtbl.8 d3,d4,d5
1840 This could be done (the meaning isn't really ambiguous), but doesn't
1841 fit in well with the current parsing framework.
dcbf9037
JB
1842 - 32 D registers may be used (also true for VFPv3).
1843 FIXME: Types are ignored in these register lists, which is probably a
1844 bug. */
6057a28f 1845
c19d1205 1846static int
037e8744 1847parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1848{
037e8744 1849 char *str = *ccp;
c19d1205
ZW
1850 int base_reg;
1851 int new_base;
21d799b5 1852 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1853 int max_regs = 0;
c19d1205
ZW
1854 int count = 0;
1855 int warned = 0;
1856 unsigned long mask = 0;
a737bd4d 1857 int i;
6057a28f 1858
477330fc 1859 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1860 {
1861 inst.error = _("expecting {");
1862 return FAIL;
1863 }
6057a28f 1864
5287ad62 1865 switch (etype)
c19d1205 1866 {
5287ad62 1867 case REGLIST_VFP_S:
c19d1205
ZW
1868 regtype = REG_TYPE_VFS;
1869 max_regs = 32;
5287ad62 1870 break;
5f4273c7 1871
5287ad62
JB
1872 case REGLIST_VFP_D:
1873 regtype = REG_TYPE_VFD;
b7fc2769 1874 break;
5f4273c7 1875
b7fc2769
JB
1876 case REGLIST_NEON_D:
1877 regtype = REG_TYPE_NDQ;
1878 break;
1879 }
1880
1881 if (etype != REGLIST_VFP_S)
1882 {
b1cc4aeb
PB
1883 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1884 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1885 {
1886 max_regs = 32;
1887 if (thumb_mode)
1888 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1889 fpu_vfp_ext_d32);
1890 else
1891 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1892 fpu_vfp_ext_d32);
1893 }
5287ad62 1894 else
477330fc 1895 max_regs = 16;
c19d1205 1896 }
6057a28f 1897
c19d1205 1898 base_reg = max_regs;
a737bd4d 1899
c19d1205
ZW
1900 do
1901 {
5287ad62 1902 int setmask = 1, addregs = 1;
dcbf9037 1903
037e8744 1904 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1905
c19d1205 1906 if (new_base == FAIL)
a737bd4d 1907 {
dcbf9037 1908 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1909 return FAIL;
1910 }
5f4273c7 1911
b7fc2769 1912 if (new_base >= max_regs)
477330fc
RM
1913 {
1914 first_error (_("register out of range in list"));
1915 return FAIL;
1916 }
5f4273c7 1917
5287ad62
JB
1918 /* Note: a value of 2 * n is returned for the register Q<n>. */
1919 if (regtype == REG_TYPE_NQ)
477330fc
RM
1920 {
1921 setmask = 3;
1922 addregs = 2;
1923 }
5287ad62 1924
c19d1205
ZW
1925 if (new_base < base_reg)
1926 base_reg = new_base;
a737bd4d 1927
5287ad62 1928 if (mask & (setmask << new_base))
c19d1205 1929 {
dcbf9037 1930 first_error (_("invalid register list"));
c19d1205 1931 return FAIL;
a737bd4d 1932 }
a737bd4d 1933
c19d1205
ZW
1934 if ((mask >> new_base) != 0 && ! warned)
1935 {
1936 as_tsktsk (_("register list not in ascending order"));
1937 warned = 1;
1938 }
0bbf2aa4 1939
5287ad62
JB
1940 mask |= setmask << new_base;
1941 count += addregs;
0bbf2aa4 1942
037e8744 1943 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1944 {
1945 int high_range;
0bbf2aa4 1946
037e8744 1947 str++;
0bbf2aa4 1948
037e8744 1949 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1950 == FAIL)
c19d1205
ZW
1951 {
1952 inst.error = gettext (reg_expected_msgs[regtype]);
1953 return FAIL;
1954 }
0bbf2aa4 1955
477330fc
RM
1956 if (high_range >= max_regs)
1957 {
1958 first_error (_("register out of range in list"));
1959 return FAIL;
1960 }
b7fc2769 1961
477330fc
RM
1962 if (regtype == REG_TYPE_NQ)
1963 high_range = high_range + 1;
5287ad62 1964
c19d1205
ZW
1965 if (high_range <= new_base)
1966 {
1967 inst.error = _("register range not in ascending order");
1968 return FAIL;
1969 }
0bbf2aa4 1970
5287ad62 1971 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1972 {
5287ad62 1973 if (mask & (setmask << new_base))
0bbf2aa4 1974 {
c19d1205
ZW
1975 inst.error = _("invalid register list");
1976 return FAIL;
0bbf2aa4 1977 }
c19d1205 1978
5287ad62
JB
1979 mask |= setmask << new_base;
1980 count += addregs;
0bbf2aa4 1981 }
0bbf2aa4 1982 }
0bbf2aa4 1983 }
037e8744 1984 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1985
037e8744 1986 str++;
0bbf2aa4 1987
c19d1205
ZW
1988 /* Sanity check -- should have raised a parse error above. */
1989 if (count == 0 || count > max_regs)
1990 abort ();
1991
1992 *pbase = base_reg;
1993
1994 /* Final test -- the registers must be consecutive. */
1995 mask >>= base_reg;
1996 for (i = 0; i < count; i++)
1997 {
1998 if ((mask & (1u << i)) == 0)
1999 {
2000 inst.error = _("non-contiguous register range");
2001 return FAIL;
2002 }
2003 }
2004
037e8744
JB
2005 *ccp = str;
2006
c19d1205 2007 return count;
b99bd4ef
NC
2008}
2009
dcbf9037
JB
2010/* True if two alias types are the same. */
2011
c921be7d 2012static bfd_boolean
dcbf9037
JB
2013neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2014{
2015 if (!a && !b)
c921be7d 2016 return TRUE;
5f4273c7 2017
dcbf9037 2018 if (!a || !b)
c921be7d 2019 return FALSE;
dcbf9037
JB
2020
2021 if (a->defined != b->defined)
c921be7d 2022 return FALSE;
5f4273c7 2023
dcbf9037
JB
2024 if ((a->defined & NTA_HASTYPE) != 0
2025 && (a->eltype.type != b->eltype.type
477330fc 2026 || a->eltype.size != b->eltype.size))
c921be7d 2027 return FALSE;
dcbf9037
JB
2028
2029 if ((a->defined & NTA_HASINDEX) != 0
2030 && (a->index != b->index))
c921be7d 2031 return FALSE;
5f4273c7 2032
c921be7d 2033 return TRUE;
dcbf9037
JB
2034}
2035
5287ad62
JB
2036/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2037 The base register is put in *PBASE.
dcbf9037 2038 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2039 the return value.
2040 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2041 Bits [6:5] encode the list length (minus one).
2042 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2043
5287ad62 2044#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2045#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2046#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2047
2048static int
dcbf9037 2049parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2050 struct neon_type_el *eltype)
5287ad62
JB
2051{
2052 char *ptr = *str;
2053 int base_reg = -1;
2054 int reg_incr = -1;
2055 int count = 0;
2056 int lane = -1;
2057 int leading_brace = 0;
2058 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2059 const char *const incr_error = _("register stride must be 1 or 2");
2060 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2061 struct neon_typed_alias firsttype;
f85d59c3
KT
2062 firsttype.defined = 0;
2063 firsttype.eltype.type = NT_invtype;
2064 firsttype.eltype.size = -1;
2065 firsttype.index = -1;
5f4273c7 2066
5287ad62
JB
2067 if (skip_past_char (&ptr, '{') == SUCCESS)
2068 leading_brace = 1;
5f4273c7 2069
5287ad62
JB
2070 do
2071 {
dcbf9037
JB
2072 struct neon_typed_alias atype;
2073 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2074
5287ad62 2075 if (getreg == FAIL)
477330fc
RM
2076 {
2077 first_error (_(reg_expected_msgs[rtype]));
2078 return FAIL;
2079 }
5f4273c7 2080
5287ad62 2081 if (base_reg == -1)
477330fc
RM
2082 {
2083 base_reg = getreg;
2084 if (rtype == REG_TYPE_NQ)
2085 {
2086 reg_incr = 1;
2087 }
2088 firsttype = atype;
2089 }
5287ad62 2090 else if (reg_incr == -1)
477330fc
RM
2091 {
2092 reg_incr = getreg - base_reg;
2093 if (reg_incr < 1 || reg_incr > 2)
2094 {
2095 first_error (_(incr_error));
2096 return FAIL;
2097 }
2098 }
5287ad62 2099 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2100 {
2101 first_error (_(incr_error));
2102 return FAIL;
2103 }
dcbf9037 2104
c921be7d 2105 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2106 {
2107 first_error (_(type_error));
2108 return FAIL;
2109 }
5f4273c7 2110
5287ad62 2111 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2112 modes. */
5287ad62 2113 if (ptr[0] == '-')
477330fc
RM
2114 {
2115 struct neon_typed_alias htype;
2116 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2117 if (lane == -1)
2118 lane = NEON_INTERLEAVE_LANES;
2119 else if (lane != NEON_INTERLEAVE_LANES)
2120 {
2121 first_error (_(type_error));
2122 return FAIL;
2123 }
2124 if (reg_incr == -1)
2125 reg_incr = 1;
2126 else if (reg_incr != 1)
2127 {
2128 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2129 return FAIL;
2130 }
2131 ptr++;
2132 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2133 if (hireg == FAIL)
2134 {
2135 first_error (_(reg_expected_msgs[rtype]));
2136 return FAIL;
2137 }
2138 if (! neon_alias_types_same (&htype, &firsttype))
2139 {
2140 first_error (_(type_error));
2141 return FAIL;
2142 }
2143 count += hireg + dregs - getreg;
2144 continue;
2145 }
5f4273c7 2146
5287ad62
JB
2147 /* If we're using Q registers, we can't use [] or [n] syntax. */
2148 if (rtype == REG_TYPE_NQ)
477330fc
RM
2149 {
2150 count += 2;
2151 continue;
2152 }
5f4273c7 2153
dcbf9037 2154 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2155 {
2156 if (lane == -1)
2157 lane = atype.index;
2158 else if (lane != atype.index)
2159 {
2160 first_error (_(type_error));
2161 return FAIL;
2162 }
2163 }
5287ad62 2164 else if (lane == -1)
477330fc 2165 lane = NEON_INTERLEAVE_LANES;
5287ad62 2166 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2167 {
2168 first_error (_(type_error));
2169 return FAIL;
2170 }
5287ad62
JB
2171 count++;
2172 }
2173 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2174
5287ad62
JB
2175 /* No lane set by [x]. We must be interleaving structures. */
2176 if (lane == -1)
2177 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2178
5287ad62
JB
2179 /* Sanity check. */
2180 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2181 || (count > 1 && reg_incr == -1))
2182 {
dcbf9037 2183 first_error (_("error parsing element/structure list"));
5287ad62
JB
2184 return FAIL;
2185 }
2186
2187 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2188 {
dcbf9037 2189 first_error (_("expected }"));
5287ad62
JB
2190 return FAIL;
2191 }
5f4273c7 2192
5287ad62
JB
2193 if (reg_incr == -1)
2194 reg_incr = 1;
2195
dcbf9037
JB
2196 if (eltype)
2197 *eltype = firsttype.eltype;
2198
5287ad62
JB
2199 *pbase = base_reg;
2200 *str = ptr;
5f4273c7 2201
5287ad62
JB
2202 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2203}
2204
c19d1205
ZW
2205/* Parse an explicit relocation suffix on an expression. This is
2206 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2207 arm_reloc_hsh contains no entries, so this function can only
2208 succeed if there is no () after the word. Returns -1 on error,
2209 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2210
c19d1205
ZW
2211static int
2212parse_reloc (char **str)
b99bd4ef 2213{
c19d1205
ZW
2214 struct reloc_entry *r;
2215 char *p, *q;
b99bd4ef 2216
c19d1205
ZW
2217 if (**str != '(')
2218 return BFD_RELOC_UNUSED;
b99bd4ef 2219
c19d1205
ZW
2220 p = *str + 1;
2221 q = p;
2222
2223 while (*q && *q != ')' && *q != ',')
2224 q++;
2225 if (*q != ')')
2226 return -1;
2227
21d799b5
NC
2228 if ((r = (struct reloc_entry *)
2229 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2230 return -1;
2231
2232 *str = q + 1;
2233 return r->reloc;
b99bd4ef
NC
2234}
2235
c19d1205
ZW
2236/* Directives: register aliases. */
2237
dcbf9037 2238static struct reg_entry *
90ec0d68 2239insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2240{
d3ce72d0 2241 struct reg_entry *new_reg;
c19d1205 2242 const char *name;
b99bd4ef 2243
d3ce72d0 2244 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2245 {
d3ce72d0 2246 if (new_reg->builtin)
c19d1205 2247 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2248
c19d1205
ZW
2249 /* Only warn about a redefinition if it's not defined as the
2250 same register. */
d3ce72d0 2251 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2252 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2253
d929913e 2254 return NULL;
c19d1205 2255 }
b99bd4ef 2256
c19d1205 2257 name = xstrdup (str);
325801bd 2258 new_reg = XNEW (struct reg_entry);
b99bd4ef 2259
d3ce72d0
NC
2260 new_reg->name = name;
2261 new_reg->number = number;
2262 new_reg->type = type;
2263 new_reg->builtin = FALSE;
2264 new_reg->neon = NULL;
b99bd4ef 2265
d3ce72d0 2266 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2267 abort ();
5f4273c7 2268
d3ce72d0 2269 return new_reg;
dcbf9037
JB
2270}
2271
2272static void
2273insert_neon_reg_alias (char *str, int number, int type,
477330fc 2274 struct neon_typed_alias *atype)
dcbf9037
JB
2275{
2276 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2277
dcbf9037
JB
2278 if (!reg)
2279 {
2280 first_error (_("attempt to redefine typed alias"));
2281 return;
2282 }
5f4273c7 2283
dcbf9037
JB
2284 if (atype)
2285 {
325801bd 2286 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2287 *reg->neon = *atype;
2288 }
c19d1205 2289}
b99bd4ef 2290
c19d1205 2291/* Look for the .req directive. This is of the form:
b99bd4ef 2292
c19d1205 2293 new_register_name .req existing_register_name
b99bd4ef 2294
c19d1205 2295 If we find one, or if it looks sufficiently like one that we want to
d929913e 2296 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2297
d929913e 2298static bfd_boolean
c19d1205
ZW
2299create_register_alias (char * newname, char *p)
2300{
2301 struct reg_entry *old;
2302 char *oldname, *nbuf;
2303 size_t nlen;
b99bd4ef 2304
c19d1205
ZW
2305 /* The input scrubber ensures that whitespace after the mnemonic is
2306 collapsed to single spaces. */
2307 oldname = p;
2308 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2309 return FALSE;
b99bd4ef 2310
c19d1205
ZW
2311 oldname += 6;
2312 if (*oldname == '\0')
d929913e 2313 return FALSE;
b99bd4ef 2314
21d799b5 2315 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2316 if (!old)
b99bd4ef 2317 {
c19d1205 2318 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2319 return TRUE;
b99bd4ef
NC
2320 }
2321
c19d1205
ZW
2322 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2323 the desired alias name, and p points to its end. If not, then
2324 the desired alias name is in the global original_case_string. */
2325#ifdef TC_CASE_SENSITIVE
2326 nlen = p - newname;
2327#else
2328 newname = original_case_string;
2329 nlen = strlen (newname);
2330#endif
b99bd4ef 2331
29a2809e 2332 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2333
c19d1205
ZW
2334 /* Create aliases under the new name as stated; an all-lowercase
2335 version of the new name; and an all-uppercase version of the new
2336 name. */
d929913e
NC
2337 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2338 {
2339 for (p = nbuf; *p; p++)
2340 *p = TOUPPER (*p);
c19d1205 2341
d929913e
NC
2342 if (strncmp (nbuf, newname, nlen))
2343 {
2344 /* If this attempt to create an additional alias fails, do not bother
2345 trying to create the all-lower case alias. We will fail and issue
2346 a second, duplicate error message. This situation arises when the
2347 programmer does something like:
2348 foo .req r0
2349 Foo .req r1
2350 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2351 the artificial FOO alias because it has already been created by the
d929913e
NC
2352 first .req. */
2353 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2354 {
2355 free (nbuf);
2356 return TRUE;
2357 }
d929913e 2358 }
c19d1205 2359
d929913e
NC
2360 for (p = nbuf; *p; p++)
2361 *p = TOLOWER (*p);
c19d1205 2362
d929913e
NC
2363 if (strncmp (nbuf, newname, nlen))
2364 insert_reg_alias (nbuf, old->number, old->type);
2365 }
c19d1205 2366
e1fa0163 2367 free (nbuf);
d929913e 2368 return TRUE;
b99bd4ef
NC
2369}
2370
dcbf9037
JB
2371/* Create a Neon typed/indexed register alias using directives, e.g.:
2372 X .dn d5.s32[1]
2373 Y .qn 6.s16
2374 Z .dn d7
2375 T .dn Z[0]
2376 These typed registers can be used instead of the types specified after the
2377 Neon mnemonic, so long as all operands given have types. Types can also be
2378 specified directly, e.g.:
5f4273c7 2379 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2380
c921be7d 2381static bfd_boolean
dcbf9037
JB
2382create_neon_reg_alias (char *newname, char *p)
2383{
2384 enum arm_reg_type basetype;
2385 struct reg_entry *basereg;
2386 struct reg_entry mybasereg;
2387 struct neon_type ntype;
2388 struct neon_typed_alias typeinfo;
12d6b0b7 2389 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2390 int namelen;
5f4273c7 2391
dcbf9037
JB
2392 typeinfo.defined = 0;
2393 typeinfo.eltype.type = NT_invtype;
2394 typeinfo.eltype.size = -1;
2395 typeinfo.index = -1;
5f4273c7 2396
dcbf9037 2397 nameend = p;
5f4273c7 2398
dcbf9037
JB
2399 if (strncmp (p, " .dn ", 5) == 0)
2400 basetype = REG_TYPE_VFD;
2401 else if (strncmp (p, " .qn ", 5) == 0)
2402 basetype = REG_TYPE_NQ;
2403 else
c921be7d 2404 return FALSE;
5f4273c7 2405
dcbf9037 2406 p += 5;
5f4273c7 2407
dcbf9037 2408 if (*p == '\0')
c921be7d 2409 return FALSE;
5f4273c7 2410
dcbf9037
JB
2411 basereg = arm_reg_parse_multi (&p);
2412
2413 if (basereg && basereg->type != basetype)
2414 {
2415 as_bad (_("bad type for register"));
c921be7d 2416 return FALSE;
dcbf9037
JB
2417 }
2418
2419 if (basereg == NULL)
2420 {
2421 expressionS exp;
2422 /* Try parsing as an integer. */
2423 my_get_expression (&exp, &p, GE_NO_PREFIX);
2424 if (exp.X_op != O_constant)
477330fc
RM
2425 {
2426 as_bad (_("expression must be constant"));
2427 return FALSE;
2428 }
dcbf9037
JB
2429 basereg = &mybasereg;
2430 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2431 : exp.X_add_number;
dcbf9037
JB
2432 basereg->neon = 0;
2433 }
2434
2435 if (basereg->neon)
2436 typeinfo = *basereg->neon;
2437
2438 if (parse_neon_type (&ntype, &p) == SUCCESS)
2439 {
2440 /* We got a type. */
2441 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2442 {
2443 as_bad (_("can't redefine the type of a register alias"));
2444 return FALSE;
2445 }
5f4273c7 2446
dcbf9037
JB
2447 typeinfo.defined |= NTA_HASTYPE;
2448 if (ntype.elems != 1)
477330fc
RM
2449 {
2450 as_bad (_("you must specify a single type only"));
2451 return FALSE;
2452 }
dcbf9037
JB
2453 typeinfo.eltype = ntype.el[0];
2454 }
5f4273c7 2455
dcbf9037
JB
2456 if (skip_past_char (&p, '[') == SUCCESS)
2457 {
2458 expressionS exp;
2459 /* We got a scalar index. */
5f4273c7 2460
dcbf9037 2461 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2462 {
2463 as_bad (_("can't redefine the index of a scalar alias"));
2464 return FALSE;
2465 }
5f4273c7 2466
dcbf9037 2467 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2468
dcbf9037 2469 if (exp.X_op != O_constant)
477330fc
RM
2470 {
2471 as_bad (_("scalar index must be constant"));
2472 return FALSE;
2473 }
5f4273c7 2474
dcbf9037
JB
2475 typeinfo.defined |= NTA_HASINDEX;
2476 typeinfo.index = exp.X_add_number;
5f4273c7 2477
dcbf9037 2478 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2479 {
2480 as_bad (_("expecting ]"));
2481 return FALSE;
2482 }
dcbf9037
JB
2483 }
2484
15735687
NS
2485 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2486 the desired alias name, and p points to its end. If not, then
2487 the desired alias name is in the global original_case_string. */
2488#ifdef TC_CASE_SENSITIVE
dcbf9037 2489 namelen = nameend - newname;
15735687
NS
2490#else
2491 newname = original_case_string;
2492 namelen = strlen (newname);
2493#endif
2494
29a2809e 2495 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2496
dcbf9037 2497 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2498 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2499
dcbf9037
JB
2500 /* Insert name in all uppercase. */
2501 for (p = namebuf; *p; p++)
2502 *p = TOUPPER (*p);
5f4273c7 2503
dcbf9037
JB
2504 if (strncmp (namebuf, newname, namelen))
2505 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2506 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2507
dcbf9037
JB
2508 /* Insert name in all lowercase. */
2509 for (p = namebuf; *p; p++)
2510 *p = TOLOWER (*p);
5f4273c7 2511
dcbf9037
JB
2512 if (strncmp (namebuf, newname, namelen))
2513 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2514 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2515
e1fa0163 2516 free (namebuf);
c921be7d 2517 return TRUE;
dcbf9037
JB
2518}
2519
c19d1205
ZW
2520/* Should never be called, as .req goes between the alias and the
2521 register name, not at the beginning of the line. */
c921be7d 2522
b99bd4ef 2523static void
c19d1205 2524s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2525{
c19d1205
ZW
2526 as_bad (_("invalid syntax for .req directive"));
2527}
b99bd4ef 2528
dcbf9037
JB
2529static void
2530s_dn (int a ATTRIBUTE_UNUSED)
2531{
2532 as_bad (_("invalid syntax for .dn directive"));
2533}
2534
2535static void
2536s_qn (int a ATTRIBUTE_UNUSED)
2537{
2538 as_bad (_("invalid syntax for .qn directive"));
2539}
2540
c19d1205
ZW
2541/* The .unreq directive deletes an alias which was previously defined
2542 by .req. For example:
b99bd4ef 2543
c19d1205
ZW
2544 my_alias .req r11
2545 .unreq my_alias */
b99bd4ef
NC
2546
2547static void
c19d1205 2548s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2549{
c19d1205
ZW
2550 char * name;
2551 char saved_char;
b99bd4ef 2552
c19d1205
ZW
2553 name = input_line_pointer;
2554
2555 while (*input_line_pointer != 0
2556 && *input_line_pointer != ' '
2557 && *input_line_pointer != '\n')
2558 ++input_line_pointer;
2559
2560 saved_char = *input_line_pointer;
2561 *input_line_pointer = 0;
2562
2563 if (!*name)
2564 as_bad (_("invalid syntax for .unreq directive"));
2565 else
2566 {
21d799b5 2567 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2568 name);
c19d1205
ZW
2569
2570 if (!reg)
2571 as_bad (_("unknown register alias '%s'"), name);
2572 else if (reg->builtin)
a1727c1a 2573 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2574 name);
2575 else
2576 {
d929913e
NC
2577 char * p;
2578 char * nbuf;
2579
db0bc284 2580 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2581 free ((char *) reg->name);
477330fc
RM
2582 if (reg->neon)
2583 free (reg->neon);
c19d1205 2584 free (reg);
d929913e
NC
2585
2586 /* Also locate the all upper case and all lower case versions.
2587 Do not complain if we cannot find one or the other as it
2588 was probably deleted above. */
5f4273c7 2589
d929913e
NC
2590 nbuf = strdup (name);
2591 for (p = nbuf; *p; p++)
2592 *p = TOUPPER (*p);
21d799b5 2593 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2594 if (reg)
2595 {
db0bc284 2596 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2597 free ((char *) reg->name);
2598 if (reg->neon)
2599 free (reg->neon);
2600 free (reg);
2601 }
2602
2603 for (p = nbuf; *p; p++)
2604 *p = TOLOWER (*p);
21d799b5 2605 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2606 if (reg)
2607 {
db0bc284 2608 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2609 free ((char *) reg->name);
2610 if (reg->neon)
2611 free (reg->neon);
2612 free (reg);
2613 }
2614
2615 free (nbuf);
c19d1205
ZW
2616 }
2617 }
b99bd4ef 2618
c19d1205 2619 *input_line_pointer = saved_char;
b99bd4ef
NC
2620 demand_empty_rest_of_line ();
2621}
2622
c19d1205
ZW
2623/* Directives: Instruction set selection. */
2624
2625#ifdef OBJ_ELF
2626/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2627 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2628 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2629 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2630
cd000bff
DJ
2631/* Create a new mapping symbol for the transition to STATE. */
2632
2633static void
2634make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2635{
a737bd4d 2636 symbolS * symbolP;
c19d1205
ZW
2637 const char * symname;
2638 int type;
b99bd4ef 2639
c19d1205 2640 switch (state)
b99bd4ef 2641 {
c19d1205
ZW
2642 case MAP_DATA:
2643 symname = "$d";
2644 type = BSF_NO_FLAGS;
2645 break;
2646 case MAP_ARM:
2647 symname = "$a";
2648 type = BSF_NO_FLAGS;
2649 break;
2650 case MAP_THUMB:
2651 symname = "$t";
2652 type = BSF_NO_FLAGS;
2653 break;
c19d1205
ZW
2654 default:
2655 abort ();
2656 }
2657
cd000bff 2658 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2659 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2660
2661 switch (state)
2662 {
2663 case MAP_ARM:
2664 THUMB_SET_FUNC (symbolP, 0);
2665 ARM_SET_THUMB (symbolP, 0);
2666 ARM_SET_INTERWORK (symbolP, support_interwork);
2667 break;
2668
2669 case MAP_THUMB:
2670 THUMB_SET_FUNC (symbolP, 1);
2671 ARM_SET_THUMB (symbolP, 1);
2672 ARM_SET_INTERWORK (symbolP, support_interwork);
2673 break;
2674
2675 case MAP_DATA:
2676 default:
cd000bff
DJ
2677 break;
2678 }
2679
2680 /* Save the mapping symbols for future reference. Also check that
2681 we do not place two mapping symbols at the same offset within a
2682 frag. We'll handle overlap between frags in
2de7820f
JZ
2683 check_mapping_symbols.
2684
2685 If .fill or other data filling directive generates zero sized data,
2686 the mapping symbol for the following code will have the same value
2687 as the one generated for the data filling directive. In this case,
2688 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2689 if (value == 0)
2690 {
2de7820f
JZ
2691 if (frag->tc_frag_data.first_map != NULL)
2692 {
2693 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2694 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2695 }
cd000bff
DJ
2696 frag->tc_frag_data.first_map = symbolP;
2697 }
2698 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2699 {
2700 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2701 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2702 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2703 }
cd000bff
DJ
2704 frag->tc_frag_data.last_map = symbolP;
2705}
2706
2707/* We must sometimes convert a region marked as code to data during
2708 code alignment, if an odd number of bytes have to be padded. The
2709 code mapping symbol is pushed to an aligned address. */
2710
2711static void
2712insert_data_mapping_symbol (enum mstate state,
2713 valueT value, fragS *frag, offsetT bytes)
2714{
2715 /* If there was already a mapping symbol, remove it. */
2716 if (frag->tc_frag_data.last_map != NULL
2717 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2718 {
2719 symbolS *symp = frag->tc_frag_data.last_map;
2720
2721 if (value == 0)
2722 {
2723 know (frag->tc_frag_data.first_map == symp);
2724 frag->tc_frag_data.first_map = NULL;
2725 }
2726 frag->tc_frag_data.last_map = NULL;
2727 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2728 }
cd000bff
DJ
2729
2730 make_mapping_symbol (MAP_DATA, value, frag);
2731 make_mapping_symbol (state, value + bytes, frag);
2732}
2733
2734static void mapping_state_2 (enum mstate state, int max_chars);
2735
2736/* Set the mapping state to STATE. Only call this when about to
2737 emit some STATE bytes to the file. */
2738
4e9aaefb 2739#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2740void
2741mapping_state (enum mstate state)
2742{
940b5ce0
DJ
2743 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2744
cd000bff
DJ
2745 if (mapstate == state)
2746 /* The mapping symbol has already been emitted.
2747 There is nothing else to do. */
2748 return;
49c62a33
NC
2749
2750 if (state == MAP_ARM || state == MAP_THUMB)
2751 /* PR gas/12931
2752 All ARM instructions require 4-byte alignment.
2753 (Almost) all Thumb instructions require 2-byte alignment.
2754
2755 When emitting instructions into any section, mark the section
2756 appropriately.
2757
2758 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2759 but themselves require 2-byte alignment; this applies to some
33eaf5de 2760 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2761 literal pool generation or an explicit .align >=2, both of
2762 which will cause the section to me marked with sufficient
2763 alignment. Thus, we don't handle those cases here. */
2764 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2765
2766 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2767 /* This case will be evaluated later. */
cd000bff 2768 return;
cd000bff
DJ
2769
2770 mapping_state_2 (state, 0);
cd000bff
DJ
2771}
2772
2773/* Same as mapping_state, but MAX_CHARS bytes have already been
2774 allocated. Put the mapping symbol that far back. */
2775
2776static void
2777mapping_state_2 (enum mstate state, int max_chars)
2778{
940b5ce0
DJ
2779 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2780
2781 if (!SEG_NORMAL (now_seg))
2782 return;
2783
cd000bff
DJ
2784 if (mapstate == state)
2785 /* The mapping symbol has already been emitted.
2786 There is nothing else to do. */
2787 return;
2788
4e9aaefb
SA
2789 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2790 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2791 {
2792 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2793 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2794
2795 if (add_symbol)
2796 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2797 }
2798
cd000bff
DJ
2799 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2800 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2801}
4e9aaefb 2802#undef TRANSITION
c19d1205 2803#else
d3106081
NS
2804#define mapping_state(x) ((void)0)
2805#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2806#endif
2807
2808/* Find the real, Thumb encoded start of a Thumb function. */
2809
4343666d 2810#ifdef OBJ_COFF
c19d1205
ZW
2811static symbolS *
2812find_real_start (symbolS * symbolP)
2813{
2814 char * real_start;
2815 const char * name = S_GET_NAME (symbolP);
2816 symbolS * new_target;
2817
2818 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2819#define STUB_NAME ".real_start_of"
2820
2821 if (name == NULL)
2822 abort ();
2823
37f6032b
ZW
2824 /* The compiler may generate BL instructions to local labels because
2825 it needs to perform a branch to a far away location. These labels
2826 do not have a corresponding ".real_start_of" label. We check
2827 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2828 the ".real_start_of" convention for nonlocal branches. */
2829 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2830 return symbolP;
2831
e1fa0163 2832 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2833 new_target = symbol_find (real_start);
e1fa0163 2834 free (real_start);
c19d1205
ZW
2835
2836 if (new_target == NULL)
2837 {
bd3ba5d1 2838 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2839 new_target = symbolP;
2840 }
2841
c19d1205
ZW
2842 return new_target;
2843}
4343666d 2844#endif
c19d1205
ZW
2845
2846static void
2847opcode_select (int width)
2848{
2849 switch (width)
2850 {
2851 case 16:
2852 if (! thumb_mode)
2853 {
e74cfd16 2854 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2855 as_bad (_("selected processor does not support THUMB opcodes"));
2856
2857 thumb_mode = 1;
2858 /* No need to force the alignment, since we will have been
2859 coming from ARM mode, which is word-aligned. */
2860 record_alignment (now_seg, 1);
2861 }
c19d1205
ZW
2862 break;
2863
2864 case 32:
2865 if (thumb_mode)
2866 {
e74cfd16 2867 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2868 as_bad (_("selected processor does not support ARM opcodes"));
2869
2870 thumb_mode = 0;
2871
2872 if (!need_pass_2)
2873 frag_align (2, 0, 0);
2874
2875 record_alignment (now_seg, 1);
2876 }
c19d1205
ZW
2877 break;
2878
2879 default:
2880 as_bad (_("invalid instruction size selected (%d)"), width);
2881 }
2882}
2883
2884static void
2885s_arm (int ignore ATTRIBUTE_UNUSED)
2886{
2887 opcode_select (32);
2888 demand_empty_rest_of_line ();
2889}
2890
2891static void
2892s_thumb (int ignore ATTRIBUTE_UNUSED)
2893{
2894 opcode_select (16);
2895 demand_empty_rest_of_line ();
2896}
2897
2898static void
2899s_code (int unused ATTRIBUTE_UNUSED)
2900{
2901 int temp;
2902
2903 temp = get_absolute_expression ();
2904 switch (temp)
2905 {
2906 case 16:
2907 case 32:
2908 opcode_select (temp);
2909 break;
2910
2911 default:
2912 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2913 }
2914}
2915
2916static void
2917s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2918{
2919 /* If we are not already in thumb mode go into it, EVEN if
2920 the target processor does not support thumb instructions.
2921 This is used by gcc/config/arm/lib1funcs.asm for example
2922 to compile interworking support functions even if the
2923 target processor should not support interworking. */
2924 if (! thumb_mode)
2925 {
2926 thumb_mode = 2;
2927 record_alignment (now_seg, 1);
2928 }
2929
2930 demand_empty_rest_of_line ();
2931}
2932
2933static void
2934s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2935{
2936 s_thumb (0);
2937
2938 /* The following label is the name/address of the start of a Thumb function.
2939 We need to know this for the interworking support. */
2940 label_is_thumb_function_name = TRUE;
2941}
2942
2943/* Perform a .set directive, but also mark the alias as
2944 being a thumb function. */
2945
2946static void
2947s_thumb_set (int equiv)
2948{
2949 /* XXX the following is a duplicate of the code for s_set() in read.c
2950 We cannot just call that code as we need to get at the symbol that
2951 is created. */
2952 char * name;
2953 char delim;
2954 char * end_name;
2955 symbolS * symbolP;
2956
2957 /* Especial apologies for the random logic:
2958 This just grew, and could be parsed much more simply!
2959 Dean - in haste. */
d02603dc 2960 delim = get_symbol_name (& name);
c19d1205 2961 end_name = input_line_pointer;
d02603dc 2962 (void) restore_line_pointer (delim);
c19d1205
ZW
2963
2964 if (*input_line_pointer != ',')
2965 {
2966 *end_name = 0;
2967 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2968 *end_name = delim;
2969 ignore_rest_of_line ();
2970 return;
2971 }
2972
2973 input_line_pointer++;
2974 *end_name = 0;
2975
2976 if (name[0] == '.' && name[1] == '\0')
2977 {
2978 /* XXX - this should not happen to .thumb_set. */
2979 abort ();
2980 }
2981
2982 if ((symbolP = symbol_find (name)) == NULL
2983 && (symbolP = md_undefined_symbol (name)) == NULL)
2984 {
2985#ifndef NO_LISTING
2986 /* When doing symbol listings, play games with dummy fragments living
2987 outside the normal fragment chain to record the file and line info
c19d1205 2988 for this symbol. */
b99bd4ef
NC
2989 if (listing & LISTING_SYMBOLS)
2990 {
2991 extern struct list_info_struct * listing_tail;
21d799b5 2992 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2993
2994 memset (dummy_frag, 0, sizeof (fragS));
2995 dummy_frag->fr_type = rs_fill;
2996 dummy_frag->line = listing_tail;
2997 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2998 dummy_frag->fr_symbol = symbolP;
2999 }
3000 else
3001#endif
3002 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3003
3004#ifdef OBJ_COFF
3005 /* "set" symbols are local unless otherwise specified. */
3006 SF_SET_LOCAL (symbolP);
3007#endif /* OBJ_COFF */
3008 } /* Make a new symbol. */
3009
3010 symbol_table_insert (symbolP);
3011
3012 * end_name = delim;
3013
3014 if (equiv
3015 && S_IS_DEFINED (symbolP)
3016 && S_GET_SEGMENT (symbolP) != reg_section)
3017 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3018
3019 pseudo_set (symbolP);
3020
3021 demand_empty_rest_of_line ();
3022
c19d1205 3023 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
3024
3025 THUMB_SET_FUNC (symbolP, 1);
3026 ARM_SET_THUMB (symbolP, 1);
3027#if defined OBJ_ELF || defined OBJ_COFF
3028 ARM_SET_INTERWORK (symbolP, support_interwork);
3029#endif
3030}
3031
c19d1205 3032/* Directives: Mode selection. */
b99bd4ef 3033
c19d1205
ZW
3034/* .syntax [unified|divided] - choose the new unified syntax
3035 (same for Arm and Thumb encoding, modulo slight differences in what
3036 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3037static void
c19d1205 3038s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3039{
c19d1205
ZW
3040 char *name, delim;
3041
d02603dc 3042 delim = get_symbol_name (& name);
c19d1205
ZW
3043
3044 if (!strcasecmp (name, "unified"))
3045 unified_syntax = TRUE;
3046 else if (!strcasecmp (name, "divided"))
3047 unified_syntax = FALSE;
3048 else
3049 {
3050 as_bad (_("unrecognized syntax mode \"%s\""), name);
3051 return;
3052 }
d02603dc 3053 (void) restore_line_pointer (delim);
b99bd4ef
NC
3054 demand_empty_rest_of_line ();
3055}
3056
c19d1205
ZW
3057/* Directives: sectioning and alignment. */
3058
c19d1205
ZW
3059static void
3060s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3061{
c19d1205
ZW
3062 /* We don't support putting frags in the BSS segment, we fake it by
3063 marking in_bss, then looking at s_skip for clues. */
3064 subseg_set (bss_section, 0);
3065 demand_empty_rest_of_line ();
cd000bff
DJ
3066
3067#ifdef md_elf_section_change_hook
3068 md_elf_section_change_hook ();
3069#endif
c19d1205 3070}
b99bd4ef 3071
c19d1205
ZW
3072static void
3073s_even (int ignore ATTRIBUTE_UNUSED)
3074{
3075 /* Never make frag if expect extra pass. */
3076 if (!need_pass_2)
3077 frag_align (1, 0, 0);
b99bd4ef 3078
c19d1205 3079 record_alignment (now_seg, 1);
b99bd4ef 3080
c19d1205 3081 demand_empty_rest_of_line ();
b99bd4ef
NC
3082}
3083
2e6976a8
DG
3084/* Directives: CodeComposer Studio. */
3085
3086/* .ref (for CodeComposer Studio syntax only). */
3087static void
3088s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3089{
3090 if (codecomposer_syntax)
3091 ignore_rest_of_line ();
3092 else
3093 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3094}
3095
3096/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3097 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3098static void
3099asmfunc_debug (const char * name)
3100{
3101 static const char * last_name = NULL;
3102
3103 if (name != NULL)
3104 {
3105 gas_assert (last_name == NULL);
3106 last_name = name;
3107
3108 if (debug_type == DEBUG_STABS)
3109 stabs_generate_asm_func (name, name);
3110 }
3111 else
3112 {
3113 gas_assert (last_name != NULL);
3114
3115 if (debug_type == DEBUG_STABS)
3116 stabs_generate_asm_endfunc (last_name, last_name);
3117
3118 last_name = NULL;
3119 }
3120}
3121
3122static void
3123s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3124{
3125 if (codecomposer_syntax)
3126 {
3127 switch (asmfunc_state)
3128 {
3129 case OUTSIDE_ASMFUNC:
3130 asmfunc_state = WAITING_ASMFUNC_NAME;
3131 break;
3132
3133 case WAITING_ASMFUNC_NAME:
3134 as_bad (_(".asmfunc repeated."));
3135 break;
3136
3137 case WAITING_ENDASMFUNC:
3138 as_bad (_(".asmfunc without function."));
3139 break;
3140 }
3141 demand_empty_rest_of_line ();
3142 }
3143 else
3144 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3145}
3146
3147static void
3148s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3149{
3150 if (codecomposer_syntax)
3151 {
3152 switch (asmfunc_state)
3153 {
3154 case OUTSIDE_ASMFUNC:
3155 as_bad (_(".endasmfunc without a .asmfunc."));
3156 break;
3157
3158 case WAITING_ASMFUNC_NAME:
3159 as_bad (_(".endasmfunc without function."));
3160 break;
3161
3162 case WAITING_ENDASMFUNC:
3163 asmfunc_state = OUTSIDE_ASMFUNC;
3164 asmfunc_debug (NULL);
3165 break;
3166 }
3167 demand_empty_rest_of_line ();
3168 }
3169 else
3170 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3171}
3172
3173static void
3174s_ccs_def (int name)
3175{
3176 if (codecomposer_syntax)
3177 s_globl (name);
3178 else
3179 as_bad (_(".def pseudo-op only available with -mccs flag."));
3180}
3181
c19d1205 3182/* Directives: Literal pools. */
a737bd4d 3183
c19d1205
ZW
3184static literal_pool *
3185find_literal_pool (void)
a737bd4d 3186{
c19d1205 3187 literal_pool * pool;
a737bd4d 3188
c19d1205 3189 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3190 {
c19d1205
ZW
3191 if (pool->section == now_seg
3192 && pool->sub_section == now_subseg)
3193 break;
a737bd4d
NC
3194 }
3195
c19d1205 3196 return pool;
a737bd4d
NC
3197}
3198
c19d1205
ZW
3199static literal_pool *
3200find_or_make_literal_pool (void)
a737bd4d 3201{
c19d1205
ZW
3202 /* Next literal pool ID number. */
3203 static unsigned int latest_pool_num = 1;
3204 literal_pool * pool;
a737bd4d 3205
c19d1205 3206 pool = find_literal_pool ();
a737bd4d 3207
c19d1205 3208 if (pool == NULL)
a737bd4d 3209 {
c19d1205 3210 /* Create a new pool. */
325801bd 3211 pool = XNEW (literal_pool);
c19d1205
ZW
3212 if (! pool)
3213 return NULL;
a737bd4d 3214
c19d1205
ZW
3215 pool->next_free_entry = 0;
3216 pool->section = now_seg;
3217 pool->sub_section = now_subseg;
3218 pool->next = list_of_pools;
3219 pool->symbol = NULL;
8335d6aa 3220 pool->alignment = 2;
c19d1205
ZW
3221
3222 /* Add it to the list. */
3223 list_of_pools = pool;
a737bd4d 3224 }
a737bd4d 3225
c19d1205
ZW
3226 /* New pools, and emptied pools, will have a NULL symbol. */
3227 if (pool->symbol == NULL)
a737bd4d 3228 {
c19d1205
ZW
3229 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3230 (valueT) 0, &zero_address_frag);
3231 pool->id = latest_pool_num ++;
a737bd4d
NC
3232 }
3233
c19d1205
ZW
3234 /* Done. */
3235 return pool;
a737bd4d
NC
3236}
3237
c19d1205 3238/* Add the literal in the global 'inst'
5f4273c7 3239 structure to the relevant literal pool. */
b99bd4ef
NC
3240
3241static int
8335d6aa 3242add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3243{
8335d6aa
JW
3244#define PADDING_SLOT 0x1
3245#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3246 literal_pool * pool;
8335d6aa
JW
3247 unsigned int entry, pool_size = 0;
3248 bfd_boolean padding_slot_p = FALSE;
e56c722b 3249 unsigned imm1 = 0;
8335d6aa
JW
3250 unsigned imm2 = 0;
3251
3252 if (nbytes == 8)
3253 {
3254 imm1 = inst.operands[1].imm;
3255 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3256 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3257 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3258 if (target_big_endian)
3259 {
3260 imm1 = imm2;
3261 imm2 = inst.operands[1].imm;
3262 }
3263 }
b99bd4ef 3264
c19d1205
ZW
3265 pool = find_or_make_literal_pool ();
3266
3267 /* Check if this literal value is already in the pool. */
3268 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3269 {
8335d6aa
JW
3270 if (nbytes == 4)
3271 {
3272 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3273 && (inst.reloc.exp.X_op == O_constant)
3274 && (pool->literals[entry].X_add_number
3275 == inst.reloc.exp.X_add_number)
3276 && (pool->literals[entry].X_md == nbytes)
3277 && (pool->literals[entry].X_unsigned
3278 == inst.reloc.exp.X_unsigned))
3279 break;
3280
3281 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3282 && (inst.reloc.exp.X_op == O_symbol)
3283 && (pool->literals[entry].X_add_number
3284 == inst.reloc.exp.X_add_number)
3285 && (pool->literals[entry].X_add_symbol
3286 == inst.reloc.exp.X_add_symbol)
3287 && (pool->literals[entry].X_op_symbol
3288 == inst.reloc.exp.X_op_symbol)
3289 && (pool->literals[entry].X_md == nbytes))
3290 break;
3291 }
3292 else if ((nbytes == 8)
3293 && !(pool_size & 0x7)
3294 && ((entry + 1) != pool->next_free_entry)
3295 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3296 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3297 && (pool->literals[entry].X_unsigned
3298 == inst.reloc.exp.X_unsigned)
3299 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3300 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3301 && (pool->literals[entry + 1].X_unsigned
3302 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3303 break;
3304
8335d6aa
JW
3305 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3306 if (padding_slot_p && (nbytes == 4))
c19d1205 3307 break;
8335d6aa
JW
3308
3309 pool_size += 4;
b99bd4ef
NC
3310 }
3311
c19d1205
ZW
3312 /* Do we need to create a new entry? */
3313 if (entry == pool->next_free_entry)
3314 {
3315 if (entry >= MAX_LITERAL_POOL_SIZE)
3316 {
3317 inst.error = _("literal pool overflow");
3318 return FAIL;
3319 }
3320
8335d6aa
JW
3321 if (nbytes == 8)
3322 {
3323 /* For 8-byte entries, we align to an 8-byte boundary,
3324 and split it into two 4-byte entries, because on 32-bit
3325 host, 8-byte constants are treated as big num, thus
3326 saved in "generic_bignum" which will be overwritten
3327 by later assignments.
3328
3329 We also need to make sure there is enough space for
3330 the split.
3331
3332 We also check to make sure the literal operand is a
3333 constant number. */
19f2f6a9
JW
3334 if (!(inst.reloc.exp.X_op == O_constant
3335 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3336 {
3337 inst.error = _("invalid type for literal pool");
3338 return FAIL;
3339 }
3340 else if (pool_size & 0x7)
3341 {
3342 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3343 {
3344 inst.error = _("literal pool overflow");
3345 return FAIL;
3346 }
3347
3348 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3349 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3350 pool->literals[entry].X_add_number = 0;
3351 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3352 pool->next_free_entry += 1;
3353 pool_size += 4;
3354 }
3355 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3356 {
3357 inst.error = _("literal pool overflow");
3358 return FAIL;
3359 }
3360
3361 pool->literals[entry] = inst.reloc.exp;
3362 pool->literals[entry].X_op = O_constant;
3363 pool->literals[entry].X_add_number = imm1;
3364 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3365 pool->literals[entry++].X_md = 4;
3366 pool->literals[entry] = inst.reloc.exp;
3367 pool->literals[entry].X_op = O_constant;
3368 pool->literals[entry].X_add_number = imm2;
3369 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3370 pool->literals[entry].X_md = 4;
3371 pool->alignment = 3;
3372 pool->next_free_entry += 1;
3373 }
3374 else
3375 {
3376 pool->literals[entry] = inst.reloc.exp;
3377 pool->literals[entry].X_md = 4;
3378 }
3379
a8040cf2
NC
3380#ifdef OBJ_ELF
3381 /* PR ld/12974: Record the location of the first source line to reference
3382 this entry in the literal pool. If it turns out during linking that the
3383 symbol does not exist we will be able to give an accurate line number for
3384 the (first use of the) missing reference. */
3385 if (debug_type == DEBUG_DWARF2)
3386 dwarf2_where (pool->locs + entry);
3387#endif
c19d1205
ZW
3388 pool->next_free_entry += 1;
3389 }
8335d6aa
JW
3390 else if (padding_slot_p)
3391 {
3392 pool->literals[entry] = inst.reloc.exp;
3393 pool->literals[entry].X_md = nbytes;
3394 }
b99bd4ef 3395
c19d1205 3396 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3397 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3398 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3399
c19d1205 3400 return SUCCESS;
b99bd4ef
NC
3401}
3402
2e6976a8 3403bfd_boolean
2e57ce7b 3404tc_start_label_without_colon (void)
2e6976a8
DG
3405{
3406 bfd_boolean ret = TRUE;
3407
3408 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3409 {
2e57ce7b 3410 const char *label = input_line_pointer;
2e6976a8
DG
3411
3412 while (!is_end_of_line[(int) label[-1]])
3413 --label;
3414
3415 if (*label == '.')
3416 {
3417 as_bad (_("Invalid label '%s'"), label);
3418 ret = FALSE;
3419 }
3420
3421 asmfunc_debug (label);
3422
3423 asmfunc_state = WAITING_ENDASMFUNC;
3424 }
3425
3426 return ret;
3427}
3428
c19d1205 3429/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3430 a later date assign it a value. That's what these functions do. */
e16bb312 3431
c19d1205
ZW
3432static void
3433symbol_locate (symbolS * symbolP,
3434 const char * name, /* It is copied, the caller can modify. */
3435 segT segment, /* Segment identifier (SEG_<something>). */
3436 valueT valu, /* Symbol value. */
3437 fragS * frag) /* Associated fragment. */
3438{
e57e6ddc 3439 size_t name_length;
c19d1205 3440 char * preserved_copy_of_name;
e16bb312 3441
c19d1205
ZW
3442 name_length = strlen (name) + 1; /* +1 for \0. */
3443 obstack_grow (&notes, name, name_length);
21d799b5 3444 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3445
c19d1205
ZW
3446#ifdef tc_canonicalize_symbol_name
3447 preserved_copy_of_name =
3448 tc_canonicalize_symbol_name (preserved_copy_of_name);
3449#endif
b99bd4ef 3450
c19d1205 3451 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3452
c19d1205
ZW
3453 S_SET_SEGMENT (symbolP, segment);
3454 S_SET_VALUE (symbolP, valu);
3455 symbol_clear_list_pointers (symbolP);
b99bd4ef 3456
c19d1205 3457 symbol_set_frag (symbolP, frag);
b99bd4ef 3458
c19d1205
ZW
3459 /* Link to end of symbol chain. */
3460 {
3461 extern int symbol_table_frozen;
b99bd4ef 3462
c19d1205
ZW
3463 if (symbol_table_frozen)
3464 abort ();
3465 }
b99bd4ef 3466
c19d1205 3467 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3468
c19d1205 3469 obj_symbol_new_hook (symbolP);
b99bd4ef 3470
c19d1205
ZW
3471#ifdef tc_symbol_new_hook
3472 tc_symbol_new_hook (symbolP);
3473#endif
3474
3475#ifdef DEBUG_SYMS
3476 verify_symbol_chain (symbol_rootP, symbol_lastP);
3477#endif /* DEBUG_SYMS */
b99bd4ef
NC
3478}
3479
c19d1205
ZW
3480static void
3481s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3482{
c19d1205
ZW
3483 unsigned int entry;
3484 literal_pool * pool;
3485 char sym_name[20];
b99bd4ef 3486
c19d1205
ZW
3487 pool = find_literal_pool ();
3488 if (pool == NULL
3489 || pool->symbol == NULL
3490 || pool->next_free_entry == 0)
3491 return;
b99bd4ef 3492
c19d1205
ZW
3493 /* Align pool as you have word accesses.
3494 Only make a frag if we have to. */
3495 if (!need_pass_2)
8335d6aa 3496 frag_align (pool->alignment, 0, 0);
b99bd4ef 3497
c19d1205 3498 record_alignment (now_seg, 2);
b99bd4ef 3499
aaca88ef 3500#ifdef OBJ_ELF
47fc6e36
WN
3501 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3502 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3503#endif
c19d1205 3504 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3505
c19d1205
ZW
3506 symbol_locate (pool->symbol, sym_name, now_seg,
3507 (valueT) frag_now_fix (), frag_now);
3508 symbol_table_insert (pool->symbol);
b99bd4ef 3509
c19d1205 3510 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3511
c19d1205
ZW
3512#if defined OBJ_COFF || defined OBJ_ELF
3513 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3514#endif
6c43fab6 3515
c19d1205 3516 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3517 {
3518#ifdef OBJ_ELF
3519 if (debug_type == DEBUG_DWARF2)
3520 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3521#endif
3522 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3523 emit_expr (&(pool->literals[entry]),
3524 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3525 }
b99bd4ef 3526
c19d1205
ZW
3527 /* Mark the pool as empty. */
3528 pool->next_free_entry = 0;
3529 pool->symbol = NULL;
b99bd4ef
NC
3530}
3531
c19d1205
ZW
3532#ifdef OBJ_ELF
3533/* Forward declarations for functions below, in the MD interface
3534 section. */
3535static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3536static valueT create_unwind_entry (int);
3537static void start_unwind_section (const segT, int);
3538static void add_unwind_opcode (valueT, int);
3539static void flush_pending_unwind (void);
b99bd4ef 3540
c19d1205 3541/* Directives: Data. */
b99bd4ef 3542
c19d1205
ZW
3543static void
3544s_arm_elf_cons (int nbytes)
3545{
3546 expressionS exp;
b99bd4ef 3547
c19d1205
ZW
3548#ifdef md_flush_pending_output
3549 md_flush_pending_output ();
3550#endif
b99bd4ef 3551
c19d1205 3552 if (is_it_end_of_statement ())
b99bd4ef 3553 {
c19d1205
ZW
3554 demand_empty_rest_of_line ();
3555 return;
b99bd4ef
NC
3556 }
3557
c19d1205
ZW
3558#ifdef md_cons_align
3559 md_cons_align (nbytes);
3560#endif
b99bd4ef 3561
c19d1205
ZW
3562 mapping_state (MAP_DATA);
3563 do
b99bd4ef 3564 {
c19d1205
ZW
3565 int reloc;
3566 char *base = input_line_pointer;
b99bd4ef 3567
c19d1205 3568 expression (& exp);
b99bd4ef 3569
c19d1205
ZW
3570 if (exp.X_op != O_symbol)
3571 emit_expr (&exp, (unsigned int) nbytes);
3572 else
3573 {
3574 char *before_reloc = input_line_pointer;
3575 reloc = parse_reloc (&input_line_pointer);
3576 if (reloc == -1)
3577 {
3578 as_bad (_("unrecognized relocation suffix"));
3579 ignore_rest_of_line ();
3580 return;
3581 }
3582 else if (reloc == BFD_RELOC_UNUSED)
3583 emit_expr (&exp, (unsigned int) nbytes);
3584 else
3585 {
21d799b5 3586 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3587 bfd_reloc_type_lookup (stdoutput,
3588 (bfd_reloc_code_real_type) reloc);
c19d1205 3589 int size = bfd_get_reloc_size (howto);
b99bd4ef 3590
2fc8bdac
ZW
3591 if (reloc == BFD_RELOC_ARM_PLT32)
3592 {
3593 as_bad (_("(plt) is only valid on branch targets"));
3594 reloc = BFD_RELOC_UNUSED;
3595 size = 0;
3596 }
3597
c19d1205 3598 if (size > nbytes)
992a06ee
AM
3599 as_bad (ngettext ("%s relocations do not fit in %d byte",
3600 "%s relocations do not fit in %d bytes",
3601 nbytes),
c19d1205
ZW
3602 howto->name, nbytes);
3603 else
3604 {
3605 /* We've parsed an expression stopping at O_symbol.
3606 But there may be more expression left now that we
3607 have parsed the relocation marker. Parse it again.
3608 XXX Surely there is a cleaner way to do this. */
3609 char *p = input_line_pointer;
3610 int offset;
325801bd 3611 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3612
c19d1205
ZW
3613 memcpy (save_buf, base, input_line_pointer - base);
3614 memmove (base + (input_line_pointer - before_reloc),
3615 base, before_reloc - base);
3616
3617 input_line_pointer = base + (input_line_pointer-before_reloc);
3618 expression (&exp);
3619 memcpy (base, save_buf, p - base);
3620
3621 offset = nbytes - size;
4b1a927e
AM
3622 p = frag_more (nbytes);
3623 memset (p, 0, nbytes);
c19d1205 3624 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3625 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3626 free (save_buf);
c19d1205
ZW
3627 }
3628 }
3629 }
b99bd4ef 3630 }
c19d1205 3631 while (*input_line_pointer++ == ',');
b99bd4ef 3632
c19d1205
ZW
3633 /* Put terminator back into stream. */
3634 input_line_pointer --;
3635 demand_empty_rest_of_line ();
b99bd4ef
NC
3636}
3637
c921be7d
NC
3638/* Emit an expression containing a 32-bit thumb instruction.
3639 Implementation based on put_thumb32_insn. */
3640
3641static void
3642emit_thumb32_expr (expressionS * exp)
3643{
3644 expressionS exp_high = *exp;
3645
3646 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3647 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3648 exp->X_add_number &= 0xffff;
3649 emit_expr (exp, (unsigned int) THUMB_SIZE);
3650}
3651
3652/* Guess the instruction size based on the opcode. */
3653
3654static int
3655thumb_insn_size (int opcode)
3656{
3657 if ((unsigned int) opcode < 0xe800u)
3658 return 2;
3659 else if ((unsigned int) opcode >= 0xe8000000u)
3660 return 4;
3661 else
3662 return 0;
3663}
3664
3665static bfd_boolean
3666emit_insn (expressionS *exp, int nbytes)
3667{
3668 int size = 0;
3669
3670 if (exp->X_op == O_constant)
3671 {
3672 size = nbytes;
3673
3674 if (size == 0)
3675 size = thumb_insn_size (exp->X_add_number);
3676
3677 if (size != 0)
3678 {
3679 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3680 {
3681 as_bad (_(".inst.n operand too big. "\
3682 "Use .inst.w instead"));
3683 size = 0;
3684 }
3685 else
3686 {
3687 if (now_it.state == AUTOMATIC_IT_BLOCK)
3688 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3689 else
3690 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3691
3692 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3693 emit_thumb32_expr (exp);
3694 else
3695 emit_expr (exp, (unsigned int) size);
3696
3697 it_fsm_post_encode ();
3698 }
3699 }
3700 else
3701 as_bad (_("cannot determine Thumb instruction size. " \
3702 "Use .inst.n/.inst.w instead"));
3703 }
3704 else
3705 as_bad (_("constant expression required"));
3706
3707 return (size != 0);
3708}
3709
3710/* Like s_arm_elf_cons but do not use md_cons_align and
3711 set the mapping state to MAP_ARM/MAP_THUMB. */
3712
3713static void
3714s_arm_elf_inst (int nbytes)
3715{
3716 if (is_it_end_of_statement ())
3717 {
3718 demand_empty_rest_of_line ();
3719 return;
3720 }
3721
3722 /* Calling mapping_state () here will not change ARM/THUMB,
3723 but will ensure not to be in DATA state. */
3724
3725 if (thumb_mode)
3726 mapping_state (MAP_THUMB);
3727 else
3728 {
3729 if (nbytes != 0)
3730 {
3731 as_bad (_("width suffixes are invalid in ARM mode"));
3732 ignore_rest_of_line ();
3733 return;
3734 }
3735
3736 nbytes = 4;
3737
3738 mapping_state (MAP_ARM);
3739 }
3740
3741 do
3742 {
3743 expressionS exp;
3744
3745 expression (& exp);
3746
3747 if (! emit_insn (& exp, nbytes))
3748 {
3749 ignore_rest_of_line ();
3750 return;
3751 }
3752 }
3753 while (*input_line_pointer++ == ',');
3754
3755 /* Put terminator back into stream. */
3756 input_line_pointer --;
3757 demand_empty_rest_of_line ();
3758}
b99bd4ef 3759
c19d1205 3760/* Parse a .rel31 directive. */
b99bd4ef 3761
c19d1205
ZW
3762static void
3763s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3764{
3765 expressionS exp;
3766 char *p;
3767 valueT highbit;
b99bd4ef 3768
c19d1205
ZW
3769 highbit = 0;
3770 if (*input_line_pointer == '1')
3771 highbit = 0x80000000;
3772 else if (*input_line_pointer != '0')
3773 as_bad (_("expected 0 or 1"));
b99bd4ef 3774
c19d1205
ZW
3775 input_line_pointer++;
3776 if (*input_line_pointer != ',')
3777 as_bad (_("missing comma"));
3778 input_line_pointer++;
b99bd4ef 3779
c19d1205
ZW
3780#ifdef md_flush_pending_output
3781 md_flush_pending_output ();
3782#endif
b99bd4ef 3783
c19d1205
ZW
3784#ifdef md_cons_align
3785 md_cons_align (4);
3786#endif
b99bd4ef 3787
c19d1205 3788 mapping_state (MAP_DATA);
b99bd4ef 3789
c19d1205 3790 expression (&exp);
b99bd4ef 3791
c19d1205
ZW
3792 p = frag_more (4);
3793 md_number_to_chars (p, highbit, 4);
3794 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3795 BFD_RELOC_ARM_PREL31);
b99bd4ef 3796
c19d1205 3797 demand_empty_rest_of_line ();
b99bd4ef
NC
3798}
3799
c19d1205 3800/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3801
c19d1205 3802/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3803
c19d1205
ZW
3804static void
3805s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3806{
3807 demand_empty_rest_of_line ();
921e5f0a
PB
3808 if (unwind.proc_start)
3809 {
c921be7d 3810 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3811 return;
3812 }
3813
c19d1205
ZW
3814 /* Mark the start of the function. */
3815 unwind.proc_start = expr_build_dot ();
b99bd4ef 3816
c19d1205
ZW
3817 /* Reset the rest of the unwind info. */
3818 unwind.opcode_count = 0;
3819 unwind.table_entry = NULL;
3820 unwind.personality_routine = NULL;
3821 unwind.personality_index = -1;
3822 unwind.frame_size = 0;
3823 unwind.fp_offset = 0;
fdfde340 3824 unwind.fp_reg = REG_SP;
c19d1205
ZW
3825 unwind.fp_used = 0;
3826 unwind.sp_restored = 0;
3827}
b99bd4ef 3828
b99bd4ef 3829
c19d1205
ZW
3830/* Parse a handlerdata directive. Creates the exception handling table entry
3831 for the function. */
b99bd4ef 3832
c19d1205
ZW
3833static void
3834s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3835{
3836 demand_empty_rest_of_line ();
921e5f0a 3837 if (!unwind.proc_start)
c921be7d 3838 as_bad (MISSING_FNSTART);
921e5f0a 3839
c19d1205 3840 if (unwind.table_entry)
6decc662 3841 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3842
c19d1205
ZW
3843 create_unwind_entry (1);
3844}
a737bd4d 3845
c19d1205 3846/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3847
c19d1205
ZW
3848static void
3849s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3850{
3851 long where;
3852 char *ptr;
3853 valueT val;
940b5ce0 3854 unsigned int marked_pr_dependency;
f02232aa 3855
c19d1205 3856 demand_empty_rest_of_line ();
f02232aa 3857
921e5f0a
PB
3858 if (!unwind.proc_start)
3859 {
c921be7d 3860 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3861 return;
3862 }
3863
c19d1205
ZW
3864 /* Add eh table entry. */
3865 if (unwind.table_entry == NULL)
3866 val = create_unwind_entry (0);
3867 else
3868 val = 0;
f02232aa 3869
c19d1205
ZW
3870 /* Add index table entry. This is two words. */
3871 start_unwind_section (unwind.saved_seg, 1);
3872 frag_align (2, 0, 0);
3873 record_alignment (now_seg, 2);
b99bd4ef 3874
c19d1205 3875 ptr = frag_more (8);
5011093d 3876 memset (ptr, 0, 8);
c19d1205 3877 where = frag_now_fix () - 8;
f02232aa 3878
c19d1205
ZW
3879 /* Self relative offset of the function start. */
3880 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3881 BFD_RELOC_ARM_PREL31);
f02232aa 3882
c19d1205
ZW
3883 /* Indicate dependency on EHABI-defined personality routines to the
3884 linker, if it hasn't been done already. */
940b5ce0
DJ
3885 marked_pr_dependency
3886 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3887 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3888 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3889 {
5f4273c7
NC
3890 static const char *const name[] =
3891 {
3892 "__aeabi_unwind_cpp_pr0",
3893 "__aeabi_unwind_cpp_pr1",
3894 "__aeabi_unwind_cpp_pr2"
3895 };
c19d1205
ZW
3896 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3897 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3898 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3899 |= 1 << unwind.personality_index;
c19d1205 3900 }
f02232aa 3901
c19d1205
ZW
3902 if (val)
3903 /* Inline exception table entry. */
3904 md_number_to_chars (ptr + 4, val, 4);
3905 else
3906 /* Self relative offset of the table entry. */
3907 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3908 BFD_RELOC_ARM_PREL31);
f02232aa 3909
c19d1205
ZW
3910 /* Restore the original section. */
3911 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3912
3913 unwind.proc_start = NULL;
c19d1205 3914}
f02232aa 3915
f02232aa 3916
c19d1205 3917/* Parse an unwind_cantunwind directive. */
b99bd4ef 3918
c19d1205
ZW
3919static void
3920s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3921{
3922 demand_empty_rest_of_line ();
921e5f0a 3923 if (!unwind.proc_start)
c921be7d 3924 as_bad (MISSING_FNSTART);
921e5f0a 3925
c19d1205
ZW
3926 if (unwind.personality_routine || unwind.personality_index != -1)
3927 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3928
c19d1205
ZW
3929 unwind.personality_index = -2;
3930}
b99bd4ef 3931
b99bd4ef 3932
c19d1205 3933/* Parse a personalityindex directive. */
b99bd4ef 3934
c19d1205
ZW
3935static void
3936s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3937{
3938 expressionS exp;
b99bd4ef 3939
921e5f0a 3940 if (!unwind.proc_start)
c921be7d 3941 as_bad (MISSING_FNSTART);
921e5f0a 3942
c19d1205
ZW
3943 if (unwind.personality_routine || unwind.personality_index != -1)
3944 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3945
c19d1205 3946 expression (&exp);
b99bd4ef 3947
c19d1205
ZW
3948 if (exp.X_op != O_constant
3949 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3950 {
c19d1205
ZW
3951 as_bad (_("bad personality routine number"));
3952 ignore_rest_of_line ();
3953 return;
b99bd4ef
NC
3954 }
3955
c19d1205 3956 unwind.personality_index = exp.X_add_number;
b99bd4ef 3957
c19d1205
ZW
3958 demand_empty_rest_of_line ();
3959}
e16bb312 3960
e16bb312 3961
c19d1205 3962/* Parse a personality directive. */
e16bb312 3963
c19d1205
ZW
3964static void
3965s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3966{
3967 char *name, *p, c;
a737bd4d 3968
921e5f0a 3969 if (!unwind.proc_start)
c921be7d 3970 as_bad (MISSING_FNSTART);
921e5f0a 3971
c19d1205
ZW
3972 if (unwind.personality_routine || unwind.personality_index != -1)
3973 as_bad (_("duplicate .personality directive"));
a737bd4d 3974
d02603dc 3975 c = get_symbol_name (& name);
c19d1205 3976 p = input_line_pointer;
d02603dc
NC
3977 if (c == '"')
3978 ++ input_line_pointer;
c19d1205
ZW
3979 unwind.personality_routine = symbol_find_or_make (name);
3980 *p = c;
3981 demand_empty_rest_of_line ();
3982}
e16bb312 3983
e16bb312 3984
c19d1205 3985/* Parse a directive saving core registers. */
e16bb312 3986
c19d1205
ZW
3987static void
3988s_arm_unwind_save_core (void)
e16bb312 3989{
c19d1205
ZW
3990 valueT op;
3991 long range;
3992 int n;
e16bb312 3993
c19d1205
ZW
3994 range = parse_reg_list (&input_line_pointer);
3995 if (range == FAIL)
e16bb312 3996 {
c19d1205
ZW
3997 as_bad (_("expected register list"));
3998 ignore_rest_of_line ();
3999 return;
4000 }
e16bb312 4001
c19d1205 4002 demand_empty_rest_of_line ();
e16bb312 4003
c19d1205
ZW
4004 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4005 into .unwind_save {..., sp...}. We aren't bothered about the value of
4006 ip because it is clobbered by calls. */
4007 if (unwind.sp_restored && unwind.fp_reg == 12
4008 && (range & 0x3000) == 0x1000)
4009 {
4010 unwind.opcode_count--;
4011 unwind.sp_restored = 0;
4012 range = (range | 0x2000) & ~0x1000;
4013 unwind.pending_offset = 0;
4014 }
e16bb312 4015
01ae4198
DJ
4016 /* Pop r4-r15. */
4017 if (range & 0xfff0)
c19d1205 4018 {
01ae4198
DJ
4019 /* See if we can use the short opcodes. These pop a block of up to 8
4020 registers starting with r4, plus maybe r14. */
4021 for (n = 0; n < 8; n++)
4022 {
4023 /* Break at the first non-saved register. */
4024 if ((range & (1 << (n + 4))) == 0)
4025 break;
4026 }
4027 /* See if there are any other bits set. */
4028 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4029 {
4030 /* Use the long form. */
4031 op = 0x8000 | ((range >> 4) & 0xfff);
4032 add_unwind_opcode (op, 2);
4033 }
0dd132b6 4034 else
01ae4198
DJ
4035 {
4036 /* Use the short form. */
4037 if (range & 0x4000)
4038 op = 0xa8; /* Pop r14. */
4039 else
4040 op = 0xa0; /* Do not pop r14. */
4041 op |= (n - 1);
4042 add_unwind_opcode (op, 1);
4043 }
c19d1205 4044 }
0dd132b6 4045
c19d1205
ZW
4046 /* Pop r0-r3. */
4047 if (range & 0xf)
4048 {
4049 op = 0xb100 | (range & 0xf);
4050 add_unwind_opcode (op, 2);
0dd132b6
NC
4051 }
4052
c19d1205
ZW
4053 /* Record the number of bytes pushed. */
4054 for (n = 0; n < 16; n++)
4055 {
4056 if (range & (1 << n))
4057 unwind.frame_size += 4;
4058 }
0dd132b6
NC
4059}
4060
c19d1205
ZW
4061
4062/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4063
4064static void
c19d1205 4065s_arm_unwind_save_fpa (int reg)
b99bd4ef 4066{
c19d1205
ZW
4067 expressionS exp;
4068 int num_regs;
4069 valueT op;
b99bd4ef 4070
c19d1205
ZW
4071 /* Get Number of registers to transfer. */
4072 if (skip_past_comma (&input_line_pointer) != FAIL)
4073 expression (&exp);
4074 else
4075 exp.X_op = O_illegal;
b99bd4ef 4076
c19d1205 4077 if (exp.X_op != O_constant)
b99bd4ef 4078 {
c19d1205
ZW
4079 as_bad (_("expected , <constant>"));
4080 ignore_rest_of_line ();
b99bd4ef
NC
4081 return;
4082 }
4083
c19d1205
ZW
4084 num_regs = exp.X_add_number;
4085
4086 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4087 {
c19d1205
ZW
4088 as_bad (_("number of registers must be in the range [1:4]"));
4089 ignore_rest_of_line ();
b99bd4ef
NC
4090 return;
4091 }
4092
c19d1205 4093 demand_empty_rest_of_line ();
b99bd4ef 4094
c19d1205
ZW
4095 if (reg == 4)
4096 {
4097 /* Short form. */
4098 op = 0xb4 | (num_regs - 1);
4099 add_unwind_opcode (op, 1);
4100 }
b99bd4ef
NC
4101 else
4102 {
c19d1205
ZW
4103 /* Long form. */
4104 op = 0xc800 | (reg << 4) | (num_regs - 1);
4105 add_unwind_opcode (op, 2);
b99bd4ef 4106 }
c19d1205 4107 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4108}
4109
c19d1205 4110
fa073d69
MS
4111/* Parse a directive saving VFP registers for ARMv6 and above. */
4112
4113static void
4114s_arm_unwind_save_vfp_armv6 (void)
4115{
4116 int count;
4117 unsigned int start;
4118 valueT op;
4119 int num_vfpv3_regs = 0;
4120 int num_regs_below_16;
4121
4122 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4123 if (count == FAIL)
4124 {
4125 as_bad (_("expected register list"));
4126 ignore_rest_of_line ();
4127 return;
4128 }
4129
4130 demand_empty_rest_of_line ();
4131
4132 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4133 than FSTMX/FLDMX-style ones). */
4134
4135 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4136 if (start >= 16)
4137 num_vfpv3_regs = count;
4138 else if (start + count > 16)
4139 num_vfpv3_regs = start + count - 16;
4140
4141 if (num_vfpv3_regs > 0)
4142 {
4143 int start_offset = start > 16 ? start - 16 : 0;
4144 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4145 add_unwind_opcode (op, 2);
4146 }
4147
4148 /* Generate opcode for registers numbered in the range 0 .. 15. */
4149 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4150 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4151 if (num_regs_below_16 > 0)
4152 {
4153 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4154 add_unwind_opcode (op, 2);
4155 }
4156
4157 unwind.frame_size += count * 8;
4158}
4159
4160
4161/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4162
4163static void
c19d1205 4164s_arm_unwind_save_vfp (void)
b99bd4ef 4165{
c19d1205 4166 int count;
ca3f61f7 4167 unsigned int reg;
c19d1205 4168 valueT op;
b99bd4ef 4169
5287ad62 4170 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4171 if (count == FAIL)
b99bd4ef 4172 {
c19d1205
ZW
4173 as_bad (_("expected register list"));
4174 ignore_rest_of_line ();
b99bd4ef
NC
4175 return;
4176 }
4177
c19d1205 4178 demand_empty_rest_of_line ();
b99bd4ef 4179
c19d1205 4180 if (reg == 8)
b99bd4ef 4181 {
c19d1205
ZW
4182 /* Short form. */
4183 op = 0xb8 | (count - 1);
4184 add_unwind_opcode (op, 1);
b99bd4ef 4185 }
c19d1205 4186 else
b99bd4ef 4187 {
c19d1205
ZW
4188 /* Long form. */
4189 op = 0xb300 | (reg << 4) | (count - 1);
4190 add_unwind_opcode (op, 2);
b99bd4ef 4191 }
c19d1205
ZW
4192 unwind.frame_size += count * 8 + 4;
4193}
b99bd4ef 4194
b99bd4ef 4195
c19d1205
ZW
4196/* Parse a directive saving iWMMXt data registers. */
4197
4198static void
4199s_arm_unwind_save_mmxwr (void)
4200{
4201 int reg;
4202 int hi_reg;
4203 int i;
4204 unsigned mask = 0;
4205 valueT op;
b99bd4ef 4206
c19d1205
ZW
4207 if (*input_line_pointer == '{')
4208 input_line_pointer++;
b99bd4ef 4209
c19d1205 4210 do
b99bd4ef 4211 {
dcbf9037 4212 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4213
c19d1205 4214 if (reg == FAIL)
b99bd4ef 4215 {
9b7132d3 4216 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4217 goto error;
b99bd4ef
NC
4218 }
4219
c19d1205
ZW
4220 if (mask >> reg)
4221 as_tsktsk (_("register list not in ascending order"));
4222 mask |= 1 << reg;
b99bd4ef 4223
c19d1205
ZW
4224 if (*input_line_pointer == '-')
4225 {
4226 input_line_pointer++;
dcbf9037 4227 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4228 if (hi_reg == FAIL)
4229 {
9b7132d3 4230 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4231 goto error;
4232 }
4233 else if (reg >= hi_reg)
4234 {
4235 as_bad (_("bad register range"));
4236 goto error;
4237 }
4238 for (; reg < hi_reg; reg++)
4239 mask |= 1 << reg;
4240 }
4241 }
4242 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4243
d996d970 4244 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4245
c19d1205 4246 demand_empty_rest_of_line ();
b99bd4ef 4247
708587a4 4248 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4249 the list. */
4250 flush_pending_unwind ();
b99bd4ef 4251
c19d1205 4252 for (i = 0; i < 16; i++)
b99bd4ef 4253 {
c19d1205
ZW
4254 if (mask & (1 << i))
4255 unwind.frame_size += 8;
b99bd4ef
NC
4256 }
4257
c19d1205
ZW
4258 /* Attempt to combine with a previous opcode. We do this because gcc
4259 likes to output separate unwind directives for a single block of
4260 registers. */
4261 if (unwind.opcode_count > 0)
b99bd4ef 4262 {
c19d1205
ZW
4263 i = unwind.opcodes[unwind.opcode_count - 1];
4264 if ((i & 0xf8) == 0xc0)
4265 {
4266 i &= 7;
4267 /* Only merge if the blocks are contiguous. */
4268 if (i < 6)
4269 {
4270 if ((mask & 0xfe00) == (1 << 9))
4271 {
4272 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4273 unwind.opcode_count--;
4274 }
4275 }
4276 else if (i == 6 && unwind.opcode_count >= 2)
4277 {
4278 i = unwind.opcodes[unwind.opcode_count - 2];
4279 reg = i >> 4;
4280 i &= 0xf;
b99bd4ef 4281
c19d1205
ZW
4282 op = 0xffff << (reg - 1);
4283 if (reg > 0
87a1fd79 4284 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4285 {
4286 op = (1 << (reg + i + 1)) - 1;
4287 op &= ~((1 << reg) - 1);
4288 mask |= op;
4289 unwind.opcode_count -= 2;
4290 }
4291 }
4292 }
b99bd4ef
NC
4293 }
4294
c19d1205
ZW
4295 hi_reg = 15;
4296 /* We want to generate opcodes in the order the registers have been
4297 saved, ie. descending order. */
4298 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4299 {
c19d1205
ZW
4300 /* Save registers in blocks. */
4301 if (reg < 0
4302 || !(mask & (1 << reg)))
4303 {
4304 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4305 preceding block. */
c19d1205
ZW
4306 if (reg != hi_reg)
4307 {
4308 if (reg == 9)
4309 {
4310 /* Short form. */
4311 op = 0xc0 | (hi_reg - 10);
4312 add_unwind_opcode (op, 1);
4313 }
4314 else
4315 {
4316 /* Long form. */
4317 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4318 add_unwind_opcode (op, 2);
4319 }
4320 }
4321 hi_reg = reg - 1;
4322 }
b99bd4ef
NC
4323 }
4324
c19d1205
ZW
4325 return;
4326error:
4327 ignore_rest_of_line ();
b99bd4ef
NC
4328}
4329
4330static void
c19d1205 4331s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4332{
c19d1205
ZW
4333 int reg;
4334 int hi_reg;
4335 unsigned mask = 0;
4336 valueT op;
b99bd4ef 4337
c19d1205
ZW
4338 if (*input_line_pointer == '{')
4339 input_line_pointer++;
b99bd4ef 4340
477330fc
RM
4341 skip_whitespace (input_line_pointer);
4342
c19d1205 4343 do
b99bd4ef 4344 {
dcbf9037 4345 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4346
c19d1205
ZW
4347 if (reg == FAIL)
4348 {
9b7132d3 4349 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4350 goto error;
4351 }
b99bd4ef 4352
c19d1205
ZW
4353 reg -= 8;
4354 if (mask >> reg)
4355 as_tsktsk (_("register list not in ascending order"));
4356 mask |= 1 << reg;
b99bd4ef 4357
c19d1205
ZW
4358 if (*input_line_pointer == '-')
4359 {
4360 input_line_pointer++;
dcbf9037 4361 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4362 if (hi_reg == FAIL)
4363 {
9b7132d3 4364 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4365 goto error;
4366 }
4367 else if (reg >= hi_reg)
4368 {
4369 as_bad (_("bad register range"));
4370 goto error;
4371 }
4372 for (; reg < hi_reg; reg++)
4373 mask |= 1 << reg;
4374 }
b99bd4ef 4375 }
c19d1205 4376 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4377
d996d970 4378 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4379
c19d1205
ZW
4380 demand_empty_rest_of_line ();
4381
708587a4 4382 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4383 the list. */
4384 flush_pending_unwind ();
b99bd4ef 4385
c19d1205 4386 for (reg = 0; reg < 16; reg++)
b99bd4ef 4387 {
c19d1205
ZW
4388 if (mask & (1 << reg))
4389 unwind.frame_size += 4;
b99bd4ef 4390 }
c19d1205
ZW
4391 op = 0xc700 | mask;
4392 add_unwind_opcode (op, 2);
4393 return;
4394error:
4395 ignore_rest_of_line ();
b99bd4ef
NC
4396}
4397
c19d1205 4398
fa073d69
MS
4399/* Parse an unwind_save directive.
4400 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4401
b99bd4ef 4402static void
fa073d69 4403s_arm_unwind_save (int arch_v6)
b99bd4ef 4404{
c19d1205
ZW
4405 char *peek;
4406 struct reg_entry *reg;
4407 bfd_boolean had_brace = FALSE;
b99bd4ef 4408
921e5f0a 4409 if (!unwind.proc_start)
c921be7d 4410 as_bad (MISSING_FNSTART);
921e5f0a 4411
c19d1205
ZW
4412 /* Figure out what sort of save we have. */
4413 peek = input_line_pointer;
b99bd4ef 4414
c19d1205 4415 if (*peek == '{')
b99bd4ef 4416 {
c19d1205
ZW
4417 had_brace = TRUE;
4418 peek++;
b99bd4ef
NC
4419 }
4420
c19d1205 4421 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4422
c19d1205 4423 if (!reg)
b99bd4ef 4424 {
c19d1205
ZW
4425 as_bad (_("register expected"));
4426 ignore_rest_of_line ();
b99bd4ef
NC
4427 return;
4428 }
4429
c19d1205 4430 switch (reg->type)
b99bd4ef 4431 {
c19d1205
ZW
4432 case REG_TYPE_FN:
4433 if (had_brace)
4434 {
4435 as_bad (_("FPA .unwind_save does not take a register list"));
4436 ignore_rest_of_line ();
4437 return;
4438 }
93ac2687 4439 input_line_pointer = peek;
c19d1205 4440 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4441 return;
c19d1205 4442
1f5afe1c
NC
4443 case REG_TYPE_RN:
4444 s_arm_unwind_save_core ();
4445 return;
4446
fa073d69
MS
4447 case REG_TYPE_VFD:
4448 if (arch_v6)
477330fc 4449 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4450 else
477330fc 4451 s_arm_unwind_save_vfp ();
fa073d69 4452 return;
1f5afe1c
NC
4453
4454 case REG_TYPE_MMXWR:
4455 s_arm_unwind_save_mmxwr ();
4456 return;
4457
4458 case REG_TYPE_MMXWCG:
4459 s_arm_unwind_save_mmxwcg ();
4460 return;
c19d1205
ZW
4461
4462 default:
4463 as_bad (_(".unwind_save does not support this kind of register"));
4464 ignore_rest_of_line ();
b99bd4ef 4465 }
c19d1205 4466}
b99bd4ef 4467
b99bd4ef 4468
c19d1205
ZW
4469/* Parse an unwind_movsp directive. */
4470
4471static void
4472s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4473{
4474 int reg;
4475 valueT op;
4fa3602b 4476 int offset;
c19d1205 4477
921e5f0a 4478 if (!unwind.proc_start)
c921be7d 4479 as_bad (MISSING_FNSTART);
921e5f0a 4480
dcbf9037 4481 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4482 if (reg == FAIL)
b99bd4ef 4483 {
9b7132d3 4484 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4485 ignore_rest_of_line ();
b99bd4ef
NC
4486 return;
4487 }
4fa3602b
PB
4488
4489 /* Optional constant. */
4490 if (skip_past_comma (&input_line_pointer) != FAIL)
4491 {
4492 if (immediate_for_directive (&offset) == FAIL)
4493 return;
4494 }
4495 else
4496 offset = 0;
4497
c19d1205 4498 demand_empty_rest_of_line ();
b99bd4ef 4499
c19d1205 4500 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4501 {
c19d1205 4502 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4503 return;
4504 }
4505
c19d1205
ZW
4506 if (unwind.fp_reg != REG_SP)
4507 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4508
c19d1205
ZW
4509 /* Generate opcode to restore the value. */
4510 op = 0x90 | reg;
4511 add_unwind_opcode (op, 1);
4512
4513 /* Record the information for later. */
4514 unwind.fp_reg = reg;
4fa3602b 4515 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4516 unwind.sp_restored = 1;
b05fe5cf
ZW
4517}
4518
c19d1205
ZW
4519/* Parse an unwind_pad directive. */
4520
b05fe5cf 4521static void
c19d1205 4522s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4523{
c19d1205 4524 int offset;
b05fe5cf 4525
921e5f0a 4526 if (!unwind.proc_start)
c921be7d 4527 as_bad (MISSING_FNSTART);
921e5f0a 4528
c19d1205
ZW
4529 if (immediate_for_directive (&offset) == FAIL)
4530 return;
b99bd4ef 4531
c19d1205
ZW
4532 if (offset & 3)
4533 {
4534 as_bad (_("stack increment must be multiple of 4"));
4535 ignore_rest_of_line ();
4536 return;
4537 }
b99bd4ef 4538
c19d1205
ZW
4539 /* Don't generate any opcodes, just record the details for later. */
4540 unwind.frame_size += offset;
4541 unwind.pending_offset += offset;
4542
4543 demand_empty_rest_of_line ();
4544}
4545
4546/* Parse an unwind_setfp directive. */
4547
4548static void
4549s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4550{
c19d1205
ZW
4551 int sp_reg;
4552 int fp_reg;
4553 int offset;
4554
921e5f0a 4555 if (!unwind.proc_start)
c921be7d 4556 as_bad (MISSING_FNSTART);
921e5f0a 4557
dcbf9037 4558 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4559 if (skip_past_comma (&input_line_pointer) == FAIL)
4560 sp_reg = FAIL;
4561 else
dcbf9037 4562 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4563
c19d1205
ZW
4564 if (fp_reg == FAIL || sp_reg == FAIL)
4565 {
4566 as_bad (_("expected <reg>, <reg>"));
4567 ignore_rest_of_line ();
4568 return;
4569 }
b99bd4ef 4570
c19d1205
ZW
4571 /* Optional constant. */
4572 if (skip_past_comma (&input_line_pointer) != FAIL)
4573 {
4574 if (immediate_for_directive (&offset) == FAIL)
4575 return;
4576 }
4577 else
4578 offset = 0;
a737bd4d 4579
c19d1205 4580 demand_empty_rest_of_line ();
a737bd4d 4581
fdfde340 4582 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4583 {
c19d1205
ZW
4584 as_bad (_("register must be either sp or set by a previous"
4585 "unwind_movsp directive"));
4586 return;
a737bd4d
NC
4587 }
4588
c19d1205
ZW
4589 /* Don't generate any opcodes, just record the information for later. */
4590 unwind.fp_reg = fp_reg;
4591 unwind.fp_used = 1;
fdfde340 4592 if (sp_reg == REG_SP)
c19d1205
ZW
4593 unwind.fp_offset = unwind.frame_size - offset;
4594 else
4595 unwind.fp_offset -= offset;
a737bd4d
NC
4596}
4597
c19d1205
ZW
4598/* Parse an unwind_raw directive. */
4599
4600static void
4601s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4602{
c19d1205 4603 expressionS exp;
708587a4 4604 /* This is an arbitrary limit. */
c19d1205
ZW
4605 unsigned char op[16];
4606 int count;
a737bd4d 4607
921e5f0a 4608 if (!unwind.proc_start)
c921be7d 4609 as_bad (MISSING_FNSTART);
921e5f0a 4610
c19d1205
ZW
4611 expression (&exp);
4612 if (exp.X_op == O_constant
4613 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4614 {
c19d1205
ZW
4615 unwind.frame_size += exp.X_add_number;
4616 expression (&exp);
4617 }
4618 else
4619 exp.X_op = O_illegal;
a737bd4d 4620
c19d1205
ZW
4621 if (exp.X_op != O_constant)
4622 {
4623 as_bad (_("expected <offset>, <opcode>"));
4624 ignore_rest_of_line ();
4625 return;
4626 }
a737bd4d 4627
c19d1205 4628 count = 0;
a737bd4d 4629
c19d1205
ZW
4630 /* Parse the opcode. */
4631 for (;;)
4632 {
4633 if (count >= 16)
4634 {
4635 as_bad (_("unwind opcode too long"));
4636 ignore_rest_of_line ();
a737bd4d 4637 }
c19d1205 4638 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4639 {
c19d1205
ZW
4640 as_bad (_("invalid unwind opcode"));
4641 ignore_rest_of_line ();
4642 return;
a737bd4d 4643 }
c19d1205 4644 op[count++] = exp.X_add_number;
a737bd4d 4645
c19d1205
ZW
4646 /* Parse the next byte. */
4647 if (skip_past_comma (&input_line_pointer) == FAIL)
4648 break;
a737bd4d 4649
c19d1205
ZW
4650 expression (&exp);
4651 }
b99bd4ef 4652
c19d1205
ZW
4653 /* Add the opcode bytes in reverse order. */
4654 while (count--)
4655 add_unwind_opcode (op[count], 1);
b99bd4ef 4656
c19d1205 4657 demand_empty_rest_of_line ();
b99bd4ef 4658}
ee065d83
PB
4659
4660
4661/* Parse a .eabi_attribute directive. */
4662
4663static void
4664s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4665{
0420f52b 4666 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4667
4668 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4669 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4670}
4671
0855e32b
NS
4672/* Emit a tls fix for the symbol. */
4673
4674static void
4675s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4676{
4677 char *p;
4678 expressionS exp;
4679#ifdef md_flush_pending_output
4680 md_flush_pending_output ();
4681#endif
4682
4683#ifdef md_cons_align
4684 md_cons_align (4);
4685#endif
4686
4687 /* Since we're just labelling the code, there's no need to define a
4688 mapping symbol. */
4689 expression (&exp);
4690 p = obstack_next_free (&frchain_now->frch_obstack);
4691 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4692 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4693 : BFD_RELOC_ARM_TLS_DESCSEQ);
4694}
cdf9ccec 4695#endif /* OBJ_ELF */
0855e32b 4696
ee065d83 4697static void s_arm_arch (int);
7a1d4c38 4698static void s_arm_object_arch (int);
ee065d83
PB
4699static void s_arm_cpu (int);
4700static void s_arm_fpu (int);
69133863 4701static void s_arm_arch_extension (int);
b99bd4ef 4702
f0927246
NC
4703#ifdef TE_PE
4704
4705static void
5f4273c7 4706pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4707{
4708 expressionS exp;
4709
4710 do
4711 {
4712 expression (&exp);
4713 if (exp.X_op == O_symbol)
4714 exp.X_op = O_secrel;
4715
4716 emit_expr (&exp, 4);
4717 }
4718 while (*input_line_pointer++ == ',');
4719
4720 input_line_pointer--;
4721 demand_empty_rest_of_line ();
4722}
4723#endif /* TE_PE */
4724
c19d1205
ZW
4725/* This table describes all the machine specific pseudo-ops the assembler
4726 has to support. The fields are:
4727 pseudo-op name without dot
4728 function to call to execute this pseudo-op
4729 Integer arg to pass to the function. */
b99bd4ef 4730
c19d1205 4731const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4732{
c19d1205
ZW
4733 /* Never called because '.req' does not start a line. */
4734 { "req", s_req, 0 },
dcbf9037
JB
4735 /* Following two are likewise never called. */
4736 { "dn", s_dn, 0 },
4737 { "qn", s_qn, 0 },
c19d1205
ZW
4738 { "unreq", s_unreq, 0 },
4739 { "bss", s_bss, 0 },
db2ed2e0 4740 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4741 { "arm", s_arm, 0 },
4742 { "thumb", s_thumb, 0 },
4743 { "code", s_code, 0 },
4744 { "force_thumb", s_force_thumb, 0 },
4745 { "thumb_func", s_thumb_func, 0 },
4746 { "thumb_set", s_thumb_set, 0 },
4747 { "even", s_even, 0 },
4748 { "ltorg", s_ltorg, 0 },
4749 { "pool", s_ltorg, 0 },
4750 { "syntax", s_syntax, 0 },
8463be01
PB
4751 { "cpu", s_arm_cpu, 0 },
4752 { "arch", s_arm_arch, 0 },
7a1d4c38 4753 { "object_arch", s_arm_object_arch, 0 },
8463be01 4754 { "fpu", s_arm_fpu, 0 },
69133863 4755 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4756#ifdef OBJ_ELF
c921be7d
NC
4757 { "word", s_arm_elf_cons, 4 },
4758 { "long", s_arm_elf_cons, 4 },
4759 { "inst.n", s_arm_elf_inst, 2 },
4760 { "inst.w", s_arm_elf_inst, 4 },
4761 { "inst", s_arm_elf_inst, 0 },
4762 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4763 { "fnstart", s_arm_unwind_fnstart, 0 },
4764 { "fnend", s_arm_unwind_fnend, 0 },
4765 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4766 { "personality", s_arm_unwind_personality, 0 },
4767 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4768 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4769 { "save", s_arm_unwind_save, 0 },
fa073d69 4770 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4771 { "movsp", s_arm_unwind_movsp, 0 },
4772 { "pad", s_arm_unwind_pad, 0 },
4773 { "setfp", s_arm_unwind_setfp, 0 },
4774 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4775 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4776 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4777#else
4778 { "word", cons, 4},
f0927246
NC
4779
4780 /* These are used for dwarf. */
4781 {"2byte", cons, 2},
4782 {"4byte", cons, 4},
4783 {"8byte", cons, 8},
4784 /* These are used for dwarf2. */
68d20676 4785 { "file", dwarf2_directive_file, 0 },
f0927246
NC
4786 { "loc", dwarf2_directive_loc, 0 },
4787 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4788#endif
4789 { "extend", float_cons, 'x' },
4790 { "ldouble", float_cons, 'x' },
4791 { "packed", float_cons, 'p' },
f0927246
NC
4792#ifdef TE_PE
4793 {"secrel32", pe_directive_secrel, 0},
4794#endif
2e6976a8
DG
4795
4796 /* These are for compatibility with CodeComposer Studio. */
4797 {"ref", s_ccs_ref, 0},
4798 {"def", s_ccs_def, 0},
4799 {"asmfunc", s_ccs_asmfunc, 0},
4800 {"endasmfunc", s_ccs_endasmfunc, 0},
4801
c19d1205
ZW
4802 { 0, 0, 0 }
4803};
4804\f
4805/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4806
c19d1205
ZW
4807/* Generic immediate-value read function for use in insn parsing.
4808 STR points to the beginning of the immediate (the leading #);
4809 VAL receives the value; if the value is outside [MIN, MAX]
4810 issue an error. PREFIX_OPT is true if the immediate prefix is
4811 optional. */
b99bd4ef 4812
c19d1205
ZW
4813static int
4814parse_immediate (char **str, int *val, int min, int max,
4815 bfd_boolean prefix_opt)
4816{
4817 expressionS exp;
0198d5e6 4818
c19d1205
ZW
4819 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4820 if (exp.X_op != O_constant)
b99bd4ef 4821 {
c19d1205
ZW
4822 inst.error = _("constant expression required");
4823 return FAIL;
4824 }
b99bd4ef 4825
c19d1205
ZW
4826 if (exp.X_add_number < min || exp.X_add_number > max)
4827 {
4828 inst.error = _("immediate value out of range");
4829 return FAIL;
4830 }
b99bd4ef 4831
c19d1205
ZW
4832 *val = exp.X_add_number;
4833 return SUCCESS;
4834}
b99bd4ef 4835
5287ad62 4836/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4837 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4838 instructions. Puts the result directly in inst.operands[i]. */
4839
4840static int
8335d6aa
JW
4841parse_big_immediate (char **str, int i, expressionS *in_exp,
4842 bfd_boolean allow_symbol_p)
5287ad62
JB
4843{
4844 expressionS exp;
8335d6aa 4845 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4846 char *ptr = *str;
4847
8335d6aa 4848 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4849
8335d6aa 4850 if (exp_p->X_op == O_constant)
036dc3f7 4851 {
8335d6aa 4852 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4853 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4854 O_constant. We have to be careful not to break compilation for
4855 32-bit X_add_number, though. */
8335d6aa 4856 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4857 {
8335d6aa
JW
4858 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4859 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4860 & 0xffffffff);
036dc3f7
PB
4861 inst.operands[i].regisimm = 1;
4862 }
4863 }
8335d6aa
JW
4864 else if (exp_p->X_op == O_big
4865 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4866 {
4867 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4868
5287ad62 4869 /* Bignums have their least significant bits in
477330fc
RM
4870 generic_bignum[0]. Make sure we put 32 bits in imm and
4871 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4872 gas_assert (parts != 0);
95b75c01
NC
4873
4874 /* Make sure that the number is not too big.
4875 PR 11972: Bignums can now be sign-extended to the
4876 size of a .octa so check that the out of range bits
4877 are all zero or all one. */
8335d6aa 4878 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4879 {
4880 LITTLENUM_TYPE m = -1;
4881
4882 if (generic_bignum[parts * 2] != 0
4883 && generic_bignum[parts * 2] != m)
4884 return FAIL;
4885
8335d6aa 4886 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4887 if (generic_bignum[j] != generic_bignum[j-1])
4888 return FAIL;
4889 }
4890
5287ad62
JB
4891 inst.operands[i].imm = 0;
4892 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4893 inst.operands[i].imm |= generic_bignum[idx]
4894 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4895 inst.operands[i].reg = 0;
4896 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4897 inst.operands[i].reg |= generic_bignum[idx]
4898 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4899 inst.operands[i].regisimm = 1;
4900 }
8335d6aa 4901 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4902 return FAIL;
5f4273c7 4903
5287ad62
JB
4904 *str = ptr;
4905
4906 return SUCCESS;
4907}
4908
c19d1205
ZW
4909/* Returns the pseudo-register number of an FPA immediate constant,
4910 or FAIL if there isn't a valid constant here. */
b99bd4ef 4911
c19d1205
ZW
4912static int
4913parse_fpa_immediate (char ** str)
4914{
4915 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4916 char * save_in;
4917 expressionS exp;
4918 int i;
4919 int j;
b99bd4ef 4920
c19d1205
ZW
4921 /* First try and match exact strings, this is to guarantee
4922 that some formats will work even for cross assembly. */
b99bd4ef 4923
c19d1205
ZW
4924 for (i = 0; fp_const[i]; i++)
4925 {
4926 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4927 {
c19d1205 4928 char *start = *str;
b99bd4ef 4929
c19d1205
ZW
4930 *str += strlen (fp_const[i]);
4931 if (is_end_of_line[(unsigned char) **str])
4932 return i + 8;
4933 *str = start;
4934 }
4935 }
b99bd4ef 4936
c19d1205
ZW
4937 /* Just because we didn't get a match doesn't mean that the constant
4938 isn't valid, just that it is in a format that we don't
4939 automatically recognize. Try parsing it with the standard
4940 expression routines. */
b99bd4ef 4941
c19d1205 4942 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4943
c19d1205
ZW
4944 /* Look for a raw floating point number. */
4945 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4946 && is_end_of_line[(unsigned char) *save_in])
4947 {
4948 for (i = 0; i < NUM_FLOAT_VALS; i++)
4949 {
4950 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4951 {
c19d1205
ZW
4952 if (words[j] != fp_values[i][j])
4953 break;
b99bd4ef
NC
4954 }
4955
c19d1205 4956 if (j == MAX_LITTLENUMS)
b99bd4ef 4957 {
c19d1205
ZW
4958 *str = save_in;
4959 return i + 8;
b99bd4ef
NC
4960 }
4961 }
4962 }
b99bd4ef 4963
c19d1205
ZW
4964 /* Try and parse a more complex expression, this will probably fail
4965 unless the code uses a floating point prefix (eg "0f"). */
4966 save_in = input_line_pointer;
4967 input_line_pointer = *str;
4968 if (expression (&exp) == absolute_section
4969 && exp.X_op == O_big
4970 && exp.X_add_number < 0)
4971 {
4972 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4973 Ditto for 15. */
ba592044
AM
4974#define X_PRECISION 5
4975#define E_PRECISION 15L
4976 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4977 {
4978 for (i = 0; i < NUM_FLOAT_VALS; i++)
4979 {
4980 for (j = 0; j < MAX_LITTLENUMS; j++)
4981 {
4982 if (words[j] != fp_values[i][j])
4983 break;
4984 }
b99bd4ef 4985
c19d1205
ZW
4986 if (j == MAX_LITTLENUMS)
4987 {
4988 *str = input_line_pointer;
4989 input_line_pointer = save_in;
4990 return i + 8;
4991 }
4992 }
4993 }
b99bd4ef
NC
4994 }
4995
c19d1205
ZW
4996 *str = input_line_pointer;
4997 input_line_pointer = save_in;
4998 inst.error = _("invalid FPA immediate expression");
4999 return FAIL;
b99bd4ef
NC
5000}
5001
136da414
JB
5002/* Returns 1 if a number has "quarter-precision" float format
5003 0baBbbbbbc defgh000 00000000 00000000. */
5004
5005static int
5006is_quarter_float (unsigned imm)
5007{
5008 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5009 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5010}
5011
aacf0b33
KT
5012
5013/* Detect the presence of a floating point or integer zero constant,
5014 i.e. #0.0 or #0. */
5015
5016static bfd_boolean
5017parse_ifimm_zero (char **in)
5018{
5019 int error_code;
5020
5021 if (!is_immediate_prefix (**in))
3c6452ae
TP
5022 {
5023 /* In unified syntax, all prefixes are optional. */
5024 if (!unified_syntax)
5025 return FALSE;
5026 }
5027 else
5028 ++*in;
0900a05b
JW
5029
5030 /* Accept #0x0 as a synonym for #0. */
5031 if (strncmp (*in, "0x", 2) == 0)
5032 {
5033 int val;
5034 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5035 return FALSE;
5036 return TRUE;
5037 }
5038
aacf0b33
KT
5039 error_code = atof_generic (in, ".", EXP_CHARS,
5040 &generic_floating_point_number);
5041
5042 if (!error_code
5043 && generic_floating_point_number.sign == '+'
5044 && (generic_floating_point_number.low
5045 > generic_floating_point_number.leader))
5046 return TRUE;
5047
5048 return FALSE;
5049}
5050
136da414
JB
5051/* Parse an 8-bit "quarter-precision" floating point number of the form:
5052 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5053 The zero and minus-zero cases need special handling, since they can't be
5054 encoded in the "quarter-precision" float format, but can nonetheless be
5055 loaded as integer constants. */
136da414
JB
5056
5057static unsigned
5058parse_qfloat_immediate (char **ccp, int *immed)
5059{
5060 char *str = *ccp;
c96612cc 5061 char *fpnum;
136da414 5062 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5063 int found_fpchar = 0;
5f4273c7 5064
136da414 5065 skip_past_char (&str, '#');
5f4273c7 5066
c96612cc
JB
5067 /* We must not accidentally parse an integer as a floating-point number. Make
5068 sure that the value we parse is not an integer by checking for special
5069 characters '.' or 'e'.
5070 FIXME: This is a horrible hack, but doing better is tricky because type
5071 information isn't in a very usable state at parse time. */
5072 fpnum = str;
5073 skip_whitespace (fpnum);
5074
5075 if (strncmp (fpnum, "0x", 2) == 0)
5076 return FAIL;
5077 else
5078 {
5079 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5080 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5081 {
5082 found_fpchar = 1;
5083 break;
5084 }
c96612cc
JB
5085
5086 if (!found_fpchar)
477330fc 5087 return FAIL;
c96612cc 5088 }
5f4273c7 5089
136da414
JB
5090 if ((str = atof_ieee (str, 's', words)) != NULL)
5091 {
5092 unsigned fpword = 0;
5093 int i;
5f4273c7 5094
136da414
JB
5095 /* Our FP word must be 32 bits (single-precision FP). */
5096 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5097 {
5098 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5099 fpword |= words[i];
5100 }
5f4273c7 5101
c96612cc 5102 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5103 *immed = fpword;
136da414 5104 else
477330fc 5105 return FAIL;
136da414
JB
5106
5107 *ccp = str;
5f4273c7 5108
136da414
JB
5109 return SUCCESS;
5110 }
5f4273c7 5111
136da414
JB
5112 return FAIL;
5113}
5114
c19d1205
ZW
5115/* Shift operands. */
5116enum shift_kind
b99bd4ef 5117{
c19d1205
ZW
5118 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5119};
b99bd4ef 5120
c19d1205
ZW
5121struct asm_shift_name
5122{
5123 const char *name;
5124 enum shift_kind kind;
5125};
b99bd4ef 5126
c19d1205
ZW
5127/* Third argument to parse_shift. */
5128enum parse_shift_mode
5129{
5130 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5131 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5132 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5133 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5134 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5135};
b99bd4ef 5136
c19d1205
ZW
5137/* Parse a <shift> specifier on an ARM data processing instruction.
5138 This has three forms:
b99bd4ef 5139
c19d1205
ZW
5140 (LSL|LSR|ASL|ASR|ROR) Rs
5141 (LSL|LSR|ASL|ASR|ROR) #imm
5142 RRX
b99bd4ef 5143
c19d1205
ZW
5144 Note that ASL is assimilated to LSL in the instruction encoding, and
5145 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5146
c19d1205
ZW
5147static int
5148parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5149{
c19d1205
ZW
5150 const struct asm_shift_name *shift_name;
5151 enum shift_kind shift;
5152 char *s = *str;
5153 char *p = s;
5154 int reg;
b99bd4ef 5155
c19d1205
ZW
5156 for (p = *str; ISALPHA (*p); p++)
5157 ;
b99bd4ef 5158
c19d1205 5159 if (p == *str)
b99bd4ef 5160 {
c19d1205
ZW
5161 inst.error = _("shift expression expected");
5162 return FAIL;
b99bd4ef
NC
5163 }
5164
21d799b5 5165 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5166 p - *str);
c19d1205
ZW
5167
5168 if (shift_name == NULL)
b99bd4ef 5169 {
c19d1205
ZW
5170 inst.error = _("shift expression expected");
5171 return FAIL;
b99bd4ef
NC
5172 }
5173
c19d1205 5174 shift = shift_name->kind;
b99bd4ef 5175
c19d1205
ZW
5176 switch (mode)
5177 {
5178 case NO_SHIFT_RESTRICT:
5179 case SHIFT_IMMEDIATE: break;
b99bd4ef 5180
c19d1205
ZW
5181 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5182 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5183 {
5184 inst.error = _("'LSL' or 'ASR' required");
5185 return FAIL;
5186 }
5187 break;
b99bd4ef 5188
c19d1205
ZW
5189 case SHIFT_LSL_IMMEDIATE:
5190 if (shift != SHIFT_LSL)
5191 {
5192 inst.error = _("'LSL' required");
5193 return FAIL;
5194 }
5195 break;
b99bd4ef 5196
c19d1205
ZW
5197 case SHIFT_ASR_IMMEDIATE:
5198 if (shift != SHIFT_ASR)
5199 {
5200 inst.error = _("'ASR' required");
5201 return FAIL;
5202 }
5203 break;
b99bd4ef 5204
c19d1205
ZW
5205 default: abort ();
5206 }
b99bd4ef 5207
c19d1205
ZW
5208 if (shift != SHIFT_RRX)
5209 {
5210 /* Whitespace can appear here if the next thing is a bare digit. */
5211 skip_whitespace (p);
b99bd4ef 5212
c19d1205 5213 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5214 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5215 {
5216 inst.operands[i].imm = reg;
5217 inst.operands[i].immisreg = 1;
5218 }
5219 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5220 return FAIL;
5221 }
5222 inst.operands[i].shift_kind = shift;
5223 inst.operands[i].shifted = 1;
5224 *str = p;
5225 return SUCCESS;
b99bd4ef
NC
5226}
5227
c19d1205 5228/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5229
c19d1205
ZW
5230 #<immediate>
5231 #<immediate>, <rotate>
5232 <Rm>
5233 <Rm>, <shift>
b99bd4ef 5234
c19d1205
ZW
5235 where <shift> is defined by parse_shift above, and <rotate> is a
5236 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5237 is deferred to md_apply_fix. */
b99bd4ef 5238
c19d1205
ZW
5239static int
5240parse_shifter_operand (char **str, int i)
5241{
5242 int value;
91d6fa6a 5243 expressionS exp;
b99bd4ef 5244
dcbf9037 5245 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5246 {
5247 inst.operands[i].reg = value;
5248 inst.operands[i].isreg = 1;
b99bd4ef 5249
c19d1205
ZW
5250 /* parse_shift will override this if appropriate */
5251 inst.reloc.exp.X_op = O_constant;
5252 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5253
c19d1205
ZW
5254 if (skip_past_comma (str) == FAIL)
5255 return SUCCESS;
b99bd4ef 5256
c19d1205
ZW
5257 /* Shift operation on register. */
5258 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5259 }
5260
c19d1205
ZW
5261 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5262 return FAIL;
b99bd4ef 5263
c19d1205 5264 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5265 {
c19d1205 5266 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5267 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5268 return FAIL;
b99bd4ef 5269
91d6fa6a 5270 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5271 {
5272 inst.error = _("constant expression expected");
5273 return FAIL;
5274 }
b99bd4ef 5275
91d6fa6a 5276 value = exp.X_add_number;
c19d1205
ZW
5277 if (value < 0 || value > 30 || value % 2 != 0)
5278 {
5279 inst.error = _("invalid rotation");
5280 return FAIL;
5281 }
5282 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5283 {
5284 inst.error = _("invalid constant");
5285 return FAIL;
5286 }
09d92015 5287
a415b1cd
JB
5288 /* Encode as specified. */
5289 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5290 return SUCCESS;
09d92015
MM
5291 }
5292
c19d1205
ZW
5293 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5294 inst.reloc.pc_rel = 0;
5295 return SUCCESS;
09d92015
MM
5296}
5297
4962c51a
MS
5298/* Group relocation information. Each entry in the table contains the
5299 textual name of the relocation as may appear in assembler source
5300 and must end with a colon.
5301 Along with this textual name are the relocation codes to be used if
5302 the corresponding instruction is an ALU instruction (ADD or SUB only),
5303 an LDR, an LDRS, or an LDC. */
5304
5305struct group_reloc_table_entry
5306{
5307 const char *name;
5308 int alu_code;
5309 int ldr_code;
5310 int ldrs_code;
5311 int ldc_code;
5312};
5313
5314typedef enum
5315{
5316 /* Varieties of non-ALU group relocation. */
5317
5318 GROUP_LDR,
5319 GROUP_LDRS,
5320 GROUP_LDC
5321} group_reloc_type;
5322
5323static struct group_reloc_table_entry group_reloc_table[] =
5324 { /* Program counter relative: */
5325 { "pc_g0_nc",
5326 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5327 0, /* LDR */
5328 0, /* LDRS */
5329 0 }, /* LDC */
5330 { "pc_g0",
5331 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5332 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5333 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5334 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5335 { "pc_g1_nc",
5336 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5337 0, /* LDR */
5338 0, /* LDRS */
5339 0 }, /* LDC */
5340 { "pc_g1",
5341 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5342 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5343 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5344 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5345 { "pc_g2",
5346 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5347 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5348 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5349 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5350 /* Section base relative */
5351 { "sb_g0_nc",
5352 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5353 0, /* LDR */
5354 0, /* LDRS */
5355 0 }, /* LDC */
5356 { "sb_g0",
5357 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5358 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5359 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5360 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5361 { "sb_g1_nc",
5362 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5363 0, /* LDR */
5364 0, /* LDRS */
5365 0 }, /* LDC */
5366 { "sb_g1",
5367 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5368 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5369 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5370 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5371 { "sb_g2",
5372 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5373 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5374 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5375 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5376 /* Absolute thumb alu relocations. */
5377 { "lower0_7",
5378 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5379 0, /* LDR. */
5380 0, /* LDRS. */
5381 0 }, /* LDC. */
5382 { "lower8_15",
5383 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5384 0, /* LDR. */
5385 0, /* LDRS. */
5386 0 }, /* LDC. */
5387 { "upper0_7",
5388 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5389 0, /* LDR. */
5390 0, /* LDRS. */
5391 0 }, /* LDC. */
5392 { "upper8_15",
5393 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5394 0, /* LDR. */
5395 0, /* LDRS. */
5396 0 } }; /* LDC. */
4962c51a
MS
5397
5398/* Given the address of a pointer pointing to the textual name of a group
5399 relocation as may appear in assembler source, attempt to find its details
5400 in group_reloc_table. The pointer will be updated to the character after
5401 the trailing colon. On failure, FAIL will be returned; SUCCESS
5402 otherwise. On success, *entry will be updated to point at the relevant
5403 group_reloc_table entry. */
5404
5405static int
5406find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5407{
5408 unsigned int i;
5409 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5410 {
5411 int length = strlen (group_reloc_table[i].name);
5412
5f4273c7
NC
5413 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5414 && (*str)[length] == ':')
477330fc
RM
5415 {
5416 *out = &group_reloc_table[i];
5417 *str += (length + 1);
5418 return SUCCESS;
5419 }
4962c51a
MS
5420 }
5421
5422 return FAIL;
5423}
5424
5425/* Parse a <shifter_operand> for an ARM data processing instruction
5426 (as for parse_shifter_operand) where group relocations are allowed:
5427
5428 #<immediate>
5429 #<immediate>, <rotate>
5430 #:<group_reloc>:<expression>
5431 <Rm>
5432 <Rm>, <shift>
5433
5434 where <group_reloc> is one of the strings defined in group_reloc_table.
5435 The hashes are optional.
5436
5437 Everything else is as for parse_shifter_operand. */
5438
5439static parse_operand_result
5440parse_shifter_operand_group_reloc (char **str, int i)
5441{
5442 /* Determine if we have the sequence of characters #: or just :
5443 coming next. If we do, then we check for a group relocation.
5444 If we don't, punt the whole lot to parse_shifter_operand. */
5445
5446 if (((*str)[0] == '#' && (*str)[1] == ':')
5447 || (*str)[0] == ':')
5448 {
5449 struct group_reloc_table_entry *entry;
5450
5451 if ((*str)[0] == '#')
477330fc 5452 (*str) += 2;
4962c51a 5453 else
477330fc 5454 (*str)++;
4962c51a
MS
5455
5456 /* Try to parse a group relocation. Anything else is an error. */
5457 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5458 {
5459 inst.error = _("unknown group relocation");
5460 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5461 }
4962c51a
MS
5462
5463 /* We now have the group relocation table entry corresponding to
477330fc 5464 the name in the assembler source. Next, we parse the expression. */
4962c51a 5465 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5466 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5467
5468 /* Record the relocation type (always the ALU variant here). */
21d799b5 5469 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5470 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5471
5472 return PARSE_OPERAND_SUCCESS;
5473 }
5474 else
5475 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5476 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5477
5478 /* Never reached. */
5479}
5480
8e560766
MGD
5481/* Parse a Neon alignment expression. Information is written to
5482 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5483
8e560766
MGD
5484 align .imm = align << 8, .immisalign=1, .preind=0 */
5485static parse_operand_result
5486parse_neon_alignment (char **str, int i)
5487{
5488 char *p = *str;
5489 expressionS exp;
5490
5491 my_get_expression (&exp, &p, GE_NO_PREFIX);
5492
5493 if (exp.X_op != O_constant)
5494 {
5495 inst.error = _("alignment must be constant");
5496 return PARSE_OPERAND_FAIL;
5497 }
5498
5499 inst.operands[i].imm = exp.X_add_number << 8;
5500 inst.operands[i].immisalign = 1;
5501 /* Alignments are not pre-indexes. */
5502 inst.operands[i].preind = 0;
5503
5504 *str = p;
5505 return PARSE_OPERAND_SUCCESS;
5506}
5507
c19d1205
ZW
5508/* Parse all forms of an ARM address expression. Information is written
5509 to inst.operands[i] and/or inst.reloc.
09d92015 5510
c19d1205 5511 Preindexed addressing (.preind=1):
09d92015 5512
c19d1205
ZW
5513 [Rn, #offset] .reg=Rn .reloc.exp=offset
5514 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5515 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5516 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5517
c19d1205 5518 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5519
c19d1205 5520 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5521
c19d1205
ZW
5522 [Rn], #offset .reg=Rn .reloc.exp=offset
5523 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5524 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5525 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5526
c19d1205 5527 Unindexed addressing (.preind=0, .postind=0):
09d92015 5528
c19d1205 5529 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5530
c19d1205 5531 Other:
09d92015 5532
c19d1205
ZW
5533 [Rn]{!} shorthand for [Rn,#0]{!}
5534 =immediate .isreg=0 .reloc.exp=immediate
5535 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5536
c19d1205
ZW
5537 It is the caller's responsibility to check for addressing modes not
5538 supported by the instruction, and to set inst.reloc.type. */
5539
4962c51a
MS
5540static parse_operand_result
5541parse_address_main (char **str, int i, int group_relocations,
477330fc 5542 group_reloc_type group_type)
09d92015 5543{
c19d1205
ZW
5544 char *p = *str;
5545 int reg;
09d92015 5546
c19d1205 5547 if (skip_past_char (&p, '[') == FAIL)
09d92015 5548 {
c19d1205
ZW
5549 if (skip_past_char (&p, '=') == FAIL)
5550 {
974da60d 5551 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5552 inst.reloc.pc_rel = 1;
5553 inst.operands[i].reg = REG_PC;
5554 inst.operands[i].isreg = 1;
5555 inst.operands[i].preind = 1;
09d92015 5556
8335d6aa
JW
5557 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5558 return PARSE_OPERAND_FAIL;
5559 }
5560 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5561 /*allow_symbol_p=*/TRUE))
4962c51a 5562 return PARSE_OPERAND_FAIL;
09d92015 5563
c19d1205 5564 *str = p;
4962c51a 5565 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5566 }
5567
8ab8155f
NC
5568 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5569 skip_whitespace (p);
5570
dcbf9037 5571 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5572 {
c19d1205 5573 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5574 return PARSE_OPERAND_FAIL;
09d92015 5575 }
c19d1205
ZW
5576 inst.operands[i].reg = reg;
5577 inst.operands[i].isreg = 1;
09d92015 5578
c19d1205 5579 if (skip_past_comma (&p) == SUCCESS)
09d92015 5580 {
c19d1205 5581 inst.operands[i].preind = 1;
09d92015 5582
c19d1205
ZW
5583 if (*p == '+') p++;
5584 else if (*p == '-') p++, inst.operands[i].negative = 1;
5585
dcbf9037 5586 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5587 {
c19d1205
ZW
5588 inst.operands[i].imm = reg;
5589 inst.operands[i].immisreg = 1;
5590
5591 if (skip_past_comma (&p) == SUCCESS)
5592 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5593 return PARSE_OPERAND_FAIL;
c19d1205 5594 }
5287ad62 5595 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5596 {
5597 /* FIXME: '@' should be used here, but it's filtered out by generic
5598 code before we get to see it here. This may be subject to
5599 change. */
5600 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5601
8e560766
MGD
5602 if (result != PARSE_OPERAND_SUCCESS)
5603 return result;
5604 }
c19d1205
ZW
5605 else
5606 {
5607 if (inst.operands[i].negative)
5608 {
5609 inst.operands[i].negative = 0;
5610 p--;
5611 }
4962c51a 5612
5f4273c7
NC
5613 if (group_relocations
5614 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5615 {
5616 struct group_reloc_table_entry *entry;
5617
477330fc
RM
5618 /* Skip over the #: or : sequence. */
5619 if (*p == '#')
5620 p += 2;
5621 else
5622 p++;
4962c51a
MS
5623
5624 /* Try to parse a group relocation. Anything else is an
477330fc 5625 error. */
4962c51a
MS
5626 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5627 {
5628 inst.error = _("unknown group relocation");
5629 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5630 }
5631
5632 /* We now have the group relocation table entry corresponding to
5633 the name in the assembler source. Next, we parse the
477330fc 5634 expression. */
4962c51a
MS
5635 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5636 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5637
5638 /* Record the relocation type. */
477330fc
RM
5639 switch (group_type)
5640 {
5641 case GROUP_LDR:
5642 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5643 break;
4962c51a 5644
477330fc
RM
5645 case GROUP_LDRS:
5646 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5647 break;
4962c51a 5648
477330fc
RM
5649 case GROUP_LDC:
5650 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5651 break;
4962c51a 5652
477330fc
RM
5653 default:
5654 gas_assert (0);
5655 }
4962c51a 5656
477330fc 5657 if (inst.reloc.type == 0)
4962c51a
MS
5658 {
5659 inst.error = _("this group relocation is not allowed on this instruction");
5660 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5661 }
477330fc
RM
5662 }
5663 else
26d97720
NS
5664 {
5665 char *q = p;
0198d5e6 5666
26d97720
NS
5667 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5668 return PARSE_OPERAND_FAIL;
5669 /* If the offset is 0, find out if it's a +0 or -0. */
5670 if (inst.reloc.exp.X_op == O_constant
5671 && inst.reloc.exp.X_add_number == 0)
5672 {
5673 skip_whitespace (q);
5674 if (*q == '#')
5675 {
5676 q++;
5677 skip_whitespace (q);
5678 }
5679 if (*q == '-')
5680 inst.operands[i].negative = 1;
5681 }
5682 }
09d92015
MM
5683 }
5684 }
8e560766
MGD
5685 else if (skip_past_char (&p, ':') == SUCCESS)
5686 {
5687 /* FIXME: '@' should be used here, but it's filtered out by generic code
5688 before we get to see it here. This may be subject to change. */
5689 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5690
8e560766
MGD
5691 if (result != PARSE_OPERAND_SUCCESS)
5692 return result;
5693 }
09d92015 5694
c19d1205 5695 if (skip_past_char (&p, ']') == FAIL)
09d92015 5696 {
c19d1205 5697 inst.error = _("']' expected");
4962c51a 5698 return PARSE_OPERAND_FAIL;
09d92015
MM
5699 }
5700
c19d1205
ZW
5701 if (skip_past_char (&p, '!') == SUCCESS)
5702 inst.operands[i].writeback = 1;
09d92015 5703
c19d1205 5704 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5705 {
c19d1205
ZW
5706 if (skip_past_char (&p, '{') == SUCCESS)
5707 {
5708 /* [Rn], {expr} - unindexed, with option */
5709 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5710 0, 255, TRUE) == FAIL)
4962c51a 5711 return PARSE_OPERAND_FAIL;
09d92015 5712
c19d1205
ZW
5713 if (skip_past_char (&p, '}') == FAIL)
5714 {
5715 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5716 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5717 }
5718 if (inst.operands[i].preind)
5719 {
5720 inst.error = _("cannot combine index with option");
4962c51a 5721 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5722 }
5723 *str = p;
4962c51a 5724 return PARSE_OPERAND_SUCCESS;
09d92015 5725 }
c19d1205
ZW
5726 else
5727 {
5728 inst.operands[i].postind = 1;
5729 inst.operands[i].writeback = 1;
09d92015 5730
c19d1205
ZW
5731 if (inst.operands[i].preind)
5732 {
5733 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5734 return PARSE_OPERAND_FAIL;
c19d1205 5735 }
09d92015 5736
c19d1205
ZW
5737 if (*p == '+') p++;
5738 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5739
dcbf9037 5740 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5741 {
477330fc
RM
5742 /* We might be using the immediate for alignment already. If we
5743 are, OR the register number into the low-order bits. */
5744 if (inst.operands[i].immisalign)
5745 inst.operands[i].imm |= reg;
5746 else
5747 inst.operands[i].imm = reg;
c19d1205 5748 inst.operands[i].immisreg = 1;
a737bd4d 5749
c19d1205
ZW
5750 if (skip_past_comma (&p) == SUCCESS)
5751 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5752 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5753 }
5754 else
5755 {
26d97720 5756 char *q = p;
0198d5e6 5757
c19d1205
ZW
5758 if (inst.operands[i].negative)
5759 {
5760 inst.operands[i].negative = 0;
5761 p--;
5762 }
5763 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5764 return PARSE_OPERAND_FAIL;
26d97720
NS
5765 /* If the offset is 0, find out if it's a +0 or -0. */
5766 if (inst.reloc.exp.X_op == O_constant
5767 && inst.reloc.exp.X_add_number == 0)
5768 {
5769 skip_whitespace (q);
5770 if (*q == '#')
5771 {
5772 q++;
5773 skip_whitespace (q);
5774 }
5775 if (*q == '-')
5776 inst.operands[i].negative = 1;
5777 }
c19d1205
ZW
5778 }
5779 }
a737bd4d
NC
5780 }
5781
c19d1205
ZW
5782 /* If at this point neither .preind nor .postind is set, we have a
5783 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5784 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5785 {
5786 inst.operands[i].preind = 1;
5787 inst.reloc.exp.X_op = O_constant;
5788 inst.reloc.exp.X_add_number = 0;
5789 }
5790 *str = p;
4962c51a
MS
5791 return PARSE_OPERAND_SUCCESS;
5792}
5793
5794static int
5795parse_address (char **str, int i)
5796{
21d799b5 5797 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5798 ? SUCCESS : FAIL;
4962c51a
MS
5799}
5800
5801static parse_operand_result
5802parse_address_group_reloc (char **str, int i, group_reloc_type type)
5803{
5804 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5805}
5806
b6895b4f
PB
5807/* Parse an operand for a MOVW or MOVT instruction. */
5808static int
5809parse_half (char **str)
5810{
5811 char * p;
5f4273c7 5812
b6895b4f
PB
5813 p = *str;
5814 skip_past_char (&p, '#');
5f4273c7 5815 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5816 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5817 else if (strncasecmp (p, ":upper16:", 9) == 0)
5818 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5819
5820 if (inst.reloc.type != BFD_RELOC_UNUSED)
5821 {
5822 p += 9;
5f4273c7 5823 skip_whitespace (p);
b6895b4f
PB
5824 }
5825
5826 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5827 return FAIL;
5828
5829 if (inst.reloc.type == BFD_RELOC_UNUSED)
5830 {
5831 if (inst.reloc.exp.X_op != O_constant)
5832 {
5833 inst.error = _("constant expression expected");
5834 return FAIL;
5835 }
5836 if (inst.reloc.exp.X_add_number < 0
5837 || inst.reloc.exp.X_add_number > 0xffff)
5838 {
5839 inst.error = _("immediate value out of range");
5840 return FAIL;
5841 }
5842 }
5843 *str = p;
5844 return SUCCESS;
5845}
5846
c19d1205 5847/* Miscellaneous. */
a737bd4d 5848
c19d1205
ZW
5849/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5850 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5851static int
d2cd1205 5852parse_psr (char **str, bfd_boolean lhs)
09d92015 5853{
c19d1205
ZW
5854 char *p;
5855 unsigned long psr_field;
62b3e311
PB
5856 const struct asm_psr *psr;
5857 char *start;
d2cd1205 5858 bfd_boolean is_apsr = FALSE;
ac7f631b 5859 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5860
a4482bb6
NC
5861 /* PR gas/12698: If the user has specified -march=all then m_profile will
5862 be TRUE, but we want to ignore it in this case as we are building for any
5863 CPU type, including non-m variants. */
823d2571 5864 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5865 m_profile = FALSE;
5866
c19d1205
ZW
5867 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5868 feature for ease of use and backwards compatibility. */
5869 p = *str;
62b3e311 5870 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5871 {
5872 if (m_profile)
5873 goto unsupported_psr;
fa94de6b 5874
d2cd1205
JB
5875 psr_field = SPSR_BIT;
5876 }
5877 else if (strncasecmp (p, "CPSR", 4) == 0)
5878 {
5879 if (m_profile)
5880 goto unsupported_psr;
5881
5882 psr_field = 0;
5883 }
5884 else if (strncasecmp (p, "APSR", 4) == 0)
5885 {
5886 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5887 and ARMv7-R architecture CPUs. */
5888 is_apsr = TRUE;
5889 psr_field = 0;
5890 }
5891 else if (m_profile)
62b3e311
PB
5892 {
5893 start = p;
5894 do
5895 p++;
5896 while (ISALNUM (*p) || *p == '_');
5897
d2cd1205
JB
5898 if (strncasecmp (start, "iapsr", 5) == 0
5899 || strncasecmp (start, "eapsr", 5) == 0
5900 || strncasecmp (start, "xpsr", 4) == 0
5901 || strncasecmp (start, "psr", 3) == 0)
5902 p = start + strcspn (start, "rR") + 1;
5903
21d799b5 5904 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5905 p - start);
d2cd1205 5906
62b3e311
PB
5907 if (!psr)
5908 return FAIL;
09d92015 5909
d2cd1205
JB
5910 /* If APSR is being written, a bitfield may be specified. Note that
5911 APSR itself is handled above. */
5912 if (psr->field <= 3)
5913 {
5914 psr_field = psr->field;
5915 is_apsr = TRUE;
5916 goto check_suffix;
5917 }
5918
62b3e311 5919 *str = p;
d2cd1205
JB
5920 /* M-profile MSR instructions have the mask field set to "10", except
5921 *PSR variants which modify APSR, which may use a different mask (and
5922 have been handled already). Do that by setting the PSR_f field
5923 here. */
5924 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5925 }
d2cd1205
JB
5926 else
5927 goto unsupported_psr;
09d92015 5928
62b3e311 5929 p += 4;
d2cd1205 5930check_suffix:
c19d1205
ZW
5931 if (*p == '_')
5932 {
5933 /* A suffix follows. */
c19d1205
ZW
5934 p++;
5935 start = p;
a737bd4d 5936
c19d1205
ZW
5937 do
5938 p++;
5939 while (ISALNUM (*p) || *p == '_');
a737bd4d 5940
d2cd1205
JB
5941 if (is_apsr)
5942 {
5943 /* APSR uses a notation for bits, rather than fields. */
5944 unsigned int nzcvq_bits = 0;
5945 unsigned int g_bit = 0;
5946 char *bit;
fa94de6b 5947
d2cd1205
JB
5948 for (bit = start; bit != p; bit++)
5949 {
5950 switch (TOLOWER (*bit))
477330fc 5951 {
d2cd1205
JB
5952 case 'n':
5953 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5954 break;
5955
5956 case 'z':
5957 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5958 break;
5959
5960 case 'c':
5961 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5962 break;
5963
5964 case 'v':
5965 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5966 break;
fa94de6b 5967
d2cd1205
JB
5968 case 'q':
5969 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5970 break;
fa94de6b 5971
d2cd1205
JB
5972 case 'g':
5973 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5974 break;
fa94de6b 5975
d2cd1205
JB
5976 default:
5977 inst.error = _("unexpected bit specified after APSR");
5978 return FAIL;
5979 }
5980 }
fa94de6b 5981
d2cd1205
JB
5982 if (nzcvq_bits == 0x1f)
5983 psr_field |= PSR_f;
fa94de6b 5984
d2cd1205
JB
5985 if (g_bit == 0x1)
5986 {
5987 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5988 {
d2cd1205
JB
5989 inst.error = _("selected processor does not "
5990 "support DSP extension");
5991 return FAIL;
5992 }
5993
5994 psr_field |= PSR_s;
5995 }
fa94de6b 5996
d2cd1205
JB
5997 if ((nzcvq_bits & 0x20) != 0
5998 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5999 || (g_bit & 0x2) != 0)
6000 {
6001 inst.error = _("bad bitmask specified after APSR");
6002 return FAIL;
6003 }
6004 }
6005 else
477330fc 6006 {
d2cd1205 6007 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 6008 p - start);
d2cd1205 6009 if (!psr)
477330fc 6010 goto error;
a737bd4d 6011
d2cd1205
JB
6012 psr_field |= psr->field;
6013 }
a737bd4d 6014 }
c19d1205 6015 else
a737bd4d 6016 {
c19d1205
ZW
6017 if (ISALNUM (*p))
6018 goto error; /* Garbage after "[CS]PSR". */
6019
d2cd1205 6020 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 6021 is deprecated, but allow it anyway. */
d2cd1205
JB
6022 if (is_apsr && lhs)
6023 {
6024 psr_field |= PSR_f;
6025 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6026 "deprecated"));
6027 }
6028 else if (!m_profile)
6029 /* These bits are never right for M-profile devices: don't set them
6030 (only code paths which read/write APSR reach here). */
6031 psr_field |= (PSR_c | PSR_f);
a737bd4d 6032 }
c19d1205
ZW
6033 *str = p;
6034 return psr_field;
a737bd4d 6035
d2cd1205
JB
6036 unsupported_psr:
6037 inst.error = _("selected processor does not support requested special "
6038 "purpose register");
6039 return FAIL;
6040
c19d1205
ZW
6041 error:
6042 inst.error = _("flag for {c}psr instruction expected");
6043 return FAIL;
a737bd4d
NC
6044}
6045
c19d1205
ZW
6046/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6047 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6048
c19d1205
ZW
6049static int
6050parse_cps_flags (char **str)
a737bd4d 6051{
c19d1205
ZW
6052 int val = 0;
6053 int saw_a_flag = 0;
6054 char *s = *str;
a737bd4d 6055
c19d1205
ZW
6056 for (;;)
6057 switch (*s++)
6058 {
6059 case '\0': case ',':
6060 goto done;
a737bd4d 6061
c19d1205
ZW
6062 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6063 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6064 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6065
c19d1205
ZW
6066 default:
6067 inst.error = _("unrecognized CPS flag");
6068 return FAIL;
6069 }
a737bd4d 6070
c19d1205
ZW
6071 done:
6072 if (saw_a_flag == 0)
a737bd4d 6073 {
c19d1205
ZW
6074 inst.error = _("missing CPS flags");
6075 return FAIL;
a737bd4d 6076 }
a737bd4d 6077
c19d1205
ZW
6078 *str = s - 1;
6079 return val;
a737bd4d
NC
6080}
6081
c19d1205
ZW
6082/* Parse an endian specifier ("BE" or "LE", case insensitive);
6083 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6084
6085static int
c19d1205 6086parse_endian_specifier (char **str)
a737bd4d 6087{
c19d1205
ZW
6088 int little_endian;
6089 char *s = *str;
a737bd4d 6090
c19d1205
ZW
6091 if (strncasecmp (s, "BE", 2))
6092 little_endian = 0;
6093 else if (strncasecmp (s, "LE", 2))
6094 little_endian = 1;
6095 else
a737bd4d 6096 {
c19d1205 6097 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6098 return FAIL;
6099 }
6100
c19d1205 6101 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6102 {
c19d1205 6103 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6104 return FAIL;
6105 }
6106
c19d1205
ZW
6107 *str = s + 2;
6108 return little_endian;
6109}
a737bd4d 6110
c19d1205
ZW
6111/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6112 value suitable for poking into the rotate field of an sxt or sxta
6113 instruction, or FAIL on error. */
6114
6115static int
6116parse_ror (char **str)
6117{
6118 int rot;
6119 char *s = *str;
6120
6121 if (strncasecmp (s, "ROR", 3) == 0)
6122 s += 3;
6123 else
a737bd4d 6124 {
c19d1205 6125 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6126 return FAIL;
6127 }
c19d1205
ZW
6128
6129 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6130 return FAIL;
6131
6132 switch (rot)
a737bd4d 6133 {
c19d1205
ZW
6134 case 0: *str = s; return 0x0;
6135 case 8: *str = s; return 0x1;
6136 case 16: *str = s; return 0x2;
6137 case 24: *str = s; return 0x3;
6138
6139 default:
6140 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6141 return FAIL;
6142 }
c19d1205 6143}
a737bd4d 6144
c19d1205
ZW
6145/* Parse a conditional code (from conds[] below). The value returned is in the
6146 range 0 .. 14, or FAIL. */
6147static int
6148parse_cond (char **str)
6149{
c462b453 6150 char *q;
c19d1205 6151 const struct asm_cond *c;
c462b453
PB
6152 int n;
6153 /* Condition codes are always 2 characters, so matching up to
6154 3 characters is sufficient. */
6155 char cond[3];
a737bd4d 6156
c462b453
PB
6157 q = *str;
6158 n = 0;
6159 while (ISALPHA (*q) && n < 3)
6160 {
e07e6e58 6161 cond[n] = TOLOWER (*q);
c462b453
PB
6162 q++;
6163 n++;
6164 }
a737bd4d 6165
21d799b5 6166 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6167 if (!c)
a737bd4d 6168 {
c19d1205 6169 inst.error = _("condition required");
a737bd4d
NC
6170 return FAIL;
6171 }
6172
c19d1205
ZW
6173 *str = q;
6174 return c->value;
6175}
6176
643afb90
MW
6177/* Record a use of the given feature. */
6178static void
6179record_feature_use (const arm_feature_set *feature)
6180{
6181 if (thumb_mode)
6182 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6183 else
6184 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6185}
6186
4d354d8b
TP
6187/* If the given feature is currently allowed, mark it as used and return TRUE.
6188 Return FALSE otherwise. */
e797f7e0
MGD
6189static bfd_boolean
6190mark_feature_used (const arm_feature_set *feature)
6191{
4d354d8b 6192 /* Ensure the option is currently allowed. */
e797f7e0
MGD
6193 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6194 return FALSE;
6195
4d354d8b 6196 /* Add the appropriate architecture feature for the barrier option used. */
643afb90 6197 record_feature_use (feature);
e797f7e0
MGD
6198
6199 return TRUE;
6200}
6201
62b3e311
PB
6202/* Parse an option for a barrier instruction. Returns the encoding for the
6203 option, or FAIL. */
6204static int
6205parse_barrier (char **str)
6206{
6207 char *p, *q;
6208 const struct asm_barrier_opt *o;
6209
6210 p = q = *str;
6211 while (ISALPHA (*q))
6212 q++;
6213
21d799b5 6214 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6215 q - p);
62b3e311
PB
6216 if (!o)
6217 return FAIL;
6218
e797f7e0
MGD
6219 if (!mark_feature_used (&o->arch))
6220 return FAIL;
6221
62b3e311
PB
6222 *str = q;
6223 return o->value;
6224}
6225
92e90b6e
PB
6226/* Parse the operands of a table branch instruction. Similar to a memory
6227 operand. */
6228static int
6229parse_tb (char **str)
6230{
6231 char * p = *str;
6232 int reg;
6233
6234 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6235 {
6236 inst.error = _("'[' expected");
6237 return FAIL;
6238 }
92e90b6e 6239
dcbf9037 6240 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6241 {
6242 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6243 return FAIL;
6244 }
6245 inst.operands[0].reg = reg;
6246
6247 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6248 {
6249 inst.error = _("',' expected");
6250 return FAIL;
6251 }
5f4273c7 6252
dcbf9037 6253 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6254 {
6255 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6256 return FAIL;
6257 }
6258 inst.operands[0].imm = reg;
6259
6260 if (skip_past_comma (&p) == SUCCESS)
6261 {
6262 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6263 return FAIL;
6264 if (inst.reloc.exp.X_add_number != 1)
6265 {
6266 inst.error = _("invalid shift");
6267 return FAIL;
6268 }
6269 inst.operands[0].shifted = 1;
6270 }
6271
6272 if (skip_past_char (&p, ']') == FAIL)
6273 {
6274 inst.error = _("']' expected");
6275 return FAIL;
6276 }
6277 *str = p;
6278 return SUCCESS;
6279}
6280
5287ad62
JB
6281/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6282 information on the types the operands can take and how they are encoded.
037e8744
JB
6283 Up to four operands may be read; this function handles setting the
6284 ".present" field for each read operand itself.
5287ad62
JB
6285 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6286 else returns FAIL. */
6287
6288static int
6289parse_neon_mov (char **str, int *which_operand)
6290{
6291 int i = *which_operand, val;
6292 enum arm_reg_type rtype;
6293 char *ptr = *str;
dcbf9037 6294 struct neon_type_el optype;
5f4273c7 6295
dcbf9037 6296 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6297 {
6298 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6299 inst.operands[i].reg = val;
6300 inst.operands[i].isscalar = 1;
dcbf9037 6301 inst.operands[i].vectype = optype;
5287ad62
JB
6302 inst.operands[i++].present = 1;
6303
6304 if (skip_past_comma (&ptr) == FAIL)
477330fc 6305 goto wanted_comma;
5f4273c7 6306
dcbf9037 6307 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6308 goto wanted_arm;
5f4273c7 6309
5287ad62
JB
6310 inst.operands[i].reg = val;
6311 inst.operands[i].isreg = 1;
6312 inst.operands[i].present = 1;
6313 }
037e8744 6314 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6315 != FAIL)
5287ad62
JB
6316 {
6317 /* Cases 0, 1, 2, 3, 5 (D only). */
6318 if (skip_past_comma (&ptr) == FAIL)
477330fc 6319 goto wanted_comma;
5f4273c7 6320
5287ad62
JB
6321 inst.operands[i].reg = val;
6322 inst.operands[i].isreg = 1;
6323 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6324 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6325 inst.operands[i].isvec = 1;
dcbf9037 6326 inst.operands[i].vectype = optype;
5287ad62
JB
6327 inst.operands[i++].present = 1;
6328
dcbf9037 6329 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6330 {
6331 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6332 Case 13: VMOV <Sd>, <Rm> */
6333 inst.operands[i].reg = val;
6334 inst.operands[i].isreg = 1;
6335 inst.operands[i].present = 1;
6336
6337 if (rtype == REG_TYPE_NQ)
6338 {
6339 first_error (_("can't use Neon quad register here"));
6340 return FAIL;
6341 }
6342 else if (rtype != REG_TYPE_VFS)
6343 {
6344 i++;
6345 if (skip_past_comma (&ptr) == FAIL)
6346 goto wanted_comma;
6347 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6348 goto wanted_arm;
6349 inst.operands[i].reg = val;
6350 inst.operands[i].isreg = 1;
6351 inst.operands[i].present = 1;
6352 }
6353 }
037e8744 6354 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6355 &optype)) != FAIL)
6356 {
6357 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6358 Case 1: VMOV<c><q> <Dd>, <Dm>
6359 Case 8: VMOV.F32 <Sd>, <Sm>
6360 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6361
6362 inst.operands[i].reg = val;
6363 inst.operands[i].isreg = 1;
6364 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6365 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6366 inst.operands[i].isvec = 1;
6367 inst.operands[i].vectype = optype;
6368 inst.operands[i].present = 1;
6369
6370 if (skip_past_comma (&ptr) == SUCCESS)
6371 {
6372 /* Case 15. */
6373 i++;
6374
6375 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6376 goto wanted_arm;
6377
6378 inst.operands[i].reg = val;
6379 inst.operands[i].isreg = 1;
6380 inst.operands[i++].present = 1;
6381
6382 if (skip_past_comma (&ptr) == FAIL)
6383 goto wanted_comma;
6384
6385 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6386 goto wanted_arm;
6387
6388 inst.operands[i].reg = val;
6389 inst.operands[i].isreg = 1;
6390 inst.operands[i].present = 1;
6391 }
6392 }
4641781c 6393 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6394 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6395 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6396 Case 10: VMOV.F32 <Sd>, #<imm>
6397 Case 11: VMOV.F64 <Dd>, #<imm> */
6398 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6399 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6400 == SUCCESS)
477330fc
RM
6401 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6402 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6403 ;
5287ad62 6404 else
477330fc
RM
6405 {
6406 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6407 return FAIL;
6408 }
5287ad62 6409 }
dcbf9037 6410 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6411 {
6412 /* Cases 6, 7. */
6413 inst.operands[i].reg = val;
6414 inst.operands[i].isreg = 1;
6415 inst.operands[i++].present = 1;
5f4273c7 6416
5287ad62 6417 if (skip_past_comma (&ptr) == FAIL)
477330fc 6418 goto wanted_comma;
5f4273c7 6419
dcbf9037 6420 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6421 {
6422 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6423 inst.operands[i].reg = val;
6424 inst.operands[i].isscalar = 1;
6425 inst.operands[i].present = 1;
6426 inst.operands[i].vectype = optype;
6427 }
dcbf9037 6428 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6429 {
6430 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6431 inst.operands[i].reg = val;
6432 inst.operands[i].isreg = 1;
6433 inst.operands[i++].present = 1;
6434
6435 if (skip_past_comma (&ptr) == FAIL)
6436 goto wanted_comma;
6437
6438 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6439 == FAIL)
6440 {
6441 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6442 return FAIL;
6443 }
6444
6445 inst.operands[i].reg = val;
6446 inst.operands[i].isreg = 1;
6447 inst.operands[i].isvec = 1;
6448 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6449 inst.operands[i].vectype = optype;
6450 inst.operands[i].present = 1;
6451
6452 if (rtype == REG_TYPE_VFS)
6453 {
6454 /* Case 14. */
6455 i++;
6456 if (skip_past_comma (&ptr) == FAIL)
6457 goto wanted_comma;
6458 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6459 &optype)) == FAIL)
6460 {
6461 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6462 return FAIL;
6463 }
6464 inst.operands[i].reg = val;
6465 inst.operands[i].isreg = 1;
6466 inst.operands[i].isvec = 1;
6467 inst.operands[i].issingle = 1;
6468 inst.operands[i].vectype = optype;
6469 inst.operands[i].present = 1;
6470 }
6471 }
037e8744 6472 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6473 != FAIL)
6474 {
6475 /* Case 13. */
6476 inst.operands[i].reg = val;
6477 inst.operands[i].isreg = 1;
6478 inst.operands[i].isvec = 1;
6479 inst.operands[i].issingle = 1;
6480 inst.operands[i].vectype = optype;
6481 inst.operands[i].present = 1;
6482 }
5287ad62
JB
6483 }
6484 else
6485 {
dcbf9037 6486 first_error (_("parse error"));
5287ad62
JB
6487 return FAIL;
6488 }
6489
6490 /* Successfully parsed the operands. Update args. */
6491 *which_operand = i;
6492 *str = ptr;
6493 return SUCCESS;
6494
5f4273c7 6495 wanted_comma:
dcbf9037 6496 first_error (_("expected comma"));
5287ad62 6497 return FAIL;
5f4273c7
NC
6498
6499 wanted_arm:
dcbf9037 6500 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6501 return FAIL;
5287ad62
JB
6502}
6503
5be8be5d
DG
6504/* Use this macro when the operand constraints are different
6505 for ARM and THUMB (e.g. ldrd). */
6506#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6507 ((arm_operand) | ((thumb_operand) << 16))
6508
c19d1205
ZW
6509/* Matcher codes for parse_operands. */
6510enum operand_parse_code
6511{
6512 OP_stop, /* end of line */
6513
6514 OP_RR, /* ARM register */
6515 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6516 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6517 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6518 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6519 optional trailing ! */
c19d1205
ZW
6520 OP_RRw, /* ARM register, not r15, optional trailing ! */
6521 OP_RCP, /* Coprocessor number */
6522 OP_RCN, /* Coprocessor register */
6523 OP_RF, /* FPA register */
6524 OP_RVS, /* VFP single precision register */
5287ad62
JB
6525 OP_RVD, /* VFP double precision register (0..15) */
6526 OP_RND, /* Neon double precision register (0..31) */
6527 OP_RNQ, /* Neon quad precision register */
037e8744 6528 OP_RVSD, /* VFP single or double precision register */
dec41383 6529 OP_RNSD, /* Neon single or double precision register */
5287ad62 6530 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6531 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6532 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6533 OP_RVC, /* VFP control register */
6534 OP_RMF, /* Maverick F register */
6535 OP_RMD, /* Maverick D register */
6536 OP_RMFX, /* Maverick FX register */
6537 OP_RMDX, /* Maverick DX register */
6538 OP_RMAX, /* Maverick AX register */
6539 OP_RMDS, /* Maverick DSPSC register */
6540 OP_RIWR, /* iWMMXt wR register */
6541 OP_RIWC, /* iWMMXt wC register */
6542 OP_RIWG, /* iWMMXt wCG register */
6543 OP_RXA, /* XScale accumulator register */
6544
6545 OP_REGLST, /* ARM register list */
6546 OP_VRSLST, /* VFP single-precision register list */
6547 OP_VRDLST, /* VFP double-precision register list */
037e8744 6548 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6549 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6550 OP_NSTRLST, /* Neon element/structure list */
6551
5287ad62 6552 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6553 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6554 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6555 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6556 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6557 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6558 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6559 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6560 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6561 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6562 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6563 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6564
6565 OP_I0, /* immediate zero */
c19d1205
ZW
6566 OP_I7, /* immediate value 0 .. 7 */
6567 OP_I15, /* 0 .. 15 */
6568 OP_I16, /* 1 .. 16 */
5287ad62 6569 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6570 OP_I31, /* 0 .. 31 */
6571 OP_I31w, /* 0 .. 31, optional trailing ! */
6572 OP_I32, /* 1 .. 32 */
5287ad62
JB
6573 OP_I32z, /* 0 .. 32 */
6574 OP_I63, /* 0 .. 63 */
c19d1205 6575 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6576 OP_I64, /* 1 .. 64 */
6577 OP_I64z, /* 0 .. 64 */
c19d1205 6578 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6579
6580 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6581 OP_I7b, /* 0 .. 7 */
6582 OP_I15b, /* 0 .. 15 */
6583 OP_I31b, /* 0 .. 31 */
6584
6585 OP_SH, /* shifter operand */
4962c51a 6586 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6587 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6588 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6589 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6590 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6591 OP_EXP, /* arbitrary expression */
6592 OP_EXPi, /* same, with optional immediate prefix */
6593 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6594 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6595 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6596 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6597
6598 OP_CPSF, /* CPS flags */
6599 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6600 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6601 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6602 OP_COND, /* conditional code */
92e90b6e 6603 OP_TB, /* Table branch. */
c19d1205 6604
037e8744
JB
6605 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6606
c19d1205 6607 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6608 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6609 OP_RR_EXi, /* ARM register or expression with imm prefix */
6610 OP_RF_IF, /* FPA register or immediate */
6611 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6612 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6613
6614 /* Optional operands. */
6615 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6616 OP_oI31b, /* 0 .. 31 */
5287ad62 6617 OP_oI32b, /* 1 .. 32 */
5f1af56b 6618 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6619 OP_oIffffb, /* 0 .. 65535 */
6620 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6621
6622 OP_oRR, /* ARM register */
6623 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6624 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6625 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6626 OP_oRND, /* Optional Neon double precision register */
6627 OP_oRNQ, /* Optional Neon quad precision register */
6628 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6629 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6630 OP_oSHll, /* LSL immediate */
6631 OP_oSHar, /* ASR immediate */
6632 OP_oSHllar, /* LSL or ASR immediate */
6633 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6634 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6635
5be8be5d
DG
6636 /* Some pre-defined mixed (ARM/THUMB) operands. */
6637 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6638 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6639 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6640
c19d1205
ZW
6641 OP_FIRST_OPTIONAL = OP_oI7b
6642};
a737bd4d 6643
c19d1205
ZW
6644/* Generic instruction operand parser. This does no encoding and no
6645 semantic validation; it merely squirrels values away in the inst
6646 structure. Returns SUCCESS or FAIL depending on whether the
6647 specified grammar matched. */
6648static int
5be8be5d 6649parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6650{
5be8be5d 6651 unsigned const int *upat = pattern;
c19d1205
ZW
6652 char *backtrack_pos = 0;
6653 const char *backtrack_error = 0;
99aad254 6654 int i, val = 0, backtrack_index = 0;
5287ad62 6655 enum arm_reg_type rtype;
4962c51a 6656 parse_operand_result result;
5be8be5d 6657 unsigned int op_parse_code;
c19d1205 6658
e07e6e58
NC
6659#define po_char_or_fail(chr) \
6660 do \
6661 { \
6662 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6663 goto bad_args; \
e07e6e58
NC
6664 } \
6665 while (0)
c19d1205 6666
e07e6e58
NC
6667#define po_reg_or_fail(regtype) \
6668 do \
dcbf9037 6669 { \
e07e6e58 6670 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6671 & inst.operands[i].vectype); \
e07e6e58 6672 if (val == FAIL) \
477330fc
RM
6673 { \
6674 first_error (_(reg_expected_msgs[regtype])); \
6675 goto failure; \
6676 } \
e07e6e58
NC
6677 inst.operands[i].reg = val; \
6678 inst.operands[i].isreg = 1; \
6679 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6680 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6681 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6682 || rtype == REG_TYPE_VFD \
6683 || rtype == REG_TYPE_NQ); \
dcbf9037 6684 } \
e07e6e58
NC
6685 while (0)
6686
6687#define po_reg_or_goto(regtype, label) \
6688 do \
6689 { \
6690 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6691 & inst.operands[i].vectype); \
6692 if (val == FAIL) \
6693 goto label; \
dcbf9037 6694 \
e07e6e58
NC
6695 inst.operands[i].reg = val; \
6696 inst.operands[i].isreg = 1; \
6697 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6698 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6699 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6700 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6701 || rtype == REG_TYPE_NQ); \
6702 } \
6703 while (0)
6704
6705#define po_imm_or_fail(min, max, popt) \
6706 do \
6707 { \
6708 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6709 goto failure; \
6710 inst.operands[i].imm = val; \
6711 } \
6712 while (0)
6713
6714#define po_scalar_or_goto(elsz, label) \
6715 do \
6716 { \
6717 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6718 if (val == FAIL) \
6719 goto label; \
6720 inst.operands[i].reg = val; \
6721 inst.operands[i].isscalar = 1; \
6722 } \
6723 while (0)
6724
6725#define po_misc_or_fail(expr) \
6726 do \
6727 { \
6728 if (expr) \
6729 goto failure; \
6730 } \
6731 while (0)
6732
6733#define po_misc_or_fail_no_backtrack(expr) \
6734 do \
6735 { \
6736 result = expr; \
6737 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6738 backtrack_pos = 0; \
6739 if (result != PARSE_OPERAND_SUCCESS) \
6740 goto failure; \
6741 } \
6742 while (0)
4962c51a 6743
52e7f43d
RE
6744#define po_barrier_or_imm(str) \
6745 do \
6746 { \
6747 val = parse_barrier (&str); \
ccb84d65
JB
6748 if (val == FAIL && ! ISALPHA (*str)) \
6749 goto immediate; \
6750 if (val == FAIL \
6751 /* ISB can only take SY as an option. */ \
6752 || ((inst.instruction & 0xf0) == 0x60 \
6753 && val != 0xf)) \
52e7f43d 6754 { \
ccb84d65
JB
6755 inst.error = _("invalid barrier type"); \
6756 backtrack_pos = 0; \
6757 goto failure; \
52e7f43d
RE
6758 } \
6759 } \
6760 while (0)
6761
c19d1205
ZW
6762 skip_whitespace (str);
6763
6764 for (i = 0; upat[i] != OP_stop; i++)
6765 {
5be8be5d
DG
6766 op_parse_code = upat[i];
6767 if (op_parse_code >= 1<<16)
6768 op_parse_code = thumb ? (op_parse_code >> 16)
6769 : (op_parse_code & ((1<<16)-1));
6770
6771 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6772 {
6773 /* Remember where we are in case we need to backtrack. */
9c2799c2 6774 gas_assert (!backtrack_pos);
c19d1205
ZW
6775 backtrack_pos = str;
6776 backtrack_error = inst.error;
6777 backtrack_index = i;
6778 }
6779
b6702015 6780 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6781 po_char_or_fail (',');
6782
5be8be5d 6783 switch (op_parse_code)
c19d1205
ZW
6784 {
6785 /* Registers */
6786 case OP_oRRnpc:
5be8be5d 6787 case OP_oRRnpcsp:
c19d1205 6788 case OP_RRnpc:
5be8be5d 6789 case OP_RRnpcsp:
c19d1205
ZW
6790 case OP_oRR:
6791 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6792 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6793 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6794 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6795 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6796 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6797 case OP_oRND:
5287ad62 6798 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6799 case OP_RVC:
6800 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6801 break;
6802 /* Also accept generic coprocessor regs for unknown registers. */
6803 coproc_reg:
6804 po_reg_or_fail (REG_TYPE_CN);
6805 break;
c19d1205
ZW
6806 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6807 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6808 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6809 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6810 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6811 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6812 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6813 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6814 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6815 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6816 case OP_oRNQ:
5287ad62 6817 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6818 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6819 case OP_oRNDQ:
5287ad62 6820 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6821 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6822 case OP_oRNSDQ:
6823 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6824
6825 /* Neon scalar. Using an element size of 8 means that some invalid
6826 scalars are accepted here, so deal with those in later code. */
6827 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6828
6829 case OP_RNDQ_I0:
6830 {
6831 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6832 break;
6833 try_imm0:
6834 po_imm_or_fail (0, 0, TRUE);
6835 }
6836 break;
6837
6838 case OP_RVSD_I0:
6839 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6840 break;
6841
aacf0b33
KT
6842 case OP_RSVD_FI0:
6843 {
6844 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6845 break;
6846 try_ifimm0:
6847 if (parse_ifimm_zero (&str))
6848 inst.operands[i].imm = 0;
6849 else
6850 {
6851 inst.error
6852 = _("only floating point zero is allowed as immediate value");
6853 goto failure;
6854 }
6855 }
6856 break;
6857
477330fc
RM
6858 case OP_RR_RNSC:
6859 {
6860 po_scalar_or_goto (8, try_rr);
6861 break;
6862 try_rr:
6863 po_reg_or_fail (REG_TYPE_RN);
6864 }
6865 break;
6866
6867 case OP_RNSDQ_RNSC:
6868 {
6869 po_scalar_or_goto (8, try_nsdq);
6870 break;
6871 try_nsdq:
6872 po_reg_or_fail (REG_TYPE_NSDQ);
6873 }
6874 break;
6875
dec41383
JW
6876 case OP_RNSD_RNSC:
6877 {
6878 po_scalar_or_goto (8, try_s_scalar);
6879 break;
6880 try_s_scalar:
6881 po_scalar_or_goto (4, try_nsd);
6882 break;
6883 try_nsd:
6884 po_reg_or_fail (REG_TYPE_NSD);
6885 }
6886 break;
6887
477330fc
RM
6888 case OP_RNDQ_RNSC:
6889 {
6890 po_scalar_or_goto (8, try_ndq);
6891 break;
6892 try_ndq:
6893 po_reg_or_fail (REG_TYPE_NDQ);
6894 }
6895 break;
6896
6897 case OP_RND_RNSC:
6898 {
6899 po_scalar_or_goto (8, try_vfd);
6900 break;
6901 try_vfd:
6902 po_reg_or_fail (REG_TYPE_VFD);
6903 }
6904 break;
6905
6906 case OP_VMOV:
6907 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6908 not careful then bad things might happen. */
6909 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6910 break;
6911
6912 case OP_RNDQ_Ibig:
6913 {
6914 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6915 break;
6916 try_immbig:
6917 /* There's a possibility of getting a 64-bit immediate here, so
6918 we need special handling. */
8335d6aa
JW
6919 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6920 == FAIL)
477330fc
RM
6921 {
6922 inst.error = _("immediate value is out of range");
6923 goto failure;
6924 }
6925 }
6926 break;
6927
6928 case OP_RNDQ_I63b:
6929 {
6930 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6931 break;
6932 try_shimm:
6933 po_imm_or_fail (0, 63, TRUE);
6934 }
6935 break;
c19d1205
ZW
6936
6937 case OP_RRnpcb:
6938 po_char_or_fail ('[');
6939 po_reg_or_fail (REG_TYPE_RN);
6940 po_char_or_fail (']');
6941 break;
a737bd4d 6942
55881a11 6943 case OP_RRnpctw:
c19d1205 6944 case OP_RRw:
b6702015 6945 case OP_oRRw:
c19d1205
ZW
6946 po_reg_or_fail (REG_TYPE_RN);
6947 if (skip_past_char (&str, '!') == SUCCESS)
6948 inst.operands[i].writeback = 1;
6949 break;
6950
6951 /* Immediates */
6952 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6953 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6954 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6955 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6956 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6957 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6958 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6959 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6960 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6961 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6962 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6963 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6964
6965 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6966 case OP_oI7b:
6967 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6968 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6969 case OP_oI31b:
6970 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6971 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6972 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6973 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6974
6975 /* Immediate variants */
6976 case OP_oI255c:
6977 po_char_or_fail ('{');
6978 po_imm_or_fail (0, 255, TRUE);
6979 po_char_or_fail ('}');
6980 break;
6981
6982 case OP_I31w:
6983 /* The expression parser chokes on a trailing !, so we have
6984 to find it first and zap it. */
6985 {
6986 char *s = str;
6987 while (*s && *s != ',')
6988 s++;
6989 if (s[-1] == '!')
6990 {
6991 s[-1] = '\0';
6992 inst.operands[i].writeback = 1;
6993 }
6994 po_imm_or_fail (0, 31, TRUE);
6995 if (str == s - 1)
6996 str = s;
6997 }
6998 break;
6999
7000 /* Expressions */
7001 case OP_EXPi: EXPi:
7002 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
7003 GE_OPT_PREFIX));
7004 break;
7005
7006 case OP_EXP:
7007 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
7008 GE_NO_PREFIX));
7009 break;
7010
7011 case OP_EXPr: EXPr:
7012 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
7013 GE_NO_PREFIX));
7014 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 7015 {
c19d1205
ZW
7016 val = parse_reloc (&str);
7017 if (val == -1)
7018 {
7019 inst.error = _("unrecognized relocation suffix");
7020 goto failure;
7021 }
7022 else if (val != BFD_RELOC_UNUSED)
7023 {
7024 inst.operands[i].imm = val;
7025 inst.operands[i].hasreloc = 1;
7026 }
a737bd4d 7027 }
c19d1205 7028 break;
a737bd4d 7029
b6895b4f
PB
7030 /* Operand for MOVW or MOVT. */
7031 case OP_HALF:
7032 po_misc_or_fail (parse_half (&str));
7033 break;
7034
e07e6e58 7035 /* Register or expression. */
c19d1205
ZW
7036 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7037 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7038
e07e6e58 7039 /* Register or immediate. */
c19d1205
ZW
7040 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7041 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7042
c19d1205
ZW
7043 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7044 IF:
7045 if (!is_immediate_prefix (*str))
7046 goto bad_args;
7047 str++;
7048 val = parse_fpa_immediate (&str);
7049 if (val == FAIL)
7050 goto failure;
7051 /* FPA immediates are encoded as registers 8-15.
7052 parse_fpa_immediate has already applied the offset. */
7053 inst.operands[i].reg = val;
7054 inst.operands[i].isreg = 1;
7055 break;
09d92015 7056
2d447fca
JM
7057 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7058 I32z: po_imm_or_fail (0, 32, FALSE); break;
7059
e07e6e58 7060 /* Two kinds of register. */
c19d1205
ZW
7061 case OP_RIWR_RIWC:
7062 {
7063 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7064 if (!rege
7065 || (rege->type != REG_TYPE_MMXWR
7066 && rege->type != REG_TYPE_MMXWC
7067 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7068 {
7069 inst.error = _("iWMMXt data or control register expected");
7070 goto failure;
7071 }
7072 inst.operands[i].reg = rege->number;
7073 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7074 }
7075 break;
09d92015 7076
41adaa5c
JM
7077 case OP_RIWC_RIWG:
7078 {
7079 struct reg_entry *rege = arm_reg_parse_multi (&str);
7080 if (!rege
7081 || (rege->type != REG_TYPE_MMXWC
7082 && rege->type != REG_TYPE_MMXWCG))
7083 {
7084 inst.error = _("iWMMXt control register expected");
7085 goto failure;
7086 }
7087 inst.operands[i].reg = rege->number;
7088 inst.operands[i].isreg = 1;
7089 }
7090 break;
7091
c19d1205
ZW
7092 /* Misc */
7093 case OP_CPSF: val = parse_cps_flags (&str); break;
7094 case OP_ENDI: val = parse_endian_specifier (&str); break;
7095 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7096 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7097 case OP_oBARRIER_I15:
7098 po_barrier_or_imm (str); break;
7099 immediate:
7100 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7101 goto failure;
52e7f43d 7102 break;
c19d1205 7103
fa94de6b 7104 case OP_wPSR:
d2cd1205 7105 case OP_rPSR:
90ec0d68
MGD
7106 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7107 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7108 {
7109 inst.error = _("Banked registers are not available with this "
7110 "architecture.");
7111 goto failure;
7112 }
7113 break;
d2cd1205
JB
7114 try_psr:
7115 val = parse_psr (&str, op_parse_code == OP_wPSR);
7116 break;
037e8744 7117
477330fc
RM
7118 case OP_APSR_RR:
7119 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7120 break;
7121 try_apsr:
7122 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7123 instruction). */
7124 if (strncasecmp (str, "APSR_", 5) == 0)
7125 {
7126 unsigned found = 0;
7127 str += 5;
7128 while (found < 15)
7129 switch (*str++)
7130 {
7131 case 'c': found = (found & 1) ? 16 : found | 1; break;
7132 case 'n': found = (found & 2) ? 16 : found | 2; break;
7133 case 'z': found = (found & 4) ? 16 : found | 4; break;
7134 case 'v': found = (found & 8) ? 16 : found | 8; break;
7135 default: found = 16;
7136 }
7137 if (found != 15)
7138 goto failure;
7139 inst.operands[i].isvec = 1;
f7c21dc7
NC
7140 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7141 inst.operands[i].reg = REG_PC;
477330fc
RM
7142 }
7143 else
7144 goto failure;
7145 break;
037e8744 7146
92e90b6e
PB
7147 case OP_TB:
7148 po_misc_or_fail (parse_tb (&str));
7149 break;
7150
e07e6e58 7151 /* Register lists. */
c19d1205
ZW
7152 case OP_REGLST:
7153 val = parse_reg_list (&str);
7154 if (*str == '^')
7155 {
5e0d7f77 7156 inst.operands[i].writeback = 1;
c19d1205
ZW
7157 str++;
7158 }
7159 break;
09d92015 7160
c19d1205 7161 case OP_VRSLST:
5287ad62 7162 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7163 break;
09d92015 7164
c19d1205 7165 case OP_VRDLST:
5287ad62 7166 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7167 break;
a737bd4d 7168
477330fc
RM
7169 case OP_VRSDLST:
7170 /* Allow Q registers too. */
7171 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7172 REGLIST_NEON_D);
7173 if (val == FAIL)
7174 {
7175 inst.error = NULL;
7176 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7177 REGLIST_VFP_S);
7178 inst.operands[i].issingle = 1;
7179 }
7180 break;
7181
7182 case OP_NRDLST:
7183 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7184 REGLIST_NEON_D);
7185 break;
5287ad62
JB
7186
7187 case OP_NSTRLST:
477330fc
RM
7188 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7189 &inst.operands[i].vectype);
7190 break;
5287ad62 7191
c19d1205
ZW
7192 /* Addressing modes */
7193 case OP_ADDR:
7194 po_misc_or_fail (parse_address (&str, i));
7195 break;
09d92015 7196
4962c51a
MS
7197 case OP_ADDRGLDR:
7198 po_misc_or_fail_no_backtrack (
477330fc 7199 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7200 break;
7201
7202 case OP_ADDRGLDRS:
7203 po_misc_or_fail_no_backtrack (
477330fc 7204 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7205 break;
7206
7207 case OP_ADDRGLDC:
7208 po_misc_or_fail_no_backtrack (
477330fc 7209 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7210 break;
7211
c19d1205
ZW
7212 case OP_SH:
7213 po_misc_or_fail (parse_shifter_operand (&str, i));
7214 break;
09d92015 7215
4962c51a
MS
7216 case OP_SHG:
7217 po_misc_or_fail_no_backtrack (
477330fc 7218 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7219 break;
7220
c19d1205
ZW
7221 case OP_oSHll:
7222 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7223 break;
09d92015 7224
c19d1205
ZW
7225 case OP_oSHar:
7226 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7227 break;
09d92015 7228
c19d1205
ZW
7229 case OP_oSHllar:
7230 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7231 break;
09d92015 7232
c19d1205 7233 default:
5be8be5d 7234 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7235 }
09d92015 7236
c19d1205
ZW
7237 /* Various value-based sanity checks and shared operations. We
7238 do not signal immediate failures for the register constraints;
7239 this allows a syntax error to take precedence. */
5be8be5d 7240 switch (op_parse_code)
c19d1205
ZW
7241 {
7242 case OP_oRRnpc:
7243 case OP_RRnpc:
7244 case OP_RRnpcb:
7245 case OP_RRw:
b6702015 7246 case OP_oRRw:
c19d1205
ZW
7247 case OP_RRnpc_I0:
7248 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7249 inst.error = BAD_PC;
7250 break;
09d92015 7251
5be8be5d
DG
7252 case OP_oRRnpcsp:
7253 case OP_RRnpcsp:
7254 if (inst.operands[i].isreg)
7255 {
7256 if (inst.operands[i].reg == REG_PC)
7257 inst.error = BAD_PC;
5c8ed6a4
JW
7258 else if (inst.operands[i].reg == REG_SP
7259 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7260 relaxed since ARMv8-A. */
7261 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7262 {
7263 gas_assert (thumb);
7264 inst.error = BAD_SP;
7265 }
5be8be5d
DG
7266 }
7267 break;
7268
55881a11 7269 case OP_RRnpctw:
fa94de6b
RM
7270 if (inst.operands[i].isreg
7271 && inst.operands[i].reg == REG_PC
55881a11
MGD
7272 && (inst.operands[i].writeback || thumb))
7273 inst.error = BAD_PC;
7274 break;
7275
c19d1205
ZW
7276 case OP_CPSF:
7277 case OP_ENDI:
7278 case OP_oROR:
d2cd1205
JB
7279 case OP_wPSR:
7280 case OP_rPSR:
c19d1205 7281 case OP_COND:
52e7f43d 7282 case OP_oBARRIER_I15:
c19d1205
ZW
7283 case OP_REGLST:
7284 case OP_VRSLST:
7285 case OP_VRDLST:
477330fc
RM
7286 case OP_VRSDLST:
7287 case OP_NRDLST:
7288 case OP_NSTRLST:
c19d1205
ZW
7289 if (val == FAIL)
7290 goto failure;
7291 inst.operands[i].imm = val;
7292 break;
a737bd4d 7293
c19d1205
ZW
7294 default:
7295 break;
7296 }
09d92015 7297
c19d1205
ZW
7298 /* If we get here, this operand was successfully parsed. */
7299 inst.operands[i].present = 1;
7300 continue;
09d92015 7301
c19d1205 7302 bad_args:
09d92015 7303 inst.error = BAD_ARGS;
c19d1205
ZW
7304
7305 failure:
7306 if (!backtrack_pos)
d252fdde
PB
7307 {
7308 /* The parse routine should already have set inst.error, but set a
5f4273c7 7309 default here just in case. */
d252fdde
PB
7310 if (!inst.error)
7311 inst.error = _("syntax error");
7312 return FAIL;
7313 }
c19d1205
ZW
7314
7315 /* Do not backtrack over a trailing optional argument that
7316 absorbed some text. We will only fail again, with the
7317 'garbage following instruction' error message, which is
7318 probably less helpful than the current one. */
7319 if (backtrack_index == i && backtrack_pos != str
7320 && upat[i+1] == OP_stop)
d252fdde
PB
7321 {
7322 if (!inst.error)
7323 inst.error = _("syntax error");
7324 return FAIL;
7325 }
c19d1205
ZW
7326
7327 /* Try again, skipping the optional argument at backtrack_pos. */
7328 str = backtrack_pos;
7329 inst.error = backtrack_error;
7330 inst.operands[backtrack_index].present = 0;
7331 i = backtrack_index;
7332 backtrack_pos = 0;
09d92015 7333 }
09d92015 7334
c19d1205
ZW
7335 /* Check that we have parsed all the arguments. */
7336 if (*str != '\0' && !inst.error)
7337 inst.error = _("garbage following instruction");
09d92015 7338
c19d1205 7339 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7340}
7341
c19d1205
ZW
7342#undef po_char_or_fail
7343#undef po_reg_or_fail
7344#undef po_reg_or_goto
7345#undef po_imm_or_fail
5287ad62 7346#undef po_scalar_or_fail
52e7f43d 7347#undef po_barrier_or_imm
e07e6e58 7348
c19d1205 7349/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7350#define constraint(expr, err) \
7351 do \
c19d1205 7352 { \
e07e6e58
NC
7353 if (expr) \
7354 { \
7355 inst.error = err; \
7356 return; \
7357 } \
c19d1205 7358 } \
e07e6e58 7359 while (0)
c19d1205 7360
fdfde340
JM
7361/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7362 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7363 is the BadReg predicate in ARM's Thumb-2 documentation.
7364
7365 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7366 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7367#define reject_bad_reg(reg) \
7368 do \
7369 if (reg == REG_PC) \
7370 { \
7371 inst.error = BAD_PC; \
7372 return; \
7373 } \
7374 else if (reg == REG_SP \
7375 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7376 { \
7377 inst.error = BAD_SP; \
7378 return; \
7379 } \
fdfde340
JM
7380 while (0)
7381
94206790
MM
7382/* If REG is R13 (the stack pointer), warn that its use is
7383 deprecated. */
7384#define warn_deprecated_sp(reg) \
7385 do \
7386 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7387 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7388 while (0)
7389
c19d1205
ZW
7390/* Functions for operand encoding. ARM, then Thumb. */
7391
d840c081 7392#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7393
9db2f6b4
RL
7394/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7395
7396 The only binary encoding difference is the Coprocessor number. Coprocessor
7397 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7398 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7399 exists for Single-Precision operation. */
7400
7401static void
7402do_scalar_fp16_v82_encode (void)
7403{
7404 if (inst.cond != COND_ALWAYS)
7405 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7406 " the behaviour is UNPREDICTABLE"));
7407 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7408 _(BAD_FP16));
7409
7410 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7411 mark_feature_used (&arm_ext_fp16);
7412}
7413
c19d1205
ZW
7414/* If VAL can be encoded in the immediate field of an ARM instruction,
7415 return the encoded form. Otherwise, return FAIL. */
7416
7417static unsigned int
7418encode_arm_immediate (unsigned int val)
09d92015 7419{
c19d1205
ZW
7420 unsigned int a, i;
7421
4f1d6205
L
7422 if (val <= 0xff)
7423 return val;
7424
7425 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7426 if ((a = rotate_left (val, i)) <= 0xff)
7427 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7428
7429 return FAIL;
09d92015
MM
7430}
7431
c19d1205
ZW
7432/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7433 return the encoded form. Otherwise, return FAIL. */
7434static unsigned int
7435encode_thumb32_immediate (unsigned int val)
09d92015 7436{
c19d1205 7437 unsigned int a, i;
09d92015 7438
9c3c69f2 7439 if (val <= 0xff)
c19d1205 7440 return val;
a737bd4d 7441
9c3c69f2 7442 for (i = 1; i <= 24; i++)
09d92015 7443 {
9c3c69f2
PB
7444 a = val >> i;
7445 if ((val & ~(0xff << i)) == 0)
7446 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7447 }
a737bd4d 7448
c19d1205
ZW
7449 a = val & 0xff;
7450 if (val == ((a << 16) | a))
7451 return 0x100 | a;
7452 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7453 return 0x300 | a;
09d92015 7454
c19d1205
ZW
7455 a = val & 0xff00;
7456 if (val == ((a << 16) | a))
7457 return 0x200 | (a >> 8);
a737bd4d 7458
c19d1205 7459 return FAIL;
09d92015 7460}
5287ad62 7461/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7462
7463static void
5287ad62
JB
7464encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7465{
7466 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7467 && reg > 15)
7468 {
b1cc4aeb 7469 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7470 {
7471 if (thumb_mode)
7472 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7473 fpu_vfp_ext_d32);
7474 else
7475 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7476 fpu_vfp_ext_d32);
7477 }
5287ad62 7478 else
477330fc
RM
7479 {
7480 first_error (_("D register out of range for selected VFP version"));
7481 return;
7482 }
5287ad62
JB
7483 }
7484
c19d1205 7485 switch (pos)
09d92015 7486 {
c19d1205
ZW
7487 case VFP_REG_Sd:
7488 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7489 break;
7490
7491 case VFP_REG_Sn:
7492 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7493 break;
7494
7495 case VFP_REG_Sm:
7496 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7497 break;
7498
5287ad62
JB
7499 case VFP_REG_Dd:
7500 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7501 break;
5f4273c7 7502
5287ad62
JB
7503 case VFP_REG_Dn:
7504 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7505 break;
5f4273c7 7506
5287ad62
JB
7507 case VFP_REG_Dm:
7508 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7509 break;
7510
c19d1205
ZW
7511 default:
7512 abort ();
09d92015 7513 }
09d92015
MM
7514}
7515
c19d1205 7516/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7517 if any, is handled by md_apply_fix. */
09d92015 7518static void
c19d1205 7519encode_arm_shift (int i)
09d92015 7520{
008a97ef
RL
7521 /* register-shifted register. */
7522 if (inst.operands[i].immisreg)
7523 {
bf355b69
MR
7524 int op_index;
7525 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7526 {
5689c942
RL
7527 /* Check the operand only when it's presented. In pre-UAL syntax,
7528 if the destination register is the same as the first operand, two
7529 register form of the instruction can be used. */
bf355b69
MR
7530 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7531 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7532 as_warn (UNPRED_REG ("r15"));
7533 }
7534
7535 if (inst.operands[i].imm == REG_PC)
7536 as_warn (UNPRED_REG ("r15"));
7537 }
7538
c19d1205
ZW
7539 if (inst.operands[i].shift_kind == SHIFT_RRX)
7540 inst.instruction |= SHIFT_ROR << 5;
7541 else
09d92015 7542 {
c19d1205
ZW
7543 inst.instruction |= inst.operands[i].shift_kind << 5;
7544 if (inst.operands[i].immisreg)
7545 {
7546 inst.instruction |= SHIFT_BY_REG;
7547 inst.instruction |= inst.operands[i].imm << 8;
7548 }
7549 else
7550 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7551 }
c19d1205 7552}
09d92015 7553
c19d1205
ZW
7554static void
7555encode_arm_shifter_operand (int i)
7556{
7557 if (inst.operands[i].isreg)
09d92015 7558 {
c19d1205
ZW
7559 inst.instruction |= inst.operands[i].reg;
7560 encode_arm_shift (i);
09d92015 7561 }
c19d1205 7562 else
a415b1cd
JB
7563 {
7564 inst.instruction |= INST_IMMEDIATE;
7565 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7566 inst.instruction |= inst.operands[i].imm;
7567 }
09d92015
MM
7568}
7569
c19d1205 7570/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7571static void
c19d1205 7572encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7573{
2b2f5df9
NC
7574 /* PR 14260:
7575 Generate an error if the operand is not a register. */
7576 constraint (!inst.operands[i].isreg,
7577 _("Instruction does not support =N addresses"));
7578
c19d1205 7579 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7580
c19d1205 7581 if (inst.operands[i].preind)
09d92015 7582 {
c19d1205
ZW
7583 if (is_t)
7584 {
7585 inst.error = _("instruction does not accept preindexed addressing");
7586 return;
7587 }
7588 inst.instruction |= PRE_INDEX;
7589 if (inst.operands[i].writeback)
7590 inst.instruction |= WRITE_BACK;
09d92015 7591
c19d1205
ZW
7592 }
7593 else if (inst.operands[i].postind)
7594 {
9c2799c2 7595 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7596 if (is_t)
7597 inst.instruction |= WRITE_BACK;
7598 }
7599 else /* unindexed - only for coprocessor */
09d92015 7600 {
c19d1205 7601 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7602 return;
7603 }
7604
c19d1205
ZW
7605 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7606 && (((inst.instruction & 0x000f0000) >> 16)
7607 == ((inst.instruction & 0x0000f000) >> 12)))
7608 as_warn ((inst.instruction & LOAD_BIT)
7609 ? _("destination register same as write-back base")
7610 : _("source register same as write-back base"));
09d92015
MM
7611}
7612
c19d1205
ZW
7613/* inst.operands[i] was set up by parse_address. Encode it into an
7614 ARM-format mode 2 load or store instruction. If is_t is true,
7615 reject forms that cannot be used with a T instruction (i.e. not
7616 post-indexed). */
a737bd4d 7617static void
c19d1205 7618encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7619{
5be8be5d
DG
7620 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7621
c19d1205 7622 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7623
c19d1205 7624 if (inst.operands[i].immisreg)
09d92015 7625 {
5be8be5d
DG
7626 constraint ((inst.operands[i].imm == REG_PC
7627 || (is_pc && inst.operands[i].writeback)),
7628 BAD_PC_ADDRESSING);
c19d1205
ZW
7629 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7630 inst.instruction |= inst.operands[i].imm;
7631 if (!inst.operands[i].negative)
7632 inst.instruction |= INDEX_UP;
7633 if (inst.operands[i].shifted)
7634 {
7635 if (inst.operands[i].shift_kind == SHIFT_RRX)
7636 inst.instruction |= SHIFT_ROR << 5;
7637 else
7638 {
7639 inst.instruction |= inst.operands[i].shift_kind << 5;
7640 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7641 }
7642 }
09d92015 7643 }
c19d1205 7644 else /* immediate offset in inst.reloc */
09d92015 7645 {
5be8be5d
DG
7646 if (is_pc && !inst.reloc.pc_rel)
7647 {
7648 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7649
7650 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7651 cannot use PC in addressing.
7652 PC cannot be used in writeback addressing, either. */
7653 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7654 BAD_PC_ADDRESSING);
23a10334 7655
dc5ec521 7656 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7657 if (warn_on_deprecated
7658 && !is_load
7659 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7660 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7661 }
7662
c19d1205 7663 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7664 {
7665 /* Prefer + for zero encoded value. */
7666 if (!inst.operands[i].negative)
7667 inst.instruction |= INDEX_UP;
7668 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7669 }
09d92015 7670 }
09d92015
MM
7671}
7672
c19d1205
ZW
7673/* inst.operands[i] was set up by parse_address. Encode it into an
7674 ARM-format mode 3 load or store instruction. Reject forms that
7675 cannot be used with such instructions. If is_t is true, reject
7676 forms that cannot be used with a T instruction (i.e. not
7677 post-indexed). */
7678static void
7679encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7680{
c19d1205 7681 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7682 {
c19d1205
ZW
7683 inst.error = _("instruction does not accept scaled register index");
7684 return;
09d92015 7685 }
a737bd4d 7686
c19d1205 7687 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7688
c19d1205
ZW
7689 if (inst.operands[i].immisreg)
7690 {
5be8be5d 7691 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7692 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7693 BAD_PC_ADDRESSING);
eb9f3f00
JB
7694 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7695 BAD_PC_WRITEBACK);
c19d1205
ZW
7696 inst.instruction |= inst.operands[i].imm;
7697 if (!inst.operands[i].negative)
7698 inst.instruction |= INDEX_UP;
7699 }
7700 else /* immediate offset in inst.reloc */
7701 {
5be8be5d
DG
7702 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7703 && inst.operands[i].writeback),
7704 BAD_PC_WRITEBACK);
c19d1205
ZW
7705 inst.instruction |= HWOFFSET_IMM;
7706 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7707 {
7708 /* Prefer + for zero encoded value. */
7709 if (!inst.operands[i].negative)
7710 inst.instruction |= INDEX_UP;
7711
7712 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7713 }
c19d1205 7714 }
a737bd4d
NC
7715}
7716
8335d6aa
JW
7717/* Write immediate bits [7:0] to the following locations:
7718
7719 |28/24|23 19|18 16|15 4|3 0|
7720 | 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|
7721
7722 This function is used by VMOV/VMVN/VORR/VBIC. */
7723
7724static void
7725neon_write_immbits (unsigned immbits)
7726{
7727 inst.instruction |= immbits & 0xf;
7728 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7729 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7730}
7731
7732/* Invert low-order SIZE bits of XHI:XLO. */
7733
7734static void
7735neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7736{
7737 unsigned immlo = xlo ? *xlo : 0;
7738 unsigned immhi = xhi ? *xhi : 0;
7739
7740 switch (size)
7741 {
7742 case 8:
7743 immlo = (~immlo) & 0xff;
7744 break;
7745
7746 case 16:
7747 immlo = (~immlo) & 0xffff;
7748 break;
7749
7750 case 64:
7751 immhi = (~immhi) & 0xffffffff;
7752 /* fall through. */
7753
7754 case 32:
7755 immlo = (~immlo) & 0xffffffff;
7756 break;
7757
7758 default:
7759 abort ();
7760 }
7761
7762 if (xlo)
7763 *xlo = immlo;
7764
7765 if (xhi)
7766 *xhi = immhi;
7767}
7768
7769/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7770 A, B, C, D. */
09d92015 7771
c19d1205 7772static int
8335d6aa 7773neon_bits_same_in_bytes (unsigned imm)
09d92015 7774{
8335d6aa
JW
7775 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7776 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7777 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7778 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7779}
a737bd4d 7780
8335d6aa 7781/* For immediate of above form, return 0bABCD. */
09d92015 7782
8335d6aa
JW
7783static unsigned
7784neon_squash_bits (unsigned imm)
7785{
7786 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7787 | ((imm & 0x01000000) >> 21);
7788}
7789
7790/* Compress quarter-float representation to 0b...000 abcdefgh. */
7791
7792static unsigned
7793neon_qfloat_bits (unsigned imm)
7794{
7795 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7796}
7797
7798/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7799 the instruction. *OP is passed as the initial value of the op field, and
7800 may be set to a different value depending on the constant (i.e.
7801 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7802 MVN). If the immediate looks like a repeated pattern then also
7803 try smaller element sizes. */
7804
7805static int
7806neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7807 unsigned *immbits, int *op, int size,
7808 enum neon_el_type type)
7809{
7810 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7811 float. */
7812 if (type == NT_float && !float_p)
7813 return FAIL;
7814
7815 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7816 {
8335d6aa
JW
7817 if (size != 32 || *op == 1)
7818 return FAIL;
7819 *immbits = neon_qfloat_bits (immlo);
7820 return 0xf;
7821 }
7822
7823 if (size == 64)
7824 {
7825 if (neon_bits_same_in_bytes (immhi)
7826 && neon_bits_same_in_bytes (immlo))
c19d1205 7827 {
8335d6aa
JW
7828 if (*op == 1)
7829 return FAIL;
7830 *immbits = (neon_squash_bits (immhi) << 4)
7831 | neon_squash_bits (immlo);
7832 *op = 1;
7833 return 0xe;
c19d1205 7834 }
a737bd4d 7835
8335d6aa
JW
7836 if (immhi != immlo)
7837 return FAIL;
7838 }
a737bd4d 7839
8335d6aa 7840 if (size >= 32)
09d92015 7841 {
8335d6aa 7842 if (immlo == (immlo & 0x000000ff))
c19d1205 7843 {
8335d6aa
JW
7844 *immbits = immlo;
7845 return 0x0;
c19d1205 7846 }
8335d6aa 7847 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7848 {
8335d6aa
JW
7849 *immbits = immlo >> 8;
7850 return 0x2;
c19d1205 7851 }
8335d6aa
JW
7852 else if (immlo == (immlo & 0x00ff0000))
7853 {
7854 *immbits = immlo >> 16;
7855 return 0x4;
7856 }
7857 else if (immlo == (immlo & 0xff000000))
7858 {
7859 *immbits = immlo >> 24;
7860 return 0x6;
7861 }
7862 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7863 {
7864 *immbits = (immlo >> 8) & 0xff;
7865 return 0xc;
7866 }
7867 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7868 {
7869 *immbits = (immlo >> 16) & 0xff;
7870 return 0xd;
7871 }
7872
7873 if ((immlo & 0xffff) != (immlo >> 16))
7874 return FAIL;
7875 immlo &= 0xffff;
09d92015 7876 }
a737bd4d 7877
8335d6aa 7878 if (size >= 16)
4962c51a 7879 {
8335d6aa
JW
7880 if (immlo == (immlo & 0x000000ff))
7881 {
7882 *immbits = immlo;
7883 return 0x8;
7884 }
7885 else if (immlo == (immlo & 0x0000ff00))
7886 {
7887 *immbits = immlo >> 8;
7888 return 0xa;
7889 }
7890
7891 if ((immlo & 0xff) != (immlo >> 8))
7892 return FAIL;
7893 immlo &= 0xff;
4962c51a
MS
7894 }
7895
8335d6aa
JW
7896 if (immlo == (immlo & 0x000000ff))
7897 {
7898 /* Don't allow MVN with 8-bit immediate. */
7899 if (*op == 1)
7900 return FAIL;
7901 *immbits = immlo;
7902 return 0xe;
7903 }
26d97720 7904
8335d6aa 7905 return FAIL;
c19d1205 7906}
a737bd4d 7907
5fc177c8 7908#if defined BFD_HOST_64_BIT
ba592044
AM
7909/* Returns TRUE if double precision value V may be cast
7910 to single precision without loss of accuracy. */
7911
7912static bfd_boolean
5fc177c8 7913is_double_a_single (bfd_int64_t v)
ba592044 7914{
5fc177c8 7915 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7916 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7917
7918 return (exp == 0 || exp == 0x7FF
7919 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7920 && (mantissa & 0x1FFFFFFFl) == 0;
7921}
7922
3739860c 7923/* Returns a double precision value casted to single precision
ba592044
AM
7924 (ignoring the least significant bits in exponent and mantissa). */
7925
7926static int
5fc177c8 7927double_to_single (bfd_int64_t v)
ba592044
AM
7928{
7929 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7930 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7931 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7932
7933 if (exp == 0x7FF)
7934 exp = 0xFF;
7935 else
7936 {
7937 exp = exp - 1023 + 127;
7938 if (exp >= 0xFF)
7939 {
7940 /* Infinity. */
7941 exp = 0x7F;
7942 mantissa = 0;
7943 }
7944 else if (exp < 0)
7945 {
7946 /* No denormalized numbers. */
7947 exp = 0;
7948 mantissa = 0;
7949 }
7950 }
7951 mantissa >>= 29;
7952 return (sign << 31) | (exp << 23) | mantissa;
7953}
5fc177c8 7954#endif /* BFD_HOST_64_BIT */
ba592044 7955
8335d6aa
JW
7956enum lit_type
7957{
7958 CONST_THUMB,
7959 CONST_ARM,
7960 CONST_VEC
7961};
7962
ba592044
AM
7963static void do_vfp_nsyn_opcode (const char *);
7964
c19d1205
ZW
7965/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7966 Determine whether it can be performed with a move instruction; if
7967 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7968 return TRUE; if it can't, convert inst.instruction to a literal-pool
7969 load and return FALSE. If this is not a valid thing to do in the
7970 current context, set inst.error and return TRUE.
a737bd4d 7971
c19d1205
ZW
7972 inst.operands[i] describes the destination register. */
7973
c921be7d 7974static bfd_boolean
8335d6aa 7975move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7976{
53365c0d 7977 unsigned long tbit;
8335d6aa
JW
7978 bfd_boolean thumb_p = (t == CONST_THUMB);
7979 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7980
7981 if (thumb_p)
7982 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7983 else
7984 tbit = LOAD_BIT;
7985
7986 if ((inst.instruction & tbit) == 0)
09d92015 7987 {
c19d1205 7988 inst.error = _("invalid pseudo operation");
c921be7d 7989 return TRUE;
09d92015 7990 }
ba592044 7991
8335d6aa
JW
7992 if (inst.reloc.exp.X_op != O_constant
7993 && inst.reloc.exp.X_op != O_symbol
7994 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7995 {
7996 inst.error = _("constant expression expected");
c921be7d 7997 return TRUE;
09d92015 7998 }
ba592044
AM
7999
8000 if (inst.reloc.exp.X_op == O_constant
8001 || inst.reloc.exp.X_op == O_big)
8335d6aa 8002 {
5fc177c8
NC
8003#if defined BFD_HOST_64_BIT
8004 bfd_int64_t v;
8005#else
ba592044 8006 offsetT v;
5fc177c8 8007#endif
ba592044 8008 if (inst.reloc.exp.X_op == O_big)
8335d6aa 8009 {
ba592044
AM
8010 LITTLENUM_TYPE w[X_PRECISION];
8011 LITTLENUM_TYPE * l;
8012
8013 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 8014 {
ba592044
AM
8015 gen_to_words (w, X_PRECISION, E_PRECISION);
8016 l = w;
8017 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 8018 }
ba592044
AM
8019 else
8020 l = generic_bignum;
3739860c 8021
5fc177c8
NC
8022#if defined BFD_HOST_64_BIT
8023 v =
8024 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8025 << LITTLENUM_NUMBER_OF_BITS)
8026 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8027 << LITTLENUM_NUMBER_OF_BITS)
8028 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8029 << LITTLENUM_NUMBER_OF_BITS)
8030 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8031#else
ba592044
AM
8032 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8033 | (l[0] & LITTLENUM_MASK);
5fc177c8 8034#endif
8335d6aa 8035 }
ba592044
AM
8036 else
8037 v = inst.reloc.exp.X_add_number;
8038
8039 if (!inst.operands[i].issingle)
8335d6aa 8040 {
12569877 8041 if (thumb_p)
8335d6aa 8042 {
53445554
TP
8043 /* LDR should not use lead in a flag-setting instruction being
8044 chosen so we do not check whether movs can be used. */
12569877 8045
53445554 8046 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8047 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8048 && inst.operands[i].reg != 13
8049 && inst.operands[i].reg != 15)
12569877 8050 {
fc289b0a
TP
8051 /* Check if on thumb2 it can be done with a mov.w, mvn or
8052 movw instruction. */
12569877
AM
8053 unsigned int newimm;
8054 bfd_boolean isNegated;
8055
8056 newimm = encode_thumb32_immediate (v);
8057 if (newimm != (unsigned int) FAIL)
8058 isNegated = FALSE;
8059 else
8060 {
582cfe03 8061 newimm = encode_thumb32_immediate (~v);
12569877
AM
8062 if (newimm != (unsigned int) FAIL)
8063 isNegated = TRUE;
8064 }
8065
fc289b0a
TP
8066 /* The number can be loaded with a mov.w or mvn
8067 instruction. */
ff8646ee
TP
8068 if (newimm != (unsigned int) FAIL
8069 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8070 {
fc289b0a 8071 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8072 | (inst.operands[i].reg << 8));
fc289b0a 8073 /* Change to MOVN. */
582cfe03 8074 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8075 inst.instruction |= (newimm & 0x800) << 15;
8076 inst.instruction |= (newimm & 0x700) << 4;
8077 inst.instruction |= (newimm & 0x0ff);
8078 return TRUE;
8079 }
fc289b0a 8080 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8081 else if ((v & ~0xFFFF) == 0
8082 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8083 {
582cfe03 8084 int imm = v & 0xFFFF;
12569877 8085
582cfe03 8086 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8087 inst.instruction |= (inst.operands[i].reg << 8);
8088 inst.instruction |= (imm & 0xf000) << 4;
8089 inst.instruction |= (imm & 0x0800) << 15;
8090 inst.instruction |= (imm & 0x0700) << 4;
8091 inst.instruction |= (imm & 0x00ff);
8092 return TRUE;
8093 }
8094 }
8335d6aa 8095 }
12569877 8096 else if (arm_p)
ba592044
AM
8097 {
8098 int value = encode_arm_immediate (v);
12569877 8099
ba592044
AM
8100 if (value != FAIL)
8101 {
8102 /* This can be done with a mov instruction. */
8103 inst.instruction &= LITERAL_MASK;
8104 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8105 inst.instruction |= value & 0xfff;
8106 return TRUE;
8107 }
8335d6aa 8108
ba592044
AM
8109 value = encode_arm_immediate (~ v);
8110 if (value != FAIL)
8111 {
8112 /* This can be done with a mvn instruction. */
8113 inst.instruction &= LITERAL_MASK;
8114 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8115 inst.instruction |= value & 0xfff;
8116 return TRUE;
8117 }
8118 }
934c2632 8119 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8120 {
ba592044
AM
8121 int op = 0;
8122 unsigned immbits = 0;
8123 unsigned immlo = inst.operands[1].imm;
8124 unsigned immhi = inst.operands[1].regisimm
8125 ? inst.operands[1].reg
8126 : inst.reloc.exp.X_unsigned
8127 ? 0
8128 : ((bfd_int64_t)((int) immlo)) >> 32;
8129 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8130 &op, 64, NT_invtype);
8131
8132 if (cmode == FAIL)
8133 {
8134 neon_invert_size (&immlo, &immhi, 64);
8135 op = !op;
8136 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8137 &op, 64, NT_invtype);
8138 }
8139
8140 if (cmode != FAIL)
8141 {
8142 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8143 | (1 << 23)
8144 | (cmode << 8)
8145 | (op << 5)
8146 | (1 << 4);
8147
8148 /* Fill other bits in vmov encoding for both thumb and arm. */
8149 if (thumb_mode)
eff0bc54 8150 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8151 else
eff0bc54 8152 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8153 neon_write_immbits (immbits);
8154 return TRUE;
8155 }
8335d6aa
JW
8156 }
8157 }
8335d6aa 8158
ba592044
AM
8159 if (t == CONST_VEC)
8160 {
8161 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8162 if (inst.operands[i].issingle
8163 && is_quarter_float (inst.operands[1].imm)
8164 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8165 {
ba592044
AM
8166 inst.operands[1].imm =
8167 neon_qfloat_bits (v);
8168 do_vfp_nsyn_opcode ("fconsts");
8169 return TRUE;
8335d6aa 8170 }
5fc177c8
NC
8171
8172 /* If our host does not support a 64-bit type then we cannot perform
8173 the following optimization. This mean that there will be a
8174 discrepancy between the output produced by an assembler built for
8175 a 32-bit-only host and the output produced from a 64-bit host, but
8176 this cannot be helped. */
8177#if defined BFD_HOST_64_BIT
ba592044
AM
8178 else if (!inst.operands[1].issingle
8179 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8180 {
ba592044
AM
8181 if (is_double_a_single (v)
8182 && is_quarter_float (double_to_single (v)))
8183 {
8184 inst.operands[1].imm =
8185 neon_qfloat_bits (double_to_single (v));
8186 do_vfp_nsyn_opcode ("fconstd");
8187 return TRUE;
8188 }
8335d6aa 8189 }
5fc177c8 8190#endif
8335d6aa
JW
8191 }
8192 }
8193
8194 if (add_to_lit_pool ((!inst.operands[i].isvec
8195 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8196 return TRUE;
8197
8198 inst.operands[1].reg = REG_PC;
8199 inst.operands[1].isreg = 1;
8200 inst.operands[1].preind = 1;
8201 inst.reloc.pc_rel = 1;
8202 inst.reloc.type = (thumb_p
8203 ? BFD_RELOC_ARM_THUMB_OFFSET
8204 : (mode_3
8205 ? BFD_RELOC_ARM_HWLITERAL
8206 : BFD_RELOC_ARM_LITERAL));
8207 return FALSE;
8208}
8209
8210/* inst.operands[i] was set up by parse_address. Encode it into an
8211 ARM-format instruction. Reject all forms which cannot be encoded
8212 into a coprocessor load/store instruction. If wb_ok is false,
8213 reject use of writeback; if unind_ok is false, reject use of
8214 unindexed addressing. If reloc_override is not 0, use it instead
8215 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8216 (in which case it is preserved). */
8217
8218static int
8219encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8220{
8221 if (!inst.operands[i].isreg)
8222 {
99b2a2dd
NC
8223 /* PR 18256 */
8224 if (! inst.operands[0].isvec)
8225 {
8226 inst.error = _("invalid co-processor operand");
8227 return FAIL;
8228 }
8335d6aa
JW
8229 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8230 return SUCCESS;
8231 }
8232
8233 inst.instruction |= inst.operands[i].reg << 16;
8234
8235 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8236
8237 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8238 {
8239 gas_assert (!inst.operands[i].writeback);
8240 if (!unind_ok)
8241 {
8242 inst.error = _("instruction does not support unindexed addressing");
8243 return FAIL;
8244 }
8245 inst.instruction |= inst.operands[i].imm;
8246 inst.instruction |= INDEX_UP;
8247 return SUCCESS;
8248 }
8249
8250 if (inst.operands[i].preind)
8251 inst.instruction |= PRE_INDEX;
8252
8253 if (inst.operands[i].writeback)
09d92015 8254 {
8335d6aa 8255 if (inst.operands[i].reg == REG_PC)
c19d1205 8256 {
8335d6aa
JW
8257 inst.error = _("pc may not be used with write-back");
8258 return FAIL;
c19d1205 8259 }
8335d6aa 8260 if (!wb_ok)
c19d1205 8261 {
8335d6aa
JW
8262 inst.error = _("instruction does not support writeback");
8263 return FAIL;
c19d1205 8264 }
8335d6aa 8265 inst.instruction |= WRITE_BACK;
09d92015
MM
8266 }
8267
8335d6aa
JW
8268 if (reloc_override)
8269 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8270 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8271 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8272 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8273 {
8335d6aa
JW
8274 if (thumb_mode)
8275 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8276 else
8277 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8278 }
8335d6aa
JW
8279
8280 /* Prefer + for zero encoded value. */
8281 if (!inst.operands[i].negative)
8282 inst.instruction |= INDEX_UP;
8283
8284 return SUCCESS;
09d92015
MM
8285}
8286
5f4273c7 8287/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8288 First some generics; their names are taken from the conventional
8289 bit positions for register arguments in ARM format instructions. */
09d92015 8290
a737bd4d 8291static void
c19d1205 8292do_noargs (void)
09d92015 8293{
c19d1205 8294}
a737bd4d 8295
c19d1205
ZW
8296static void
8297do_rd (void)
8298{
8299 inst.instruction |= inst.operands[0].reg << 12;
8300}
a737bd4d 8301
16a1fa25
TP
8302static void
8303do_rn (void)
8304{
8305 inst.instruction |= inst.operands[0].reg << 16;
8306}
8307
c19d1205
ZW
8308static void
8309do_rd_rm (void)
8310{
8311 inst.instruction |= inst.operands[0].reg << 12;
8312 inst.instruction |= inst.operands[1].reg;
8313}
09d92015 8314
9eb6c0f1
MGD
8315static void
8316do_rm_rn (void)
8317{
8318 inst.instruction |= inst.operands[0].reg;
8319 inst.instruction |= inst.operands[1].reg << 16;
8320}
8321
c19d1205
ZW
8322static void
8323do_rd_rn (void)
8324{
8325 inst.instruction |= inst.operands[0].reg << 12;
8326 inst.instruction |= inst.operands[1].reg << 16;
8327}
a737bd4d 8328
c19d1205
ZW
8329static void
8330do_rn_rd (void)
8331{
8332 inst.instruction |= inst.operands[0].reg << 16;
8333 inst.instruction |= inst.operands[1].reg << 12;
8334}
09d92015 8335
4ed7ed8d
TP
8336static void
8337do_tt (void)
8338{
8339 inst.instruction |= inst.operands[0].reg << 8;
8340 inst.instruction |= inst.operands[1].reg << 16;
8341}
8342
59d09be6
MGD
8343static bfd_boolean
8344check_obsolete (const arm_feature_set *feature, const char *msg)
8345{
8346 if (ARM_CPU_IS_ANY (cpu_variant))
8347 {
5c3696f8 8348 as_tsktsk ("%s", msg);
59d09be6
MGD
8349 return TRUE;
8350 }
8351 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8352 {
8353 as_bad ("%s", msg);
8354 return TRUE;
8355 }
8356
8357 return FALSE;
8358}
8359
c19d1205
ZW
8360static void
8361do_rd_rm_rn (void)
8362{
9a64e435 8363 unsigned Rn = inst.operands[2].reg;
708587a4 8364 /* Enforce restrictions on SWP instruction. */
9a64e435 8365 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8366 {
8367 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8368 _("Rn must not overlap other operands"));
8369
59d09be6
MGD
8370 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8371 */
8372 if (!check_obsolete (&arm_ext_v8,
8373 _("swp{b} use is obsoleted for ARMv8 and later"))
8374 && warn_on_deprecated
8375 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8376 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8377 }
59d09be6 8378
c19d1205
ZW
8379 inst.instruction |= inst.operands[0].reg << 12;
8380 inst.instruction |= inst.operands[1].reg;
9a64e435 8381 inst.instruction |= Rn << 16;
c19d1205 8382}
09d92015 8383
c19d1205
ZW
8384static void
8385do_rd_rn_rm (void)
8386{
8387 inst.instruction |= inst.operands[0].reg << 12;
8388 inst.instruction |= inst.operands[1].reg << 16;
8389 inst.instruction |= inst.operands[2].reg;
8390}
a737bd4d 8391
c19d1205
ZW
8392static void
8393do_rm_rd_rn (void)
8394{
5be8be5d
DG
8395 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8396 constraint (((inst.reloc.exp.X_op != O_constant
8397 && inst.reloc.exp.X_op != O_illegal)
8398 || inst.reloc.exp.X_add_number != 0),
8399 BAD_ADDR_MODE);
c19d1205
ZW
8400 inst.instruction |= inst.operands[0].reg;
8401 inst.instruction |= inst.operands[1].reg << 12;
8402 inst.instruction |= inst.operands[2].reg << 16;
8403}
09d92015 8404
c19d1205
ZW
8405static void
8406do_imm0 (void)
8407{
8408 inst.instruction |= inst.operands[0].imm;
8409}
09d92015 8410
c19d1205
ZW
8411static void
8412do_rd_cpaddr (void)
8413{
8414 inst.instruction |= inst.operands[0].reg << 12;
8415 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8416}
a737bd4d 8417
c19d1205
ZW
8418/* ARM instructions, in alphabetical order by function name (except
8419 that wrapper functions appear immediately after the function they
8420 wrap). */
09d92015 8421
c19d1205
ZW
8422/* This is a pseudo-op of the form "adr rd, label" to be converted
8423 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8424
8425static void
c19d1205 8426do_adr (void)
09d92015 8427{
c19d1205 8428 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8429
c19d1205
ZW
8430 /* Frag hacking will turn this into a sub instruction if the offset turns
8431 out to be negative. */
8432 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8433 inst.reloc.pc_rel = 1;
2fc8bdac 8434 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8435
8436 if (inst.reloc.exp.X_op == O_symbol
8437 && inst.reloc.exp.X_add_symbol != NULL
8438 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8439 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8440 inst.reloc.exp.X_add_number += 1;
c19d1205 8441}
b99bd4ef 8442
c19d1205
ZW
8443/* This is a pseudo-op of the form "adrl rd, label" to be converted
8444 into a relative address of the form:
8445 add rd, pc, #low(label-.-8)"
8446 add rd, rd, #high(label-.-8)" */
b99bd4ef 8447
c19d1205
ZW
8448static void
8449do_adrl (void)
8450{
8451 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8452
c19d1205
ZW
8453 /* Frag hacking will turn this into a sub instruction if the offset turns
8454 out to be negative. */
8455 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8456 inst.reloc.pc_rel = 1;
8457 inst.size = INSN_SIZE * 2;
2fc8bdac 8458 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8459
8460 if (inst.reloc.exp.X_op == O_symbol
8461 && inst.reloc.exp.X_add_symbol != NULL
8462 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8463 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8464 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8465}
8466
b99bd4ef 8467static void
c19d1205 8468do_arit (void)
b99bd4ef 8469{
a9f02af8
MG
8470 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8471 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8472 THUMB1_RELOC_ONLY);
c19d1205
ZW
8473 if (!inst.operands[1].present)
8474 inst.operands[1].reg = inst.operands[0].reg;
8475 inst.instruction |= inst.operands[0].reg << 12;
8476 inst.instruction |= inst.operands[1].reg << 16;
8477 encode_arm_shifter_operand (2);
8478}
b99bd4ef 8479
62b3e311
PB
8480static void
8481do_barrier (void)
8482{
8483 if (inst.operands[0].present)
ccb84d65 8484 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8485 else
8486 inst.instruction |= 0xf;
8487}
8488
c19d1205
ZW
8489static void
8490do_bfc (void)
8491{
8492 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8493 constraint (msb > 32, _("bit-field extends past end of register"));
8494 /* The instruction encoding stores the LSB and MSB,
8495 not the LSB and width. */
8496 inst.instruction |= inst.operands[0].reg << 12;
8497 inst.instruction |= inst.operands[1].imm << 7;
8498 inst.instruction |= (msb - 1) << 16;
8499}
b99bd4ef 8500
c19d1205
ZW
8501static void
8502do_bfi (void)
8503{
8504 unsigned int msb;
b99bd4ef 8505
c19d1205
ZW
8506 /* #0 in second position is alternative syntax for bfc, which is
8507 the same instruction but with REG_PC in the Rm field. */
8508 if (!inst.operands[1].isreg)
8509 inst.operands[1].reg = REG_PC;
b99bd4ef 8510
c19d1205
ZW
8511 msb = inst.operands[2].imm + inst.operands[3].imm;
8512 constraint (msb > 32, _("bit-field extends past end of register"));
8513 /* The instruction encoding stores the LSB and MSB,
8514 not the LSB and width. */
8515 inst.instruction |= inst.operands[0].reg << 12;
8516 inst.instruction |= inst.operands[1].reg;
8517 inst.instruction |= inst.operands[2].imm << 7;
8518 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8519}
8520
b99bd4ef 8521static void
c19d1205 8522do_bfx (void)
b99bd4ef 8523{
c19d1205
ZW
8524 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8525 _("bit-field extends past end of register"));
8526 inst.instruction |= inst.operands[0].reg << 12;
8527 inst.instruction |= inst.operands[1].reg;
8528 inst.instruction |= inst.operands[2].imm << 7;
8529 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8530}
09d92015 8531
c19d1205
ZW
8532/* ARM V5 breakpoint instruction (argument parse)
8533 BKPT <16 bit unsigned immediate>
8534 Instruction is not conditional.
8535 The bit pattern given in insns[] has the COND_ALWAYS condition,
8536 and it is an error if the caller tried to override that. */
b99bd4ef 8537
c19d1205
ZW
8538static void
8539do_bkpt (void)
8540{
8541 /* Top 12 of 16 bits to bits 19:8. */
8542 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8543
c19d1205
ZW
8544 /* Bottom 4 of 16 bits to bits 3:0. */
8545 inst.instruction |= inst.operands[0].imm & 0xf;
8546}
09d92015 8547
c19d1205
ZW
8548static void
8549encode_branch (int default_reloc)
8550{
8551 if (inst.operands[0].hasreloc)
8552 {
0855e32b
NS
8553 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8554 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8555 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8556 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8557 ? BFD_RELOC_ARM_PLT32
8558 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8559 }
b99bd4ef 8560 else
9ae92b05 8561 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8562 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8563}
8564
b99bd4ef 8565static void
c19d1205 8566do_branch (void)
b99bd4ef 8567{
39b41c9c
PB
8568#ifdef OBJ_ELF
8569 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8570 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8571 else
8572#endif
8573 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8574}
8575
8576static void
8577do_bl (void)
8578{
8579#ifdef OBJ_ELF
8580 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8581 {
8582 if (inst.cond == COND_ALWAYS)
8583 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8584 else
8585 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8586 }
8587 else
8588#endif
8589 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8590}
b99bd4ef 8591
c19d1205
ZW
8592/* ARM V5 branch-link-exchange instruction (argument parse)
8593 BLX <target_addr> ie BLX(1)
8594 BLX{<condition>} <Rm> ie BLX(2)
8595 Unfortunately, there are two different opcodes for this mnemonic.
8596 So, the insns[].value is not used, and the code here zaps values
8597 into inst.instruction.
8598 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8599
c19d1205
ZW
8600static void
8601do_blx (void)
8602{
8603 if (inst.operands[0].isreg)
b99bd4ef 8604 {
c19d1205
ZW
8605 /* Arg is a register; the opcode provided by insns[] is correct.
8606 It is not illegal to do "blx pc", just useless. */
8607 if (inst.operands[0].reg == REG_PC)
8608 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8609
c19d1205
ZW
8610 inst.instruction |= inst.operands[0].reg;
8611 }
8612 else
b99bd4ef 8613 {
c19d1205 8614 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8615 conditionally, and the opcode must be adjusted.
8616 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8617 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8618 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8619 inst.instruction = 0xfa000000;
267bf995 8620 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8621 }
c19d1205
ZW
8622}
8623
8624static void
8625do_bx (void)
8626{
845b51d6
PB
8627 bfd_boolean want_reloc;
8628
c19d1205
ZW
8629 if (inst.operands[0].reg == REG_PC)
8630 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8631
c19d1205 8632 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8633 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8634 it is for ARMv4t or earlier. */
8635 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
4d354d8b
TP
8636 if (!ARM_FEATURE_ZERO (selected_object_arch)
8637 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
845b51d6
PB
8638 want_reloc = TRUE;
8639
5ad34203 8640#ifdef OBJ_ELF
845b51d6 8641 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8642#endif
584206db 8643 want_reloc = FALSE;
845b51d6
PB
8644
8645 if (want_reloc)
8646 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8647}
8648
c19d1205
ZW
8649
8650/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8651
8652static void
c19d1205 8653do_bxj (void)
a737bd4d 8654{
c19d1205
ZW
8655 if (inst.operands[0].reg == REG_PC)
8656 as_tsktsk (_("use of r15 in bxj is not really useful"));
8657
8658 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8659}
8660
c19d1205
ZW
8661/* Co-processor data operation:
8662 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8663 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8664static void
8665do_cdp (void)
8666{
8667 inst.instruction |= inst.operands[0].reg << 8;
8668 inst.instruction |= inst.operands[1].imm << 20;
8669 inst.instruction |= inst.operands[2].reg << 12;
8670 inst.instruction |= inst.operands[3].reg << 16;
8671 inst.instruction |= inst.operands[4].reg;
8672 inst.instruction |= inst.operands[5].imm << 5;
8673}
a737bd4d
NC
8674
8675static void
c19d1205 8676do_cmp (void)
a737bd4d 8677{
c19d1205
ZW
8678 inst.instruction |= inst.operands[0].reg << 16;
8679 encode_arm_shifter_operand (1);
a737bd4d
NC
8680}
8681
c19d1205
ZW
8682/* Transfer between coprocessor and ARM registers.
8683 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8684 MRC2
8685 MCR{cond}
8686 MCR2
8687
8688 No special properties. */
09d92015 8689
dcbd0d71
MGD
8690struct deprecated_coproc_regs_s
8691{
8692 unsigned cp;
8693 int opc1;
8694 unsigned crn;
8695 unsigned crm;
8696 int opc2;
8697 arm_feature_set deprecated;
8698 arm_feature_set obsoleted;
8699 const char *dep_msg;
8700 const char *obs_msg;
8701};
8702
8703#define DEPR_ACCESS_V8 \
8704 N_("This coprocessor register access is deprecated in ARMv8")
8705
8706/* Table of all deprecated coprocessor registers. */
8707static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8708{
8709 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8710 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8711 DEPR_ACCESS_V8, NULL},
8712 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8713 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8714 DEPR_ACCESS_V8, NULL},
8715 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8716 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8717 DEPR_ACCESS_V8, NULL},
8718 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8719 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8720 DEPR_ACCESS_V8, NULL},
8721 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8722 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8723 DEPR_ACCESS_V8, NULL},
8724};
8725
8726#undef DEPR_ACCESS_V8
8727
8728static const size_t deprecated_coproc_reg_count =
8729 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8730
09d92015 8731static void
c19d1205 8732do_co_reg (void)
09d92015 8733{
fdfde340 8734 unsigned Rd;
dcbd0d71 8735 size_t i;
fdfde340
JM
8736
8737 Rd = inst.operands[2].reg;
8738 if (thumb_mode)
8739 {
8740 if (inst.instruction == 0xee000010
8741 || inst.instruction == 0xfe000010)
8742 /* MCR, MCR2 */
8743 reject_bad_reg (Rd);
5c8ed6a4 8744 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8745 /* MRC, MRC2 */
8746 constraint (Rd == REG_SP, BAD_SP);
8747 }
8748 else
8749 {
8750 /* MCR */
8751 if (inst.instruction == 0xe000010)
8752 constraint (Rd == REG_PC, BAD_PC);
8753 }
8754
dcbd0d71
MGD
8755 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8756 {
8757 const struct deprecated_coproc_regs_s *r =
8758 deprecated_coproc_regs + i;
8759
8760 if (inst.operands[0].reg == r->cp
8761 && inst.operands[1].imm == r->opc1
8762 && inst.operands[3].reg == r->crn
8763 && inst.operands[4].reg == r->crm
8764 && inst.operands[5].imm == r->opc2)
8765 {
b10bf8c5 8766 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8767 && warn_on_deprecated
dcbd0d71 8768 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8769 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8770 }
8771 }
fdfde340 8772
c19d1205
ZW
8773 inst.instruction |= inst.operands[0].reg << 8;
8774 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8775 inst.instruction |= Rd << 12;
c19d1205
ZW
8776 inst.instruction |= inst.operands[3].reg << 16;
8777 inst.instruction |= inst.operands[4].reg;
8778 inst.instruction |= inst.operands[5].imm << 5;
8779}
09d92015 8780
c19d1205
ZW
8781/* Transfer between coprocessor register and pair of ARM registers.
8782 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8783 MCRR2
8784 MRRC{cond}
8785 MRRC2
b99bd4ef 8786
c19d1205 8787 Two XScale instructions are special cases of these:
09d92015 8788
c19d1205
ZW
8789 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8790 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8791
5f4273c7 8792 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8793
c19d1205
ZW
8794static void
8795do_co_reg2c (void)
8796{
fdfde340
JM
8797 unsigned Rd, Rn;
8798
8799 Rd = inst.operands[2].reg;
8800 Rn = inst.operands[3].reg;
8801
8802 if (thumb_mode)
8803 {
8804 reject_bad_reg (Rd);
8805 reject_bad_reg (Rn);
8806 }
8807 else
8808 {
8809 constraint (Rd == REG_PC, BAD_PC);
8810 constraint (Rn == REG_PC, BAD_PC);
8811 }
8812
873f10f0
TC
8813 /* Only check the MRRC{2} variants. */
8814 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8815 {
8816 /* If Rd == Rn, error that the operation is
8817 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8818 constraint (Rd == Rn, BAD_OVERLAP);
8819 }
8820
c19d1205
ZW
8821 inst.instruction |= inst.operands[0].reg << 8;
8822 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8823 inst.instruction |= Rd << 12;
8824 inst.instruction |= Rn << 16;
c19d1205 8825 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8826}
8827
c19d1205
ZW
8828static void
8829do_cpsi (void)
8830{
8831 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8832 if (inst.operands[1].present)
8833 {
8834 inst.instruction |= CPSI_MMOD;
8835 inst.instruction |= inst.operands[1].imm;
8836 }
c19d1205 8837}
b99bd4ef 8838
62b3e311
PB
8839static void
8840do_dbg (void)
8841{
8842 inst.instruction |= inst.operands[0].imm;
8843}
8844
eea54501
MGD
8845static void
8846do_div (void)
8847{
8848 unsigned Rd, Rn, Rm;
8849
8850 Rd = inst.operands[0].reg;
8851 Rn = (inst.operands[1].present
8852 ? inst.operands[1].reg : Rd);
8853 Rm = inst.operands[2].reg;
8854
8855 constraint ((Rd == REG_PC), BAD_PC);
8856 constraint ((Rn == REG_PC), BAD_PC);
8857 constraint ((Rm == REG_PC), BAD_PC);
8858
8859 inst.instruction |= Rd << 16;
8860 inst.instruction |= Rn << 0;
8861 inst.instruction |= Rm << 8;
8862}
8863
b99bd4ef 8864static void
c19d1205 8865do_it (void)
b99bd4ef 8866{
c19d1205 8867 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8868 process it to do the validation as if in
8869 thumb mode, just in case the code gets
8870 assembled for thumb using the unified syntax. */
8871
c19d1205 8872 inst.size = 0;
e07e6e58
NC
8873 if (unified_syntax)
8874 {
8875 set_it_insn_type (IT_INSN);
8876 now_it.mask = (inst.instruction & 0xf) | 0x10;
8877 now_it.cc = inst.operands[0].imm;
8878 }
09d92015 8879}
b99bd4ef 8880
6530b175
NC
8881/* If there is only one register in the register list,
8882 then return its register number. Otherwise return -1. */
8883static int
8884only_one_reg_in_list (int range)
8885{
8886 int i = ffs (range) - 1;
8887 return (i > 15 || range != (1 << i)) ? -1 : i;
8888}
8889
09d92015 8890static void
6530b175 8891encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8892{
c19d1205
ZW
8893 int base_reg = inst.operands[0].reg;
8894 int range = inst.operands[1].imm;
6530b175 8895 int one_reg;
ea6ef066 8896
c19d1205
ZW
8897 inst.instruction |= base_reg << 16;
8898 inst.instruction |= range;
ea6ef066 8899
c19d1205
ZW
8900 if (inst.operands[1].writeback)
8901 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8902
c19d1205 8903 if (inst.operands[0].writeback)
ea6ef066 8904 {
c19d1205
ZW
8905 inst.instruction |= WRITE_BACK;
8906 /* Check for unpredictable uses of writeback. */
8907 if (inst.instruction & LOAD_BIT)
09d92015 8908 {
c19d1205
ZW
8909 /* Not allowed in LDM type 2. */
8910 if ((inst.instruction & LDM_TYPE_2_OR_3)
8911 && ((range & (1 << REG_PC)) == 0))
8912 as_warn (_("writeback of base register is UNPREDICTABLE"));
8913 /* Only allowed if base reg not in list for other types. */
8914 else if (range & (1 << base_reg))
8915 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8916 }
8917 else /* STM. */
8918 {
8919 /* Not allowed for type 2. */
8920 if (inst.instruction & LDM_TYPE_2_OR_3)
8921 as_warn (_("writeback of base register is UNPREDICTABLE"));
8922 /* Only allowed if base reg not in list, or first in list. */
8923 else if ((range & (1 << base_reg))
8924 && (range & ((1 << base_reg) - 1)))
8925 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8926 }
ea6ef066 8927 }
6530b175
NC
8928
8929 /* If PUSH/POP has only one register, then use the A2 encoding. */
8930 one_reg = only_one_reg_in_list (range);
8931 if (from_push_pop_mnem && one_reg >= 0)
8932 {
8933 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8934
4f588891
NC
8935 if (is_push && one_reg == 13 /* SP */)
8936 /* PR 22483: The A2 encoding cannot be used when
8937 pushing the stack pointer as this is UNPREDICTABLE. */
8938 return;
8939
6530b175
NC
8940 inst.instruction &= A_COND_MASK;
8941 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8942 inst.instruction |= one_reg << 12;
8943 }
8944}
8945
8946static void
8947do_ldmstm (void)
8948{
8949 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8950}
8951
c19d1205
ZW
8952/* ARMv5TE load-consecutive (argument parse)
8953 Mode is like LDRH.
8954
8955 LDRccD R, mode
8956 STRccD R, mode. */
8957
a737bd4d 8958static void
c19d1205 8959do_ldrd (void)
a737bd4d 8960{
c19d1205 8961 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8962 _("first transfer register must be even"));
c19d1205
ZW
8963 constraint (inst.operands[1].present
8964 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8965 _("can only transfer two consecutive registers"));
c19d1205
ZW
8966 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8967 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8968
c19d1205
ZW
8969 if (!inst.operands[1].present)
8970 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8971
c56791bb
RE
8972 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8973 register and the first register written; we have to diagnose
8974 overlap between the base and the second register written here. */
ea6ef066 8975
c56791bb
RE
8976 if (inst.operands[2].reg == inst.operands[1].reg
8977 && (inst.operands[2].writeback || inst.operands[2].postind))
8978 as_warn (_("base register written back, and overlaps "
8979 "second transfer register"));
b05fe5cf 8980
c56791bb
RE
8981 if (!(inst.instruction & V4_STR_BIT))
8982 {
c19d1205 8983 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8984 destination (even if not write-back). */
8985 if (inst.operands[2].immisreg
8986 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8987 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8988 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8989 }
c19d1205
ZW
8990 inst.instruction |= inst.operands[0].reg << 12;
8991 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8992}
8993
8994static void
c19d1205 8995do_ldrex (void)
b05fe5cf 8996{
c19d1205
ZW
8997 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8998 || inst.operands[1].postind || inst.operands[1].writeback
8999 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
9000 || inst.operands[1].negative
9001 /* This can arise if the programmer has written
9002 strex rN, rM, foo
9003 or if they have mistakenly used a register name as the last
9004 operand, eg:
9005 strex rN, rM, rX
9006 It is very difficult to distinguish between these two cases
9007 because "rX" might actually be a label. ie the register
9008 name has been occluded by a symbol of the same name. So we
9009 just generate a general 'bad addressing mode' type error
9010 message and leave it up to the programmer to discover the
9011 true cause and fix their mistake. */
9012 || (inst.operands[1].reg == REG_PC),
9013 BAD_ADDR_MODE);
b05fe5cf 9014
c19d1205
ZW
9015 constraint (inst.reloc.exp.X_op != O_constant
9016 || inst.reloc.exp.X_add_number != 0,
9017 _("offset must be zero in ARM encoding"));
b05fe5cf 9018
5be8be5d
DG
9019 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9020
c19d1205
ZW
9021 inst.instruction |= inst.operands[0].reg << 12;
9022 inst.instruction |= inst.operands[1].reg << 16;
9023 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
9024}
9025
9026static void
c19d1205 9027do_ldrexd (void)
b05fe5cf 9028{
c19d1205
ZW
9029 constraint (inst.operands[0].reg % 2 != 0,
9030 _("even register required"));
9031 constraint (inst.operands[1].present
9032 && inst.operands[1].reg != inst.operands[0].reg + 1,
9033 _("can only load two consecutive registers"));
9034 /* If op 1 were present and equal to PC, this function wouldn't
9035 have been called in the first place. */
9036 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9037
c19d1205
ZW
9038 inst.instruction |= inst.operands[0].reg << 12;
9039 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9040}
9041
1be5fd2e
NC
9042/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9043 which is not a multiple of four is UNPREDICTABLE. */
9044static void
9045check_ldr_r15_aligned (void)
9046{
9047 constraint (!(inst.operands[1].immisreg)
9048 && (inst.operands[0].reg == REG_PC
9049 && inst.operands[1].reg == REG_PC
9050 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 9051 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9052}
9053
b05fe5cf 9054static void
c19d1205 9055do_ldst (void)
b05fe5cf 9056{
c19d1205
ZW
9057 inst.instruction |= inst.operands[0].reg << 12;
9058 if (!inst.operands[1].isreg)
8335d6aa 9059 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9060 return;
c19d1205 9061 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9062 check_ldr_r15_aligned ();
b05fe5cf
ZW
9063}
9064
9065static void
c19d1205 9066do_ldstt (void)
b05fe5cf 9067{
c19d1205
ZW
9068 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9069 reject [Rn,...]. */
9070 if (inst.operands[1].preind)
b05fe5cf 9071 {
bd3ba5d1
NC
9072 constraint (inst.reloc.exp.X_op != O_constant
9073 || inst.reloc.exp.X_add_number != 0,
c19d1205 9074 _("this instruction requires a post-indexed address"));
b05fe5cf 9075
c19d1205
ZW
9076 inst.operands[1].preind = 0;
9077 inst.operands[1].postind = 1;
9078 inst.operands[1].writeback = 1;
b05fe5cf 9079 }
c19d1205
ZW
9080 inst.instruction |= inst.operands[0].reg << 12;
9081 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9082}
b05fe5cf 9083
c19d1205 9084/* Halfword and signed-byte load/store operations. */
b05fe5cf 9085
c19d1205
ZW
9086static void
9087do_ldstv4 (void)
9088{
ff4a8d2b 9089 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9090 inst.instruction |= inst.operands[0].reg << 12;
9091 if (!inst.operands[1].isreg)
8335d6aa 9092 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9093 return;
c19d1205 9094 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9095}
9096
9097static void
c19d1205 9098do_ldsttv4 (void)
b05fe5cf 9099{
c19d1205
ZW
9100 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9101 reject [Rn,...]. */
9102 if (inst.operands[1].preind)
b05fe5cf 9103 {
bd3ba5d1
NC
9104 constraint (inst.reloc.exp.X_op != O_constant
9105 || inst.reloc.exp.X_add_number != 0,
c19d1205 9106 _("this instruction requires a post-indexed address"));
b05fe5cf 9107
c19d1205
ZW
9108 inst.operands[1].preind = 0;
9109 inst.operands[1].postind = 1;
9110 inst.operands[1].writeback = 1;
b05fe5cf 9111 }
c19d1205
ZW
9112 inst.instruction |= inst.operands[0].reg << 12;
9113 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9114}
b05fe5cf 9115
c19d1205
ZW
9116/* Co-processor register load/store.
9117 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9118static void
9119do_lstc (void)
9120{
9121 inst.instruction |= inst.operands[0].reg << 8;
9122 inst.instruction |= inst.operands[1].reg << 12;
9123 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9124}
9125
b05fe5cf 9126static void
c19d1205 9127do_mlas (void)
b05fe5cf 9128{
8fb9d7b9 9129 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9130 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9131 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9132 && !(inst.instruction & 0x00400000))
8fb9d7b9 9133 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9134
c19d1205
ZW
9135 inst.instruction |= inst.operands[0].reg << 16;
9136 inst.instruction |= inst.operands[1].reg;
9137 inst.instruction |= inst.operands[2].reg << 8;
9138 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9139}
b05fe5cf 9140
c19d1205
ZW
9141static void
9142do_mov (void)
9143{
a9f02af8
MG
9144 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9145 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9146 THUMB1_RELOC_ONLY);
c19d1205
ZW
9147 inst.instruction |= inst.operands[0].reg << 12;
9148 encode_arm_shifter_operand (1);
9149}
b05fe5cf 9150
c19d1205
ZW
9151/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9152static void
9153do_mov16 (void)
9154{
b6895b4f
PB
9155 bfd_vma imm;
9156 bfd_boolean top;
9157
9158 top = (inst.instruction & 0x00400000) != 0;
9159 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9160 _(":lower16: not allowed in this instruction"));
b6895b4f 9161 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9162 _(":upper16: not allowed in this instruction"));
c19d1205 9163 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9164 if (inst.reloc.type == BFD_RELOC_UNUSED)
9165 {
9166 imm = inst.reloc.exp.X_add_number;
9167 /* The value is in two pieces: 0:11, 16:19. */
9168 inst.instruction |= (imm & 0x00000fff);
9169 inst.instruction |= (imm & 0x0000f000) << 4;
9170 }
b05fe5cf 9171}
b99bd4ef 9172
037e8744
JB
9173static int
9174do_vfp_nsyn_mrs (void)
9175{
9176 if (inst.operands[0].isvec)
9177 {
9178 if (inst.operands[1].reg != 1)
477330fc 9179 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9180 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9181 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9182 do_vfp_nsyn_opcode ("fmstat");
9183 }
9184 else if (inst.operands[1].isvec)
9185 do_vfp_nsyn_opcode ("fmrx");
9186 else
9187 return FAIL;
5f4273c7 9188
037e8744
JB
9189 return SUCCESS;
9190}
9191
9192static int
9193do_vfp_nsyn_msr (void)
9194{
9195 if (inst.operands[0].isvec)
9196 do_vfp_nsyn_opcode ("fmxr");
9197 else
9198 return FAIL;
9199
9200 return SUCCESS;
9201}
9202
f7c21dc7
NC
9203static void
9204do_vmrs (void)
9205{
9206 unsigned Rt = inst.operands[0].reg;
fa94de6b 9207
16d02dc9 9208 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9209 {
9210 inst.error = BAD_SP;
9211 return;
9212 }
9213
40c7d507
RR
9214 /* MVFR2 is only valid at ARMv8-A. */
9215 if (inst.operands[1].reg == 5)
9216 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9217 _(BAD_FPU));
9218
f7c21dc7 9219 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9220 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9221 {
9222 inst.error = BAD_PC;
9223 return;
9224 }
9225
16d02dc9
JB
9226 /* If we get through parsing the register name, we just insert the number
9227 generated into the instruction without further validation. */
9228 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9229 inst.instruction |= (Rt << 12);
9230}
9231
9232static void
9233do_vmsr (void)
9234{
9235 unsigned Rt = inst.operands[1].reg;
fa94de6b 9236
f7c21dc7
NC
9237 if (thumb_mode)
9238 reject_bad_reg (Rt);
9239 else if (Rt == REG_PC)
9240 {
9241 inst.error = BAD_PC;
9242 return;
9243 }
9244
40c7d507
RR
9245 /* MVFR2 is only valid for ARMv8-A. */
9246 if (inst.operands[0].reg == 5)
9247 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9248 _(BAD_FPU));
9249
16d02dc9
JB
9250 /* If we get through parsing the register name, we just insert the number
9251 generated into the instruction without further validation. */
9252 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9253 inst.instruction |= (Rt << 12);
9254}
9255
b99bd4ef 9256static void
c19d1205 9257do_mrs (void)
b99bd4ef 9258{
90ec0d68
MGD
9259 unsigned br;
9260
037e8744
JB
9261 if (do_vfp_nsyn_mrs () == SUCCESS)
9262 return;
9263
ff4a8d2b 9264 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9265 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9266
9267 if (inst.operands[1].isreg)
9268 {
9269 br = inst.operands[1].reg;
806ab1c0 9270 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
90ec0d68
MGD
9271 as_bad (_("bad register for mrs"));
9272 }
9273 else
9274 {
9275 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9276 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9277 != (PSR_c|PSR_f),
d2cd1205 9278 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9279 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9280 }
9281
9282 inst.instruction |= br;
c19d1205 9283}
b99bd4ef 9284
c19d1205
ZW
9285/* Two possible forms:
9286 "{C|S}PSR_<field>, Rm",
9287 "{C|S}PSR_f, #expression". */
b99bd4ef 9288
c19d1205
ZW
9289static void
9290do_msr (void)
9291{
037e8744
JB
9292 if (do_vfp_nsyn_msr () == SUCCESS)
9293 return;
9294
c19d1205
ZW
9295 inst.instruction |= inst.operands[0].imm;
9296 if (inst.operands[1].isreg)
9297 inst.instruction |= inst.operands[1].reg;
9298 else
b99bd4ef 9299 {
c19d1205
ZW
9300 inst.instruction |= INST_IMMEDIATE;
9301 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9302 inst.reloc.pc_rel = 0;
b99bd4ef 9303 }
b99bd4ef
NC
9304}
9305
c19d1205
ZW
9306static void
9307do_mul (void)
a737bd4d 9308{
ff4a8d2b
NC
9309 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9310
c19d1205
ZW
9311 if (!inst.operands[2].present)
9312 inst.operands[2].reg = inst.operands[0].reg;
9313 inst.instruction |= inst.operands[0].reg << 16;
9314 inst.instruction |= inst.operands[1].reg;
9315 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9316
8fb9d7b9
MS
9317 if (inst.operands[0].reg == inst.operands[1].reg
9318 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9319 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9320}
9321
c19d1205
ZW
9322/* Long Multiply Parser
9323 UMULL RdLo, RdHi, Rm, Rs
9324 SMULL RdLo, RdHi, Rm, Rs
9325 UMLAL RdLo, RdHi, Rm, Rs
9326 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9327
9328static void
c19d1205 9329do_mull (void)
b99bd4ef 9330{
c19d1205
ZW
9331 inst.instruction |= inst.operands[0].reg << 12;
9332 inst.instruction |= inst.operands[1].reg << 16;
9333 inst.instruction |= inst.operands[2].reg;
9334 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9335
682b27ad
PB
9336 /* rdhi and rdlo must be different. */
9337 if (inst.operands[0].reg == inst.operands[1].reg)
9338 as_tsktsk (_("rdhi and rdlo must be different"));
9339
9340 /* rdhi, rdlo and rm must all be different before armv6. */
9341 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9342 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9343 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9344 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9345}
b99bd4ef 9346
c19d1205
ZW
9347static void
9348do_nop (void)
9349{
e7495e45
NS
9350 if (inst.operands[0].present
9351 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9352 {
9353 /* Architectural NOP hints are CPSR sets with no bits selected. */
9354 inst.instruction &= 0xf0000000;
e7495e45
NS
9355 inst.instruction |= 0x0320f000;
9356 if (inst.operands[0].present)
9357 inst.instruction |= inst.operands[0].imm;
c19d1205 9358 }
b99bd4ef
NC
9359}
9360
c19d1205
ZW
9361/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9362 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9363 Condition defaults to COND_ALWAYS.
9364 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9365
9366static void
c19d1205 9367do_pkhbt (void)
b99bd4ef 9368{
c19d1205
ZW
9369 inst.instruction |= inst.operands[0].reg << 12;
9370 inst.instruction |= inst.operands[1].reg << 16;
9371 inst.instruction |= inst.operands[2].reg;
9372 if (inst.operands[3].present)
9373 encode_arm_shift (3);
9374}
b99bd4ef 9375
c19d1205 9376/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9377
c19d1205
ZW
9378static void
9379do_pkhtb (void)
9380{
9381 if (!inst.operands[3].present)
b99bd4ef 9382 {
c19d1205
ZW
9383 /* If the shift specifier is omitted, turn the instruction
9384 into pkhbt rd, rm, rn. */
9385 inst.instruction &= 0xfff00010;
9386 inst.instruction |= inst.operands[0].reg << 12;
9387 inst.instruction |= inst.operands[1].reg;
9388 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9389 }
9390 else
9391 {
c19d1205
ZW
9392 inst.instruction |= inst.operands[0].reg << 12;
9393 inst.instruction |= inst.operands[1].reg << 16;
9394 inst.instruction |= inst.operands[2].reg;
9395 encode_arm_shift (3);
b99bd4ef
NC
9396 }
9397}
9398
c19d1205 9399/* ARMv5TE: Preload-Cache
60e5ef9f 9400 MP Extensions: Preload for write
c19d1205 9401
60e5ef9f 9402 PLD(W) <addr_mode>
c19d1205
ZW
9403
9404 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9405
9406static void
c19d1205 9407do_pld (void)
b99bd4ef 9408{
c19d1205
ZW
9409 constraint (!inst.operands[0].isreg,
9410 _("'[' expected after PLD mnemonic"));
9411 constraint (inst.operands[0].postind,
9412 _("post-indexed expression used in preload instruction"));
9413 constraint (inst.operands[0].writeback,
9414 _("writeback used in preload instruction"));
9415 constraint (!inst.operands[0].preind,
9416 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9417 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9418}
b99bd4ef 9419
62b3e311
PB
9420/* ARMv7: PLI <addr_mode> */
9421static void
9422do_pli (void)
9423{
9424 constraint (!inst.operands[0].isreg,
9425 _("'[' expected after PLI mnemonic"));
9426 constraint (inst.operands[0].postind,
9427 _("post-indexed expression used in preload instruction"));
9428 constraint (inst.operands[0].writeback,
9429 _("writeback used in preload instruction"));
9430 constraint (!inst.operands[0].preind,
9431 _("unindexed addressing used in preload instruction"));
9432 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9433 inst.instruction &= ~PRE_INDEX;
9434}
9435
c19d1205
ZW
9436static void
9437do_push_pop (void)
9438{
5e0d7f77
MP
9439 constraint (inst.operands[0].writeback,
9440 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9441 inst.operands[1] = inst.operands[0];
9442 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9443 inst.operands[0].isreg = 1;
9444 inst.operands[0].writeback = 1;
9445 inst.operands[0].reg = REG_SP;
6530b175 9446 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9447}
b99bd4ef 9448
c19d1205
ZW
9449/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9450 word at the specified address and the following word
9451 respectively.
9452 Unconditionally executed.
9453 Error if Rn is R15. */
b99bd4ef 9454
c19d1205
ZW
9455static void
9456do_rfe (void)
9457{
9458 inst.instruction |= inst.operands[0].reg << 16;
9459 if (inst.operands[0].writeback)
9460 inst.instruction |= WRITE_BACK;
9461}
b99bd4ef 9462
c19d1205 9463/* ARM V6 ssat (argument parse). */
b99bd4ef 9464
c19d1205
ZW
9465static void
9466do_ssat (void)
9467{
9468 inst.instruction |= inst.operands[0].reg << 12;
9469 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9470 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9471
c19d1205
ZW
9472 if (inst.operands[3].present)
9473 encode_arm_shift (3);
b99bd4ef
NC
9474}
9475
c19d1205 9476/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9477
9478static void
c19d1205 9479do_usat (void)
b99bd4ef 9480{
c19d1205
ZW
9481 inst.instruction |= inst.operands[0].reg << 12;
9482 inst.instruction |= inst.operands[1].imm << 16;
9483 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9484
c19d1205
ZW
9485 if (inst.operands[3].present)
9486 encode_arm_shift (3);
b99bd4ef
NC
9487}
9488
c19d1205 9489/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9490
9491static void
c19d1205 9492do_ssat16 (void)
09d92015 9493{
c19d1205
ZW
9494 inst.instruction |= inst.operands[0].reg << 12;
9495 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9496 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9497}
9498
c19d1205
ZW
9499static void
9500do_usat16 (void)
a737bd4d 9501{
c19d1205
ZW
9502 inst.instruction |= inst.operands[0].reg << 12;
9503 inst.instruction |= inst.operands[1].imm << 16;
9504 inst.instruction |= inst.operands[2].reg;
9505}
a737bd4d 9506
c19d1205
ZW
9507/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9508 preserving the other bits.
a737bd4d 9509
c19d1205
ZW
9510 setend <endian_specifier>, where <endian_specifier> is either
9511 BE or LE. */
a737bd4d 9512
c19d1205
ZW
9513static void
9514do_setend (void)
9515{
12e37cbc
MGD
9516 if (warn_on_deprecated
9517 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9518 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9519
c19d1205
ZW
9520 if (inst.operands[0].imm)
9521 inst.instruction |= 0x200;
a737bd4d
NC
9522}
9523
9524static void
c19d1205 9525do_shift (void)
a737bd4d 9526{
c19d1205
ZW
9527 unsigned int Rm = (inst.operands[1].present
9528 ? inst.operands[1].reg
9529 : inst.operands[0].reg);
a737bd4d 9530
c19d1205
ZW
9531 inst.instruction |= inst.operands[0].reg << 12;
9532 inst.instruction |= Rm;
9533 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9534 {
c19d1205
ZW
9535 inst.instruction |= inst.operands[2].reg << 8;
9536 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9537 /* PR 12854: Error on extraneous shifts. */
9538 constraint (inst.operands[2].shifted,
9539 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9540 }
9541 else
c19d1205 9542 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9543}
9544
09d92015 9545static void
3eb17e6b 9546do_smc (void)
09d92015 9547{
3eb17e6b 9548 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9549 inst.reloc.pc_rel = 0;
09d92015
MM
9550}
9551
90ec0d68
MGD
9552static void
9553do_hvc (void)
9554{
9555 inst.reloc.type = BFD_RELOC_ARM_HVC;
9556 inst.reloc.pc_rel = 0;
9557}
9558
09d92015 9559static void
c19d1205 9560do_swi (void)
09d92015 9561{
c19d1205
ZW
9562 inst.reloc.type = BFD_RELOC_ARM_SWI;
9563 inst.reloc.pc_rel = 0;
09d92015
MM
9564}
9565
ddfded2f
MW
9566static void
9567do_setpan (void)
9568{
9569 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9570 _("selected processor does not support SETPAN instruction"));
9571
9572 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9573}
9574
9575static void
9576do_t_setpan (void)
9577{
9578 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9579 _("selected processor does not support SETPAN instruction"));
9580
9581 inst.instruction |= (inst.operands[0].imm << 3);
9582}
9583
c19d1205
ZW
9584/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9585 SMLAxy{cond} Rd,Rm,Rs,Rn
9586 SMLAWy{cond} Rd,Rm,Rs,Rn
9587 Error if any register is R15. */
e16bb312 9588
c19d1205
ZW
9589static void
9590do_smla (void)
e16bb312 9591{
c19d1205
ZW
9592 inst.instruction |= inst.operands[0].reg << 16;
9593 inst.instruction |= inst.operands[1].reg;
9594 inst.instruction |= inst.operands[2].reg << 8;
9595 inst.instruction |= inst.operands[3].reg << 12;
9596}
a737bd4d 9597
c19d1205
ZW
9598/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9599 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9600 Error if any register is R15.
9601 Warning if Rdlo == Rdhi. */
a737bd4d 9602
c19d1205
ZW
9603static void
9604do_smlal (void)
9605{
9606 inst.instruction |= inst.operands[0].reg << 12;
9607 inst.instruction |= inst.operands[1].reg << 16;
9608 inst.instruction |= inst.operands[2].reg;
9609 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9610
c19d1205
ZW
9611 if (inst.operands[0].reg == inst.operands[1].reg)
9612 as_tsktsk (_("rdhi and rdlo must be different"));
9613}
a737bd4d 9614
c19d1205
ZW
9615/* ARM V5E (El Segundo) signed-multiply (argument parse)
9616 SMULxy{cond} Rd,Rm,Rs
9617 Error if any register is R15. */
a737bd4d 9618
c19d1205
ZW
9619static void
9620do_smul (void)
9621{
9622 inst.instruction |= inst.operands[0].reg << 16;
9623 inst.instruction |= inst.operands[1].reg;
9624 inst.instruction |= inst.operands[2].reg << 8;
9625}
a737bd4d 9626
b6702015
PB
9627/* ARM V6 srs (argument parse). The variable fields in the encoding are
9628 the same for both ARM and Thumb-2. */
a737bd4d 9629
c19d1205
ZW
9630static void
9631do_srs (void)
9632{
b6702015
PB
9633 int reg;
9634
9635 if (inst.operands[0].present)
9636 {
9637 reg = inst.operands[0].reg;
fdfde340 9638 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9639 }
9640 else
fdfde340 9641 reg = REG_SP;
b6702015
PB
9642
9643 inst.instruction |= reg << 16;
9644 inst.instruction |= inst.operands[1].imm;
9645 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9646 inst.instruction |= WRITE_BACK;
9647}
a737bd4d 9648
c19d1205 9649/* ARM V6 strex (argument parse). */
a737bd4d 9650
c19d1205
ZW
9651static void
9652do_strex (void)
9653{
9654 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9655 || inst.operands[2].postind || inst.operands[2].writeback
9656 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9657 || inst.operands[2].negative
9658 /* See comment in do_ldrex(). */
9659 || (inst.operands[2].reg == REG_PC),
9660 BAD_ADDR_MODE);
a737bd4d 9661
c19d1205
ZW
9662 constraint (inst.operands[0].reg == inst.operands[1].reg
9663 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9664
c19d1205
ZW
9665 constraint (inst.reloc.exp.X_op != O_constant
9666 || inst.reloc.exp.X_add_number != 0,
9667 _("offset must be zero in ARM encoding"));
a737bd4d 9668
c19d1205
ZW
9669 inst.instruction |= inst.operands[0].reg << 12;
9670 inst.instruction |= inst.operands[1].reg;
9671 inst.instruction |= inst.operands[2].reg << 16;
9672 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9673}
9674
877807f8
NC
9675static void
9676do_t_strexbh (void)
9677{
9678 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9679 || inst.operands[2].postind || inst.operands[2].writeback
9680 || inst.operands[2].immisreg || inst.operands[2].shifted
9681 || inst.operands[2].negative,
9682 BAD_ADDR_MODE);
9683
9684 constraint (inst.operands[0].reg == inst.operands[1].reg
9685 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9686
9687 do_rm_rd_rn ();
9688}
9689
e16bb312 9690static void
c19d1205 9691do_strexd (void)
e16bb312 9692{
c19d1205
ZW
9693 constraint (inst.operands[1].reg % 2 != 0,
9694 _("even register required"));
9695 constraint (inst.operands[2].present
9696 && inst.operands[2].reg != inst.operands[1].reg + 1,
9697 _("can only store two consecutive registers"));
9698 /* If op 2 were present and equal to PC, this function wouldn't
9699 have been called in the first place. */
9700 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9701
c19d1205
ZW
9702 constraint (inst.operands[0].reg == inst.operands[1].reg
9703 || inst.operands[0].reg == inst.operands[1].reg + 1
9704 || inst.operands[0].reg == inst.operands[3].reg,
9705 BAD_OVERLAP);
e16bb312 9706
c19d1205
ZW
9707 inst.instruction |= inst.operands[0].reg << 12;
9708 inst.instruction |= inst.operands[1].reg;
9709 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9710}
9711
9eb6c0f1
MGD
9712/* ARM V8 STRL. */
9713static void
4b8c8c02 9714do_stlex (void)
9eb6c0f1
MGD
9715{
9716 constraint (inst.operands[0].reg == inst.operands[1].reg
9717 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9718
9719 do_rd_rm_rn ();
9720}
9721
9722static void
4b8c8c02 9723do_t_stlex (void)
9eb6c0f1
MGD
9724{
9725 constraint (inst.operands[0].reg == inst.operands[1].reg
9726 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9727
9728 do_rm_rd_rn ();
9729}
9730
c19d1205
ZW
9731/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9732 extends it to 32-bits, and adds the result to a value in another
9733 register. You can specify a rotation by 0, 8, 16, or 24 bits
9734 before extracting the 16-bit value.
9735 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9736 Condition defaults to COND_ALWAYS.
9737 Error if any register uses R15. */
9738
e16bb312 9739static void
c19d1205 9740do_sxtah (void)
e16bb312 9741{
c19d1205
ZW
9742 inst.instruction |= inst.operands[0].reg << 12;
9743 inst.instruction |= inst.operands[1].reg << 16;
9744 inst.instruction |= inst.operands[2].reg;
9745 inst.instruction |= inst.operands[3].imm << 10;
9746}
e16bb312 9747
c19d1205 9748/* ARM V6 SXTH.
e16bb312 9749
c19d1205
ZW
9750 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9751 Condition defaults to COND_ALWAYS.
9752 Error if any register uses R15. */
e16bb312
NC
9753
9754static void
c19d1205 9755do_sxth (void)
e16bb312 9756{
c19d1205
ZW
9757 inst.instruction |= inst.operands[0].reg << 12;
9758 inst.instruction |= inst.operands[1].reg;
9759 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9760}
c19d1205
ZW
9761\f
9762/* VFP instructions. In a logical order: SP variant first, monad
9763 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9764
9765static void
c19d1205 9766do_vfp_sp_monadic (void)
e16bb312 9767{
5287ad62
JB
9768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9769 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9770}
9771
9772static void
c19d1205 9773do_vfp_sp_dyadic (void)
e16bb312 9774{
5287ad62
JB
9775 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9777 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9778}
9779
9780static void
c19d1205 9781do_vfp_sp_compare_z (void)
e16bb312 9782{
5287ad62 9783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9784}
9785
9786static void
c19d1205 9787do_vfp_dp_sp_cvt (void)
e16bb312 9788{
5287ad62
JB
9789 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9790 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9791}
9792
9793static void
c19d1205 9794do_vfp_sp_dp_cvt (void)
e16bb312 9795{
5287ad62
JB
9796 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9797 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9798}
9799
9800static void
c19d1205 9801do_vfp_reg_from_sp (void)
e16bb312 9802{
c19d1205 9803 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9804 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9805}
9806
9807static void
c19d1205 9808do_vfp_reg2_from_sp2 (void)
e16bb312 9809{
c19d1205
ZW
9810 constraint (inst.operands[2].imm != 2,
9811 _("only two consecutive VFP SP registers allowed here"));
9812 inst.instruction |= inst.operands[0].reg << 12;
9813 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9814 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9815}
9816
9817static void
c19d1205 9818do_vfp_sp_from_reg (void)
e16bb312 9819{
5287ad62 9820 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9821 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9822}
9823
9824static void
c19d1205 9825do_vfp_sp2_from_reg2 (void)
e16bb312 9826{
c19d1205
ZW
9827 constraint (inst.operands[0].imm != 2,
9828 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9829 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9830 inst.instruction |= inst.operands[1].reg << 12;
9831 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9832}
9833
9834static void
c19d1205 9835do_vfp_sp_ldst (void)
e16bb312 9836{
5287ad62 9837 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9838 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9839}
9840
9841static void
c19d1205 9842do_vfp_dp_ldst (void)
e16bb312 9843{
5287ad62 9844 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9845 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9846}
9847
c19d1205 9848
e16bb312 9849static void
c19d1205 9850vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9851{
c19d1205
ZW
9852 if (inst.operands[0].writeback)
9853 inst.instruction |= WRITE_BACK;
9854 else
9855 constraint (ldstm_type != VFP_LDSTMIA,
9856 _("this addressing mode requires base-register writeback"));
9857 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9858 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9859 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9860}
9861
9862static void
c19d1205 9863vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9864{
c19d1205 9865 int count;
e16bb312 9866
c19d1205
ZW
9867 if (inst.operands[0].writeback)
9868 inst.instruction |= WRITE_BACK;
9869 else
9870 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9871 _("this addressing mode requires base-register writeback"));
e16bb312 9872
c19d1205 9873 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9874 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9875
c19d1205
ZW
9876 count = inst.operands[1].imm << 1;
9877 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9878 count += 1;
e16bb312 9879
c19d1205 9880 inst.instruction |= count;
e16bb312
NC
9881}
9882
9883static void
c19d1205 9884do_vfp_sp_ldstmia (void)
e16bb312 9885{
c19d1205 9886 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9887}
9888
9889static void
c19d1205 9890do_vfp_sp_ldstmdb (void)
e16bb312 9891{
c19d1205 9892 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9893}
9894
9895static void
c19d1205 9896do_vfp_dp_ldstmia (void)
e16bb312 9897{
c19d1205 9898 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9899}
9900
9901static void
c19d1205 9902do_vfp_dp_ldstmdb (void)
e16bb312 9903{
c19d1205 9904 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9905}
9906
9907static void
c19d1205 9908do_vfp_xp_ldstmia (void)
e16bb312 9909{
c19d1205
ZW
9910 vfp_dp_ldstm (VFP_LDSTMIAX);
9911}
e16bb312 9912
c19d1205
ZW
9913static void
9914do_vfp_xp_ldstmdb (void)
9915{
9916 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9917}
5287ad62
JB
9918
9919static void
9920do_vfp_dp_rd_rm (void)
9921{
9922 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9923 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9924}
9925
9926static void
9927do_vfp_dp_rn_rd (void)
9928{
9929 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9930 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9931}
9932
9933static void
9934do_vfp_dp_rd_rn (void)
9935{
9936 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9937 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9938}
9939
9940static void
9941do_vfp_dp_rd_rn_rm (void)
9942{
9943 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9944 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9945 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9946}
9947
9948static void
9949do_vfp_dp_rd (void)
9950{
9951 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9952}
9953
9954static void
9955do_vfp_dp_rm_rd_rn (void)
9956{
9957 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9958 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9959 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9960}
9961
9962/* VFPv3 instructions. */
9963static void
9964do_vfp_sp_const (void)
9965{
9966 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9967 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9968 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9969}
9970
9971static void
9972do_vfp_dp_const (void)
9973{
9974 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9975 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9976 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9977}
9978
9979static void
9980vfp_conv (int srcsize)
9981{
5f1af56b
MGD
9982 int immbits = srcsize - inst.operands[1].imm;
9983
fa94de6b
RM
9984 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9985 {
5f1af56b 9986 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9987 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9988 inst.error = _("immediate value out of range, expected range [0, 16]");
9989 return;
9990 }
fa94de6b 9991 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9992 {
9993 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9994 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9995 inst.error = _("immediate value out of range, expected range [1, 32]");
9996 return;
9997 }
9998
5287ad62
JB
9999 inst.instruction |= (immbits & 1) << 5;
10000 inst.instruction |= (immbits >> 1);
10001}
10002
10003static void
10004do_vfp_sp_conv_16 (void)
10005{
10006 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10007 vfp_conv (16);
10008}
10009
10010static void
10011do_vfp_dp_conv_16 (void)
10012{
10013 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10014 vfp_conv (16);
10015}
10016
10017static void
10018do_vfp_sp_conv_32 (void)
10019{
10020 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10021 vfp_conv (32);
10022}
10023
10024static void
10025do_vfp_dp_conv_32 (void)
10026{
10027 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10028 vfp_conv (32);
10029}
c19d1205
ZW
10030\f
10031/* FPA instructions. Also in a logical order. */
e16bb312 10032
c19d1205
ZW
10033static void
10034do_fpa_cmp (void)
10035{
10036 inst.instruction |= inst.operands[0].reg << 16;
10037 inst.instruction |= inst.operands[1].reg;
10038}
b99bd4ef
NC
10039
10040static void
c19d1205 10041do_fpa_ldmstm (void)
b99bd4ef 10042{
c19d1205
ZW
10043 inst.instruction |= inst.operands[0].reg << 12;
10044 switch (inst.operands[1].imm)
10045 {
10046 case 1: inst.instruction |= CP_T_X; break;
10047 case 2: inst.instruction |= CP_T_Y; break;
10048 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10049 case 4: break;
10050 default: abort ();
10051 }
b99bd4ef 10052
c19d1205
ZW
10053 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10054 {
10055 /* The instruction specified "ea" or "fd", so we can only accept
10056 [Rn]{!}. The instruction does not really support stacking or
10057 unstacking, so we have to emulate these by setting appropriate
10058 bits and offsets. */
10059 constraint (inst.reloc.exp.X_op != O_constant
10060 || inst.reloc.exp.X_add_number != 0,
10061 _("this instruction does not support indexing"));
b99bd4ef 10062
c19d1205
ZW
10063 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10064 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10065
c19d1205
ZW
10066 if (!(inst.instruction & INDEX_UP))
10067 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 10068
c19d1205
ZW
10069 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10070 {
10071 inst.operands[2].preind = 0;
10072 inst.operands[2].postind = 1;
10073 }
10074 }
b99bd4ef 10075
c19d1205 10076 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10077}
c19d1205
ZW
10078\f
10079/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10080
c19d1205
ZW
10081static void
10082do_iwmmxt_tandorc (void)
10083{
10084 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10085}
b99bd4ef 10086
c19d1205
ZW
10087static void
10088do_iwmmxt_textrc (void)
10089{
10090 inst.instruction |= inst.operands[0].reg << 12;
10091 inst.instruction |= inst.operands[1].imm;
10092}
b99bd4ef
NC
10093
10094static void
c19d1205 10095do_iwmmxt_textrm (void)
b99bd4ef 10096{
c19d1205
ZW
10097 inst.instruction |= inst.operands[0].reg << 12;
10098 inst.instruction |= inst.operands[1].reg << 16;
10099 inst.instruction |= inst.operands[2].imm;
10100}
b99bd4ef 10101
c19d1205
ZW
10102static void
10103do_iwmmxt_tinsr (void)
10104{
10105 inst.instruction |= inst.operands[0].reg << 16;
10106 inst.instruction |= inst.operands[1].reg << 12;
10107 inst.instruction |= inst.operands[2].imm;
10108}
b99bd4ef 10109
c19d1205
ZW
10110static void
10111do_iwmmxt_tmia (void)
10112{
10113 inst.instruction |= inst.operands[0].reg << 5;
10114 inst.instruction |= inst.operands[1].reg;
10115 inst.instruction |= inst.operands[2].reg << 12;
10116}
b99bd4ef 10117
c19d1205
ZW
10118static void
10119do_iwmmxt_waligni (void)
10120{
10121 inst.instruction |= inst.operands[0].reg << 12;
10122 inst.instruction |= inst.operands[1].reg << 16;
10123 inst.instruction |= inst.operands[2].reg;
10124 inst.instruction |= inst.operands[3].imm << 20;
10125}
b99bd4ef 10126
2d447fca
JM
10127static void
10128do_iwmmxt_wmerge (void)
10129{
10130 inst.instruction |= inst.operands[0].reg << 12;
10131 inst.instruction |= inst.operands[1].reg << 16;
10132 inst.instruction |= inst.operands[2].reg;
10133 inst.instruction |= inst.operands[3].imm << 21;
10134}
10135
c19d1205
ZW
10136static void
10137do_iwmmxt_wmov (void)
10138{
10139 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10140 inst.instruction |= inst.operands[0].reg << 12;
10141 inst.instruction |= inst.operands[1].reg << 16;
10142 inst.instruction |= inst.operands[1].reg;
10143}
b99bd4ef 10144
c19d1205
ZW
10145static void
10146do_iwmmxt_wldstbh (void)
10147{
8f06b2d8 10148 int reloc;
c19d1205 10149 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10150 if (thumb_mode)
10151 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10152 else
10153 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10154 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10155}
10156
c19d1205
ZW
10157static void
10158do_iwmmxt_wldstw (void)
10159{
10160 /* RIWR_RIWC clears .isreg for a control register. */
10161 if (!inst.operands[0].isreg)
10162 {
10163 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10164 inst.instruction |= 0xf0000000;
10165 }
b99bd4ef 10166
c19d1205
ZW
10167 inst.instruction |= inst.operands[0].reg << 12;
10168 encode_arm_cp_address (1, TRUE, TRUE, 0);
10169}
b99bd4ef
NC
10170
10171static void
c19d1205 10172do_iwmmxt_wldstd (void)
b99bd4ef 10173{
c19d1205 10174 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10175 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10176 && inst.operands[1].immisreg)
10177 {
10178 inst.instruction &= ~0x1a000ff;
eff0bc54 10179 inst.instruction |= (0xfU << 28);
2d447fca
JM
10180 if (inst.operands[1].preind)
10181 inst.instruction |= PRE_INDEX;
10182 if (!inst.operands[1].negative)
10183 inst.instruction |= INDEX_UP;
10184 if (inst.operands[1].writeback)
10185 inst.instruction |= WRITE_BACK;
10186 inst.instruction |= inst.operands[1].reg << 16;
10187 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10188 inst.instruction |= inst.operands[1].imm;
10189 }
10190 else
10191 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10192}
b99bd4ef 10193
c19d1205
ZW
10194static void
10195do_iwmmxt_wshufh (void)
10196{
10197 inst.instruction |= inst.operands[0].reg << 12;
10198 inst.instruction |= inst.operands[1].reg << 16;
10199 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10200 inst.instruction |= (inst.operands[2].imm & 0x0f);
10201}
b99bd4ef 10202
c19d1205
ZW
10203static void
10204do_iwmmxt_wzero (void)
10205{
10206 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10207 inst.instruction |= inst.operands[0].reg;
10208 inst.instruction |= inst.operands[0].reg << 12;
10209 inst.instruction |= inst.operands[0].reg << 16;
10210}
2d447fca
JM
10211
10212static void
10213do_iwmmxt_wrwrwr_or_imm5 (void)
10214{
10215 if (inst.operands[2].isreg)
10216 do_rd_rn_rm ();
10217 else {
10218 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10219 _("immediate operand requires iWMMXt2"));
10220 do_rd_rn ();
10221 if (inst.operands[2].imm == 0)
10222 {
10223 switch ((inst.instruction >> 20) & 0xf)
10224 {
10225 case 4:
10226 case 5:
10227 case 6:
5f4273c7 10228 case 7:
2d447fca
JM
10229 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10230 inst.operands[2].imm = 16;
10231 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10232 break;
10233 case 8:
10234 case 9:
10235 case 10:
10236 case 11:
10237 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10238 inst.operands[2].imm = 32;
10239 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10240 break;
10241 case 12:
10242 case 13:
10243 case 14:
10244 case 15:
10245 {
10246 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10247 unsigned long wrn;
10248 wrn = (inst.instruction >> 16) & 0xf;
10249 inst.instruction &= 0xff0fff0f;
10250 inst.instruction |= wrn;
10251 /* Bail out here; the instruction is now assembled. */
10252 return;
10253 }
10254 }
10255 }
10256 /* Map 32 -> 0, etc. */
10257 inst.operands[2].imm &= 0x1f;
eff0bc54 10258 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10259 }
10260}
c19d1205
ZW
10261\f
10262/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10263 operations first, then control, shift, and load/store. */
b99bd4ef 10264
c19d1205 10265/* Insns like "foo X,Y,Z". */
b99bd4ef 10266
c19d1205
ZW
10267static void
10268do_mav_triple (void)
10269{
10270 inst.instruction |= inst.operands[0].reg << 16;
10271 inst.instruction |= inst.operands[1].reg;
10272 inst.instruction |= inst.operands[2].reg << 12;
10273}
b99bd4ef 10274
c19d1205
ZW
10275/* Insns like "foo W,X,Y,Z".
10276 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10277
c19d1205
ZW
10278static void
10279do_mav_quad (void)
10280{
10281 inst.instruction |= inst.operands[0].reg << 5;
10282 inst.instruction |= inst.operands[1].reg << 12;
10283 inst.instruction |= inst.operands[2].reg << 16;
10284 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10285}
10286
c19d1205
ZW
10287/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10288static void
10289do_mav_dspsc (void)
a737bd4d 10290{
c19d1205
ZW
10291 inst.instruction |= inst.operands[1].reg << 12;
10292}
a737bd4d 10293
c19d1205
ZW
10294/* Maverick shift immediate instructions.
10295 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10296 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10297
c19d1205
ZW
10298static void
10299do_mav_shift (void)
10300{
10301 int imm = inst.operands[2].imm;
a737bd4d 10302
c19d1205
ZW
10303 inst.instruction |= inst.operands[0].reg << 12;
10304 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10305
c19d1205
ZW
10306 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10307 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10308 Bit 4 should be 0. */
10309 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10310
c19d1205
ZW
10311 inst.instruction |= imm;
10312}
10313\f
10314/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10315
c19d1205
ZW
10316/* Xscale multiply-accumulate (argument parse)
10317 MIAcc acc0,Rm,Rs
10318 MIAPHcc acc0,Rm,Rs
10319 MIAxycc acc0,Rm,Rs. */
a737bd4d 10320
c19d1205
ZW
10321static void
10322do_xsc_mia (void)
10323{
10324 inst.instruction |= inst.operands[1].reg;
10325 inst.instruction |= inst.operands[2].reg << 12;
10326}
a737bd4d 10327
c19d1205 10328/* Xscale move-accumulator-register (argument parse)
a737bd4d 10329
c19d1205 10330 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10331
c19d1205
ZW
10332static void
10333do_xsc_mar (void)
10334{
10335 inst.instruction |= inst.operands[1].reg << 12;
10336 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10337}
10338
c19d1205 10339/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10340
c19d1205 10341 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10342
10343static void
c19d1205 10344do_xsc_mra (void)
b99bd4ef 10345{
c19d1205
ZW
10346 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10347 inst.instruction |= inst.operands[0].reg << 12;
10348 inst.instruction |= inst.operands[1].reg << 16;
10349}
10350\f
10351/* Encoding functions relevant only to Thumb. */
b99bd4ef 10352
c19d1205
ZW
10353/* inst.operands[i] is a shifted-register operand; encode
10354 it into inst.instruction in the format used by Thumb32. */
10355
10356static void
10357encode_thumb32_shifted_operand (int i)
10358{
10359 unsigned int value = inst.reloc.exp.X_add_number;
10360 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10361
9c3c69f2
PB
10362 constraint (inst.operands[i].immisreg,
10363 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10364 inst.instruction |= inst.operands[i].reg;
10365 if (shift == SHIFT_RRX)
10366 inst.instruction |= SHIFT_ROR << 4;
10367 else
b99bd4ef 10368 {
c19d1205
ZW
10369 constraint (inst.reloc.exp.X_op != O_constant,
10370 _("expression too complex"));
10371
10372 constraint (value > 32
10373 || (value == 32 && (shift == SHIFT_LSL
10374 || shift == SHIFT_ROR)),
10375 _("shift expression is too large"));
10376
10377 if (value == 0)
10378 shift = SHIFT_LSL;
10379 else if (value == 32)
10380 value = 0;
10381
10382 inst.instruction |= shift << 4;
10383 inst.instruction |= (value & 0x1c) << 10;
10384 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10385 }
c19d1205 10386}
b99bd4ef 10387
b99bd4ef 10388
c19d1205
ZW
10389/* inst.operands[i] was set up by parse_address. Encode it into a
10390 Thumb32 format load or store instruction. Reject forms that cannot
10391 be used with such instructions. If is_t is true, reject forms that
10392 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10393 that cannot be used with a D instruction. If it is a store insn,
10394 reject PC in Rn. */
b99bd4ef 10395
c19d1205
ZW
10396static void
10397encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10398{
5be8be5d 10399 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10400
10401 constraint (!inst.operands[i].isreg,
53365c0d 10402 _("Instruction does not support =N addresses"));
b99bd4ef 10403
c19d1205
ZW
10404 inst.instruction |= inst.operands[i].reg << 16;
10405 if (inst.operands[i].immisreg)
b99bd4ef 10406 {
5be8be5d 10407 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10408 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10409 constraint (inst.operands[i].negative,
10410 _("Thumb does not support negative register indexing"));
10411 constraint (inst.operands[i].postind,
10412 _("Thumb does not support register post-indexing"));
10413 constraint (inst.operands[i].writeback,
10414 _("Thumb does not support register indexing with writeback"));
10415 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10416 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10417
f40d1643 10418 inst.instruction |= inst.operands[i].imm;
c19d1205 10419 if (inst.operands[i].shifted)
b99bd4ef 10420 {
c19d1205
ZW
10421 constraint (inst.reloc.exp.X_op != O_constant,
10422 _("expression too complex"));
9c3c69f2
PB
10423 constraint (inst.reloc.exp.X_add_number < 0
10424 || inst.reloc.exp.X_add_number > 3,
c19d1205 10425 _("shift out of range"));
9c3c69f2 10426 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10427 }
10428 inst.reloc.type = BFD_RELOC_UNUSED;
10429 }
10430 else if (inst.operands[i].preind)
10431 {
5be8be5d 10432 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10433 constraint (is_t && inst.operands[i].writeback,
c19d1205 10434 _("cannot use writeback with this instruction"));
4755303e
WN
10435 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10436 BAD_PC_ADDRESSING);
c19d1205
ZW
10437
10438 if (is_d)
10439 {
10440 inst.instruction |= 0x01000000;
10441 if (inst.operands[i].writeback)
10442 inst.instruction |= 0x00200000;
b99bd4ef 10443 }
c19d1205 10444 else
b99bd4ef 10445 {
c19d1205
ZW
10446 inst.instruction |= 0x00000c00;
10447 if (inst.operands[i].writeback)
10448 inst.instruction |= 0x00000100;
b99bd4ef 10449 }
c19d1205 10450 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10451 }
c19d1205 10452 else if (inst.operands[i].postind)
b99bd4ef 10453 {
9c2799c2 10454 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10455 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10456 constraint (is_t, _("cannot use post-indexing with this instruction"));
10457
10458 if (is_d)
10459 inst.instruction |= 0x00200000;
10460 else
10461 inst.instruction |= 0x00000900;
10462 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10463 }
10464 else /* unindexed - only for coprocessor */
10465 inst.error = _("instruction does not accept unindexed addressing");
10466}
10467
10468/* Table of Thumb instructions which exist in both 16- and 32-bit
10469 encodings (the latter only in post-V6T2 cores). The index is the
10470 value used in the insns table below. When there is more than one
10471 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10472 holds variant (1).
10473 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10474#define T16_32_TAB \
21d799b5
NC
10475 X(_adc, 4140, eb400000), \
10476 X(_adcs, 4140, eb500000), \
10477 X(_add, 1c00, eb000000), \
10478 X(_adds, 1c00, eb100000), \
10479 X(_addi, 0000, f1000000), \
10480 X(_addis, 0000, f1100000), \
10481 X(_add_pc,000f, f20f0000), \
10482 X(_add_sp,000d, f10d0000), \
10483 X(_adr, 000f, f20f0000), \
10484 X(_and, 4000, ea000000), \
10485 X(_ands, 4000, ea100000), \
10486 X(_asr, 1000, fa40f000), \
10487 X(_asrs, 1000, fa50f000), \
10488 X(_b, e000, f000b000), \
10489 X(_bcond, d000, f0008000), \
10490 X(_bic, 4380, ea200000), \
10491 X(_bics, 4380, ea300000), \
10492 X(_cmn, 42c0, eb100f00), \
10493 X(_cmp, 2800, ebb00f00), \
10494 X(_cpsie, b660, f3af8400), \
10495 X(_cpsid, b670, f3af8600), \
10496 X(_cpy, 4600, ea4f0000), \
10497 X(_dec_sp,80dd, f1ad0d00), \
10498 X(_eor, 4040, ea800000), \
10499 X(_eors, 4040, ea900000), \
10500 X(_inc_sp,00dd, f10d0d00), \
10501 X(_ldmia, c800, e8900000), \
10502 X(_ldr, 6800, f8500000), \
10503 X(_ldrb, 7800, f8100000), \
10504 X(_ldrh, 8800, f8300000), \
10505 X(_ldrsb, 5600, f9100000), \
10506 X(_ldrsh, 5e00, f9300000), \
10507 X(_ldr_pc,4800, f85f0000), \
10508 X(_ldr_pc2,4800, f85f0000), \
10509 X(_ldr_sp,9800, f85d0000), \
10510 X(_lsl, 0000, fa00f000), \
10511 X(_lsls, 0000, fa10f000), \
10512 X(_lsr, 0800, fa20f000), \
10513 X(_lsrs, 0800, fa30f000), \
10514 X(_mov, 2000, ea4f0000), \
10515 X(_movs, 2000, ea5f0000), \
10516 X(_mul, 4340, fb00f000), \
10517 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10518 X(_mvn, 43c0, ea6f0000), \
10519 X(_mvns, 43c0, ea7f0000), \
10520 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10521 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10522 X(_orr, 4300, ea400000), \
10523 X(_orrs, 4300, ea500000), \
10524 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10525 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10526 X(_rev, ba00, fa90f080), \
10527 X(_rev16, ba40, fa90f090), \
10528 X(_revsh, bac0, fa90f0b0), \
10529 X(_ror, 41c0, fa60f000), \
10530 X(_rors, 41c0, fa70f000), \
10531 X(_sbc, 4180, eb600000), \
10532 X(_sbcs, 4180, eb700000), \
10533 X(_stmia, c000, e8800000), \
10534 X(_str, 6000, f8400000), \
10535 X(_strb, 7000, f8000000), \
10536 X(_strh, 8000, f8200000), \
10537 X(_str_sp,9000, f84d0000), \
10538 X(_sub, 1e00, eba00000), \
10539 X(_subs, 1e00, ebb00000), \
10540 X(_subi, 8000, f1a00000), \
10541 X(_subis, 8000, f1b00000), \
10542 X(_sxtb, b240, fa4ff080), \
10543 X(_sxth, b200, fa0ff080), \
10544 X(_tst, 4200, ea100f00), \
10545 X(_uxtb, b2c0, fa5ff080), \
10546 X(_uxth, b280, fa1ff080), \
10547 X(_nop, bf00, f3af8000), \
10548 X(_yield, bf10, f3af8001), \
10549 X(_wfe, bf20, f3af8002), \
10550 X(_wfi, bf30, f3af8003), \
53c4b28b 10551 X(_sev, bf40, f3af8004), \
74db7efb
NC
10552 X(_sevl, bf50, f3af8005), \
10553 X(_udf, de00, f7f0a000)
c19d1205
ZW
10554
10555/* To catch errors in encoding functions, the codes are all offset by
10556 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10557 as 16-bit instructions. */
21d799b5 10558#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10559enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10560#undef X
10561
10562#define X(a,b,c) 0x##b
10563static const unsigned short thumb_op16[] = { T16_32_TAB };
10564#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10565#undef X
10566
10567#define X(a,b,c) 0x##c
10568static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10569#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10570#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10571#undef X
10572#undef T16_32_TAB
10573
10574/* Thumb instruction encoders, in alphabetical order. */
10575
92e90b6e 10576/* ADDW or SUBW. */
c921be7d 10577
92e90b6e
PB
10578static void
10579do_t_add_sub_w (void)
10580{
10581 int Rd, Rn;
10582
10583 Rd = inst.operands[0].reg;
10584 Rn = inst.operands[1].reg;
10585
539d4391
NC
10586 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10587 is the SP-{plus,minus}-immediate form of the instruction. */
10588 if (Rn == REG_SP)
10589 constraint (Rd == REG_PC, BAD_PC);
10590 else
10591 reject_bad_reg (Rd);
fdfde340 10592
92e90b6e
PB
10593 inst.instruction |= (Rn << 16) | (Rd << 8);
10594 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10595}
10596
c19d1205 10597/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10598 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10599
10600static void
10601do_t_add_sub (void)
10602{
10603 int Rd, Rs, Rn;
10604
10605 Rd = inst.operands[0].reg;
10606 Rs = (inst.operands[1].present
10607 ? inst.operands[1].reg /* Rd, Rs, foo */
10608 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10609
e07e6e58
NC
10610 if (Rd == REG_PC)
10611 set_it_insn_type_last ();
10612
c19d1205
ZW
10613 if (unified_syntax)
10614 {
0110f2b8
PB
10615 bfd_boolean flags;
10616 bfd_boolean narrow;
10617 int opcode;
10618
10619 flags = (inst.instruction == T_MNEM_adds
10620 || inst.instruction == T_MNEM_subs);
10621 if (flags)
e07e6e58 10622 narrow = !in_it_block ();
0110f2b8 10623 else
e07e6e58 10624 narrow = in_it_block ();
c19d1205 10625 if (!inst.operands[2].isreg)
b99bd4ef 10626 {
16805f35
PB
10627 int add;
10628
5c8ed6a4
JW
10629 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10630 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10631
16805f35
PB
10632 add = (inst.instruction == T_MNEM_add
10633 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10634 opcode = 0;
10635 if (inst.size_req != 4)
10636 {
0110f2b8 10637 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10638 appropriate. */
0110f2b8
PB
10639 if (Rd == REG_SP && Rs == REG_SP && !flags)
10640 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10641 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10642 opcode = T_MNEM_add_sp;
10643 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10644 opcode = T_MNEM_add_pc;
10645 else if (Rd <= 7 && Rs <= 7 && narrow)
10646 {
10647 if (flags)
10648 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10649 else
10650 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10651 }
10652 if (opcode)
10653 {
10654 inst.instruction = THUMB_OP16(opcode);
10655 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10656 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10657 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10658 {
10659 if (inst.size_req == 2)
10660 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10661 else
10662 inst.relax = opcode;
10663 }
0110f2b8
PB
10664 }
10665 else
10666 constraint (inst.size_req == 2, BAD_HIREG);
10667 }
10668 if (inst.size_req == 4
10669 || (inst.size_req != 2 && !opcode))
10670 {
a9f02af8
MG
10671 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10672 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10673 THUMB1_RELOC_ONLY);
efd81785
PB
10674 if (Rd == REG_PC)
10675 {
fdfde340 10676 constraint (add, BAD_PC);
efd81785
PB
10677 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10678 _("only SUBS PC, LR, #const allowed"));
10679 constraint (inst.reloc.exp.X_op != O_constant,
10680 _("expression too complex"));
10681 constraint (inst.reloc.exp.X_add_number < 0
10682 || inst.reloc.exp.X_add_number > 0xff,
10683 _("immediate value out of range"));
10684 inst.instruction = T2_SUBS_PC_LR
10685 | inst.reloc.exp.X_add_number;
10686 inst.reloc.type = BFD_RELOC_UNUSED;
10687 return;
10688 }
10689 else if (Rs == REG_PC)
16805f35
PB
10690 {
10691 /* Always use addw/subw. */
10692 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10693 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10694 }
10695 else
10696 {
10697 inst.instruction = THUMB_OP32 (inst.instruction);
10698 inst.instruction = (inst.instruction & 0xe1ffffff)
10699 | 0x10000000;
10700 if (flags)
10701 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10702 else
10703 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10704 }
dc4503c6
PB
10705 inst.instruction |= Rd << 8;
10706 inst.instruction |= Rs << 16;
0110f2b8 10707 }
b99bd4ef 10708 }
c19d1205
ZW
10709 else
10710 {
5f4cb198
NC
10711 unsigned int value = inst.reloc.exp.X_add_number;
10712 unsigned int shift = inst.operands[2].shift_kind;
10713
c19d1205
ZW
10714 Rn = inst.operands[2].reg;
10715 /* See if we can do this with a 16-bit instruction. */
10716 if (!inst.operands[2].shifted && inst.size_req != 4)
10717 {
e27ec89e
PB
10718 if (Rd > 7 || Rs > 7 || Rn > 7)
10719 narrow = FALSE;
10720
10721 if (narrow)
c19d1205 10722 {
e27ec89e
PB
10723 inst.instruction = ((inst.instruction == T_MNEM_adds
10724 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10725 ? T_OPCODE_ADD_R3
10726 : T_OPCODE_SUB_R3);
10727 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10728 return;
10729 }
b99bd4ef 10730
7e806470 10731 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10732 {
7e806470
PB
10733 /* Thumb-1 cores (except v6-M) require at least one high
10734 register in a narrow non flag setting add. */
10735 if (Rd > 7 || Rn > 7
10736 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10737 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10738 {
7e806470
PB
10739 if (Rd == Rn)
10740 {
10741 Rn = Rs;
10742 Rs = Rd;
10743 }
c19d1205
ZW
10744 inst.instruction = T_OPCODE_ADD_HI;
10745 inst.instruction |= (Rd & 8) << 4;
10746 inst.instruction |= (Rd & 7);
10747 inst.instruction |= Rn << 3;
10748 return;
10749 }
c19d1205
ZW
10750 }
10751 }
c921be7d 10752
fdfde340 10753 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10754 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10755 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10756 constraint (Rs == REG_PC, BAD_PC);
10757 reject_bad_reg (Rn);
10758
c19d1205
ZW
10759 /* If we get here, it can't be done in 16 bits. */
10760 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10761 _("shift must be constant"));
10762 inst.instruction = THUMB_OP32 (inst.instruction);
10763 inst.instruction |= Rd << 8;
10764 inst.instruction |= Rs << 16;
5f4cb198
NC
10765 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10766 _("shift value over 3 not allowed in thumb mode"));
10767 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10768 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10769 encode_thumb32_shifted_operand (2);
10770 }
10771 }
10772 else
10773 {
10774 constraint (inst.instruction == T_MNEM_adds
10775 || inst.instruction == T_MNEM_subs,
10776 BAD_THUMB32);
b99bd4ef 10777
c19d1205 10778 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10779 {
c19d1205
ZW
10780 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10781 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10782 BAD_HIREG);
10783
10784 inst.instruction = (inst.instruction == T_MNEM_add
10785 ? 0x0000 : 0x8000);
10786 inst.instruction |= (Rd << 4) | Rs;
10787 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10788 return;
10789 }
10790
c19d1205
ZW
10791 Rn = inst.operands[2].reg;
10792 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10793
c19d1205
ZW
10794 /* We now have Rd, Rs, and Rn set to registers. */
10795 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10796 {
c19d1205
ZW
10797 /* Can't do this for SUB. */
10798 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10799 inst.instruction = T_OPCODE_ADD_HI;
10800 inst.instruction |= (Rd & 8) << 4;
10801 inst.instruction |= (Rd & 7);
10802 if (Rs == Rd)
10803 inst.instruction |= Rn << 3;
10804 else if (Rn == Rd)
10805 inst.instruction |= Rs << 3;
10806 else
10807 constraint (1, _("dest must overlap one source register"));
10808 }
10809 else
10810 {
10811 inst.instruction = (inst.instruction == T_MNEM_add
10812 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10813 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10814 }
b99bd4ef 10815 }
b99bd4ef
NC
10816}
10817
c19d1205
ZW
10818static void
10819do_t_adr (void)
10820{
fdfde340
JM
10821 unsigned Rd;
10822
10823 Rd = inst.operands[0].reg;
10824 reject_bad_reg (Rd);
10825
10826 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10827 {
10828 /* Defer to section relaxation. */
10829 inst.relax = inst.instruction;
10830 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10831 inst.instruction |= Rd << 4;
0110f2b8
PB
10832 }
10833 else if (unified_syntax && inst.size_req != 2)
e9f89963 10834 {
0110f2b8 10835 /* Generate a 32-bit opcode. */
e9f89963 10836 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10837 inst.instruction |= Rd << 8;
e9f89963
PB
10838 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10839 inst.reloc.pc_rel = 1;
10840 }
10841 else
10842 {
0110f2b8 10843 /* Generate a 16-bit opcode. */
e9f89963
PB
10844 inst.instruction = THUMB_OP16 (inst.instruction);
10845 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10846 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10847 inst.reloc.pc_rel = 1;
fdfde340 10848 inst.instruction |= Rd << 4;
e9f89963 10849 }
52a86f84
NC
10850
10851 if (inst.reloc.exp.X_op == O_symbol
10852 && inst.reloc.exp.X_add_symbol != NULL
10853 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10854 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10855 inst.reloc.exp.X_add_number += 1;
c19d1205 10856}
b99bd4ef 10857
c19d1205
ZW
10858/* Arithmetic instructions for which there is just one 16-bit
10859 instruction encoding, and it allows only two low registers.
10860 For maximal compatibility with ARM syntax, we allow three register
10861 operands even when Thumb-32 instructions are not available, as long
10862 as the first two are identical. For instance, both "sbc r0,r1" and
10863 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10864static void
c19d1205 10865do_t_arit3 (void)
b99bd4ef 10866{
c19d1205 10867 int Rd, Rs, Rn;
b99bd4ef 10868
c19d1205
ZW
10869 Rd = inst.operands[0].reg;
10870 Rs = (inst.operands[1].present
10871 ? inst.operands[1].reg /* Rd, Rs, foo */
10872 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10873 Rn = inst.operands[2].reg;
b99bd4ef 10874
fdfde340
JM
10875 reject_bad_reg (Rd);
10876 reject_bad_reg (Rs);
10877 if (inst.operands[2].isreg)
10878 reject_bad_reg (Rn);
10879
c19d1205 10880 if (unified_syntax)
b99bd4ef 10881 {
c19d1205
ZW
10882 if (!inst.operands[2].isreg)
10883 {
10884 /* For an immediate, we always generate a 32-bit opcode;
10885 section relaxation will shrink it later if possible. */
10886 inst.instruction = THUMB_OP32 (inst.instruction);
10887 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10888 inst.instruction |= Rd << 8;
10889 inst.instruction |= Rs << 16;
10890 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10891 }
10892 else
10893 {
e27ec89e
PB
10894 bfd_boolean narrow;
10895
c19d1205 10896 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10897 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10898 narrow = !in_it_block ();
e27ec89e 10899 else
e07e6e58 10900 narrow = in_it_block ();
e27ec89e
PB
10901
10902 if (Rd > 7 || Rn > 7 || Rs > 7)
10903 narrow = FALSE;
10904 if (inst.operands[2].shifted)
10905 narrow = FALSE;
10906 if (inst.size_req == 4)
10907 narrow = FALSE;
10908
10909 if (narrow
c19d1205
ZW
10910 && Rd == Rs)
10911 {
10912 inst.instruction = THUMB_OP16 (inst.instruction);
10913 inst.instruction |= Rd;
10914 inst.instruction |= Rn << 3;
10915 return;
10916 }
b99bd4ef 10917
c19d1205
ZW
10918 /* If we get here, it can't be done in 16 bits. */
10919 constraint (inst.operands[2].shifted
10920 && inst.operands[2].immisreg,
10921 _("shift must be constant"));
10922 inst.instruction = THUMB_OP32 (inst.instruction);
10923 inst.instruction |= Rd << 8;
10924 inst.instruction |= Rs << 16;
10925 encode_thumb32_shifted_operand (2);
10926 }
a737bd4d 10927 }
c19d1205 10928 else
b99bd4ef 10929 {
c19d1205
ZW
10930 /* On its face this is a lie - the instruction does set the
10931 flags. However, the only supported mnemonic in this mode
10932 says it doesn't. */
10933 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10934
c19d1205
ZW
10935 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10936 _("unshifted register required"));
10937 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10938 constraint (Rd != Rs,
10939 _("dest and source1 must be the same register"));
a737bd4d 10940
c19d1205
ZW
10941 inst.instruction = THUMB_OP16 (inst.instruction);
10942 inst.instruction |= Rd;
10943 inst.instruction |= Rn << 3;
b99bd4ef 10944 }
a737bd4d 10945}
b99bd4ef 10946
c19d1205
ZW
10947/* Similarly, but for instructions where the arithmetic operation is
10948 commutative, so we can allow either of them to be different from
10949 the destination operand in a 16-bit instruction. For instance, all
10950 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10951 accepted. */
10952static void
10953do_t_arit3c (void)
a737bd4d 10954{
c19d1205 10955 int Rd, Rs, Rn;
b99bd4ef 10956
c19d1205
ZW
10957 Rd = inst.operands[0].reg;
10958 Rs = (inst.operands[1].present
10959 ? inst.operands[1].reg /* Rd, Rs, foo */
10960 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10961 Rn = inst.operands[2].reg;
c921be7d 10962
fdfde340
JM
10963 reject_bad_reg (Rd);
10964 reject_bad_reg (Rs);
10965 if (inst.operands[2].isreg)
10966 reject_bad_reg (Rn);
a737bd4d 10967
c19d1205 10968 if (unified_syntax)
a737bd4d 10969 {
c19d1205 10970 if (!inst.operands[2].isreg)
b99bd4ef 10971 {
c19d1205
ZW
10972 /* For an immediate, we always generate a 32-bit opcode;
10973 section relaxation will shrink it later if possible. */
10974 inst.instruction = THUMB_OP32 (inst.instruction);
10975 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10976 inst.instruction |= Rd << 8;
10977 inst.instruction |= Rs << 16;
10978 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10979 }
c19d1205 10980 else
a737bd4d 10981 {
e27ec89e
PB
10982 bfd_boolean narrow;
10983
c19d1205 10984 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10985 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10986 narrow = !in_it_block ();
e27ec89e 10987 else
e07e6e58 10988 narrow = in_it_block ();
e27ec89e
PB
10989
10990 if (Rd > 7 || Rn > 7 || Rs > 7)
10991 narrow = FALSE;
10992 if (inst.operands[2].shifted)
10993 narrow = FALSE;
10994 if (inst.size_req == 4)
10995 narrow = FALSE;
10996
10997 if (narrow)
a737bd4d 10998 {
c19d1205 10999 if (Rd == Rs)
a737bd4d 11000 {
c19d1205
ZW
11001 inst.instruction = THUMB_OP16 (inst.instruction);
11002 inst.instruction |= Rd;
11003 inst.instruction |= Rn << 3;
11004 return;
a737bd4d 11005 }
c19d1205 11006 if (Rd == Rn)
a737bd4d 11007 {
c19d1205
ZW
11008 inst.instruction = THUMB_OP16 (inst.instruction);
11009 inst.instruction |= Rd;
11010 inst.instruction |= Rs << 3;
11011 return;
a737bd4d
NC
11012 }
11013 }
c19d1205
ZW
11014
11015 /* If we get here, it can't be done in 16 bits. */
11016 constraint (inst.operands[2].shifted
11017 && inst.operands[2].immisreg,
11018 _("shift must be constant"));
11019 inst.instruction = THUMB_OP32 (inst.instruction);
11020 inst.instruction |= Rd << 8;
11021 inst.instruction |= Rs << 16;
11022 encode_thumb32_shifted_operand (2);
a737bd4d 11023 }
b99bd4ef 11024 }
c19d1205
ZW
11025 else
11026 {
11027 /* On its face this is a lie - the instruction does set the
11028 flags. However, the only supported mnemonic in this mode
11029 says it doesn't. */
11030 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 11031
c19d1205
ZW
11032 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11033 _("unshifted register required"));
11034 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11035
11036 inst.instruction = THUMB_OP16 (inst.instruction);
11037 inst.instruction |= Rd;
11038
11039 if (Rd == Rs)
11040 inst.instruction |= Rn << 3;
11041 else if (Rd == Rn)
11042 inst.instruction |= Rs << 3;
11043 else
11044 constraint (1, _("dest must overlap one source register"));
11045 }
a737bd4d
NC
11046}
11047
c19d1205
ZW
11048static void
11049do_t_bfc (void)
a737bd4d 11050{
fdfde340 11051 unsigned Rd;
c19d1205
ZW
11052 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11053 constraint (msb > 32, _("bit-field extends past end of register"));
11054 /* The instruction encoding stores the LSB and MSB,
11055 not the LSB and width. */
fdfde340
JM
11056 Rd = inst.operands[0].reg;
11057 reject_bad_reg (Rd);
11058 inst.instruction |= Rd << 8;
c19d1205
ZW
11059 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11060 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11061 inst.instruction |= msb - 1;
b99bd4ef
NC
11062}
11063
c19d1205
ZW
11064static void
11065do_t_bfi (void)
b99bd4ef 11066{
fdfde340 11067 int Rd, Rn;
c19d1205 11068 unsigned int msb;
b99bd4ef 11069
fdfde340
JM
11070 Rd = inst.operands[0].reg;
11071 reject_bad_reg (Rd);
11072
c19d1205
ZW
11073 /* #0 in second position is alternative syntax for bfc, which is
11074 the same instruction but with REG_PC in the Rm field. */
11075 if (!inst.operands[1].isreg)
fdfde340
JM
11076 Rn = REG_PC;
11077 else
11078 {
11079 Rn = inst.operands[1].reg;
11080 reject_bad_reg (Rn);
11081 }
b99bd4ef 11082
c19d1205
ZW
11083 msb = inst.operands[2].imm + inst.operands[3].imm;
11084 constraint (msb > 32, _("bit-field extends past end of register"));
11085 /* The instruction encoding stores the LSB and MSB,
11086 not the LSB and width. */
fdfde340
JM
11087 inst.instruction |= Rd << 8;
11088 inst.instruction |= Rn << 16;
c19d1205
ZW
11089 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11090 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11091 inst.instruction |= msb - 1;
b99bd4ef
NC
11092}
11093
c19d1205
ZW
11094static void
11095do_t_bfx (void)
b99bd4ef 11096{
fdfde340
JM
11097 unsigned Rd, Rn;
11098
11099 Rd = inst.operands[0].reg;
11100 Rn = inst.operands[1].reg;
11101
11102 reject_bad_reg (Rd);
11103 reject_bad_reg (Rn);
11104
c19d1205
ZW
11105 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11106 _("bit-field extends past end of register"));
fdfde340
JM
11107 inst.instruction |= Rd << 8;
11108 inst.instruction |= Rn << 16;
c19d1205
ZW
11109 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11110 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11111 inst.instruction |= inst.operands[3].imm - 1;
11112}
b99bd4ef 11113
c19d1205
ZW
11114/* ARM V5 Thumb BLX (argument parse)
11115 BLX <target_addr> which is BLX(1)
11116 BLX <Rm> which is BLX(2)
11117 Unfortunately, there are two different opcodes for this mnemonic.
11118 So, the insns[].value is not used, and the code here zaps values
11119 into inst.instruction.
b99bd4ef 11120
c19d1205
ZW
11121 ??? How to take advantage of the additional two bits of displacement
11122 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11123
c19d1205
ZW
11124static void
11125do_t_blx (void)
11126{
e07e6e58
NC
11127 set_it_insn_type_last ();
11128
c19d1205 11129 if (inst.operands[0].isreg)
fdfde340
JM
11130 {
11131 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11132 /* We have a register, so this is BLX(2). */
11133 inst.instruction |= inst.operands[0].reg << 3;
11134 }
b99bd4ef
NC
11135 else
11136 {
c19d1205 11137 /* No register. This must be BLX(1). */
2fc8bdac 11138 inst.instruction = 0xf000e800;
0855e32b 11139 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11140 }
11141}
11142
c19d1205
ZW
11143static void
11144do_t_branch (void)
b99bd4ef 11145{
0110f2b8 11146 int opcode;
dfa9f0d5 11147 int cond;
2fe88214 11148 bfd_reloc_code_real_type reloc;
dfa9f0d5 11149
e07e6e58
NC
11150 cond = inst.cond;
11151 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11152
11153 if (in_it_block ())
dfa9f0d5
PB
11154 {
11155 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11156 branches. */
dfa9f0d5 11157 cond = COND_ALWAYS;
dfa9f0d5
PB
11158 }
11159 else
11160 cond = inst.cond;
11161
11162 if (cond != COND_ALWAYS)
0110f2b8
PB
11163 opcode = T_MNEM_bcond;
11164 else
11165 opcode = inst.instruction;
11166
12d6b0b7
RS
11167 if (unified_syntax
11168 && (inst.size_req == 4
10960bfb
PB
11169 || (inst.size_req != 2
11170 && (inst.operands[0].hasreloc
11171 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11172 {
0110f2b8 11173 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11174 if (cond == COND_ALWAYS)
9ae92b05 11175 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11176 else
11177 {
ff8646ee
TP
11178 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11179 _("selected architecture does not support "
11180 "wide conditional branch instruction"));
11181
9c2799c2 11182 gas_assert (cond != 0xF);
dfa9f0d5 11183 inst.instruction |= cond << 22;
9ae92b05 11184 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11185 }
11186 }
b99bd4ef
NC
11187 else
11188 {
0110f2b8 11189 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11190 if (cond == COND_ALWAYS)
9ae92b05 11191 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11192 else
b99bd4ef 11193 {
dfa9f0d5 11194 inst.instruction |= cond << 8;
9ae92b05 11195 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11196 }
0110f2b8
PB
11197 /* Allow section relaxation. */
11198 if (unified_syntax && inst.size_req != 2)
11199 inst.relax = opcode;
b99bd4ef 11200 }
9ae92b05 11201 inst.reloc.type = reloc;
c19d1205 11202 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11203}
11204
8884b720 11205/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11206 between the two is the maximum immediate allowed - which is passed in
8884b720 11207 RANGE. */
b99bd4ef 11208static void
8884b720 11209do_t_bkpt_hlt1 (int range)
b99bd4ef 11210{
dfa9f0d5
PB
11211 constraint (inst.cond != COND_ALWAYS,
11212 _("instruction is always unconditional"));
c19d1205 11213 if (inst.operands[0].present)
b99bd4ef 11214 {
8884b720 11215 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11216 _("immediate value out of range"));
11217 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11218 }
8884b720
MGD
11219
11220 set_it_insn_type (NEUTRAL_IT_INSN);
11221}
11222
11223static void
11224do_t_hlt (void)
11225{
11226 do_t_bkpt_hlt1 (63);
11227}
11228
11229static void
11230do_t_bkpt (void)
11231{
11232 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11233}
11234
11235static void
c19d1205 11236do_t_branch23 (void)
b99bd4ef 11237{
e07e6e58 11238 set_it_insn_type_last ();
0855e32b 11239 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11240
0855e32b
NS
11241 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11242 this file. We used to simply ignore the PLT reloc type here --
11243 the branch encoding is now needed to deal with TLSCALL relocs.
11244 So if we see a PLT reloc now, put it back to how it used to be to
11245 keep the preexisting behaviour. */
11246 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11247 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11248
4343666d 11249#if defined(OBJ_COFF)
c19d1205
ZW
11250 /* If the destination of the branch is a defined symbol which does not have
11251 the THUMB_FUNC attribute, then we must be calling a function which has
11252 the (interfacearm) attribute. We look for the Thumb entry point to that
11253 function and change the branch to refer to that function instead. */
11254 if ( inst.reloc.exp.X_op == O_symbol
11255 && inst.reloc.exp.X_add_symbol != NULL
11256 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11257 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11258 inst.reloc.exp.X_add_symbol =
11259 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11260#endif
90e4755a
RE
11261}
11262
11263static void
c19d1205 11264do_t_bx (void)
90e4755a 11265{
e07e6e58 11266 set_it_insn_type_last ();
c19d1205
ZW
11267 inst.instruction |= inst.operands[0].reg << 3;
11268 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11269 should cause the alignment to be checked once it is known. This is
11270 because BX PC only works if the instruction is word aligned. */
11271}
90e4755a 11272
c19d1205
ZW
11273static void
11274do_t_bxj (void)
11275{
fdfde340 11276 int Rm;
90e4755a 11277
e07e6e58 11278 set_it_insn_type_last ();
fdfde340
JM
11279 Rm = inst.operands[0].reg;
11280 reject_bad_reg (Rm);
11281 inst.instruction |= Rm << 16;
90e4755a
RE
11282}
11283
11284static void
c19d1205 11285do_t_clz (void)
90e4755a 11286{
fdfde340
JM
11287 unsigned Rd;
11288 unsigned Rm;
11289
11290 Rd = inst.operands[0].reg;
11291 Rm = inst.operands[1].reg;
11292
11293 reject_bad_reg (Rd);
11294 reject_bad_reg (Rm);
11295
11296 inst.instruction |= Rd << 8;
11297 inst.instruction |= Rm << 16;
11298 inst.instruction |= Rm;
c19d1205 11299}
90e4755a 11300
91d8b670
JG
11301static void
11302do_t_csdb (void)
11303{
11304 set_it_insn_type (OUTSIDE_IT_INSN);
11305}
11306
dfa9f0d5
PB
11307static void
11308do_t_cps (void)
11309{
e07e6e58 11310 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11311 inst.instruction |= inst.operands[0].imm;
11312}
11313
c19d1205
ZW
11314static void
11315do_t_cpsi (void)
11316{
e07e6e58 11317 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11318 if (unified_syntax
62b3e311
PB
11319 && (inst.operands[1].present || inst.size_req == 4)
11320 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11321 {
c19d1205
ZW
11322 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11323 inst.instruction = 0xf3af8000;
11324 inst.instruction |= imod << 9;
11325 inst.instruction |= inst.operands[0].imm << 5;
11326 if (inst.operands[1].present)
11327 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11328 }
c19d1205 11329 else
90e4755a 11330 {
62b3e311
PB
11331 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11332 && (inst.operands[0].imm & 4),
11333 _("selected processor does not support 'A' form "
11334 "of this instruction"));
11335 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11336 _("Thumb does not support the 2-argument "
11337 "form of this instruction"));
11338 inst.instruction |= inst.operands[0].imm;
90e4755a 11339 }
90e4755a
RE
11340}
11341
c19d1205
ZW
11342/* THUMB CPY instruction (argument parse). */
11343
90e4755a 11344static void
c19d1205 11345do_t_cpy (void)
90e4755a 11346{
c19d1205 11347 if (inst.size_req == 4)
90e4755a 11348 {
c19d1205
ZW
11349 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11350 inst.instruction |= inst.operands[0].reg << 8;
11351 inst.instruction |= inst.operands[1].reg;
90e4755a 11352 }
c19d1205 11353 else
90e4755a 11354 {
c19d1205
ZW
11355 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11356 inst.instruction |= (inst.operands[0].reg & 0x7);
11357 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11358 }
90e4755a
RE
11359}
11360
90e4755a 11361static void
25fe350b 11362do_t_cbz (void)
90e4755a 11363{
e07e6e58 11364 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11365 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11366 inst.instruction |= inst.operands[0].reg;
11367 inst.reloc.pc_rel = 1;
11368 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11369}
90e4755a 11370
62b3e311
PB
11371static void
11372do_t_dbg (void)
11373{
11374 inst.instruction |= inst.operands[0].imm;
11375}
11376
11377static void
11378do_t_div (void)
11379{
fdfde340
JM
11380 unsigned Rd, Rn, Rm;
11381
11382 Rd = inst.operands[0].reg;
11383 Rn = (inst.operands[1].present
11384 ? inst.operands[1].reg : Rd);
11385 Rm = inst.operands[2].reg;
11386
11387 reject_bad_reg (Rd);
11388 reject_bad_reg (Rn);
11389 reject_bad_reg (Rm);
11390
11391 inst.instruction |= Rd << 8;
11392 inst.instruction |= Rn << 16;
11393 inst.instruction |= Rm;
62b3e311
PB
11394}
11395
c19d1205
ZW
11396static void
11397do_t_hint (void)
11398{
11399 if (unified_syntax && inst.size_req == 4)
11400 inst.instruction = THUMB_OP32 (inst.instruction);
11401 else
11402 inst.instruction = THUMB_OP16 (inst.instruction);
11403}
90e4755a 11404
c19d1205
ZW
11405static void
11406do_t_it (void)
11407{
11408 unsigned int cond = inst.operands[0].imm;
e27ec89e 11409
e07e6e58
NC
11410 set_it_insn_type (IT_INSN);
11411 now_it.mask = (inst.instruction & 0xf) | 0x10;
11412 now_it.cc = cond;
5a01bb1d 11413 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11414
11415 /* If the condition is a negative condition, invert the mask. */
c19d1205 11416 if ((cond & 0x1) == 0x0)
90e4755a 11417 {
c19d1205 11418 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11419
c19d1205 11420 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11421 {
11422 /* No conversion needed. */
11423 now_it.block_length = 1;
11424 }
c19d1205 11425 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11426 {
11427 mask ^= 0x8;
11428 now_it.block_length = 2;
11429 }
e27ec89e 11430 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11431 {
11432 mask ^= 0xC;
11433 now_it.block_length = 3;
11434 }
c19d1205 11435 else
5a01bb1d
MGD
11436 {
11437 mask ^= 0xE;
11438 now_it.block_length = 4;
11439 }
90e4755a 11440
e27ec89e
PB
11441 inst.instruction &= 0xfff0;
11442 inst.instruction |= mask;
c19d1205 11443 }
90e4755a 11444
c19d1205
ZW
11445 inst.instruction |= cond << 4;
11446}
90e4755a 11447
3c707909
PB
11448/* Helper function used for both push/pop and ldm/stm. */
11449static void
11450encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11451{
11452 bfd_boolean load;
11453
11454 load = (inst.instruction & (1 << 20)) != 0;
11455
11456 if (mask & (1 << 13))
11457 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11458
11459 if ((mask & (1 << base)) != 0
11460 && writeback)
11461 inst.error = _("having the base register in the register list when "
11462 "using write back is UNPREDICTABLE");
11463
3c707909
PB
11464 if (load)
11465 {
e07e6e58 11466 if (mask & (1 << 15))
477330fc
RM
11467 {
11468 if (mask & (1 << 14))
11469 inst.error = _("LR and PC should not both be in register list");
11470 else
11471 set_it_insn_type_last ();
11472 }
3c707909
PB
11473 }
11474 else
11475 {
11476 if (mask & (1 << 15))
11477 inst.error = _("PC not allowed in register list");
3c707909
PB
11478 }
11479
11480 if ((mask & (mask - 1)) == 0)
11481 {
11482 /* Single register transfers implemented as str/ldr. */
11483 if (writeback)
11484 {
11485 if (inst.instruction & (1 << 23))
11486 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11487 else
11488 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11489 }
11490 else
11491 {
11492 if (inst.instruction & (1 << 23))
11493 inst.instruction = 0x00800000; /* ia -> [base] */
11494 else
11495 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11496 }
11497
11498 inst.instruction |= 0xf8400000;
11499 if (load)
11500 inst.instruction |= 0x00100000;
11501
5f4273c7 11502 mask = ffs (mask) - 1;
3c707909
PB
11503 mask <<= 12;
11504 }
11505 else if (writeback)
11506 inst.instruction |= WRITE_BACK;
11507
11508 inst.instruction |= mask;
11509 inst.instruction |= base << 16;
11510}
11511
c19d1205
ZW
11512static void
11513do_t_ldmstm (void)
11514{
11515 /* This really doesn't seem worth it. */
11516 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11517 _("expression too complex"));
11518 constraint (inst.operands[1].writeback,
11519 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11520
c19d1205
ZW
11521 if (unified_syntax)
11522 {
3c707909
PB
11523 bfd_boolean narrow;
11524 unsigned mask;
11525
11526 narrow = FALSE;
c19d1205
ZW
11527 /* See if we can use a 16-bit instruction. */
11528 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11529 && inst.size_req != 4
3c707909 11530 && !(inst.operands[1].imm & ~0xff))
90e4755a 11531 {
3c707909 11532 mask = 1 << inst.operands[0].reg;
90e4755a 11533
eab4f823 11534 if (inst.operands[0].reg <= 7)
90e4755a 11535 {
3c707909 11536 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11537 ? inst.operands[0].writeback
11538 : (inst.operands[0].writeback
11539 == !(inst.operands[1].imm & mask)))
477330fc 11540 {
eab4f823
MGD
11541 if (inst.instruction == T_MNEM_stmia
11542 && (inst.operands[1].imm & mask)
11543 && (inst.operands[1].imm & (mask - 1)))
11544 as_warn (_("value stored for r%d is UNKNOWN"),
11545 inst.operands[0].reg);
3c707909 11546
eab4f823
MGD
11547 inst.instruction = THUMB_OP16 (inst.instruction);
11548 inst.instruction |= inst.operands[0].reg << 8;
11549 inst.instruction |= inst.operands[1].imm;
11550 narrow = TRUE;
11551 }
11552 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11553 {
11554 /* This means 1 register in reg list one of 3 situations:
11555 1. Instruction is stmia, but without writeback.
11556 2. lmdia without writeback, but with Rn not in
477330fc 11557 reglist.
eab4f823
MGD
11558 3. ldmia with writeback, but with Rn in reglist.
11559 Case 3 is UNPREDICTABLE behaviour, so we handle
11560 case 1 and 2 which can be converted into a 16-bit
11561 str or ldr. The SP cases are handled below. */
11562 unsigned long opcode;
11563 /* First, record an error for Case 3. */
11564 if (inst.operands[1].imm & mask
11565 && inst.operands[0].writeback)
fa94de6b 11566 inst.error =
eab4f823
MGD
11567 _("having the base register in the register list when "
11568 "using write back is UNPREDICTABLE");
fa94de6b
RM
11569
11570 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11571 : T_MNEM_ldr);
11572 inst.instruction = THUMB_OP16 (opcode);
11573 inst.instruction |= inst.operands[0].reg << 3;
11574 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11575 narrow = TRUE;
11576 }
90e4755a 11577 }
eab4f823 11578 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11579 {
eab4f823
MGD
11580 if (inst.operands[0].writeback)
11581 {
fa94de6b 11582 inst.instruction =
eab4f823 11583 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11584 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11585 inst.instruction |= inst.operands[1].imm;
477330fc 11586 narrow = TRUE;
eab4f823
MGD
11587 }
11588 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11589 {
fa94de6b 11590 inst.instruction =
eab4f823 11591 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11592 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11593 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11594 narrow = TRUE;
eab4f823 11595 }
90e4755a 11596 }
3c707909
PB
11597 }
11598
11599 if (!narrow)
11600 {
c19d1205
ZW
11601 if (inst.instruction < 0xffff)
11602 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11603
5f4273c7
NC
11604 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11605 inst.operands[0].writeback);
90e4755a
RE
11606 }
11607 }
c19d1205 11608 else
90e4755a 11609 {
c19d1205
ZW
11610 constraint (inst.operands[0].reg > 7
11611 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11612 constraint (inst.instruction != T_MNEM_ldmia
11613 && inst.instruction != T_MNEM_stmia,
11614 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11615 if (inst.instruction == T_MNEM_stmia)
f03698e6 11616 {
c19d1205
ZW
11617 if (!inst.operands[0].writeback)
11618 as_warn (_("this instruction will write back the base register"));
11619 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11620 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11621 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11622 inst.operands[0].reg);
f03698e6 11623 }
c19d1205 11624 else
90e4755a 11625 {
c19d1205
ZW
11626 if (!inst.operands[0].writeback
11627 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11628 as_warn (_("this instruction will write back the base register"));
11629 else if (inst.operands[0].writeback
11630 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11631 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11632 }
11633
c19d1205
ZW
11634 inst.instruction = THUMB_OP16 (inst.instruction);
11635 inst.instruction |= inst.operands[0].reg << 8;
11636 inst.instruction |= inst.operands[1].imm;
11637 }
11638}
e28cd48c 11639
c19d1205
ZW
11640static void
11641do_t_ldrex (void)
11642{
11643 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11644 || inst.operands[1].postind || inst.operands[1].writeback
11645 || inst.operands[1].immisreg || inst.operands[1].shifted
11646 || inst.operands[1].negative,
01cfc07f 11647 BAD_ADDR_MODE);
e28cd48c 11648
5be8be5d
DG
11649 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11650
c19d1205
ZW
11651 inst.instruction |= inst.operands[0].reg << 12;
11652 inst.instruction |= inst.operands[1].reg << 16;
11653 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11654}
e28cd48c 11655
c19d1205
ZW
11656static void
11657do_t_ldrexd (void)
11658{
11659 if (!inst.operands[1].present)
1cac9012 11660 {
c19d1205
ZW
11661 constraint (inst.operands[0].reg == REG_LR,
11662 _("r14 not allowed as first register "
11663 "when second register is omitted"));
11664 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11665 }
c19d1205
ZW
11666 constraint (inst.operands[0].reg == inst.operands[1].reg,
11667 BAD_OVERLAP);
b99bd4ef 11668
c19d1205
ZW
11669 inst.instruction |= inst.operands[0].reg << 12;
11670 inst.instruction |= inst.operands[1].reg << 8;
11671 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11672}
11673
11674static void
c19d1205 11675do_t_ldst (void)
b99bd4ef 11676{
0110f2b8
PB
11677 unsigned long opcode;
11678 int Rn;
11679
e07e6e58
NC
11680 if (inst.operands[0].isreg
11681 && !inst.operands[0].preind
11682 && inst.operands[0].reg == REG_PC)
11683 set_it_insn_type_last ();
11684
0110f2b8 11685 opcode = inst.instruction;
c19d1205 11686 if (unified_syntax)
b99bd4ef 11687 {
53365c0d
PB
11688 if (!inst.operands[1].isreg)
11689 {
11690 if (opcode <= 0xffff)
11691 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11692 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11693 return;
11694 }
0110f2b8
PB
11695 if (inst.operands[1].isreg
11696 && !inst.operands[1].writeback
c19d1205
ZW
11697 && !inst.operands[1].shifted && !inst.operands[1].postind
11698 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11699 && opcode <= 0xffff
11700 && inst.size_req != 4)
c19d1205 11701 {
0110f2b8
PB
11702 /* Insn may have a 16-bit form. */
11703 Rn = inst.operands[1].reg;
11704 if (inst.operands[1].immisreg)
11705 {
11706 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11707 /* [Rn, Rik] */
0110f2b8
PB
11708 if (Rn <= 7 && inst.operands[1].imm <= 7)
11709 goto op16;
5be8be5d
DG
11710 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11711 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11712 }
11713 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11714 && opcode != T_MNEM_ldrsb)
11715 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11716 || (Rn == REG_SP && opcode == T_MNEM_str))
11717 {
11718 /* [Rn, #const] */
11719 if (Rn > 7)
11720 {
11721 if (Rn == REG_PC)
11722 {
11723 if (inst.reloc.pc_rel)
11724 opcode = T_MNEM_ldr_pc2;
11725 else
11726 opcode = T_MNEM_ldr_pc;
11727 }
11728 else
11729 {
11730 if (opcode == T_MNEM_ldr)
11731 opcode = T_MNEM_ldr_sp;
11732 else
11733 opcode = T_MNEM_str_sp;
11734 }
11735 inst.instruction = inst.operands[0].reg << 8;
11736 }
11737 else
11738 {
11739 inst.instruction = inst.operands[0].reg;
11740 inst.instruction |= inst.operands[1].reg << 3;
11741 }
11742 inst.instruction |= THUMB_OP16 (opcode);
11743 if (inst.size_req == 2)
11744 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11745 else
11746 inst.relax = opcode;
11747 return;
11748 }
c19d1205 11749 }
0110f2b8 11750 /* Definitely a 32-bit variant. */
5be8be5d 11751
8d67f500
NC
11752 /* Warning for Erratum 752419. */
11753 if (opcode == T_MNEM_ldr
11754 && inst.operands[0].reg == REG_SP
11755 && inst.operands[1].writeback == 1
11756 && !inst.operands[1].immisreg)
11757 {
11758 if (no_cpu_selected ()
11759 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11760 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11761 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11762 as_warn (_("This instruction may be unpredictable "
11763 "if executed on M-profile cores "
11764 "with interrupts enabled."));
11765 }
11766
5be8be5d 11767 /* Do some validations regarding addressing modes. */
1be5fd2e 11768 if (inst.operands[1].immisreg)
5be8be5d
DG
11769 reject_bad_reg (inst.operands[1].imm);
11770
1be5fd2e
NC
11771 constraint (inst.operands[1].writeback == 1
11772 && inst.operands[0].reg == inst.operands[1].reg,
11773 BAD_OVERLAP);
11774
0110f2b8 11775 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11776 inst.instruction |= inst.operands[0].reg << 12;
11777 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11778 check_ldr_r15_aligned ();
b99bd4ef
NC
11779 return;
11780 }
11781
c19d1205
ZW
11782 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11783
11784 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11785 {
c19d1205
ZW
11786 /* Only [Rn,Rm] is acceptable. */
11787 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11788 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11789 || inst.operands[1].postind || inst.operands[1].shifted
11790 || inst.operands[1].negative,
11791 _("Thumb does not support this addressing mode"));
11792 inst.instruction = THUMB_OP16 (inst.instruction);
11793 goto op16;
b99bd4ef 11794 }
5f4273c7 11795
c19d1205
ZW
11796 inst.instruction = THUMB_OP16 (inst.instruction);
11797 if (!inst.operands[1].isreg)
8335d6aa 11798 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11799 return;
b99bd4ef 11800
c19d1205
ZW
11801 constraint (!inst.operands[1].preind
11802 || inst.operands[1].shifted
11803 || inst.operands[1].writeback,
11804 _("Thumb does not support this addressing mode"));
11805 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11806 {
c19d1205
ZW
11807 constraint (inst.instruction & 0x0600,
11808 _("byte or halfword not valid for base register"));
11809 constraint (inst.operands[1].reg == REG_PC
11810 && !(inst.instruction & THUMB_LOAD_BIT),
11811 _("r15 based store not allowed"));
11812 constraint (inst.operands[1].immisreg,
11813 _("invalid base register for register offset"));
b99bd4ef 11814
c19d1205
ZW
11815 if (inst.operands[1].reg == REG_PC)
11816 inst.instruction = T_OPCODE_LDR_PC;
11817 else if (inst.instruction & THUMB_LOAD_BIT)
11818 inst.instruction = T_OPCODE_LDR_SP;
11819 else
11820 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11821
c19d1205
ZW
11822 inst.instruction |= inst.operands[0].reg << 8;
11823 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11824 return;
11825 }
90e4755a 11826
c19d1205
ZW
11827 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11828 if (!inst.operands[1].immisreg)
11829 {
11830 /* Immediate offset. */
11831 inst.instruction |= inst.operands[0].reg;
11832 inst.instruction |= inst.operands[1].reg << 3;
11833 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11834 return;
11835 }
90e4755a 11836
c19d1205
ZW
11837 /* Register offset. */
11838 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11839 constraint (inst.operands[1].negative,
11840 _("Thumb does not support this addressing mode"));
90e4755a 11841
c19d1205
ZW
11842 op16:
11843 switch (inst.instruction)
11844 {
11845 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11846 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11847 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11848 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11849 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11850 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11851 case 0x5600 /* ldrsb */:
11852 case 0x5e00 /* ldrsh */: break;
11853 default: abort ();
11854 }
90e4755a 11855
c19d1205
ZW
11856 inst.instruction |= inst.operands[0].reg;
11857 inst.instruction |= inst.operands[1].reg << 3;
11858 inst.instruction |= inst.operands[1].imm << 6;
11859}
90e4755a 11860
c19d1205
ZW
11861static void
11862do_t_ldstd (void)
11863{
11864 if (!inst.operands[1].present)
b99bd4ef 11865 {
c19d1205
ZW
11866 inst.operands[1].reg = inst.operands[0].reg + 1;
11867 constraint (inst.operands[0].reg == REG_LR,
11868 _("r14 not allowed here"));
bd340a04 11869 constraint (inst.operands[0].reg == REG_R12,
477330fc 11870 _("r12 not allowed here"));
b99bd4ef 11871 }
bd340a04
MGD
11872
11873 if (inst.operands[2].writeback
11874 && (inst.operands[0].reg == inst.operands[2].reg
11875 || inst.operands[1].reg == inst.operands[2].reg))
11876 as_warn (_("base register written back, and overlaps "
477330fc 11877 "one of transfer registers"));
bd340a04 11878
c19d1205
ZW
11879 inst.instruction |= inst.operands[0].reg << 12;
11880 inst.instruction |= inst.operands[1].reg << 8;
11881 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11882}
11883
c19d1205
ZW
11884static void
11885do_t_ldstt (void)
11886{
11887 inst.instruction |= inst.operands[0].reg << 12;
11888 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11889}
a737bd4d 11890
b99bd4ef 11891static void
c19d1205 11892do_t_mla (void)
b99bd4ef 11893{
fdfde340 11894 unsigned Rd, Rn, Rm, Ra;
c921be7d 11895
fdfde340
JM
11896 Rd = inst.operands[0].reg;
11897 Rn = inst.operands[1].reg;
11898 Rm = inst.operands[2].reg;
11899 Ra = inst.operands[3].reg;
11900
11901 reject_bad_reg (Rd);
11902 reject_bad_reg (Rn);
11903 reject_bad_reg (Rm);
11904 reject_bad_reg (Ra);
11905
11906 inst.instruction |= Rd << 8;
11907 inst.instruction |= Rn << 16;
11908 inst.instruction |= Rm;
11909 inst.instruction |= Ra << 12;
c19d1205 11910}
b99bd4ef 11911
c19d1205
ZW
11912static void
11913do_t_mlal (void)
11914{
fdfde340
JM
11915 unsigned RdLo, RdHi, Rn, Rm;
11916
11917 RdLo = inst.operands[0].reg;
11918 RdHi = inst.operands[1].reg;
11919 Rn = inst.operands[2].reg;
11920 Rm = inst.operands[3].reg;
11921
11922 reject_bad_reg (RdLo);
11923 reject_bad_reg (RdHi);
11924 reject_bad_reg (Rn);
11925 reject_bad_reg (Rm);
11926
11927 inst.instruction |= RdLo << 12;
11928 inst.instruction |= RdHi << 8;
11929 inst.instruction |= Rn << 16;
11930 inst.instruction |= Rm;
c19d1205 11931}
b99bd4ef 11932
c19d1205
ZW
11933static void
11934do_t_mov_cmp (void)
11935{
fdfde340
JM
11936 unsigned Rn, Rm;
11937
11938 Rn = inst.operands[0].reg;
11939 Rm = inst.operands[1].reg;
11940
e07e6e58
NC
11941 if (Rn == REG_PC)
11942 set_it_insn_type_last ();
11943
c19d1205 11944 if (unified_syntax)
b99bd4ef 11945 {
c19d1205
ZW
11946 int r0off = (inst.instruction == T_MNEM_mov
11947 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11948 unsigned long opcode;
3d388997
PB
11949 bfd_boolean narrow;
11950 bfd_boolean low_regs;
11951
fdfde340 11952 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11953 opcode = inst.instruction;
e07e6e58 11954 if (in_it_block ())
0110f2b8 11955 narrow = opcode != T_MNEM_movs;
3d388997 11956 else
0110f2b8 11957 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11958 if (inst.size_req == 4
11959 || inst.operands[1].shifted)
11960 narrow = FALSE;
11961
efd81785
PB
11962 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11963 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11964 && !inst.operands[1].shifted
fdfde340
JM
11965 && Rn == REG_PC
11966 && Rm == REG_LR)
efd81785
PB
11967 {
11968 inst.instruction = T2_SUBS_PC_LR;
11969 return;
11970 }
11971
fdfde340
JM
11972 if (opcode == T_MNEM_cmp)
11973 {
11974 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11975 if (narrow)
11976 {
11977 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11978 but valid. */
11979 warn_deprecated_sp (Rm);
11980 /* R15 was documented as a valid choice for Rm in ARMv6,
11981 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11982 tools reject R15, so we do too. */
11983 constraint (Rm == REG_PC, BAD_PC);
11984 }
11985 else
11986 reject_bad_reg (Rm);
fdfde340
JM
11987 }
11988 else if (opcode == T_MNEM_mov
11989 || opcode == T_MNEM_movs)
11990 {
11991 if (inst.operands[1].isreg)
11992 {
11993 if (opcode == T_MNEM_movs)
11994 {
11995 reject_bad_reg (Rn);
11996 reject_bad_reg (Rm);
11997 }
76fa04a4
MGD
11998 else if (narrow)
11999 {
12000 /* This is mov.n. */
12001 if ((Rn == REG_SP || Rn == REG_PC)
12002 && (Rm == REG_SP || Rm == REG_PC))
12003 {
5c3696f8 12004 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
12005 "deprecated when r%u is the destination "
12006 "register."), Rm, Rn);
12007 }
12008 }
12009 else
12010 {
12011 /* This is mov.w. */
12012 constraint (Rn == REG_PC, BAD_PC);
12013 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
12014 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12015 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 12016 }
fdfde340
JM
12017 }
12018 else
12019 reject_bad_reg (Rn);
12020 }
12021
c19d1205
ZW
12022 if (!inst.operands[1].isreg)
12023 {
0110f2b8 12024 /* Immediate operand. */
e07e6e58 12025 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
12026 narrow = 0;
12027 if (low_regs && narrow)
12028 {
12029 inst.instruction = THUMB_OP16 (opcode);
fdfde340 12030 inst.instruction |= Rn << 8;
a9f02af8
MG
12031 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12032 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 12033 {
a9f02af8 12034 if (inst.size_req == 2)
72d98d16 12035 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
12036 else
12037 inst.relax = opcode;
72d98d16 12038 }
0110f2b8
PB
12039 }
12040 else
12041 {
a9f02af8
MG
12042 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12043 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
12044 THUMB1_RELOC_ONLY);
12045
0110f2b8
PB
12046 inst.instruction = THUMB_OP32 (inst.instruction);
12047 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12048 inst.instruction |= Rn << r0off;
0110f2b8
PB
12049 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12050 }
c19d1205 12051 }
728ca7c9
PB
12052 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12053 && (inst.instruction == T_MNEM_mov
12054 || inst.instruction == T_MNEM_movs))
12055 {
12056 /* Register shifts are encoded as separate shift instructions. */
12057 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12058
e07e6e58 12059 if (in_it_block ())
728ca7c9
PB
12060 narrow = !flags;
12061 else
12062 narrow = flags;
12063
12064 if (inst.size_req == 4)
12065 narrow = FALSE;
12066
12067 if (!low_regs || inst.operands[1].imm > 7)
12068 narrow = FALSE;
12069
fdfde340 12070 if (Rn != Rm)
728ca7c9
PB
12071 narrow = FALSE;
12072
12073 switch (inst.operands[1].shift_kind)
12074 {
12075 case SHIFT_LSL:
12076 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12077 break;
12078 case SHIFT_ASR:
12079 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12080 break;
12081 case SHIFT_LSR:
12082 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12083 break;
12084 case SHIFT_ROR:
12085 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12086 break;
12087 default:
5f4273c7 12088 abort ();
728ca7c9
PB
12089 }
12090
12091 inst.instruction = opcode;
12092 if (narrow)
12093 {
fdfde340 12094 inst.instruction |= Rn;
728ca7c9
PB
12095 inst.instruction |= inst.operands[1].imm << 3;
12096 }
12097 else
12098 {
12099 if (flags)
12100 inst.instruction |= CONDS_BIT;
12101
fdfde340
JM
12102 inst.instruction |= Rn << 8;
12103 inst.instruction |= Rm << 16;
728ca7c9
PB
12104 inst.instruction |= inst.operands[1].imm;
12105 }
12106 }
3d388997 12107 else if (!narrow)
c19d1205 12108 {
728ca7c9
PB
12109 /* Some mov with immediate shift have narrow variants.
12110 Register shifts are handled above. */
12111 if (low_regs && inst.operands[1].shifted
12112 && (inst.instruction == T_MNEM_mov
12113 || inst.instruction == T_MNEM_movs))
12114 {
e07e6e58 12115 if (in_it_block ())
728ca7c9
PB
12116 narrow = (inst.instruction == T_MNEM_mov);
12117 else
12118 narrow = (inst.instruction == T_MNEM_movs);
12119 }
12120
12121 if (narrow)
12122 {
12123 switch (inst.operands[1].shift_kind)
12124 {
12125 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12126 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12127 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12128 default: narrow = FALSE; break;
12129 }
12130 }
12131
12132 if (narrow)
12133 {
fdfde340
JM
12134 inst.instruction |= Rn;
12135 inst.instruction |= Rm << 3;
728ca7c9
PB
12136 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12137 }
12138 else
12139 {
12140 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12141 inst.instruction |= Rn << r0off;
728ca7c9
PB
12142 encode_thumb32_shifted_operand (1);
12143 }
c19d1205
ZW
12144 }
12145 else
12146 switch (inst.instruction)
12147 {
12148 case T_MNEM_mov:
837b3435 12149 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12150 results. Don't allow this. */
12151 if (low_regs)
12152 {
12153 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12154 "MOV Rd, Rs with two low registers is not "
12155 "permitted on this architecture");
fa94de6b 12156 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12157 arm_ext_v6);
12158 }
12159
c19d1205 12160 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12161 inst.instruction |= (Rn & 0x8) << 4;
12162 inst.instruction |= (Rn & 0x7);
12163 inst.instruction |= Rm << 3;
c19d1205 12164 break;
b99bd4ef 12165
c19d1205
ZW
12166 case T_MNEM_movs:
12167 /* We know we have low registers at this point.
941a8a52
MGD
12168 Generate LSLS Rd, Rs, #0. */
12169 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12170 inst.instruction |= Rn;
12171 inst.instruction |= Rm << 3;
c19d1205
ZW
12172 break;
12173
12174 case T_MNEM_cmp:
3d388997 12175 if (low_regs)
c19d1205
ZW
12176 {
12177 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12178 inst.instruction |= Rn;
12179 inst.instruction |= Rm << 3;
c19d1205
ZW
12180 }
12181 else
12182 {
12183 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12184 inst.instruction |= (Rn & 0x8) << 4;
12185 inst.instruction |= (Rn & 0x7);
12186 inst.instruction |= Rm << 3;
c19d1205
ZW
12187 }
12188 break;
12189 }
b99bd4ef
NC
12190 return;
12191 }
12192
c19d1205 12193 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12194
12195 /* PR 10443: Do not silently ignore shifted operands. */
12196 constraint (inst.operands[1].shifted,
12197 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12198
c19d1205 12199 if (inst.operands[1].isreg)
b99bd4ef 12200 {
fdfde340 12201 if (Rn < 8 && Rm < 8)
b99bd4ef 12202 {
c19d1205
ZW
12203 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12204 since a MOV instruction produces unpredictable results. */
12205 if (inst.instruction == T_OPCODE_MOV_I8)
12206 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12207 else
c19d1205 12208 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12209
fdfde340
JM
12210 inst.instruction |= Rn;
12211 inst.instruction |= Rm << 3;
b99bd4ef
NC
12212 }
12213 else
12214 {
c19d1205
ZW
12215 if (inst.instruction == T_OPCODE_MOV_I8)
12216 inst.instruction = T_OPCODE_MOV_HR;
12217 else
12218 inst.instruction = T_OPCODE_CMP_HR;
12219 do_t_cpy ();
b99bd4ef
NC
12220 }
12221 }
c19d1205 12222 else
b99bd4ef 12223 {
fdfde340 12224 constraint (Rn > 7,
c19d1205 12225 _("only lo regs allowed with immediate"));
fdfde340 12226 inst.instruction |= Rn << 8;
c19d1205
ZW
12227 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12228 }
12229}
b99bd4ef 12230
c19d1205
ZW
12231static void
12232do_t_mov16 (void)
12233{
fdfde340 12234 unsigned Rd;
b6895b4f
PB
12235 bfd_vma imm;
12236 bfd_boolean top;
12237
12238 top = (inst.instruction & 0x00800000) != 0;
12239 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12240 {
33eaf5de 12241 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12242 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12243 }
12244 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12245 {
33eaf5de 12246 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12247 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12248 }
12249
fdfde340
JM
12250 Rd = inst.operands[0].reg;
12251 reject_bad_reg (Rd);
12252
12253 inst.instruction |= Rd << 8;
b6895b4f
PB
12254 if (inst.reloc.type == BFD_RELOC_UNUSED)
12255 {
12256 imm = inst.reloc.exp.X_add_number;
12257 inst.instruction |= (imm & 0xf000) << 4;
12258 inst.instruction |= (imm & 0x0800) << 15;
12259 inst.instruction |= (imm & 0x0700) << 4;
12260 inst.instruction |= (imm & 0x00ff);
12261 }
c19d1205 12262}
b99bd4ef 12263
c19d1205
ZW
12264static void
12265do_t_mvn_tst (void)
12266{
fdfde340 12267 unsigned Rn, Rm;
c921be7d 12268
fdfde340
JM
12269 Rn = inst.operands[0].reg;
12270 Rm = inst.operands[1].reg;
12271
12272 if (inst.instruction == T_MNEM_cmp
12273 || inst.instruction == T_MNEM_cmn)
12274 constraint (Rn == REG_PC, BAD_PC);
12275 else
12276 reject_bad_reg (Rn);
12277 reject_bad_reg (Rm);
12278
c19d1205
ZW
12279 if (unified_syntax)
12280 {
12281 int r0off = (inst.instruction == T_MNEM_mvn
12282 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12283 bfd_boolean narrow;
12284
12285 if (inst.size_req == 4
12286 || inst.instruction > 0xffff
12287 || inst.operands[1].shifted
fdfde340 12288 || Rn > 7 || Rm > 7)
3d388997 12289 narrow = FALSE;
fe8b4cc3
KT
12290 else if (inst.instruction == T_MNEM_cmn
12291 || inst.instruction == T_MNEM_tst)
3d388997
PB
12292 narrow = TRUE;
12293 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12294 narrow = !in_it_block ();
3d388997 12295 else
e07e6e58 12296 narrow = in_it_block ();
3d388997 12297
c19d1205 12298 if (!inst.operands[1].isreg)
b99bd4ef 12299 {
c19d1205
ZW
12300 /* For an immediate, we always generate a 32-bit opcode;
12301 section relaxation will shrink it later if possible. */
12302 if (inst.instruction < 0xffff)
12303 inst.instruction = THUMB_OP32 (inst.instruction);
12304 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12305 inst.instruction |= Rn << r0off;
c19d1205 12306 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12307 }
c19d1205 12308 else
b99bd4ef 12309 {
c19d1205 12310 /* See if we can do this with a 16-bit instruction. */
3d388997 12311 if (narrow)
b99bd4ef 12312 {
c19d1205 12313 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12314 inst.instruction |= Rn;
12315 inst.instruction |= Rm << 3;
b99bd4ef 12316 }
c19d1205 12317 else
b99bd4ef 12318 {
c19d1205
ZW
12319 constraint (inst.operands[1].shifted
12320 && inst.operands[1].immisreg,
12321 _("shift must be constant"));
12322 if (inst.instruction < 0xffff)
12323 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12324 inst.instruction |= Rn << r0off;
c19d1205 12325 encode_thumb32_shifted_operand (1);
b99bd4ef 12326 }
b99bd4ef
NC
12327 }
12328 }
12329 else
12330 {
c19d1205
ZW
12331 constraint (inst.instruction > 0xffff
12332 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12333 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12334 _("unshifted register required"));
fdfde340 12335 constraint (Rn > 7 || Rm > 7,
c19d1205 12336 BAD_HIREG);
b99bd4ef 12337
c19d1205 12338 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12339 inst.instruction |= Rn;
12340 inst.instruction |= Rm << 3;
b99bd4ef 12341 }
b99bd4ef
NC
12342}
12343
b05fe5cf 12344static void
c19d1205 12345do_t_mrs (void)
b05fe5cf 12346{
fdfde340 12347 unsigned Rd;
037e8744
JB
12348
12349 if (do_vfp_nsyn_mrs () == SUCCESS)
12350 return;
12351
90ec0d68
MGD
12352 Rd = inst.operands[0].reg;
12353 reject_bad_reg (Rd);
12354 inst.instruction |= Rd << 8;
12355
12356 if (inst.operands[1].isreg)
62b3e311 12357 {
90ec0d68
MGD
12358 unsigned br = inst.operands[1].reg;
12359 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12360 as_bad (_("bad register for mrs"));
12361
12362 inst.instruction |= br & (0xf << 16);
12363 inst.instruction |= (br & 0x300) >> 4;
12364 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12365 }
12366 else
12367 {
90ec0d68 12368 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12369
d2cd1205 12370 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12371 {
12372 /* PR gas/12698: The constraint is only applied for m_profile.
12373 If the user has specified -march=all, we want to ignore it as
12374 we are building for any CPU type, including non-m variants. */
823d2571
TG
12375 bfd_boolean m_profile =
12376 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12377 constraint ((flags != 0) && m_profile, _("selected processor does "
12378 "not support requested special purpose register"));
12379 }
90ec0d68 12380 else
d2cd1205
JB
12381 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12382 devices). */
12383 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12384 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12385
90ec0d68
MGD
12386 inst.instruction |= (flags & SPSR_BIT) >> 2;
12387 inst.instruction |= inst.operands[1].imm & 0xff;
12388 inst.instruction |= 0xf0000;
12389 }
c19d1205 12390}
b05fe5cf 12391
c19d1205
ZW
12392static void
12393do_t_msr (void)
12394{
62b3e311 12395 int flags;
fdfde340 12396 unsigned Rn;
62b3e311 12397
037e8744
JB
12398 if (do_vfp_nsyn_msr () == SUCCESS)
12399 return;
12400
c19d1205
ZW
12401 constraint (!inst.operands[1].isreg,
12402 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12403
12404 if (inst.operands[0].isreg)
12405 flags = (int)(inst.operands[0].reg);
12406 else
12407 flags = inst.operands[0].imm;
12408
d2cd1205 12409 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12410 {
d2cd1205
JB
12411 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12412
1a43faaf 12413 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12414 If the user has specified -march=all, we want to ignore it as
12415 we are building for any CPU type, including non-m variants. */
823d2571
TG
12416 bfd_boolean m_profile =
12417 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12418 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12419 && (bits & ~(PSR_s | PSR_f)) != 0)
12420 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12421 && bits != PSR_f)) && m_profile,
12422 _("selected processor does not support requested special "
12423 "purpose register"));
62b3e311
PB
12424 }
12425 else
d2cd1205
JB
12426 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12427 "requested special purpose register"));
c921be7d 12428
fdfde340
JM
12429 Rn = inst.operands[1].reg;
12430 reject_bad_reg (Rn);
12431
62b3e311 12432 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12433 inst.instruction |= (flags & 0xf0000) >> 8;
12434 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12435 inst.instruction |= (flags & 0xff);
fdfde340 12436 inst.instruction |= Rn << 16;
c19d1205 12437}
b05fe5cf 12438
c19d1205
ZW
12439static void
12440do_t_mul (void)
12441{
17828f45 12442 bfd_boolean narrow;
fdfde340 12443 unsigned Rd, Rn, Rm;
17828f45 12444
c19d1205
ZW
12445 if (!inst.operands[2].present)
12446 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12447
fdfde340
JM
12448 Rd = inst.operands[0].reg;
12449 Rn = inst.operands[1].reg;
12450 Rm = inst.operands[2].reg;
12451
17828f45 12452 if (unified_syntax)
b05fe5cf 12453 {
17828f45 12454 if (inst.size_req == 4
fdfde340
JM
12455 || (Rd != Rn
12456 && Rd != Rm)
12457 || Rn > 7
12458 || Rm > 7)
17828f45
JM
12459 narrow = FALSE;
12460 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12461 narrow = !in_it_block ();
17828f45 12462 else
e07e6e58 12463 narrow = in_it_block ();
b05fe5cf 12464 }
c19d1205 12465 else
b05fe5cf 12466 {
17828f45 12467 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12468 constraint (Rn > 7 || Rm > 7,
c19d1205 12469 BAD_HIREG);
17828f45
JM
12470 narrow = TRUE;
12471 }
b05fe5cf 12472
17828f45
JM
12473 if (narrow)
12474 {
12475 /* 16-bit MULS/Conditional MUL. */
c19d1205 12476 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12477 inst.instruction |= Rd;
b05fe5cf 12478
fdfde340
JM
12479 if (Rd == Rn)
12480 inst.instruction |= Rm << 3;
12481 else if (Rd == Rm)
12482 inst.instruction |= Rn << 3;
c19d1205
ZW
12483 else
12484 constraint (1, _("dest must overlap one source register"));
12485 }
17828f45
JM
12486 else
12487 {
e07e6e58
NC
12488 constraint (inst.instruction != T_MNEM_mul,
12489 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12490 /* 32-bit MUL. */
12491 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12492 inst.instruction |= Rd << 8;
12493 inst.instruction |= Rn << 16;
12494 inst.instruction |= Rm << 0;
12495
12496 reject_bad_reg (Rd);
12497 reject_bad_reg (Rn);
12498 reject_bad_reg (Rm);
17828f45 12499 }
c19d1205 12500}
b05fe5cf 12501
c19d1205
ZW
12502static void
12503do_t_mull (void)
12504{
fdfde340 12505 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12506
fdfde340
JM
12507 RdLo = inst.operands[0].reg;
12508 RdHi = inst.operands[1].reg;
12509 Rn = inst.operands[2].reg;
12510 Rm = inst.operands[3].reg;
12511
12512 reject_bad_reg (RdLo);
12513 reject_bad_reg (RdHi);
12514 reject_bad_reg (Rn);
12515 reject_bad_reg (Rm);
12516
12517 inst.instruction |= RdLo << 12;
12518 inst.instruction |= RdHi << 8;
12519 inst.instruction |= Rn << 16;
12520 inst.instruction |= Rm;
12521
12522 if (RdLo == RdHi)
c19d1205
ZW
12523 as_tsktsk (_("rdhi and rdlo must be different"));
12524}
b05fe5cf 12525
c19d1205
ZW
12526static void
12527do_t_nop (void)
12528{
e07e6e58
NC
12529 set_it_insn_type (NEUTRAL_IT_INSN);
12530
c19d1205
ZW
12531 if (unified_syntax)
12532 {
12533 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12534 {
c19d1205
ZW
12535 inst.instruction = THUMB_OP32 (inst.instruction);
12536 inst.instruction |= inst.operands[0].imm;
12537 }
12538 else
12539 {
bc2d1808
NC
12540 /* PR9722: Check for Thumb2 availability before
12541 generating a thumb2 nop instruction. */
afa62d5e 12542 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12543 {
12544 inst.instruction = THUMB_OP16 (inst.instruction);
12545 inst.instruction |= inst.operands[0].imm << 4;
12546 }
12547 else
12548 inst.instruction = 0x46c0;
c19d1205
ZW
12549 }
12550 }
12551 else
12552 {
12553 constraint (inst.operands[0].present,
12554 _("Thumb does not support NOP with hints"));
12555 inst.instruction = 0x46c0;
12556 }
12557}
b05fe5cf 12558
c19d1205
ZW
12559static void
12560do_t_neg (void)
12561{
12562 if (unified_syntax)
12563 {
3d388997
PB
12564 bfd_boolean narrow;
12565
12566 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12567 narrow = !in_it_block ();
3d388997 12568 else
e07e6e58 12569 narrow = in_it_block ();
3d388997
PB
12570 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12571 narrow = FALSE;
12572 if (inst.size_req == 4)
12573 narrow = FALSE;
12574
12575 if (!narrow)
c19d1205
ZW
12576 {
12577 inst.instruction = THUMB_OP32 (inst.instruction);
12578 inst.instruction |= inst.operands[0].reg << 8;
12579 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12580 }
12581 else
12582 {
c19d1205
ZW
12583 inst.instruction = THUMB_OP16 (inst.instruction);
12584 inst.instruction |= inst.operands[0].reg;
12585 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12586 }
12587 }
12588 else
12589 {
c19d1205
ZW
12590 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12591 BAD_HIREG);
12592 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12593
12594 inst.instruction = THUMB_OP16 (inst.instruction);
12595 inst.instruction |= inst.operands[0].reg;
12596 inst.instruction |= inst.operands[1].reg << 3;
12597 }
12598}
12599
1c444d06
JM
12600static void
12601do_t_orn (void)
12602{
12603 unsigned Rd, Rn;
12604
12605 Rd = inst.operands[0].reg;
12606 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12607
fdfde340
JM
12608 reject_bad_reg (Rd);
12609 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12610 reject_bad_reg (Rn);
12611
1c444d06
JM
12612 inst.instruction |= Rd << 8;
12613 inst.instruction |= Rn << 16;
12614
12615 if (!inst.operands[2].isreg)
12616 {
12617 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12618 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12619 }
12620 else
12621 {
12622 unsigned Rm;
12623
12624 Rm = inst.operands[2].reg;
fdfde340 12625 reject_bad_reg (Rm);
1c444d06
JM
12626
12627 constraint (inst.operands[2].shifted
12628 && inst.operands[2].immisreg,
12629 _("shift must be constant"));
12630 encode_thumb32_shifted_operand (2);
12631 }
12632}
12633
c19d1205
ZW
12634static void
12635do_t_pkhbt (void)
12636{
fdfde340
JM
12637 unsigned Rd, Rn, Rm;
12638
12639 Rd = inst.operands[0].reg;
12640 Rn = inst.operands[1].reg;
12641 Rm = inst.operands[2].reg;
12642
12643 reject_bad_reg (Rd);
12644 reject_bad_reg (Rn);
12645 reject_bad_reg (Rm);
12646
12647 inst.instruction |= Rd << 8;
12648 inst.instruction |= Rn << 16;
12649 inst.instruction |= Rm;
c19d1205
ZW
12650 if (inst.operands[3].present)
12651 {
12652 unsigned int val = inst.reloc.exp.X_add_number;
12653 constraint (inst.reloc.exp.X_op != O_constant,
12654 _("expression too complex"));
12655 inst.instruction |= (val & 0x1c) << 10;
12656 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12657 }
c19d1205 12658}
b05fe5cf 12659
c19d1205
ZW
12660static void
12661do_t_pkhtb (void)
12662{
12663 if (!inst.operands[3].present)
1ef52f49
NC
12664 {
12665 unsigned Rtmp;
12666
12667 inst.instruction &= ~0x00000020;
12668
12669 /* PR 10168. Swap the Rm and Rn registers. */
12670 Rtmp = inst.operands[1].reg;
12671 inst.operands[1].reg = inst.operands[2].reg;
12672 inst.operands[2].reg = Rtmp;
12673 }
c19d1205 12674 do_t_pkhbt ();
b05fe5cf
ZW
12675}
12676
c19d1205
ZW
12677static void
12678do_t_pld (void)
12679{
fdfde340
JM
12680 if (inst.operands[0].immisreg)
12681 reject_bad_reg (inst.operands[0].imm);
12682
c19d1205
ZW
12683 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12684}
b05fe5cf 12685
c19d1205
ZW
12686static void
12687do_t_push_pop (void)
b99bd4ef 12688{
e9f89963 12689 unsigned mask;
5f4273c7 12690
c19d1205
ZW
12691 constraint (inst.operands[0].writeback,
12692 _("push/pop do not support {reglist}^"));
12693 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12694 _("expression too complex"));
b99bd4ef 12695
e9f89963 12696 mask = inst.operands[0].imm;
d3bfe16e 12697 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12698 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12699 else if (inst.size_req != 4
c6025a80 12700 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12701 ? REG_LR : REG_PC)))
b99bd4ef 12702 {
c19d1205
ZW
12703 inst.instruction = THUMB_OP16 (inst.instruction);
12704 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12705 inst.instruction |= mask & 0xff;
c19d1205
ZW
12706 }
12707 else if (unified_syntax)
12708 {
3c707909 12709 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12710 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12711 }
12712 else
12713 {
12714 inst.error = _("invalid register list to push/pop instruction");
12715 return;
12716 }
c19d1205 12717}
b99bd4ef 12718
c19d1205
ZW
12719static void
12720do_t_rbit (void)
12721{
fdfde340
JM
12722 unsigned Rd, Rm;
12723
12724 Rd = inst.operands[0].reg;
12725 Rm = inst.operands[1].reg;
12726
12727 reject_bad_reg (Rd);
12728 reject_bad_reg (Rm);
12729
12730 inst.instruction |= Rd << 8;
12731 inst.instruction |= Rm << 16;
12732 inst.instruction |= Rm;
c19d1205 12733}
b99bd4ef 12734
c19d1205
ZW
12735static void
12736do_t_rev (void)
12737{
fdfde340
JM
12738 unsigned Rd, Rm;
12739
12740 Rd = inst.operands[0].reg;
12741 Rm = inst.operands[1].reg;
12742
12743 reject_bad_reg (Rd);
12744 reject_bad_reg (Rm);
12745
12746 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12747 && inst.size_req != 4)
12748 {
12749 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12750 inst.instruction |= Rd;
12751 inst.instruction |= Rm << 3;
c19d1205
ZW
12752 }
12753 else if (unified_syntax)
12754 {
12755 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12756 inst.instruction |= Rd << 8;
12757 inst.instruction |= Rm << 16;
12758 inst.instruction |= Rm;
c19d1205
ZW
12759 }
12760 else
12761 inst.error = BAD_HIREG;
12762}
b99bd4ef 12763
1c444d06
JM
12764static void
12765do_t_rrx (void)
12766{
12767 unsigned Rd, Rm;
12768
12769 Rd = inst.operands[0].reg;
12770 Rm = inst.operands[1].reg;
12771
fdfde340
JM
12772 reject_bad_reg (Rd);
12773 reject_bad_reg (Rm);
c921be7d 12774
1c444d06
JM
12775 inst.instruction |= Rd << 8;
12776 inst.instruction |= Rm;
12777}
12778
c19d1205
ZW
12779static void
12780do_t_rsb (void)
12781{
fdfde340 12782 unsigned Rd, Rs;
b99bd4ef 12783
c19d1205
ZW
12784 Rd = inst.operands[0].reg;
12785 Rs = (inst.operands[1].present
12786 ? inst.operands[1].reg /* Rd, Rs, foo */
12787 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12788
fdfde340
JM
12789 reject_bad_reg (Rd);
12790 reject_bad_reg (Rs);
12791 if (inst.operands[2].isreg)
12792 reject_bad_reg (inst.operands[2].reg);
12793
c19d1205
ZW
12794 inst.instruction |= Rd << 8;
12795 inst.instruction |= Rs << 16;
12796 if (!inst.operands[2].isreg)
12797 {
026d3abb
PB
12798 bfd_boolean narrow;
12799
12800 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12801 narrow = !in_it_block ();
026d3abb 12802 else
e07e6e58 12803 narrow = in_it_block ();
026d3abb
PB
12804
12805 if (Rd > 7 || Rs > 7)
12806 narrow = FALSE;
12807
12808 if (inst.size_req == 4 || !unified_syntax)
12809 narrow = FALSE;
12810
12811 if (inst.reloc.exp.X_op != O_constant
12812 || inst.reloc.exp.X_add_number != 0)
12813 narrow = FALSE;
12814
12815 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12816 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12817 if (narrow)
12818 {
12819 inst.reloc.type = BFD_RELOC_UNUSED;
12820 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12821 inst.instruction |= Rs << 3;
12822 inst.instruction |= Rd;
12823 }
12824 else
12825 {
12826 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12827 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12828 }
c19d1205
ZW
12829 }
12830 else
12831 encode_thumb32_shifted_operand (2);
12832}
b99bd4ef 12833
c19d1205
ZW
12834static void
12835do_t_setend (void)
12836{
12e37cbc
MGD
12837 if (warn_on_deprecated
12838 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12839 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12840
e07e6e58 12841 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12842 if (inst.operands[0].imm)
12843 inst.instruction |= 0x8;
12844}
b99bd4ef 12845
c19d1205
ZW
12846static void
12847do_t_shift (void)
12848{
12849 if (!inst.operands[1].present)
12850 inst.operands[1].reg = inst.operands[0].reg;
12851
12852 if (unified_syntax)
12853 {
3d388997
PB
12854 bfd_boolean narrow;
12855 int shift_kind;
12856
12857 switch (inst.instruction)
12858 {
12859 case T_MNEM_asr:
12860 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12861 case T_MNEM_lsl:
12862 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12863 case T_MNEM_lsr:
12864 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12865 case T_MNEM_ror:
12866 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12867 default: abort ();
12868 }
12869
12870 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12871 narrow = !in_it_block ();
3d388997 12872 else
e07e6e58 12873 narrow = in_it_block ();
3d388997
PB
12874 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12875 narrow = FALSE;
12876 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12877 narrow = FALSE;
12878 if (inst.operands[2].isreg
12879 && (inst.operands[1].reg != inst.operands[0].reg
12880 || inst.operands[2].reg > 7))
12881 narrow = FALSE;
12882 if (inst.size_req == 4)
12883 narrow = FALSE;
12884
fdfde340
JM
12885 reject_bad_reg (inst.operands[0].reg);
12886 reject_bad_reg (inst.operands[1].reg);
c921be7d 12887
3d388997 12888 if (!narrow)
c19d1205
ZW
12889 {
12890 if (inst.operands[2].isreg)
b99bd4ef 12891 {
fdfde340 12892 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12893 inst.instruction = THUMB_OP32 (inst.instruction);
12894 inst.instruction |= inst.operands[0].reg << 8;
12895 inst.instruction |= inst.operands[1].reg << 16;
12896 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12897
12898 /* PR 12854: Error on extraneous shifts. */
12899 constraint (inst.operands[2].shifted,
12900 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12901 }
12902 else
12903 {
12904 inst.operands[1].shifted = 1;
3d388997 12905 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12906 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12907 ? T_MNEM_movs : T_MNEM_mov);
12908 inst.instruction |= inst.operands[0].reg << 8;
12909 encode_thumb32_shifted_operand (1);
12910 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12911 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12912 }
12913 }
12914 else
12915 {
c19d1205 12916 if (inst.operands[2].isreg)
b99bd4ef 12917 {
3d388997 12918 switch (shift_kind)
b99bd4ef 12919 {
3d388997
PB
12920 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12921 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12922 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12923 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12924 default: abort ();
b99bd4ef 12925 }
5f4273c7 12926
c19d1205
ZW
12927 inst.instruction |= inst.operands[0].reg;
12928 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12929
12930 /* PR 12854: Error on extraneous shifts. */
12931 constraint (inst.operands[2].shifted,
12932 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12933 }
12934 else
12935 {
3d388997 12936 switch (shift_kind)
b99bd4ef 12937 {
3d388997
PB
12938 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12939 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12940 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12941 default: abort ();
b99bd4ef 12942 }
c19d1205
ZW
12943 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12944 inst.instruction |= inst.operands[0].reg;
12945 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12946 }
12947 }
c19d1205
ZW
12948 }
12949 else
12950 {
12951 constraint (inst.operands[0].reg > 7
12952 || inst.operands[1].reg > 7, BAD_HIREG);
12953 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12954
c19d1205
ZW
12955 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12956 {
12957 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12958 constraint (inst.operands[0].reg != inst.operands[1].reg,
12959 _("source1 and dest must be same register"));
b99bd4ef 12960
c19d1205
ZW
12961 switch (inst.instruction)
12962 {
12963 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12964 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12965 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12966 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12967 default: abort ();
12968 }
5f4273c7 12969
c19d1205
ZW
12970 inst.instruction |= inst.operands[0].reg;
12971 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12972
12973 /* PR 12854: Error on extraneous shifts. */
12974 constraint (inst.operands[2].shifted,
12975 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12976 }
12977 else
b99bd4ef 12978 {
c19d1205
ZW
12979 switch (inst.instruction)
12980 {
12981 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12982 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12983 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12984 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12985 default: abort ();
12986 }
12987 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12988 inst.instruction |= inst.operands[0].reg;
12989 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12990 }
12991 }
b99bd4ef
NC
12992}
12993
12994static void
c19d1205 12995do_t_simd (void)
b99bd4ef 12996{
fdfde340
JM
12997 unsigned Rd, Rn, Rm;
12998
12999 Rd = inst.operands[0].reg;
13000 Rn = inst.operands[1].reg;
13001 Rm = inst.operands[2].reg;
13002
13003 reject_bad_reg (Rd);
13004 reject_bad_reg (Rn);
13005 reject_bad_reg (Rm);
13006
13007 inst.instruction |= Rd << 8;
13008 inst.instruction |= Rn << 16;
13009 inst.instruction |= Rm;
c19d1205 13010}
b99bd4ef 13011
03ee1b7f
NC
13012static void
13013do_t_simd2 (void)
13014{
13015 unsigned Rd, Rn, Rm;
13016
13017 Rd = inst.operands[0].reg;
13018 Rm = inst.operands[1].reg;
13019 Rn = inst.operands[2].reg;
13020
13021 reject_bad_reg (Rd);
13022 reject_bad_reg (Rn);
13023 reject_bad_reg (Rm);
13024
13025 inst.instruction |= Rd << 8;
13026 inst.instruction |= Rn << 16;
13027 inst.instruction |= Rm;
13028}
13029
c19d1205 13030static void
3eb17e6b 13031do_t_smc (void)
c19d1205
ZW
13032{
13033 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
13034 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13035 _("SMC is not permitted on this architecture"));
c19d1205
ZW
13036 constraint (inst.reloc.exp.X_op != O_constant,
13037 _("expression too complex"));
13038 inst.reloc.type = BFD_RELOC_UNUSED;
13039 inst.instruction |= (value & 0xf000) >> 12;
13040 inst.instruction |= (value & 0x0ff0);
13041 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13042 /* PR gas/15623: SMC instructions must be last in an IT block. */
13043 set_it_insn_type_last ();
c19d1205 13044}
b99bd4ef 13045
90ec0d68
MGD
13046static void
13047do_t_hvc (void)
13048{
13049 unsigned int value = inst.reloc.exp.X_add_number;
13050
13051 inst.reloc.type = BFD_RELOC_UNUSED;
13052 inst.instruction |= (value & 0x0fff);
13053 inst.instruction |= (value & 0xf000) << 4;
13054}
13055
c19d1205 13056static void
3a21c15a 13057do_t_ssat_usat (int bias)
c19d1205 13058{
fdfde340
JM
13059 unsigned Rd, Rn;
13060
13061 Rd = inst.operands[0].reg;
13062 Rn = inst.operands[2].reg;
13063
13064 reject_bad_reg (Rd);
13065 reject_bad_reg (Rn);
13066
13067 inst.instruction |= Rd << 8;
3a21c15a 13068 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13069 inst.instruction |= Rn << 16;
b99bd4ef 13070
c19d1205 13071 if (inst.operands[3].present)
b99bd4ef 13072 {
3a21c15a
NC
13073 offsetT shift_amount = inst.reloc.exp.X_add_number;
13074
13075 inst.reloc.type = BFD_RELOC_UNUSED;
13076
c19d1205
ZW
13077 constraint (inst.reloc.exp.X_op != O_constant,
13078 _("expression too complex"));
b99bd4ef 13079
3a21c15a 13080 if (shift_amount != 0)
6189168b 13081 {
3a21c15a
NC
13082 constraint (shift_amount > 31,
13083 _("shift expression is too large"));
13084
c19d1205 13085 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13086 inst.instruction |= 0x00200000; /* sh bit. */
13087
13088 inst.instruction |= (shift_amount & 0x1c) << 10;
13089 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13090 }
13091 }
b99bd4ef 13092}
c921be7d 13093
3a21c15a
NC
13094static void
13095do_t_ssat (void)
13096{
13097 do_t_ssat_usat (1);
13098}
b99bd4ef 13099
0dd132b6 13100static void
c19d1205 13101do_t_ssat16 (void)
0dd132b6 13102{
fdfde340
JM
13103 unsigned Rd, Rn;
13104
13105 Rd = inst.operands[0].reg;
13106 Rn = inst.operands[2].reg;
13107
13108 reject_bad_reg (Rd);
13109 reject_bad_reg (Rn);
13110
13111 inst.instruction |= Rd << 8;
c19d1205 13112 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13113 inst.instruction |= Rn << 16;
c19d1205 13114}
0dd132b6 13115
c19d1205
ZW
13116static void
13117do_t_strex (void)
13118{
13119 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13120 || inst.operands[2].postind || inst.operands[2].writeback
13121 || inst.operands[2].immisreg || inst.operands[2].shifted
13122 || inst.operands[2].negative,
01cfc07f 13123 BAD_ADDR_MODE);
0dd132b6 13124
5be8be5d
DG
13125 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13126
c19d1205
ZW
13127 inst.instruction |= inst.operands[0].reg << 8;
13128 inst.instruction |= inst.operands[1].reg << 12;
13129 inst.instruction |= inst.operands[2].reg << 16;
13130 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13131}
13132
b99bd4ef 13133static void
c19d1205 13134do_t_strexd (void)
b99bd4ef 13135{
c19d1205
ZW
13136 if (!inst.operands[2].present)
13137 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13138
c19d1205
ZW
13139 constraint (inst.operands[0].reg == inst.operands[1].reg
13140 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13141 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13142 BAD_OVERLAP);
b99bd4ef 13143
c19d1205
ZW
13144 inst.instruction |= inst.operands[0].reg;
13145 inst.instruction |= inst.operands[1].reg << 12;
13146 inst.instruction |= inst.operands[2].reg << 8;
13147 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13148}
13149
13150static void
c19d1205 13151do_t_sxtah (void)
b99bd4ef 13152{
fdfde340
JM
13153 unsigned Rd, Rn, Rm;
13154
13155 Rd = inst.operands[0].reg;
13156 Rn = inst.operands[1].reg;
13157 Rm = inst.operands[2].reg;
13158
13159 reject_bad_reg (Rd);
13160 reject_bad_reg (Rn);
13161 reject_bad_reg (Rm);
13162
13163 inst.instruction |= Rd << 8;
13164 inst.instruction |= Rn << 16;
13165 inst.instruction |= Rm;
c19d1205
ZW
13166 inst.instruction |= inst.operands[3].imm << 4;
13167}
b99bd4ef 13168
c19d1205
ZW
13169static void
13170do_t_sxth (void)
13171{
fdfde340
JM
13172 unsigned Rd, Rm;
13173
13174 Rd = inst.operands[0].reg;
13175 Rm = inst.operands[1].reg;
13176
13177 reject_bad_reg (Rd);
13178 reject_bad_reg (Rm);
c921be7d
NC
13179
13180 if (inst.instruction <= 0xffff
13181 && inst.size_req != 4
fdfde340 13182 && Rd <= 7 && Rm <= 7
c19d1205 13183 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13184 {
c19d1205 13185 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13186 inst.instruction |= Rd;
13187 inst.instruction |= Rm << 3;
b99bd4ef 13188 }
c19d1205 13189 else if (unified_syntax)
b99bd4ef 13190 {
c19d1205
ZW
13191 if (inst.instruction <= 0xffff)
13192 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13193 inst.instruction |= Rd << 8;
13194 inst.instruction |= Rm;
c19d1205 13195 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13196 }
c19d1205 13197 else
b99bd4ef 13198 {
c19d1205
ZW
13199 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13200 _("Thumb encoding does not support rotation"));
13201 constraint (1, BAD_HIREG);
b99bd4ef 13202 }
c19d1205 13203}
b99bd4ef 13204
c19d1205
ZW
13205static void
13206do_t_swi (void)
13207{
13208 inst.reloc.type = BFD_RELOC_ARM_SWI;
13209}
b99bd4ef 13210
92e90b6e
PB
13211static void
13212do_t_tb (void)
13213{
fdfde340 13214 unsigned Rn, Rm;
92e90b6e
PB
13215 int half;
13216
13217 half = (inst.instruction & 0x10) != 0;
e07e6e58 13218 set_it_insn_type_last ();
dfa9f0d5
PB
13219 constraint (inst.operands[0].immisreg,
13220 _("instruction requires register index"));
fdfde340
JM
13221
13222 Rn = inst.operands[0].reg;
13223 Rm = inst.operands[0].imm;
c921be7d 13224
5c8ed6a4
JW
13225 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13226 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13227 reject_bad_reg (Rm);
13228
92e90b6e
PB
13229 constraint (!half && inst.operands[0].shifted,
13230 _("instruction does not allow shifted index"));
fdfde340 13231 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13232}
13233
74db7efb
NC
13234static void
13235do_t_udf (void)
13236{
13237 if (!inst.operands[0].present)
13238 inst.operands[0].imm = 0;
13239
13240 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13241 {
13242 constraint (inst.size_req == 2,
13243 _("immediate value out of range"));
13244 inst.instruction = THUMB_OP32 (inst.instruction);
13245 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13246 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13247 }
13248 else
13249 {
13250 inst.instruction = THUMB_OP16 (inst.instruction);
13251 inst.instruction |= inst.operands[0].imm;
13252 }
13253
13254 set_it_insn_type (NEUTRAL_IT_INSN);
13255}
13256
13257
c19d1205
ZW
13258static void
13259do_t_usat (void)
13260{
3a21c15a 13261 do_t_ssat_usat (0);
b99bd4ef
NC
13262}
13263
13264static void
c19d1205 13265do_t_usat16 (void)
b99bd4ef 13266{
fdfde340
JM
13267 unsigned Rd, Rn;
13268
13269 Rd = inst.operands[0].reg;
13270 Rn = inst.operands[2].reg;
13271
13272 reject_bad_reg (Rd);
13273 reject_bad_reg (Rn);
13274
13275 inst.instruction |= Rd << 8;
c19d1205 13276 inst.instruction |= inst.operands[1].imm;
fdfde340 13277 inst.instruction |= Rn << 16;
b99bd4ef 13278}
c19d1205 13279
5287ad62 13280/* Neon instruction encoder helpers. */
5f4273c7 13281
5287ad62 13282/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13283
5287ad62
JB
13284/* An "invalid" code for the following tables. */
13285#define N_INV -1u
13286
13287struct neon_tab_entry
b99bd4ef 13288{
5287ad62
JB
13289 unsigned integer;
13290 unsigned float_or_poly;
13291 unsigned scalar_or_imm;
13292};
5f4273c7 13293
5287ad62
JB
13294/* Map overloaded Neon opcodes to their respective encodings. */
13295#define NEON_ENC_TAB \
13296 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13297 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13298 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13299 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13300 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13301 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13302 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13303 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13304 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13305 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13306 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13307 /* Register variants of the following two instructions are encoded as
e07e6e58 13308 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13309 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13310 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13311 X(vfma, N_INV, 0x0000c10, N_INV), \
13312 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13313 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13314 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13315 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13316 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13317 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13318 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13319 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13320 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13321 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13322 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13323 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13324 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13325 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13326 X(vshl, 0x0000400, N_INV, 0x0800510), \
13327 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13328 X(vand, 0x0000110, N_INV, 0x0800030), \
13329 X(vbic, 0x0100110, N_INV, 0x0800030), \
13330 X(veor, 0x1000110, N_INV, N_INV), \
13331 X(vorn, 0x0300110, N_INV, 0x0800010), \
13332 X(vorr, 0x0200110, N_INV, 0x0800010), \
13333 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13334 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13335 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13336 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13337 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13338 X(vst1, 0x0000000, 0x0800000, N_INV), \
13339 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13340 X(vst2, 0x0000100, 0x0800100, N_INV), \
13341 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13342 X(vst3, 0x0000200, 0x0800200, N_INV), \
13343 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13344 X(vst4, 0x0000300, 0x0800300, N_INV), \
13345 X(vmovn, 0x1b20200, N_INV, N_INV), \
13346 X(vtrn, 0x1b20080, N_INV, N_INV), \
13347 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13348 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13349 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13350 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13351 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13352 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13353 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13354 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13355 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13356 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13357 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13358 X(vseleq, 0xe000a00, N_INV, N_INV), \
13359 X(vselvs, 0xe100a00, N_INV, N_INV), \
13360 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13361 X(vselgt, 0xe300a00, N_INV, N_INV), \
13362 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13363 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13364 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13365 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13366 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13367 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13368 X(sha3op, 0x2000c00, N_INV, N_INV), \
13369 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13370 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13371
13372enum neon_opc
13373{
13374#define X(OPC,I,F,S) N_MNEM_##OPC
13375NEON_ENC_TAB
13376#undef X
13377};
b99bd4ef 13378
5287ad62
JB
13379static const struct neon_tab_entry neon_enc_tab[] =
13380{
13381#define X(OPC,I,F,S) { (I), (F), (S) }
13382NEON_ENC_TAB
13383#undef X
13384};
b99bd4ef 13385
88714cb8
DG
13386/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13387#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13388#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13389#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13390#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13391#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13392#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13393#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13394#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13395#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13396#define NEON_ENC_SINGLE_(X) \
037e8744 13397 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13398#define NEON_ENC_DOUBLE_(X) \
037e8744 13399 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13400#define NEON_ENC_FPV8_(X) \
13401 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13402
88714cb8
DG
13403#define NEON_ENCODE(type, inst) \
13404 do \
13405 { \
13406 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13407 inst.is_neon = 1; \
13408 } \
13409 while (0)
13410
13411#define check_neon_suffixes \
13412 do \
13413 { \
13414 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13415 { \
13416 as_bad (_("invalid neon suffix for non neon instruction")); \
13417 return; \
13418 } \
13419 } \
13420 while (0)
13421
037e8744
JB
13422/* Define shapes for instruction operands. The following mnemonic characters
13423 are used in this table:
5287ad62 13424
037e8744 13425 F - VFP S<n> register
5287ad62
JB
13426 D - Neon D<n> register
13427 Q - Neon Q<n> register
13428 I - Immediate
13429 S - Scalar
13430 R - ARM register
13431 L - D<n> register list
5f4273c7 13432
037e8744
JB
13433 This table is used to generate various data:
13434 - enumerations of the form NS_DDR to be used as arguments to
13435 neon_select_shape.
13436 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13437 - a table used to drive neon_select_shape. */
b99bd4ef 13438
037e8744
JB
13439#define NEON_SHAPE_DEF \
13440 X(3, (D, D, D), DOUBLE), \
13441 X(3, (Q, Q, Q), QUAD), \
13442 X(3, (D, D, I), DOUBLE), \
13443 X(3, (Q, Q, I), QUAD), \
13444 X(3, (D, D, S), DOUBLE), \
13445 X(3, (Q, Q, S), QUAD), \
13446 X(2, (D, D), DOUBLE), \
13447 X(2, (Q, Q), QUAD), \
13448 X(2, (D, S), DOUBLE), \
13449 X(2, (Q, S), QUAD), \
13450 X(2, (D, R), DOUBLE), \
13451 X(2, (Q, R), QUAD), \
13452 X(2, (D, I), DOUBLE), \
13453 X(2, (Q, I), QUAD), \
13454 X(3, (D, L, D), DOUBLE), \
13455 X(2, (D, Q), MIXED), \
13456 X(2, (Q, D), MIXED), \
13457 X(3, (D, Q, I), MIXED), \
13458 X(3, (Q, D, I), MIXED), \
13459 X(3, (Q, D, D), MIXED), \
13460 X(3, (D, Q, Q), MIXED), \
13461 X(3, (Q, Q, D), MIXED), \
13462 X(3, (Q, D, S), MIXED), \
13463 X(3, (D, Q, S), MIXED), \
13464 X(4, (D, D, D, I), DOUBLE), \
13465 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13466 X(4, (D, D, S, I), DOUBLE), \
13467 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13468 X(2, (F, F), SINGLE), \
13469 X(3, (F, F, F), SINGLE), \
13470 X(2, (F, I), SINGLE), \
13471 X(2, (F, D), MIXED), \
13472 X(2, (D, F), MIXED), \
13473 X(3, (F, F, I), MIXED), \
13474 X(4, (R, R, F, F), SINGLE), \
13475 X(4, (F, F, R, R), SINGLE), \
13476 X(3, (D, R, R), DOUBLE), \
13477 X(3, (R, R, D), DOUBLE), \
13478 X(2, (S, R), SINGLE), \
13479 X(2, (R, S), SINGLE), \
13480 X(2, (F, R), SINGLE), \
d54af2d0
RL
13481 X(2, (R, F), SINGLE), \
13482/* Half float shape supported so far. */\
13483 X (2, (H, D), MIXED), \
13484 X (2, (D, H), MIXED), \
13485 X (2, (H, F), MIXED), \
13486 X (2, (F, H), MIXED), \
13487 X (2, (H, H), HALF), \
13488 X (2, (H, R), HALF), \
13489 X (2, (R, H), HALF), \
13490 X (2, (H, I), HALF), \
13491 X (3, (H, H, H), HALF), \
13492 X (3, (H, F, I), MIXED), \
dec41383
JW
13493 X (3, (F, H, I), MIXED), \
13494 X (3, (D, H, H), MIXED), \
13495 X (3, (D, H, S), MIXED)
037e8744
JB
13496
13497#define S2(A,B) NS_##A##B
13498#define S3(A,B,C) NS_##A##B##C
13499#define S4(A,B,C,D) NS_##A##B##C##D
13500
13501#define X(N, L, C) S##N L
13502
5287ad62
JB
13503enum neon_shape
13504{
037e8744
JB
13505 NEON_SHAPE_DEF,
13506 NS_NULL
5287ad62 13507};
b99bd4ef 13508
037e8744
JB
13509#undef X
13510#undef S2
13511#undef S3
13512#undef S4
13513
13514enum neon_shape_class
13515{
d54af2d0 13516 SC_HALF,
037e8744
JB
13517 SC_SINGLE,
13518 SC_DOUBLE,
13519 SC_QUAD,
13520 SC_MIXED
13521};
13522
13523#define X(N, L, C) SC_##C
13524
13525static enum neon_shape_class neon_shape_class[] =
13526{
13527 NEON_SHAPE_DEF
13528};
13529
13530#undef X
13531
13532enum neon_shape_el
13533{
d54af2d0 13534 SE_H,
037e8744
JB
13535 SE_F,
13536 SE_D,
13537 SE_Q,
13538 SE_I,
13539 SE_S,
13540 SE_R,
13541 SE_L
13542};
13543
13544/* Register widths of above. */
13545static unsigned neon_shape_el_size[] =
13546{
d54af2d0 13547 16,
037e8744
JB
13548 32,
13549 64,
13550 128,
13551 0,
13552 32,
13553 32,
13554 0
13555};
13556
13557struct neon_shape_info
13558{
13559 unsigned els;
13560 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13561};
13562
13563#define S2(A,B) { SE_##A, SE_##B }
13564#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13565#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13566
13567#define X(N, L, C) { N, S##N L }
13568
13569static struct neon_shape_info neon_shape_tab[] =
13570{
13571 NEON_SHAPE_DEF
13572};
13573
13574#undef X
13575#undef S2
13576#undef S3
13577#undef S4
13578
5287ad62
JB
13579/* Bit masks used in type checking given instructions.
13580 'N_EQK' means the type must be the same as (or based on in some way) the key
13581 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13582 set, various other bits can be set as well in order to modify the meaning of
13583 the type constraint. */
13584
13585enum neon_type_mask
13586{
8e79c3df
CM
13587 N_S8 = 0x0000001,
13588 N_S16 = 0x0000002,
13589 N_S32 = 0x0000004,
13590 N_S64 = 0x0000008,
13591 N_U8 = 0x0000010,
13592 N_U16 = 0x0000020,
13593 N_U32 = 0x0000040,
13594 N_U64 = 0x0000080,
13595 N_I8 = 0x0000100,
13596 N_I16 = 0x0000200,
13597 N_I32 = 0x0000400,
13598 N_I64 = 0x0000800,
13599 N_8 = 0x0001000,
13600 N_16 = 0x0002000,
13601 N_32 = 0x0004000,
13602 N_64 = 0x0008000,
13603 N_P8 = 0x0010000,
13604 N_P16 = 0x0020000,
13605 N_F16 = 0x0040000,
13606 N_F32 = 0x0080000,
13607 N_F64 = 0x0100000,
4f51b4bd 13608 N_P64 = 0x0200000,
c921be7d
NC
13609 N_KEY = 0x1000000, /* Key element (main type specifier). */
13610 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13611 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13612 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13613 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13614 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13615 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13616 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13617 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13618 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13619 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13620 N_UTYP = 0,
4f51b4bd 13621 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13622};
13623
dcbf9037
JB
13624#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13625
5287ad62
JB
13626#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13627#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13628#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13629#define N_S_32 (N_S8 | N_S16 | N_S32)
13630#define N_F_16_32 (N_F16 | N_F32)
13631#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13632#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13633#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13634#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13635
13636/* Pass this as the first type argument to neon_check_type to ignore types
13637 altogether. */
13638#define N_IGNORE_TYPE (N_KEY | N_EQK)
13639
037e8744
JB
13640/* Select a "shape" for the current instruction (describing register types or
13641 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13642 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13643 function of operand parsing, so this function doesn't need to be called.
13644 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13645
13646static enum neon_shape
037e8744 13647neon_select_shape (enum neon_shape shape, ...)
5287ad62 13648{
037e8744
JB
13649 va_list ap;
13650 enum neon_shape first_shape = shape;
5287ad62
JB
13651
13652 /* Fix missing optional operands. FIXME: we don't know at this point how
13653 many arguments we should have, so this makes the assumption that we have
13654 > 1. This is true of all current Neon opcodes, I think, but may not be
13655 true in the future. */
13656 if (!inst.operands[1].present)
13657 inst.operands[1] = inst.operands[0];
13658
037e8744 13659 va_start (ap, shape);
5f4273c7 13660
21d799b5 13661 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13662 {
13663 unsigned j;
13664 int matches = 1;
13665
13666 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13667 {
13668 if (!inst.operands[j].present)
13669 {
13670 matches = 0;
13671 break;
13672 }
13673
13674 switch (neon_shape_tab[shape].el[j])
13675 {
d54af2d0
RL
13676 /* If a .f16, .16, .u16, .s16 type specifier is given over
13677 a VFP single precision register operand, it's essentially
13678 means only half of the register is used.
13679
13680 If the type specifier is given after the mnemonics, the
13681 information is stored in inst.vectype. If the type specifier
13682 is given after register operand, the information is stored
13683 in inst.operands[].vectype.
13684
13685 When there is only one type specifier, and all the register
13686 operands are the same type of hardware register, the type
13687 specifier applies to all register operands.
13688
13689 If no type specifier is given, the shape is inferred from
13690 operand information.
13691
13692 for example:
13693 vadd.f16 s0, s1, s2: NS_HHH
13694 vabs.f16 s0, s1: NS_HH
13695 vmov.f16 s0, r1: NS_HR
13696 vmov.f16 r0, s1: NS_RH
13697 vcvt.f16 r0, s1: NS_RH
13698 vcvt.f16.s32 s2, s2, #29: NS_HFI
13699 vcvt.f16.s32 s2, s2: NS_HF
13700 */
13701 case SE_H:
13702 if (!(inst.operands[j].isreg
13703 && inst.operands[j].isvec
13704 && inst.operands[j].issingle
13705 && !inst.operands[j].isquad
13706 && ((inst.vectype.elems == 1
13707 && inst.vectype.el[0].size == 16)
13708 || (inst.vectype.elems > 1
13709 && inst.vectype.el[j].size == 16)
13710 || (inst.vectype.elems == 0
13711 && inst.operands[j].vectype.type != NT_invtype
13712 && inst.operands[j].vectype.size == 16))))
13713 matches = 0;
13714 break;
13715
477330fc
RM
13716 case SE_F:
13717 if (!(inst.operands[j].isreg
13718 && inst.operands[j].isvec
13719 && inst.operands[j].issingle
d54af2d0
RL
13720 && !inst.operands[j].isquad
13721 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13722 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13723 || (inst.vectype.elems == 0
13724 && (inst.operands[j].vectype.size == 32
13725 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13726 matches = 0;
13727 break;
13728
13729 case SE_D:
13730 if (!(inst.operands[j].isreg
13731 && inst.operands[j].isvec
13732 && !inst.operands[j].isquad
13733 && !inst.operands[j].issingle))
13734 matches = 0;
13735 break;
13736
13737 case SE_R:
13738 if (!(inst.operands[j].isreg
13739 && !inst.operands[j].isvec))
13740 matches = 0;
13741 break;
13742
13743 case SE_Q:
13744 if (!(inst.operands[j].isreg
13745 && inst.operands[j].isvec
13746 && inst.operands[j].isquad
13747 && !inst.operands[j].issingle))
13748 matches = 0;
13749 break;
13750
13751 case SE_I:
13752 if (!(!inst.operands[j].isreg
13753 && !inst.operands[j].isscalar))
13754 matches = 0;
13755 break;
13756
13757 case SE_S:
13758 if (!(!inst.operands[j].isreg
13759 && inst.operands[j].isscalar))
13760 matches = 0;
13761 break;
13762
13763 case SE_L:
13764 break;
13765 }
3fde54a2
JZ
13766 if (!matches)
13767 break;
477330fc 13768 }
ad6cec43
MGD
13769 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13770 /* We've matched all the entries in the shape table, and we don't
13771 have any left over operands which have not been matched. */
477330fc 13772 break;
037e8744 13773 }
5f4273c7 13774
037e8744 13775 va_end (ap);
5287ad62 13776
037e8744
JB
13777 if (shape == NS_NULL && first_shape != NS_NULL)
13778 first_error (_("invalid instruction shape"));
5287ad62 13779
037e8744
JB
13780 return shape;
13781}
5287ad62 13782
037e8744
JB
13783/* True if SHAPE is predominantly a quadword operation (most of the time, this
13784 means the Q bit should be set). */
13785
13786static int
13787neon_quad (enum neon_shape shape)
13788{
13789 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13790}
037e8744 13791
5287ad62
JB
13792static void
13793neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13794 unsigned *g_size)
5287ad62
JB
13795{
13796 /* Allow modification to be made to types which are constrained to be
13797 based on the key element, based on bits set alongside N_EQK. */
13798 if ((typebits & N_EQK) != 0)
13799 {
13800 if ((typebits & N_HLF) != 0)
13801 *g_size /= 2;
13802 else if ((typebits & N_DBL) != 0)
13803 *g_size *= 2;
13804 if ((typebits & N_SGN) != 0)
13805 *g_type = NT_signed;
13806 else if ((typebits & N_UNS) != 0)
477330fc 13807 *g_type = NT_unsigned;
5287ad62 13808 else if ((typebits & N_INT) != 0)
477330fc 13809 *g_type = NT_integer;
5287ad62 13810 else if ((typebits & N_FLT) != 0)
477330fc 13811 *g_type = NT_float;
dcbf9037 13812 else if ((typebits & N_SIZ) != 0)
477330fc 13813 *g_type = NT_untyped;
5287ad62
JB
13814 }
13815}
5f4273c7 13816
5287ad62
JB
13817/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13818 operand type, i.e. the single type specified in a Neon instruction when it
13819 is the only one given. */
13820
13821static struct neon_type_el
13822neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13823{
13824 struct neon_type_el dest = *key;
5f4273c7 13825
9c2799c2 13826 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13827
5287ad62
JB
13828 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13829
13830 return dest;
13831}
13832
13833/* Convert Neon type and size into compact bitmask representation. */
13834
13835static enum neon_type_mask
13836type_chk_of_el_type (enum neon_el_type type, unsigned size)
13837{
13838 switch (type)
13839 {
13840 case NT_untyped:
13841 switch (size)
477330fc
RM
13842 {
13843 case 8: return N_8;
13844 case 16: return N_16;
13845 case 32: return N_32;
13846 case 64: return N_64;
13847 default: ;
13848 }
5287ad62
JB
13849 break;
13850
13851 case NT_integer:
13852 switch (size)
477330fc
RM
13853 {
13854 case 8: return N_I8;
13855 case 16: return N_I16;
13856 case 32: return N_I32;
13857 case 64: return N_I64;
13858 default: ;
13859 }
5287ad62
JB
13860 break;
13861
13862 case NT_float:
037e8744 13863 switch (size)
477330fc 13864 {
8e79c3df 13865 case 16: return N_F16;
477330fc
RM
13866 case 32: return N_F32;
13867 case 64: return N_F64;
13868 default: ;
13869 }
5287ad62
JB
13870 break;
13871
13872 case NT_poly:
13873 switch (size)
477330fc
RM
13874 {
13875 case 8: return N_P8;
13876 case 16: return N_P16;
4f51b4bd 13877 case 64: return N_P64;
477330fc
RM
13878 default: ;
13879 }
5287ad62
JB
13880 break;
13881
13882 case NT_signed:
13883 switch (size)
477330fc
RM
13884 {
13885 case 8: return N_S8;
13886 case 16: return N_S16;
13887 case 32: return N_S32;
13888 case 64: return N_S64;
13889 default: ;
13890 }
5287ad62
JB
13891 break;
13892
13893 case NT_unsigned:
13894 switch (size)
477330fc
RM
13895 {
13896 case 8: return N_U8;
13897 case 16: return N_U16;
13898 case 32: return N_U32;
13899 case 64: return N_U64;
13900 default: ;
13901 }
5287ad62
JB
13902 break;
13903
13904 default: ;
13905 }
5f4273c7 13906
5287ad62
JB
13907 return N_UTYP;
13908}
13909
13910/* Convert compact Neon bitmask type representation to a type and size. Only
13911 handles the case where a single bit is set in the mask. */
13912
dcbf9037 13913static int
5287ad62 13914el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13915 enum neon_type_mask mask)
5287ad62 13916{
dcbf9037
JB
13917 if ((mask & N_EQK) != 0)
13918 return FAIL;
13919
5287ad62
JB
13920 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13921 *size = 8;
c70a8987 13922 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13923 *size = 16;
dcbf9037 13924 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13925 *size = 32;
4f51b4bd 13926 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13927 *size = 64;
dcbf9037
JB
13928 else
13929 return FAIL;
13930
5287ad62
JB
13931 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13932 *type = NT_signed;
dcbf9037 13933 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13934 *type = NT_unsigned;
dcbf9037 13935 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13936 *type = NT_integer;
dcbf9037 13937 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13938 *type = NT_untyped;
4f51b4bd 13939 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13940 *type = NT_poly;
d54af2d0 13941 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13942 *type = NT_float;
dcbf9037
JB
13943 else
13944 return FAIL;
5f4273c7 13945
dcbf9037 13946 return SUCCESS;
5287ad62
JB
13947}
13948
13949/* Modify a bitmask of allowed types. This is only needed for type
13950 relaxation. */
13951
13952static unsigned
13953modify_types_allowed (unsigned allowed, unsigned mods)
13954{
13955 unsigned size;
13956 enum neon_el_type type;
13957 unsigned destmask;
13958 int i;
5f4273c7 13959
5287ad62 13960 destmask = 0;
5f4273c7 13961
5287ad62
JB
13962 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13963 {
21d799b5 13964 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13965 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13966 {
13967 neon_modify_type_size (mods, &type, &size);
13968 destmask |= type_chk_of_el_type (type, size);
13969 }
5287ad62 13970 }
5f4273c7 13971
5287ad62
JB
13972 return destmask;
13973}
13974
13975/* Check type and return type classification.
13976 The manual states (paraphrase): If one datatype is given, it indicates the
13977 type given in:
13978 - the second operand, if there is one
13979 - the operand, if there is no second operand
13980 - the result, if there are no operands.
13981 This isn't quite good enough though, so we use a concept of a "key" datatype
13982 which is set on a per-instruction basis, which is the one which matters when
13983 only one data type is written.
13984 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13985 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13986
13987static struct neon_type_el
13988neon_check_type (unsigned els, enum neon_shape ns, ...)
13989{
13990 va_list ap;
13991 unsigned i, pass, key_el = 0;
13992 unsigned types[NEON_MAX_TYPE_ELS];
13993 enum neon_el_type k_type = NT_invtype;
13994 unsigned k_size = -1u;
13995 struct neon_type_el badtype = {NT_invtype, -1};
13996 unsigned key_allowed = 0;
13997
13998 /* Optional registers in Neon instructions are always (not) in operand 1.
13999 Fill in the missing operand here, if it was omitted. */
14000 if (els > 1 && !inst.operands[1].present)
14001 inst.operands[1] = inst.operands[0];
14002
14003 /* Suck up all the varargs. */
14004 va_start (ap, ns);
14005 for (i = 0; i < els; i++)
14006 {
14007 unsigned thisarg = va_arg (ap, unsigned);
14008 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
14009 {
14010 va_end (ap);
14011 return badtype;
14012 }
5287ad62
JB
14013 types[i] = thisarg;
14014 if ((thisarg & N_KEY) != 0)
477330fc 14015 key_el = i;
5287ad62
JB
14016 }
14017 va_end (ap);
14018
dcbf9037
JB
14019 if (inst.vectype.elems > 0)
14020 for (i = 0; i < els; i++)
14021 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
14022 {
14023 first_error (_("types specified in both the mnemonic and operands"));
14024 return badtype;
14025 }
dcbf9037 14026
5287ad62
JB
14027 /* Duplicate inst.vectype elements here as necessary.
14028 FIXME: No idea if this is exactly the same as the ARM assembler,
14029 particularly when an insn takes one register and one non-register
14030 operand. */
14031 if (inst.vectype.elems == 1 && els > 1)
14032 {
14033 unsigned j;
14034 inst.vectype.elems = els;
14035 inst.vectype.el[key_el] = inst.vectype.el[0];
14036 for (j = 0; j < els; j++)
477330fc
RM
14037 if (j != key_el)
14038 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14039 types[j]);
dcbf9037
JB
14040 }
14041 else if (inst.vectype.elems == 0 && els > 0)
14042 {
14043 unsigned j;
14044 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14045 after each operand. We allow some flexibility here; as long as the
14046 "key" operand has a type, we can infer the others. */
dcbf9037 14047 for (j = 0; j < els; j++)
477330fc
RM
14048 if (inst.operands[j].vectype.type != NT_invtype)
14049 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14050
14051 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14052 {
14053 for (j = 0; j < els; j++)
14054 if (inst.operands[j].vectype.type == NT_invtype)
14055 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14056 types[j]);
14057 }
dcbf9037 14058 else
477330fc
RM
14059 {
14060 first_error (_("operand types can't be inferred"));
14061 return badtype;
14062 }
5287ad62
JB
14063 }
14064 else if (inst.vectype.elems != els)
14065 {
dcbf9037 14066 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14067 return badtype;
14068 }
14069
14070 for (pass = 0; pass < 2; pass++)
14071 {
14072 for (i = 0; i < els; i++)
477330fc
RM
14073 {
14074 unsigned thisarg = types[i];
14075 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14076 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14077 enum neon_el_type g_type = inst.vectype.el[i].type;
14078 unsigned g_size = inst.vectype.el[i].size;
14079
14080 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14081 integer types if sign-specific variants are unavailable. */
477330fc 14082 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14083 && (types_allowed & N_SU_ALL) == 0)
14084 g_type = NT_integer;
14085
477330fc 14086 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14087 them. Some instructions only care about signs for some element
14088 sizes, so handle that properly. */
477330fc 14089 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14090 && ((g_size == 8 && (types_allowed & N_8) != 0)
14091 || (g_size == 16 && (types_allowed & N_16) != 0)
14092 || (g_size == 32 && (types_allowed & N_32) != 0)
14093 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14094 g_type = NT_untyped;
14095
477330fc
RM
14096 if (pass == 0)
14097 {
14098 if ((thisarg & N_KEY) != 0)
14099 {
14100 k_type = g_type;
14101 k_size = g_size;
14102 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14103
14104 /* Check architecture constraint on FP16 extension. */
14105 if (k_size == 16
14106 && k_type == NT_float
14107 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14108 {
14109 inst.error = _(BAD_FP16);
14110 return badtype;
14111 }
477330fc
RM
14112 }
14113 }
14114 else
14115 {
14116 if ((thisarg & N_VFP) != 0)
14117 {
14118 enum neon_shape_el regshape;
14119 unsigned regwidth, match;
99b253c5
NC
14120
14121 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14122 if (ns == NS_NULL)
14123 {
14124 first_error (_("invalid instruction shape"));
14125 return badtype;
14126 }
477330fc
RM
14127 regshape = neon_shape_tab[ns].el[i];
14128 regwidth = neon_shape_el_size[regshape];
14129
14130 /* In VFP mode, operands must match register widths. If we
14131 have a key operand, use its width, else use the width of
14132 the current operand. */
14133 if (k_size != -1u)
14134 match = k_size;
14135 else
14136 match = g_size;
14137
9db2f6b4
RL
14138 /* FP16 will use a single precision register. */
14139 if (regwidth == 32 && match == 16)
14140 {
14141 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14142 match = regwidth;
14143 else
14144 {
14145 inst.error = _(BAD_FP16);
14146 return badtype;
14147 }
14148 }
14149
477330fc
RM
14150 if (regwidth != match)
14151 {
14152 first_error (_("operand size must match register width"));
14153 return badtype;
14154 }
14155 }
14156
14157 if ((thisarg & N_EQK) == 0)
14158 {
14159 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14160
14161 if ((given_type & types_allowed) == 0)
14162 {
14163 first_error (_("bad type in Neon instruction"));
14164 return badtype;
14165 }
14166 }
14167 else
14168 {
14169 enum neon_el_type mod_k_type = k_type;
14170 unsigned mod_k_size = k_size;
14171 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14172 if (g_type != mod_k_type || g_size != mod_k_size)
14173 {
14174 first_error (_("inconsistent types in Neon instruction"));
14175 return badtype;
14176 }
14177 }
14178 }
14179 }
5287ad62
JB
14180 }
14181
14182 return inst.vectype.el[key_el];
14183}
14184
037e8744 14185/* Neon-style VFP instruction forwarding. */
5287ad62 14186
037e8744
JB
14187/* Thumb VFP instructions have 0xE in the condition field. */
14188
14189static void
14190do_vfp_cond_or_thumb (void)
5287ad62 14191{
88714cb8
DG
14192 inst.is_neon = 1;
14193
5287ad62 14194 if (thumb_mode)
037e8744 14195 inst.instruction |= 0xe0000000;
5287ad62 14196 else
037e8744 14197 inst.instruction |= inst.cond << 28;
5287ad62
JB
14198}
14199
037e8744
JB
14200/* Look up and encode a simple mnemonic, for use as a helper function for the
14201 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14202 etc. It is assumed that operand parsing has already been done, and that the
14203 operands are in the form expected by the given opcode (this isn't necessarily
14204 the same as the form in which they were parsed, hence some massaging must
14205 take place before this function is called).
14206 Checks current arch version against that in the looked-up opcode. */
5287ad62 14207
037e8744
JB
14208static void
14209do_vfp_nsyn_opcode (const char *opname)
5287ad62 14210{
037e8744 14211 const struct asm_opcode *opcode;
5f4273c7 14212
21d799b5 14213 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14214
037e8744
JB
14215 if (!opcode)
14216 abort ();
5287ad62 14217
037e8744 14218 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14219 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14220 _(BAD_FPU));
5287ad62 14221
88714cb8
DG
14222 inst.is_neon = 1;
14223
037e8744
JB
14224 if (thumb_mode)
14225 {
14226 inst.instruction = opcode->tvalue;
14227 opcode->tencode ();
14228 }
14229 else
14230 {
14231 inst.instruction = (inst.cond << 28) | opcode->avalue;
14232 opcode->aencode ();
14233 }
14234}
5287ad62
JB
14235
14236static void
037e8744 14237do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14238{
037e8744
JB
14239 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14240
9db2f6b4 14241 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14242 {
14243 if (is_add)
477330fc 14244 do_vfp_nsyn_opcode ("fadds");
037e8744 14245 else
477330fc 14246 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14247
14248 /* ARMv8.2 fp16 instruction. */
14249 if (rs == NS_HHH)
14250 do_scalar_fp16_v82_encode ();
037e8744
JB
14251 }
14252 else
14253 {
14254 if (is_add)
477330fc 14255 do_vfp_nsyn_opcode ("faddd");
037e8744 14256 else
477330fc 14257 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14258 }
14259}
14260
14261/* Check operand types to see if this is a VFP instruction, and if so call
14262 PFN (). */
14263
14264static int
14265try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14266{
14267 enum neon_shape rs;
14268 struct neon_type_el et;
14269
14270 switch (args)
14271 {
14272 case 2:
9db2f6b4
RL
14273 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14274 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14275 break;
5f4273c7 14276
037e8744 14277 case 3:
9db2f6b4
RL
14278 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14279 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14280 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14281 break;
14282
14283 default:
14284 abort ();
14285 }
14286
14287 if (et.type != NT_invtype)
14288 {
14289 pfn (rs);
14290 return SUCCESS;
14291 }
037e8744 14292
99b253c5 14293 inst.error = NULL;
037e8744
JB
14294 return FAIL;
14295}
14296
14297static void
14298do_vfp_nsyn_mla_mls (enum neon_shape rs)
14299{
14300 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14301
9db2f6b4 14302 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14303 {
14304 if (is_mla)
477330fc 14305 do_vfp_nsyn_opcode ("fmacs");
037e8744 14306 else
477330fc 14307 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14308
14309 /* ARMv8.2 fp16 instruction. */
14310 if (rs == NS_HHH)
14311 do_scalar_fp16_v82_encode ();
037e8744
JB
14312 }
14313 else
14314 {
14315 if (is_mla)
477330fc 14316 do_vfp_nsyn_opcode ("fmacd");
037e8744 14317 else
477330fc 14318 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14319 }
14320}
14321
62f3b8c8
PB
14322static void
14323do_vfp_nsyn_fma_fms (enum neon_shape rs)
14324{
14325 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14326
9db2f6b4 14327 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14328 {
14329 if (is_fma)
477330fc 14330 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14331 else
477330fc 14332 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14333
14334 /* ARMv8.2 fp16 instruction. */
14335 if (rs == NS_HHH)
14336 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14337 }
14338 else
14339 {
14340 if (is_fma)
477330fc 14341 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14342 else
477330fc 14343 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14344 }
14345}
14346
037e8744
JB
14347static void
14348do_vfp_nsyn_mul (enum neon_shape rs)
14349{
9db2f6b4
RL
14350 if (rs == NS_FFF || rs == NS_HHH)
14351 {
14352 do_vfp_nsyn_opcode ("fmuls");
14353
14354 /* ARMv8.2 fp16 instruction. */
14355 if (rs == NS_HHH)
14356 do_scalar_fp16_v82_encode ();
14357 }
037e8744
JB
14358 else
14359 do_vfp_nsyn_opcode ("fmuld");
14360}
14361
14362static void
14363do_vfp_nsyn_abs_neg (enum neon_shape rs)
14364{
14365 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14366 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14367
9db2f6b4 14368 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14369 {
14370 if (is_neg)
477330fc 14371 do_vfp_nsyn_opcode ("fnegs");
037e8744 14372 else
477330fc 14373 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14374
14375 /* ARMv8.2 fp16 instruction. */
14376 if (rs == NS_HH)
14377 do_scalar_fp16_v82_encode ();
037e8744
JB
14378 }
14379 else
14380 {
14381 if (is_neg)
477330fc 14382 do_vfp_nsyn_opcode ("fnegd");
037e8744 14383 else
477330fc 14384 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14385 }
14386}
14387
14388/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14389 insns belong to Neon, and are handled elsewhere. */
14390
14391static void
14392do_vfp_nsyn_ldm_stm (int is_dbmode)
14393{
14394 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14395 if (is_ldm)
14396 {
14397 if (is_dbmode)
477330fc 14398 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14399 else
477330fc 14400 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14401 }
14402 else
14403 {
14404 if (is_dbmode)
477330fc 14405 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14406 else
477330fc 14407 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14408 }
14409}
14410
037e8744
JB
14411static void
14412do_vfp_nsyn_sqrt (void)
14413{
9db2f6b4
RL
14414 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14415 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14416
9db2f6b4
RL
14417 if (rs == NS_FF || rs == NS_HH)
14418 {
14419 do_vfp_nsyn_opcode ("fsqrts");
14420
14421 /* ARMv8.2 fp16 instruction. */
14422 if (rs == NS_HH)
14423 do_scalar_fp16_v82_encode ();
14424 }
037e8744
JB
14425 else
14426 do_vfp_nsyn_opcode ("fsqrtd");
14427}
14428
14429static void
14430do_vfp_nsyn_div (void)
14431{
9db2f6b4 14432 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14433 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14434 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14435
9db2f6b4
RL
14436 if (rs == NS_FFF || rs == NS_HHH)
14437 {
14438 do_vfp_nsyn_opcode ("fdivs");
14439
14440 /* ARMv8.2 fp16 instruction. */
14441 if (rs == NS_HHH)
14442 do_scalar_fp16_v82_encode ();
14443 }
037e8744
JB
14444 else
14445 do_vfp_nsyn_opcode ("fdivd");
14446}
14447
14448static void
14449do_vfp_nsyn_nmul (void)
14450{
9db2f6b4 14451 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14452 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14453 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14454
9db2f6b4 14455 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14456 {
88714cb8 14457 NEON_ENCODE (SINGLE, inst);
037e8744 14458 do_vfp_sp_dyadic ();
9db2f6b4
RL
14459
14460 /* ARMv8.2 fp16 instruction. */
14461 if (rs == NS_HHH)
14462 do_scalar_fp16_v82_encode ();
037e8744
JB
14463 }
14464 else
14465 {
88714cb8 14466 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14467 do_vfp_dp_rd_rn_rm ();
14468 }
14469 do_vfp_cond_or_thumb ();
9db2f6b4 14470
037e8744
JB
14471}
14472
14473static void
14474do_vfp_nsyn_cmp (void)
14475{
9db2f6b4 14476 enum neon_shape rs;
037e8744
JB
14477 if (inst.operands[1].isreg)
14478 {
9db2f6b4
RL
14479 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14480 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14481
9db2f6b4 14482 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14483 {
14484 NEON_ENCODE (SINGLE, inst);
14485 do_vfp_sp_monadic ();
14486 }
037e8744 14487 else
477330fc
RM
14488 {
14489 NEON_ENCODE (DOUBLE, inst);
14490 do_vfp_dp_rd_rm ();
14491 }
037e8744
JB
14492 }
14493 else
14494 {
9db2f6b4
RL
14495 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14496 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14497
14498 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14499 {
14500 case N_MNEM_vcmp:
14501 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14502 break;
14503 case N_MNEM_vcmpe:
14504 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14505 break;
14506 default:
14507 abort ();
14508 }
5f4273c7 14509
9db2f6b4 14510 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14511 {
14512 NEON_ENCODE (SINGLE, inst);
14513 do_vfp_sp_compare_z ();
14514 }
037e8744 14515 else
477330fc
RM
14516 {
14517 NEON_ENCODE (DOUBLE, inst);
14518 do_vfp_dp_rd ();
14519 }
037e8744
JB
14520 }
14521 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14522
14523 /* ARMv8.2 fp16 instruction. */
14524 if (rs == NS_HI || rs == NS_HH)
14525 do_scalar_fp16_v82_encode ();
037e8744
JB
14526}
14527
14528static void
14529nsyn_insert_sp (void)
14530{
14531 inst.operands[1] = inst.operands[0];
14532 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14533 inst.operands[0].reg = REG_SP;
037e8744
JB
14534 inst.operands[0].isreg = 1;
14535 inst.operands[0].writeback = 1;
14536 inst.operands[0].present = 1;
14537}
14538
14539static void
14540do_vfp_nsyn_push (void)
14541{
14542 nsyn_insert_sp ();
b126985e
NC
14543
14544 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14545 _("register list must contain at least 1 and at most 16 "
14546 "registers"));
14547
037e8744
JB
14548 if (inst.operands[1].issingle)
14549 do_vfp_nsyn_opcode ("fstmdbs");
14550 else
14551 do_vfp_nsyn_opcode ("fstmdbd");
14552}
14553
14554static void
14555do_vfp_nsyn_pop (void)
14556{
14557 nsyn_insert_sp ();
b126985e
NC
14558
14559 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14560 _("register list must contain at least 1 and at most 16 "
14561 "registers"));
14562
037e8744 14563 if (inst.operands[1].issingle)
22b5b651 14564 do_vfp_nsyn_opcode ("fldmias");
037e8744 14565 else
22b5b651 14566 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14567}
14568
14569/* Fix up Neon data-processing instructions, ORing in the correct bits for
14570 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14571
88714cb8
DG
14572static void
14573neon_dp_fixup (struct arm_it* insn)
037e8744 14574{
88714cb8
DG
14575 unsigned int i = insn->instruction;
14576 insn->is_neon = 1;
14577
037e8744
JB
14578 if (thumb_mode)
14579 {
14580 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14581 if (i & (1 << 24))
477330fc 14582 i |= 1 << 28;
5f4273c7 14583
037e8744 14584 i &= ~(1 << 24);
5f4273c7 14585
037e8744
JB
14586 i |= 0xef000000;
14587 }
14588 else
14589 i |= 0xf2000000;
5f4273c7 14590
88714cb8 14591 insn->instruction = i;
037e8744
JB
14592}
14593
14594/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14595 (0, 1, 2, 3). */
14596
14597static unsigned
14598neon_logbits (unsigned x)
14599{
14600 return ffs (x) - 4;
14601}
14602
14603#define LOW4(R) ((R) & 0xf)
14604#define HI1(R) (((R) >> 4) & 1)
14605
14606/* Encode insns with bit pattern:
14607
14608 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14609 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14610
037e8744
JB
14611 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14612 different meaning for some instruction. */
14613
14614static void
14615neon_three_same (int isquad, int ubit, int size)
14616{
14617 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14618 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14619 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14620 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14621 inst.instruction |= LOW4 (inst.operands[2].reg);
14622 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14623 inst.instruction |= (isquad != 0) << 6;
14624 inst.instruction |= (ubit != 0) << 24;
14625 if (size != -1)
14626 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14627
88714cb8 14628 neon_dp_fixup (&inst);
037e8744
JB
14629}
14630
14631/* Encode instructions of the form:
14632
14633 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14634 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14635
14636 Don't write size if SIZE == -1. */
14637
14638static void
14639neon_two_same (int qbit, int ubit, int size)
14640{
14641 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14642 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14643 inst.instruction |= LOW4 (inst.operands[1].reg);
14644 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14645 inst.instruction |= (qbit != 0) << 6;
14646 inst.instruction |= (ubit != 0) << 24;
14647
14648 if (size != -1)
14649 inst.instruction |= neon_logbits (size) << 18;
14650
88714cb8 14651 neon_dp_fixup (&inst);
5287ad62
JB
14652}
14653
14654/* Neon instruction encoders, in approximate order of appearance. */
14655
14656static void
14657do_neon_dyadic_i_su (void)
14658{
037e8744 14659 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14660 struct neon_type_el et = neon_check_type (3, rs,
14661 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14662 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14663}
14664
14665static void
14666do_neon_dyadic_i64_su (void)
14667{
037e8744 14668 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14669 struct neon_type_el et = neon_check_type (3, rs,
14670 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14671 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14672}
14673
14674static void
14675neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14676 unsigned immbits)
5287ad62
JB
14677{
14678 unsigned size = et.size >> 3;
14679 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14680 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14681 inst.instruction |= LOW4 (inst.operands[1].reg);
14682 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14683 inst.instruction |= (isquad != 0) << 6;
14684 inst.instruction |= immbits << 16;
14685 inst.instruction |= (size >> 3) << 7;
14686 inst.instruction |= (size & 0x7) << 19;
14687 if (write_ubit)
14688 inst.instruction |= (uval != 0) << 24;
14689
88714cb8 14690 neon_dp_fixup (&inst);
5287ad62
JB
14691}
14692
14693static void
14694do_neon_shl_imm (void)
14695{
14696 if (!inst.operands[2].isreg)
14697 {
037e8744 14698 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14699 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14700 int imm = inst.operands[2].imm;
14701
14702 constraint (imm < 0 || (unsigned)imm >= et.size,
14703 _("immediate out of range for shift"));
88714cb8 14704 NEON_ENCODE (IMMED, inst);
cb3b1e65 14705 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14706 }
14707 else
14708 {
037e8744 14709 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14710 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14711 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14712 unsigned int tmp;
14713
14714 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14715 vshl.xx Dd, Dm, Dn
14716 whereas other 3-register operations encoded by neon_three_same have
14717 syntax like:
14718 vadd.xx Dd, Dn, Dm
14719 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14720 here. */
627907b7
JB
14721 tmp = inst.operands[2].reg;
14722 inst.operands[2].reg = inst.operands[1].reg;
14723 inst.operands[1].reg = tmp;
88714cb8 14724 NEON_ENCODE (INTEGER, inst);
037e8744 14725 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14726 }
14727}
14728
14729static void
14730do_neon_qshl_imm (void)
14731{
14732 if (!inst.operands[2].isreg)
14733 {
037e8744 14734 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14735 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14736 int imm = inst.operands[2].imm;
627907b7 14737
cb3b1e65
JB
14738 constraint (imm < 0 || (unsigned)imm >= et.size,
14739 _("immediate out of range for shift"));
88714cb8 14740 NEON_ENCODE (IMMED, inst);
cb3b1e65 14741 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14742 }
14743 else
14744 {
037e8744 14745 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14746 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14747 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14748 unsigned int tmp;
14749
14750 /* See note in do_neon_shl_imm. */
14751 tmp = inst.operands[2].reg;
14752 inst.operands[2].reg = inst.operands[1].reg;
14753 inst.operands[1].reg = tmp;
88714cb8 14754 NEON_ENCODE (INTEGER, inst);
037e8744 14755 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14756 }
14757}
14758
627907b7
JB
14759static void
14760do_neon_rshl (void)
14761{
14762 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14763 struct neon_type_el et = neon_check_type (3, rs,
14764 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14765 unsigned int tmp;
14766
14767 tmp = inst.operands[2].reg;
14768 inst.operands[2].reg = inst.operands[1].reg;
14769 inst.operands[1].reg = tmp;
14770 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14771}
14772
5287ad62
JB
14773static int
14774neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14775{
036dc3f7
PB
14776 /* Handle .I8 pseudo-instructions. */
14777 if (size == 8)
5287ad62 14778 {
5287ad62 14779 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14780 FIXME is this the intended semantics? There doesn't seem much point in
14781 accepting .I8 if so. */
5287ad62
JB
14782 immediate |= immediate << 8;
14783 size = 16;
036dc3f7
PB
14784 }
14785
14786 if (size >= 32)
14787 {
14788 if (immediate == (immediate & 0x000000ff))
14789 {
14790 *immbits = immediate;
14791 return 0x1;
14792 }
14793 else if (immediate == (immediate & 0x0000ff00))
14794 {
14795 *immbits = immediate >> 8;
14796 return 0x3;
14797 }
14798 else if (immediate == (immediate & 0x00ff0000))
14799 {
14800 *immbits = immediate >> 16;
14801 return 0x5;
14802 }
14803 else if (immediate == (immediate & 0xff000000))
14804 {
14805 *immbits = immediate >> 24;
14806 return 0x7;
14807 }
14808 if ((immediate & 0xffff) != (immediate >> 16))
14809 goto bad_immediate;
14810 immediate &= 0xffff;
5287ad62
JB
14811 }
14812
14813 if (immediate == (immediate & 0x000000ff))
14814 {
14815 *immbits = immediate;
036dc3f7 14816 return 0x9;
5287ad62
JB
14817 }
14818 else if (immediate == (immediate & 0x0000ff00))
14819 {
14820 *immbits = immediate >> 8;
036dc3f7 14821 return 0xb;
5287ad62
JB
14822 }
14823
14824 bad_immediate:
dcbf9037 14825 first_error (_("immediate value out of range"));
5287ad62
JB
14826 return FAIL;
14827}
14828
5287ad62
JB
14829static void
14830do_neon_logic (void)
14831{
14832 if (inst.operands[2].present && inst.operands[2].isreg)
14833 {
037e8744 14834 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14835 neon_check_type (3, rs, N_IGNORE_TYPE);
14836 /* U bit and size field were set as part of the bitmask. */
88714cb8 14837 NEON_ENCODE (INTEGER, inst);
037e8744 14838 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14839 }
14840 else
14841 {
4316f0d2
DG
14842 const int three_ops_form = (inst.operands[2].present
14843 && !inst.operands[2].isreg);
14844 const int immoperand = (three_ops_form ? 2 : 1);
14845 enum neon_shape rs = (three_ops_form
14846 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14847 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14848 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14849 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14850 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14851 unsigned immbits;
14852 int cmode;
5f4273c7 14853
5287ad62 14854 if (et.type == NT_invtype)
477330fc 14855 return;
5f4273c7 14856
4316f0d2
DG
14857 if (three_ops_form)
14858 constraint (inst.operands[0].reg != inst.operands[1].reg,
14859 _("first and second operands shall be the same register"));
14860
88714cb8 14861 NEON_ENCODE (IMMED, inst);
5287ad62 14862
4316f0d2 14863 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14864 if (et.size == 64)
14865 {
14866 /* .i64 is a pseudo-op, so the immediate must be a repeating
14867 pattern. */
4316f0d2
DG
14868 if (immbits != (inst.operands[immoperand].regisimm ?
14869 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14870 {
14871 /* Set immbits to an invalid constant. */
14872 immbits = 0xdeadbeef;
14873 }
14874 }
14875
5287ad62 14876 switch (opcode)
477330fc
RM
14877 {
14878 case N_MNEM_vbic:
14879 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14880 break;
14881
14882 case N_MNEM_vorr:
14883 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14884 break;
14885
14886 case N_MNEM_vand:
14887 /* Pseudo-instruction for VBIC. */
14888 neon_invert_size (&immbits, 0, et.size);
14889 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14890 break;
14891
14892 case N_MNEM_vorn:
14893 /* Pseudo-instruction for VORR. */
14894 neon_invert_size (&immbits, 0, et.size);
14895 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14896 break;
14897
14898 default:
14899 abort ();
14900 }
5287ad62
JB
14901
14902 if (cmode == FAIL)
477330fc 14903 return;
5287ad62 14904
037e8744 14905 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14906 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14907 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14908 inst.instruction |= cmode << 8;
14909 neon_write_immbits (immbits);
5f4273c7 14910
88714cb8 14911 neon_dp_fixup (&inst);
5287ad62
JB
14912 }
14913}
14914
14915static void
14916do_neon_bitfield (void)
14917{
037e8744 14918 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14919 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14920 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14921}
14922
14923static void
dcbf9037 14924neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14925 unsigned destbits)
5287ad62 14926{
037e8744 14927 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14928 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14929 types | N_KEY);
5287ad62
JB
14930 if (et.type == NT_float)
14931 {
88714cb8 14932 NEON_ENCODE (FLOAT, inst);
cc933301 14933 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14934 }
14935 else
14936 {
88714cb8 14937 NEON_ENCODE (INTEGER, inst);
037e8744 14938 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14939 }
14940}
14941
14942static void
14943do_neon_dyadic_if_su (void)
14944{
dcbf9037 14945 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14946}
14947
14948static void
14949do_neon_dyadic_if_su_d (void)
14950{
14951 /* This version only allow D registers, but that constraint is enforced during
14952 operand parsing so we don't need to do anything extra here. */
dcbf9037 14953 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14954}
14955
5287ad62
JB
14956static void
14957do_neon_dyadic_if_i_d (void)
14958{
428e3f1f
PB
14959 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14960 affected if we specify unsigned args. */
14961 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14962}
14963
037e8744
JB
14964enum vfp_or_neon_is_neon_bits
14965{
14966 NEON_CHECK_CC = 1,
73924fbc
MGD
14967 NEON_CHECK_ARCH = 2,
14968 NEON_CHECK_ARCH8 = 4
037e8744
JB
14969};
14970
14971/* Call this function if an instruction which may have belonged to the VFP or
14972 Neon instruction sets, but turned out to be a Neon instruction (due to the
14973 operand types involved, etc.). We have to check and/or fix-up a couple of
14974 things:
14975
14976 - Make sure the user hasn't attempted to make a Neon instruction
14977 conditional.
14978 - Alter the value in the condition code field if necessary.
14979 - Make sure that the arch supports Neon instructions.
14980
14981 Which of these operations take place depends on bits from enum
14982 vfp_or_neon_is_neon_bits.
14983
14984 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14985 current instruction's condition is COND_ALWAYS, the condition field is
14986 changed to inst.uncond_value. This is necessary because instructions shared
14987 between VFP and Neon may be conditional for the VFP variants only, and the
14988 unconditional Neon version must have, e.g., 0xF in the condition field. */
14989
14990static int
14991vfp_or_neon_is_neon (unsigned check)
14992{
14993 /* Conditions are always legal in Thumb mode (IT blocks). */
14994 if (!thumb_mode && (check & NEON_CHECK_CC))
14995 {
14996 if (inst.cond != COND_ALWAYS)
477330fc
RM
14997 {
14998 first_error (_(BAD_COND));
14999 return FAIL;
15000 }
037e8744 15001 if (inst.uncond_value != -1)
477330fc 15002 inst.instruction |= inst.uncond_value << 28;
037e8744 15003 }
5f4273c7 15004
037e8744 15005 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
15006 && !mark_feature_used (&fpu_neon_ext_v1))
15007 {
15008 first_error (_(BAD_FPU));
15009 return FAIL;
15010 }
15011
15012 if ((check & NEON_CHECK_ARCH8)
15013 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
15014 {
15015 first_error (_(BAD_FPU));
15016 return FAIL;
15017 }
5f4273c7 15018
037e8744
JB
15019 return SUCCESS;
15020}
15021
5287ad62
JB
15022static void
15023do_neon_addsub_if_i (void)
15024{
037e8744
JB
15025 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15026 return;
15027
15028 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15029 return;
15030
5287ad62
JB
15031 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15032 affected if we specify unsigned args. */
dcbf9037 15033 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
15034}
15035
15036/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15037 result to be:
15038 V<op> A,B (A is operand 0, B is operand 2)
15039 to mean:
15040 V<op> A,B,A
15041 not:
15042 V<op> A,B,B
15043 so handle that case specially. */
15044
15045static void
15046neon_exchange_operands (void)
15047{
5287ad62
JB
15048 if (inst.operands[1].present)
15049 {
e1fa0163
NC
15050 void *scratch = xmalloc (sizeof (inst.operands[0]));
15051
5287ad62
JB
15052 /* Swap operands[1] and operands[2]. */
15053 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15054 inst.operands[1] = inst.operands[2];
15055 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15056 free (scratch);
5287ad62
JB
15057 }
15058 else
15059 {
15060 inst.operands[1] = inst.operands[2];
15061 inst.operands[2] = inst.operands[0];
15062 }
15063}
15064
15065static void
15066neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15067{
15068 if (inst.operands[2].isreg)
15069 {
15070 if (invert)
477330fc 15071 neon_exchange_operands ();
dcbf9037 15072 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15073 }
15074 else
15075 {
037e8744 15076 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15077 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15078 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15079
88714cb8 15080 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15081 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15082 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15083 inst.instruction |= LOW4 (inst.operands[1].reg);
15084 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15085 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15086 inst.instruction |= (et.type == NT_float) << 10;
15087 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15088
88714cb8 15089 neon_dp_fixup (&inst);
5287ad62
JB
15090 }
15091}
15092
15093static void
15094do_neon_cmp (void)
15095{
cc933301 15096 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15097}
15098
15099static void
15100do_neon_cmp_inv (void)
15101{
cc933301 15102 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15103}
15104
15105static void
15106do_neon_ceq (void)
15107{
15108 neon_compare (N_IF_32, N_IF_32, FALSE);
15109}
15110
15111/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15112 scalars, which are encoded in 5 bits, M : Rm.
15113 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15114 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15115 index in M.
15116
15117 Dot Product instructions are similar to multiply instructions except elsize
15118 should always be 32.
15119
15120 This function translates SCALAR, which is GAS's internal encoding of indexed
15121 scalar register, to raw encoding. There is also register and index range
15122 check based on ELSIZE. */
5287ad62
JB
15123
15124static unsigned
15125neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15126{
dcbf9037
JB
15127 unsigned regno = NEON_SCALAR_REG (scalar);
15128 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15129
15130 switch (elsize)
15131 {
15132 case 16:
15133 if (regno > 7 || elno > 3)
477330fc 15134 goto bad_scalar;
5287ad62 15135 return regno | (elno << 3);
5f4273c7 15136
5287ad62
JB
15137 case 32:
15138 if (regno > 15 || elno > 1)
477330fc 15139 goto bad_scalar;
5287ad62
JB
15140 return regno | (elno << 4);
15141
15142 default:
15143 bad_scalar:
dcbf9037 15144 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15145 }
15146
15147 return 0;
15148}
15149
15150/* Encode multiply / multiply-accumulate scalar instructions. */
15151
15152static void
15153neon_mul_mac (struct neon_type_el et, int ubit)
15154{
dcbf9037
JB
15155 unsigned scalar;
15156
15157 /* Give a more helpful error message if we have an invalid type. */
15158 if (et.type == NT_invtype)
15159 return;
5f4273c7 15160
dcbf9037 15161 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15162 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15163 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15164 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15165 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15166 inst.instruction |= LOW4 (scalar);
15167 inst.instruction |= HI1 (scalar) << 5;
15168 inst.instruction |= (et.type == NT_float) << 8;
15169 inst.instruction |= neon_logbits (et.size) << 20;
15170 inst.instruction |= (ubit != 0) << 24;
15171
88714cb8 15172 neon_dp_fixup (&inst);
5287ad62
JB
15173}
15174
15175static void
15176do_neon_mac_maybe_scalar (void)
15177{
037e8744
JB
15178 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15179 return;
15180
15181 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15182 return;
15183
5287ad62
JB
15184 if (inst.operands[2].isscalar)
15185 {
037e8744 15186 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15187 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15188 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15189 NEON_ENCODE (SCALAR, inst);
037e8744 15190 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15191 }
15192 else
428e3f1f
PB
15193 {
15194 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15195 affected if we specify unsigned args. */
15196 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15197 }
5287ad62
JB
15198}
15199
62f3b8c8
PB
15200static void
15201do_neon_fmac (void)
15202{
15203 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15204 return;
15205
15206 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15207 return;
15208
15209 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15210}
15211
5287ad62
JB
15212static void
15213do_neon_tst (void)
15214{
037e8744 15215 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15216 struct neon_type_el et = neon_check_type (3, rs,
15217 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15218 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15219}
15220
15221/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15222 same types as the MAC equivalents. The polynomial type for this instruction
15223 is encoded the same as the integer type. */
15224
15225static void
15226do_neon_mul (void)
15227{
037e8744
JB
15228 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15229 return;
15230
15231 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15232 return;
15233
5287ad62
JB
15234 if (inst.operands[2].isscalar)
15235 do_neon_mac_maybe_scalar ();
15236 else
cc933301 15237 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15238}
15239
15240static void
15241do_neon_qdmulh (void)
15242{
15243 if (inst.operands[2].isscalar)
15244 {
037e8744 15245 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15246 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15247 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15248 NEON_ENCODE (SCALAR, inst);
037e8744 15249 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15250 }
15251 else
15252 {
037e8744 15253 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15254 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15255 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15256 NEON_ENCODE (INTEGER, inst);
5287ad62 15257 /* The U bit (rounding) comes from bit mask. */
037e8744 15258 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15259 }
15260}
15261
643afb90
MW
15262static void
15263do_neon_qrdmlah (void)
15264{
15265 /* Check we're on the correct architecture. */
15266 if (!mark_feature_used (&fpu_neon_ext_armv8))
15267 inst.error =
15268 _("instruction form not available on this architecture.");
15269 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15270 {
15271 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15272 record_feature_use (&fpu_neon_ext_v8_1);
15273 }
15274
15275 if (inst.operands[2].isscalar)
15276 {
15277 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15278 struct neon_type_el et = neon_check_type (3, rs,
15279 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15280 NEON_ENCODE (SCALAR, inst);
15281 neon_mul_mac (et, neon_quad (rs));
15282 }
15283 else
15284 {
15285 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15286 struct neon_type_el et = neon_check_type (3, rs,
15287 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15288 NEON_ENCODE (INTEGER, inst);
15289 /* The U bit (rounding) comes from bit mask. */
15290 neon_three_same (neon_quad (rs), 0, et.size);
15291 }
15292}
15293
5287ad62
JB
15294static void
15295do_neon_fcmp_absolute (void)
15296{
037e8744 15297 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15298 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15299 N_F_16_32 | N_KEY);
5287ad62 15300 /* Size field comes from bit mask. */
cc933301 15301 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15302}
15303
15304static void
15305do_neon_fcmp_absolute_inv (void)
15306{
15307 neon_exchange_operands ();
15308 do_neon_fcmp_absolute ();
15309}
15310
15311static void
15312do_neon_step (void)
15313{
037e8744 15314 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15315 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15316 N_F_16_32 | N_KEY);
15317 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15318}
15319
15320static void
15321do_neon_abs_neg (void)
15322{
037e8744
JB
15323 enum neon_shape rs;
15324 struct neon_type_el et;
5f4273c7 15325
037e8744
JB
15326 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15327 return;
15328
15329 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15330 return;
15331
15332 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15333 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15334
5287ad62
JB
15335 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15336 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15337 inst.instruction |= LOW4 (inst.operands[1].reg);
15338 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15339 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15340 inst.instruction |= (et.type == NT_float) << 10;
15341 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15342
88714cb8 15343 neon_dp_fixup (&inst);
5287ad62
JB
15344}
15345
15346static void
15347do_neon_sli (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 < 0 || (unsigned)imm >= et.size,
477330fc 15354 _("immediate out of range for insert"));
037e8744 15355 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15356}
15357
15358static void
15359do_neon_sri (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_8 | N_16 | N_32 | N_64 | N_KEY);
15364 int imm = inst.operands[2].imm;
15365 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15366 _("immediate out of range for insert"));
037e8744 15367 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15368}
15369
15370static void
15371do_neon_qshlu_imm (void)
15372{
037e8744 15373 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15374 struct neon_type_el et = neon_check_type (2, rs,
15375 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15376 int imm = inst.operands[2].imm;
15377 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15378 _("immediate out of range for shift"));
5287ad62
JB
15379 /* Only encodes the 'U present' variant of the instruction.
15380 In this case, signed types have OP (bit 8) set to 0.
15381 Unsigned types have OP set to 1. */
15382 inst.instruction |= (et.type == NT_unsigned) << 8;
15383 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15384 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15385}
15386
15387static void
15388do_neon_qmovn (void)
15389{
15390 struct neon_type_el et = neon_check_type (2, NS_DQ,
15391 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15392 /* Saturating move where operands can be signed or unsigned, and the
15393 destination has the same signedness. */
88714cb8 15394 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15395 if (et.type == NT_unsigned)
15396 inst.instruction |= 0xc0;
15397 else
15398 inst.instruction |= 0x80;
15399 neon_two_same (0, 1, et.size / 2);
15400}
15401
15402static void
15403do_neon_qmovun (void)
15404{
15405 struct neon_type_el et = neon_check_type (2, NS_DQ,
15406 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15407 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15408 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15409 neon_two_same (0, 1, et.size / 2);
15410}
15411
15412static void
15413do_neon_rshift_sat_narrow (void)
15414{
15415 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15416 or unsigned. If operands are unsigned, results must also be unsigned. */
15417 struct neon_type_el et = neon_check_type (2, NS_DQI,
15418 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15419 int imm = inst.operands[2].imm;
15420 /* This gets the bounds check, size encoding and immediate bits calculation
15421 right. */
15422 et.size /= 2;
5f4273c7 15423
5287ad62
JB
15424 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15425 VQMOVN.I<size> <Dd>, <Qm>. */
15426 if (imm == 0)
15427 {
15428 inst.operands[2].present = 0;
15429 inst.instruction = N_MNEM_vqmovn;
15430 do_neon_qmovn ();
15431 return;
15432 }
5f4273c7 15433
5287ad62 15434 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15435 _("immediate out of range"));
5287ad62
JB
15436 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15437}
15438
15439static void
15440do_neon_rshift_sat_narrow_u (void)
15441{
15442 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15443 or unsigned. If operands are unsigned, results must also be unsigned. */
15444 struct neon_type_el et = neon_check_type (2, NS_DQI,
15445 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15446 int imm = inst.operands[2].imm;
15447 /* This gets the bounds check, size encoding and immediate bits calculation
15448 right. */
15449 et.size /= 2;
15450
15451 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15452 VQMOVUN.I<size> <Dd>, <Qm>. */
15453 if (imm == 0)
15454 {
15455 inst.operands[2].present = 0;
15456 inst.instruction = N_MNEM_vqmovun;
15457 do_neon_qmovun ();
15458 return;
15459 }
15460
15461 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15462 _("immediate out of range"));
5287ad62
JB
15463 /* FIXME: The manual is kind of unclear about what value U should have in
15464 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15465 must be 1. */
15466 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15467}
15468
15469static void
15470do_neon_movn (void)
15471{
15472 struct neon_type_el et = neon_check_type (2, NS_DQ,
15473 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15474 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15475 neon_two_same (0, 1, et.size / 2);
15476}
15477
15478static void
15479do_neon_rshift_narrow (void)
15480{
15481 struct neon_type_el et = neon_check_type (2, NS_DQI,
15482 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15483 int imm = inst.operands[2].imm;
15484 /* This gets the bounds check, size encoding and immediate bits calculation
15485 right. */
15486 et.size /= 2;
5f4273c7 15487
5287ad62
JB
15488 /* If immediate is zero then we are a pseudo-instruction for
15489 VMOVN.I<size> <Dd>, <Qm> */
15490 if (imm == 0)
15491 {
15492 inst.operands[2].present = 0;
15493 inst.instruction = N_MNEM_vmovn;
15494 do_neon_movn ();
15495 return;
15496 }
5f4273c7 15497
5287ad62 15498 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15499 _("immediate out of range for narrowing operation"));
5287ad62
JB
15500 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15501}
15502
15503static void
15504do_neon_shll (void)
15505{
15506 /* FIXME: Type checking when lengthening. */
15507 struct neon_type_el et = neon_check_type (2, NS_QDI,
15508 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15509 unsigned imm = inst.operands[2].imm;
15510
15511 if (imm == et.size)
15512 {
15513 /* Maximum shift variant. */
88714cb8 15514 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15515 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15516 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15517 inst.instruction |= LOW4 (inst.operands[1].reg);
15518 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15519 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15520
88714cb8 15521 neon_dp_fixup (&inst);
5287ad62
JB
15522 }
15523 else
15524 {
15525 /* A more-specific type check for non-max versions. */
15526 et = neon_check_type (2, NS_QDI,
477330fc 15527 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15528 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15529 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15530 }
15531}
15532
037e8744 15533/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15534 the current instruction is. */
15535
6b9a8b67
MGD
15536#define CVT_FLAVOUR_VAR \
15537 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15538 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15539 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15540 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15541 /* Half-precision conversions. */ \
cc933301
JW
15542 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15543 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15544 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15545 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15546 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15547 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15548 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15549 Compared with single/double precision variants, only the co-processor \
15550 field is different, so the encoding flow is reused here. */ \
15551 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15552 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15553 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15554 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15555 /* VFP instructions. */ \
15556 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15557 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15558 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15559 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15560 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15561 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15562 /* VFP instructions with bitshift. */ \
15563 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15564 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15565 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15566 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15567 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15568 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15569 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15570 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15571
15572#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15573 neon_cvt_flavour_##C,
15574
15575/* The different types of conversions we can do. */
15576enum neon_cvt_flavour
15577{
15578 CVT_FLAVOUR_VAR
15579 neon_cvt_flavour_invalid,
15580 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15581};
15582
15583#undef CVT_VAR
15584
15585static enum neon_cvt_flavour
15586get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15587{
6b9a8b67
MGD
15588#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15589 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15590 if (et.type != NT_invtype) \
15591 { \
15592 inst.error = NULL; \
15593 return (neon_cvt_flavour_##C); \
5287ad62 15594 }
6b9a8b67 15595
5287ad62 15596 struct neon_type_el et;
037e8744 15597 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15598 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15599 /* The instruction versions which take an immediate take one register
15600 argument, which is extended to the width of the full register. Thus the
15601 "source" and "destination" registers must have the same width. Hack that
15602 here by making the size equal to the key (wider, in this case) operand. */
15603 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15604
6b9a8b67
MGD
15605 CVT_FLAVOUR_VAR;
15606
15607 return neon_cvt_flavour_invalid;
5287ad62
JB
15608#undef CVT_VAR
15609}
15610
7e8e6784
MGD
15611enum neon_cvt_mode
15612{
15613 neon_cvt_mode_a,
15614 neon_cvt_mode_n,
15615 neon_cvt_mode_p,
15616 neon_cvt_mode_m,
15617 neon_cvt_mode_z,
30bdf752
MGD
15618 neon_cvt_mode_x,
15619 neon_cvt_mode_r
7e8e6784
MGD
15620};
15621
037e8744
JB
15622/* Neon-syntax VFP conversions. */
15623
5287ad62 15624static void
6b9a8b67 15625do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15626{
037e8744 15627 const char *opname = 0;
5f4273c7 15628
d54af2d0
RL
15629 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15630 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15631 {
037e8744
JB
15632 /* Conversions with immediate bitshift. */
15633 const char *enc[] =
477330fc 15634 {
6b9a8b67
MGD
15635#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15636 CVT_FLAVOUR_VAR
15637 NULL
15638#undef CVT_VAR
477330fc 15639 };
037e8744 15640
6b9a8b67 15641 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15642 {
15643 opname = enc[flavour];
15644 constraint (inst.operands[0].reg != inst.operands[1].reg,
15645 _("operands 0 and 1 must be the same register"));
15646 inst.operands[1] = inst.operands[2];
15647 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15648 }
5287ad62
JB
15649 }
15650 else
15651 {
037e8744
JB
15652 /* Conversions without bitshift. */
15653 const char *enc[] =
477330fc 15654 {
6b9a8b67
MGD
15655#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15656 CVT_FLAVOUR_VAR
15657 NULL
15658#undef CVT_VAR
477330fc 15659 };
037e8744 15660
6b9a8b67 15661 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15662 opname = enc[flavour];
037e8744
JB
15663 }
15664
15665 if (opname)
15666 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15667
15668 /* ARMv8.2 fp16 VCVT instruction. */
15669 if (flavour == neon_cvt_flavour_s32_f16
15670 || flavour == neon_cvt_flavour_u32_f16
15671 || flavour == neon_cvt_flavour_f16_u32
15672 || flavour == neon_cvt_flavour_f16_s32)
15673 do_scalar_fp16_v82_encode ();
037e8744
JB
15674}
15675
15676static void
15677do_vfp_nsyn_cvtz (void)
15678{
d54af2d0 15679 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15680 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15681 const char *enc[] =
15682 {
6b9a8b67
MGD
15683#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15684 CVT_FLAVOUR_VAR
15685 NULL
15686#undef CVT_VAR
037e8744
JB
15687 };
15688
6b9a8b67 15689 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15690 do_vfp_nsyn_opcode (enc[flavour]);
15691}
f31fef98 15692
037e8744 15693static void
bacebabc 15694do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15695 enum neon_cvt_mode mode)
15696{
15697 int sz, op;
15698 int rm;
15699
a715796b
TG
15700 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15701 D register operands. */
15702 if (flavour == neon_cvt_flavour_s32_f64
15703 || flavour == neon_cvt_flavour_u32_f64)
15704 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15705 _(BAD_FPU));
15706
9db2f6b4
RL
15707 if (flavour == neon_cvt_flavour_s32_f16
15708 || flavour == neon_cvt_flavour_u32_f16)
15709 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15710 _(BAD_FP16));
15711
7e8e6784
MGD
15712 set_it_insn_type (OUTSIDE_IT_INSN);
15713
15714 switch (flavour)
15715 {
15716 case neon_cvt_flavour_s32_f64:
15717 sz = 1;
827f64ff 15718 op = 1;
7e8e6784
MGD
15719 break;
15720 case neon_cvt_flavour_s32_f32:
15721 sz = 0;
15722 op = 1;
15723 break;
9db2f6b4
RL
15724 case neon_cvt_flavour_s32_f16:
15725 sz = 0;
15726 op = 1;
15727 break;
7e8e6784
MGD
15728 case neon_cvt_flavour_u32_f64:
15729 sz = 1;
15730 op = 0;
15731 break;
15732 case neon_cvt_flavour_u32_f32:
15733 sz = 0;
15734 op = 0;
15735 break;
9db2f6b4
RL
15736 case neon_cvt_flavour_u32_f16:
15737 sz = 0;
15738 op = 0;
15739 break;
7e8e6784
MGD
15740 default:
15741 first_error (_("invalid instruction shape"));
15742 return;
15743 }
15744
15745 switch (mode)
15746 {
15747 case neon_cvt_mode_a: rm = 0; break;
15748 case neon_cvt_mode_n: rm = 1; break;
15749 case neon_cvt_mode_p: rm = 2; break;
15750 case neon_cvt_mode_m: rm = 3; break;
15751 default: first_error (_("invalid rounding mode")); return;
15752 }
15753
15754 NEON_ENCODE (FPV8, inst);
15755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15756 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15757 inst.instruction |= sz << 8;
9db2f6b4
RL
15758
15759 /* ARMv8.2 fp16 VCVT instruction. */
15760 if (flavour == neon_cvt_flavour_s32_f16
15761 ||flavour == neon_cvt_flavour_u32_f16)
15762 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15763 inst.instruction |= op << 7;
15764 inst.instruction |= rm << 16;
15765 inst.instruction |= 0xf0000000;
15766 inst.is_neon = TRUE;
15767}
15768
15769static void
15770do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15771{
15772 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15773 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15774 NS_FH, NS_HF, NS_FHI, NS_HFI,
15775 NS_NULL);
6b9a8b67 15776 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15777
cc933301
JW
15778 if (flavour == neon_cvt_flavour_invalid)
15779 return;
15780
e3e535bc 15781 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15782 if (mode == neon_cvt_mode_z
e3e535bc 15783 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15784 && (flavour == neon_cvt_flavour_s16_f16
15785 || flavour == neon_cvt_flavour_u16_f16
15786 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15787 || flavour == neon_cvt_flavour_u32_f32
15788 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15789 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15790 && (rs == NS_FD || rs == NS_FF))
15791 {
15792 do_vfp_nsyn_cvtz ();
15793 return;
15794 }
15795
9db2f6b4
RL
15796 /* ARMv8.2 fp16 VCVT conversions. */
15797 if (mode == neon_cvt_mode_z
15798 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15799 && (flavour == neon_cvt_flavour_s32_f16
15800 || flavour == neon_cvt_flavour_u32_f16)
15801 && (rs == NS_FH))
15802 {
15803 do_vfp_nsyn_cvtz ();
15804 do_scalar_fp16_v82_encode ();
15805 return;
15806 }
15807
037e8744 15808 /* VFP rather than Neon conversions. */
6b9a8b67 15809 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15810 {
7e8e6784
MGD
15811 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15812 do_vfp_nsyn_cvt (rs, flavour);
15813 else
15814 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15815
037e8744
JB
15816 return;
15817 }
15818
15819 switch (rs)
15820 {
15821 case NS_DDI:
15822 case NS_QQI:
15823 {
477330fc 15824 unsigned immbits;
cc933301
JW
15825 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15826 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15827
477330fc
RM
15828 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15829 return;
037e8744 15830
477330fc
RM
15831 /* Fixed-point conversion with #0 immediate is encoded as an
15832 integer conversion. */
15833 if (inst.operands[2].present && inst.operands[2].imm == 0)
15834 goto int_encode;
477330fc
RM
15835 NEON_ENCODE (IMMED, inst);
15836 if (flavour != neon_cvt_flavour_invalid)
15837 inst.instruction |= enctab[flavour];
15838 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15839 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15840 inst.instruction |= LOW4 (inst.operands[1].reg);
15841 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15842 inst.instruction |= neon_quad (rs) << 6;
15843 inst.instruction |= 1 << 21;
cc933301
JW
15844 if (flavour < neon_cvt_flavour_s16_f16)
15845 {
15846 inst.instruction |= 1 << 21;
15847 immbits = 32 - inst.operands[2].imm;
15848 inst.instruction |= immbits << 16;
15849 }
15850 else
15851 {
15852 inst.instruction |= 3 << 20;
15853 immbits = 16 - inst.operands[2].imm;
15854 inst.instruction |= immbits << 16;
15855 inst.instruction &= ~(1 << 9);
15856 }
477330fc
RM
15857
15858 neon_dp_fixup (&inst);
037e8744
JB
15859 }
15860 break;
15861
15862 case NS_DD:
15863 case NS_QQ:
7e8e6784
MGD
15864 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15865 {
15866 NEON_ENCODE (FLOAT, inst);
15867 set_it_insn_type (OUTSIDE_IT_INSN);
15868
15869 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15870 return;
15871
15872 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15873 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15874 inst.instruction |= LOW4 (inst.operands[1].reg);
15875 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15876 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15877 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15878 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15879 inst.instruction |= mode << 8;
cc933301
JW
15880 if (flavour == neon_cvt_flavour_u16_f16
15881 || flavour == neon_cvt_flavour_s16_f16)
15882 /* Mask off the original size bits and reencode them. */
15883 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15884
7e8e6784
MGD
15885 if (thumb_mode)
15886 inst.instruction |= 0xfc000000;
15887 else
15888 inst.instruction |= 0xf0000000;
15889 }
15890 else
15891 {
037e8744 15892 int_encode:
7e8e6784 15893 {
cc933301
JW
15894 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15895 0x100, 0x180, 0x0, 0x080};
037e8744 15896
7e8e6784 15897 NEON_ENCODE (INTEGER, inst);
037e8744 15898
7e8e6784
MGD
15899 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15900 return;
037e8744 15901
7e8e6784
MGD
15902 if (flavour != neon_cvt_flavour_invalid)
15903 inst.instruction |= enctab[flavour];
037e8744 15904
7e8e6784
MGD
15905 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15906 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15907 inst.instruction |= LOW4 (inst.operands[1].reg);
15908 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15909 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15910 if (flavour >= neon_cvt_flavour_s16_f16
15911 && flavour <= neon_cvt_flavour_f16_u16)
15912 /* Half precision. */
15913 inst.instruction |= 1 << 18;
15914 else
15915 inst.instruction |= 2 << 18;
037e8744 15916
7e8e6784
MGD
15917 neon_dp_fixup (&inst);
15918 }
15919 }
15920 break;
037e8744 15921
8e79c3df
CM
15922 /* Half-precision conversions for Advanced SIMD -- neon. */
15923 case NS_QD:
15924 case NS_DQ:
15925
15926 if ((rs == NS_DQ)
15927 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15928 {
15929 as_bad (_("operand size must match register width"));
15930 break;
15931 }
15932
15933 if ((rs == NS_QD)
15934 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15935 {
15936 as_bad (_("operand size must match register width"));
15937 break;
15938 }
15939
15940 if (rs == NS_DQ)
477330fc 15941 inst.instruction = 0x3b60600;
8e79c3df
CM
15942 else
15943 inst.instruction = 0x3b60700;
15944
15945 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15946 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15947 inst.instruction |= LOW4 (inst.operands[1].reg);
15948 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15949 neon_dp_fixup (&inst);
8e79c3df
CM
15950 break;
15951
037e8744
JB
15952 default:
15953 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15954 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15955 do_vfp_nsyn_cvt (rs, flavour);
15956 else
15957 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15958 }
5287ad62
JB
15959}
15960
e3e535bc
NC
15961static void
15962do_neon_cvtr (void)
15963{
7e8e6784 15964 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15965}
15966
15967static void
15968do_neon_cvt (void)
15969{
7e8e6784
MGD
15970 do_neon_cvt_1 (neon_cvt_mode_z);
15971}
15972
15973static void
15974do_neon_cvta (void)
15975{
15976 do_neon_cvt_1 (neon_cvt_mode_a);
15977}
15978
15979static void
15980do_neon_cvtn (void)
15981{
15982 do_neon_cvt_1 (neon_cvt_mode_n);
15983}
15984
15985static void
15986do_neon_cvtp (void)
15987{
15988 do_neon_cvt_1 (neon_cvt_mode_p);
15989}
15990
15991static void
15992do_neon_cvtm (void)
15993{
15994 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15995}
15996
8e79c3df 15997static void
c70a8987 15998do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15999{
c70a8987
MGD
16000 if (is_double)
16001 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 16002
c70a8987
MGD
16003 encode_arm_vfp_reg (inst.operands[0].reg,
16004 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16005 encode_arm_vfp_reg (inst.operands[1].reg,
16006 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16007 inst.instruction |= to ? 0x10000 : 0;
16008 inst.instruction |= t ? 0x80 : 0;
16009 inst.instruction |= is_double ? 0x100 : 0;
16010 do_vfp_cond_or_thumb ();
16011}
8e79c3df 16012
c70a8987
MGD
16013static void
16014do_neon_cvttb_1 (bfd_boolean t)
16015{
d54af2d0
RL
16016 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16017 NS_DF, NS_DH, NS_NULL);
8e79c3df 16018
c70a8987
MGD
16019 if (rs == NS_NULL)
16020 return;
16021 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16022 {
16023 inst.error = NULL;
16024 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16025 }
16026 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16027 {
16028 inst.error = NULL;
16029 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16030 }
16031 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16032 {
a715796b
TG
16033 /* The VCVTB and VCVTT instructions with D-register operands
16034 don't work for SP only targets. */
16035 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16036 _(BAD_FPU));
16037
c70a8987
MGD
16038 inst.error = NULL;
16039 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16040 }
16041 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16042 {
a715796b
TG
16043 /* The VCVTB and VCVTT instructions with D-register operands
16044 don't work for SP only targets. */
16045 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16046 _(BAD_FPU));
16047
c70a8987
MGD
16048 inst.error = NULL;
16049 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16050 }
16051 else
16052 return;
16053}
16054
16055static void
16056do_neon_cvtb (void)
16057{
16058 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16059}
16060
16061
16062static void
16063do_neon_cvtt (void)
16064{
c70a8987 16065 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16066}
16067
5287ad62
JB
16068static void
16069neon_move_immediate (void)
16070{
037e8744
JB
16071 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16072 struct neon_type_el et = neon_check_type (2, rs,
16073 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16074 unsigned immlo, immhi = 0, immbits;
c96612cc 16075 int op, cmode, float_p;
5287ad62 16076
037e8744 16077 constraint (et.type == NT_invtype,
477330fc 16078 _("operand size must be specified for immediate VMOV"));
037e8744 16079
5287ad62
JB
16080 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16081 op = (inst.instruction & (1 << 5)) != 0;
16082
16083 immlo = inst.operands[1].imm;
16084 if (inst.operands[1].regisimm)
16085 immhi = inst.operands[1].reg;
16086
16087 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16088 _("immediate has bits set outside the operand size"));
5287ad62 16089
c96612cc
JB
16090 float_p = inst.operands[1].immisfloat;
16091
16092 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16093 et.size, et.type)) == FAIL)
5287ad62
JB
16094 {
16095 /* Invert relevant bits only. */
16096 neon_invert_size (&immlo, &immhi, et.size);
16097 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16098 with one or the other; those cases are caught by
16099 neon_cmode_for_move_imm. */
5287ad62 16100 op = !op;
c96612cc
JB
16101 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16102 &op, et.size, et.type)) == FAIL)
477330fc
RM
16103 {
16104 first_error (_("immediate out of range"));
16105 return;
16106 }
5287ad62
JB
16107 }
16108
16109 inst.instruction &= ~(1 << 5);
16110 inst.instruction |= op << 5;
16111
16112 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16113 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16114 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16115 inst.instruction |= cmode << 8;
16116
16117 neon_write_immbits (immbits);
16118}
16119
16120static void
16121do_neon_mvn (void)
16122{
16123 if (inst.operands[1].isreg)
16124 {
037e8744 16125 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16126
88714cb8 16127 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16128 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16129 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16130 inst.instruction |= LOW4 (inst.operands[1].reg);
16131 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16132 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16133 }
16134 else
16135 {
88714cb8 16136 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16137 neon_move_immediate ();
16138 }
16139
88714cb8 16140 neon_dp_fixup (&inst);
5287ad62
JB
16141}
16142
16143/* Encode instructions of form:
16144
16145 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16146 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16147
16148static void
16149neon_mixed_length (struct neon_type_el et, unsigned size)
16150{
16151 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16152 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16153 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16154 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16155 inst.instruction |= LOW4 (inst.operands[2].reg);
16156 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16157 inst.instruction |= (et.type == NT_unsigned) << 24;
16158 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16159
88714cb8 16160 neon_dp_fixup (&inst);
5287ad62
JB
16161}
16162
16163static void
16164do_neon_dyadic_long (void)
16165{
16166 /* FIXME: Type checking for lengthening op. */
16167 struct neon_type_el et = neon_check_type (3, NS_QDD,
16168 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16169 neon_mixed_length (et, et.size);
16170}
16171
16172static void
16173do_neon_abal (void)
16174{
16175 struct neon_type_el et = neon_check_type (3, NS_QDD,
16176 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16177 neon_mixed_length (et, et.size);
16178}
16179
16180static void
16181neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16182{
16183 if (inst.operands[2].isscalar)
16184 {
dcbf9037 16185 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16186 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16187 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16188 neon_mul_mac (et, et.type == NT_unsigned);
16189 }
16190 else
16191 {
16192 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16193 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16194 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16195 neon_mixed_length (et, et.size);
16196 }
16197}
16198
16199static void
16200do_neon_mac_maybe_scalar_long (void)
16201{
16202 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16203}
16204
dec41383
JW
16205/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16206 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16207
16208static unsigned
16209neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16210{
16211 unsigned regno = NEON_SCALAR_REG (scalar);
16212 unsigned elno = NEON_SCALAR_INDEX (scalar);
16213
16214 if (quad_p)
16215 {
16216 if (regno > 7 || elno > 3)
16217 goto bad_scalar;
16218
16219 return ((regno & 0x7)
16220 | ((elno & 0x1) << 3)
16221 | (((elno >> 1) & 0x1) << 5));
16222 }
16223 else
16224 {
16225 if (regno > 15 || elno > 1)
16226 goto bad_scalar;
16227
16228 return (((regno & 0x1) << 5)
16229 | ((regno >> 1) & 0x7)
16230 | ((elno & 0x1) << 3));
16231 }
16232
16233bad_scalar:
16234 first_error (_("scalar out of range for multiply instruction"));
16235 return 0;
16236}
16237
16238static void
16239do_neon_fmac_maybe_scalar_long (int subtype)
16240{
16241 enum neon_shape rs;
16242 int high8;
16243 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16244 field (bits[21:20]) has different meaning. For scalar index variant, it's
16245 used to differentiate add and subtract, otherwise it's with fixed value
16246 0x2. */
16247 int size = -1;
16248
16249 if (inst.cond != COND_ALWAYS)
16250 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16251 "behaviour is UNPREDICTABLE"));
16252
01f48020 16253 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
dec41383
JW
16254 _(BAD_FP16));
16255
16256 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16257 _(BAD_FPU));
16258
16259 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16260 be a scalar index register. */
16261 if (inst.operands[2].isscalar)
16262 {
16263 high8 = 0xfe000000;
16264 if (subtype)
16265 size = 16;
16266 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16267 }
16268 else
16269 {
16270 high8 = 0xfc000000;
16271 size = 32;
16272 if (subtype)
16273 inst.instruction |= (0x1 << 23);
16274 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16275 }
16276
16277 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16278
16279 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16280 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16281 so we simply pass -1 as size. */
16282 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16283 neon_three_same (quad_p, 0, size);
16284
16285 /* Undo neon_dp_fixup. Redo the high eight bits. */
16286 inst.instruction &= 0x00ffffff;
16287 inst.instruction |= high8;
16288
16289#define LOW1(R) ((R) & 0x1)
16290#define HI4(R) (((R) >> 1) & 0xf)
16291 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16292 whether the instruction is in Q form and whether Vm is a scalar indexed
16293 operand. */
16294 if (inst.operands[2].isscalar)
16295 {
16296 unsigned rm
16297 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16298 inst.instruction &= 0xffffffd0;
16299 inst.instruction |= rm;
16300
16301 if (!quad_p)
16302 {
16303 /* Redo Rn as well. */
16304 inst.instruction &= 0xfff0ff7f;
16305 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16306 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16307 }
16308 }
16309 else if (!quad_p)
16310 {
16311 /* Redo Rn and Rm. */
16312 inst.instruction &= 0xfff0ff50;
16313 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16314 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16315 inst.instruction |= HI4 (inst.operands[2].reg);
16316 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16317 }
16318}
16319
16320static void
16321do_neon_vfmal (void)
16322{
16323 return do_neon_fmac_maybe_scalar_long (0);
16324}
16325
16326static void
16327do_neon_vfmsl (void)
16328{
16329 return do_neon_fmac_maybe_scalar_long (1);
16330}
16331
5287ad62
JB
16332static void
16333do_neon_dyadic_wide (void)
16334{
16335 struct neon_type_el et = neon_check_type (3, NS_QQD,
16336 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16337 neon_mixed_length (et, et.size);
16338}
16339
16340static void
16341do_neon_dyadic_narrow (void)
16342{
16343 struct neon_type_el et = neon_check_type (3, NS_QDD,
16344 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16345 /* Operand sign is unimportant, and the U bit is part of the opcode,
16346 so force the operand type to integer. */
16347 et.type = NT_integer;
5287ad62
JB
16348 neon_mixed_length (et, et.size / 2);
16349}
16350
16351static void
16352do_neon_mul_sat_scalar_long (void)
16353{
16354 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16355}
16356
16357static void
16358do_neon_vmull (void)
16359{
16360 if (inst.operands[2].isscalar)
16361 do_neon_mac_maybe_scalar_long ();
16362 else
16363 {
16364 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16365 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16366
5287ad62 16367 if (et.type == NT_poly)
477330fc 16368 NEON_ENCODE (POLY, inst);
5287ad62 16369 else
477330fc 16370 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16371
16372 /* For polynomial encoding the U bit must be zero, and the size must
16373 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16374 obviously, as 0b10). */
16375 if (et.size == 64)
16376 {
16377 /* Check we're on the correct architecture. */
16378 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16379 inst.error =
16380 _("Instruction form not available on this architecture.");
16381
16382 et.size = 32;
16383 }
16384
5287ad62
JB
16385 neon_mixed_length (et, et.size);
16386 }
16387}
16388
16389static void
16390do_neon_ext (void)
16391{
037e8744 16392 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16393 struct neon_type_el et = neon_check_type (3, rs,
16394 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16395 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16396
16397 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16398 _("shift out of range"));
5287ad62
JB
16399 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16400 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16401 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16402 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16403 inst.instruction |= LOW4 (inst.operands[2].reg);
16404 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16405 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16406 inst.instruction |= imm << 8;
5f4273c7 16407
88714cb8 16408 neon_dp_fixup (&inst);
5287ad62
JB
16409}
16410
16411static void
16412do_neon_rev (void)
16413{
037e8744 16414 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16415 struct neon_type_el et = neon_check_type (2, rs,
16416 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16417 unsigned op = (inst.instruction >> 7) & 3;
16418 /* N (width of reversed regions) is encoded as part of the bitmask. We
16419 extract it here to check the elements to be reversed are smaller.
16420 Otherwise we'd get a reserved instruction. */
16421 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16422 gas_assert (elsize != 0);
5287ad62 16423 constraint (et.size >= elsize,
477330fc 16424 _("elements must be smaller than reversal region"));
037e8744 16425 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16426}
16427
16428static void
16429do_neon_dup (void)
16430{
16431 if (inst.operands[1].isscalar)
16432 {
037e8744 16433 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16434 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16435 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16436 unsigned sizebits = et.size >> 3;
dcbf9037 16437 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16438 int logsize = neon_logbits (et.size);
dcbf9037 16439 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16440
16441 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16442 return;
037e8744 16443
88714cb8 16444 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16445 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16446 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16447 inst.instruction |= LOW4 (dm);
16448 inst.instruction |= HI1 (dm) << 5;
037e8744 16449 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16450 inst.instruction |= x << 17;
16451 inst.instruction |= sizebits << 16;
5f4273c7 16452
88714cb8 16453 neon_dp_fixup (&inst);
5287ad62
JB
16454 }
16455 else
16456 {
037e8744
JB
16457 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16458 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16459 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16460 /* Duplicate ARM register to lanes of vector. */
88714cb8 16461 NEON_ENCODE (ARMREG, inst);
5287ad62 16462 switch (et.size)
477330fc
RM
16463 {
16464 case 8: inst.instruction |= 0x400000; break;
16465 case 16: inst.instruction |= 0x000020; break;
16466 case 32: inst.instruction |= 0x000000; break;
16467 default: break;
16468 }
5287ad62
JB
16469 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16470 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16471 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16472 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16473 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16474 variants, except for the condition field. */
037e8744 16475 do_vfp_cond_or_thumb ();
5287ad62
JB
16476 }
16477}
16478
16479/* VMOV has particularly many variations. It can be one of:
16480 0. VMOV<c><q> <Qd>, <Qm>
16481 1. VMOV<c><q> <Dd>, <Dm>
16482 (Register operations, which are VORR with Rm = Rn.)
16483 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16484 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16485 (Immediate loads.)
16486 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16487 (ARM register to scalar.)
16488 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16489 (Two ARM registers to vector.)
16490 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16491 (Scalar to ARM register.)
16492 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16493 (Vector to two ARM registers.)
037e8744
JB
16494 8. VMOV.F32 <Sd>, <Sm>
16495 9. VMOV.F64 <Dd>, <Dm>
16496 (VFP register moves.)
16497 10. VMOV.F32 <Sd>, #imm
16498 11. VMOV.F64 <Dd>, #imm
16499 (VFP float immediate load.)
16500 12. VMOV <Rd>, <Sm>
16501 (VFP single to ARM reg.)
16502 13. VMOV <Sd>, <Rm>
16503 (ARM reg to VFP single.)
16504 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16505 (Two ARM regs to two VFP singles.)
16506 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16507 (Two VFP singles to two ARM regs.)
5f4273c7 16508
037e8744
JB
16509 These cases can be disambiguated using neon_select_shape, except cases 1/9
16510 and 3/11 which depend on the operand type too.
5f4273c7 16511
5287ad62 16512 All the encoded bits are hardcoded by this function.
5f4273c7 16513
b7fc2769
JB
16514 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16515 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16516
5287ad62 16517 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16518 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16519
16520static void
16521do_neon_mov (void)
16522{
037e8744 16523 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16524 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16525 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16526 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16527 struct neon_type_el et;
16528 const char *ldconst = 0;
5287ad62 16529
037e8744 16530 switch (rs)
5287ad62 16531 {
037e8744
JB
16532 case NS_DD: /* case 1/9. */
16533 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16534 /* It is not an error here if no type is given. */
16535 inst.error = NULL;
16536 if (et.type == NT_float && et.size == 64)
477330fc
RM
16537 {
16538 do_vfp_nsyn_opcode ("fcpyd");
16539 break;
16540 }
037e8744 16541 /* fall through. */
5287ad62 16542
037e8744
JB
16543 case NS_QQ: /* case 0/1. */
16544 {
477330fc
RM
16545 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16546 return;
16547 /* The architecture manual I have doesn't explicitly state which
16548 value the U bit should have for register->register moves, but
16549 the equivalent VORR instruction has U = 0, so do that. */
16550 inst.instruction = 0x0200110;
16551 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16552 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16553 inst.instruction |= LOW4 (inst.operands[1].reg);
16554 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16555 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16556 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16557 inst.instruction |= neon_quad (rs) << 6;
16558
16559 neon_dp_fixup (&inst);
037e8744
JB
16560 }
16561 break;
5f4273c7 16562
037e8744
JB
16563 case NS_DI: /* case 3/11. */
16564 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16565 inst.error = NULL;
16566 if (et.type == NT_float && et.size == 64)
477330fc
RM
16567 {
16568 /* case 11 (fconstd). */
16569 ldconst = "fconstd";
16570 goto encode_fconstd;
16571 }
037e8744
JB
16572 /* fall through. */
16573
16574 case NS_QI: /* case 2/3. */
16575 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16576 return;
037e8744
JB
16577 inst.instruction = 0x0800010;
16578 neon_move_immediate ();
88714cb8 16579 neon_dp_fixup (&inst);
5287ad62 16580 break;
5f4273c7 16581
037e8744
JB
16582 case NS_SR: /* case 4. */
16583 {
477330fc
RM
16584 unsigned bcdebits = 0;
16585 int logsize;
16586 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16587 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16588
05ac0ffb
JB
16589 /* .<size> is optional here, defaulting to .32. */
16590 if (inst.vectype.elems == 0
16591 && inst.operands[0].vectype.type == NT_invtype
16592 && inst.operands[1].vectype.type == NT_invtype)
16593 {
16594 inst.vectype.el[0].type = NT_untyped;
16595 inst.vectype.el[0].size = 32;
16596 inst.vectype.elems = 1;
16597 }
16598
477330fc
RM
16599 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16600 logsize = neon_logbits (et.size);
16601
16602 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16603 _(BAD_FPU));
16604 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16605 && et.size != 32, _(BAD_FPU));
16606 constraint (et.type == NT_invtype, _("bad type for scalar"));
16607 constraint (x >= 64 / et.size, _("scalar index out of range"));
16608
16609 switch (et.size)
16610 {
16611 case 8: bcdebits = 0x8; break;
16612 case 16: bcdebits = 0x1; break;
16613 case 32: bcdebits = 0x0; break;
16614 default: ;
16615 }
16616
16617 bcdebits |= x << logsize;
16618
16619 inst.instruction = 0xe000b10;
16620 do_vfp_cond_or_thumb ();
16621 inst.instruction |= LOW4 (dn) << 16;
16622 inst.instruction |= HI1 (dn) << 7;
16623 inst.instruction |= inst.operands[1].reg << 12;
16624 inst.instruction |= (bcdebits & 3) << 5;
16625 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16626 }
16627 break;
5f4273c7 16628
037e8744 16629 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16630 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16631 _(BAD_FPU));
b7fc2769 16632
037e8744
JB
16633 inst.instruction = 0xc400b10;
16634 do_vfp_cond_or_thumb ();
16635 inst.instruction |= LOW4 (inst.operands[0].reg);
16636 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16637 inst.instruction |= inst.operands[1].reg << 12;
16638 inst.instruction |= inst.operands[2].reg << 16;
16639 break;
5f4273c7 16640
037e8744
JB
16641 case NS_RS: /* case 6. */
16642 {
477330fc
RM
16643 unsigned logsize;
16644 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16645 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16646 unsigned abcdebits = 0;
037e8744 16647
05ac0ffb
JB
16648 /* .<dt> is optional here, defaulting to .32. */
16649 if (inst.vectype.elems == 0
16650 && inst.operands[0].vectype.type == NT_invtype
16651 && inst.operands[1].vectype.type == NT_invtype)
16652 {
16653 inst.vectype.el[0].type = NT_untyped;
16654 inst.vectype.el[0].size = 32;
16655 inst.vectype.elems = 1;
16656 }
16657
91d6fa6a
NC
16658 et = neon_check_type (2, NS_NULL,
16659 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16660 logsize = neon_logbits (et.size);
16661
16662 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16663 _(BAD_FPU));
16664 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16665 && et.size != 32, _(BAD_FPU));
16666 constraint (et.type == NT_invtype, _("bad type for scalar"));
16667 constraint (x >= 64 / et.size, _("scalar index out of range"));
16668
16669 switch (et.size)
16670 {
16671 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16672 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16673 case 32: abcdebits = 0x00; break;
16674 default: ;
16675 }
16676
16677 abcdebits |= x << logsize;
16678 inst.instruction = 0xe100b10;
16679 do_vfp_cond_or_thumb ();
16680 inst.instruction |= LOW4 (dn) << 16;
16681 inst.instruction |= HI1 (dn) << 7;
16682 inst.instruction |= inst.operands[0].reg << 12;
16683 inst.instruction |= (abcdebits & 3) << 5;
16684 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16685 }
16686 break;
5f4273c7 16687
037e8744
JB
16688 case NS_RRD: /* case 7 (fmrrd). */
16689 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16690 _(BAD_FPU));
037e8744
JB
16691
16692 inst.instruction = 0xc500b10;
16693 do_vfp_cond_or_thumb ();
16694 inst.instruction |= inst.operands[0].reg << 12;
16695 inst.instruction |= inst.operands[1].reg << 16;
16696 inst.instruction |= LOW4 (inst.operands[2].reg);
16697 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16698 break;
5f4273c7 16699
037e8744
JB
16700 case NS_FF: /* case 8 (fcpys). */
16701 do_vfp_nsyn_opcode ("fcpys");
16702 break;
5f4273c7 16703
9db2f6b4 16704 case NS_HI:
037e8744
JB
16705 case NS_FI: /* case 10 (fconsts). */
16706 ldconst = "fconsts";
16707 encode_fconstd:
16708 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16709 {
16710 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16711 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16712
16713 /* ARMv8.2 fp16 vmov.f16 instruction. */
16714 if (rs == NS_HI)
16715 do_scalar_fp16_v82_encode ();
477330fc 16716 }
5287ad62 16717 else
477330fc 16718 first_error (_("immediate out of range"));
037e8744 16719 break;
5f4273c7 16720
9db2f6b4 16721 case NS_RH:
037e8744
JB
16722 case NS_RF: /* case 12 (fmrs). */
16723 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16724 /* ARMv8.2 fp16 vmov.f16 instruction. */
16725 if (rs == NS_RH)
16726 do_scalar_fp16_v82_encode ();
037e8744 16727 break;
5f4273c7 16728
9db2f6b4 16729 case NS_HR:
037e8744
JB
16730 case NS_FR: /* case 13 (fmsr). */
16731 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16732 /* ARMv8.2 fp16 vmov.f16 instruction. */
16733 if (rs == NS_HR)
16734 do_scalar_fp16_v82_encode ();
037e8744 16735 break;
5f4273c7 16736
037e8744
JB
16737 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16738 (one of which is a list), but we have parsed four. Do some fiddling to
16739 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16740 expect. */
16741 case NS_RRFF: /* case 14 (fmrrs). */
16742 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16743 _("VFP registers must be adjacent"));
037e8744
JB
16744 inst.operands[2].imm = 2;
16745 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16746 do_vfp_nsyn_opcode ("fmrrs");
16747 break;
5f4273c7 16748
037e8744
JB
16749 case NS_FFRR: /* case 15 (fmsrr). */
16750 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16751 _("VFP registers must be adjacent"));
037e8744
JB
16752 inst.operands[1] = inst.operands[2];
16753 inst.operands[2] = inst.operands[3];
16754 inst.operands[0].imm = 2;
16755 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16756 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16757 break;
5f4273c7 16758
4c261dff
NC
16759 case NS_NULL:
16760 /* neon_select_shape has determined that the instruction
16761 shape is wrong and has already set the error message. */
16762 break;
16763
5287ad62
JB
16764 default:
16765 abort ();
16766 }
16767}
16768
16769static void
16770do_neon_rshift_round_imm (void)
16771{
037e8744 16772 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16773 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16774 int imm = inst.operands[2].imm;
16775
16776 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16777 if (imm == 0)
16778 {
16779 inst.operands[2].present = 0;
16780 do_neon_mov ();
16781 return;
16782 }
16783
16784 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16785 _("immediate out of range for shift"));
037e8744 16786 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16787 et.size - imm);
5287ad62
JB
16788}
16789
9db2f6b4
RL
16790static void
16791do_neon_movhf (void)
16792{
16793 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16794 constraint (rs != NS_HH, _("invalid suffix"));
16795
16796 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16797 _(BAD_FPU));
16798
7bdf778b
ASDV
16799 if (inst.cond != COND_ALWAYS)
16800 {
16801 if (thumb_mode)
16802 {
16803 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
16804 " the behaviour is UNPREDICTABLE"));
16805 }
16806 else
16807 {
16808 inst.error = BAD_COND;
16809 return;
16810 }
16811 }
16812
9db2f6b4
RL
16813 do_vfp_sp_monadic ();
16814
16815 inst.is_neon = 1;
16816 inst.instruction |= 0xf0000000;
16817}
16818
5287ad62
JB
16819static void
16820do_neon_movl (void)
16821{
16822 struct neon_type_el et = neon_check_type (2, NS_QD,
16823 N_EQK | N_DBL, N_SU_32 | N_KEY);
16824 unsigned sizebits = et.size >> 3;
16825 inst.instruction |= sizebits << 19;
16826 neon_two_same (0, et.type == NT_unsigned, -1);
16827}
16828
16829static void
16830do_neon_trn (void)
16831{
037e8744 16832 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16833 struct neon_type_el et = neon_check_type (2, rs,
16834 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16835 NEON_ENCODE (INTEGER, inst);
037e8744 16836 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16837}
16838
16839static void
16840do_neon_zip_uzp (void)
16841{
037e8744 16842 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16843 struct neon_type_el et = neon_check_type (2, rs,
16844 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16845 if (rs == NS_DD && et.size == 32)
16846 {
16847 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16848 inst.instruction = N_MNEM_vtrn;
16849 do_neon_trn ();
16850 return;
16851 }
037e8744 16852 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16853}
16854
16855static void
16856do_neon_sat_abs_neg (void)
16857{
037e8744 16858 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16859 struct neon_type_el et = neon_check_type (2, rs,
16860 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16861 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16862}
16863
16864static void
16865do_neon_pair_long (void)
16866{
037e8744 16867 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16868 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16869 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16870 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16871 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16872}
16873
16874static void
16875do_neon_recip_est (void)
16876{
037e8744 16877 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16878 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16879 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16880 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16881 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16882}
16883
16884static void
16885do_neon_cls (void)
16886{
037e8744 16887 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16888 struct neon_type_el et = neon_check_type (2, rs,
16889 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16890 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16891}
16892
16893static void
16894do_neon_clz (void)
16895{
037e8744 16896 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16897 struct neon_type_el et = neon_check_type (2, rs,
16898 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16899 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16900}
16901
16902static void
16903do_neon_cnt (void)
16904{
037e8744 16905 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16906 struct neon_type_el et = neon_check_type (2, rs,
16907 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16908 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16909}
16910
16911static void
16912do_neon_swp (void)
16913{
037e8744
JB
16914 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16915 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16916}
16917
16918static void
16919do_neon_tbl_tbx (void)
16920{
16921 unsigned listlenbits;
dcbf9037 16922 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16923
5287ad62
JB
16924 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16925 {
dcbf9037 16926 first_error (_("bad list length for table lookup"));
5287ad62
JB
16927 return;
16928 }
5f4273c7 16929
5287ad62
JB
16930 listlenbits = inst.operands[1].imm - 1;
16931 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16932 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16933 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16934 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16935 inst.instruction |= LOW4 (inst.operands[2].reg);
16936 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16937 inst.instruction |= listlenbits << 8;
5f4273c7 16938
88714cb8 16939 neon_dp_fixup (&inst);
5287ad62
JB
16940}
16941
16942static void
16943do_neon_ldm_stm (void)
16944{
16945 /* P, U and L bits are part of bitmask. */
16946 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16947 unsigned offsetbits = inst.operands[1].imm * 2;
16948
037e8744
JB
16949 if (inst.operands[1].issingle)
16950 {
16951 do_vfp_nsyn_ldm_stm (is_dbmode);
16952 return;
16953 }
16954
5287ad62 16955 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16956 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16957
16958 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16959 _("register list must contain at least 1 and at most 16 "
16960 "registers"));
5287ad62
JB
16961
16962 inst.instruction |= inst.operands[0].reg << 16;
16963 inst.instruction |= inst.operands[0].writeback << 21;
16964 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16965 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16966
16967 inst.instruction |= offsetbits;
5f4273c7 16968
037e8744 16969 do_vfp_cond_or_thumb ();
5287ad62
JB
16970}
16971
16972static void
16973do_neon_ldr_str (void)
16974{
5287ad62 16975 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16976
6844b2c2
MGD
16977 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16978 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16979 if (!is_ldr
6844b2c2 16980 && inst.operands[1].reg == REG_PC
ba86b375 16981 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16982 {
94dcf8bf 16983 if (thumb_mode)
6844b2c2 16984 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16985 else if (warn_on_deprecated)
5c3696f8 16986 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16987 }
16988
037e8744
JB
16989 if (inst.operands[0].issingle)
16990 {
cd2f129f 16991 if (is_ldr)
477330fc 16992 do_vfp_nsyn_opcode ("flds");
cd2f129f 16993 else
477330fc 16994 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16995
16996 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16997 if (inst.vectype.el[0].size == 16)
16998 do_scalar_fp16_v82_encode ();
5287ad62
JB
16999 }
17000 else
5287ad62 17001 {
cd2f129f 17002 if (is_ldr)
477330fc 17003 do_vfp_nsyn_opcode ("fldd");
5287ad62 17004 else
477330fc 17005 do_vfp_nsyn_opcode ("fstd");
5287ad62 17006 }
5287ad62
JB
17007}
17008
17009/* "interleave" version also handles non-interleaving register VLD1/VST1
17010 instructions. */
17011
17012static void
17013do_neon_ld_st_interleave (void)
17014{
037e8744 17015 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 17016 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
17017 unsigned alignbits = 0;
17018 unsigned idx;
17019 /* The bits in this table go:
17020 0: register stride of one (0) or two (1)
17021 1,2: register list length, minus one (1, 2, 3, 4).
17022 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17023 We use -1 for invalid entries. */
17024 const int typetable[] =
17025 {
17026 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17027 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17028 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17029 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17030 };
17031 int typebits;
17032
dcbf9037
JB
17033 if (et.type == NT_invtype)
17034 return;
17035
5287ad62
JB
17036 if (inst.operands[1].immisalign)
17037 switch (inst.operands[1].imm >> 8)
17038 {
17039 case 64: alignbits = 1; break;
17040 case 128:
477330fc 17041 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 17042 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
17043 goto bad_alignment;
17044 alignbits = 2;
17045 break;
5287ad62 17046 case 256:
477330fc
RM
17047 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17048 goto bad_alignment;
17049 alignbits = 3;
17050 break;
5287ad62
JB
17051 default:
17052 bad_alignment:
477330fc
RM
17053 first_error (_("bad alignment"));
17054 return;
5287ad62
JB
17055 }
17056
17057 inst.instruction |= alignbits << 4;
17058 inst.instruction |= neon_logbits (et.size) << 6;
17059
17060 /* Bits [4:6] of the immediate in a list specifier encode register stride
17061 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17062 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17063 up the right value for "type" in a table based on this value and the given
17064 list style, then stick it back. */
17065 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17066 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17067
17068 typebits = typetable[idx];
5f4273c7 17069
5287ad62 17070 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17071 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17072 _("bad element type for instruction"));
5287ad62
JB
17073
17074 inst.instruction &= ~0xf00;
17075 inst.instruction |= typebits << 8;
17076}
17077
17078/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17079 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17080 otherwise. The variable arguments are a list of pairs of legal (size, align)
17081 values, terminated with -1. */
17082
17083static int
aa8a0863 17084neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17085{
17086 va_list ap;
17087 int result = FAIL, thissize, thisalign;
5f4273c7 17088
5287ad62
JB
17089 if (!inst.operands[1].immisalign)
17090 {
aa8a0863 17091 *do_alignment = 0;
5287ad62
JB
17092 return SUCCESS;
17093 }
5f4273c7 17094
aa8a0863 17095 va_start (ap, do_alignment);
5287ad62
JB
17096
17097 do
17098 {
17099 thissize = va_arg (ap, int);
17100 if (thissize == -1)
477330fc 17101 break;
5287ad62
JB
17102 thisalign = va_arg (ap, int);
17103
17104 if (size == thissize && align == thisalign)
477330fc 17105 result = SUCCESS;
5287ad62
JB
17106 }
17107 while (result != SUCCESS);
17108
17109 va_end (ap);
17110
17111 if (result == SUCCESS)
aa8a0863 17112 *do_alignment = 1;
5287ad62 17113 else
dcbf9037 17114 first_error (_("unsupported alignment for instruction"));
5f4273c7 17115
5287ad62
JB
17116 return result;
17117}
17118
17119static void
17120do_neon_ld_st_lane (void)
17121{
037e8744 17122 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17123 int align_good, do_alignment = 0;
5287ad62
JB
17124 int logsize = neon_logbits (et.size);
17125 int align = inst.operands[1].imm >> 8;
17126 int n = (inst.instruction >> 8) & 3;
17127 int max_el = 64 / et.size;
5f4273c7 17128
dcbf9037
JB
17129 if (et.type == NT_invtype)
17130 return;
5f4273c7 17131
5287ad62 17132 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17133 _("bad list length"));
5287ad62 17134 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17135 _("scalar index out of range"));
5287ad62 17136 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17137 && et.size == 8,
17138 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17139
5287ad62
JB
17140 switch (n)
17141 {
17142 case 0: /* VLD1 / VST1. */
aa8a0863 17143 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17144 32, 32, -1);
5287ad62 17145 if (align_good == FAIL)
477330fc 17146 return;
aa8a0863 17147 if (do_alignment)
477330fc
RM
17148 {
17149 unsigned alignbits = 0;
17150 switch (et.size)
17151 {
17152 case 16: alignbits = 0x1; break;
17153 case 32: alignbits = 0x3; break;
17154 default: ;
17155 }
17156 inst.instruction |= alignbits << 4;
17157 }
5287ad62
JB
17158 break;
17159
17160 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17161 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17162 16, 32, 32, 64, -1);
5287ad62 17163 if (align_good == FAIL)
477330fc 17164 return;
aa8a0863 17165 if (do_alignment)
477330fc 17166 inst.instruction |= 1 << 4;
5287ad62
JB
17167 break;
17168
17169 case 2: /* VLD3 / VST3. */
17170 constraint (inst.operands[1].immisalign,
477330fc 17171 _("can't use alignment with this instruction"));
5287ad62
JB
17172 break;
17173
17174 case 3: /* VLD4 / VST4. */
aa8a0863 17175 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17176 16, 64, 32, 64, 32, 128, -1);
5287ad62 17177 if (align_good == FAIL)
477330fc 17178 return;
aa8a0863 17179 if (do_alignment)
477330fc
RM
17180 {
17181 unsigned alignbits = 0;
17182 switch (et.size)
17183 {
17184 case 8: alignbits = 0x1; break;
17185 case 16: alignbits = 0x1; break;
17186 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17187 default: ;
17188 }
17189 inst.instruction |= alignbits << 4;
17190 }
5287ad62
JB
17191 break;
17192
17193 default: ;
17194 }
17195
17196 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17197 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17198 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17199
5287ad62
JB
17200 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17201 inst.instruction |= logsize << 10;
17202}
17203
17204/* Encode single n-element structure to all lanes VLD<n> instructions. */
17205
17206static void
17207do_neon_ld_dup (void)
17208{
037e8744 17209 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17210 int align_good, do_alignment = 0;
5287ad62 17211
dcbf9037
JB
17212 if (et.type == NT_invtype)
17213 return;
17214
5287ad62
JB
17215 switch ((inst.instruction >> 8) & 3)
17216 {
17217 case 0: /* VLD1. */
9c2799c2 17218 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17219 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17220 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17221 if (align_good == FAIL)
477330fc 17222 return;
5287ad62 17223 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17224 {
17225 case 1: break;
17226 case 2: inst.instruction |= 1 << 5; break;
17227 default: first_error (_("bad list length")); return;
17228 }
5287ad62
JB
17229 inst.instruction |= neon_logbits (et.size) << 6;
17230 break;
17231
17232 case 1: /* VLD2. */
17233 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17234 &do_alignment, 8, 16, 16, 32, 32, 64,
17235 -1);
5287ad62 17236 if (align_good == FAIL)
477330fc 17237 return;
5287ad62 17238 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17239 _("bad list length"));
5287ad62 17240 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17241 inst.instruction |= 1 << 5;
5287ad62
JB
17242 inst.instruction |= neon_logbits (et.size) << 6;
17243 break;
17244
17245 case 2: /* VLD3. */
17246 constraint (inst.operands[1].immisalign,
477330fc 17247 _("can't use alignment with this instruction"));
5287ad62 17248 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17249 _("bad list length"));
5287ad62 17250 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17251 inst.instruction |= 1 << 5;
5287ad62
JB
17252 inst.instruction |= neon_logbits (et.size) << 6;
17253 break;
17254
17255 case 3: /* VLD4. */
17256 {
477330fc 17257 int align = inst.operands[1].imm >> 8;
aa8a0863 17258 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17259 16, 64, 32, 64, 32, 128, -1);
17260 if (align_good == FAIL)
17261 return;
17262 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17263 _("bad list length"));
17264 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17265 inst.instruction |= 1 << 5;
17266 if (et.size == 32 && align == 128)
17267 inst.instruction |= 0x3 << 6;
17268 else
17269 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17270 }
17271 break;
17272
17273 default: ;
17274 }
17275
aa8a0863 17276 inst.instruction |= do_alignment << 4;
5287ad62
JB
17277}
17278
17279/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17280 apart from bits [11:4]. */
17281
17282static void
17283do_neon_ldx_stx (void)
17284{
b1a769ed
DG
17285 if (inst.operands[1].isreg)
17286 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17287
5287ad62
JB
17288 switch (NEON_LANE (inst.operands[0].imm))
17289 {
17290 case NEON_INTERLEAVE_LANES:
88714cb8 17291 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17292 do_neon_ld_st_interleave ();
17293 break;
5f4273c7 17294
5287ad62 17295 case NEON_ALL_LANES:
88714cb8 17296 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17297 if (inst.instruction == N_INV)
17298 {
17299 first_error ("only loads support such operands");
17300 break;
17301 }
5287ad62
JB
17302 do_neon_ld_dup ();
17303 break;
5f4273c7 17304
5287ad62 17305 default:
88714cb8 17306 NEON_ENCODE (LANE, inst);
5287ad62
JB
17307 do_neon_ld_st_lane ();
17308 }
17309
17310 /* L bit comes from bit mask. */
17311 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17312 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17313 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17314
5287ad62
JB
17315 if (inst.operands[1].postind)
17316 {
17317 int postreg = inst.operands[1].imm & 0xf;
17318 constraint (!inst.operands[1].immisreg,
477330fc 17319 _("post-index must be a register"));
5287ad62 17320 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17321 _("bad register for post-index"));
5287ad62
JB
17322 inst.instruction |= postreg;
17323 }
4f2374c7 17324 else
5287ad62 17325 {
4f2374c7
WN
17326 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17327 constraint (inst.reloc.exp.X_op != O_constant
17328 || inst.reloc.exp.X_add_number != 0,
17329 BAD_ADDR_MODE);
17330
17331 if (inst.operands[1].writeback)
17332 {
17333 inst.instruction |= 0xd;
17334 }
17335 else
17336 inst.instruction |= 0xf;
5287ad62 17337 }
5f4273c7 17338
5287ad62
JB
17339 if (thumb_mode)
17340 inst.instruction |= 0xf9000000;
17341 else
17342 inst.instruction |= 0xf4000000;
17343}
33399f07
MGD
17344
17345/* FP v8. */
17346static void
17347do_vfp_nsyn_fpv8 (enum neon_shape rs)
17348{
a715796b
TG
17349 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17350 D register operands. */
17351 if (neon_shape_class[rs] == SC_DOUBLE)
17352 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17353 _(BAD_FPU));
17354
33399f07
MGD
17355 NEON_ENCODE (FPV8, inst);
17356
9db2f6b4
RL
17357 if (rs == NS_FFF || rs == NS_HHH)
17358 {
17359 do_vfp_sp_dyadic ();
17360
17361 /* ARMv8.2 fp16 instruction. */
17362 if (rs == NS_HHH)
17363 do_scalar_fp16_v82_encode ();
17364 }
33399f07
MGD
17365 else
17366 do_vfp_dp_rd_rn_rm ();
17367
17368 if (rs == NS_DDD)
17369 inst.instruction |= 0x100;
17370
17371 inst.instruction |= 0xf0000000;
17372}
17373
17374static void
17375do_vsel (void)
17376{
17377 set_it_insn_type (OUTSIDE_IT_INSN);
17378
17379 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17380 first_error (_("invalid instruction shape"));
17381}
17382
73924fbc
MGD
17383static void
17384do_vmaxnm (void)
17385{
17386 set_it_insn_type (OUTSIDE_IT_INSN);
17387
17388 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17389 return;
17390
17391 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17392 return;
17393
cc933301 17394 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17395}
17396
30bdf752
MGD
17397static void
17398do_vrint_1 (enum neon_cvt_mode mode)
17399{
9db2f6b4 17400 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17401 struct neon_type_el et;
17402
17403 if (rs == NS_NULL)
17404 return;
17405
a715796b
TG
17406 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17407 D register operands. */
17408 if (neon_shape_class[rs] == SC_DOUBLE)
17409 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17410 _(BAD_FPU));
17411
9db2f6b4
RL
17412 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17413 | N_VFP);
30bdf752
MGD
17414 if (et.type != NT_invtype)
17415 {
17416 /* VFP encodings. */
17417 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17418 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17419 set_it_insn_type (OUTSIDE_IT_INSN);
17420
17421 NEON_ENCODE (FPV8, inst);
9db2f6b4 17422 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17423 do_vfp_sp_monadic ();
17424 else
17425 do_vfp_dp_rd_rm ();
17426
17427 switch (mode)
17428 {
17429 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17430 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17431 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17432 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17433 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17434 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17435 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17436 default: abort ();
17437 }
17438
17439 inst.instruction |= (rs == NS_DD) << 8;
17440 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17441
17442 /* ARMv8.2 fp16 vrint instruction. */
17443 if (rs == NS_HH)
17444 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17445 }
17446 else
17447 {
17448 /* Neon encodings (or something broken...). */
17449 inst.error = NULL;
cc933301 17450 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17451
17452 if (et.type == NT_invtype)
17453 return;
17454
17455 set_it_insn_type (OUTSIDE_IT_INSN);
17456 NEON_ENCODE (FLOAT, inst);
17457
17458 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17459 return;
17460
17461 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17462 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17463 inst.instruction |= LOW4 (inst.operands[1].reg);
17464 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17465 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17466 /* Mask off the original size bits and reencode them. */
17467 inst.instruction = ((inst.instruction & 0xfff3ffff)
17468 | neon_logbits (et.size) << 18);
17469
30bdf752
MGD
17470 switch (mode)
17471 {
17472 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17473 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17474 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17475 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17476 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17477 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17478 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17479 default: abort ();
17480 }
17481
17482 if (thumb_mode)
17483 inst.instruction |= 0xfc000000;
17484 else
17485 inst.instruction |= 0xf0000000;
17486 }
17487}
17488
17489static void
17490do_vrintx (void)
17491{
17492 do_vrint_1 (neon_cvt_mode_x);
17493}
17494
17495static void
17496do_vrintz (void)
17497{
17498 do_vrint_1 (neon_cvt_mode_z);
17499}
17500
17501static void
17502do_vrintr (void)
17503{
17504 do_vrint_1 (neon_cvt_mode_r);
17505}
17506
17507static void
17508do_vrinta (void)
17509{
17510 do_vrint_1 (neon_cvt_mode_a);
17511}
17512
17513static void
17514do_vrintn (void)
17515{
17516 do_vrint_1 (neon_cvt_mode_n);
17517}
17518
17519static void
17520do_vrintp (void)
17521{
17522 do_vrint_1 (neon_cvt_mode_p);
17523}
17524
17525static void
17526do_vrintm (void)
17527{
17528 do_vrint_1 (neon_cvt_mode_m);
17529}
17530
c28eeff2
SN
17531static unsigned
17532neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17533{
17534 unsigned regno = NEON_SCALAR_REG (opnd);
17535 unsigned elno = NEON_SCALAR_INDEX (opnd);
17536
17537 if (elsize == 16 && elno < 2 && regno < 16)
17538 return regno | (elno << 4);
17539 else if (elsize == 32 && elno == 0)
17540 return regno;
17541
17542 first_error (_("scalar out of range"));
17543 return 0;
17544}
17545
17546static void
17547do_vcmla (void)
17548{
17549 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17550 _(BAD_FPU));
17551 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17552 unsigned rot = inst.reloc.exp.X_add_number;
17553 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17554 _("immediate out of range"));
17555 rot /= 90;
17556 if (inst.operands[2].isscalar)
17557 {
17558 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17559 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17560 N_KEY | N_F16 | N_F32).size;
17561 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17562 inst.is_neon = 1;
17563 inst.instruction = 0xfe000800;
17564 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17565 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17566 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17567 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17568 inst.instruction |= LOW4 (m);
17569 inst.instruction |= HI1 (m) << 5;
17570 inst.instruction |= neon_quad (rs) << 6;
17571 inst.instruction |= rot << 20;
17572 inst.instruction |= (size == 32) << 23;
17573 }
17574 else
17575 {
17576 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17577 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17578 N_KEY | N_F16 | N_F32).size;
17579 neon_three_same (neon_quad (rs), 0, -1);
17580 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17581 inst.instruction |= 0xfc200800;
17582 inst.instruction |= rot << 23;
17583 inst.instruction |= (size == 32) << 20;
17584 }
17585}
17586
17587static void
17588do_vcadd (void)
17589{
17590 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17591 _(BAD_FPU));
17592 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17593 unsigned rot = inst.reloc.exp.X_add_number;
17594 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17595 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17596 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17597 N_KEY | N_F16 | N_F32).size;
17598 neon_three_same (neon_quad (rs), 0, -1);
17599 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17600 inst.instruction |= 0xfc800800;
17601 inst.instruction |= (rot == 270) << 24;
17602 inst.instruction |= (size == 32) << 20;
17603}
17604
c604a79a
JW
17605/* Dot Product instructions encoding support. */
17606
17607static void
17608do_neon_dotproduct (int unsigned_p)
17609{
17610 enum neon_shape rs;
17611 unsigned scalar_oprd2 = 0;
17612 int high8;
17613
17614 if (inst.cond != COND_ALWAYS)
17615 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17616 "is UNPREDICTABLE"));
17617
17618 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17619 _(BAD_FPU));
17620
17621 /* Dot Product instructions are in three-same D/Q register format or the third
17622 operand can be a scalar index register. */
17623 if (inst.operands[2].isscalar)
17624 {
17625 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17626 high8 = 0xfe000000;
17627 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17628 }
17629 else
17630 {
17631 high8 = 0xfc000000;
17632 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17633 }
17634
17635 if (unsigned_p)
17636 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17637 else
17638 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17639
17640 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17641 Product instruction, so we pass 0 as the "ubit" parameter. And the
17642 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17643 neon_three_same (neon_quad (rs), 0, 32);
17644
17645 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17646 different NEON three-same encoding. */
17647 inst.instruction &= 0x00ffffff;
17648 inst.instruction |= high8;
17649 /* Encode 'U' bit which indicates signedness. */
17650 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17651 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17652 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17653 the instruction encoding. */
17654 if (inst.operands[2].isscalar)
17655 {
17656 inst.instruction &= 0xffffffd0;
17657 inst.instruction |= LOW4 (scalar_oprd2);
17658 inst.instruction |= HI1 (scalar_oprd2) << 5;
17659 }
17660}
17661
17662/* Dot Product instructions for signed integer. */
17663
17664static void
17665do_neon_dotproduct_s (void)
17666{
17667 return do_neon_dotproduct (0);
17668}
17669
17670/* Dot Product instructions for unsigned integer. */
17671
17672static void
17673do_neon_dotproduct_u (void)
17674{
17675 return do_neon_dotproduct (1);
17676}
17677
91ff7894
MGD
17678/* Crypto v1 instructions. */
17679static void
17680do_crypto_2op_1 (unsigned elttype, int op)
17681{
17682 set_it_insn_type (OUTSIDE_IT_INSN);
17683
17684 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17685 == NT_invtype)
17686 return;
17687
17688 inst.error = NULL;
17689
17690 NEON_ENCODE (INTEGER, inst);
17691 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17692 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17693 inst.instruction |= LOW4 (inst.operands[1].reg);
17694 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17695 if (op != -1)
17696 inst.instruction |= op << 6;
17697
17698 if (thumb_mode)
17699 inst.instruction |= 0xfc000000;
17700 else
17701 inst.instruction |= 0xf0000000;
17702}
17703
48adcd8e
MGD
17704static void
17705do_crypto_3op_1 (int u, int op)
17706{
17707 set_it_insn_type (OUTSIDE_IT_INSN);
17708
17709 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17710 N_32 | N_UNT | N_KEY).type == NT_invtype)
17711 return;
17712
17713 inst.error = NULL;
17714
17715 NEON_ENCODE (INTEGER, inst);
17716 neon_three_same (1, u, 8 << op);
17717}
17718
91ff7894
MGD
17719static void
17720do_aese (void)
17721{
17722 do_crypto_2op_1 (N_8, 0);
17723}
17724
17725static void
17726do_aesd (void)
17727{
17728 do_crypto_2op_1 (N_8, 1);
17729}
17730
17731static void
17732do_aesmc (void)
17733{
17734 do_crypto_2op_1 (N_8, 2);
17735}
17736
17737static void
17738do_aesimc (void)
17739{
17740 do_crypto_2op_1 (N_8, 3);
17741}
17742
48adcd8e
MGD
17743static void
17744do_sha1c (void)
17745{
17746 do_crypto_3op_1 (0, 0);
17747}
17748
17749static void
17750do_sha1p (void)
17751{
17752 do_crypto_3op_1 (0, 1);
17753}
17754
17755static void
17756do_sha1m (void)
17757{
17758 do_crypto_3op_1 (0, 2);
17759}
17760
17761static void
17762do_sha1su0 (void)
17763{
17764 do_crypto_3op_1 (0, 3);
17765}
91ff7894 17766
48adcd8e
MGD
17767static void
17768do_sha256h (void)
17769{
17770 do_crypto_3op_1 (1, 0);
17771}
17772
17773static void
17774do_sha256h2 (void)
17775{
17776 do_crypto_3op_1 (1, 1);
17777}
17778
17779static void
17780do_sha256su1 (void)
17781{
17782 do_crypto_3op_1 (1, 2);
17783}
3c9017d2
MGD
17784
17785static void
17786do_sha1h (void)
17787{
17788 do_crypto_2op_1 (N_32, -1);
17789}
17790
17791static void
17792do_sha1su1 (void)
17793{
17794 do_crypto_2op_1 (N_32, 0);
17795}
17796
17797static void
17798do_sha256su0 (void)
17799{
17800 do_crypto_2op_1 (N_32, 1);
17801}
dd5181d5
KT
17802
17803static void
17804do_crc32_1 (unsigned int poly, unsigned int sz)
17805{
17806 unsigned int Rd = inst.operands[0].reg;
17807 unsigned int Rn = inst.operands[1].reg;
17808 unsigned int Rm = inst.operands[2].reg;
17809
17810 set_it_insn_type (OUTSIDE_IT_INSN);
17811 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17812 inst.instruction |= LOW4 (Rn) << 16;
17813 inst.instruction |= LOW4 (Rm);
17814 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17815 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17816
17817 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17818 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17819}
17820
17821static void
17822do_crc32b (void)
17823{
17824 do_crc32_1 (0, 0);
17825}
17826
17827static void
17828do_crc32h (void)
17829{
17830 do_crc32_1 (0, 1);
17831}
17832
17833static void
17834do_crc32w (void)
17835{
17836 do_crc32_1 (0, 2);
17837}
17838
17839static void
17840do_crc32cb (void)
17841{
17842 do_crc32_1 (1, 0);
17843}
17844
17845static void
17846do_crc32ch (void)
17847{
17848 do_crc32_1 (1, 1);
17849}
17850
17851static void
17852do_crc32cw (void)
17853{
17854 do_crc32_1 (1, 2);
17855}
17856
49e8a725
SN
17857static void
17858do_vjcvt (void)
17859{
17860 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17861 _(BAD_FPU));
17862 neon_check_type (2, NS_FD, N_S32, N_F64);
17863 do_vfp_sp_dp_cvt ();
17864 do_vfp_cond_or_thumb ();
17865}
17866
5287ad62
JB
17867\f
17868/* Overall per-instruction processing. */
17869
17870/* We need to be able to fix up arbitrary expressions in some statements.
17871 This is so that we can handle symbols that are an arbitrary distance from
17872 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17873 which returns part of an address in a form which will be valid for
17874 a data instruction. We do this by pushing the expression into a symbol
17875 in the expr_section, and creating a fix for that. */
17876
17877static void
17878fix_new_arm (fragS * frag,
17879 int where,
17880 short int size,
17881 expressionS * exp,
17882 int pc_rel,
17883 int reloc)
17884{
17885 fixS * new_fix;
17886
17887 switch (exp->X_op)
17888 {
17889 case O_constant:
6e7ce2cd
PB
17890 if (pc_rel)
17891 {
17892 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17893 refer to in the object file. Unfortunately for us, gas's
17894 generic expression parsing will already have folded out
17895 any use of .set foo/.type foo %function that may have
17896 been used to set type information of the target location,
17897 that's being specified symbolically. We have to presume
17898 the user knows what they are doing. */
6e7ce2cd
PB
17899 char name[16 + 8];
17900 symbolS *symbol;
17901
17902 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17903
17904 symbol = symbol_find_or_make (name);
17905 S_SET_SEGMENT (symbol, absolute_section);
17906 symbol_set_frag (symbol, &zero_address_frag);
17907 S_SET_VALUE (symbol, exp->X_add_number);
17908 exp->X_op = O_symbol;
17909 exp->X_add_symbol = symbol;
17910 exp->X_add_number = 0;
17911 }
17912 /* FALLTHROUGH */
5287ad62
JB
17913 case O_symbol:
17914 case O_add:
17915 case O_subtract:
21d799b5 17916 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17917 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17918 break;
17919
17920 default:
21d799b5 17921 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17922 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17923 break;
17924 }
17925
17926 /* Mark whether the fix is to a THUMB instruction, or an ARM
17927 instruction. */
17928 new_fix->tc_fix_data = thumb_mode;
17929}
17930
17931/* Create a frg for an instruction requiring relaxation. */
17932static void
17933output_relax_insn (void)
17934{
17935 char * to;
17936 symbolS *sym;
0110f2b8
PB
17937 int offset;
17938
6e1cb1a6
PB
17939 /* The size of the instruction is unknown, so tie the debug info to the
17940 start of the instruction. */
17941 dwarf2_emit_insn (0);
6e1cb1a6 17942
0110f2b8
PB
17943 switch (inst.reloc.exp.X_op)
17944 {
17945 case O_symbol:
17946 sym = inst.reloc.exp.X_add_symbol;
17947 offset = inst.reloc.exp.X_add_number;
17948 break;
17949 case O_constant:
17950 sym = NULL;
17951 offset = inst.reloc.exp.X_add_number;
17952 break;
17953 default:
17954 sym = make_expr_symbol (&inst.reloc.exp);
17955 offset = 0;
17956 break;
17957 }
17958 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17959 inst.relax, sym, offset, NULL/*offset, opcode*/);
17960 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17961}
17962
17963/* Write a 32-bit thumb instruction to buf. */
17964static void
17965put_thumb32_insn (char * buf, unsigned long insn)
17966{
17967 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17968 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17969}
17970
b99bd4ef 17971static void
c19d1205 17972output_inst (const char * str)
b99bd4ef 17973{
c19d1205 17974 char * to = NULL;
b99bd4ef 17975
c19d1205 17976 if (inst.error)
b99bd4ef 17977 {
c19d1205 17978 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17979 return;
17980 }
5f4273c7
NC
17981 if (inst.relax)
17982 {
17983 output_relax_insn ();
0110f2b8 17984 return;
5f4273c7 17985 }
c19d1205
ZW
17986 if (inst.size == 0)
17987 return;
b99bd4ef 17988
c19d1205 17989 to = frag_more (inst.size);
8dc2430f
NC
17990 /* PR 9814: Record the thumb mode into the current frag so that we know
17991 what type of NOP padding to use, if necessary. We override any previous
17992 setting so that if the mode has changed then the NOPS that we use will
17993 match the encoding of the last instruction in the frag. */
cd000bff 17994 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17995
17996 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17997 {
9c2799c2 17998 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17999 put_thumb32_insn (to, inst.instruction);
b99bd4ef 18000 }
c19d1205 18001 else if (inst.size > INSN_SIZE)
b99bd4ef 18002 {
9c2799c2 18003 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
18004 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18005 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 18006 }
c19d1205
ZW
18007 else
18008 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 18009
c19d1205
ZW
18010 if (inst.reloc.type != BFD_RELOC_UNUSED)
18011 fix_new_arm (frag_now, to - frag_now->fr_literal,
18012 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
18013 inst.reloc.type);
b99bd4ef 18014
c19d1205 18015 dwarf2_emit_insn (inst.size);
c19d1205 18016}
b99bd4ef 18017
e07e6e58
NC
18018static char *
18019output_it_inst (int cond, int mask, char * to)
18020{
18021 unsigned long instruction = 0xbf00;
18022
18023 mask &= 0xf;
18024 instruction |= mask;
18025 instruction |= cond << 4;
18026
18027 if (to == NULL)
18028 {
18029 to = frag_more (2);
18030#ifdef OBJ_ELF
18031 dwarf2_emit_insn (2);
18032#endif
18033 }
18034
18035 md_number_to_chars (to, instruction, 2);
18036
18037 return to;
18038}
18039
c19d1205
ZW
18040/* Tag values used in struct asm_opcode's tag field. */
18041enum opcode_tag
18042{
18043 OT_unconditional, /* Instruction cannot be conditionalized.
18044 The ARM condition field is still 0xE. */
18045 OT_unconditionalF, /* Instruction cannot be conditionalized
18046 and carries 0xF in its ARM condition field. */
18047 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 18048 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
18049 suffix, others place 0xF where the condition field
18050 would be. */
c19d1205
ZW
18051 OT_cinfix3, /* Instruction takes a conditional infix,
18052 beginning at character index 3. (In
18053 unified mode, it becomes a suffix.) */
088fa78e
KH
18054 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18055 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18056 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18057 character index 3, even in unified mode. Used for
18058 legacy instructions where suffix and infix forms
18059 may be ambiguous. */
c19d1205 18060 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18061 suffix or an infix at character index 3. */
c19d1205
ZW
18062 OT_odd_infix_unc, /* This is the unconditional variant of an
18063 instruction that takes a conditional infix
18064 at an unusual position. In unified mode,
18065 this variant will accept a suffix. */
18066 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18067 are the conditional variants of instructions that
18068 take conditional infixes in unusual positions.
18069 The infix appears at character index
18070 (tag - OT_odd_infix_0). These are not accepted
18071 in unified mode. */
18072};
b99bd4ef 18073
c19d1205
ZW
18074/* Subroutine of md_assemble, responsible for looking up the primary
18075 opcode from the mnemonic the user wrote. STR points to the
18076 beginning of the mnemonic.
18077
18078 This is not simply a hash table lookup, because of conditional
18079 variants. Most instructions have conditional variants, which are
18080 expressed with a _conditional affix_ to the mnemonic. If we were
18081 to encode each conditional variant as a literal string in the opcode
18082 table, it would have approximately 20,000 entries.
18083
18084 Most mnemonics take this affix as a suffix, and in unified syntax,
18085 'most' is upgraded to 'all'. However, in the divided syntax, some
18086 instructions take the affix as an infix, notably the s-variants of
18087 the arithmetic instructions. Of those instructions, all but six
18088 have the infix appear after the third character of the mnemonic.
18089
18090 Accordingly, the algorithm for looking up primary opcodes given
18091 an identifier is:
18092
18093 1. Look up the identifier in the opcode table.
18094 If we find a match, go to step U.
18095
18096 2. Look up the last two characters of the identifier in the
18097 conditions table. If we find a match, look up the first N-2
18098 characters of the identifier in the opcode table. If we
18099 find a match, go to step CE.
18100
18101 3. Look up the fourth and fifth characters of the identifier in
18102 the conditions table. If we find a match, extract those
18103 characters from the identifier, and look up the remaining
18104 characters in the opcode table. If we find a match, go
18105 to step CM.
18106
18107 4. Fail.
18108
18109 U. Examine the tag field of the opcode structure, in case this is
18110 one of the six instructions with its conditional infix in an
18111 unusual place. If it is, the tag tells us where to find the
18112 infix; look it up in the conditions table and set inst.cond
18113 accordingly. Otherwise, this is an unconditional instruction.
18114 Again set inst.cond accordingly. Return the opcode structure.
18115
18116 CE. Examine the tag field to make sure this is an instruction that
18117 should receive a conditional suffix. If it is not, fail.
18118 Otherwise, set inst.cond from the suffix we already looked up,
18119 and return the opcode structure.
18120
18121 CM. Examine the tag field to make sure this is an instruction that
18122 should receive a conditional infix after the third character.
18123 If it is not, fail. Otherwise, undo the edits to the current
18124 line of input and proceed as for case CE. */
18125
18126static const struct asm_opcode *
18127opcode_lookup (char **str)
18128{
18129 char *end, *base;
18130 char *affix;
18131 const struct asm_opcode *opcode;
18132 const struct asm_cond *cond;
e3cb604e 18133 char save[2];
c19d1205
ZW
18134
18135 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18136 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18137 for (base = end = *str; *end != '\0'; end++)
721a8186 18138 if (*end == ' ' || *end == '.')
c19d1205 18139 break;
b99bd4ef 18140
c19d1205 18141 if (end == base)
c921be7d 18142 return NULL;
b99bd4ef 18143
5287ad62 18144 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18145 if (end[0] == '.')
b99bd4ef 18146 {
5287ad62 18147 int offset = 2;
5f4273c7 18148
267d2029 18149 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18150 use. */
267d2029 18151 if (unified_syntax && end[1] == 'w')
c19d1205 18152 inst.size_req = 4;
267d2029 18153 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18154 inst.size_req = 2;
18155 else
477330fc 18156 offset = 0;
5287ad62
JB
18157
18158 inst.vectype.elems = 0;
18159
18160 *str = end + offset;
b99bd4ef 18161
5f4273c7 18162 if (end[offset] == '.')
5287ad62 18163 {
267d2029 18164 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18165 non-unified ARM syntax mode). */
18166 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18167 return NULL;
477330fc 18168 }
5287ad62 18169 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18170 return NULL;
b99bd4ef 18171 }
c19d1205
ZW
18172 else
18173 *str = end;
b99bd4ef 18174
c19d1205 18175 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18176 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18177 end - base);
c19d1205 18178 if (opcode)
b99bd4ef 18179 {
c19d1205
ZW
18180 /* step U */
18181 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18182 {
c19d1205
ZW
18183 inst.cond = COND_ALWAYS;
18184 return opcode;
b99bd4ef 18185 }
b99bd4ef 18186
278df34e 18187 if (warn_on_deprecated && unified_syntax)
5c3696f8 18188 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18189 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18190 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18191 gas_assert (cond);
b99bd4ef 18192
c19d1205
ZW
18193 inst.cond = cond->value;
18194 return opcode;
18195 }
b99bd4ef 18196
c19d1205
ZW
18197 /* Cannot have a conditional suffix on a mnemonic of less than two
18198 characters. */
18199 if (end - base < 3)
c921be7d 18200 return NULL;
b99bd4ef 18201
c19d1205
ZW
18202 /* Look for suffixed mnemonic. */
18203 affix = end - 2;
21d799b5
NC
18204 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18205 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18206 affix - base);
c19d1205
ZW
18207 if (opcode && cond)
18208 {
18209 /* step CE */
18210 switch (opcode->tag)
18211 {
e3cb604e
PB
18212 case OT_cinfix3_legacy:
18213 /* Ignore conditional suffixes matched on infix only mnemonics. */
18214 break;
18215
c19d1205 18216 case OT_cinfix3:
088fa78e 18217 case OT_cinfix3_deprecated:
c19d1205
ZW
18218 case OT_odd_infix_unc:
18219 if (!unified_syntax)
0198d5e6 18220 return NULL;
1a0670f3 18221 /* Fall through. */
c19d1205
ZW
18222
18223 case OT_csuffix:
477330fc 18224 case OT_csuffixF:
c19d1205
ZW
18225 case OT_csuf_or_in3:
18226 inst.cond = cond->value;
18227 return opcode;
18228
18229 case OT_unconditional:
18230 case OT_unconditionalF:
dfa9f0d5 18231 if (thumb_mode)
c921be7d 18232 inst.cond = cond->value;
dfa9f0d5
PB
18233 else
18234 {
c921be7d 18235 /* Delayed diagnostic. */
dfa9f0d5
PB
18236 inst.error = BAD_COND;
18237 inst.cond = COND_ALWAYS;
18238 }
c19d1205 18239 return opcode;
b99bd4ef 18240
c19d1205 18241 default:
c921be7d 18242 return NULL;
c19d1205
ZW
18243 }
18244 }
b99bd4ef 18245
c19d1205
ZW
18246 /* Cannot have a usual-position infix on a mnemonic of less than
18247 six characters (five would be a suffix). */
18248 if (end - base < 6)
c921be7d 18249 return NULL;
b99bd4ef 18250
c19d1205
ZW
18251 /* Look for infixed mnemonic in the usual position. */
18252 affix = base + 3;
21d799b5 18253 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18254 if (!cond)
c921be7d 18255 return NULL;
e3cb604e
PB
18256
18257 memcpy (save, affix, 2);
18258 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18259 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18260 (end - base) - 2);
e3cb604e
PB
18261 memmove (affix + 2, affix, (end - affix) - 2);
18262 memcpy (affix, save, 2);
18263
088fa78e
KH
18264 if (opcode
18265 && (opcode->tag == OT_cinfix3
18266 || opcode->tag == OT_cinfix3_deprecated
18267 || opcode->tag == OT_csuf_or_in3
18268 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18269 {
c921be7d 18270 /* Step CM. */
278df34e 18271 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18272 && (opcode->tag == OT_cinfix3
18273 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18274 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18275
18276 inst.cond = cond->value;
18277 return opcode;
b99bd4ef
NC
18278 }
18279
c921be7d 18280 return NULL;
b99bd4ef
NC
18281}
18282
e07e6e58
NC
18283/* This function generates an initial IT instruction, leaving its block
18284 virtually open for the new instructions. Eventually,
18285 the mask will be updated by now_it_add_mask () each time
18286 a new instruction needs to be included in the IT block.
18287 Finally, the block is closed with close_automatic_it_block ().
18288 The block closure can be requested either from md_assemble (),
18289 a tencode (), or due to a label hook. */
18290
18291static void
18292new_automatic_it_block (int cond)
18293{
18294 now_it.state = AUTOMATIC_IT_BLOCK;
18295 now_it.mask = 0x18;
18296 now_it.cc = cond;
18297 now_it.block_length = 1;
cd000bff 18298 mapping_state (MAP_THUMB);
e07e6e58 18299 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18300 now_it.warn_deprecated = FALSE;
18301 now_it.insn_cond = TRUE;
e07e6e58
NC
18302}
18303
18304/* Close an automatic IT block.
18305 See comments in new_automatic_it_block (). */
18306
18307static void
18308close_automatic_it_block (void)
18309{
18310 now_it.mask = 0x10;
18311 now_it.block_length = 0;
18312}
18313
18314/* Update the mask of the current automatically-generated IT
18315 instruction. See comments in new_automatic_it_block (). */
18316
18317static void
18318now_it_add_mask (int cond)
18319{
18320#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18321#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18322 | ((bitvalue) << (nbit)))
e07e6e58 18323 const int resulting_bit = (cond & 1);
c921be7d 18324
e07e6e58
NC
18325 now_it.mask &= 0xf;
18326 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18327 resulting_bit,
18328 (5 - now_it.block_length));
e07e6e58 18329 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18330 1,
18331 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18332 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18333
18334#undef CLEAR_BIT
18335#undef SET_BIT_VALUE
e07e6e58
NC
18336}
18337
18338/* The IT blocks handling machinery is accessed through the these functions:
18339 it_fsm_pre_encode () from md_assemble ()
18340 set_it_insn_type () optional, from the tencode functions
18341 set_it_insn_type_last () ditto
18342 in_it_block () ditto
18343 it_fsm_post_encode () from md_assemble ()
33eaf5de 18344 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18345
18346 Rationale:
18347 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18348 initializing the IT insn type with a generic initial value depending
18349 on the inst.condition.
e07e6e58 18350 2) During the tencode function, two things may happen:
477330fc
RM
18351 a) The tencode function overrides the IT insn type by
18352 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18353 b) The tencode function queries the IT block state by
18354 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18355
18356 Both set_it_insn_type and in_it_block run the internal FSM state
18357 handling function (handle_it_state), because: a) setting the IT insn
18358 type may incur in an invalid state (exiting the function),
18359 and b) querying the state requires the FSM to be updated.
18360 Specifically we want to avoid creating an IT block for conditional
18361 branches, so it_fsm_pre_encode is actually a guess and we can't
18362 determine whether an IT block is required until the tencode () routine
18363 has decided what type of instruction this actually it.
18364 Because of this, if set_it_insn_type and in_it_block have to be used,
18365 set_it_insn_type has to be called first.
18366
18367 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18368 determines the insn IT type depending on the inst.cond code.
18369 When a tencode () routine encodes an instruction that can be
18370 either outside an IT block, or, in the case of being inside, has to be
18371 the last one, set_it_insn_type_last () will determine the proper
18372 IT instruction type based on the inst.cond code. Otherwise,
18373 set_it_insn_type can be called for overriding that logic or
18374 for covering other cases.
18375
18376 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18377 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18378 still queried. Instead, if the FSM determines that the state should
18379 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18380 after the tencode () function: that's what it_fsm_post_encode () does.
18381
18382 Since in_it_block () calls the state handling function to get an
18383 updated state, an error may occur (due to invalid insns combination).
18384 In that case, inst.error is set.
18385 Therefore, inst.error has to be checked after the execution of
18386 the tencode () routine.
e07e6e58
NC
18387
18388 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18389 any pending state change (if any) that didn't take place in
18390 handle_it_state () as explained above. */
e07e6e58
NC
18391
18392static void
18393it_fsm_pre_encode (void)
18394{
18395 if (inst.cond != COND_ALWAYS)
18396 inst.it_insn_type = INSIDE_IT_INSN;
18397 else
18398 inst.it_insn_type = OUTSIDE_IT_INSN;
18399
18400 now_it.state_handled = 0;
18401}
18402
18403/* IT state FSM handling function. */
18404
18405static int
18406handle_it_state (void)
18407{
18408 now_it.state_handled = 1;
5a01bb1d 18409 now_it.insn_cond = FALSE;
e07e6e58
NC
18410
18411 switch (now_it.state)
18412 {
18413 case OUTSIDE_IT_BLOCK:
18414 switch (inst.it_insn_type)
18415 {
18416 case OUTSIDE_IT_INSN:
18417 break;
18418
18419 case INSIDE_IT_INSN:
18420 case INSIDE_IT_LAST_INSN:
18421 if (thumb_mode == 0)
18422 {
c921be7d 18423 if (unified_syntax
e07e6e58
NC
18424 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18425 as_tsktsk (_("Warning: conditional outside an IT block"\
18426 " for Thumb."));
18427 }
18428 else
18429 {
18430 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18431 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18432 {
18433 /* Automatically generate the IT instruction. */
18434 new_automatic_it_block (inst.cond);
18435 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18436 close_automatic_it_block ();
18437 }
18438 else
18439 {
18440 inst.error = BAD_OUT_IT;
18441 return FAIL;
18442 }
18443 }
18444 break;
18445
18446 case IF_INSIDE_IT_LAST_INSN:
18447 case NEUTRAL_IT_INSN:
18448 break;
18449
18450 case IT_INSN:
18451 now_it.state = MANUAL_IT_BLOCK;
18452 now_it.block_length = 0;
18453 break;
18454 }
18455 break;
18456
18457 case AUTOMATIC_IT_BLOCK:
18458 /* Three things may happen now:
18459 a) We should increment current it block size;
18460 b) We should close current it block (closing insn or 4 insns);
18461 c) We should close current it block and start a new one (due
18462 to incompatible conditions or
18463 4 insns-length block reached). */
18464
18465 switch (inst.it_insn_type)
18466 {
18467 case OUTSIDE_IT_INSN:
2b0f3761 18468 /* The closure of the block shall happen immediately,
e07e6e58
NC
18469 so any in_it_block () call reports the block as closed. */
18470 force_automatic_it_block_close ();
18471 break;
18472
18473 case INSIDE_IT_INSN:
18474 case INSIDE_IT_LAST_INSN:
18475 case IF_INSIDE_IT_LAST_INSN:
18476 now_it.block_length++;
18477
18478 if (now_it.block_length > 4
18479 || !now_it_compatible (inst.cond))
18480 {
18481 force_automatic_it_block_close ();
18482 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18483 new_automatic_it_block (inst.cond);
18484 }
18485 else
18486 {
5a01bb1d 18487 now_it.insn_cond = TRUE;
e07e6e58
NC
18488 now_it_add_mask (inst.cond);
18489 }
18490
18491 if (now_it.state == AUTOMATIC_IT_BLOCK
18492 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18493 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18494 close_automatic_it_block ();
18495 break;
18496
18497 case NEUTRAL_IT_INSN:
18498 now_it.block_length++;
5a01bb1d 18499 now_it.insn_cond = TRUE;
e07e6e58
NC
18500
18501 if (now_it.block_length > 4)
18502 force_automatic_it_block_close ();
18503 else
18504 now_it_add_mask (now_it.cc & 1);
18505 break;
18506
18507 case IT_INSN:
18508 close_automatic_it_block ();
18509 now_it.state = MANUAL_IT_BLOCK;
18510 break;
18511 }
18512 break;
18513
18514 case MANUAL_IT_BLOCK:
18515 {
18516 /* Check conditional suffixes. */
18517 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18518 int is_last;
18519 now_it.mask <<= 1;
18520 now_it.mask &= 0x1f;
18521 is_last = (now_it.mask == 0x10);
5a01bb1d 18522 now_it.insn_cond = TRUE;
e07e6e58
NC
18523
18524 switch (inst.it_insn_type)
18525 {
18526 case OUTSIDE_IT_INSN:
18527 inst.error = BAD_NOT_IT;
18528 return FAIL;
18529
18530 case INSIDE_IT_INSN:
18531 if (cond != inst.cond)
18532 {
18533 inst.error = BAD_IT_COND;
18534 return FAIL;
18535 }
18536 break;
18537
18538 case INSIDE_IT_LAST_INSN:
18539 case IF_INSIDE_IT_LAST_INSN:
18540 if (cond != inst.cond)
18541 {
18542 inst.error = BAD_IT_COND;
18543 return FAIL;
18544 }
18545 if (!is_last)
18546 {
18547 inst.error = BAD_BRANCH;
18548 return FAIL;
18549 }
18550 break;
18551
18552 case NEUTRAL_IT_INSN:
18553 /* The BKPT instruction is unconditional even in an IT block. */
18554 break;
18555
18556 case IT_INSN:
18557 inst.error = BAD_IT_IT;
18558 return FAIL;
18559 }
18560 }
18561 break;
18562 }
18563
18564 return SUCCESS;
18565}
18566
5a01bb1d
MGD
18567struct depr_insn_mask
18568{
18569 unsigned long pattern;
18570 unsigned long mask;
18571 const char* description;
18572};
18573
18574/* List of 16-bit instruction patterns deprecated in an IT block in
18575 ARMv8. */
18576static const struct depr_insn_mask depr_it_insns[] = {
18577 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18578 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18579 { 0xa000, 0xb800, N_("ADR") },
18580 { 0x4800, 0xf800, N_("Literal loads") },
18581 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18582 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18583 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18584 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18585 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18586 { 0, 0, NULL }
18587};
18588
e07e6e58
NC
18589static void
18590it_fsm_post_encode (void)
18591{
18592 int is_last;
18593
18594 if (!now_it.state_handled)
18595 handle_it_state ();
18596
5a01bb1d
MGD
18597 if (now_it.insn_cond
18598 && !now_it.warn_deprecated
18599 && warn_on_deprecated
df9909b8
TP
18600 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18601 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
5a01bb1d
MGD
18602 {
18603 if (inst.instruction >= 0x10000)
18604 {
5c3696f8 18605 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
df9909b8 18606 "performance deprecated in ARMv8-A and ARMv8-R"));
5a01bb1d
MGD
18607 now_it.warn_deprecated = TRUE;
18608 }
18609 else
18610 {
18611 const struct depr_insn_mask *p = depr_it_insns;
18612
18613 while (p->mask != 0)
18614 {
18615 if ((inst.instruction & p->mask) == p->pattern)
18616 {
df9909b8
TP
18617 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18618 "instructions of the following class are "
18619 "performance deprecated in ARMv8-A and "
18620 "ARMv8-R: %s"), p->description);
5a01bb1d
MGD
18621 now_it.warn_deprecated = TRUE;
18622 break;
18623 }
18624
18625 ++p;
18626 }
18627 }
18628
18629 if (now_it.block_length > 1)
18630 {
5c3696f8 18631 as_tsktsk (_("IT blocks containing more than one conditional "
df9909b8
TP
18632 "instruction are performance deprecated in ARMv8-A and "
18633 "ARMv8-R"));
5a01bb1d
MGD
18634 now_it.warn_deprecated = TRUE;
18635 }
18636 }
18637
e07e6e58
NC
18638 is_last = (now_it.mask == 0x10);
18639 if (is_last)
18640 {
18641 now_it.state = OUTSIDE_IT_BLOCK;
18642 now_it.mask = 0;
18643 }
18644}
18645
18646static void
18647force_automatic_it_block_close (void)
18648{
18649 if (now_it.state == AUTOMATIC_IT_BLOCK)
18650 {
18651 close_automatic_it_block ();
18652 now_it.state = OUTSIDE_IT_BLOCK;
18653 now_it.mask = 0;
18654 }
18655}
18656
18657static int
18658in_it_block (void)
18659{
18660 if (!now_it.state_handled)
18661 handle_it_state ();
18662
18663 return now_it.state != OUTSIDE_IT_BLOCK;
18664}
18665
ff8646ee
TP
18666/* Whether OPCODE only has T32 encoding. Since this function is only used by
18667 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18668 here, hence the "known" in the function name. */
fc289b0a
TP
18669
18670static bfd_boolean
ff8646ee 18671known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18672{
18673 /* Original Thumb-1 wide instruction. */
18674 if (opcode->tencode == do_t_blx
18675 || opcode->tencode == do_t_branch23
18676 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18677 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18678 return TRUE;
18679
16a1fa25
TP
18680 /* Wide-only instruction added to ARMv8-M Baseline. */
18681 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18682 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18683 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18684 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18685 return TRUE;
18686
18687 return FALSE;
18688}
18689
18690/* Whether wide instruction variant can be used if available for a valid OPCODE
18691 in ARCH. */
18692
18693static bfd_boolean
18694t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18695{
18696 if (known_t32_only_insn (opcode))
18697 return TRUE;
18698
18699 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18700 of variant T3 of B.W is checked in do_t_branch. */
18701 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18702 && opcode->tencode == do_t_branch)
18703 return TRUE;
18704
bada4342
JW
18705 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18706 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18707 && opcode->tencode == do_t_mov_cmp
18708 /* Make sure CMP instruction is not affected. */
18709 && opcode->aencode == do_mov)
18710 return TRUE;
18711
ff8646ee
TP
18712 /* Wide instruction variants of all instructions with narrow *and* wide
18713 variants become available with ARMv6t2. Other opcodes are either
18714 narrow-only or wide-only and are thus available if OPCODE is valid. */
18715 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18716 return TRUE;
18717
18718 /* OPCODE with narrow only instruction variant or wide variant not
18719 available. */
fc289b0a
TP
18720 return FALSE;
18721}
18722
c19d1205
ZW
18723void
18724md_assemble (char *str)
b99bd4ef 18725{
c19d1205
ZW
18726 char *p = str;
18727 const struct asm_opcode * opcode;
b99bd4ef 18728
c19d1205
ZW
18729 /* Align the previous label if needed. */
18730 if (last_label_seen != NULL)
b99bd4ef 18731 {
c19d1205
ZW
18732 symbol_set_frag (last_label_seen, frag_now);
18733 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18734 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18735 }
18736
c19d1205
ZW
18737 memset (&inst, '\0', sizeof (inst));
18738 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18739
c19d1205
ZW
18740 opcode = opcode_lookup (&p);
18741 if (!opcode)
b99bd4ef 18742 {
c19d1205 18743 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18744 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18745 if (! create_register_alias (str, p)
477330fc 18746 && ! create_neon_reg_alias (str, p))
c19d1205 18747 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18748
b99bd4ef
NC
18749 return;
18750 }
18751
278df34e 18752 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18753 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18754
037e8744
JB
18755 /* The value which unconditional instructions should have in place of the
18756 condition field. */
18757 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18758
c19d1205 18759 if (thumb_mode)
b99bd4ef 18760 {
e74cfd16 18761 arm_feature_set variant;
8f06b2d8
PB
18762
18763 variant = cpu_variant;
18764 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18765 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18766 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18767 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18768 if (!opcode->tvariant
18769 || (thumb_mode == 1
18770 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18771 {
173205ca
TP
18772 if (opcode->tencode == do_t_swi)
18773 as_bad (_("SVC is not permitted on this architecture"));
18774 else
18775 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18776 return;
18777 }
c19d1205
ZW
18778 if (inst.cond != COND_ALWAYS && !unified_syntax
18779 && opcode->tencode != do_t_branch)
b99bd4ef 18780 {
c19d1205 18781 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18782 return;
18783 }
18784
fc289b0a
TP
18785 /* Two things are addressed here:
18786 1) Implicit require narrow instructions on Thumb-1.
18787 This avoids relaxation accidentally introducing Thumb-2
18788 instructions.
18789 2) Reject wide instructions in non Thumb-2 cores.
18790
18791 Only instructions with narrow and wide variants need to be handled
18792 but selecting all non wide-only instructions is easier. */
18793 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18794 && !t32_insn_ok (variant, opcode))
076d447c 18795 {
fc289b0a
TP
18796 if (inst.size_req == 0)
18797 inst.size_req = 2;
18798 else if (inst.size_req == 4)
752d5da4 18799 {
ff8646ee
TP
18800 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18801 as_bad (_("selected processor does not support 32bit wide "
18802 "variant of instruction `%s'"), str);
18803 else
18804 as_bad (_("selected processor does not support `%s' in "
18805 "Thumb-2 mode"), str);
fc289b0a 18806 return;
752d5da4 18807 }
076d447c
PB
18808 }
18809
c19d1205
ZW
18810 inst.instruction = opcode->tvalue;
18811
5be8be5d 18812 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18813 {
18814 /* Prepare the it_insn_type for those encodings that don't set
18815 it. */
18816 it_fsm_pre_encode ();
c19d1205 18817
477330fc 18818 opcode->tencode ();
e07e6e58 18819
477330fc
RM
18820 it_fsm_post_encode ();
18821 }
e27ec89e 18822
0110f2b8 18823 if (!(inst.error || inst.relax))
b99bd4ef 18824 {
9c2799c2 18825 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18826 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18827 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18828 {
c19d1205 18829 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18830 return;
18831 }
18832 }
076d447c
PB
18833
18834 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18835 instruction. */
9c2799c2 18836 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18837
e74cfd16
PB
18838 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18839 *opcode->tvariant);
ee065d83 18840 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18841 set those bits when Thumb-2 32-bit instructions are seen. The impact
18842 of relaxable instructions will be considered later after we finish all
18843 relaxation. */
ff8646ee
TP
18844 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18845 variant = arm_arch_none;
18846 else
18847 variant = cpu_variant;
18848 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18849 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18850 arm_ext_v6t2);
cd000bff 18851
88714cb8
DG
18852 check_neon_suffixes;
18853
cd000bff 18854 if (!inst.error)
c877a2f2
NC
18855 {
18856 mapping_state (MAP_THUMB);
18857 }
c19d1205 18858 }
3e9e4fcf 18859 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18860 {
845b51d6
PB
18861 bfd_boolean is_bx;
18862
18863 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18864 is_bx = (opcode->aencode == do_bx);
18865
c19d1205 18866 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18867 if (!(is_bx && fix_v4bx)
18868 && !(opcode->avariant &&
18869 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18870 {
84b52b66 18871 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18872 return;
b99bd4ef 18873 }
c19d1205 18874 if (inst.size_req)
b99bd4ef 18875 {
c19d1205
ZW
18876 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18877 return;
b99bd4ef
NC
18878 }
18879
c19d1205
ZW
18880 inst.instruction = opcode->avalue;
18881 if (opcode->tag == OT_unconditionalF)
eff0bc54 18882 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18883 else
18884 inst.instruction |= inst.cond << 28;
18885 inst.size = INSN_SIZE;
5be8be5d 18886 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18887 {
18888 it_fsm_pre_encode ();
18889 opcode->aencode ();
18890 it_fsm_post_encode ();
18891 }
ee065d83 18892 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18893 on a hypothetical non-thumb v5 core. */
845b51d6 18894 if (is_bx)
e74cfd16 18895 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18896 else
e74cfd16
PB
18897 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18898 *opcode->avariant);
88714cb8
DG
18899
18900 check_neon_suffixes;
18901
cd000bff 18902 if (!inst.error)
c877a2f2
NC
18903 {
18904 mapping_state (MAP_ARM);
18905 }
b99bd4ef 18906 }
3e9e4fcf
JB
18907 else
18908 {
18909 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18910 "-- `%s'"), str);
18911 return;
18912 }
c19d1205
ZW
18913 output_inst (str);
18914}
b99bd4ef 18915
e07e6e58
NC
18916static void
18917check_it_blocks_finished (void)
18918{
18919#ifdef OBJ_ELF
18920 asection *sect;
18921
18922 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18923 if (seg_info (sect)->tc_segment_info_data.current_it.state
18924 == MANUAL_IT_BLOCK)
18925 {
18926 as_warn (_("section '%s' finished with an open IT block."),
18927 sect->name);
18928 }
18929#else
18930 if (now_it.state == MANUAL_IT_BLOCK)
18931 as_warn (_("file finished with an open IT block."));
18932#endif
18933}
18934
c19d1205
ZW
18935/* Various frobbings of labels and their addresses. */
18936
18937void
18938arm_start_line_hook (void)
18939{
18940 last_label_seen = NULL;
b99bd4ef
NC
18941}
18942
c19d1205
ZW
18943void
18944arm_frob_label (symbolS * sym)
b99bd4ef 18945{
c19d1205 18946 last_label_seen = sym;
b99bd4ef 18947
c19d1205 18948 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18949
c19d1205
ZW
18950#if defined OBJ_COFF || defined OBJ_ELF
18951 ARM_SET_INTERWORK (sym, support_interwork);
18952#endif
b99bd4ef 18953
e07e6e58
NC
18954 force_automatic_it_block_close ();
18955
5f4273c7 18956 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18957 as Thumb functions. This is because these labels, whilst
18958 they exist inside Thumb code, are not the entry points for
18959 possible ARM->Thumb calls. Also, these labels can be used
18960 as part of a computed goto or switch statement. eg gcc
18961 can generate code that looks like this:
b99bd4ef 18962
c19d1205
ZW
18963 ldr r2, [pc, .Laaa]
18964 lsl r3, r3, #2
18965 ldr r2, [r3, r2]
18966 mov pc, r2
b99bd4ef 18967
c19d1205
ZW
18968 .Lbbb: .word .Lxxx
18969 .Lccc: .word .Lyyy
18970 ..etc...
18971 .Laaa: .word Lbbb
b99bd4ef 18972
c19d1205
ZW
18973 The first instruction loads the address of the jump table.
18974 The second instruction converts a table index into a byte offset.
18975 The third instruction gets the jump address out of the table.
18976 The fourth instruction performs the jump.
b99bd4ef 18977
c19d1205
ZW
18978 If the address stored at .Laaa is that of a symbol which has the
18979 Thumb_Func bit set, then the linker will arrange for this address
18980 to have the bottom bit set, which in turn would mean that the
18981 address computation performed by the third instruction would end
18982 up with the bottom bit set. Since the ARM is capable of unaligned
18983 word loads, the instruction would then load the incorrect address
18984 out of the jump table, and chaos would ensue. */
18985 if (label_is_thumb_function_name
18986 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18987 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18988 {
c19d1205
ZW
18989 /* When the address of a Thumb function is taken the bottom
18990 bit of that address should be set. This will allow
18991 interworking between Arm and Thumb functions to work
18992 correctly. */
b99bd4ef 18993
c19d1205 18994 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18995
c19d1205 18996 label_is_thumb_function_name = FALSE;
b99bd4ef 18997 }
07a53e5c 18998
07a53e5c 18999 dwarf2_emit_label (sym);
b99bd4ef
NC
19000}
19001
c921be7d 19002bfd_boolean
c19d1205 19003arm_data_in_code (void)
b99bd4ef 19004{
c19d1205 19005 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 19006 {
c19d1205
ZW
19007 *input_line_pointer = '/';
19008 input_line_pointer += 5;
19009 *input_line_pointer = 0;
c921be7d 19010 return TRUE;
b99bd4ef
NC
19011 }
19012
c921be7d 19013 return FALSE;
b99bd4ef
NC
19014}
19015
c19d1205
ZW
19016char *
19017arm_canonicalize_symbol_name (char * name)
b99bd4ef 19018{
c19d1205 19019 int len;
b99bd4ef 19020
c19d1205
ZW
19021 if (thumb_mode && (len = strlen (name)) > 5
19022 && streq (name + len - 5, "/data"))
19023 *(name + len - 5) = 0;
b99bd4ef 19024
c19d1205 19025 return name;
b99bd4ef 19026}
c19d1205
ZW
19027\f
19028/* Table of all register names defined by default. The user can
19029 define additional names with .req. Note that all register names
19030 should appear in both upper and lowercase variants. Some registers
19031 also have mixed-case names. */
b99bd4ef 19032
dcbf9037 19033#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 19034#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 19035#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
19036#define REGSET(p,t) \
19037 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19038 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19039 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19040 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
19041#define REGSETH(p,t) \
19042 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19043 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19044 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19045 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19046#define REGSET2(p,t) \
19047 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19048 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19049 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19050 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
19051#define SPLRBANK(base,bank,t) \
19052 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19053 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19054 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19055 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19056 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19057 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19058
c19d1205 19059static const struct reg_entry reg_names[] =
7ed4c4c5 19060{
c19d1205
ZW
19061 /* ARM integer registers. */
19062 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19063
c19d1205
ZW
19064 /* ATPCS synonyms. */
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 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19070 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19071 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19072
c19d1205
ZW
19073 /* Well-known aliases. */
19074 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19075 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19076
19077 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19078 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19079
19080 /* Coprocessor numbers. */
19081 REGSET(p, CP), REGSET(P, CP),
19082
19083 /* Coprocessor register numbers. The "cr" variants are for backward
19084 compatibility. */
19085 REGSET(c, CN), REGSET(C, CN),
19086 REGSET(cr, CN), REGSET(CR, CN),
19087
90ec0d68
MGD
19088 /* ARM banked registers. */
19089 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19090 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19091 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19092 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19093 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19094 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19095 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19096
19097 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19098 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19099 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19100 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19101 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19102 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19103 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19104 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19105
19106 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19107 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19108 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19109 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19110 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19111 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19112 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19113 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19114 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19115
c19d1205
ZW
19116 /* FPA registers. */
19117 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19118 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19119
19120 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19121 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19122
19123 /* VFP SP registers. */
5287ad62
JB
19124 REGSET(s,VFS), REGSET(S,VFS),
19125 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19126
19127 /* VFP DP Registers. */
5287ad62
JB
19128 REGSET(d,VFD), REGSET(D,VFD),
19129 /* Extra Neon DP registers. */
19130 REGSETH(d,VFD), REGSETH(D,VFD),
19131
19132 /* Neon QP registers. */
19133 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19134
19135 /* VFP control registers. */
19136 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19137 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19138 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19139 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19140 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19141 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19142 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19143
19144 /* Maverick DSP coprocessor registers. */
19145 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19146 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
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 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19153 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19154 REGDEF(DSPSC,0,DSPSC),
19155
19156 /* iWMMXt data registers - p0, c0-15. */
19157 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19158
19159 /* iWMMXt control registers - p1, c0-3. */
19160 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19161 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19162 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19163 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19164
19165 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19166 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19167 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19168 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19169 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19170
19171 /* XScale accumulator registers. */
19172 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19173};
19174#undef REGDEF
19175#undef REGNUM
19176#undef REGSET
7ed4c4c5 19177
c19d1205
ZW
19178/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19179 within psr_required_here. */
19180static const struct asm_psr psrs[] =
19181{
19182 /* Backward compatibility notation. Note that "all" is no longer
19183 truly all possible PSR bits. */
19184 {"all", PSR_c | PSR_f},
19185 {"flg", PSR_f},
19186 {"ctl", PSR_c},
19187
19188 /* Individual flags. */
19189 {"f", PSR_f},
19190 {"c", PSR_c},
19191 {"x", PSR_x},
19192 {"s", PSR_s},
59b42a0d 19193
c19d1205
ZW
19194 /* Combinations of flags. */
19195 {"fs", PSR_f | PSR_s},
19196 {"fx", PSR_f | PSR_x},
19197 {"fc", PSR_f | PSR_c},
19198 {"sf", PSR_s | PSR_f},
19199 {"sx", PSR_s | PSR_x},
19200 {"sc", PSR_s | PSR_c},
19201 {"xf", PSR_x | PSR_f},
19202 {"xs", PSR_x | PSR_s},
19203 {"xc", PSR_x | PSR_c},
19204 {"cf", PSR_c | PSR_f},
19205 {"cs", PSR_c | PSR_s},
19206 {"cx", PSR_c | PSR_x},
19207 {"fsx", PSR_f | PSR_s | PSR_x},
19208 {"fsc", PSR_f | PSR_s | PSR_c},
19209 {"fxs", PSR_f | PSR_x | PSR_s},
19210 {"fxc", PSR_f | PSR_x | PSR_c},
19211 {"fcs", PSR_f | PSR_c | PSR_s},
19212 {"fcx", PSR_f | PSR_c | PSR_x},
19213 {"sfx", PSR_s | PSR_f | PSR_x},
19214 {"sfc", PSR_s | PSR_f | PSR_c},
19215 {"sxf", PSR_s | PSR_x | PSR_f},
19216 {"sxc", PSR_s | PSR_x | PSR_c},
19217 {"scf", PSR_s | PSR_c | PSR_f},
19218 {"scx", PSR_s | PSR_c | PSR_x},
19219 {"xfs", PSR_x | PSR_f | PSR_s},
19220 {"xfc", PSR_x | PSR_f | PSR_c},
19221 {"xsf", PSR_x | PSR_s | PSR_f},
19222 {"xsc", PSR_x | PSR_s | PSR_c},
19223 {"xcf", PSR_x | PSR_c | PSR_f},
19224 {"xcs", PSR_x | PSR_c | PSR_s},
19225 {"cfs", PSR_c | PSR_f | PSR_s},
19226 {"cfx", PSR_c | PSR_f | PSR_x},
19227 {"csf", PSR_c | PSR_s | PSR_f},
19228 {"csx", PSR_c | PSR_s | PSR_x},
19229 {"cxf", PSR_c | PSR_x | PSR_f},
19230 {"cxs", PSR_c | PSR_x | PSR_s},
19231 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19232 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19233 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19234 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19235 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19236 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19237 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19238 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19239 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19240 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19241 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19242 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19243 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19244 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19245 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19246 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19247 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19248 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19249 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19250 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19251 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19252 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19253 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19254 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19255};
19256
62b3e311
PB
19257/* Table of V7M psr names. */
19258static const struct asm_psr v7m_psrs[] =
19259{
1a336194
TP
19260 {"apsr", 0x0 }, {"APSR", 0x0 },
19261 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19262 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19263 {"psr", 0x3 }, {"PSR", 0x3 },
19264 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19265 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19266 {"epsr", 0x6 }, {"EPSR", 0x6 },
19267 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19268 {"msp", 0x8 }, {"MSP", 0x8 },
19269 {"psp", 0x9 }, {"PSP", 0x9 },
19270 {"msplim", 0xa }, {"MSPLIM", 0xa },
19271 {"psplim", 0xb }, {"PSPLIM", 0xb },
19272 {"primask", 0x10}, {"PRIMASK", 0x10},
19273 {"basepri", 0x11}, {"BASEPRI", 0x11},
19274 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19275 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19276 {"control", 0x14}, {"CONTROL", 0x14},
19277 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19278 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19279 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19280 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19281 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19282 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19283 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19284 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19285 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19286};
19287
c19d1205
ZW
19288/* Table of all shift-in-operand names. */
19289static const struct asm_shift_name shift_names [] =
b99bd4ef 19290{
c19d1205
ZW
19291 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19292 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19293 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19294 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19295 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19296 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19297};
b99bd4ef 19298
c19d1205
ZW
19299/* Table of all explicit relocation names. */
19300#ifdef OBJ_ELF
19301static struct reloc_entry reloc_names[] =
19302{
19303 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19304 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19305 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19306 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19307 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19308 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19309 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19310 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19311 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19312 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19313 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19314 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19315 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19316 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19317 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19318 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19319 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19320 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19321};
19322#endif
b99bd4ef 19323
c19d1205
ZW
19324/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19325static const struct asm_cond conds[] =
19326{
19327 {"eq", 0x0},
19328 {"ne", 0x1},
19329 {"cs", 0x2}, {"hs", 0x2},
19330 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19331 {"mi", 0x4},
19332 {"pl", 0x5},
19333 {"vs", 0x6},
19334 {"vc", 0x7},
19335 {"hi", 0x8},
19336 {"ls", 0x9},
19337 {"ge", 0xa},
19338 {"lt", 0xb},
19339 {"gt", 0xc},
19340 {"le", 0xd},
19341 {"al", 0xe}
19342};
bfae80f2 19343
e797f7e0 19344#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19345 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19346 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19347
62b3e311
PB
19348static struct asm_barrier_opt barrier_opt_names[] =
19349{
e797f7e0
MGD
19350 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19351 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19352 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19353 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19354 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19355 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19356 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19357 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19358 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19359 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19360 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19361 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19362 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19363 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19364 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19365 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19366};
19367
e797f7e0
MGD
19368#undef UL_BARRIER
19369
c19d1205
ZW
19370/* Table of ARM-format instructions. */
19371
19372/* Macros for gluing together operand strings. N.B. In all cases
19373 other than OPS0, the trailing OP_stop comes from default
19374 zero-initialization of the unspecified elements of the array. */
19375#define OPS0() { OP_stop, }
19376#define OPS1(a) { OP_##a, }
19377#define OPS2(a,b) { OP_##a,OP_##b, }
19378#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19379#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19380#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19381#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19382
5be8be5d
DG
19383/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19384 This is useful when mixing operands for ARM and THUMB, i.e. using the
19385 MIX_ARM_THUMB_OPERANDS macro.
19386 In order to use these macros, prefix the number of operands with _
19387 e.g. _3. */
19388#define OPS_1(a) { a, }
19389#define OPS_2(a,b) { a,b, }
19390#define OPS_3(a,b,c) { a,b,c, }
19391#define OPS_4(a,b,c,d) { a,b,c,d, }
19392#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19393#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19394
c19d1205
ZW
19395/* These macros abstract out the exact format of the mnemonic table and
19396 save some repeated characters. */
19397
19398/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19399#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19400 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19401 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19402
19403/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19404 a T_MNEM_xyz enumerator. */
19405#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19406 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19407#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19408 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19409
19410/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19411 infix after the third character. */
19412#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19413 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19414 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19415#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19416 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19417 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19418#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19419 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19420#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19421 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19422#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19423 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19424#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19425 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19426
c19d1205 19427/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19428 field is still 0xE. Many of the Thumb variants can be executed
19429 conditionally, so this is checked separately. */
c19d1205 19430#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19431 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19432 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19433
dd5181d5
KT
19434/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19435 Used by mnemonics that have very minimal differences in the encoding for
19436 ARM and Thumb variants and can be handled in a common function. */
19437#define TUEc(mnem, op, top, nops, ops, en) \
19438 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19439 THUMB_VARIANT, do_##en, do_##en }
19440
c19d1205
ZW
19441/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19442 condition code field. */
19443#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19444 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19445 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19446
19447/* ARM-only variants of all the above. */
6a86118a 19448#define CE(mnem, op, nops, ops, ae) \
21d799b5 19449 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19450
19451#define C3(mnem, op, nops, ops, ae) \
19452 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19453
cf3cf39d
TP
19454/* Thumb-only variants of TCE and TUE. */
19455#define ToC(mnem, top, nops, ops, te) \
19456 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19457 do_##te }
cf3cf39d
TP
19458
19459#define ToU(mnem, top, nops, ops, te) \
19460 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19461 NULL, do_##te }
cf3cf39d 19462
e3cb604e
PB
19463/* Legacy mnemonics that always have conditional infix after the third
19464 character. */
19465#define CL(mnem, op, nops, ops, ae) \
21d799b5 19466 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19467 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19468
8f06b2d8
PB
19469/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19470#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19471 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19472
e3cb604e
PB
19473/* Legacy coprocessor instructions where conditional infix and conditional
19474 suffix are ambiguous. For consistency this includes all FPA instructions,
19475 not just the potentially ambiguous ones. */
19476#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19477 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19478 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19479
19480/* Coprocessor, takes either a suffix or a position-3 infix
19481 (for an FPA corner case). */
19482#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19483 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19484 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19485
6a86118a 19486#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19487 { m1 #m2 m3, OPS##nops ops, \
19488 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19489 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19490
19491#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19492 xCM_ (m1, , m2, op, nops, ops, ae), \
19493 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19494 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19495 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19496 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19497 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19498 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19499 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19500 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19501 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19502 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19503 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19504 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19505 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19506 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19507 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19508 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19509 xCM_ (m1, le, m2, op, nops, ops, ae), \
19510 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19511
19512#define UE(mnem, op, nops, ops, ae) \
19513 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19514
19515#define UF(mnem, op, nops, ops, ae) \
19516 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19517
5287ad62
JB
19518/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19519 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19520 use the same encoding function for each. */
19521#define NUF(mnem, op, nops, ops, enc) \
19522 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19523 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19524
19525/* Neon data processing, version which indirects through neon_enc_tab for
19526 the various overloaded versions of opcodes. */
19527#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19528 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19529 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19530
19531/* Neon insn with conditional suffix for the ARM version, non-overloaded
19532 version. */
037e8744
JB
19533#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19534 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19535 THUMB_VARIANT, do_##enc, do_##enc }
19536
037e8744 19537#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19538 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19539
19540#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19541 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19542
5287ad62 19543/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19544#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19545 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19546 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19547
037e8744 19548#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19549 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19550
19551#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19552 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19553
c19d1205
ZW
19554#define do_0 0
19555
c19d1205 19556static const struct asm_opcode insns[] =
bfae80f2 19557{
74db7efb
NC
19558#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19559#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19560 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19561 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19562 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19563 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19564 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19565 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19566 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19567 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19568 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19569 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19570 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19571 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19572 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19573 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19574 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19575 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19576
19577 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19578 for setting PSR flag bits. They are obsolete in V6 and do not
19579 have Thumb equivalents. */
21d799b5
NC
19580 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19581 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19582 CL("tstp", 110f000, 2, (RR, SH), cmp),
19583 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19584 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19585 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19586 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19587 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19588 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19589
19590 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19591 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19592 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19593 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19594
19595 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19596 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19597 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19598 OP_RRnpc),
19599 OP_ADDRGLDR),ldst, t_ldst),
19600 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19601
19602 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19603 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19604 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19605 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19606 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19607 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19608
21d799b5
NC
19609 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19610 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19611
c19d1205 19612 /* Pseudo ops. */
21d799b5 19613 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19614 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19615 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19616 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19617
19618 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19619 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19620 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19621 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19622 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19623 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19624 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19625 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19626 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19627 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19628 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19629 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19630 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19631
16a4cf17 19632 /* These may simplify to neg. */
21d799b5
NC
19633 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19634 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19635
173205ca
TP
19636#undef THUMB_VARIANT
19637#define THUMB_VARIANT & arm_ext_os
19638
19639 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19640 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19641
c921be7d
NC
19642#undef THUMB_VARIANT
19643#define THUMB_VARIANT & arm_ext_v6
19644
21d799b5 19645 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19646
19647 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19648#undef THUMB_VARIANT
19649#define THUMB_VARIANT & arm_ext_v6t2
19650
21d799b5
NC
19651 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19652 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19653 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19654
5be8be5d
DG
19655 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19656 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19657 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19658 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19659
21d799b5
NC
19660 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19661 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19662
21d799b5
NC
19663 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19664 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19665
19666 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19667 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19668 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19669
19670 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19671 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19672 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19673 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19674 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19675 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19676 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19677 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19678
c921be7d
NC
19679#undef ARM_VARIANT
19680#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19681#undef THUMB_VARIANT
19682#define THUMB_VARIANT & arm_ext_v4t
19683
21d799b5
NC
19684 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19685 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19686
c921be7d
NC
19687#undef THUMB_VARIANT
19688#define THUMB_VARIANT & arm_ext_v6t2
19689
21d799b5 19690 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19691 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19692
19693 /* Generic coprocessor instructions. */
21d799b5
NC
19694 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19695 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19696 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19697 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19698 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19699 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19700 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19701
c921be7d
NC
19702#undef ARM_VARIANT
19703#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19704
21d799b5 19705 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19706 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19707
c921be7d
NC
19708#undef ARM_VARIANT
19709#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19710#undef THUMB_VARIANT
19711#define THUMB_VARIANT & arm_ext_msr
19712
d2cd1205
JB
19713 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19714 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19715
c921be7d
NC
19716#undef ARM_VARIANT
19717#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19718#undef THUMB_VARIANT
19719#define THUMB_VARIANT & arm_ext_v6t2
19720
21d799b5
NC
19721 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19722 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19723 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19724 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19725 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19726 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19727 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19728 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19729
c921be7d
NC
19730#undef ARM_VARIANT
19731#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19732#undef THUMB_VARIANT
19733#define THUMB_VARIANT & arm_ext_v4t
19734
5be8be5d
DG
19735 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19736 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19737 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19738 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19739 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19740 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19741
c921be7d
NC
19742#undef ARM_VARIANT
19743#define ARM_VARIANT & arm_ext_v4t_5
19744
c19d1205
ZW
19745 /* ARM Architecture 4T. */
19746 /* Note: bx (and blx) are required on V5, even if the processor does
19747 not support Thumb. */
21d799b5 19748 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19749
c921be7d
NC
19750#undef ARM_VARIANT
19751#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19752#undef THUMB_VARIANT
19753#define THUMB_VARIANT & arm_ext_v5t
19754
c19d1205
ZW
19755 /* Note: blx has 2 variants; the .value coded here is for
19756 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19757 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19758 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19759
c921be7d
NC
19760#undef THUMB_VARIANT
19761#define THUMB_VARIANT & arm_ext_v6t2
19762
21d799b5
NC
19763 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19764 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19765 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19766 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19767 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19768 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19769 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19770 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19771
c921be7d 19772#undef ARM_VARIANT
74db7efb
NC
19773#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19774#undef THUMB_VARIANT
19775#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19776
21d799b5
NC
19777 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19778 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19779 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19780 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19781
21d799b5
NC
19782 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19783 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19784
21d799b5
NC
19785 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19786 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19787 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19788 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19789
21d799b5
NC
19790 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19791 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19792 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19793 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19794
21d799b5
NC
19795 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19796 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19797
03ee1b7f
NC
19798 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19799 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19800 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19801 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19802
c921be7d 19803#undef ARM_VARIANT
74db7efb
NC
19804#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19805#undef THUMB_VARIANT
19806#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19807
21d799b5 19808 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19809 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19810 ldrd, t_ldstd),
19811 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19812 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19813
21d799b5
NC
19814 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19815 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19816
c921be7d
NC
19817#undef ARM_VARIANT
19818#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19819
21d799b5 19820 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19821
c921be7d
NC
19822#undef ARM_VARIANT
19823#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19824#undef THUMB_VARIANT
19825#define THUMB_VARIANT & arm_ext_v6
19826
21d799b5
NC
19827 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19828 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19829 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19830 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19831 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19832 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19833 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19834 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19835 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19836 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19837
c921be7d 19838#undef THUMB_VARIANT
ff8646ee 19839#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19840
5be8be5d
DG
19841 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19842 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19843 strex, t_strex),
ff8646ee
TP
19844#undef THUMB_VARIANT
19845#define THUMB_VARIANT & arm_ext_v6t2
19846
21d799b5
NC
19847 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19848 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19849
21d799b5
NC
19850 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19851 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19852
9e3c6df6 19853/* ARM V6 not included in V7M. */
c921be7d
NC
19854#undef THUMB_VARIANT
19855#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19856 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19857 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19858 UF(rfeib, 9900a00, 1, (RRw), rfe),
19859 UF(rfeda, 8100a00, 1, (RRw), rfe),
19860 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19861 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19862 UF(rfefa, 8100a00, 1, (RRw), rfe),
19863 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19864 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19865 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19866 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19867 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19868 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19869 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19870 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19871 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19872 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19873 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19874 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19875
9e3c6df6
PB
19876/* ARM V6 not included in V7M (eg. integer SIMD). */
19877#undef THUMB_VARIANT
19878#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19879 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19880 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19881 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19882 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19883 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19884 /* Old name for QASX. */
74db7efb 19885 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19886 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19887 /* Old name for QSAX. */
74db7efb 19888 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19889 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19890 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19891 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19892 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19893 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19894 /* Old name for SASX. */
74db7efb 19895 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19896 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19897 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19898 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19899 /* Old name for SHASX. */
21d799b5 19900 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19901 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19902 /* Old name for SHSAX. */
21d799b5
NC
19903 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19904 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19905 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19906 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19907 /* Old name for SSAX. */
74db7efb 19908 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19909 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19910 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19911 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19912 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19913 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19914 /* Old name for UASX. */
74db7efb 19915 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19916 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19917 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19918 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19919 /* Old name for UHASX. */
21d799b5
NC
19920 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19921 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19922 /* Old name for UHSAX. */
21d799b5
NC
19923 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19924 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19925 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19926 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19927 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19928 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19929 /* Old name for UQASX. */
21d799b5
NC
19930 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19931 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19932 /* Old name for UQSAX. */
21d799b5
NC
19933 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19934 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19935 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19936 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19937 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19938 /* Old name for USAX. */
74db7efb 19939 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19940 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19941 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19942 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19943 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19944 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19945 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19946 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19947 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19948 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19949 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19950 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19951 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19952 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19953 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19954 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19955 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19956 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19957 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19958 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19959 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19960 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19961 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19962 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19963 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19964 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19965 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19966 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19967 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19968 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19969 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19970 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19971 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19972 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19973
c921be7d
NC
19974#undef ARM_VARIANT
19975#define ARM_VARIANT & arm_ext_v6k
19976#undef THUMB_VARIANT
19977#define THUMB_VARIANT & arm_ext_v6k
19978
21d799b5
NC
19979 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19980 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19981 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19982 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19983
c921be7d
NC
19984#undef THUMB_VARIANT
19985#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19986 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19987 ldrexd, t_ldrexd),
19988 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19989 RRnpcb), strexd, t_strexd),
ebdca51a 19990
c921be7d 19991#undef THUMB_VARIANT
ff8646ee 19992#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19993 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19994 rd_rn, rd_rn),
19995 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19996 rd_rn, rd_rn),
19997 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19998 strex, t_strexbh),
5be8be5d 19999 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 20000 strex, t_strexbh),
21d799b5 20001 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 20002
c921be7d 20003#undef ARM_VARIANT
f4c65163 20004#define ARM_VARIANT & arm_ext_sec
74db7efb 20005#undef THUMB_VARIANT
f4c65163 20006#define THUMB_VARIANT & arm_ext_sec
c921be7d 20007
21d799b5 20008 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 20009
90ec0d68
MGD
20010#undef ARM_VARIANT
20011#define ARM_VARIANT & arm_ext_virt
20012#undef THUMB_VARIANT
20013#define THUMB_VARIANT & arm_ext_virt
20014
20015 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20016 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20017
ddfded2f
MW
20018#undef ARM_VARIANT
20019#define ARM_VARIANT & arm_ext_pan
20020#undef THUMB_VARIANT
20021#define THUMB_VARIANT & arm_ext_pan
20022
20023 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20024
c921be7d 20025#undef ARM_VARIANT
74db7efb 20026#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
20027#undef THUMB_VARIANT
20028#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20029
21d799b5
NC
20030 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20031 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20032 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20033 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 20034
21d799b5 20035 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 20036 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 20037
5be8be5d
DG
20038 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20039 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20040 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20041 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 20042
91d8b670
JG
20043#undef ARM_VARIANT
20044#define ARM_VARIANT & arm_ext_v3
20045#undef THUMB_VARIANT
20046#define THUMB_VARIANT & arm_ext_v6t2
20047
20048 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
20049
20050#undef ARM_VARIANT
20051#define ARM_VARIANT & arm_ext_v6t2
ff8646ee
TP
20052#undef THUMB_VARIANT
20053#define THUMB_VARIANT & arm_ext_v6t2_v8m
20054 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20055 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20056
bf3eeda7 20057 /* Thumb-only instructions. */
74db7efb 20058#undef ARM_VARIANT
bf3eeda7
NS
20059#define ARM_VARIANT NULL
20060 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20061 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
20062
20063 /* ARM does not really have an IT instruction, so always allow it.
20064 The opcode is copied from Thumb in order to allow warnings in
20065 -mimplicit-it=[never | arm] modes. */
20066#undef ARM_VARIANT
20067#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
20068#undef THUMB_VARIANT
20069#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 20070
21d799b5
NC
20071 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20072 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20073 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20074 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20075 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20076 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20077 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20078 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20079 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20080 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20081 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20082 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20083 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20084 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20085 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20086 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20087 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20088 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20089
92e90b6e 20090 /* Thumb2 only instructions. */
c921be7d
NC
20091#undef ARM_VARIANT
20092#define ARM_VARIANT NULL
92e90b6e 20093
21d799b5
NC
20094 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20095 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20096 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20097 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20098 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20099 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20100
eea54501
MGD
20101 /* Hardware division instructions. */
20102#undef ARM_VARIANT
20103#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20104#undef THUMB_VARIANT
20105#define THUMB_VARIANT & arm_ext_div
20106
eea54501
MGD
20107 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20108 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20109
7e806470 20110 /* ARM V6M/V7 instructions. */
c921be7d
NC
20111#undef ARM_VARIANT
20112#define ARM_VARIANT & arm_ext_barrier
20113#undef THUMB_VARIANT
20114#define THUMB_VARIANT & arm_ext_barrier
20115
ccb84d65
JB
20116 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20117 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20118 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20119
62b3e311 20120 /* ARM V7 instructions. */
c921be7d
NC
20121#undef ARM_VARIANT
20122#define ARM_VARIANT & arm_ext_v7
20123#undef THUMB_VARIANT
20124#define THUMB_VARIANT & arm_ext_v7
20125
21d799b5
NC
20126 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20127 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20128
74db7efb 20129#undef ARM_VARIANT
60e5ef9f 20130#define ARM_VARIANT & arm_ext_mp
74db7efb 20131#undef THUMB_VARIANT
60e5ef9f
MGD
20132#define THUMB_VARIANT & arm_ext_mp
20133
20134 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20135
53c4b28b
MGD
20136 /* AArchv8 instructions. */
20137#undef ARM_VARIANT
20138#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20139
20140/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20141#undef THUMB_VARIANT
4ed7ed8d 20142#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20143
4ed7ed8d
TP
20144 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20145 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20146 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20147 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20148 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20149 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20150 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20151 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20152 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20153 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20154 stlex, t_stlex),
4b8c8c02
RE
20155 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20156 stlex, t_stlex),
20157 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20158 stlex, t_stlex),
4ed7ed8d
TP
20159#undef THUMB_VARIANT
20160#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20161
4ed7ed8d
TP
20162 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
20163 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20164 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20165 ldrexd, t_ldrexd),
20166 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20167 strexd, t_strexd),
8884b720 20168 /* ARMv8 T32 only. */
74db7efb 20169#undef ARM_VARIANT
b79f7053
MGD
20170#define ARM_VARIANT NULL
20171 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20172 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20173 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20174
33399f07
MGD
20175 /* FP for ARMv8. */
20176#undef ARM_VARIANT
a715796b 20177#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20178#undef THUMB_VARIANT
a715796b 20179#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20180
20181 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20182 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20183 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20184 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20185 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20186 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20187 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20188 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20189 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20190 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20191 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20192 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20193 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20194 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20195 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20196 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20197 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20198
91ff7894
MGD
20199 /* Crypto v1 extensions. */
20200#undef ARM_VARIANT
20201#define ARM_VARIANT & fpu_crypto_ext_armv8
20202#undef THUMB_VARIANT
20203#define THUMB_VARIANT & fpu_crypto_ext_armv8
20204
20205 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20206 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20207 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20208 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20209 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20210 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20211 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20212 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20213 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20214 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20215 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20216 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20217 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20218 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20219
dd5181d5 20220#undef ARM_VARIANT
74db7efb 20221#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20222#undef THUMB_VARIANT
20223#define THUMB_VARIANT & crc_ext_armv8
20224 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20225 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20226 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20227 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20228 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20229 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20230
105bde57
MW
20231 /* ARMv8.2 RAS extension. */
20232#undef ARM_VARIANT
4d1464f2 20233#define ARM_VARIANT & arm_ext_ras
105bde57 20234#undef THUMB_VARIANT
4d1464f2 20235#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20236 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20237
49e8a725
SN
20238#undef ARM_VARIANT
20239#define ARM_VARIANT & arm_ext_v8_3
20240#undef THUMB_VARIANT
20241#define THUMB_VARIANT & arm_ext_v8_3
20242 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20243 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20244 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20245
c604a79a
JW
20246#undef ARM_VARIANT
20247#define ARM_VARIANT & fpu_neon_ext_dotprod
20248#undef THUMB_VARIANT
20249#define THUMB_VARIANT & fpu_neon_ext_dotprod
20250 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20251 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20252
c921be7d
NC
20253#undef ARM_VARIANT
20254#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20255#undef THUMB_VARIANT
20256#define THUMB_VARIANT NULL
c921be7d 20257
21d799b5
NC
20258 cCE("wfs", e200110, 1, (RR), rd),
20259 cCE("rfs", e300110, 1, (RR), rd),
20260 cCE("wfc", e400110, 1, (RR), rd),
20261 cCE("rfc", e500110, 1, (RR), rd),
20262
20263 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20264 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20265 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20266 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20267
20268 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20269 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20270 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20271 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20272
20273 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20274 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20275 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20276 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20277 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20278 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20279 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20280 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20281 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20282 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20283 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20284 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20285
20286 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20287 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20288 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20289 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20290 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20291 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20292 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20293 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20294 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20295 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20296 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20297 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20298
20299 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20300 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20301 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20302 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20303 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20304 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20305 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20306 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20307 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20308 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20309 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20310 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20311
20312 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20313 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20314 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20315 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20316 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20317 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20318 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20319 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20320 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20321 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20322 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20323 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20324
20325 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20326 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20327 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20328 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20329 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20330 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20331 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20332 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20333 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20334 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20335 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20336 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20337
20338 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20339 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20340 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20341 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20342 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20343 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20344 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20345 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20346 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20347 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20348 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20349 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20350
20351 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20352 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20353 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20354 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20355 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20356 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20357 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20358 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20359 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20360 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20361 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20362 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20363
20364 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20365 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20366 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20367 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20368 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20369 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20370 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20371 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20372 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20373 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20374 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20375 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20376
20377 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20378 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20379 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20380 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20381 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20382 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20383 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20384 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20385 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20386 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20387 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20388 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20389
20390 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20391 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20392 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20393 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20394 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20395 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20396 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20397 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20398 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20399 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20400 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20401 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20402
20403 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20404 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20405 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20406 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20407 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20408 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20409 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20410 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20411 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20412 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20413 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20414 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20415
20416 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20417 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20418 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20419 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20420 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20421 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20422 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20423 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20424 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20425 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20426 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20427 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20428
20429 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20430 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20431 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20432 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20433 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20434 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20435 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20436 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20437 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20438 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20439 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20440 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20441
20442 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20443 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20444 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20445 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20446 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20447 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20448 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20449 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20450 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20451 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20452 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20453 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20454
20455 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20456 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20457 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20458 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20459 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20460 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20461 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20462 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20463 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20464 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20465 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20466 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20467
20468 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20469 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20470 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20471 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20472 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20473 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20474 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20475 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20476 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20477 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20478 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20479 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20480
20481 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20482 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20483 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20484 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20485 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20486 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20487 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20488 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20489 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20490 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20491 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20492 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20493
20494 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20495 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20496 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20497 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20498 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20499 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20500 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20501 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20502 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20503 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20504 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20505 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20506
20507 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20508 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20509 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20510 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20511 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20512 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20513 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20514 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20515 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20516 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20517 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20518 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20519
20520 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20521 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20522 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20523 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20524 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20525 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20526 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20527 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20528 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20529 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20530 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20531 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20532
20533 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20534 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20535 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20536 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20537 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20538 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20539 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20540 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20541 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20542 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20543 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20544 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20545
20546 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20547 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20548 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20549 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20550 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20551 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20552 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20553 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20554 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20555 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20556 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20557 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20558
20559 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20560 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20561 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20562 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20563 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20564 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20565 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20566 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20567 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20568 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20569 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20570 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20571
20572 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20574 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20575 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20576 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20577 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20578 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20579 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20580 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20581 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20582 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20583 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20584
20585 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20586 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20587 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20588 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20589 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20590 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20591 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20592 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20593 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20594 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20595 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20596 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20597
20598 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20599 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20600 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20601 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20602 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20603 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20604 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20605 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20606 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20607 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20608 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20609 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20610
20611 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20612 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20613 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20614 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20615 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20616 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20617 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20618 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20619 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20620 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20621 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20622 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20623
20624 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20625 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20626 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20627 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20628 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20629 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20630 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20631 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20632 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20633 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20634 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20635 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20636
20637 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20638 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20639 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20640 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20641 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20642 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20643 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20644 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20645 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20646 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20647 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20648 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20649
20650 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20651 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20652 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20653 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20654
20655 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20656 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20657 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20658 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20659 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20660 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20661 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20662 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20663 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20664 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20665 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20666 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20667
c19d1205
ZW
20668 /* The implementation of the FIX instruction is broken on some
20669 assemblers, in that it accepts a precision specifier as well as a
20670 rounding specifier, despite the fact that this is meaningless.
20671 To be more compatible, we accept it as well, though of course it
20672 does not set any bits. */
21d799b5
NC
20673 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20674 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20675 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20676 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20677 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20678 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20679 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20680 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20681 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20682 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20683 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20684 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20685 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20686
c19d1205 20687 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20688#undef ARM_VARIANT
20689#define ARM_VARIANT & fpu_fpa_ext_v2
20690
21d799b5
NC
20691 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20692 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20693 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20694 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20695 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20696 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20697
c921be7d
NC
20698#undef ARM_VARIANT
20699#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20700
c19d1205 20701 /* Moves and type conversions. */
21d799b5
NC
20702 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20703 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20704 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20705 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20706 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20707 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20708 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20709 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20710 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20711 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20712 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20713 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20714 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20715 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20716
20717 /* Memory operations. */
21d799b5
NC
20718 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20719 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20720 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20721 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20722 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20723 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20724 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20725 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20726 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20727 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20728 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20729 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20730 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20731 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20732 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20733 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20734 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20735 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20736
c19d1205 20737 /* Monadic operations. */
21d799b5
NC
20738 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20739 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20740 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20741
20742 /* Dyadic operations. */
21d799b5
NC
20743 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20744 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20745 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20746 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20747 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20748 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20749 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20750 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20751 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20752
c19d1205 20753 /* Comparisons. */
21d799b5
NC
20754 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20755 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20756 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20757 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20758
62f3b8c8
PB
20759 /* Double precision load/store are still present on single precision
20760 implementations. */
20761 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20762 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20763 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20764 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20765 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20766 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20767 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20768 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20769 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20770 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20771
c921be7d
NC
20772#undef ARM_VARIANT
20773#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20774
c19d1205 20775 /* Moves and type conversions. */
21d799b5
NC
20776 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20777 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20778 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20779 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20780 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20781 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20782 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20783 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20784 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20785 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20786 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20787 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20788 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20789
c19d1205 20790 /* Monadic operations. */
21d799b5
NC
20791 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20792 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20793 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20794
20795 /* Dyadic operations. */
21d799b5
NC
20796 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20797 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20798 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20799 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20800 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20801 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20802 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20803 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20804 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20805
c19d1205 20806 /* Comparisons. */
21d799b5
NC
20807 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20808 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20809 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20810 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20811
c921be7d
NC
20812#undef ARM_VARIANT
20813#define ARM_VARIANT & fpu_vfp_ext_v2
20814
21d799b5
NC
20815 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20816 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20817 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20818 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20819
037e8744
JB
20820/* Instructions which may belong to either the Neon or VFP instruction sets.
20821 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20822#undef ARM_VARIANT
20823#define ARM_VARIANT & fpu_vfp_ext_v1xd
20824#undef THUMB_VARIANT
20825#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20826
037e8744
JB
20827 /* These mnemonics are unique to VFP. */
20828 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20829 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20830 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20831 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20832 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20833 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20834 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20835 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20836 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20837 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20838
20839 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20840 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20841 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20842 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20843
21d799b5
NC
20844 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20845 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20846
20847 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20848 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20849
55881a11
MGD
20850 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20851 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20852 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20853 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20854 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20855 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20856 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20857 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20858
5f1af56b 20859 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20860 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20861 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20862 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20863
037e8744
JB
20864
20865 /* NOTE: All VMOV encoding is special-cased! */
20866 NCE(vmov, 0, 1, (VMOV), neon_mov),
20867 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20868
9db2f6b4
RL
20869#undef ARM_VARIANT
20870#define ARM_VARIANT & arm_ext_fp16
20871#undef THUMB_VARIANT
20872#define THUMB_VARIANT & arm_ext_fp16
20873 /* New instructions added from v8.2, allowing the extraction and insertion of
20874 the upper 16 bits of a 32-bit vector register. */
20875 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20876 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20877
dec41383
JW
20878 /* New backported fma/fms instructions optional in v8.2. */
20879 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20880 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20881
c921be7d
NC
20882#undef THUMB_VARIANT
20883#define THUMB_VARIANT & fpu_neon_ext_v1
20884#undef ARM_VARIANT
20885#define ARM_VARIANT & fpu_neon_ext_v1
20886
5287ad62
JB
20887 /* Data processing with three registers of the same length. */
20888 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20889 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20890 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20891 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20892 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20893 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20894 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20895 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20896 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20897 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20898 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20899 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20900 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20901 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20902 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20903 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20904 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20905 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20906 /* If not immediate, fall back to neon_dyadic_i64_su.
20907 shl_imm should accept I8 I16 I32 I64,
20908 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20909 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20910 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20911 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20912 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20913 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20914 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20915 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20916 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20917 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20918 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20919 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20920 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20921 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20922 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20923 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20924 /* Bitfield ops, untyped. */
20925 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20926 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20927 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20928 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20929 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20930 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20931 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20932 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20933 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20934 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20935 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20936 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20937 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20938 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20939 back to neon_dyadic_if_su. */
21d799b5
NC
20940 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20941 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20942 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20943 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20944 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20945 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20946 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20947 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20948 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20949 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20950 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20951 /* As above, D registers only. */
21d799b5
NC
20952 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20953 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20954 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20955 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20956 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20957 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20958 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20959 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20960 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20961 /* vtst takes sizes 8, 16, 32. */
20962 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20963 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20964 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20965 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20966 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20967 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20968 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20969 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20970 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20971 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20972 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20973 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20974 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20975 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20976 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20977 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20978 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20979 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20980 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20981 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20982 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20983 /* ARM v8.1 extension. */
643afb90
MW
20984 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20985 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20986 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20987 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20988
20989 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20990 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20991 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20992
20993 /* Data processing with two registers and a shift amount. */
20994 /* Right shifts, and variants with rounding.
20995 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20996 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20997 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20998 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20999 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21000 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21001 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21002 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21003 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21004 /* Shift and insert. Sizes accepted 8 16 32 64. */
21005 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21006 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21007 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21008 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21009 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21010 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21011 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21012 /* Right shift immediate, saturating & narrowing, with rounding variants.
21013 Types accepted S16 S32 S64 U16 U32 U64. */
21014 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21015 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21016 /* As above, unsigned. Types accepted S16 S32 S64. */
21017 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21018 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21019 /* Right shift narrowing. Types accepted I16 I32 I64. */
21020 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21021 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21022 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 21023 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 21024 /* CVT with optional immediate for fixed-point variant. */
21d799b5 21025 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 21026
4316f0d2
DG
21027 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21028 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
21029
21030 /* Data processing, three registers of different lengths. */
21031 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21032 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21033 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21034 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21035 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21036 /* If not scalar, fall back to neon_dyadic_long.
21037 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
21038 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21039 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
21040 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21041 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21042 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21043 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21044 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21045 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21046 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21047 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21048 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
21049 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21050 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21051 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
21052 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21053 S16 S32 U16 U32. */
21d799b5 21054 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
21055
21056 /* Extract. Size 8. */
3b8d421e
PB
21057 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21058 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
21059
21060 /* Two registers, miscellaneous. */
21061 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21062 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21063 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21064 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21065 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21066 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21067 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21068 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
21069 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21070 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
21071 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21072 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21073 /* VMOVN. Types I16 I32 I64. */
21d799b5 21074 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21075 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21076 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21077 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21078 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21079 /* VZIP / VUZP. Sizes 8 16 32. */
21080 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21081 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21082 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21083 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21084 /* VQABS / VQNEG. Types S8 S16 S32. */
21085 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21086 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21087 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21088 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21089 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21090 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21091 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21092 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21093 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21094 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21095 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21096 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21097 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21098 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21099 /* VCLS. Types S8 S16 S32. */
21100 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21101 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21102 /* VCLZ. Types I8 I16 I32. */
21103 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21104 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21105 /* VCNT. Size 8. */
21106 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21107 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21108 /* Two address, untyped. */
21109 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21110 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21111 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21112 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21113 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21114
21115 /* Table lookup. Size 8. */
21116 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21117 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21118
c921be7d
NC
21119#undef THUMB_VARIANT
21120#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21121#undef ARM_VARIANT
21122#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21123
5287ad62 21124 /* Neon element/structure load/store. */
21d799b5
NC
21125 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21126 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21127 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21128 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21129 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21130 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21131 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21132 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21133
c921be7d 21134#undef THUMB_VARIANT
74db7efb
NC
21135#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21136#undef ARM_VARIANT
21137#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21138 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21139 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21140 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21141 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21142 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21143 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21144 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21145 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21146 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21147
74db7efb 21148#undef THUMB_VARIANT
c921be7d
NC
21149#define THUMB_VARIANT & fpu_vfp_ext_v3
21150#undef ARM_VARIANT
21151#define ARM_VARIANT & fpu_vfp_ext_v3
21152
21d799b5 21153 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21154 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21155 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21156 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21157 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21158 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21159 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21160 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21161 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21162
74db7efb
NC
21163#undef ARM_VARIANT
21164#define ARM_VARIANT & fpu_vfp_ext_fma
21165#undef THUMB_VARIANT
21166#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21167 /* Mnemonics shared by Neon and VFP. These are included in the
21168 VFP FMA variant; NEON and VFP FMA always includes the NEON
21169 FMA instructions. */
21170 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21171 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21172 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21173 the v form should always be used. */
21174 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21175 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21176 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21177 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21178 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21179 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21180
5287ad62 21181#undef THUMB_VARIANT
c921be7d
NC
21182#undef ARM_VARIANT
21183#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21184
21d799b5
NC
21185 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21186 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21187 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21188 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21189 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21190 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21191 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21192 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21193
c921be7d
NC
21194#undef ARM_VARIANT
21195#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21196
21d799b5
NC
21197 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21198 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21199 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21200 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21201 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21202 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21203 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21204 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21205 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21206 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21207 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21208 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21209 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21210 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21211 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21212 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21213 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21214 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21215 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21216 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21217 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21218 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21219 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21220 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21221 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21222 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21223 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21224 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21225 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21226 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21227 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21228 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21229 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21230 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21231 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21232 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21233 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21234 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21235 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21236 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21237 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21238 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21239 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21240 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21241 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21242 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21243 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21244 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21245 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21246 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21247 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21248 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21249 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21250 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21251 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21252 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21253 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21254 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21255 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21256 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21257 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21258 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21259 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21260 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21261 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21262 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21263 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21264 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21265 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21266 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21267 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21268 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21269 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21270 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21271 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21272 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21273 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21274 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21275 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21276 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21277 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21278 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21279 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21280 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21281 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21282 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21283 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21284 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21285 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21286 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21287 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21288 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21289 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21290 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21291 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21292 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21293 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21294 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21295 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21296 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21297 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21298 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21299 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21300 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21301 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21302 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21303 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21304 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21305 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21306 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21307 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21308 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21309 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21310 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21311 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21312 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21313 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21314 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21315 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21316 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21317 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21318 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21319 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21320 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21321 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21322 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21323 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21324 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21325 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21326 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21327 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21328 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21329 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21330 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21331 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21332 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21333 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21334 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21335 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21336 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21337 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21338 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21339 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21340 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21341 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21342 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21343 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21344 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21345 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21346 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21347 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21348 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21349 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21350 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21351 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21352 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21353 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21354 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21355 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21356 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21357 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21358 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21359
c921be7d
NC
21360#undef ARM_VARIANT
21361#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21362
21d799b5
NC
21363 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21364 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21365 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21366 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21367 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21368 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21369 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21370 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21371 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21372 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21373 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21374 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21375 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21376 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21377 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21378 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21379 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21380 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21381 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21382 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21383 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21384 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21385 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21386 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21387 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21388 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21389 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21390 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21391 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21392 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21393 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21394 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21395 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21396 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21397 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21398 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21399 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21400 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21401 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21402 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21403 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21404 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21405 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21406 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21407 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21408 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21409 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21410 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21411 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21412 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21413 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21414 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21415 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21416 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21417 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21418 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21419 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21420
c921be7d
NC
21421#undef ARM_VARIANT
21422#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21423
21d799b5
NC
21424 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21425 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21426 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21427 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21428 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21429 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21430 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21431 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21432 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21433 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21434 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21435 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21436 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21437 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21438 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21439 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21440 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21441 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21442 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21443 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21444 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21445 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21446 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21447 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21448 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21449 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21450 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21451 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21452 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21453 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21454 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21455 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21456 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21457 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21458 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21459 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21460 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21461 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21462 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21463 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21464 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21465 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21466 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21467 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21468 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21469 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21470 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21471 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21472 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21473 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21474 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21475 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21476 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21477 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21478 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21479 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21480 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21481 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21482 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21483 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21484 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21485 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21486 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21487 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21488 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21489 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21490 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21491 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21492 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21493 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21494 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21495 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21496 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21497 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21498 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21499 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21500
16a1fa25 21501 /* ARMv8-M instructions. */
4ed7ed8d
TP
21502#undef ARM_VARIANT
21503#define ARM_VARIANT NULL
21504#undef THUMB_VARIANT
21505#define THUMB_VARIANT & arm_ext_v8m
cf3cf39d
TP
21506 ToU("sg", e97fe97f, 0, (), noargs),
21507 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21508 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21509 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21510 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21511 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21512 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
16a1fa25
TP
21513
21514 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21515 instructions behave as nop if no VFP is present. */
21516#undef THUMB_VARIANT
21517#define THUMB_VARIANT & arm_ext_v8m_main
cf3cf39d
TP
21518 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21519 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21520};
21521#undef ARM_VARIANT
21522#undef THUMB_VARIANT
21523#undef TCE
c19d1205
ZW
21524#undef TUE
21525#undef TUF
21526#undef TCC
8f06b2d8 21527#undef cCE
e3cb604e
PB
21528#undef cCL
21529#undef C3E
c19d1205
ZW
21530#undef CE
21531#undef CM
21532#undef UE
21533#undef UF
21534#undef UT
5287ad62
JB
21535#undef NUF
21536#undef nUF
21537#undef NCE
21538#undef nCE
c19d1205
ZW
21539#undef OPS0
21540#undef OPS1
21541#undef OPS2
21542#undef OPS3
21543#undef OPS4
21544#undef OPS5
21545#undef OPS6
21546#undef do_0
21547\f
21548/* MD interface: bits in the object file. */
bfae80f2 21549
c19d1205
ZW
21550/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21551 for use in the a.out file, and stores them in the array pointed to by buf.
21552 This knows about the endian-ness of the target machine and does
21553 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21554 2 (short) and 4 (long) Floating numbers are put out as a series of
21555 LITTLENUMS (shorts, here at least). */
b99bd4ef 21556
c19d1205
ZW
21557void
21558md_number_to_chars (char * buf, valueT val, int n)
21559{
21560 if (target_big_endian)
21561 number_to_chars_bigendian (buf, val, n);
21562 else
21563 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21564}
21565
c19d1205
ZW
21566static valueT
21567md_chars_to_number (char * buf, int n)
bfae80f2 21568{
c19d1205
ZW
21569 valueT result = 0;
21570 unsigned char * where = (unsigned char *) buf;
bfae80f2 21571
c19d1205 21572 if (target_big_endian)
b99bd4ef 21573 {
c19d1205
ZW
21574 while (n--)
21575 {
21576 result <<= 8;
21577 result |= (*where++ & 255);
21578 }
b99bd4ef 21579 }
c19d1205 21580 else
b99bd4ef 21581 {
c19d1205
ZW
21582 while (n--)
21583 {
21584 result <<= 8;
21585 result |= (where[n] & 255);
21586 }
bfae80f2 21587 }
b99bd4ef 21588
c19d1205 21589 return result;
bfae80f2 21590}
b99bd4ef 21591
c19d1205 21592/* MD interface: Sections. */
b99bd4ef 21593
fa94de6b
RM
21594/* Calculate the maximum variable size (i.e., excluding fr_fix)
21595 that an rs_machine_dependent frag may reach. */
21596
21597unsigned int
21598arm_frag_max_var (fragS *fragp)
21599{
21600 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21601 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21602
21603 Note that we generate relaxable instructions even for cases that don't
21604 really need it, like an immediate that's a trivial constant. So we're
21605 overestimating the instruction size for some of those cases. Rather
21606 than putting more intelligence here, it would probably be better to
21607 avoid generating a relaxation frag in the first place when it can be
21608 determined up front that a short instruction will suffice. */
21609
21610 gas_assert (fragp->fr_type == rs_machine_dependent);
21611 return INSN_SIZE;
21612}
21613
0110f2b8
PB
21614/* Estimate the size of a frag before relaxing. Assume everything fits in
21615 2 bytes. */
21616
c19d1205 21617int
0110f2b8 21618md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21619 segT segtype ATTRIBUTE_UNUSED)
21620{
0110f2b8
PB
21621 fragp->fr_var = 2;
21622 return 2;
21623}
21624
21625/* Convert a machine dependent frag. */
21626
21627void
21628md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21629{
21630 unsigned long insn;
21631 unsigned long old_op;
21632 char *buf;
21633 expressionS exp;
21634 fixS *fixp;
21635 int reloc_type;
21636 int pc_rel;
21637 int opcode;
21638
21639 buf = fragp->fr_literal + fragp->fr_fix;
21640
21641 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21642 if (fragp->fr_symbol)
21643 {
0110f2b8
PB
21644 exp.X_op = O_symbol;
21645 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21646 }
21647 else
21648 {
0110f2b8 21649 exp.X_op = O_constant;
5f4273c7 21650 }
0110f2b8
PB
21651 exp.X_add_number = fragp->fr_offset;
21652 opcode = fragp->fr_subtype;
21653 switch (opcode)
21654 {
21655 case T_MNEM_ldr_pc:
21656 case T_MNEM_ldr_pc2:
21657 case T_MNEM_ldr_sp:
21658 case T_MNEM_str_sp:
21659 case T_MNEM_ldr:
21660 case T_MNEM_ldrb:
21661 case T_MNEM_ldrh:
21662 case T_MNEM_str:
21663 case T_MNEM_strb:
21664 case T_MNEM_strh:
21665 if (fragp->fr_var == 4)
21666 {
5f4273c7 21667 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21668 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21669 {
21670 insn |= (old_op & 0x700) << 4;
21671 }
21672 else
21673 {
21674 insn |= (old_op & 7) << 12;
21675 insn |= (old_op & 0x38) << 13;
21676 }
21677 insn |= 0x00000c00;
21678 put_thumb32_insn (buf, insn);
21679 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21680 }
21681 else
21682 {
21683 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21684 }
21685 pc_rel = (opcode == T_MNEM_ldr_pc2);
21686 break;
21687 case T_MNEM_adr:
21688 if (fragp->fr_var == 4)
21689 {
21690 insn = THUMB_OP32 (opcode);
21691 insn |= (old_op & 0xf0) << 4;
21692 put_thumb32_insn (buf, insn);
21693 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21694 }
21695 else
21696 {
21697 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21698 exp.X_add_number -= 4;
21699 }
21700 pc_rel = 1;
21701 break;
21702 case T_MNEM_mov:
21703 case T_MNEM_movs:
21704 case T_MNEM_cmp:
21705 case T_MNEM_cmn:
21706 if (fragp->fr_var == 4)
21707 {
21708 int r0off = (opcode == T_MNEM_mov
21709 || opcode == T_MNEM_movs) ? 0 : 8;
21710 insn = THUMB_OP32 (opcode);
21711 insn = (insn & 0xe1ffffff) | 0x10000000;
21712 insn |= (old_op & 0x700) << r0off;
21713 put_thumb32_insn (buf, insn);
21714 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21715 }
21716 else
21717 {
21718 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21719 }
21720 pc_rel = 0;
21721 break;
21722 case T_MNEM_b:
21723 if (fragp->fr_var == 4)
21724 {
21725 insn = THUMB_OP32(opcode);
21726 put_thumb32_insn (buf, insn);
21727 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21728 }
21729 else
21730 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21731 pc_rel = 1;
21732 break;
21733 case T_MNEM_bcond:
21734 if (fragp->fr_var == 4)
21735 {
21736 insn = THUMB_OP32(opcode);
21737 insn |= (old_op & 0xf00) << 14;
21738 put_thumb32_insn (buf, insn);
21739 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21740 }
21741 else
21742 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21743 pc_rel = 1;
21744 break;
21745 case T_MNEM_add_sp:
21746 case T_MNEM_add_pc:
21747 case T_MNEM_inc_sp:
21748 case T_MNEM_dec_sp:
21749 if (fragp->fr_var == 4)
21750 {
21751 /* ??? Choose between add and addw. */
21752 insn = THUMB_OP32 (opcode);
21753 insn |= (old_op & 0xf0) << 4;
21754 put_thumb32_insn (buf, insn);
16805f35
PB
21755 if (opcode == T_MNEM_add_pc)
21756 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21757 else
21758 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21759 }
21760 else
21761 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21762 pc_rel = 0;
21763 break;
21764
21765 case T_MNEM_addi:
21766 case T_MNEM_addis:
21767 case T_MNEM_subi:
21768 case T_MNEM_subis:
21769 if (fragp->fr_var == 4)
21770 {
21771 insn = THUMB_OP32 (opcode);
21772 insn |= (old_op & 0xf0) << 4;
21773 insn |= (old_op & 0xf) << 16;
21774 put_thumb32_insn (buf, insn);
16805f35
PB
21775 if (insn & (1 << 20))
21776 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21777 else
21778 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21779 }
21780 else
21781 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21782 pc_rel = 0;
21783 break;
21784 default:
5f4273c7 21785 abort ();
0110f2b8
PB
21786 }
21787 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21788 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21789 fixp->fx_file = fragp->fr_file;
21790 fixp->fx_line = fragp->fr_line;
21791 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21792
21793 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21794 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21795 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21796 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21797}
21798
21799/* Return the size of a relaxable immediate operand instruction.
21800 SHIFT and SIZE specify the form of the allowable immediate. */
21801static int
21802relax_immediate (fragS *fragp, int size, int shift)
21803{
21804 offsetT offset;
21805 offsetT mask;
21806 offsetT low;
21807
21808 /* ??? Should be able to do better than this. */
21809 if (fragp->fr_symbol)
21810 return 4;
21811
21812 low = (1 << shift) - 1;
21813 mask = (1 << (shift + size)) - (1 << shift);
21814 offset = fragp->fr_offset;
21815 /* Force misaligned offsets to 32-bit variant. */
21816 if (offset & low)
5e77afaa 21817 return 4;
0110f2b8
PB
21818 if (offset & ~mask)
21819 return 4;
21820 return 2;
21821}
21822
5e77afaa
PB
21823/* Get the address of a symbol during relaxation. */
21824static addressT
5f4273c7 21825relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21826{
21827 fragS *sym_frag;
21828 addressT addr;
21829 symbolS *sym;
21830
21831 sym = fragp->fr_symbol;
21832 sym_frag = symbol_get_frag (sym);
21833 know (S_GET_SEGMENT (sym) != absolute_section
21834 || sym_frag == &zero_address_frag);
21835 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21836
21837 /* If frag has yet to be reached on this pass, assume it will
21838 move by STRETCH just as we did. If this is not so, it will
21839 be because some frag between grows, and that will force
21840 another pass. */
21841
21842 if (stretch != 0
21843 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21844 {
21845 fragS *f;
21846
21847 /* Adjust stretch for any alignment frag. Note that if have
21848 been expanding the earlier code, the symbol may be
21849 defined in what appears to be an earlier frag. FIXME:
21850 This doesn't handle the fr_subtype field, which specifies
21851 a maximum number of bytes to skip when doing an
21852 alignment. */
21853 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21854 {
21855 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21856 {
21857 if (stretch < 0)
21858 stretch = - ((- stretch)
21859 & ~ ((1 << (int) f->fr_offset) - 1));
21860 else
21861 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21862 if (stretch == 0)
21863 break;
21864 }
21865 }
21866 if (f != NULL)
21867 addr += stretch;
21868 }
5e77afaa
PB
21869
21870 return addr;
21871}
21872
0110f2b8
PB
21873/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21874 load. */
21875static int
5e77afaa 21876relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21877{
21878 addressT addr;
21879 offsetT val;
21880
21881 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21882 if (fragp->fr_symbol == NULL
21883 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21884 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21885 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21886 return 4;
21887
5f4273c7 21888 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21889 addr = fragp->fr_address + fragp->fr_fix;
21890 addr = (addr + 4) & ~3;
5e77afaa 21891 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21892 if (val & 3)
5e77afaa 21893 return 4;
0110f2b8
PB
21894 val -= addr;
21895 if (val < 0 || val > 1020)
21896 return 4;
21897 return 2;
21898}
21899
21900/* Return the size of a relaxable add/sub immediate instruction. */
21901static int
21902relax_addsub (fragS *fragp, asection *sec)
21903{
21904 char *buf;
21905 int op;
21906
21907 buf = fragp->fr_literal + fragp->fr_fix;
21908 op = bfd_get_16(sec->owner, buf);
21909 if ((op & 0xf) == ((op >> 4) & 0xf))
21910 return relax_immediate (fragp, 8, 0);
21911 else
21912 return relax_immediate (fragp, 3, 0);
21913}
21914
e83a675f
RE
21915/* Return TRUE iff the definition of symbol S could be pre-empted
21916 (overridden) at link or load time. */
21917static bfd_boolean
21918symbol_preemptible (symbolS *s)
21919{
21920 /* Weak symbols can always be pre-empted. */
21921 if (S_IS_WEAK (s))
21922 return TRUE;
21923
21924 /* Non-global symbols cannot be pre-empted. */
21925 if (! S_IS_EXTERNAL (s))
21926 return FALSE;
21927
21928#ifdef OBJ_ELF
21929 /* In ELF, a global symbol can be marked protected, or private. In that
21930 case it can't be pre-empted (other definitions in the same link unit
21931 would violate the ODR). */
21932 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21933 return FALSE;
21934#endif
21935
21936 /* Other global symbols might be pre-empted. */
21937 return TRUE;
21938}
0110f2b8
PB
21939
21940/* Return the size of a relaxable branch instruction. BITS is the
21941 size of the offset field in the narrow instruction. */
21942
21943static int
5e77afaa 21944relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21945{
21946 addressT addr;
21947 offsetT val;
21948 offsetT limit;
21949
21950 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21951 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21952 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21953 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21954 return 4;
21955
267bf995 21956#ifdef OBJ_ELF
e83a675f 21957 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21958 if (S_IS_DEFINED (fragp->fr_symbol)
21959 && ARM_IS_FUNC (fragp->fr_symbol))
21960 return 4;
e83a675f 21961#endif
0d9b4b55 21962
e83a675f 21963 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21964 return 4;
267bf995 21965
5f4273c7 21966 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21967 addr = fragp->fr_address + fragp->fr_fix + 4;
21968 val -= addr;
21969
21970 /* Offset is a signed value *2 */
21971 limit = 1 << bits;
21972 if (val >= limit || val < -limit)
21973 return 4;
21974 return 2;
21975}
21976
21977
21978/* Relax a machine dependent frag. This returns the amount by which
21979 the current size of the frag should change. */
21980
21981int
5e77afaa 21982arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21983{
21984 int oldsize;
21985 int newsize;
21986
21987 oldsize = fragp->fr_var;
21988 switch (fragp->fr_subtype)
21989 {
21990 case T_MNEM_ldr_pc2:
5f4273c7 21991 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21992 break;
21993 case T_MNEM_ldr_pc:
21994 case T_MNEM_ldr_sp:
21995 case T_MNEM_str_sp:
5f4273c7 21996 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21997 break;
21998 case T_MNEM_ldr:
21999 case T_MNEM_str:
5f4273c7 22000 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
22001 break;
22002 case T_MNEM_ldrh:
22003 case T_MNEM_strh:
5f4273c7 22004 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
22005 break;
22006 case T_MNEM_ldrb:
22007 case T_MNEM_strb:
5f4273c7 22008 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
22009 break;
22010 case T_MNEM_adr:
5f4273c7 22011 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
22012 break;
22013 case T_MNEM_mov:
22014 case T_MNEM_movs:
22015 case T_MNEM_cmp:
22016 case T_MNEM_cmn:
5f4273c7 22017 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
22018 break;
22019 case T_MNEM_b:
5f4273c7 22020 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
22021 break;
22022 case T_MNEM_bcond:
5f4273c7 22023 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
22024 break;
22025 case T_MNEM_add_sp:
22026 case T_MNEM_add_pc:
22027 newsize = relax_immediate (fragp, 8, 2);
22028 break;
22029 case T_MNEM_inc_sp:
22030 case T_MNEM_dec_sp:
22031 newsize = relax_immediate (fragp, 7, 2);
22032 break;
22033 case T_MNEM_addi:
22034 case T_MNEM_addis:
22035 case T_MNEM_subi:
22036 case T_MNEM_subis:
22037 newsize = relax_addsub (fragp, sec);
22038 break;
22039 default:
5f4273c7 22040 abort ();
0110f2b8 22041 }
5e77afaa
PB
22042
22043 fragp->fr_var = newsize;
22044 /* Freeze wide instructions that are at or before the same location as
22045 in the previous pass. This avoids infinite loops.
5f4273c7
NC
22046 Don't freeze them unconditionally because targets may be artificially
22047 misaligned by the expansion of preceding frags. */
5e77afaa 22048 if (stretch <= 0 && newsize > 2)
0110f2b8 22049 {
0110f2b8 22050 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 22051 frag_wane (fragp);
0110f2b8 22052 }
5e77afaa 22053
0110f2b8 22054 return newsize - oldsize;
c19d1205 22055}
b99bd4ef 22056
c19d1205 22057/* Round up a section size to the appropriate boundary. */
b99bd4ef 22058
c19d1205
ZW
22059valueT
22060md_section_align (segT segment ATTRIBUTE_UNUSED,
22061 valueT size)
22062{
f0927246
NC
22063#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
22064 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
22065 {
22066 /* For a.out, force the section size to be aligned. If we don't do
22067 this, BFD will align it for us, but it will not write out the
22068 final bytes of the section. This may be a bug in BFD, but it is
22069 easier to fix it here since that is how the other a.out targets
22070 work. */
22071 int align;
22072
22073 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 22074 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 22075 }
c19d1205 22076#endif
f0927246 22077
6844c0cc 22078 return size;
bfae80f2 22079}
b99bd4ef 22080
c19d1205
ZW
22081/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22082 of an rs_align_code fragment. */
22083
22084void
22085arm_handle_align (fragS * fragP)
bfae80f2 22086{
d9235011 22087 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22088 {
22089 { /* ARMv1 */
22090 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22091 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22092 },
22093 { /* ARMv6k */
22094 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22095 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22096 },
22097 };
d9235011 22098 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22099 {
22100 { /* Thumb-1 */
22101 {0xc0, 0x46}, /* LE */
22102 {0x46, 0xc0}, /* BE */
22103 },
22104 { /* Thumb-2 */
22105 {0x00, 0xbf}, /* LE */
22106 {0xbf, 0x00} /* BE */
22107 }
22108 };
d9235011 22109 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22110 { /* Wide Thumb-2 */
22111 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22112 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22113 };
c921be7d 22114
e7495e45 22115 unsigned bytes, fix, noop_size;
c19d1205 22116 char * p;
d9235011
TS
22117 const unsigned char * noop;
22118 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22119#ifdef OBJ_ELF
22120 enum mstate state;
22121#endif
bfae80f2 22122
c19d1205 22123 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22124 return;
22125
c19d1205
ZW
22126 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22127 p = fragP->fr_literal + fragP->fr_fix;
22128 fix = 0;
bfae80f2 22129
c19d1205
ZW
22130 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22131 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22132
cd000bff 22133 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22134
cd000bff 22135 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22136 {
7f78eb34
JW
22137 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22138 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22139 {
22140 narrow_noop = thumb_noop[1][target_big_endian];
22141 noop = wide_thumb_noop[target_big_endian];
22142 }
c19d1205 22143 else
e7495e45
NS
22144 noop = thumb_noop[0][target_big_endian];
22145 noop_size = 2;
cd000bff
DJ
22146#ifdef OBJ_ELF
22147 state = MAP_THUMB;
22148#endif
7ed4c4c5
NC
22149 }
22150 else
22151 {
7f78eb34
JW
22152 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22153 ? selected_cpu : arm_arch_none,
22154 arm_ext_v6k) != 0]
e7495e45
NS
22155 [target_big_endian];
22156 noop_size = 4;
cd000bff
DJ
22157#ifdef OBJ_ELF
22158 state = MAP_ARM;
22159#endif
7ed4c4c5 22160 }
c921be7d 22161
e7495e45 22162 fragP->fr_var = noop_size;
c921be7d 22163
c19d1205 22164 if (bytes & (noop_size - 1))
7ed4c4c5 22165 {
c19d1205 22166 fix = bytes & (noop_size - 1);
cd000bff
DJ
22167#ifdef OBJ_ELF
22168 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22169#endif
c19d1205
ZW
22170 memset (p, 0, fix);
22171 p += fix;
22172 bytes -= fix;
a737bd4d 22173 }
a737bd4d 22174
e7495e45
NS
22175 if (narrow_noop)
22176 {
22177 if (bytes & noop_size)
22178 {
22179 /* Insert a narrow noop. */
22180 memcpy (p, narrow_noop, noop_size);
22181 p += noop_size;
22182 bytes -= noop_size;
22183 fix += noop_size;
22184 }
22185
22186 /* Use wide noops for the remainder */
22187 noop_size = 4;
22188 }
22189
c19d1205 22190 while (bytes >= noop_size)
a737bd4d 22191 {
c19d1205
ZW
22192 memcpy (p, noop, noop_size);
22193 p += noop_size;
22194 bytes -= noop_size;
22195 fix += noop_size;
a737bd4d
NC
22196 }
22197
c19d1205 22198 fragP->fr_fix += fix;
a737bd4d
NC
22199}
22200
c19d1205
ZW
22201/* Called from md_do_align. Used to create an alignment
22202 frag in a code section. */
22203
22204void
22205arm_frag_align_code (int n, int max)
bfae80f2 22206{
c19d1205 22207 char * p;
7ed4c4c5 22208
c19d1205 22209 /* We assume that there will never be a requirement
6ec8e702 22210 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22211 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22212 {
22213 char err_msg[128];
22214
fa94de6b 22215 sprintf (err_msg,
477330fc
RM
22216 _("alignments greater than %d bytes not supported in .text sections."),
22217 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22218 as_fatal ("%s", err_msg);
6ec8e702 22219 }
bfae80f2 22220
c19d1205
ZW
22221 p = frag_var (rs_align_code,
22222 MAX_MEM_FOR_RS_ALIGN_CODE,
22223 1,
22224 (relax_substateT) max,
22225 (symbolS *) NULL,
22226 (offsetT) n,
22227 (char *) NULL);
22228 *p = 0;
22229}
bfae80f2 22230
8dc2430f
NC
22231/* Perform target specific initialisation of a frag.
22232 Note - despite the name this initialisation is not done when the frag
22233 is created, but only when its type is assigned. A frag can be created
22234 and used a long time before its type is set, so beware of assuming that
33eaf5de 22235 this initialisation is performed first. */
bfae80f2 22236
cd000bff
DJ
22237#ifndef OBJ_ELF
22238void
22239arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22240{
22241 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22242 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22243}
22244
22245#else /* OBJ_ELF is defined. */
c19d1205 22246void
cd000bff 22247arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22248{
e8d84ca1 22249 bfd_boolean frag_thumb_mode;
b968d18a 22250
8dc2430f
NC
22251 /* If the current ARM vs THUMB mode has not already
22252 been recorded into this frag then do so now. */
cd000bff 22253 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22254 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22255
e8d84ca1
NC
22256 /* PR 21809: Do not set a mapping state for debug sections
22257 - it just confuses other tools. */
22258 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22259 return;
22260
b968d18a 22261 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22262
f9c1b181
RL
22263 /* Record a mapping symbol for alignment frags. We will delete this
22264 later if the alignment ends up empty. */
22265 switch (fragP->fr_type)
22266 {
22267 case rs_align:
22268 case rs_align_test:
22269 case rs_fill:
22270 mapping_state_2 (MAP_DATA, max_chars);
22271 break;
22272 case rs_align_code:
b968d18a 22273 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22274 break;
22275 default:
22276 break;
cd000bff 22277 }
bfae80f2
RE
22278}
22279
c19d1205
ZW
22280/* When we change sections we need to issue a new mapping symbol. */
22281
22282void
22283arm_elf_change_section (void)
bfae80f2 22284{
c19d1205
ZW
22285 /* Link an unlinked unwind index table section to the .text section. */
22286 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22287 && elf_linked_to_section (now_seg) == NULL)
22288 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22289}
22290
c19d1205
ZW
22291int
22292arm_elf_section_type (const char * str, size_t len)
e45d0630 22293{
c19d1205
ZW
22294 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22295 return SHT_ARM_EXIDX;
e45d0630 22296
c19d1205
ZW
22297 return -1;
22298}
22299\f
22300/* Code to deal with unwinding tables. */
e45d0630 22301
c19d1205 22302static void add_unwind_adjustsp (offsetT);
e45d0630 22303
5f4273c7 22304/* Generate any deferred unwind frame offset. */
e45d0630 22305
bfae80f2 22306static void
c19d1205 22307flush_pending_unwind (void)
bfae80f2 22308{
c19d1205 22309 offsetT offset;
bfae80f2 22310
c19d1205
ZW
22311 offset = unwind.pending_offset;
22312 unwind.pending_offset = 0;
22313 if (offset != 0)
22314 add_unwind_adjustsp (offset);
bfae80f2
RE
22315}
22316
c19d1205
ZW
22317/* Add an opcode to this list for this function. Two-byte opcodes should
22318 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22319 order. */
22320
bfae80f2 22321static void
c19d1205 22322add_unwind_opcode (valueT op, int length)
bfae80f2 22323{
c19d1205
ZW
22324 /* Add any deferred stack adjustment. */
22325 if (unwind.pending_offset)
22326 flush_pending_unwind ();
bfae80f2 22327
c19d1205 22328 unwind.sp_restored = 0;
bfae80f2 22329
c19d1205 22330 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22331 {
c19d1205
ZW
22332 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22333 if (unwind.opcodes)
325801bd
TS
22334 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22335 unwind.opcode_alloc);
c19d1205 22336 else
325801bd 22337 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22338 }
c19d1205 22339 while (length > 0)
bfae80f2 22340 {
c19d1205
ZW
22341 length--;
22342 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22343 op >>= 8;
22344 unwind.opcode_count++;
bfae80f2 22345 }
bfae80f2
RE
22346}
22347
c19d1205
ZW
22348/* Add unwind opcodes to adjust the stack pointer. */
22349
bfae80f2 22350static void
c19d1205 22351add_unwind_adjustsp (offsetT offset)
bfae80f2 22352{
c19d1205 22353 valueT op;
bfae80f2 22354
c19d1205 22355 if (offset > 0x200)
bfae80f2 22356 {
c19d1205
ZW
22357 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22358 char bytes[5];
22359 int n;
22360 valueT o;
bfae80f2 22361
c19d1205
ZW
22362 /* Long form: 0xb2, uleb128. */
22363 /* This might not fit in a word so add the individual bytes,
22364 remembering the list is built in reverse order. */
22365 o = (valueT) ((offset - 0x204) >> 2);
22366 if (o == 0)
22367 add_unwind_opcode (0, 1);
bfae80f2 22368
c19d1205
ZW
22369 /* Calculate the uleb128 encoding of the offset. */
22370 n = 0;
22371 while (o)
22372 {
22373 bytes[n] = o & 0x7f;
22374 o >>= 7;
22375 if (o)
22376 bytes[n] |= 0x80;
22377 n++;
22378 }
22379 /* Add the insn. */
22380 for (; n; n--)
22381 add_unwind_opcode (bytes[n - 1], 1);
22382 add_unwind_opcode (0xb2, 1);
22383 }
22384 else if (offset > 0x100)
bfae80f2 22385 {
c19d1205
ZW
22386 /* Two short opcodes. */
22387 add_unwind_opcode (0x3f, 1);
22388 op = (offset - 0x104) >> 2;
22389 add_unwind_opcode (op, 1);
bfae80f2 22390 }
c19d1205
ZW
22391 else if (offset > 0)
22392 {
22393 /* Short opcode. */
22394 op = (offset - 4) >> 2;
22395 add_unwind_opcode (op, 1);
22396 }
22397 else if (offset < 0)
bfae80f2 22398 {
c19d1205
ZW
22399 offset = -offset;
22400 while (offset > 0x100)
bfae80f2 22401 {
c19d1205
ZW
22402 add_unwind_opcode (0x7f, 1);
22403 offset -= 0x100;
bfae80f2 22404 }
c19d1205
ZW
22405 op = ((offset - 4) >> 2) | 0x40;
22406 add_unwind_opcode (op, 1);
bfae80f2 22407 }
bfae80f2
RE
22408}
22409
c19d1205 22410/* Finish the list of unwind opcodes for this function. */
0198d5e6 22411
c19d1205
ZW
22412static void
22413finish_unwind_opcodes (void)
bfae80f2 22414{
c19d1205 22415 valueT op;
bfae80f2 22416
c19d1205 22417 if (unwind.fp_used)
bfae80f2 22418 {
708587a4 22419 /* Adjust sp as necessary. */
c19d1205
ZW
22420 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22421 flush_pending_unwind ();
bfae80f2 22422
c19d1205
ZW
22423 /* After restoring sp from the frame pointer. */
22424 op = 0x90 | unwind.fp_reg;
22425 add_unwind_opcode (op, 1);
22426 }
22427 else
22428 flush_pending_unwind ();
bfae80f2
RE
22429}
22430
bfae80f2 22431
c19d1205
ZW
22432/* Start an exception table entry. If idx is nonzero this is an index table
22433 entry. */
bfae80f2
RE
22434
22435static void
c19d1205 22436start_unwind_section (const segT text_seg, int idx)
bfae80f2 22437{
c19d1205
ZW
22438 const char * text_name;
22439 const char * prefix;
22440 const char * prefix_once;
22441 const char * group_name;
c19d1205 22442 char * sec_name;
c19d1205
ZW
22443 int type;
22444 int flags;
22445 int linkonce;
bfae80f2 22446
c19d1205 22447 if (idx)
bfae80f2 22448 {
c19d1205
ZW
22449 prefix = ELF_STRING_ARM_unwind;
22450 prefix_once = ELF_STRING_ARM_unwind_once;
22451 type = SHT_ARM_EXIDX;
bfae80f2 22452 }
c19d1205 22453 else
bfae80f2 22454 {
c19d1205
ZW
22455 prefix = ELF_STRING_ARM_unwind_info;
22456 prefix_once = ELF_STRING_ARM_unwind_info_once;
22457 type = SHT_PROGBITS;
bfae80f2
RE
22458 }
22459
c19d1205
ZW
22460 text_name = segment_name (text_seg);
22461 if (streq (text_name, ".text"))
22462 text_name = "";
22463
22464 if (strncmp (text_name, ".gnu.linkonce.t.",
22465 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22466 {
c19d1205
ZW
22467 prefix = prefix_once;
22468 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22469 }
22470
29a2809e 22471 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22472
c19d1205
ZW
22473 flags = SHF_ALLOC;
22474 linkonce = 0;
22475 group_name = 0;
bfae80f2 22476
c19d1205
ZW
22477 /* Handle COMDAT group. */
22478 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22479 {
c19d1205
ZW
22480 group_name = elf_group_name (text_seg);
22481 if (group_name == NULL)
22482 {
bd3ba5d1 22483 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22484 segment_name (text_seg));
22485 ignore_rest_of_line ();
22486 return;
22487 }
22488 flags |= SHF_GROUP;
22489 linkonce = 1;
bfae80f2
RE
22490 }
22491
a91e1603
L
22492 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22493 linkonce, 0);
bfae80f2 22494
5f4273c7 22495 /* Set the section link for index tables. */
c19d1205
ZW
22496 if (idx)
22497 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22498}
22499
bfae80f2 22500
c19d1205
ZW
22501/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22502 personality routine data. Returns zero, or the index table value for
cad0da33 22503 an inline entry. */
c19d1205
ZW
22504
22505static valueT
22506create_unwind_entry (int have_data)
bfae80f2 22507{
c19d1205
ZW
22508 int size;
22509 addressT where;
22510 char *ptr;
22511 /* The current word of data. */
22512 valueT data;
22513 /* The number of bytes left in this word. */
22514 int n;
bfae80f2 22515
c19d1205 22516 finish_unwind_opcodes ();
bfae80f2 22517
c19d1205
ZW
22518 /* Remember the current text section. */
22519 unwind.saved_seg = now_seg;
22520 unwind.saved_subseg = now_subseg;
bfae80f2 22521
c19d1205 22522 start_unwind_section (now_seg, 0);
bfae80f2 22523
c19d1205 22524 if (unwind.personality_routine == NULL)
bfae80f2 22525 {
c19d1205
ZW
22526 if (unwind.personality_index == -2)
22527 {
22528 if (have_data)
5f4273c7 22529 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22530 return 1; /* EXIDX_CANTUNWIND. */
22531 }
bfae80f2 22532
c19d1205
ZW
22533 /* Use a default personality routine if none is specified. */
22534 if (unwind.personality_index == -1)
22535 {
22536 if (unwind.opcode_count > 3)
22537 unwind.personality_index = 1;
22538 else
22539 unwind.personality_index = 0;
22540 }
bfae80f2 22541
c19d1205
ZW
22542 /* Space for the personality routine entry. */
22543 if (unwind.personality_index == 0)
22544 {
22545 if (unwind.opcode_count > 3)
22546 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22547
c19d1205
ZW
22548 if (!have_data)
22549 {
22550 /* All the data is inline in the index table. */
22551 data = 0x80;
22552 n = 3;
22553 while (unwind.opcode_count > 0)
22554 {
22555 unwind.opcode_count--;
22556 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22557 n--;
22558 }
bfae80f2 22559
c19d1205
ZW
22560 /* Pad with "finish" opcodes. */
22561 while (n--)
22562 data = (data << 8) | 0xb0;
bfae80f2 22563
c19d1205
ZW
22564 return data;
22565 }
22566 size = 0;
22567 }
22568 else
22569 /* We get two opcodes "free" in the first word. */
22570 size = unwind.opcode_count - 2;
22571 }
22572 else
5011093d 22573 {
cad0da33
NC
22574 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22575 if (unwind.personality_index != -1)
22576 {
22577 as_bad (_("attempt to recreate an unwind entry"));
22578 return 1;
22579 }
5011093d
NC
22580
22581 /* An extra byte is required for the opcode count. */
22582 size = unwind.opcode_count + 1;
22583 }
bfae80f2 22584
c19d1205
ZW
22585 size = (size + 3) >> 2;
22586 if (size > 0xff)
22587 as_bad (_("too many unwind opcodes"));
bfae80f2 22588
c19d1205
ZW
22589 frag_align (2, 0, 0);
22590 record_alignment (now_seg, 2);
22591 unwind.table_entry = expr_build_dot ();
22592
22593 /* Allocate the table entry. */
22594 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22595 /* PR 13449: Zero the table entries in case some of them are not used. */
22596 memset (ptr, 0, (size << 2) + 4);
c19d1205 22597 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22598
c19d1205 22599 switch (unwind.personality_index)
bfae80f2 22600 {
c19d1205
ZW
22601 case -1:
22602 /* ??? Should this be a PLT generating relocation? */
22603 /* Custom personality routine. */
22604 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22605 BFD_RELOC_ARM_PREL31);
bfae80f2 22606
c19d1205
ZW
22607 where += 4;
22608 ptr += 4;
bfae80f2 22609
c19d1205 22610 /* Set the first byte to the number of additional words. */
5011093d 22611 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22612 n = 3;
22613 break;
bfae80f2 22614
c19d1205
ZW
22615 /* ABI defined personality routines. */
22616 case 0:
22617 /* Three opcodes bytes are packed into the first word. */
22618 data = 0x80;
22619 n = 3;
22620 break;
bfae80f2 22621
c19d1205
ZW
22622 case 1:
22623 case 2:
22624 /* The size and first two opcode bytes go in the first word. */
22625 data = ((0x80 + unwind.personality_index) << 8) | size;
22626 n = 2;
22627 break;
bfae80f2 22628
c19d1205
ZW
22629 default:
22630 /* Should never happen. */
22631 abort ();
22632 }
bfae80f2 22633
c19d1205
ZW
22634 /* Pack the opcodes into words (MSB first), reversing the list at the same
22635 time. */
22636 while (unwind.opcode_count > 0)
22637 {
22638 if (n == 0)
22639 {
22640 md_number_to_chars (ptr, data, 4);
22641 ptr += 4;
22642 n = 4;
22643 data = 0;
22644 }
22645 unwind.opcode_count--;
22646 n--;
22647 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22648 }
22649
22650 /* Finish off the last word. */
22651 if (n < 4)
22652 {
22653 /* Pad with "finish" opcodes. */
22654 while (n--)
22655 data = (data << 8) | 0xb0;
22656
22657 md_number_to_chars (ptr, data, 4);
22658 }
22659
22660 if (!have_data)
22661 {
22662 /* Add an empty descriptor if there is no user-specified data. */
22663 ptr = frag_more (4);
22664 md_number_to_chars (ptr, 0, 4);
22665 }
22666
22667 return 0;
bfae80f2
RE
22668}
22669
f0927246
NC
22670
22671/* Initialize the DWARF-2 unwind information for this procedure. */
22672
22673void
22674tc_arm_frame_initial_instructions (void)
22675{
22676 cfi_add_CFA_def_cfa (REG_SP, 0);
22677}
22678#endif /* OBJ_ELF */
22679
c19d1205
ZW
22680/* Convert REGNAME to a DWARF-2 register number. */
22681
22682int
1df69f4f 22683tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22684{
1df69f4f 22685 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22686 if (reg != FAIL)
22687 return reg;
c19d1205 22688
1f5afe1c
NC
22689 /* PR 16694: Allow VFP registers as well. */
22690 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22691 if (reg != FAIL)
22692 return 64 + reg;
c19d1205 22693
1f5afe1c
NC
22694 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22695 if (reg != FAIL)
22696 return reg + 256;
22697
0198d5e6 22698 return FAIL;
bfae80f2
RE
22699}
22700
f0927246 22701#ifdef TE_PE
c19d1205 22702void
f0927246 22703tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22704{
91d6fa6a 22705 expressionS exp;
bfae80f2 22706
91d6fa6a
NC
22707 exp.X_op = O_secrel;
22708 exp.X_add_symbol = symbol;
22709 exp.X_add_number = 0;
22710 emit_expr (&exp, size);
f0927246
NC
22711}
22712#endif
bfae80f2 22713
c19d1205 22714/* MD interface: Symbol and relocation handling. */
bfae80f2 22715
2fc8bdac
ZW
22716/* Return the address within the segment that a PC-relative fixup is
22717 relative to. For ARM, PC-relative fixups applied to instructions
22718 are generally relative to the location of the fixup plus 8 bytes.
22719 Thumb branches are offset by 4, and Thumb loads relative to PC
22720 require special handling. */
bfae80f2 22721
c19d1205 22722long
2fc8bdac 22723md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22724{
2fc8bdac
ZW
22725 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22726
22727 /* If this is pc-relative and we are going to emit a relocation
22728 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22729 will need. Otherwise we want to use the calculated base.
22730 For WinCE we skip the bias for externals as well, since this
22731 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22732 if (fixP->fx_pcrel
2fc8bdac 22733 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22734 || (arm_force_relocation (fixP)
22735#ifdef TE_WINCE
22736 && !S_IS_EXTERNAL (fixP->fx_addsy)
22737#endif
22738 )))
2fc8bdac 22739 base = 0;
bfae80f2 22740
267bf995 22741
c19d1205 22742 switch (fixP->fx_r_type)
bfae80f2 22743 {
2fc8bdac
ZW
22744 /* PC relative addressing on the Thumb is slightly odd as the
22745 bottom two bits of the PC are forced to zero for the
22746 calculation. This happens *after* application of the
22747 pipeline offset. However, Thumb adrl already adjusts for
22748 this, so we need not do it again. */
c19d1205 22749 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22750 return base & ~3;
c19d1205
ZW
22751
22752 case BFD_RELOC_ARM_THUMB_OFFSET:
22753 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22754 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22755 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22756 return (base + 4) & ~3;
c19d1205 22757
2fc8bdac
ZW
22758 /* Thumb branches are simply offset by +4. */
22759 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22760 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22761 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22762 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22763 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22764 return base + 4;
bfae80f2 22765
267bf995 22766 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22767 if (fixP->fx_addsy
22768 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22769 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22770 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22771 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22772 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22773 return base + 4;
22774
00adf2d4
JB
22775 /* BLX is like branches above, but forces the low two bits of PC to
22776 zero. */
486499d0
CL
22777 case BFD_RELOC_THUMB_PCREL_BLX:
22778 if (fixP->fx_addsy
22779 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22780 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22781 && THUMB_IS_FUNC (fixP->fx_addsy)
22782 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22783 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22784 return (base + 4) & ~3;
22785
2fc8bdac
ZW
22786 /* ARM mode branches are offset by +8. However, the Windows CE
22787 loader expects the relocation not to take this into account. */
267bf995 22788 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22789 if (fixP->fx_addsy
22790 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22791 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22792 && ARM_IS_FUNC (fixP->fx_addsy)
22793 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22794 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22795 return base + 8;
267bf995 22796
486499d0
CL
22797 case BFD_RELOC_ARM_PCREL_CALL:
22798 if (fixP->fx_addsy
22799 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22800 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22801 && THUMB_IS_FUNC (fixP->fx_addsy)
22802 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22803 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22804 return base + 8;
267bf995 22805
2fc8bdac 22806 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22807 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22808 case BFD_RELOC_ARM_PLT32:
c19d1205 22809#ifdef TE_WINCE
5f4273c7 22810 /* When handling fixups immediately, because we have already
477330fc 22811 discovered the value of a symbol, or the address of the frag involved
53baae48 22812 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22813 see fixup_segment() in write.c
22814 The S_IS_EXTERNAL test handles the case of global symbols.
22815 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22816 if (fixP->fx_pcrel
22817 && fixP->fx_addsy != NULL
22818 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22819 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22820 return base + 8;
2fc8bdac 22821 return base;
c19d1205 22822#else
2fc8bdac 22823 return base + 8;
c19d1205 22824#endif
2fc8bdac 22825
267bf995 22826
2fc8bdac
ZW
22827 /* ARM mode loads relative to PC are also offset by +8. Unlike
22828 branches, the Windows CE loader *does* expect the relocation
22829 to take this into account. */
22830 case BFD_RELOC_ARM_OFFSET_IMM:
22831 case BFD_RELOC_ARM_OFFSET_IMM8:
22832 case BFD_RELOC_ARM_HWLITERAL:
22833 case BFD_RELOC_ARM_LITERAL:
22834 case BFD_RELOC_ARM_CP_OFF_IMM:
22835 return base + 8;
22836
22837
22838 /* Other PC-relative relocations are un-offset. */
22839 default:
22840 return base;
22841 }
bfae80f2
RE
22842}
22843
8b2d793c
NC
22844static bfd_boolean flag_warn_syms = TRUE;
22845
ae8714c2
NC
22846bfd_boolean
22847arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22848{
8b2d793c
NC
22849 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22850 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22851 does mean that the resulting code might be very confusing to the reader.
22852 Also this warning can be triggered if the user omits an operand before
22853 an immediate address, eg:
22854
22855 LDR =foo
22856
22857 GAS treats this as an assignment of the value of the symbol foo to a
22858 symbol LDR, and so (without this code) it will not issue any kind of
22859 warning or error message.
22860
22861 Note - ARM instructions are case-insensitive but the strings in the hash
22862 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22863 lower case too. */
22864 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22865 {
22866 char * nbuf = strdup (name);
22867 char * p;
22868
22869 for (p = nbuf; *p; p++)
22870 *p = TOLOWER (*p);
22871 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22872 {
22873 static struct hash_control * already_warned = NULL;
22874
22875 if (already_warned == NULL)
22876 already_warned = hash_new ();
22877 /* Only warn about the symbol once. To keep the code
22878 simple we let hash_insert do the lookup for us. */
22879 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22880 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22881 }
22882 else
22883 free (nbuf);
22884 }
3739860c 22885
ae8714c2
NC
22886 return FALSE;
22887}
22888
22889/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22890 Otherwise we have no need to default values of symbols. */
22891
22892symbolS *
22893md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22894{
22895#ifdef OBJ_ELF
22896 if (name[0] == '_' && name[1] == 'G'
22897 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22898 {
22899 if (!GOT_symbol)
22900 {
22901 if (symbol_find (name))
22902 as_bad (_("GOT already in the symbol table"));
22903
22904 GOT_symbol = symbol_new (name, undefined_section,
22905 (valueT) 0, & zero_address_frag);
22906 }
22907
22908 return GOT_symbol;
22909 }
22910#endif
22911
c921be7d 22912 return NULL;
bfae80f2
RE
22913}
22914
55cf6793 22915/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22916 computed as two separate immediate values, added together. We
22917 already know that this value cannot be computed by just one ARM
22918 instruction. */
22919
22920static unsigned int
22921validate_immediate_twopart (unsigned int val,
22922 unsigned int * highpart)
bfae80f2 22923{
c19d1205
ZW
22924 unsigned int a;
22925 unsigned int i;
bfae80f2 22926
c19d1205
ZW
22927 for (i = 0; i < 32; i += 2)
22928 if (((a = rotate_left (val, i)) & 0xff) != 0)
22929 {
22930 if (a & 0xff00)
22931 {
22932 if (a & ~ 0xffff)
22933 continue;
22934 * highpart = (a >> 8) | ((i + 24) << 7);
22935 }
22936 else if (a & 0xff0000)
22937 {
22938 if (a & 0xff000000)
22939 continue;
22940 * highpart = (a >> 16) | ((i + 16) << 7);
22941 }
22942 else
22943 {
9c2799c2 22944 gas_assert (a & 0xff000000);
c19d1205
ZW
22945 * highpart = (a >> 24) | ((i + 8) << 7);
22946 }
bfae80f2 22947
c19d1205
ZW
22948 return (a & 0xff) | (i << 7);
22949 }
bfae80f2 22950
c19d1205 22951 return FAIL;
bfae80f2
RE
22952}
22953
c19d1205
ZW
22954static int
22955validate_offset_imm (unsigned int val, int hwse)
22956{
22957 if ((hwse && val > 255) || val > 4095)
22958 return FAIL;
22959 return val;
22960}
bfae80f2 22961
55cf6793 22962/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22963 negative immediate constant by altering the instruction. A bit of
22964 a hack really.
22965 MOV <-> MVN
22966 AND <-> BIC
22967 ADC <-> SBC
22968 by inverting the second operand, and
22969 ADD <-> SUB
22970 CMP <-> CMN
22971 by negating the second operand. */
bfae80f2 22972
c19d1205
ZW
22973static int
22974negate_data_op (unsigned long * instruction,
22975 unsigned long value)
bfae80f2 22976{
c19d1205
ZW
22977 int op, new_inst;
22978 unsigned long negated, inverted;
bfae80f2 22979
c19d1205
ZW
22980 negated = encode_arm_immediate (-value);
22981 inverted = encode_arm_immediate (~value);
bfae80f2 22982
c19d1205
ZW
22983 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22984 switch (op)
bfae80f2 22985 {
c19d1205
ZW
22986 /* First negates. */
22987 case OPCODE_SUB: /* ADD <-> SUB */
22988 new_inst = OPCODE_ADD;
22989 value = negated;
22990 break;
bfae80f2 22991
c19d1205
ZW
22992 case OPCODE_ADD:
22993 new_inst = OPCODE_SUB;
22994 value = negated;
22995 break;
bfae80f2 22996
c19d1205
ZW
22997 case OPCODE_CMP: /* CMP <-> CMN */
22998 new_inst = OPCODE_CMN;
22999 value = negated;
23000 break;
bfae80f2 23001
c19d1205
ZW
23002 case OPCODE_CMN:
23003 new_inst = OPCODE_CMP;
23004 value = negated;
23005 break;
bfae80f2 23006
c19d1205
ZW
23007 /* Now Inverted ops. */
23008 case OPCODE_MOV: /* MOV <-> MVN */
23009 new_inst = OPCODE_MVN;
23010 value = inverted;
23011 break;
bfae80f2 23012
c19d1205
ZW
23013 case OPCODE_MVN:
23014 new_inst = OPCODE_MOV;
23015 value = inverted;
23016 break;
bfae80f2 23017
c19d1205
ZW
23018 case OPCODE_AND: /* AND <-> BIC */
23019 new_inst = OPCODE_BIC;
23020 value = inverted;
23021 break;
bfae80f2 23022
c19d1205
ZW
23023 case OPCODE_BIC:
23024 new_inst = OPCODE_AND;
23025 value = inverted;
23026 break;
bfae80f2 23027
c19d1205
ZW
23028 case OPCODE_ADC: /* ADC <-> SBC */
23029 new_inst = OPCODE_SBC;
23030 value = inverted;
23031 break;
bfae80f2 23032
c19d1205
ZW
23033 case OPCODE_SBC:
23034 new_inst = OPCODE_ADC;
23035 value = inverted;
23036 break;
bfae80f2 23037
c19d1205
ZW
23038 /* We cannot do anything. */
23039 default:
23040 return FAIL;
b99bd4ef
NC
23041 }
23042
c19d1205
ZW
23043 if (value == (unsigned) FAIL)
23044 return FAIL;
23045
23046 *instruction &= OPCODE_MASK;
23047 *instruction |= new_inst << DATA_OP_SHIFT;
23048 return value;
b99bd4ef
NC
23049}
23050
ef8d22e6
PB
23051/* Like negate_data_op, but for Thumb-2. */
23052
23053static unsigned int
16dd5e42 23054thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
23055{
23056 int op, new_inst;
23057 int rd;
16dd5e42 23058 unsigned int negated, inverted;
ef8d22e6
PB
23059
23060 negated = encode_thumb32_immediate (-value);
23061 inverted = encode_thumb32_immediate (~value);
23062
23063 rd = (*instruction >> 8) & 0xf;
23064 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23065 switch (op)
23066 {
23067 /* ADD <-> SUB. Includes CMP <-> CMN. */
23068 case T2_OPCODE_SUB:
23069 new_inst = T2_OPCODE_ADD;
23070 value = negated;
23071 break;
23072
23073 case T2_OPCODE_ADD:
23074 new_inst = T2_OPCODE_SUB;
23075 value = negated;
23076 break;
23077
23078 /* ORR <-> ORN. Includes MOV <-> MVN. */
23079 case T2_OPCODE_ORR:
23080 new_inst = T2_OPCODE_ORN;
23081 value = inverted;
23082 break;
23083
23084 case T2_OPCODE_ORN:
23085 new_inst = T2_OPCODE_ORR;
23086 value = inverted;
23087 break;
23088
23089 /* AND <-> BIC. TST has no inverted equivalent. */
23090 case T2_OPCODE_AND:
23091 new_inst = T2_OPCODE_BIC;
23092 if (rd == 15)
23093 value = FAIL;
23094 else
23095 value = inverted;
23096 break;
23097
23098 case T2_OPCODE_BIC:
23099 new_inst = T2_OPCODE_AND;
23100 value = inverted;
23101 break;
23102
23103 /* ADC <-> SBC */
23104 case T2_OPCODE_ADC:
23105 new_inst = T2_OPCODE_SBC;
23106 value = inverted;
23107 break;
23108
23109 case T2_OPCODE_SBC:
23110 new_inst = T2_OPCODE_ADC;
23111 value = inverted;
23112 break;
23113
23114 /* We cannot do anything. */
23115 default:
23116 return FAIL;
23117 }
23118
16dd5e42 23119 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23120 return FAIL;
23121
23122 *instruction &= T2_OPCODE_MASK;
23123 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23124 return value;
23125}
23126
8f06b2d8 23127/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23128
8f06b2d8
PB
23129static unsigned long
23130get_thumb32_insn (char * buf)
23131{
23132 unsigned long insn;
23133 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23134 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23135
23136 return insn;
23137}
23138
a8bc6c78
PB
23139/* We usually want to set the low bit on the address of thumb function
23140 symbols. In particular .word foo - . should have the low bit set.
23141 Generic code tries to fold the difference of two symbols to
23142 a constant. Prevent this and force a relocation when the first symbols
23143 is a thumb function. */
c921be7d
NC
23144
23145bfd_boolean
a8bc6c78
PB
23146arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23147{
23148 if (op == O_subtract
23149 && l->X_op == O_symbol
23150 && r->X_op == O_symbol
23151 && THUMB_IS_FUNC (l->X_add_symbol))
23152 {
23153 l->X_op = O_subtract;
23154 l->X_op_symbol = r->X_add_symbol;
23155 l->X_add_number -= r->X_add_number;
c921be7d 23156 return TRUE;
a8bc6c78 23157 }
c921be7d 23158
a8bc6c78 23159 /* Process as normal. */
c921be7d 23160 return FALSE;
a8bc6c78
PB
23161}
23162
4a42ebbc
RR
23163/* Encode Thumb2 unconditional branches and calls. The encoding
23164 for the 2 are identical for the immediate values. */
23165
23166static void
23167encode_thumb2_b_bl_offset (char * buf, offsetT value)
23168{
23169#define T2I1I2MASK ((1 << 13) | (1 << 11))
23170 offsetT newval;
23171 offsetT newval2;
23172 addressT S, I1, I2, lo, hi;
23173
23174 S = (value >> 24) & 0x01;
23175 I1 = (value >> 23) & 0x01;
23176 I2 = (value >> 22) & 0x01;
23177 hi = (value >> 12) & 0x3ff;
fa94de6b 23178 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23179 newval = md_chars_to_number (buf, THUMB_SIZE);
23180 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23181 newval |= (S << 10) | hi;
23182 newval2 &= ~T2I1I2MASK;
23183 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23184 md_number_to_chars (buf, newval, THUMB_SIZE);
23185 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23186}
23187
c19d1205 23188void
55cf6793 23189md_apply_fix (fixS * fixP,
c19d1205
ZW
23190 valueT * valP,
23191 segT seg)
23192{
23193 offsetT value = * valP;
23194 offsetT newval;
23195 unsigned int newimm;
23196 unsigned long temp;
23197 int sign;
23198 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23199
9c2799c2 23200 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23201
c19d1205 23202 /* Note whether this will delete the relocation. */
4962c51a 23203
c19d1205
ZW
23204 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23205 fixP->fx_done = 1;
b99bd4ef 23206
adbaf948 23207 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23208 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23209 for emit_reloc. */
23210 value &= 0xffffffff;
23211 value ^= 0x80000000;
5f4273c7 23212 value -= 0x80000000;
adbaf948
ZW
23213
23214 *valP = value;
c19d1205 23215 fixP->fx_addnumber = value;
b99bd4ef 23216
adbaf948
ZW
23217 /* Same treatment for fixP->fx_offset. */
23218 fixP->fx_offset &= 0xffffffff;
23219 fixP->fx_offset ^= 0x80000000;
23220 fixP->fx_offset -= 0x80000000;
23221
c19d1205 23222 switch (fixP->fx_r_type)
b99bd4ef 23223 {
c19d1205
ZW
23224 case BFD_RELOC_NONE:
23225 /* This will need to go in the object file. */
23226 fixP->fx_done = 0;
23227 break;
b99bd4ef 23228
c19d1205
ZW
23229 case BFD_RELOC_ARM_IMMEDIATE:
23230 /* We claim that this fixup has been processed here,
23231 even if in fact we generate an error because we do
23232 not have a reloc for it, so tc_gen_reloc will reject it. */
23233 fixP->fx_done = 1;
b99bd4ef 23234
77db8e2e 23235 if (fixP->fx_addsy)
b99bd4ef 23236 {
77db8e2e 23237 const char *msg = 0;
b99bd4ef 23238
77db8e2e
NC
23239 if (! S_IS_DEFINED (fixP->fx_addsy))
23240 msg = _("undefined symbol %s used as an immediate value");
23241 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23242 msg = _("symbol %s is in a different section");
23243 else if (S_IS_WEAK (fixP->fx_addsy))
23244 msg = _("symbol %s is weak and may be overridden later");
23245
23246 if (msg)
23247 {
23248 as_bad_where (fixP->fx_file, fixP->fx_line,
23249 msg, S_GET_NAME (fixP->fx_addsy));
23250 break;
23251 }
42e5fcbf
AS
23252 }
23253
c19d1205
ZW
23254 temp = md_chars_to_number (buf, INSN_SIZE);
23255
5e73442d
SL
23256 /* If the offset is negative, we should use encoding A2 for ADR. */
23257 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23258 newimm = negate_data_op (&temp, value);
23259 else
23260 {
23261 newimm = encode_arm_immediate (value);
23262
23263 /* If the instruction will fail, see if we can fix things up by
23264 changing the opcode. */
23265 if (newimm == (unsigned int) FAIL)
23266 newimm = negate_data_op (&temp, value);
bada4342
JW
23267 /* MOV accepts both ARM modified immediate (A1 encoding) and
23268 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23269 When disassembling, MOV is preferred when there is no encoding
23270 overlap. */
23271 if (newimm == (unsigned int) FAIL
23272 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23273 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23274 && !((temp >> SBIT_SHIFT) & 0x1)
23275 && value >= 0 && value <= 0xffff)
23276 {
23277 /* Clear bits[23:20] to change encoding from A1 to A2. */
23278 temp &= 0xff0fffff;
23279 /* Encoding high 4bits imm. Code below will encode the remaining
23280 low 12bits. */
23281 temp |= (value & 0x0000f000) << 4;
23282 newimm = value & 0x00000fff;
23283 }
5e73442d
SL
23284 }
23285
23286 if (newimm == (unsigned int) FAIL)
b99bd4ef 23287 {
c19d1205
ZW
23288 as_bad_where (fixP->fx_file, fixP->fx_line,
23289 _("invalid constant (%lx) after fixup"),
23290 (unsigned long) value);
23291 break;
b99bd4ef 23292 }
b99bd4ef 23293
c19d1205
ZW
23294 newimm |= (temp & 0xfffff000);
23295 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23296 break;
b99bd4ef 23297
c19d1205
ZW
23298 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23299 {
23300 unsigned int highpart = 0;
23301 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23302
77db8e2e 23303 if (fixP->fx_addsy)
42e5fcbf 23304 {
77db8e2e 23305 const char *msg = 0;
42e5fcbf 23306
77db8e2e
NC
23307 if (! S_IS_DEFINED (fixP->fx_addsy))
23308 msg = _("undefined symbol %s used as an immediate value");
23309 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23310 msg = _("symbol %s is in a different section");
23311 else if (S_IS_WEAK (fixP->fx_addsy))
23312 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23313
77db8e2e
NC
23314 if (msg)
23315 {
23316 as_bad_where (fixP->fx_file, fixP->fx_line,
23317 msg, S_GET_NAME (fixP->fx_addsy));
23318 break;
23319 }
23320 }
fa94de6b 23321
c19d1205
ZW
23322 newimm = encode_arm_immediate (value);
23323 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23324
c19d1205
ZW
23325 /* If the instruction will fail, see if we can fix things up by
23326 changing the opcode. */
23327 if (newimm == (unsigned int) FAIL
23328 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23329 {
23330 /* No ? OK - try using two ADD instructions to generate
23331 the value. */
23332 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23333
c19d1205
ZW
23334 /* Yes - then make sure that the second instruction is
23335 also an add. */
23336 if (newimm != (unsigned int) FAIL)
23337 newinsn = temp;
23338 /* Still No ? Try using a negated value. */
23339 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23340 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23341 /* Otherwise - give up. */
23342 else
23343 {
23344 as_bad_where (fixP->fx_file, fixP->fx_line,
23345 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23346 (long) value);
23347 break;
23348 }
b99bd4ef 23349
c19d1205
ZW
23350 /* Replace the first operand in the 2nd instruction (which
23351 is the PC) with the destination register. We have
23352 already added in the PC in the first instruction and we
23353 do not want to do it again. */
23354 newinsn &= ~ 0xf0000;
23355 newinsn |= ((newinsn & 0x0f000) << 4);
23356 }
b99bd4ef 23357
c19d1205
ZW
23358 newimm |= (temp & 0xfffff000);
23359 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23360
c19d1205
ZW
23361 highpart |= (newinsn & 0xfffff000);
23362 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23363 }
23364 break;
b99bd4ef 23365
c19d1205 23366 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23367 if (!fixP->fx_done && seg->use_rela_p)
23368 value = 0;
1a0670f3 23369 /* Fall through. */
00a97672 23370
c19d1205 23371 case BFD_RELOC_ARM_LITERAL:
26d97720 23372 sign = value > 0;
b99bd4ef 23373
c19d1205
ZW
23374 if (value < 0)
23375 value = - value;
b99bd4ef 23376
c19d1205 23377 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23378 {
c19d1205
ZW
23379 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23380 as_bad_where (fixP->fx_file, fixP->fx_line,
23381 _("invalid literal constant: pool needs to be closer"));
23382 else
23383 as_bad_where (fixP->fx_file, fixP->fx_line,
23384 _("bad immediate value for offset (%ld)"),
23385 (long) value);
23386 break;
f03698e6
RE
23387 }
23388
c19d1205 23389 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23390 if (value == 0)
23391 newval &= 0xfffff000;
23392 else
23393 {
23394 newval &= 0xff7ff000;
23395 newval |= value | (sign ? INDEX_UP : 0);
23396 }
c19d1205
ZW
23397 md_number_to_chars (buf, newval, INSN_SIZE);
23398 break;
b99bd4ef 23399
c19d1205
ZW
23400 case BFD_RELOC_ARM_OFFSET_IMM8:
23401 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23402 sign = value > 0;
b99bd4ef 23403
c19d1205
ZW
23404 if (value < 0)
23405 value = - value;
b99bd4ef 23406
c19d1205 23407 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23408 {
c19d1205
ZW
23409 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23410 as_bad_where (fixP->fx_file, fixP->fx_line,
23411 _("invalid literal constant: pool needs to be closer"));
23412 else
427d0db6
RM
23413 as_bad_where (fixP->fx_file, fixP->fx_line,
23414 _("bad immediate value for 8-bit offset (%ld)"),
23415 (long) value);
c19d1205 23416 break;
b99bd4ef
NC
23417 }
23418
c19d1205 23419 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23420 if (value == 0)
23421 newval &= 0xfffff0f0;
23422 else
23423 {
23424 newval &= 0xff7ff0f0;
23425 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23426 }
c19d1205
ZW
23427 md_number_to_chars (buf, newval, INSN_SIZE);
23428 break;
b99bd4ef 23429
c19d1205
ZW
23430 case BFD_RELOC_ARM_T32_OFFSET_U8:
23431 if (value < 0 || value > 1020 || value % 4 != 0)
23432 as_bad_where (fixP->fx_file, fixP->fx_line,
23433 _("bad immediate value for offset (%ld)"), (long) value);
23434 value /= 4;
b99bd4ef 23435
c19d1205 23436 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23437 newval |= value;
23438 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23439 break;
b99bd4ef 23440
c19d1205
ZW
23441 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23442 /* This is a complicated relocation used for all varieties of Thumb32
23443 load/store instruction with immediate offset:
23444
23445 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23446 *4, optional writeback(W)
c19d1205
ZW
23447 (doubleword load/store)
23448
23449 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23450 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23451 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23452 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23453 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23454
23455 Uppercase letters indicate bits that are already encoded at
23456 this point. Lowercase letters are our problem. For the
23457 second block of instructions, the secondary opcode nybble
23458 (bits 8..11) is present, and bit 23 is zero, even if this is
23459 a PC-relative operation. */
23460 newval = md_chars_to_number (buf, THUMB_SIZE);
23461 newval <<= 16;
23462 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23463
c19d1205 23464 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23465 {
c19d1205
ZW
23466 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23467 if (value >= 0)
23468 newval |= (1 << 23);
23469 else
23470 value = -value;
23471 if (value % 4 != 0)
23472 {
23473 as_bad_where (fixP->fx_file, fixP->fx_line,
23474 _("offset not a multiple of 4"));
23475 break;
23476 }
23477 value /= 4;
216d22bc 23478 if (value > 0xff)
c19d1205
ZW
23479 {
23480 as_bad_where (fixP->fx_file, fixP->fx_line,
23481 _("offset out of range"));
23482 break;
23483 }
23484 newval &= ~0xff;
b99bd4ef 23485 }
c19d1205 23486 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23487 {
c19d1205
ZW
23488 /* PC-relative, 12-bit offset. */
23489 if (value >= 0)
23490 newval |= (1 << 23);
23491 else
23492 value = -value;
216d22bc 23493 if (value > 0xfff)
c19d1205
ZW
23494 {
23495 as_bad_where (fixP->fx_file, fixP->fx_line,
23496 _("offset out of range"));
23497 break;
23498 }
23499 newval &= ~0xfff;
b99bd4ef 23500 }
c19d1205 23501 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23502 {
c19d1205
ZW
23503 /* Writeback: 8-bit, +/- offset. */
23504 if (value >= 0)
23505 newval |= (1 << 9);
23506 else
23507 value = -value;
216d22bc 23508 if (value > 0xff)
c19d1205
ZW
23509 {
23510 as_bad_where (fixP->fx_file, fixP->fx_line,
23511 _("offset out of range"));
23512 break;
23513 }
23514 newval &= ~0xff;
b99bd4ef 23515 }
c19d1205 23516 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23517 {
c19d1205 23518 /* T-instruction: positive 8-bit offset. */
216d22bc 23519 if (value < 0 || value > 0xff)
b99bd4ef 23520 {
c19d1205
ZW
23521 as_bad_where (fixP->fx_file, fixP->fx_line,
23522 _("offset out of range"));
23523 break;
b99bd4ef 23524 }
c19d1205
ZW
23525 newval &= ~0xff;
23526 newval |= value;
b99bd4ef
NC
23527 }
23528 else
b99bd4ef 23529 {
c19d1205
ZW
23530 /* Positive 12-bit or negative 8-bit offset. */
23531 int limit;
23532 if (value >= 0)
b99bd4ef 23533 {
c19d1205
ZW
23534 newval |= (1 << 23);
23535 limit = 0xfff;
23536 }
23537 else
23538 {
23539 value = -value;
23540 limit = 0xff;
23541 }
23542 if (value > limit)
23543 {
23544 as_bad_where (fixP->fx_file, fixP->fx_line,
23545 _("offset out of range"));
23546 break;
b99bd4ef 23547 }
c19d1205 23548 newval &= ~limit;
b99bd4ef 23549 }
b99bd4ef 23550
c19d1205
ZW
23551 newval |= value;
23552 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23553 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23554 break;
404ff6b5 23555
c19d1205
ZW
23556 case BFD_RELOC_ARM_SHIFT_IMM:
23557 newval = md_chars_to_number (buf, INSN_SIZE);
23558 if (((unsigned long) value) > 32
23559 || (value == 32
23560 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23561 {
23562 as_bad_where (fixP->fx_file, fixP->fx_line,
23563 _("shift expression is too large"));
23564 break;
23565 }
404ff6b5 23566
c19d1205
ZW
23567 if (value == 0)
23568 /* Shifts of zero must be done as lsl. */
23569 newval &= ~0x60;
23570 else if (value == 32)
23571 value = 0;
23572 newval &= 0xfffff07f;
23573 newval |= (value & 0x1f) << 7;
23574 md_number_to_chars (buf, newval, INSN_SIZE);
23575 break;
404ff6b5 23576
c19d1205 23577 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23578 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23579 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23580 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23581 /* We claim that this fixup has been processed here,
23582 even if in fact we generate an error because we do
23583 not have a reloc for it, so tc_gen_reloc will reject it. */
23584 fixP->fx_done = 1;
404ff6b5 23585
c19d1205
ZW
23586 if (fixP->fx_addsy
23587 && ! S_IS_DEFINED (fixP->fx_addsy))
23588 {
23589 as_bad_where (fixP->fx_file, fixP->fx_line,
23590 _("undefined symbol %s used as an immediate value"),
23591 S_GET_NAME (fixP->fx_addsy));
23592 break;
23593 }
404ff6b5 23594
c19d1205
ZW
23595 newval = md_chars_to_number (buf, THUMB_SIZE);
23596 newval <<= 16;
23597 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23598
16805f35 23599 newimm = FAIL;
bada4342
JW
23600 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23601 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23602 Thumb2 modified immediate encoding (T2). */
23603 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23604 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23605 {
23606 newimm = encode_thumb32_immediate (value);
23607 if (newimm == (unsigned int) FAIL)
23608 newimm = thumb32_negate_data_op (&newval, value);
23609 }
bada4342 23610 if (newimm == (unsigned int) FAIL)
92e90b6e 23611 {
bada4342 23612 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23613 {
bada4342
JW
23614 /* Turn add/sum into addw/subw. */
23615 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23616 newval = (newval & 0xfeffffff) | 0x02000000;
23617 /* No flat 12-bit imm encoding for addsw/subsw. */
23618 if ((newval & 0x00100000) == 0)
40f246e3 23619 {
bada4342
JW
23620 /* 12 bit immediate for addw/subw. */
23621 if (value < 0)
23622 {
23623 value = -value;
23624 newval ^= 0x00a00000;
23625 }
23626 if (value > 0xfff)
23627 newimm = (unsigned int) FAIL;
23628 else
23629 newimm = value;
23630 }
23631 }
23632 else
23633 {
23634 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23635 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23636 disassembling, MOV is preferred when there is no encoding
db7bf105 23637 overlap. */
bada4342 23638 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
db7bf105
NC
23639 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23640 but with the Rn field [19:16] set to 1111. */
23641 && (((newval >> 16) & 0xf) == 0xf)
bada4342
JW
23642 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23643 && !((newval >> T2_SBIT_SHIFT) & 0x1)
db7bf105 23644 && value >= 0 && value <= 0xffff)
bada4342
JW
23645 {
23646 /* Toggle bit[25] to change encoding from T2 to T3. */
23647 newval ^= 1 << 25;
23648 /* Clear bits[19:16]. */
23649 newval &= 0xfff0ffff;
23650 /* Encoding high 4bits imm. Code below will encode the
23651 remaining low 12bits. */
23652 newval |= (value & 0x0000f000) << 4;
23653 newimm = value & 0x00000fff;
40f246e3 23654 }
e9f89963 23655 }
92e90b6e 23656 }
cc8a6dd0 23657
c19d1205 23658 if (newimm == (unsigned int)FAIL)
3631a3c8 23659 {
c19d1205
ZW
23660 as_bad_where (fixP->fx_file, fixP->fx_line,
23661 _("invalid constant (%lx) after fixup"),
23662 (unsigned long) value);
23663 break;
3631a3c8
NC
23664 }
23665
c19d1205
ZW
23666 newval |= (newimm & 0x800) << 15;
23667 newval |= (newimm & 0x700) << 4;
23668 newval |= (newimm & 0x0ff);
cc8a6dd0 23669
c19d1205
ZW
23670 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23671 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23672 break;
a737bd4d 23673
3eb17e6b 23674 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23675 if (((unsigned long) value) > 0xffff)
23676 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23677 _("invalid smc expression"));
2fc8bdac 23678 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23679 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23680 md_number_to_chars (buf, newval, INSN_SIZE);
23681 break;
a737bd4d 23682
90ec0d68
MGD
23683 case BFD_RELOC_ARM_HVC:
23684 if (((unsigned long) value) > 0xffff)
23685 as_bad_where (fixP->fx_file, fixP->fx_line,
23686 _("invalid hvc expression"));
23687 newval = md_chars_to_number (buf, INSN_SIZE);
23688 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23689 md_number_to_chars (buf, newval, INSN_SIZE);
23690 break;
23691
c19d1205 23692 case BFD_RELOC_ARM_SWI:
adbaf948 23693 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23694 {
23695 if (((unsigned long) value) > 0xff)
23696 as_bad_where (fixP->fx_file, fixP->fx_line,
23697 _("invalid swi expression"));
2fc8bdac 23698 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23699 newval |= value;
23700 md_number_to_chars (buf, newval, THUMB_SIZE);
23701 }
23702 else
23703 {
23704 if (((unsigned long) value) > 0x00ffffff)
23705 as_bad_where (fixP->fx_file, fixP->fx_line,
23706 _("invalid swi expression"));
2fc8bdac 23707 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23708 newval |= value;
23709 md_number_to_chars (buf, newval, INSN_SIZE);
23710 }
23711 break;
a737bd4d 23712
c19d1205
ZW
23713 case BFD_RELOC_ARM_MULTI:
23714 if (((unsigned long) value) > 0xffff)
23715 as_bad_where (fixP->fx_file, fixP->fx_line,
23716 _("invalid expression in load/store multiple"));
23717 newval = value | md_chars_to_number (buf, INSN_SIZE);
23718 md_number_to_chars (buf, newval, INSN_SIZE);
23719 break;
a737bd4d 23720
c19d1205 23721#ifdef OBJ_ELF
39b41c9c 23722 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23723
23724 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23725 && fixP->fx_addsy
34e77a92 23726 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23727 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23728 && THUMB_IS_FUNC (fixP->fx_addsy))
23729 /* Flip the bl to blx. This is a simple flip
23730 bit here because we generate PCREL_CALL for
23731 unconditional bls. */
23732 {
23733 newval = md_chars_to_number (buf, INSN_SIZE);
23734 newval = newval | 0x10000000;
23735 md_number_to_chars (buf, newval, INSN_SIZE);
23736 temp = 1;
23737 fixP->fx_done = 1;
23738 }
39b41c9c
PB
23739 else
23740 temp = 3;
23741 goto arm_branch_common;
23742
23743 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23744 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23745 && fixP->fx_addsy
34e77a92 23746 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23747 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23748 && THUMB_IS_FUNC (fixP->fx_addsy))
23749 {
23750 /* This would map to a bl<cond>, b<cond>,
23751 b<always> to a Thumb function. We
23752 need to force a relocation for this particular
23753 case. */
23754 newval = md_chars_to_number (buf, INSN_SIZE);
23755 fixP->fx_done = 0;
23756 }
1a0670f3 23757 /* Fall through. */
267bf995 23758
2fc8bdac 23759 case BFD_RELOC_ARM_PLT32:
c19d1205 23760#endif
39b41c9c
PB
23761 case BFD_RELOC_ARM_PCREL_BRANCH:
23762 temp = 3;
23763 goto arm_branch_common;
a737bd4d 23764
39b41c9c 23765 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23766
39b41c9c 23767 temp = 1;
267bf995
RR
23768 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23769 && fixP->fx_addsy
34e77a92 23770 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23771 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23772 && ARM_IS_FUNC (fixP->fx_addsy))
23773 {
23774 /* Flip the blx to a bl and warn. */
23775 const char *name = S_GET_NAME (fixP->fx_addsy);
23776 newval = 0xeb000000;
23777 as_warn_where (fixP->fx_file, fixP->fx_line,
23778 _("blx to '%s' an ARM ISA state function changed to bl"),
23779 name);
23780 md_number_to_chars (buf, newval, INSN_SIZE);
23781 temp = 3;
23782 fixP->fx_done = 1;
23783 }
23784
23785#ifdef OBJ_ELF
23786 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23787 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23788#endif
23789
39b41c9c 23790 arm_branch_common:
c19d1205 23791 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23792 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23793 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23794 also be clear. */
39b41c9c 23795 if (value & temp)
c19d1205 23796 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23797 _("misaligned branch destination"));
23798 if ((value & (offsetT)0xfe000000) != (offsetT)0
23799 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23800 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23801
2fc8bdac 23802 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23803 {
2fc8bdac
ZW
23804 newval = md_chars_to_number (buf, INSN_SIZE);
23805 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23806 /* Set the H bit on BLX instructions. */
23807 if (temp == 1)
23808 {
23809 if (value & 2)
23810 newval |= 0x01000000;
23811 else
23812 newval &= ~0x01000000;
23813 }
2fc8bdac 23814 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23815 }
c19d1205 23816 break;
a737bd4d 23817
25fe350b
MS
23818 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23819 /* CBZ can only branch forward. */
a737bd4d 23820
738755b0 23821 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23822 (which, strictly speaking, are prohibited) will be turned into
23823 no-ops.
738755b0
MS
23824
23825 FIXME: It may be better to remove the instruction completely and
23826 perform relaxation. */
23827 if (value == -2)
2fc8bdac
ZW
23828 {
23829 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23830 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23831 md_number_to_chars (buf, newval, THUMB_SIZE);
23832 }
738755b0
MS
23833 else
23834 {
23835 if (value & ~0x7e)
08f10d51 23836 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23837
477330fc 23838 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23839 {
23840 newval = md_chars_to_number (buf, THUMB_SIZE);
23841 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23842 md_number_to_chars (buf, newval, THUMB_SIZE);
23843 }
23844 }
c19d1205 23845 break;
a737bd4d 23846
c19d1205 23847 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23848 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23849 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23850
2fc8bdac
ZW
23851 if (fixP->fx_done || !seg->use_rela_p)
23852 {
23853 newval = md_chars_to_number (buf, THUMB_SIZE);
23854 newval |= (value & 0x1ff) >> 1;
23855 md_number_to_chars (buf, newval, THUMB_SIZE);
23856 }
c19d1205 23857 break;
a737bd4d 23858
c19d1205 23859 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23860 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23861 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23862
2fc8bdac
ZW
23863 if (fixP->fx_done || !seg->use_rela_p)
23864 {
23865 newval = md_chars_to_number (buf, THUMB_SIZE);
23866 newval |= (value & 0xfff) >> 1;
23867 md_number_to_chars (buf, newval, THUMB_SIZE);
23868 }
c19d1205 23869 break;
a737bd4d 23870
c19d1205 23871 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23872 if (fixP->fx_addsy
23873 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23874 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23875 && ARM_IS_FUNC (fixP->fx_addsy)
23876 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23877 {
23878 /* Force a relocation for a branch 20 bits wide. */
23879 fixP->fx_done = 0;
23880 }
08f10d51 23881 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23882 as_bad_where (fixP->fx_file, fixP->fx_line,
23883 _("conditional branch out of range"));
404ff6b5 23884
2fc8bdac
ZW
23885 if (fixP->fx_done || !seg->use_rela_p)
23886 {
23887 offsetT newval2;
23888 addressT S, J1, J2, lo, hi;
404ff6b5 23889
2fc8bdac
ZW
23890 S = (value & 0x00100000) >> 20;
23891 J2 = (value & 0x00080000) >> 19;
23892 J1 = (value & 0x00040000) >> 18;
23893 hi = (value & 0x0003f000) >> 12;
23894 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23895
2fc8bdac
ZW
23896 newval = md_chars_to_number (buf, THUMB_SIZE);
23897 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23898 newval |= (S << 10) | hi;
23899 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23900 md_number_to_chars (buf, newval, THUMB_SIZE);
23901 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23902 }
c19d1205 23903 break;
6c43fab6 23904
c19d1205 23905 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23906 /* If there is a blx from a thumb state function to
23907 another thumb function flip this to a bl and warn
23908 about it. */
23909
23910 if (fixP->fx_addsy
34e77a92 23911 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23912 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23913 && THUMB_IS_FUNC (fixP->fx_addsy))
23914 {
23915 const char *name = S_GET_NAME (fixP->fx_addsy);
23916 as_warn_where (fixP->fx_file, fixP->fx_line,
23917 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23918 name);
23919 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23920 newval = newval | 0x1000;
23921 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23922 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23923 fixP->fx_done = 1;
23924 }
23925
23926
23927 goto thumb_bl_common;
23928
c19d1205 23929 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23930 /* A bl from Thumb state ISA to an internal ARM state function
23931 is converted to a blx. */
23932 if (fixP->fx_addsy
23933 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23934 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23935 && ARM_IS_FUNC (fixP->fx_addsy)
23936 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23937 {
23938 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23939 newval = newval & ~0x1000;
23940 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23941 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23942 fixP->fx_done = 1;
23943 }
23944
23945 thumb_bl_common:
23946
2fc8bdac
ZW
23947 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23948 /* For a BLX instruction, make sure that the relocation is rounded up
23949 to a word boundary. This follows the semantics of the instruction
23950 which specifies that bit 1 of the target address will come from bit
23951 1 of the base address. */
d406f3e4
JB
23952 value = (value + 3) & ~ 3;
23953
23954#ifdef OBJ_ELF
23955 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23956 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23957 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23958#endif
404ff6b5 23959
2b2f5df9
NC
23960 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23961 {
fc289b0a 23962 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23963 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23964 else if ((value & ~0x1ffffff)
23965 && ((value & ~0x1ffffff) != ~0x1ffffff))
23966 as_bad_where (fixP->fx_file, fixP->fx_line,
23967 _("Thumb2 branch out of range"));
23968 }
4a42ebbc
RR
23969
23970 if (fixP->fx_done || !seg->use_rela_p)
23971 encode_thumb2_b_bl_offset (buf, value);
23972
c19d1205 23973 break;
404ff6b5 23974
c19d1205 23975 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23976 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23977 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23978
2fc8bdac 23979 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23980 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23981
2fc8bdac 23982 break;
a737bd4d 23983
2fc8bdac
ZW
23984 case BFD_RELOC_8:
23985 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23986 *buf = value;
c19d1205 23987 break;
a737bd4d 23988
c19d1205 23989 case BFD_RELOC_16:
2fc8bdac 23990 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23991 md_number_to_chars (buf, value, 2);
c19d1205 23992 break;
a737bd4d 23993
c19d1205 23994#ifdef OBJ_ELF
0855e32b
NS
23995 case BFD_RELOC_ARM_TLS_CALL:
23996 case BFD_RELOC_ARM_THM_TLS_CALL:
23997 case BFD_RELOC_ARM_TLS_DESCSEQ:
23998 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23999 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
24000 case BFD_RELOC_ARM_TLS_GD32:
24001 case BFD_RELOC_ARM_TLS_LE32:
24002 case BFD_RELOC_ARM_TLS_IE32:
24003 case BFD_RELOC_ARM_TLS_LDM32:
24004 case BFD_RELOC_ARM_TLS_LDO32:
24005 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 24006 break;
6c43fab6 24007
c19d1205
ZW
24008 case BFD_RELOC_ARM_GOT32:
24009 case BFD_RELOC_ARM_GOTOFF:
c19d1205 24010 break;
b43420e6
NC
24011
24012 case BFD_RELOC_ARM_GOT_PREL:
24013 if (fixP->fx_done || !seg->use_rela_p)
477330fc 24014 md_number_to_chars (buf, value, 4);
b43420e6
NC
24015 break;
24016
9a6f4e97
NS
24017 case BFD_RELOC_ARM_TARGET2:
24018 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
24019 addend here for REL targets, because it won't be written out
24020 during reloc processing later. */
9a6f4e97
NS
24021 if (fixP->fx_done || !seg->use_rela_p)
24022 md_number_to_chars (buf, fixP->fx_offset, 4);
24023 break;
c19d1205 24024#endif
6c43fab6 24025
c19d1205
ZW
24026 case BFD_RELOC_RVA:
24027 case BFD_RELOC_32:
24028 case BFD_RELOC_ARM_TARGET1:
24029 case BFD_RELOC_ARM_ROSEGREL32:
24030 case BFD_RELOC_ARM_SBREL32:
24031 case BFD_RELOC_32_PCREL:
f0927246
NC
24032#ifdef TE_PE
24033 case BFD_RELOC_32_SECREL:
24034#endif
2fc8bdac 24035 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
24036#ifdef TE_WINCE
24037 /* For WinCE we only do this for pcrel fixups. */
24038 if (fixP->fx_done || fixP->fx_pcrel)
24039#endif
24040 md_number_to_chars (buf, value, 4);
c19d1205 24041 break;
6c43fab6 24042
c19d1205
ZW
24043#ifdef OBJ_ELF
24044 case BFD_RELOC_ARM_PREL31:
2fc8bdac 24045 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
24046 {
24047 newval = md_chars_to_number (buf, 4) & 0x80000000;
24048 if ((value ^ (value >> 1)) & 0x40000000)
24049 {
24050 as_bad_where (fixP->fx_file, fixP->fx_line,
24051 _("rel31 relocation overflow"));
24052 }
24053 newval |= value & 0x7fffffff;
24054 md_number_to_chars (buf, newval, 4);
24055 }
24056 break;
c19d1205 24057#endif
a737bd4d 24058
c19d1205 24059 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 24060 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
24061 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24062 newval = md_chars_to_number (buf, INSN_SIZE);
24063 else
24064 newval = get_thumb32_insn (buf);
24065 if ((newval & 0x0f200f00) == 0x0d000900)
24066 {
24067 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24068 has permitted values that are multiples of 2, in the range 0
24069 to 510. */
24070 if (value < -510 || value > 510 || (value & 1))
24071 as_bad_where (fixP->fx_file, fixP->fx_line,
24072 _("co-processor offset out of range"));
24073 }
24074 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
24075 as_bad_where (fixP->fx_file, fixP->fx_line,
24076 _("co-processor offset out of range"));
24077 cp_off_common:
26d97720 24078 sign = value > 0;
c19d1205
ZW
24079 if (value < 0)
24080 value = -value;
8f06b2d8
PB
24081 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24082 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24083 newval = md_chars_to_number (buf, INSN_SIZE);
24084 else
24085 newval = get_thumb32_insn (buf);
26d97720
NS
24086 if (value == 0)
24087 newval &= 0xffffff00;
24088 else
24089 {
24090 newval &= 0xff7fff00;
9db2f6b4
RL
24091 if ((newval & 0x0f200f00) == 0x0d000900)
24092 {
24093 /* This is a fp16 vstr/vldr.
24094
24095 It requires the immediate offset in the instruction is shifted
24096 left by 1 to be a half-word offset.
24097
24098 Here, left shift by 1 first, and later right shift by 2
24099 should get the right offset. */
24100 value <<= 1;
24101 }
26d97720
NS
24102 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24103 }
8f06b2d8
PB
24104 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24105 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24106 md_number_to_chars (buf, newval, INSN_SIZE);
24107 else
24108 put_thumb32_insn (buf, newval);
c19d1205 24109 break;
a737bd4d 24110
c19d1205 24111 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24112 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24113 if (value < -255 || value > 255)
24114 as_bad_where (fixP->fx_file, fixP->fx_line,
24115 _("co-processor offset out of range"));
df7849c5 24116 value *= 4;
c19d1205 24117 goto cp_off_common;
6c43fab6 24118
c19d1205
ZW
24119 case BFD_RELOC_ARM_THUMB_OFFSET:
24120 newval = md_chars_to_number (buf, THUMB_SIZE);
24121 /* Exactly what ranges, and where the offset is inserted depends
24122 on the type of instruction, we can establish this from the
24123 top 4 bits. */
24124 switch (newval >> 12)
24125 {
24126 case 4: /* PC load. */
24127 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24128 forced to zero for these loads; md_pcrel_from has already
24129 compensated for this. */
24130 if (value & 3)
24131 as_bad_where (fixP->fx_file, fixP->fx_line,
24132 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24133 (((unsigned long) fixP->fx_frag->fr_address
24134 + (unsigned long) fixP->fx_where) & ~3)
24135 + (unsigned long) value);
a737bd4d 24136
c19d1205
ZW
24137 if (value & ~0x3fc)
24138 as_bad_where (fixP->fx_file, fixP->fx_line,
24139 _("invalid offset, value too big (0x%08lX)"),
24140 (long) value);
a737bd4d 24141
c19d1205
ZW
24142 newval |= value >> 2;
24143 break;
a737bd4d 24144
c19d1205
ZW
24145 case 9: /* SP load/store. */
24146 if (value & ~0x3fc)
24147 as_bad_where (fixP->fx_file, fixP->fx_line,
24148 _("invalid offset, value too big (0x%08lX)"),
24149 (long) value);
24150 newval |= value >> 2;
24151 break;
6c43fab6 24152
c19d1205
ZW
24153 case 6: /* Word load/store. */
24154 if (value & ~0x7c)
24155 as_bad_where (fixP->fx_file, fixP->fx_line,
24156 _("invalid offset, value too big (0x%08lX)"),
24157 (long) value);
24158 newval |= value << 4; /* 6 - 2. */
24159 break;
a737bd4d 24160
c19d1205
ZW
24161 case 7: /* Byte load/store. */
24162 if (value & ~0x1f)
24163 as_bad_where (fixP->fx_file, fixP->fx_line,
24164 _("invalid offset, value too big (0x%08lX)"),
24165 (long) value);
24166 newval |= value << 6;
24167 break;
a737bd4d 24168
c19d1205
ZW
24169 case 8: /* Halfword load/store. */
24170 if (value & ~0x3e)
24171 as_bad_where (fixP->fx_file, fixP->fx_line,
24172 _("invalid offset, value too big (0x%08lX)"),
24173 (long) value);
24174 newval |= value << 5; /* 6 - 1. */
24175 break;
a737bd4d 24176
c19d1205
ZW
24177 default:
24178 as_bad_where (fixP->fx_file, fixP->fx_line,
24179 "Unable to process relocation for thumb opcode: %lx",
24180 (unsigned long) newval);
24181 break;
24182 }
24183 md_number_to_chars (buf, newval, THUMB_SIZE);
24184 break;
a737bd4d 24185
c19d1205
ZW
24186 case BFD_RELOC_ARM_THUMB_ADD:
24187 /* This is a complicated relocation, since we use it for all of
24188 the following immediate relocations:
a737bd4d 24189
c19d1205
ZW
24190 3bit ADD/SUB
24191 8bit ADD/SUB
24192 9bit ADD/SUB SP word-aligned
24193 10bit ADD PC/SP word-aligned
a737bd4d 24194
c19d1205
ZW
24195 The type of instruction being processed is encoded in the
24196 instruction field:
a737bd4d 24197
c19d1205
ZW
24198 0x8000 SUB
24199 0x00F0 Rd
24200 0x000F Rs
24201 */
24202 newval = md_chars_to_number (buf, THUMB_SIZE);
24203 {
24204 int rd = (newval >> 4) & 0xf;
24205 int rs = newval & 0xf;
24206 int subtract = !!(newval & 0x8000);
a737bd4d 24207
c19d1205
ZW
24208 /* Check for HI regs, only very restricted cases allowed:
24209 Adjusting SP, and using PC or SP to get an address. */
24210 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24211 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24212 as_bad_where (fixP->fx_file, fixP->fx_line,
24213 _("invalid Hi register with immediate"));
a737bd4d 24214
c19d1205
ZW
24215 /* If value is negative, choose the opposite instruction. */
24216 if (value < 0)
24217 {
24218 value = -value;
24219 subtract = !subtract;
24220 if (value < 0)
24221 as_bad_where (fixP->fx_file, fixP->fx_line,
24222 _("immediate value out of range"));
24223 }
a737bd4d 24224
c19d1205
ZW
24225 if (rd == REG_SP)
24226 {
75c11999 24227 if (value & ~0x1fc)
c19d1205
ZW
24228 as_bad_where (fixP->fx_file, fixP->fx_line,
24229 _("invalid immediate for stack address calculation"));
24230 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24231 newval |= value >> 2;
24232 }
24233 else if (rs == REG_PC || rs == REG_SP)
24234 {
c12d2c9d
NC
24235 /* PR gas/18541. If the addition is for a defined symbol
24236 within range of an ADR instruction then accept it. */
24237 if (subtract
24238 && value == 4
24239 && fixP->fx_addsy != NULL)
24240 {
24241 subtract = 0;
24242
24243 if (! S_IS_DEFINED (fixP->fx_addsy)
24244 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24245 || S_IS_WEAK (fixP->fx_addsy))
24246 {
24247 as_bad_where (fixP->fx_file, fixP->fx_line,
24248 _("address calculation needs a strongly defined nearby symbol"));
24249 }
24250 else
24251 {
24252 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24253
24254 /* Round up to the next 4-byte boundary. */
24255 if (v & 3)
24256 v = (v + 3) & ~ 3;
24257 else
24258 v += 4;
24259 v = S_GET_VALUE (fixP->fx_addsy) - v;
24260
24261 if (v & ~0x3fc)
24262 {
24263 as_bad_where (fixP->fx_file, fixP->fx_line,
24264 _("symbol too far away"));
24265 }
24266 else
24267 {
24268 fixP->fx_done = 1;
24269 value = v;
24270 }
24271 }
24272 }
24273
c19d1205
ZW
24274 if (subtract || value & ~0x3fc)
24275 as_bad_where (fixP->fx_file, fixP->fx_line,
24276 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24277 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24278 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24279 newval |= rd << 8;
24280 newval |= value >> 2;
24281 }
24282 else if (rs == rd)
24283 {
24284 if (value & ~0xff)
24285 as_bad_where (fixP->fx_file, fixP->fx_line,
24286 _("immediate value out of range"));
24287 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24288 newval |= (rd << 8) | value;
24289 }
24290 else
24291 {
24292 if (value & ~0x7)
24293 as_bad_where (fixP->fx_file, fixP->fx_line,
24294 _("immediate value out of range"));
24295 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24296 newval |= rd | (rs << 3) | (value << 6);
24297 }
24298 }
24299 md_number_to_chars (buf, newval, THUMB_SIZE);
24300 break;
a737bd4d 24301
c19d1205
ZW
24302 case BFD_RELOC_ARM_THUMB_IMM:
24303 newval = md_chars_to_number (buf, THUMB_SIZE);
24304 if (value < 0 || value > 255)
24305 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24306 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24307 (long) value);
24308 newval |= value;
24309 md_number_to_chars (buf, newval, THUMB_SIZE);
24310 break;
a737bd4d 24311
c19d1205
ZW
24312 case BFD_RELOC_ARM_THUMB_SHIFT:
24313 /* 5bit shift value (0..32). LSL cannot take 32. */
24314 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24315 temp = newval & 0xf800;
24316 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24317 as_bad_where (fixP->fx_file, fixP->fx_line,
24318 _("invalid shift value: %ld"), (long) value);
24319 /* Shifts of zero must be encoded as LSL. */
24320 if (value == 0)
24321 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24322 /* Shifts of 32 are encoded as zero. */
24323 else if (value == 32)
24324 value = 0;
24325 newval |= value << 6;
24326 md_number_to_chars (buf, newval, THUMB_SIZE);
24327 break;
a737bd4d 24328
c19d1205
ZW
24329 case BFD_RELOC_VTABLE_INHERIT:
24330 case BFD_RELOC_VTABLE_ENTRY:
24331 fixP->fx_done = 0;
24332 return;
6c43fab6 24333
b6895b4f
PB
24334 case BFD_RELOC_ARM_MOVW:
24335 case BFD_RELOC_ARM_MOVT:
24336 case BFD_RELOC_ARM_THUMB_MOVW:
24337 case BFD_RELOC_ARM_THUMB_MOVT:
24338 if (fixP->fx_done || !seg->use_rela_p)
24339 {
24340 /* REL format relocations are limited to a 16-bit addend. */
24341 if (!fixP->fx_done)
24342 {
39623e12 24343 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24344 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24345 _("offset out of range"));
b6895b4f
PB
24346 }
24347 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24348 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24349 {
24350 value >>= 16;
24351 }
24352
24353 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24354 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24355 {
24356 newval = get_thumb32_insn (buf);
24357 newval &= 0xfbf08f00;
24358 newval |= (value & 0xf000) << 4;
24359 newval |= (value & 0x0800) << 15;
24360 newval |= (value & 0x0700) << 4;
24361 newval |= (value & 0x00ff);
24362 put_thumb32_insn (buf, newval);
24363 }
24364 else
24365 {
24366 newval = md_chars_to_number (buf, 4);
24367 newval &= 0xfff0f000;
24368 newval |= value & 0x0fff;
24369 newval |= (value & 0xf000) << 4;
24370 md_number_to_chars (buf, newval, 4);
24371 }
24372 }
24373 return;
24374
72d98d16
MG
24375 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24376 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24377 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24378 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24379 gas_assert (!fixP->fx_done);
24380 {
24381 bfd_vma insn;
24382 bfd_boolean is_mov;
24383 bfd_vma encoded_addend = value;
24384
24385 /* Check that addend can be encoded in instruction. */
24386 if (!seg->use_rela_p && (value < 0 || value > 255))
24387 as_bad_where (fixP->fx_file, fixP->fx_line,
24388 _("the offset 0x%08lX is not representable"),
24389 (unsigned long) encoded_addend);
24390
24391 /* Extract the instruction. */
24392 insn = md_chars_to_number (buf, THUMB_SIZE);
24393 is_mov = (insn & 0xf800) == 0x2000;
24394
24395 /* Encode insn. */
24396 if (is_mov)
24397 {
24398 if (!seg->use_rela_p)
24399 insn |= encoded_addend;
24400 }
24401 else
24402 {
24403 int rd, rs;
24404
24405 /* Extract the instruction. */
24406 /* Encoding is the following
24407 0x8000 SUB
24408 0x00F0 Rd
24409 0x000F Rs
24410 */
24411 /* The following conditions must be true :
24412 - ADD
24413 - Rd == Rs
24414 - Rd <= 7
24415 */
24416 rd = (insn >> 4) & 0xf;
24417 rs = insn & 0xf;
24418 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24419 as_bad_where (fixP->fx_file, fixP->fx_line,
24420 _("Unable to process relocation for thumb opcode: %lx"),
24421 (unsigned long) insn);
24422
24423 /* Encode as ADD immediate8 thumb 1 code. */
24424 insn = 0x3000 | (rd << 8);
24425
24426 /* Place the encoded addend into the first 8 bits of the
24427 instruction. */
24428 if (!seg->use_rela_p)
24429 insn |= encoded_addend;
24430 }
24431
24432 /* Update the instruction. */
24433 md_number_to_chars (buf, insn, THUMB_SIZE);
24434 }
24435 break;
24436
4962c51a
MS
24437 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24438 case BFD_RELOC_ARM_ALU_PC_G0:
24439 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24440 case BFD_RELOC_ARM_ALU_PC_G1:
24441 case BFD_RELOC_ARM_ALU_PC_G2:
24442 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24443 case BFD_RELOC_ARM_ALU_SB_G0:
24444 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24445 case BFD_RELOC_ARM_ALU_SB_G1:
24446 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24447 gas_assert (!fixP->fx_done);
4962c51a
MS
24448 if (!seg->use_rela_p)
24449 {
477330fc
RM
24450 bfd_vma insn;
24451 bfd_vma encoded_addend;
24452 bfd_vma addend_abs = abs (value);
24453
24454 /* Check that the absolute value of the addend can be
24455 expressed as an 8-bit constant plus a rotation. */
24456 encoded_addend = encode_arm_immediate (addend_abs);
24457 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24458 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24459 _("the offset 0x%08lX is not representable"),
24460 (unsigned long) addend_abs);
24461
24462 /* Extract the instruction. */
24463 insn = md_chars_to_number (buf, INSN_SIZE);
24464
24465 /* If the addend is positive, use an ADD instruction.
24466 Otherwise use a SUB. Take care not to destroy the S bit. */
24467 insn &= 0xff1fffff;
24468 if (value < 0)
24469 insn |= 1 << 22;
24470 else
24471 insn |= 1 << 23;
24472
24473 /* Place the encoded addend into the first 12 bits of the
24474 instruction. */
24475 insn &= 0xfffff000;
24476 insn |= encoded_addend;
24477
24478 /* Update the instruction. */
24479 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24480 }
24481 break;
24482
24483 case BFD_RELOC_ARM_LDR_PC_G0:
24484 case BFD_RELOC_ARM_LDR_PC_G1:
24485 case BFD_RELOC_ARM_LDR_PC_G2:
24486 case BFD_RELOC_ARM_LDR_SB_G0:
24487 case BFD_RELOC_ARM_LDR_SB_G1:
24488 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24489 gas_assert (!fixP->fx_done);
4962c51a 24490 if (!seg->use_rela_p)
477330fc
RM
24491 {
24492 bfd_vma insn;
24493 bfd_vma addend_abs = abs (value);
4962c51a 24494
477330fc
RM
24495 /* Check that the absolute value of the addend can be
24496 encoded in 12 bits. */
24497 if (addend_abs >= 0x1000)
4962c51a 24498 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24499 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24500 (unsigned long) addend_abs);
24501
24502 /* Extract the instruction. */
24503 insn = md_chars_to_number (buf, INSN_SIZE);
24504
24505 /* If the addend is negative, clear bit 23 of the instruction.
24506 Otherwise set it. */
24507 if (value < 0)
24508 insn &= ~(1 << 23);
24509 else
24510 insn |= 1 << 23;
24511
24512 /* Place the absolute value of the addend into the first 12 bits
24513 of the instruction. */
24514 insn &= 0xfffff000;
24515 insn |= addend_abs;
24516
24517 /* Update the instruction. */
24518 md_number_to_chars (buf, insn, INSN_SIZE);
24519 }
4962c51a
MS
24520 break;
24521
24522 case BFD_RELOC_ARM_LDRS_PC_G0:
24523 case BFD_RELOC_ARM_LDRS_PC_G1:
24524 case BFD_RELOC_ARM_LDRS_PC_G2:
24525 case BFD_RELOC_ARM_LDRS_SB_G0:
24526 case BFD_RELOC_ARM_LDRS_SB_G1:
24527 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24528 gas_assert (!fixP->fx_done);
4962c51a 24529 if (!seg->use_rela_p)
477330fc
RM
24530 {
24531 bfd_vma insn;
24532 bfd_vma addend_abs = abs (value);
4962c51a 24533
477330fc
RM
24534 /* Check that the absolute value of the addend can be
24535 encoded in 8 bits. */
24536 if (addend_abs >= 0x100)
4962c51a 24537 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24538 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24539 (unsigned long) addend_abs);
24540
24541 /* Extract the instruction. */
24542 insn = md_chars_to_number (buf, INSN_SIZE);
24543
24544 /* If the addend is negative, clear bit 23 of the instruction.
24545 Otherwise set it. */
24546 if (value < 0)
24547 insn &= ~(1 << 23);
24548 else
24549 insn |= 1 << 23;
24550
24551 /* Place the first four bits of the absolute value of the addend
24552 into the first 4 bits of the instruction, and the remaining
24553 four into bits 8 .. 11. */
24554 insn &= 0xfffff0f0;
24555 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24556
24557 /* Update the instruction. */
24558 md_number_to_chars (buf, insn, INSN_SIZE);
24559 }
4962c51a
MS
24560 break;
24561
24562 case BFD_RELOC_ARM_LDC_PC_G0:
24563 case BFD_RELOC_ARM_LDC_PC_G1:
24564 case BFD_RELOC_ARM_LDC_PC_G2:
24565 case BFD_RELOC_ARM_LDC_SB_G0:
24566 case BFD_RELOC_ARM_LDC_SB_G1:
24567 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24568 gas_assert (!fixP->fx_done);
4962c51a 24569 if (!seg->use_rela_p)
477330fc
RM
24570 {
24571 bfd_vma insn;
24572 bfd_vma addend_abs = abs (value);
4962c51a 24573
477330fc
RM
24574 /* Check that the absolute value of the addend is a multiple of
24575 four and, when divided by four, fits in 8 bits. */
24576 if (addend_abs & 0x3)
4962c51a 24577 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24578 _("bad offset 0x%08lX (must be word-aligned)"),
24579 (unsigned long) addend_abs);
4962c51a 24580
477330fc 24581 if ((addend_abs >> 2) > 0xff)
4962c51a 24582 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24583 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24584 (unsigned long) addend_abs);
24585
24586 /* Extract the instruction. */
24587 insn = md_chars_to_number (buf, INSN_SIZE);
24588
24589 /* If the addend is negative, clear bit 23 of the instruction.
24590 Otherwise set it. */
24591 if (value < 0)
24592 insn &= ~(1 << 23);
24593 else
24594 insn |= 1 << 23;
24595
24596 /* Place the addend (divided by four) into the first eight
24597 bits of the instruction. */
24598 insn &= 0xfffffff0;
24599 insn |= addend_abs >> 2;
24600
24601 /* Update the instruction. */
24602 md_number_to_chars (buf, insn, INSN_SIZE);
24603 }
4962c51a
MS
24604 break;
24605
845b51d6
PB
24606 case BFD_RELOC_ARM_V4BX:
24607 /* This will need to go in the object file. */
24608 fixP->fx_done = 0;
24609 break;
24610
c19d1205
ZW
24611 case BFD_RELOC_UNUSED:
24612 default:
24613 as_bad_where (fixP->fx_file, fixP->fx_line,
24614 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24615 }
6c43fab6
RE
24616}
24617
c19d1205
ZW
24618/* Translate internal representation of relocation info to BFD target
24619 format. */
a737bd4d 24620
c19d1205 24621arelent *
00a97672 24622tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24623{
c19d1205
ZW
24624 arelent * reloc;
24625 bfd_reloc_code_real_type code;
a737bd4d 24626
325801bd 24627 reloc = XNEW (arelent);
a737bd4d 24628
325801bd 24629 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24630 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24631 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24632
2fc8bdac 24633 if (fixp->fx_pcrel)
00a97672
RS
24634 {
24635 if (section->use_rela_p)
24636 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24637 else
24638 fixp->fx_offset = reloc->address;
24639 }
c19d1205 24640 reloc->addend = fixp->fx_offset;
a737bd4d 24641
c19d1205 24642 switch (fixp->fx_r_type)
a737bd4d 24643 {
c19d1205
ZW
24644 case BFD_RELOC_8:
24645 if (fixp->fx_pcrel)
24646 {
24647 code = BFD_RELOC_8_PCREL;
24648 break;
24649 }
1a0670f3 24650 /* Fall through. */
a737bd4d 24651
c19d1205
ZW
24652 case BFD_RELOC_16:
24653 if (fixp->fx_pcrel)
24654 {
24655 code = BFD_RELOC_16_PCREL;
24656 break;
24657 }
1a0670f3 24658 /* Fall through. */
6c43fab6 24659
c19d1205
ZW
24660 case BFD_RELOC_32:
24661 if (fixp->fx_pcrel)
24662 {
24663 code = BFD_RELOC_32_PCREL;
24664 break;
24665 }
1a0670f3 24666 /* Fall through. */
a737bd4d 24667
b6895b4f
PB
24668 case BFD_RELOC_ARM_MOVW:
24669 if (fixp->fx_pcrel)
24670 {
24671 code = BFD_RELOC_ARM_MOVW_PCREL;
24672 break;
24673 }
1a0670f3 24674 /* Fall through. */
b6895b4f
PB
24675
24676 case BFD_RELOC_ARM_MOVT:
24677 if (fixp->fx_pcrel)
24678 {
24679 code = BFD_RELOC_ARM_MOVT_PCREL;
24680 break;
24681 }
1a0670f3 24682 /* Fall through. */
b6895b4f
PB
24683
24684 case BFD_RELOC_ARM_THUMB_MOVW:
24685 if (fixp->fx_pcrel)
24686 {
24687 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24688 break;
24689 }
1a0670f3 24690 /* Fall through. */
b6895b4f
PB
24691
24692 case BFD_RELOC_ARM_THUMB_MOVT:
24693 if (fixp->fx_pcrel)
24694 {
24695 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24696 break;
24697 }
1a0670f3 24698 /* Fall through. */
b6895b4f 24699
c19d1205
ZW
24700 case BFD_RELOC_NONE:
24701 case BFD_RELOC_ARM_PCREL_BRANCH:
24702 case BFD_RELOC_ARM_PCREL_BLX:
24703 case BFD_RELOC_RVA:
24704 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24705 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24706 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24707 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24708 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24709 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24710 case BFD_RELOC_VTABLE_ENTRY:
24711 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24712#ifdef TE_PE
24713 case BFD_RELOC_32_SECREL:
24714#endif
c19d1205
ZW
24715 code = fixp->fx_r_type;
24716 break;
a737bd4d 24717
00adf2d4
JB
24718 case BFD_RELOC_THUMB_PCREL_BLX:
24719#ifdef OBJ_ELF
24720 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24721 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24722 else
24723#endif
24724 code = BFD_RELOC_THUMB_PCREL_BLX;
24725 break;
24726
c19d1205
ZW
24727 case BFD_RELOC_ARM_LITERAL:
24728 case BFD_RELOC_ARM_HWLITERAL:
24729 /* If this is called then the a literal has
24730 been referenced across a section boundary. */
24731 as_bad_where (fixp->fx_file, fixp->fx_line,
24732 _("literal referenced across section boundary"));
24733 return NULL;
a737bd4d 24734
c19d1205 24735#ifdef OBJ_ELF
0855e32b
NS
24736 case BFD_RELOC_ARM_TLS_CALL:
24737 case BFD_RELOC_ARM_THM_TLS_CALL:
24738 case BFD_RELOC_ARM_TLS_DESCSEQ:
24739 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24740 case BFD_RELOC_ARM_GOT32:
24741 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24742 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24743 case BFD_RELOC_ARM_PLT32:
24744 case BFD_RELOC_ARM_TARGET1:
24745 case BFD_RELOC_ARM_ROSEGREL32:
24746 case BFD_RELOC_ARM_SBREL32:
24747 case BFD_RELOC_ARM_PREL31:
24748 case BFD_RELOC_ARM_TARGET2:
c19d1205 24749 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24750 case BFD_RELOC_ARM_PCREL_CALL:
24751 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24752 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24753 case BFD_RELOC_ARM_ALU_PC_G0:
24754 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24755 case BFD_RELOC_ARM_ALU_PC_G1:
24756 case BFD_RELOC_ARM_ALU_PC_G2:
24757 case BFD_RELOC_ARM_LDR_PC_G0:
24758 case BFD_RELOC_ARM_LDR_PC_G1:
24759 case BFD_RELOC_ARM_LDR_PC_G2:
24760 case BFD_RELOC_ARM_LDRS_PC_G0:
24761 case BFD_RELOC_ARM_LDRS_PC_G1:
24762 case BFD_RELOC_ARM_LDRS_PC_G2:
24763 case BFD_RELOC_ARM_LDC_PC_G0:
24764 case BFD_RELOC_ARM_LDC_PC_G1:
24765 case BFD_RELOC_ARM_LDC_PC_G2:
24766 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24767 case BFD_RELOC_ARM_ALU_SB_G0:
24768 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24769 case BFD_RELOC_ARM_ALU_SB_G1:
24770 case BFD_RELOC_ARM_ALU_SB_G2:
24771 case BFD_RELOC_ARM_LDR_SB_G0:
24772 case BFD_RELOC_ARM_LDR_SB_G1:
24773 case BFD_RELOC_ARM_LDR_SB_G2:
24774 case BFD_RELOC_ARM_LDRS_SB_G0:
24775 case BFD_RELOC_ARM_LDRS_SB_G1:
24776 case BFD_RELOC_ARM_LDRS_SB_G2:
24777 case BFD_RELOC_ARM_LDC_SB_G0:
24778 case BFD_RELOC_ARM_LDC_SB_G1:
24779 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24780 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24781 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24782 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24783 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24784 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24785 code = fixp->fx_r_type;
24786 break;
a737bd4d 24787
0855e32b 24788 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24789 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24790 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24791 case BFD_RELOC_ARM_TLS_IE32:
24792 case BFD_RELOC_ARM_TLS_LDM32:
24793 /* BFD will include the symbol's address in the addend.
24794 But we don't want that, so subtract it out again here. */
24795 if (!S_IS_COMMON (fixp->fx_addsy))
24796 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24797 code = fixp->fx_r_type;
24798 break;
24799#endif
a737bd4d 24800
c19d1205
ZW
24801 case BFD_RELOC_ARM_IMMEDIATE:
24802 as_bad_where (fixp->fx_file, fixp->fx_line,
24803 _("internal relocation (type: IMMEDIATE) not fixed up"));
24804 return NULL;
a737bd4d 24805
c19d1205
ZW
24806 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24807 as_bad_where (fixp->fx_file, fixp->fx_line,
24808 _("ADRL used for a symbol not defined in the same file"));
24809 return NULL;
a737bd4d 24810
c19d1205 24811 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24812 if (section->use_rela_p)
24813 {
24814 code = fixp->fx_r_type;
24815 break;
24816 }
24817
c19d1205
ZW
24818 if (fixp->fx_addsy != NULL
24819 && !S_IS_DEFINED (fixp->fx_addsy)
24820 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24821 {
c19d1205
ZW
24822 as_bad_where (fixp->fx_file, fixp->fx_line,
24823 _("undefined local label `%s'"),
24824 S_GET_NAME (fixp->fx_addsy));
24825 return NULL;
a737bd4d
NC
24826 }
24827
c19d1205
ZW
24828 as_bad_where (fixp->fx_file, fixp->fx_line,
24829 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24830 return NULL;
a737bd4d 24831
c19d1205
ZW
24832 default:
24833 {
e0471c16 24834 const char * type;
6c43fab6 24835
c19d1205
ZW
24836 switch (fixp->fx_r_type)
24837 {
24838 case BFD_RELOC_NONE: type = "NONE"; break;
24839 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24840 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24841 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24842 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24843 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24844 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24845 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24846 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24847 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24848 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24849 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24850 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24851 default: type = _("<unknown>"); break;
24852 }
24853 as_bad_where (fixp->fx_file, fixp->fx_line,
24854 _("cannot represent %s relocation in this object file format"),
24855 type);
24856 return NULL;
24857 }
a737bd4d 24858 }
6c43fab6 24859
c19d1205
ZW
24860#ifdef OBJ_ELF
24861 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24862 && GOT_symbol
24863 && fixp->fx_addsy == GOT_symbol)
24864 {
24865 code = BFD_RELOC_ARM_GOTPC;
24866 reloc->addend = fixp->fx_offset = reloc->address;
24867 }
24868#endif
6c43fab6 24869
c19d1205 24870 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24871
c19d1205
ZW
24872 if (reloc->howto == NULL)
24873 {
24874 as_bad_where (fixp->fx_file, fixp->fx_line,
24875 _("cannot represent %s relocation in this object file format"),
24876 bfd_get_reloc_code_name (code));
24877 return NULL;
24878 }
6c43fab6 24879
c19d1205
ZW
24880 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24881 vtable entry to be used in the relocation's section offset. */
24882 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24883 reloc->address = fixp->fx_offset;
6c43fab6 24884
c19d1205 24885 return reloc;
6c43fab6
RE
24886}
24887
c19d1205 24888/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24889
c19d1205
ZW
24890void
24891cons_fix_new_arm (fragS * frag,
24892 int where,
24893 int size,
62ebcb5c
AM
24894 expressionS * exp,
24895 bfd_reloc_code_real_type reloc)
6c43fab6 24896{
c19d1205 24897 int pcrel = 0;
6c43fab6 24898
c19d1205
ZW
24899 /* Pick a reloc.
24900 FIXME: @@ Should look at CPU word size. */
24901 switch (size)
24902 {
24903 case 1:
62ebcb5c 24904 reloc = BFD_RELOC_8;
c19d1205
ZW
24905 break;
24906 case 2:
62ebcb5c 24907 reloc = BFD_RELOC_16;
c19d1205
ZW
24908 break;
24909 case 4:
24910 default:
62ebcb5c 24911 reloc = BFD_RELOC_32;
c19d1205
ZW
24912 break;
24913 case 8:
62ebcb5c 24914 reloc = BFD_RELOC_64;
c19d1205
ZW
24915 break;
24916 }
6c43fab6 24917
f0927246
NC
24918#ifdef TE_PE
24919 if (exp->X_op == O_secrel)
24920 {
24921 exp->X_op = O_symbol;
62ebcb5c 24922 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24923 }
24924#endif
24925
62ebcb5c 24926 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24927}
6c43fab6 24928
4343666d 24929#if defined (OBJ_COFF)
c19d1205
ZW
24930void
24931arm_validate_fix (fixS * fixP)
6c43fab6 24932{
c19d1205
ZW
24933 /* If the destination of the branch is a defined symbol which does not have
24934 the THUMB_FUNC attribute, then we must be calling a function which has
24935 the (interfacearm) attribute. We look for the Thumb entry point to that
24936 function and change the branch to refer to that function instead. */
24937 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24938 && fixP->fx_addsy != NULL
24939 && S_IS_DEFINED (fixP->fx_addsy)
24940 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24941 {
c19d1205 24942 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24943 }
c19d1205
ZW
24944}
24945#endif
6c43fab6 24946
267bf995 24947
c19d1205
ZW
24948int
24949arm_force_relocation (struct fix * fixp)
24950{
24951#if defined (OBJ_COFF) && defined (TE_PE)
24952 if (fixp->fx_r_type == BFD_RELOC_RVA)
24953 return 1;
24954#endif
6c43fab6 24955
267bf995
RR
24956 /* In case we have a call or a branch to a function in ARM ISA mode from
24957 a thumb function or vice-versa force the relocation. These relocations
24958 are cleared off for some cores that might have blx and simple transformations
24959 are possible. */
24960
24961#ifdef OBJ_ELF
24962 switch (fixp->fx_r_type)
24963 {
24964 case BFD_RELOC_ARM_PCREL_JUMP:
24965 case BFD_RELOC_ARM_PCREL_CALL:
24966 case BFD_RELOC_THUMB_PCREL_BLX:
24967 if (THUMB_IS_FUNC (fixp->fx_addsy))
24968 return 1;
24969 break;
24970
24971 case BFD_RELOC_ARM_PCREL_BLX:
24972 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24973 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24974 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24975 if (ARM_IS_FUNC (fixp->fx_addsy))
24976 return 1;
24977 break;
24978
24979 default:
24980 break;
24981 }
24982#endif
24983
b5884301
PB
24984 /* Resolve these relocations even if the symbol is extern or weak.
24985 Technically this is probably wrong due to symbol preemption.
24986 In practice these relocations do not have enough range to be useful
24987 at dynamic link time, and some code (e.g. in the Linux kernel)
24988 expects these references to be resolved. */
c19d1205
ZW
24989 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24990 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24991 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24992 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24993 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24994 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24995 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24996 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24997 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24998 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24999 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25000 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25001 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25002 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 25003 return 0;
a737bd4d 25004
4962c51a
MS
25005 /* Always leave these relocations for the linker. */
25006 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25007 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25008 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25009 return 1;
25010
f0291e4c
PB
25011 /* Always generate relocations against function symbols. */
25012 if (fixp->fx_r_type == BFD_RELOC_32
25013 && fixp->fx_addsy
25014 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25015 return 1;
25016
c19d1205 25017 return generic_force_reloc (fixp);
404ff6b5
AH
25018}
25019
0ffdc86c 25020#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
25021/* Relocations against function names must be left unadjusted,
25022 so that the linker can use this information to generate interworking
25023 stubs. The MIPS version of this function
c19d1205
ZW
25024 also prevents relocations that are mips-16 specific, but I do not
25025 know why it does this.
404ff6b5 25026
c19d1205
ZW
25027 FIXME:
25028 There is one other problem that ought to be addressed here, but
25029 which currently is not: Taking the address of a label (rather
25030 than a function) and then later jumping to that address. Such
25031 addresses also ought to have their bottom bit set (assuming that
25032 they reside in Thumb code), but at the moment they will not. */
404ff6b5 25033
c19d1205
ZW
25034bfd_boolean
25035arm_fix_adjustable (fixS * fixP)
404ff6b5 25036{
c19d1205
ZW
25037 if (fixP->fx_addsy == NULL)
25038 return 1;
404ff6b5 25039
e28387c3
PB
25040 /* Preserve relocations against symbols with function type. */
25041 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 25042 return FALSE;
e28387c3 25043
c19d1205
ZW
25044 if (THUMB_IS_FUNC (fixP->fx_addsy)
25045 && fixP->fx_subsy == NULL)
c921be7d 25046 return FALSE;
a737bd4d 25047
c19d1205
ZW
25048 /* We need the symbol name for the VTABLE entries. */
25049 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25050 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 25051 return FALSE;
404ff6b5 25052
c19d1205
ZW
25053 /* Don't allow symbols to be discarded on GOT related relocs. */
25054 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25055 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25056 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25057 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
25058 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25059 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
25060 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
25061 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
25062 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25063 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25064 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25065 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25066 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 25067 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 25068 return FALSE;
a737bd4d 25069
4962c51a
MS
25070 /* Similarly for group relocations. */
25071 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25072 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25073 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 25074 return FALSE;
4962c51a 25075
79947c54
CD
25076 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25077 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25078 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25079 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25080 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25081 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25082 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25083 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25084 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25085 return FALSE;
79947c54 25086
72d98d16
MG
25087 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25088 offsets, so keep these symbols. */
25089 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25090 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25091 return FALSE;
25092
c921be7d 25093 return TRUE;
a737bd4d 25094}
0ffdc86c
NC
25095#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25096
25097#ifdef OBJ_ELF
c19d1205
ZW
25098const char *
25099elf32_arm_target_format (void)
404ff6b5 25100{
c19d1205
ZW
25101#ifdef TE_SYMBIAN
25102 return (target_big_endian
25103 ? "elf32-bigarm-symbian"
25104 : "elf32-littlearm-symbian");
25105#elif defined (TE_VXWORKS)
25106 return (target_big_endian
25107 ? "elf32-bigarm-vxworks"
25108 : "elf32-littlearm-vxworks");
b38cadfb
NC
25109#elif defined (TE_NACL)
25110 return (target_big_endian
25111 ? "elf32-bigarm-nacl"
25112 : "elf32-littlearm-nacl");
c19d1205
ZW
25113#else
25114 if (target_big_endian)
25115 return "elf32-bigarm";
25116 else
25117 return "elf32-littlearm";
25118#endif
404ff6b5
AH
25119}
25120
c19d1205
ZW
25121void
25122armelf_frob_symbol (symbolS * symp,
25123 int * puntp)
404ff6b5 25124{
c19d1205
ZW
25125 elf_frob_symbol (symp, puntp);
25126}
25127#endif
404ff6b5 25128
c19d1205 25129/* MD interface: Finalization. */
a737bd4d 25130
c19d1205
ZW
25131void
25132arm_cleanup (void)
25133{
25134 literal_pool * pool;
a737bd4d 25135
e07e6e58
NC
25136 /* Ensure that all the IT blocks are properly closed. */
25137 check_it_blocks_finished ();
25138
c19d1205
ZW
25139 for (pool = list_of_pools; pool; pool = pool->next)
25140 {
5f4273c7 25141 /* Put it at the end of the relevant section. */
c19d1205
ZW
25142 subseg_set (pool->section, pool->sub_section);
25143#ifdef OBJ_ELF
25144 arm_elf_change_section ();
25145#endif
25146 s_ltorg (0);
25147 }
404ff6b5
AH
25148}
25149
cd000bff
DJ
25150#ifdef OBJ_ELF
25151/* Remove any excess mapping symbols generated for alignment frags in
25152 SEC. We may have created a mapping symbol before a zero byte
25153 alignment; remove it if there's a mapping symbol after the
25154 alignment. */
25155static void
25156check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25157 void *dummy ATTRIBUTE_UNUSED)
25158{
25159 segment_info_type *seginfo = seg_info (sec);
25160 fragS *fragp;
25161
25162 if (seginfo == NULL || seginfo->frchainP == NULL)
25163 return;
25164
25165 for (fragp = seginfo->frchainP->frch_root;
25166 fragp != NULL;
25167 fragp = fragp->fr_next)
25168 {
25169 symbolS *sym = fragp->tc_frag_data.last_map;
25170 fragS *next = fragp->fr_next;
25171
25172 /* Variable-sized frags have been converted to fixed size by
25173 this point. But if this was variable-sized to start with,
25174 there will be a fixed-size frag after it. So don't handle
25175 next == NULL. */
25176 if (sym == NULL || next == NULL)
25177 continue;
25178
25179 if (S_GET_VALUE (sym) < next->fr_address)
25180 /* Not at the end of this frag. */
25181 continue;
25182 know (S_GET_VALUE (sym) == next->fr_address);
25183
25184 do
25185 {
25186 if (next->tc_frag_data.first_map != NULL)
25187 {
25188 /* Next frag starts with a mapping symbol. Discard this
25189 one. */
25190 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25191 break;
25192 }
25193
25194 if (next->fr_next == NULL)
25195 {
25196 /* This mapping symbol is at the end of the section. Discard
25197 it. */
25198 know (next->fr_fix == 0 && next->fr_var == 0);
25199 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25200 break;
25201 }
25202
25203 /* As long as we have empty frags without any mapping symbols,
25204 keep looking. */
25205 /* If the next frag is non-empty and does not start with a
25206 mapping symbol, then this mapping symbol is required. */
25207 if (next->fr_address != next->fr_next->fr_address)
25208 break;
25209
25210 next = next->fr_next;
25211 }
25212 while (next != NULL);
25213 }
25214}
25215#endif
25216
c19d1205
ZW
25217/* Adjust the symbol table. This marks Thumb symbols as distinct from
25218 ARM ones. */
404ff6b5 25219
c19d1205
ZW
25220void
25221arm_adjust_symtab (void)
404ff6b5 25222{
c19d1205
ZW
25223#ifdef OBJ_COFF
25224 symbolS * sym;
404ff6b5 25225
c19d1205
ZW
25226 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25227 {
25228 if (ARM_IS_THUMB (sym))
25229 {
25230 if (THUMB_IS_FUNC (sym))
25231 {
25232 /* Mark the symbol as a Thumb function. */
25233 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25234 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25235 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25236
c19d1205
ZW
25237 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25238 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25239 else
25240 as_bad (_("%s: unexpected function type: %d"),
25241 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25242 }
25243 else switch (S_GET_STORAGE_CLASS (sym))
25244 {
25245 case C_EXT:
25246 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25247 break;
25248 case C_STAT:
25249 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25250 break;
25251 case C_LABEL:
25252 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25253 break;
25254 default:
25255 /* Do nothing. */
25256 break;
25257 }
25258 }
a737bd4d 25259
c19d1205
ZW
25260 if (ARM_IS_INTERWORK (sym))
25261 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25262 }
c19d1205
ZW
25263#endif
25264#ifdef OBJ_ELF
25265 symbolS * sym;
25266 char bind;
404ff6b5 25267
c19d1205 25268 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25269 {
c19d1205
ZW
25270 if (ARM_IS_THUMB (sym))
25271 {
25272 elf_symbol_type * elf_sym;
404ff6b5 25273
c19d1205
ZW
25274 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25275 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25276
b0796911
PB
25277 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25278 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25279 {
25280 /* If it's a .thumb_func, declare it as so,
25281 otherwise tag label as .code 16. */
25282 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25283 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25284 ST_BRANCH_TO_THUMB);
3ba67470 25285 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25286 elf_sym->internal_elf_sym.st_info =
25287 ELF_ST_INFO (bind, STT_ARM_16BIT);
25288 }
25289 }
25290 }
cd000bff
DJ
25291
25292 /* Remove any overlapping mapping symbols generated by alignment frags. */
25293 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25294 /* Now do generic ELF adjustments. */
25295 elf_adjust_symtab ();
c19d1205 25296#endif
404ff6b5
AH
25297}
25298
c19d1205 25299/* MD interface: Initialization. */
404ff6b5 25300
a737bd4d 25301static void
c19d1205 25302set_constant_flonums (void)
a737bd4d 25303{
c19d1205 25304 int i;
404ff6b5 25305
c19d1205
ZW
25306 for (i = 0; i < NUM_FLOAT_VALS; i++)
25307 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25308 abort ();
a737bd4d 25309}
404ff6b5 25310
3e9e4fcf
JB
25311/* Auto-select Thumb mode if it's the only available instruction set for the
25312 given architecture. */
25313
25314static void
25315autoselect_thumb_from_cpu_variant (void)
25316{
25317 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25318 opcode_select (16);
25319}
25320
c19d1205
ZW
25321void
25322md_begin (void)
a737bd4d 25323{
c19d1205
ZW
25324 unsigned mach;
25325 unsigned int i;
404ff6b5 25326
c19d1205
ZW
25327 if ( (arm_ops_hsh = hash_new ()) == NULL
25328 || (arm_cond_hsh = hash_new ()) == NULL
25329 || (arm_shift_hsh = hash_new ()) == NULL
25330 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25331 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25332 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25333 || (arm_reloc_hsh = hash_new ()) == NULL
25334 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25335 as_fatal (_("virtual memory exhausted"));
25336
25337 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25338 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25339 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25340 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25341 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25342 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25343 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25344 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25345 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25346 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25347 (void *) (v7m_psrs + i));
c19d1205 25348 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25349 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25350 for (i = 0;
25351 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25352 i++)
d3ce72d0 25353 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25354 (void *) (barrier_opt_names + i));
c19d1205 25355#ifdef OBJ_ELF
3da1d841
NC
25356 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25357 {
25358 struct reloc_entry * entry = reloc_names + i;
25359
25360 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25361 /* This makes encode_branch() use the EABI versions of this relocation. */
25362 entry->reloc = BFD_RELOC_UNUSED;
25363
25364 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25365 }
c19d1205
ZW
25366#endif
25367
25368 set_constant_flonums ();
404ff6b5 25369
c19d1205
ZW
25370 /* Set the cpu variant based on the command-line options. We prefer
25371 -mcpu= over -march= if both are set (as for GCC); and we prefer
25372 -mfpu= over any other way of setting the floating point unit.
25373 Use of legacy options with new options are faulted. */
e74cfd16 25374 if (legacy_cpu)
404ff6b5 25375 {
e74cfd16 25376 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25377 as_bad (_("use of old and new-style options to set CPU type"));
25378
4d354d8b 25379 selected_arch = *legacy_cpu;
404ff6b5 25380 }
4d354d8b
TP
25381 else if (mcpu_cpu_opt)
25382 {
25383 selected_arch = *mcpu_cpu_opt;
25384 selected_ext = *mcpu_ext_opt;
25385 }
25386 else if (march_cpu_opt)
c168ce07 25387 {
4d354d8b
TP
25388 selected_arch = *march_cpu_opt;
25389 selected_ext = *march_ext_opt;
c168ce07 25390 }
4d354d8b 25391 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
404ff6b5 25392
e74cfd16 25393 if (legacy_fpu)
c19d1205 25394 {
e74cfd16 25395 if (mfpu_opt)
c19d1205 25396 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f 25397
4d354d8b 25398 selected_fpu = *legacy_fpu;
03b1477f 25399 }
4d354d8b
TP
25400 else if (mfpu_opt)
25401 selected_fpu = *mfpu_opt;
25402 else
03b1477f 25403 {
45eb4c1b
NS
25404#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25405 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25406 /* Some environments specify a default FPU. If they don't, infer it
25407 from the processor. */
e74cfd16 25408 if (mcpu_fpu_opt)
4d354d8b 25409 selected_fpu = *mcpu_fpu_opt;
e7da50fa 25410 else if (march_fpu_opt)
4d354d8b 25411 selected_fpu = *march_fpu_opt;
39c2da32 25412#else
4d354d8b 25413 selected_fpu = fpu_default;
39c2da32 25414#endif
03b1477f
RE
25415 }
25416
4d354d8b 25417 if (ARM_FEATURE_ZERO (selected_fpu))
03b1477f 25418 {
4d354d8b
TP
25419 if (!no_cpu_selected ())
25420 selected_fpu = fpu_default;
03b1477f 25421 else
4d354d8b 25422 selected_fpu = fpu_arch_fpa;
03b1477f
RE
25423 }
25424
ee065d83 25425#ifdef CPU_DEFAULT
4d354d8b 25426 if (ARM_FEATURE_ZERO (selected_arch))
ee065d83 25427 {
4d354d8b
TP
25428 selected_arch = cpu_default;
25429 selected_cpu = selected_arch;
ee065d83 25430 }
4d354d8b 25431 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
e74cfd16 25432#else
4d354d8b
TP
25433 /* Autodection of feature mode: allow all features in cpu_variant but leave
25434 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25435 after all instruction have been processed and we can decide what CPU
25436 should be selected. */
25437 if (ARM_FEATURE_ZERO (selected_arch))
25438 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
ee065d83 25439 else
4d354d8b 25440 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83 25441#endif
03b1477f 25442
3e9e4fcf
JB
25443 autoselect_thumb_from_cpu_variant ();
25444
e74cfd16 25445 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25446
f17c130b 25447#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25448 {
7cc69913
NC
25449 unsigned int flags = 0;
25450
25451#if defined OBJ_ELF
25452 flags = meabi_flags;
d507cf36
PB
25453
25454 switch (meabi_flags)
33a392fb 25455 {
d507cf36 25456 case EF_ARM_EABI_UNKNOWN:
7cc69913 25457#endif
d507cf36
PB
25458 /* Set the flags in the private structure. */
25459 if (uses_apcs_26) flags |= F_APCS26;
25460 if (support_interwork) flags |= F_INTERWORK;
25461 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25462 if (pic_code) flags |= F_PIC;
e74cfd16 25463 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25464 flags |= F_SOFT_FLOAT;
25465
d507cf36
PB
25466 switch (mfloat_abi_opt)
25467 {
25468 case ARM_FLOAT_ABI_SOFT:
25469 case ARM_FLOAT_ABI_SOFTFP:
25470 flags |= F_SOFT_FLOAT;
25471 break;
33a392fb 25472
d507cf36
PB
25473 case ARM_FLOAT_ABI_HARD:
25474 if (flags & F_SOFT_FLOAT)
25475 as_bad (_("hard-float conflicts with specified fpu"));
25476 break;
25477 }
03b1477f 25478
e74cfd16
PB
25479 /* Using pure-endian doubles (even if soft-float). */
25480 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25481 flags |= F_VFP_FLOAT;
f17c130b 25482
fde78edd 25483#if defined OBJ_ELF
e74cfd16 25484 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25485 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25486 break;
25487
8cb51566 25488 case EF_ARM_EABI_VER4:
3a4a14e9 25489 case EF_ARM_EABI_VER5:
c19d1205 25490 /* No additional flags to set. */
d507cf36
PB
25491 break;
25492
25493 default:
25494 abort ();
25495 }
7cc69913 25496#endif
b99bd4ef
NC
25497 bfd_set_private_flags (stdoutput, flags);
25498
25499 /* We have run out flags in the COFF header to encode the
25500 status of ATPCS support, so instead we create a dummy,
c19d1205 25501 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25502 if (atpcs)
25503 {
25504 asection * sec;
25505
25506 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25507
25508 if (sec != NULL)
25509 {
25510 bfd_set_section_flags
25511 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25512 bfd_set_section_size (stdoutput, sec, 0);
25513 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25514 }
25515 }
7cc69913 25516 }
f17c130b 25517#endif
b99bd4ef
NC
25518
25519 /* Record the CPU type as well. */
2d447fca
JM
25520 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25521 mach = bfd_mach_arm_iWMMXt2;
25522 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25523 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25524 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25525 mach = bfd_mach_arm_XScale;
e74cfd16 25526 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25527 mach = bfd_mach_arm_ep9312;
e74cfd16 25528 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25529 mach = bfd_mach_arm_5TE;
e74cfd16 25530 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25531 {
e74cfd16 25532 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25533 mach = bfd_mach_arm_5T;
25534 else
25535 mach = bfd_mach_arm_5;
25536 }
e74cfd16 25537 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25538 {
e74cfd16 25539 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25540 mach = bfd_mach_arm_4T;
25541 else
25542 mach = bfd_mach_arm_4;
25543 }
e74cfd16 25544 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25545 mach = bfd_mach_arm_3M;
e74cfd16
PB
25546 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25547 mach = bfd_mach_arm_3;
25548 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25549 mach = bfd_mach_arm_2a;
25550 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25551 mach = bfd_mach_arm_2;
25552 else
25553 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25554
25555 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25556}
25557
c19d1205 25558/* Command line processing. */
b99bd4ef 25559
c19d1205
ZW
25560/* md_parse_option
25561 Invocation line includes a switch not recognized by the base assembler.
25562 See if it's a processor-specific option.
b99bd4ef 25563
c19d1205
ZW
25564 This routine is somewhat complicated by the need for backwards
25565 compatibility (since older releases of gcc can't be changed).
25566 The new options try to make the interface as compatible as
25567 possible with GCC.
b99bd4ef 25568
c19d1205 25569 New options (supported) are:
b99bd4ef 25570
c19d1205
ZW
25571 -mcpu=<cpu name> Assemble for selected processor
25572 -march=<architecture name> Assemble for selected architecture
25573 -mfpu=<fpu architecture> Assemble for selected FPU.
25574 -EB/-mbig-endian Big-endian
25575 -EL/-mlittle-endian Little-endian
25576 -k Generate PIC code
25577 -mthumb Start in Thumb mode
25578 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25579
278df34e 25580 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25581 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25582
c19d1205 25583 For now we will also provide support for:
b99bd4ef 25584
c19d1205
ZW
25585 -mapcs-32 32-bit Program counter
25586 -mapcs-26 26-bit Program counter
25587 -macps-float Floats passed in FP registers
25588 -mapcs-reentrant Reentrant code
25589 -matpcs
25590 (sometime these will probably be replaced with -mapcs=<list of options>
25591 and -matpcs=<list of options>)
b99bd4ef 25592
c19d1205
ZW
25593 The remaining options are only supported for back-wards compatibility.
25594 Cpu variants, the arm part is optional:
25595 -m[arm]1 Currently not supported.
25596 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25597 -m[arm]3 Arm 3 processor
25598 -m[arm]6[xx], Arm 6 processors
25599 -m[arm]7[xx][t][[d]m] Arm 7 processors
25600 -m[arm]8[10] Arm 8 processors
25601 -m[arm]9[20][tdmi] Arm 9 processors
25602 -mstrongarm[110[0]] StrongARM processors
25603 -mxscale XScale processors
25604 -m[arm]v[2345[t[e]]] Arm architectures
25605 -mall All (except the ARM1)
25606 FP variants:
25607 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25608 -mfpe-old (No float load/store multiples)
25609 -mvfpxd VFP Single precision
25610 -mvfp All VFP
25611 -mno-fpu Disable all floating point instructions
b99bd4ef 25612
c19d1205
ZW
25613 The following CPU names are recognized:
25614 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25615 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25616 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25617 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25618 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25619 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25620 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25621
c19d1205 25622 */
b99bd4ef 25623
c19d1205 25624const char * md_shortopts = "m:k";
b99bd4ef 25625
c19d1205
ZW
25626#ifdef ARM_BI_ENDIAN
25627#define OPTION_EB (OPTION_MD_BASE + 0)
25628#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25629#else
c19d1205
ZW
25630#if TARGET_BYTES_BIG_ENDIAN
25631#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25632#else
c19d1205
ZW
25633#define OPTION_EL (OPTION_MD_BASE + 1)
25634#endif
b99bd4ef 25635#endif
845b51d6 25636#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25637
c19d1205 25638struct option md_longopts[] =
b99bd4ef 25639{
c19d1205
ZW
25640#ifdef OPTION_EB
25641 {"EB", no_argument, NULL, OPTION_EB},
25642#endif
25643#ifdef OPTION_EL
25644 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25645#endif
845b51d6 25646 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25647 {NULL, no_argument, NULL, 0}
25648};
b99bd4ef 25649
c19d1205 25650size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25651
c19d1205 25652struct arm_option_table
b99bd4ef 25653{
0198d5e6
TC
25654 const char * option; /* Option name to match. */
25655 const char * help; /* Help information. */
25656 int * var; /* Variable to change. */
25657 int value; /* What to change it to. */
25658 const char * deprecated; /* If non-null, print this message. */
c19d1205 25659};
b99bd4ef 25660
c19d1205
ZW
25661struct arm_option_table arm_opts[] =
25662{
25663 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25664 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25665 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25666 &support_interwork, 1, NULL},
25667 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25668 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25669 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25670 1, NULL},
25671 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25672 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25673 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25674 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25675 NULL},
b99bd4ef 25676
c19d1205
ZW
25677 /* These are recognized by the assembler, but have no affect on code. */
25678 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25679 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25680
25681 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25682 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25683 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25684 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25685 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25686 {NULL, NULL, NULL, 0, NULL}
25687};
25688
25689struct arm_legacy_option_table
25690{
0198d5e6
TC
25691 const char * option; /* Option name to match. */
25692 const arm_feature_set ** var; /* Variable to change. */
25693 const arm_feature_set value; /* What to change it to. */
25694 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25695};
b99bd4ef 25696
e74cfd16
PB
25697const struct arm_legacy_option_table arm_legacy_opts[] =
25698{
c19d1205
ZW
25699 /* DON'T add any new processors to this list -- we want the whole list
25700 to go away... Add them to the processors table instead. */
e74cfd16
PB
25701 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25702 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25703 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25704 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25705 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25706 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25707 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25708 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25709 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25710 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25711 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25712 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25713 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25714 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25715 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25716 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25717 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25718 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25719 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25720 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25721 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25722 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25723 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25724 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25725 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25726 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25727 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25728 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25729 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25730 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25731 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25732 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25733 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25734 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25735 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25736 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25737 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25738 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25739 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25740 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25741 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25742 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25743 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25744 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25745 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25746 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25747 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25748 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25749 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25750 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25751 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25752 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25753 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25754 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25755 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25756 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25757 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25758 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25759 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25760 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25761 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25762 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25763 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25764 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25765 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25766 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25767 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25768 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25769 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25770 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25771 N_("use -mcpu=strongarm110")},
e74cfd16 25772 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25773 N_("use -mcpu=strongarm1100")},
e74cfd16 25774 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25775 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25776 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25777 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25778 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25779
c19d1205 25780 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25781 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25782 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25783 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25784 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25785 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25786 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25787 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25788 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25789 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25790 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25791 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25792 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25793 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25794 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25795 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25796 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25797 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25798 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25799
c19d1205 25800 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
25801 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25802 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25803 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25804 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25805 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25806
e74cfd16 25807 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25808};
7ed4c4c5 25809
c19d1205 25810struct arm_cpu_option_table
7ed4c4c5 25811{
0198d5e6
TC
25812 const char * name;
25813 size_t name_len;
25814 const arm_feature_set value;
25815 const arm_feature_set ext;
c19d1205
ZW
25816 /* For some CPUs we assume an FPU unless the user explicitly sets
25817 -mfpu=... */
0198d5e6 25818 const arm_feature_set default_fpu;
ee065d83
PB
25819 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25820 case. */
0198d5e6 25821 const char * canonical_name;
c19d1205 25822};
7ed4c4c5 25823
c19d1205
ZW
25824/* This list should, at a minimum, contain all the cpu names
25825 recognized by GCC. */
996b5569 25826#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 25827
e74cfd16 25828static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25829{
996b5569
TP
25830 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25831 ARM_ARCH_NONE,
25832 FPU_ARCH_FPA),
25833 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25834 ARM_ARCH_NONE,
25835 FPU_ARCH_FPA),
25836 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25837 ARM_ARCH_NONE,
25838 FPU_ARCH_FPA),
25839 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25840 ARM_ARCH_NONE,
25841 FPU_ARCH_FPA),
25842 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25843 ARM_ARCH_NONE,
25844 FPU_ARCH_FPA),
25845 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25846 ARM_ARCH_NONE,
25847 FPU_ARCH_FPA),
25848 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25849 ARM_ARCH_NONE,
25850 FPU_ARCH_FPA),
25851 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25852 ARM_ARCH_NONE,
25853 FPU_ARCH_FPA),
25854 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25855 ARM_ARCH_NONE,
25856 FPU_ARCH_FPA),
25857 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25858 ARM_ARCH_NONE,
25859 FPU_ARCH_FPA),
25860 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25861 ARM_ARCH_NONE,
25862 FPU_ARCH_FPA),
25863 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25864 ARM_ARCH_NONE,
25865 FPU_ARCH_FPA),
25866 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25867 ARM_ARCH_NONE,
25868 FPU_ARCH_FPA),
25869 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25870 ARM_ARCH_NONE,
25871 FPU_ARCH_FPA),
25872 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25873 ARM_ARCH_NONE,
25874 FPU_ARCH_FPA),
25875 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25876 ARM_ARCH_NONE,
25877 FPU_ARCH_FPA),
25878 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25879 ARM_ARCH_NONE,
25880 FPU_ARCH_FPA),
25881 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25882 ARM_ARCH_NONE,
25883 FPU_ARCH_FPA),
25884 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25885 ARM_ARCH_NONE,
25886 FPU_ARCH_FPA),
25887 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25888 ARM_ARCH_NONE,
25889 FPU_ARCH_FPA),
25890 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25891 ARM_ARCH_NONE,
25892 FPU_ARCH_FPA),
25893 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25894 ARM_ARCH_NONE,
25895 FPU_ARCH_FPA),
25896 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25897 ARM_ARCH_NONE,
25898 FPU_ARCH_FPA),
25899 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25900 ARM_ARCH_NONE,
25901 FPU_ARCH_FPA),
25902 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25903 ARM_ARCH_NONE,
25904 FPU_ARCH_FPA),
25905 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25906 ARM_ARCH_NONE,
25907 FPU_ARCH_FPA),
25908 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25909 ARM_ARCH_NONE,
25910 FPU_ARCH_FPA),
25911 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25912 ARM_ARCH_NONE,
25913 FPU_ARCH_FPA),
25914 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25915 ARM_ARCH_NONE,
25916 FPU_ARCH_FPA),
25917 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25918 ARM_ARCH_NONE,
25919 FPU_ARCH_FPA),
25920 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25921 ARM_ARCH_NONE,
25922 FPU_ARCH_FPA),
25923 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25924 ARM_ARCH_NONE,
25925 FPU_ARCH_FPA),
25926 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25927 ARM_ARCH_NONE,
25928 FPU_ARCH_FPA),
25929 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25930 ARM_ARCH_NONE,
25931 FPU_ARCH_FPA),
25932 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25933 ARM_ARCH_NONE,
25934 FPU_ARCH_FPA),
25935 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25936 ARM_ARCH_NONE,
25937 FPU_ARCH_FPA),
25938 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25939 ARM_ARCH_NONE,
25940 FPU_ARCH_FPA),
25941 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25942 ARM_ARCH_NONE,
25943 FPU_ARCH_FPA),
25944 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25945 ARM_ARCH_NONE,
25946 FPU_ARCH_FPA),
25947 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25948 ARM_ARCH_NONE,
25949 FPU_ARCH_FPA),
25950 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25951 ARM_ARCH_NONE,
25952 FPU_ARCH_FPA),
25953 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25954 ARM_ARCH_NONE,
25955 FPU_ARCH_FPA),
25956 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25957 ARM_ARCH_NONE,
25958 FPU_ARCH_FPA),
25959 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25960 ARM_ARCH_NONE,
25961 FPU_ARCH_FPA),
25962 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25963 ARM_ARCH_NONE,
25964 FPU_ARCH_FPA),
25965 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25966 ARM_ARCH_NONE,
25967 FPU_ARCH_FPA),
25968
c19d1205
ZW
25969 /* For V5 or later processors we default to using VFP; but the user
25970 should really set the FPU type explicitly. */
996b5569
TP
25971 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25972 ARM_ARCH_NONE,
25973 FPU_ARCH_VFP_V2),
25974 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25975 ARM_ARCH_NONE,
25976 FPU_ARCH_VFP_V2),
25977 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25978 ARM_ARCH_NONE,
25979 FPU_ARCH_VFP_V2),
25980 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25981 ARM_ARCH_NONE,
25982 FPU_ARCH_VFP_V2),
25983 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25984 ARM_ARCH_NONE,
25985 FPU_ARCH_VFP_V2),
25986 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25987 ARM_ARCH_NONE,
25988 FPU_ARCH_VFP_V2),
25989 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25990 ARM_ARCH_NONE,
25991 FPU_ARCH_VFP_V2),
25992 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25993 ARM_ARCH_NONE,
25994 FPU_ARCH_VFP_V2),
25995 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25996 ARM_ARCH_NONE,
25997 FPU_ARCH_VFP_V2),
25998 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25999 ARM_ARCH_NONE,
26000 FPU_ARCH_VFP_V2),
26001 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26002 ARM_ARCH_NONE,
26003 FPU_ARCH_VFP_V2),
26004 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26005 ARM_ARCH_NONE,
26006 FPU_ARCH_VFP_V2),
26007 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26008 ARM_ARCH_NONE,
26009 FPU_ARCH_VFP_V1),
26010 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26011 ARM_ARCH_NONE,
26012 FPU_ARCH_VFP_V1),
26013 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26014 ARM_ARCH_NONE,
26015 FPU_ARCH_VFP_V2),
26016 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26017 ARM_ARCH_NONE,
26018 FPU_ARCH_VFP_V2),
26019 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26020 ARM_ARCH_NONE,
26021 FPU_ARCH_VFP_V1),
26022 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26023 ARM_ARCH_NONE,
26024 FPU_ARCH_VFP_V2),
26025 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26026 ARM_ARCH_NONE,
26027 FPU_ARCH_VFP_V2),
26028 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26029 ARM_ARCH_NONE,
26030 FPU_ARCH_VFP_V2),
26031 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26032 ARM_ARCH_NONE,
26033 FPU_ARCH_VFP_V2),
26034 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26035 ARM_ARCH_NONE,
26036 FPU_ARCH_VFP_V2),
26037 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26038 ARM_ARCH_NONE,
26039 FPU_ARCH_VFP_V2),
26040 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26041 ARM_ARCH_NONE,
26042 FPU_ARCH_VFP_V2),
26043 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26044 ARM_ARCH_NONE,
26045 FPU_ARCH_VFP_V2),
26046 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26047 ARM_ARCH_NONE,
26048 FPU_ARCH_VFP_V2),
26049 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26050 ARM_ARCH_NONE,
26051 FPU_NONE),
26052 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26053 ARM_ARCH_NONE,
26054 FPU_NONE),
26055 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26056 ARM_ARCH_NONE,
26057 FPU_ARCH_VFP_V2),
26058 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26059 ARM_ARCH_NONE,
26060 FPU_ARCH_VFP_V2),
26061 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26062 ARM_ARCH_NONE,
26063 FPU_ARCH_VFP_V2),
26064 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26065 ARM_ARCH_NONE,
26066 FPU_NONE),
26067 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26068 ARM_ARCH_NONE,
26069 FPU_NONE),
26070 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26071 ARM_ARCH_NONE,
26072 FPU_ARCH_VFP_V2),
26073 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26074 ARM_ARCH_NONE,
26075 FPU_NONE),
26076 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26077 ARM_ARCH_NONE,
26078 FPU_ARCH_VFP_V2),
26079 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26080 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26081 FPU_NONE),
26082 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26083 ARM_ARCH_NONE,
26084 FPU_ARCH_NEON_VFP_V4),
26085 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26086 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26087 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26088 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26089 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26090 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26091 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26092 ARM_ARCH_NONE,
26093 FPU_ARCH_NEON_VFP_V4),
26094 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26095 ARM_ARCH_NONE,
26096 FPU_ARCH_NEON_VFP_V4),
26097 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26098 ARM_ARCH_NONE,
26099 FPU_ARCH_NEON_VFP_V4),
26100 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26101 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26102 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26103 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26104 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26105 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26106 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26107 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26108 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26109 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26110 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26111 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26112 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26113 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26114 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26115 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26116 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26117 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26118 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26119 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26120 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26121 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26122 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26123 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26124 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26125 ARM_ARCH_NONE,
26126 FPU_NONE),
26127 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26128 ARM_ARCH_NONE,
26129 FPU_ARCH_VFP_V3D16),
26130 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26131 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26132 FPU_NONE),
26133 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26134 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26135 FPU_ARCH_VFP_V3D16),
26136 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26137 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26138 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26139 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26140 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26141 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26142 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26143 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26144 FPU_NONE),
26145 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26146 ARM_ARCH_NONE,
26147 FPU_NONE),
26148 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26149 ARM_ARCH_NONE,
26150 FPU_NONE),
26151 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26152 ARM_ARCH_NONE,
26153 FPU_NONE),
26154 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26155 ARM_ARCH_NONE,
26156 FPU_NONE),
26157 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26158 ARM_ARCH_NONE,
26159 FPU_NONE),
26160 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26161 ARM_ARCH_NONE,
26162 FPU_NONE),
26163 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26164 ARM_ARCH_NONE,
26165 FPU_NONE),
26166 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26167 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26168 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 26169
c19d1205 26170 /* ??? XSCALE is really an architecture. */
996b5569
TP
26171 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26172 ARM_ARCH_NONE,
26173 FPU_ARCH_VFP_V2),
26174
c19d1205 26175 /* ??? iwmmxt is not a processor. */
996b5569
TP
26176 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26177 ARM_ARCH_NONE,
26178 FPU_ARCH_VFP_V2),
26179 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26180 ARM_ARCH_NONE,
26181 FPU_ARCH_VFP_V2),
26182 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26183 ARM_ARCH_NONE,
26184 FPU_ARCH_VFP_V2),
26185
0198d5e6 26186 /* Maverick. */
996b5569
TP
26187 ARM_CPU_OPT ("ep9312", "ARM920T",
26188 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26189 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26190
da4339ed 26191 /* Marvell processors. */
996b5569
TP
26192 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26193 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26194 FPU_ARCH_VFP_V3D16),
26195 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26196 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26197 FPU_ARCH_NEON_VFP_V4),
da4339ed 26198
996b5569
TP
26199 /* APM X-Gene family. */
26200 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26201 ARM_ARCH_NONE,
26202 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26203 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26204 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26205 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26206
26207 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26208};
f3bad469 26209#undef ARM_CPU_OPT
7ed4c4c5 26210
c19d1205 26211struct arm_arch_option_table
7ed4c4c5 26212{
0198d5e6
TC
26213 const char * name;
26214 size_t name_len;
26215 const arm_feature_set value;
26216 const arm_feature_set default_fpu;
c19d1205 26217};
7ed4c4c5 26218
c19d1205
ZW
26219/* This list should, at a minimum, contain all the architecture names
26220 recognized by GCC. */
f3bad469 26221#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
0198d5e6 26222
e74cfd16 26223static const struct arm_arch_option_table arm_archs[] =
c19d1205 26224{
f3bad469
MGD
26225 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26226 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26227 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26228 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26229 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26230 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26231 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26232 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26233 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26234 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26235 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26236 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26237 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26238 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26239 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26240 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26241 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26242 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26243 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26244 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26245 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26246 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26247 kept to preserve existing behaviour. */
26248 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26249 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
26250 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26251 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26252 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26253 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26254 kept to preserve existing behaviour. */
26255 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26256 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
26257 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26258 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26259 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26260 /* The official spelling of the ARMv7 profile variants is the dashed form.
26261 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 26262 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 26263 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
26264 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26265 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26266 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26267 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26268 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26269 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 26270 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 26271 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 26272 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 26273 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 26274 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 26275 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
ced40572 26276 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
dec41383 26277 ARM_ARCH_OPT ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP),
f3bad469
MGD
26278 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26279 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26280 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26281 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26282};
f3bad469 26283#undef ARM_ARCH_OPT
7ed4c4c5 26284
69133863 26285/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26286
69133863 26287struct arm_option_extension_value_table
c19d1205 26288{
0198d5e6
TC
26289 const char * name;
26290 size_t name_len;
26291 const arm_feature_set merge_value;
26292 const arm_feature_set clear_value;
d942732e
TP
26293 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26294 indicates that an extension is available for all architectures while
26295 ARM_ANY marks an empty entry. */
0198d5e6 26296 const arm_feature_set allowed_archs[2];
c19d1205 26297};
7ed4c4c5 26298
0198d5e6
TC
26299/* The following table must be in alphabetical order with a NULL last entry. */
26300
d942732e
TP
26301#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26302#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26303
69133863 26304static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26305{
823d2571
TG
26306 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26307 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26308 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26309 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26310 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26311 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26312 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26313 ARM_ARCH_V8_2A),
15afaa63
TP
26314 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26315 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26316 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26317 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26318 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26319 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26320 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26321 ARM_ARCH_V8_2A),
01f48020
TC
26322 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26323 | ARM_EXT2_FP16_FML),
26324 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26325 | ARM_EXT2_FP16_FML),
26326 ARM_ARCH_V8_2A),
d942732e 26327 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26328 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26329 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26330 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26331 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26332 Thumb divide instruction. Due to this having the same name as the
26333 previous entry, this will be ignored when doing command-line parsing and
26334 only considered by build attribute selection code. */
26335 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26336 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26337 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26338 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26339 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26340 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26341 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26342 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26343 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26344 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26345 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26346 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26347 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26348 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26349 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26350 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26351 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26352 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26353 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
4d1464f2
MW
26354 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26355 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26356 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26357 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26358 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26359 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
d942732e 26360 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26361 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26362 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26363 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26364 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26365 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26366 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26367 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26368 | ARM_EXT_DIV),
26369 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26370 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26371 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26372 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26373 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26374};
f3bad469 26375#undef ARM_EXT_OPT
69133863
MGD
26376
26377/* ISA floating-point and Advanced SIMD extensions. */
26378struct arm_option_fpu_value_table
26379{
0198d5e6
TC
26380 const char * name;
26381 const arm_feature_set value;
c19d1205 26382};
7ed4c4c5 26383
c19d1205
ZW
26384/* This list should, at a minimum, contain all the fpu names
26385 recognized by GCC. */
69133863 26386static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26387{
26388 {"softfpa", FPU_NONE},
26389 {"fpe", FPU_ARCH_FPE},
26390 {"fpe2", FPU_ARCH_FPE},
26391 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26392 {"fpa", FPU_ARCH_FPA},
26393 {"fpa10", FPU_ARCH_FPA},
26394 {"fpa11", FPU_ARCH_FPA},
26395 {"arm7500fe", FPU_ARCH_FPA},
26396 {"softvfp", FPU_ARCH_VFP},
26397 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26398 {"vfp", FPU_ARCH_VFP_V2},
26399 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26400 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26401 {"vfp10", FPU_ARCH_VFP_V2},
26402 {"vfp10-r0", FPU_ARCH_VFP_V1},
26403 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26404 {"vfpv2", FPU_ARCH_VFP_V2},
26405 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26406 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26407 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26408 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26409 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26410 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26411 {"arm1020t", FPU_ARCH_VFP_V1},
26412 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26413 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26414 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26415 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26416 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26417 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26418 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26419 {"vfpv4", FPU_ARCH_VFP_V4},
26420 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26421 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26422 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26423 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26424 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26425 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26426 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26427 {"crypto-neon-fp-armv8",
26428 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26429 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26430 {"crypto-neon-fp-armv8.1",
26431 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26432 {NULL, ARM_ARCH_NONE}
26433};
26434
26435struct arm_option_value_table
26436{
e0471c16 26437 const char *name;
e74cfd16 26438 long value;
c19d1205 26439};
7ed4c4c5 26440
e74cfd16 26441static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26442{
26443 {"hard", ARM_FLOAT_ABI_HARD},
26444 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26445 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26446 {NULL, 0}
c19d1205 26447};
7ed4c4c5 26448
c19d1205 26449#ifdef OBJ_ELF
3a4a14e9 26450/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26451static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26452{
26453 {"gnu", EF_ARM_EABI_UNKNOWN},
26454 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26455 {"5", EF_ARM_EABI_VER5},
e74cfd16 26456 {NULL, 0}
c19d1205
ZW
26457};
26458#endif
7ed4c4c5 26459
c19d1205
ZW
26460struct arm_long_option_table
26461{
0198d5e6 26462 const char * option; /* Substring to match. */
e0471c16 26463 const char * help; /* Help information. */
17b9d67d 26464 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26465 const char * deprecated; /* If non-null, print this message. */
c19d1205 26466};
7ed4c4c5 26467
c921be7d 26468static bfd_boolean
c168ce07 26469arm_parse_extension (const char *str, const arm_feature_set *opt_set,
4d354d8b 26470 arm_feature_set *ext_set)
7ed4c4c5 26471{
69133863 26472 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26473 extensions being added before being removed. We achieve this by having
26474 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26475 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26476 or removing it (0) and only allowing it to change in the order
69133863
MGD
26477 -1 -> 1 -> 0. */
26478 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26479 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26480 int adding_value = -1;
26481
c19d1205 26482 while (str != NULL && *str != 0)
7ed4c4c5 26483 {
82b8a785 26484 const char *ext;
f3bad469 26485 size_t len;
7ed4c4c5 26486
c19d1205
ZW
26487 if (*str != '+')
26488 {
26489 as_bad (_("invalid architectural extension"));
c921be7d 26490 return FALSE;
c19d1205 26491 }
7ed4c4c5 26492
c19d1205
ZW
26493 str++;
26494 ext = strchr (str, '+');
7ed4c4c5 26495
c19d1205 26496 if (ext != NULL)
f3bad469 26497 len = ext - str;
c19d1205 26498 else
f3bad469 26499 len = strlen (str);
7ed4c4c5 26500
f3bad469 26501 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26502 {
26503 if (adding_value != 0)
26504 {
26505 adding_value = 0;
26506 opt = arm_extensions;
26507 }
26508
f3bad469 26509 len -= 2;
69133863
MGD
26510 str += 2;
26511 }
f3bad469 26512 else if (len > 0)
69133863
MGD
26513 {
26514 if (adding_value == -1)
26515 {
26516 adding_value = 1;
26517 opt = arm_extensions;
26518 }
26519 else if (adding_value != 1)
26520 {
26521 as_bad (_("must specify extensions to add before specifying "
26522 "those to remove"));
26523 return FALSE;
26524 }
26525 }
26526
f3bad469 26527 if (len == 0)
c19d1205
ZW
26528 {
26529 as_bad (_("missing architectural extension"));
c921be7d 26530 return FALSE;
c19d1205 26531 }
7ed4c4c5 26532
69133863
MGD
26533 gas_assert (adding_value != -1);
26534 gas_assert (opt != NULL);
26535
26536 /* Scan over the options table trying to find an exact match. */
26537 for (; opt->name != NULL; opt++)
f3bad469 26538 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26539 {
d942732e
TP
26540 int i, nb_allowed_archs =
26541 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26542 /* Check we can apply the extension to this architecture. */
d942732e
TP
26543 for (i = 0; i < nb_allowed_archs; i++)
26544 {
26545 /* Empty entry. */
26546 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26547 continue;
c168ce07 26548 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26549 break;
26550 }
26551 if (i == nb_allowed_archs)
69133863
MGD
26552 {
26553 as_bad (_("extension does not apply to the base architecture"));
26554 return FALSE;
26555 }
26556
26557 /* Add or remove the extension. */
26558 if (adding_value)
4d354d8b 26559 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 26560 else
4d354d8b 26561 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 26562
3d030cdb
TP
26563 /* Allowing Thumb division instructions for ARMv7 in autodetection
26564 rely on this break so that duplicate extensions (extensions
26565 with the same name as a previous extension in the list) are not
26566 considered for command-line parsing. */
c19d1205
ZW
26567 break;
26568 }
7ed4c4c5 26569
c19d1205
ZW
26570 if (opt->name == NULL)
26571 {
69133863
MGD
26572 /* Did we fail to find an extension because it wasn't specified in
26573 alphabetical order, or because it does not exist? */
26574
26575 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26576 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26577 break;
26578
26579 if (opt->name == NULL)
26580 as_bad (_("unknown architectural extension `%s'"), str);
26581 else
26582 as_bad (_("architectural extensions must be specified in "
26583 "alphabetical order"));
26584
c921be7d 26585 return FALSE;
c19d1205 26586 }
69133863
MGD
26587 else
26588 {
26589 /* We should skip the extension we've just matched the next time
26590 round. */
26591 opt++;
26592 }
7ed4c4c5 26593
c19d1205
ZW
26594 str = ext;
26595 };
7ed4c4c5 26596
c921be7d 26597 return TRUE;
c19d1205 26598}
7ed4c4c5 26599
c921be7d 26600static bfd_boolean
17b9d67d 26601arm_parse_cpu (const char *str)
7ed4c4c5 26602{
f3bad469 26603 const struct arm_cpu_option_table *opt;
82b8a785 26604 const char *ext = strchr (str, '+');
f3bad469 26605 size_t len;
7ed4c4c5 26606
c19d1205 26607 if (ext != NULL)
f3bad469 26608 len = ext - str;
7ed4c4c5 26609 else
f3bad469 26610 len = strlen (str);
7ed4c4c5 26611
f3bad469 26612 if (len == 0)
7ed4c4c5 26613 {
c19d1205 26614 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26615 return FALSE;
7ed4c4c5
NC
26616 }
26617
c19d1205 26618 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26619 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26620 {
c168ce07 26621 mcpu_cpu_opt = &opt->value;
4d354d8b
TP
26622 if (mcpu_ext_opt == NULL)
26623 mcpu_ext_opt = XNEW (arm_feature_set);
26624 *mcpu_ext_opt = opt->ext;
e74cfd16 26625 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26626 if (opt->canonical_name)
ef8e6722
JW
26627 {
26628 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26629 strcpy (selected_cpu_name, opt->canonical_name);
26630 }
ee065d83
PB
26631 else
26632 {
f3bad469 26633 size_t i;
c921be7d 26634
ef8e6722
JW
26635 if (len >= sizeof selected_cpu_name)
26636 len = (sizeof selected_cpu_name) - 1;
26637
f3bad469 26638 for (i = 0; i < len; i++)
ee065d83
PB
26639 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26640 selected_cpu_name[i] = 0;
26641 }
7ed4c4c5 26642
c19d1205 26643 if (ext != NULL)
4d354d8b 26644 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt);
7ed4c4c5 26645
c921be7d 26646 return TRUE;
c19d1205 26647 }
7ed4c4c5 26648
c19d1205 26649 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26650 return FALSE;
7ed4c4c5
NC
26651}
26652
c921be7d 26653static bfd_boolean
17b9d67d 26654arm_parse_arch (const char *str)
7ed4c4c5 26655{
e74cfd16 26656 const struct arm_arch_option_table *opt;
82b8a785 26657 const char *ext = strchr (str, '+');
f3bad469 26658 size_t len;
7ed4c4c5 26659
c19d1205 26660 if (ext != NULL)
f3bad469 26661 len = ext - str;
7ed4c4c5 26662 else
f3bad469 26663 len = strlen (str);
7ed4c4c5 26664
f3bad469 26665 if (len == 0)
7ed4c4c5 26666 {
c19d1205 26667 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26668 return FALSE;
7ed4c4c5
NC
26669 }
26670
c19d1205 26671 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26672 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26673 {
e74cfd16 26674 march_cpu_opt = &opt->value;
4d354d8b
TP
26675 if (march_ext_opt == NULL)
26676 march_ext_opt = XNEW (arm_feature_set);
26677 *march_ext_opt = arm_arch_none;
e74cfd16 26678 march_fpu_opt = &opt->default_fpu;
5f4273c7 26679 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26680
c19d1205 26681 if (ext != NULL)
4d354d8b 26682 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt);
7ed4c4c5 26683
c921be7d 26684 return TRUE;
c19d1205
ZW
26685 }
26686
26687 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26688 return FALSE;
7ed4c4c5 26689}
eb043451 26690
c921be7d 26691static bfd_boolean
17b9d67d 26692arm_parse_fpu (const char * str)
c19d1205 26693{
69133863 26694 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26695
c19d1205
ZW
26696 for (opt = arm_fpus; opt->name != NULL; opt++)
26697 if (streq (opt->name, str))
26698 {
e74cfd16 26699 mfpu_opt = &opt->value;
c921be7d 26700 return TRUE;
c19d1205 26701 }
b99bd4ef 26702
c19d1205 26703 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26704 return FALSE;
c19d1205
ZW
26705}
26706
c921be7d 26707static bfd_boolean
17b9d67d 26708arm_parse_float_abi (const char * str)
b99bd4ef 26709{
e74cfd16 26710 const struct arm_option_value_table * opt;
b99bd4ef 26711
c19d1205
ZW
26712 for (opt = arm_float_abis; opt->name != NULL; opt++)
26713 if (streq (opt->name, str))
26714 {
26715 mfloat_abi_opt = opt->value;
c921be7d 26716 return TRUE;
c19d1205 26717 }
cc8a6dd0 26718
c19d1205 26719 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26720 return FALSE;
c19d1205 26721}
b99bd4ef 26722
c19d1205 26723#ifdef OBJ_ELF
c921be7d 26724static bfd_boolean
17b9d67d 26725arm_parse_eabi (const char * str)
c19d1205 26726{
e74cfd16 26727 const struct arm_option_value_table *opt;
cc8a6dd0 26728
c19d1205
ZW
26729 for (opt = arm_eabis; opt->name != NULL; opt++)
26730 if (streq (opt->name, str))
26731 {
26732 meabi_flags = opt->value;
c921be7d 26733 return TRUE;
c19d1205
ZW
26734 }
26735 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26736 return FALSE;
c19d1205
ZW
26737}
26738#endif
cc8a6dd0 26739
c921be7d 26740static bfd_boolean
17b9d67d 26741arm_parse_it_mode (const char * str)
e07e6e58 26742{
c921be7d 26743 bfd_boolean ret = TRUE;
e07e6e58
NC
26744
26745 if (streq ("arm", str))
26746 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26747 else if (streq ("thumb", str))
26748 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26749 else if (streq ("always", str))
26750 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26751 else if (streq ("never", str))
26752 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26753 else
26754 {
26755 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26756 "arm, thumb, always, or never."), str);
c921be7d 26757 ret = FALSE;
e07e6e58
NC
26758 }
26759
26760 return ret;
26761}
26762
2e6976a8 26763static bfd_boolean
17b9d67d 26764arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26765{
26766 codecomposer_syntax = TRUE;
26767 arm_comment_chars[0] = ';';
26768 arm_line_separator_chars[0] = 0;
26769 return TRUE;
26770}
26771
c19d1205
ZW
26772struct arm_long_option_table arm_long_opts[] =
26773{
26774 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26775 arm_parse_cpu, NULL},
26776 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26777 arm_parse_arch, NULL},
26778 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26779 arm_parse_fpu, NULL},
26780 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26781 arm_parse_float_abi, NULL},
26782#ifdef OBJ_ELF
7fac0536 26783 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26784 arm_parse_eabi, NULL},
26785#endif
e07e6e58
NC
26786 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26787 arm_parse_it_mode, NULL},
2e6976a8
DG
26788 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26789 arm_ccs_mode, NULL},
c19d1205
ZW
26790 {NULL, NULL, 0, NULL}
26791};
cc8a6dd0 26792
c19d1205 26793int
17b9d67d 26794md_parse_option (int c, const char * arg)
c19d1205
ZW
26795{
26796 struct arm_option_table *opt;
e74cfd16 26797 const struct arm_legacy_option_table *fopt;
c19d1205 26798 struct arm_long_option_table *lopt;
b99bd4ef 26799
c19d1205 26800 switch (c)
b99bd4ef 26801 {
c19d1205
ZW
26802#ifdef OPTION_EB
26803 case OPTION_EB:
26804 target_big_endian = 1;
26805 break;
26806#endif
cc8a6dd0 26807
c19d1205
ZW
26808#ifdef OPTION_EL
26809 case OPTION_EL:
26810 target_big_endian = 0;
26811 break;
26812#endif
b99bd4ef 26813
845b51d6
PB
26814 case OPTION_FIX_V4BX:
26815 fix_v4bx = TRUE;
26816 break;
26817
c19d1205
ZW
26818 case 'a':
26819 /* Listing option. Just ignore these, we don't support additional
26820 ones. */
26821 return 0;
b99bd4ef 26822
c19d1205
ZW
26823 default:
26824 for (opt = arm_opts; opt->option != NULL; opt++)
26825 {
26826 if (c == opt->option[0]
26827 && ((arg == NULL && opt->option[1] == 0)
26828 || streq (arg, opt->option + 1)))
26829 {
c19d1205 26830 /* If the option is deprecated, tell the user. */
278df34e 26831 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26832 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26833 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26834
c19d1205
ZW
26835 if (opt->var != NULL)
26836 *opt->var = opt->value;
cc8a6dd0 26837
c19d1205
ZW
26838 return 1;
26839 }
26840 }
b99bd4ef 26841
e74cfd16
PB
26842 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26843 {
26844 if (c == fopt->option[0]
26845 && ((arg == NULL && fopt->option[1] == 0)
26846 || streq (arg, fopt->option + 1)))
26847 {
e74cfd16 26848 /* If the option is deprecated, tell the user. */
278df34e 26849 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26850 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26851 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26852
26853 if (fopt->var != NULL)
26854 *fopt->var = &fopt->value;
26855
26856 return 1;
26857 }
26858 }
26859
c19d1205
ZW
26860 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26861 {
26862 /* These options are expected to have an argument. */
26863 if (c == lopt->option[0]
26864 && arg != NULL
26865 && strncmp (arg, lopt->option + 1,
26866 strlen (lopt->option + 1)) == 0)
26867 {
c19d1205 26868 /* If the option is deprecated, tell the user. */
278df34e 26869 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26870 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26871 _(lopt->deprecated));
b99bd4ef 26872
c19d1205
ZW
26873 /* Call the sup-option parser. */
26874 return lopt->func (arg + strlen (lopt->option) - 1);
26875 }
26876 }
a737bd4d 26877
c19d1205
ZW
26878 return 0;
26879 }
a394c00f 26880
c19d1205
ZW
26881 return 1;
26882}
a394c00f 26883
c19d1205
ZW
26884void
26885md_show_usage (FILE * fp)
a394c00f 26886{
c19d1205
ZW
26887 struct arm_option_table *opt;
26888 struct arm_long_option_table *lopt;
a394c00f 26889
c19d1205 26890 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26891
c19d1205
ZW
26892 for (opt = arm_opts; opt->option != NULL; opt++)
26893 if (opt->help != NULL)
26894 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26895
c19d1205
ZW
26896 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26897 if (lopt->help != NULL)
26898 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26899
c19d1205
ZW
26900#ifdef OPTION_EB
26901 fprintf (fp, _("\
26902 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26903#endif
26904
c19d1205
ZW
26905#ifdef OPTION_EL
26906 fprintf (fp, _("\
26907 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26908#endif
845b51d6
PB
26909
26910 fprintf (fp, _("\
26911 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26912}
ee065d83 26913
ee065d83 26914#ifdef OBJ_ELF
0198d5e6 26915
62b3e311
PB
26916typedef struct
26917{
26918 int val;
26919 arm_feature_set flags;
26920} cpu_arch_ver_table;
26921
2c6b98ea
TP
26922/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26923 chronologically for architectures, with an exception for ARMv6-M and
26924 ARMv6S-M due to legacy reasons. No new architecture should have a
26925 special case. This allows for build attribute selection results to be
26926 stable when new architectures are added. */
62b3e311
PB
26927static const cpu_arch_ver_table cpu_arch_ver[] =
26928{
2c6b98ea
TP
26929 {0, ARM_ARCH_V1},
26930 {0, ARM_ARCH_V2},
26931 {0, ARM_ARCH_V2S},
26932 {0, ARM_ARCH_V3},
26933 {0, ARM_ARCH_V3M},
26934 {1, ARM_ARCH_V4xM},
62b3e311 26935 {1, ARM_ARCH_V4},
2c6b98ea 26936 {2, ARM_ARCH_V4TxM},
62b3e311 26937 {2, ARM_ARCH_V4T},
2c6b98ea 26938 {3, ARM_ARCH_V5xM},
62b3e311 26939 {3, ARM_ARCH_V5},
2c6b98ea 26940 {3, ARM_ARCH_V5TxM},
ee3c0378 26941 {3, ARM_ARCH_V5T},
2c6b98ea 26942 {4, ARM_ARCH_V5TExP},
62b3e311
PB
26943 {4, ARM_ARCH_V5TE},
26944 {5, ARM_ARCH_V5TEJ},
26945 {6, ARM_ARCH_V6},
f4c65163 26946 {7, ARM_ARCH_V6Z},
2c6b98ea
TP
26947 {7, ARM_ARCH_V6KZ},
26948 {9, ARM_ARCH_V6K},
26949 {8, ARM_ARCH_V6T2},
26950 {8, ARM_ARCH_V6KT2},
26951 {8, ARM_ARCH_V6ZT2},
26952 {8, ARM_ARCH_V6KZT2},
26953
26954 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
26955 always selected build attributes to match those of ARMv6-M
26956 (resp. ARMv6S-M). However, due to these architectures being a strict
26957 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
26958 would be selected when fully respecting chronology of architectures.
26959 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
26960 move them before ARMv7 architectures. */
91e22acd 26961 {11, ARM_ARCH_V6M},
b2a5fbdc 26962 {12, ARM_ARCH_V6SM},
2c6b98ea
TP
26963
26964 {10, ARM_ARCH_V7},
26965 {10, ARM_ARCH_V7A},
62b3e311
PB
26966 {10, ARM_ARCH_V7R},
26967 {10, ARM_ARCH_V7M},
2c6b98ea
TP
26968 {10, ARM_ARCH_V7VE},
26969 {13, ARM_ARCH_V7EM},
bca38921 26970 {14, ARM_ARCH_V8A},
2c6b98ea
TP
26971 {14, ARM_ARCH_V8_1A},
26972 {14, ARM_ARCH_V8_2A},
26973 {14, ARM_ARCH_V8_3A},
ff8646ee 26974 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26975 {17, ARM_ARCH_V8M_MAIN},
ced40572 26976 {15, ARM_ARCH_V8R},
49ded53d 26977 {14, ARM_ARCH_V8_4A},
2c6b98ea 26978 {-1, ARM_ARCH_NONE}
62b3e311
PB
26979};
26980
ee3c0378 26981/* Set an attribute if it has not already been set by the user. */
0198d5e6 26982
ee3c0378
AS
26983static void
26984aeabi_set_attribute_int (int tag, int value)
26985{
26986 if (tag < 1
26987 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26988 || !attributes_set_explicitly[tag])
26989 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26990}
26991
26992static void
26993aeabi_set_attribute_string (int tag, const char *value)
26994{
26995 if (tag < 1
26996 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26997 || !attributes_set_explicitly[tag])
26998 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26999}
27000
2c6b98ea
TP
27001/* Return whether features in the *NEEDED feature set are available via
27002 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 27003
2c6b98ea
TP
27004static bfd_boolean
27005have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27006 const arm_feature_set *needed)
27007{
27008 int i, nb_allowed_archs;
27009 arm_feature_set ext_fset;
27010 const struct arm_option_extension_value_table *opt;
27011
27012 ext_fset = arm_arch_none;
27013 for (opt = arm_extensions; opt->name != NULL; opt++)
27014 {
27015 /* Extension does not provide any feature we need. */
27016 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27017 continue;
27018
27019 nb_allowed_archs =
27020 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27021 for (i = 0; i < nb_allowed_archs; i++)
27022 {
27023 /* Empty entry. */
27024 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27025 break;
27026
27027 /* Extension is available, add it. */
27028 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27029 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27030 }
27031 }
27032
27033 /* Can we enable all features in *needed? */
27034 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27035}
27036
27037/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27038 a given architecture feature set *ARCH_EXT_FSET including extension feature
27039 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27040 - if true, check for an exact match of the architecture modulo extensions;
27041 - otherwise, select build attribute value of the first superset
27042 architecture released so that results remains stable when new architectures
27043 are added.
27044 For -march/-mcpu=all the build attribute value of the most featureful
27045 architecture is returned. Tag_CPU_arch_profile result is returned in
27046 PROFILE. */
0198d5e6 27047
2c6b98ea
TP
27048static int
27049get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27050 const arm_feature_set *ext_fset,
27051 char *profile, int exact_match)
27052{
27053 arm_feature_set arch_fset;
27054 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27055
27056 /* Select most featureful architecture with all its extensions if building
27057 for -march=all as the feature sets used to set build attributes. */
27058 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27059 {
27060 /* Force revisiting of decision for each new architecture. */
27061 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
27062 *profile = 'A';
27063 return TAG_CPU_ARCH_V8;
27064 }
27065
27066 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27067
27068 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27069 {
27070 arm_feature_set known_arch_fset;
27071
27072 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27073 if (exact_match)
27074 {
27075 /* Base architecture match user-specified architecture and
27076 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27077 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27078 {
27079 p_ver_ret = p_ver;
27080 goto found;
27081 }
27082 /* Base architecture match user-specified architecture only
27083 (eg. ARMv6-M in the same case as above). Record it in case we
27084 find a match with above condition. */
27085 else if (p_ver_ret == NULL
27086 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27087 p_ver_ret = p_ver;
27088 }
27089 else
27090 {
27091
27092 /* Architecture has all features wanted. */
27093 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27094 {
27095 arm_feature_set added_fset;
27096
27097 /* Compute features added by this architecture over the one
27098 recorded in p_ver_ret. */
27099 if (p_ver_ret != NULL)
27100 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27101 p_ver_ret->flags);
27102 /* First architecture that match incl. with extensions, or the
27103 only difference in features over the recorded match is
27104 features that were optional and are now mandatory. */
27105 if (p_ver_ret == NULL
27106 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27107 {
27108 p_ver_ret = p_ver;
27109 goto found;
27110 }
27111 }
27112 else if (p_ver_ret == NULL)
27113 {
27114 arm_feature_set needed_ext_fset;
27115
27116 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27117
27118 /* Architecture has all features needed when using some
27119 extensions. Record it and continue searching in case there
27120 exist an architecture providing all needed features without
27121 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27122 OS extension). */
27123 if (have_ext_for_needed_feat_p (&known_arch_fset,
27124 &needed_ext_fset))
27125 p_ver_ret = p_ver;
27126 }
27127 }
27128 }
27129
27130 if (p_ver_ret == NULL)
27131 return -1;
27132
27133found:
27134 /* Tag_CPU_arch_profile. */
27135 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27136 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27137 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27138 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27139 *profile = 'A';
27140 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27141 *profile = 'R';
27142 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27143 *profile = 'M';
27144 else
27145 *profile = '\0';
27146 return p_ver_ret->val;
27147}
27148
ee065d83 27149/* Set the public EABI object attributes. */
0198d5e6 27150
c168ce07 27151static void
ee065d83
PB
27152aeabi_set_public_attributes (void)
27153{
b90d5ba0 27154 char profile = '\0';
2c6b98ea 27155 int arch = -1;
90ec0d68 27156 int virt_sec = 0;
bca38921 27157 int fp16_optional = 0;
2c6b98ea
TP
27158 int skip_exact_match = 0;
27159 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 27160
54bab281
TP
27161 /* Autodetection mode, choose the architecture based the instructions
27162 actually used. */
27163 if (no_cpu_selected ())
27164 {
27165 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 27166
54bab281
TP
27167 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27168 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 27169
54bab281
TP
27170 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27171 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 27172
54bab281 27173 /* Code run during relaxation relies on selected_cpu being set. */
4d354d8b
TP
27174 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27175 flags_ext = arm_arch_none;
27176 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
27177 selected_ext = flags_ext;
54bab281
TP
27178 selected_cpu = flags;
27179 }
27180 /* Otherwise, choose the architecture based on the capabilities of the
27181 requested cpu. */
27182 else
4d354d8b
TP
27183 {
27184 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
27185 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
27186 flags_ext = selected_ext;
27187 flags = selected_cpu;
27188 }
27189 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
7f78eb34 27190
ddd7f988 27191 /* Allow the user to override the reported architecture. */
4d354d8b 27192 if (!ARM_FEATURE_ZERO (selected_object_arch))
7a1d4c38 27193 {
4d354d8b 27194 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
2c6b98ea 27195 flags_ext = arm_arch_none;
7a1d4c38 27196 }
2c6b98ea 27197 else
4d354d8b 27198 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
2c6b98ea
TP
27199
27200 /* When this function is run again after relaxation has happened there is no
27201 way to determine whether an architecture or CPU was specified by the user:
27202 - selected_cpu is set above for relaxation to work;
27203 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27204 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27205 Therefore, if not in -march=all case we first try an exact match and fall
27206 back to autodetection. */
27207 if (!skip_exact_match)
27208 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27209 if (arch == -1)
27210 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27211 if (arch == -1)
27212 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 27213
ee065d83
PB
27214 /* Tag_CPU_name. */
27215 if (selected_cpu_name[0])
27216 {
91d6fa6a 27217 char *q;
ee065d83 27218
91d6fa6a
NC
27219 q = selected_cpu_name;
27220 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
27221 {
27222 int i;
5f4273c7 27223
91d6fa6a
NC
27224 q += 4;
27225 for (i = 0; q[i]; i++)
27226 q[i] = TOUPPER (q[i]);
ee065d83 27227 }
91d6fa6a 27228 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 27229 }
62f3b8c8 27230
ee065d83 27231 /* Tag_CPU_arch. */
ee3c0378 27232 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 27233
62b3e311 27234 /* Tag_CPU_arch_profile. */
69239280
MGD
27235 if (profile != '\0')
27236 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 27237
15afaa63 27238 /* Tag_DSP_extension. */
4d354d8b 27239 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
6c290d53 27240 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 27241
2c6b98ea 27242 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 27243 /* Tag_ARM_ISA_use. */
ee3c0378 27244 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27245 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27246 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27247
ee065d83 27248 /* Tag_THUMB_ISA_use. */
ee3c0378 27249 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27250 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27251 {
27252 int thumb_isa_use;
27253
27254 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27255 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27256 thumb_isa_use = 3;
27257 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27258 thumb_isa_use = 2;
27259 else
27260 thumb_isa_use = 1;
27261 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27262 }
62f3b8c8 27263
ee065d83 27264 /* Tag_VFP_arch. */
a715796b
TG
27265 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27266 aeabi_set_attribute_int (Tag_VFP_arch,
27267 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27268 ? 7 : 8);
bca38921 27269 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27270 aeabi_set_attribute_int (Tag_VFP_arch,
27271 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27272 ? 5 : 6);
27273 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27274 {
27275 fp16_optional = 1;
27276 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27277 }
ada65aa3 27278 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27279 {
27280 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27281 fp16_optional = 1;
27282 }
ee3c0378
AS
27283 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27284 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27285 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27286 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27287 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27288
4547cb56
NC
27289 /* Tag_ABI_HardFP_use. */
27290 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27291 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27292 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27293
ee065d83 27294 /* Tag_WMMX_arch. */
ee3c0378
AS
27295 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27296 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27297 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27298 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27299
ee3c0378 27300 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27301 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27302 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27303 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27304 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27305 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27306 {
27307 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27308 {
27309 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27310 }
27311 else
27312 {
27313 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27314 fp16_optional = 1;
27315 }
27316 }
fa94de6b 27317
ee3c0378 27318 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27319 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27320 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27321
69239280
MGD
27322 /* Tag_DIV_use.
27323
27324 We set Tag_DIV_use to two when integer divide instructions have been used
27325 in ARM state, or when Thumb integer divide instructions have been used,
27326 but we have no architecture profile set, nor have we any ARM instructions.
27327
4ed7ed8d
TP
27328 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27329 by the base architecture.
bca38921 27330
69239280 27331 For new architectures we will have to check these tests. */
ced40572 27332 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27333 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27334 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27335 aeabi_set_attribute_int (Tag_DIV_use, 0);
27336 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27337 || (profile == '\0'
27338 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27339 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27340 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27341
27342 /* Tag_MP_extension_use. */
27343 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27344 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27345
27346 /* Tag Virtualization_use. */
27347 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27348 virt_sec |= 1;
27349 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27350 virt_sec |= 2;
27351 if (virt_sec != 0)
27352 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27353}
27354
c168ce07
TP
27355/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27356 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27357
c168ce07
TP
27358void
27359arm_md_post_relax (void)
27360{
27361 aeabi_set_public_attributes ();
4d354d8b
TP
27362 XDELETE (mcpu_ext_opt);
27363 mcpu_ext_opt = NULL;
27364 XDELETE (march_ext_opt);
27365 march_ext_opt = NULL;
c168ce07
TP
27366}
27367
104d59d1 27368/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27369
ee065d83
PB
27370void
27371arm_md_end (void)
27372{
ee065d83
PB
27373 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27374 return;
27375
27376 aeabi_set_public_attributes ();
ee065d83 27377}
8463be01 27378#endif /* OBJ_ELF */
ee065d83 27379
ee065d83
PB
27380/* Parse a .cpu directive. */
27381
27382static void
27383s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27384{
e74cfd16 27385 const struct arm_cpu_option_table *opt;
ee065d83
PB
27386 char *name;
27387 char saved_char;
27388
27389 name = input_line_pointer;
5f4273c7 27390 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27391 input_line_pointer++;
27392 saved_char = *input_line_pointer;
27393 *input_line_pointer = 0;
27394
27395 /* Skip the first "all" entry. */
27396 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27397 if (streq (opt->name, name))
27398 {
4d354d8b
TP
27399 selected_arch = opt->value;
27400 selected_ext = opt->ext;
27401 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
ee065d83 27402 if (opt->canonical_name)
5f4273c7 27403 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27404 else
27405 {
27406 int i;
27407 for (i = 0; opt->name[i]; i++)
27408 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27409
ee065d83
PB
27410 selected_cpu_name[i] = 0;
27411 }
4d354d8b
TP
27412 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27413
ee065d83
PB
27414 *input_line_pointer = saved_char;
27415 demand_empty_rest_of_line ();
27416 return;
27417 }
27418 as_bad (_("unknown cpu `%s'"), name);
27419 *input_line_pointer = saved_char;
27420 ignore_rest_of_line ();
27421}
27422
ee065d83
PB
27423/* Parse a .arch directive. */
27424
27425static void
27426s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27427{
e74cfd16 27428 const struct arm_arch_option_table *opt;
ee065d83
PB
27429 char saved_char;
27430 char *name;
27431
27432 name = input_line_pointer;
5f4273c7 27433 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27434 input_line_pointer++;
27435 saved_char = *input_line_pointer;
27436 *input_line_pointer = 0;
27437
27438 /* Skip the first "all" entry. */
27439 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27440 if (streq (opt->name, name))
27441 {
4d354d8b
TP
27442 selected_arch = opt->value;
27443 selected_ext = arm_arch_none;
27444 selected_cpu = selected_arch;
5f4273c7 27445 strcpy (selected_cpu_name, opt->name);
4d354d8b 27446 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
27447 *input_line_pointer = saved_char;
27448 demand_empty_rest_of_line ();
27449 return;
27450 }
27451
27452 as_bad (_("unknown architecture `%s'\n"), name);
27453 *input_line_pointer = saved_char;
27454 ignore_rest_of_line ();
27455}
27456
7a1d4c38
PB
27457/* Parse a .object_arch directive. */
27458
27459static void
27460s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27461{
27462 const struct arm_arch_option_table *opt;
27463 char saved_char;
27464 char *name;
27465
27466 name = input_line_pointer;
5f4273c7 27467 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27468 input_line_pointer++;
27469 saved_char = *input_line_pointer;
27470 *input_line_pointer = 0;
27471
27472 /* Skip the first "all" entry. */
27473 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27474 if (streq (opt->name, name))
27475 {
4d354d8b 27476 selected_object_arch = opt->value;
7a1d4c38
PB
27477 *input_line_pointer = saved_char;
27478 demand_empty_rest_of_line ();
27479 return;
27480 }
27481
27482 as_bad (_("unknown architecture `%s'\n"), name);
27483 *input_line_pointer = saved_char;
27484 ignore_rest_of_line ();
27485}
27486
69133863
MGD
27487/* Parse a .arch_extension directive. */
27488
27489static void
27490s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27491{
27492 const struct arm_option_extension_value_table *opt;
27493 char saved_char;
27494 char *name;
27495 int adding_value = 1;
27496
27497 name = input_line_pointer;
27498 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27499 input_line_pointer++;
27500 saved_char = *input_line_pointer;
27501 *input_line_pointer = 0;
27502
27503 if (strlen (name) >= 2
27504 && strncmp (name, "no", 2) == 0)
27505 {
27506 adding_value = 0;
27507 name += 2;
27508 }
27509
27510 for (opt = arm_extensions; opt->name != NULL; opt++)
27511 if (streq (opt->name, name))
27512 {
d942732e
TP
27513 int i, nb_allowed_archs =
27514 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27515 for (i = 0; i < nb_allowed_archs; i++)
27516 {
27517 /* Empty entry. */
4d354d8b 27518 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
d942732e 27519 continue;
4d354d8b 27520 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
d942732e
TP
27521 break;
27522 }
27523
27524 if (i == nb_allowed_archs)
69133863
MGD
27525 {
27526 as_bad (_("architectural extension `%s' is not allowed for the "
27527 "current base architecture"), name);
27528 break;
27529 }
27530
27531 if (adding_value)
4d354d8b 27532 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
5a70a223 27533 opt->merge_value);
69133863 27534 else
4d354d8b 27535 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
69133863 27536
4d354d8b
TP
27537 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
27538 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
69133863
MGD
27539 *input_line_pointer = saved_char;
27540 demand_empty_rest_of_line ();
3d030cdb
TP
27541 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27542 on this return so that duplicate extensions (extensions with the
27543 same name as a previous extension in the list) are not considered
27544 for command-line parsing. */
69133863
MGD
27545 return;
27546 }
27547
27548 if (opt->name == NULL)
e673710a 27549 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27550
27551 *input_line_pointer = saved_char;
27552 ignore_rest_of_line ();
27553}
27554
ee065d83
PB
27555/* Parse a .fpu directive. */
27556
27557static void
27558s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27559{
69133863 27560 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27561 char saved_char;
27562 char *name;
27563
27564 name = input_line_pointer;
5f4273c7 27565 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27566 input_line_pointer++;
27567 saved_char = *input_line_pointer;
27568 *input_line_pointer = 0;
5f4273c7 27569
ee065d83
PB
27570 for (opt = arm_fpus; opt->name != NULL; opt++)
27571 if (streq (opt->name, name))
27572 {
4d354d8b
TP
27573 selected_fpu = opt->value;
27574#ifndef CPU_DEFAULT
27575 if (no_cpu_selected ())
27576 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
27577 else
27578#endif
27579 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
ee065d83
PB
27580 *input_line_pointer = saved_char;
27581 demand_empty_rest_of_line ();
27582 return;
27583 }
27584
27585 as_bad (_("unknown floating point format `%s'\n"), name);
27586 *input_line_pointer = saved_char;
27587 ignore_rest_of_line ();
27588}
ee065d83 27589
794ba86a 27590/* Copy symbol information. */
f31fef98 27591
794ba86a
DJ
27592void
27593arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27594{
27595 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27596}
e04befd0 27597
f31fef98 27598#ifdef OBJ_ELF
e04befd0
AS
27599/* Given a symbolic attribute NAME, return the proper integer value.
27600 Returns -1 if the attribute is not known. */
f31fef98 27601
e04befd0
AS
27602int
27603arm_convert_symbolic_attribute (const char *name)
27604{
f31fef98
NC
27605 static const struct
27606 {
27607 const char * name;
27608 const int tag;
27609 }
27610 attribute_table[] =
27611 {
27612 /* When you modify this table you should
27613 also modify the list in doc/c-arm.texi. */
e04befd0 27614#define T(tag) {#tag, tag}
f31fef98
NC
27615 T (Tag_CPU_raw_name),
27616 T (Tag_CPU_name),
27617 T (Tag_CPU_arch),
27618 T (Tag_CPU_arch_profile),
27619 T (Tag_ARM_ISA_use),
27620 T (Tag_THUMB_ISA_use),
75375b3e 27621 T (Tag_FP_arch),
f31fef98
NC
27622 T (Tag_VFP_arch),
27623 T (Tag_WMMX_arch),
27624 T (Tag_Advanced_SIMD_arch),
27625 T (Tag_PCS_config),
27626 T (Tag_ABI_PCS_R9_use),
27627 T (Tag_ABI_PCS_RW_data),
27628 T (Tag_ABI_PCS_RO_data),
27629 T (Tag_ABI_PCS_GOT_use),
27630 T (Tag_ABI_PCS_wchar_t),
27631 T (Tag_ABI_FP_rounding),
27632 T (Tag_ABI_FP_denormal),
27633 T (Tag_ABI_FP_exceptions),
27634 T (Tag_ABI_FP_user_exceptions),
27635 T (Tag_ABI_FP_number_model),
75375b3e 27636 T (Tag_ABI_align_needed),
f31fef98 27637 T (Tag_ABI_align8_needed),
75375b3e 27638 T (Tag_ABI_align_preserved),
f31fef98
NC
27639 T (Tag_ABI_align8_preserved),
27640 T (Tag_ABI_enum_size),
27641 T (Tag_ABI_HardFP_use),
27642 T (Tag_ABI_VFP_args),
27643 T (Tag_ABI_WMMX_args),
27644 T (Tag_ABI_optimization_goals),
27645 T (Tag_ABI_FP_optimization_goals),
27646 T (Tag_compatibility),
27647 T (Tag_CPU_unaligned_access),
75375b3e 27648 T (Tag_FP_HP_extension),
f31fef98
NC
27649 T (Tag_VFP_HP_extension),
27650 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27651 T (Tag_MPextension_use),
27652 T (Tag_DIV_use),
f31fef98
NC
27653 T (Tag_nodefaults),
27654 T (Tag_also_compatible_with),
27655 T (Tag_conformance),
27656 T (Tag_T2EE_use),
27657 T (Tag_Virtualization_use),
15afaa63 27658 T (Tag_DSP_extension),
cd21e546 27659 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27660#undef T
f31fef98 27661 };
e04befd0
AS
27662 unsigned int i;
27663
27664 if (name == NULL)
27665 return -1;
27666
f31fef98 27667 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27668 if (streq (name, attribute_table[i].name))
e04befd0
AS
27669 return attribute_table[i].tag;
27670
27671 return -1;
27672}
267bf995 27673
93ef582d
NC
27674/* Apply sym value for relocations only in the case that they are for
27675 local symbols in the same segment as the fixup and you have the
27676 respective architectural feature for blx and simple switches. */
0198d5e6 27677
267bf995 27678int
93ef582d 27679arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27680{
27681 if (fixP->fx_addsy
27682 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27683 /* PR 17444: If the local symbol is in a different section then a reloc
27684 will always be generated for it, so applying the symbol value now
27685 will result in a double offset being stored in the relocation. */
27686 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27687 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27688 {
27689 switch (fixP->fx_r_type)
27690 {
27691 case BFD_RELOC_ARM_PCREL_BLX:
27692 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27693 if (ARM_IS_FUNC (fixP->fx_addsy))
27694 return 1;
27695 break;
27696
27697 case BFD_RELOC_ARM_PCREL_CALL:
27698 case BFD_RELOC_THUMB_PCREL_BLX:
27699 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27700 return 1;
267bf995
RR
27701 break;
27702
27703 default:
27704 break;
27705 }
27706
27707 }
27708 return 0;
27709}
f31fef98 27710#endif /* OBJ_ELF */
This page took 3.975248 seconds and 4 git commands to generate.