]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
PR22374, PowerPC unnecessary PLT entries
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
2571583a 2 Copyright (C) 1994-2017 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
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
c168ce07 150static arm_feature_set *dyn_mcpu_ext_opt = NULL;
e74cfd16
PB
151static const arm_feature_set *mcpu_fpu_opt = NULL;
152static const arm_feature_set *march_cpu_opt = NULL;
c168ce07 153static arm_feature_set *dyn_march_ext_opt = NULL;
e74cfd16
PB
154static const arm_feature_set *march_fpu_opt = NULL;
155static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 156static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
157
158/* Constants for known architecture features. */
159static const arm_feature_set fpu_default = FPU_DEFAULT;
f85d59c3 160static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 161static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
162static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
163static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
e74cfd16
PB
164static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
165static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
69c9e028 166#ifdef OBJ_ELF
e74cfd16 167static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 168#endif
e74cfd16
PB
169static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
170
171#ifdef CPU_DEFAULT
172static const arm_feature_set cpu_default = CPU_DEFAULT;
173#endif
174
823d2571
TG
175static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
176static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
177static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
178static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
179static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
180static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
181static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
182static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 183static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
184 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
185static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
186static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
187static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
188static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
189static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
190static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
191static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
823d2571
TG
192static const arm_feature_set arm_ext_v6_notm =
193 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
194static const arm_feature_set arm_ext_v6_dsp =
195 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
196static const arm_feature_set arm_ext_barrier =
197 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
198static const arm_feature_set arm_ext_msr =
199 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
200static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
201static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
202static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
203static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 204#ifdef OBJ_ELF
e7d39ed3 205static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 206#endif
823d2571 207static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 208static const arm_feature_set arm_ext_m =
173205ca 209 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
16a1fa25 210 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
211static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
212static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
213static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
214static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
215static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 216static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 217static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
218static const arm_feature_set arm_ext_v8m_main =
219 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
220/* Instructions in ARMv8-M only found in M profile architectures. */
221static const arm_feature_set arm_ext_v8m_m_only =
222 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
223static const arm_feature_set arm_ext_v6t2_v8m =
224 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
225/* Instructions shared between ARMv8-A and ARMv8-M. */
226static const arm_feature_set arm_ext_atomics =
227 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 228#ifdef OBJ_ELF
15afaa63
TP
229/* DSP instructions Tag_DSP_extension refers to. */
230static const arm_feature_set arm_ext_dsp =
231 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 232#endif
4d1464f2
MW
233static const arm_feature_set arm_ext_ras =
234 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
235/* FP16 instructions. */
236static const arm_feature_set arm_ext_fp16 =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
49e8a725
SN
238static const arm_feature_set arm_ext_v8_3 =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
240
241static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 242#ifdef OBJ_ELF
2c6b98ea 243static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 244#endif
f85d59c3 245static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
246static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
247static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
248
2d447fca 249static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 250 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 251static const arm_feature_set arm_cext_iwmmxt =
823d2571 252 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 253static const arm_feature_set arm_cext_xscale =
823d2571 254 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 255static const arm_feature_set arm_cext_maverick =
823d2571
TG
256 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
257static const arm_feature_set fpu_fpa_ext_v1 =
258 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
259static const arm_feature_set fpu_fpa_ext_v2 =
260 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 261static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
262 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
263static const arm_feature_set fpu_vfp_ext_v1 =
264 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
265static const arm_feature_set fpu_vfp_ext_v2 =
266 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
267static const arm_feature_set fpu_vfp_ext_v3xd =
268 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
269static const arm_feature_set fpu_vfp_ext_v3 =
270 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 271static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
272 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
273static const arm_feature_set fpu_neon_ext_v1 =
274 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 275static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 276 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 277#ifdef OBJ_ELF
823d2571
TG
278static const arm_feature_set fpu_vfp_fp16 =
279 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
280static const arm_feature_set fpu_neon_ext_fma =
281 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 282#endif
823d2571
TG
283static const arm_feature_set fpu_vfp_ext_fma =
284 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 285static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 286 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 287static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 288 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 289static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 290 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 291static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 292 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 293static const arm_feature_set crc_ext_armv8 =
823d2571 294 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 295static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 296 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
297static const arm_feature_set fpu_neon_ext_dotprod =
298 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 299
33a392fb 300static int mfloat_abi_opt = -1;
e74cfd16
PB
301/* Record user cpu selection for object attributes. */
302static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 303/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 304static char selected_cpu_name[20];
8d67f500 305
aacf0b33
KT
306extern FLONUM_TYPE generic_floating_point_number;
307
8d67f500
NC
308/* Return if no cpu was selected on command-line. */
309static bfd_boolean
310no_cpu_selected (void)
311{
823d2571 312 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
313}
314
7cc69913 315#ifdef OBJ_ELF
deeaaff8
DJ
316# ifdef EABI_DEFAULT
317static int meabi_flags = EABI_DEFAULT;
318# else
d507cf36 319static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 320# endif
e1da3f5b 321
ee3c0378
AS
322static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
323
e1da3f5b 324bfd_boolean
5f4273c7 325arm_is_eabi (void)
e1da3f5b
PB
326{
327 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
328}
7cc69913 329#endif
b99bd4ef 330
b99bd4ef 331#ifdef OBJ_ELF
c19d1205 332/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
333symbolS * GOT_symbol;
334#endif
335
b99bd4ef
NC
336/* 0: assemble for ARM,
337 1: assemble for Thumb,
338 2: assemble for Thumb even though target CPU does not support thumb
339 instructions. */
340static int thumb_mode = 0;
8dc2430f
NC
341/* A value distinct from the possible values for thumb_mode that we
342 can use to record whether thumb_mode has been copied into the
343 tc_frag_data field of a frag. */
344#define MODE_RECORDED (1 << 4)
b99bd4ef 345
e07e6e58
NC
346/* Specifies the intrinsic IT insn behavior mode. */
347enum implicit_it_mode
348{
349 IMPLICIT_IT_MODE_NEVER = 0x00,
350 IMPLICIT_IT_MODE_ARM = 0x01,
351 IMPLICIT_IT_MODE_THUMB = 0x02,
352 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
353};
354static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
355
c19d1205
ZW
356/* If unified_syntax is true, we are processing the new unified
357 ARM/Thumb syntax. Important differences from the old ARM mode:
358
359 - Immediate operands do not require a # prefix.
360 - Conditional affixes always appear at the end of the
361 instruction. (For backward compatibility, those instructions
362 that formerly had them in the middle, continue to accept them
363 there.)
364 - The IT instruction may appear, and if it does is validated
365 against subsequent conditional affixes. It does not generate
366 machine code.
367
368 Important differences from the old Thumb mode:
369
370 - Immediate operands do not require a # prefix.
371 - Most of the V6T2 instructions are only available in unified mode.
372 - The .N and .W suffixes are recognized and honored (it is an error
373 if they cannot be honored).
374 - All instructions set the flags if and only if they have an 's' affix.
375 - Conditional affixes may be used. They are validated against
376 preceding IT instructions. Unlike ARM mode, you cannot use a
377 conditional affix except in the scope of an IT instruction. */
378
379static bfd_boolean unified_syntax = FALSE;
b99bd4ef 380
bacebabc
RM
381/* An immediate operand can start with #, and ld*, st*, pld operands
382 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
383 before a [, which can appear as the first operand for pld.
384 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
385const char arm_symbol_chars[] = "#[]{}";
bacebabc 386
5287ad62
JB
387enum neon_el_type
388{
dcbf9037 389 NT_invtype,
5287ad62
JB
390 NT_untyped,
391 NT_integer,
392 NT_float,
393 NT_poly,
394 NT_signed,
dcbf9037 395 NT_unsigned
5287ad62
JB
396};
397
398struct neon_type_el
399{
400 enum neon_el_type type;
401 unsigned size;
402};
403
404#define NEON_MAX_TYPE_ELS 4
405
406struct neon_type
407{
408 struct neon_type_el el[NEON_MAX_TYPE_ELS];
409 unsigned elems;
410};
411
e07e6e58
NC
412enum it_instruction_type
413{
414 OUTSIDE_IT_INSN,
415 INSIDE_IT_INSN,
416 INSIDE_IT_LAST_INSN,
417 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 418 if inside, should be the last one. */
e07e6e58 419 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 420 i.e. BKPT and NOP. */
e07e6e58
NC
421 IT_INSN /* The IT insn has been parsed. */
422};
423
ad6cec43
MGD
424/* The maximum number of operands we need. */
425#define ARM_IT_MAX_OPERANDS 6
426
b99bd4ef
NC
427struct arm_it
428{
c19d1205 429 const char * error;
b99bd4ef 430 unsigned long instruction;
c19d1205
ZW
431 int size;
432 int size_req;
433 int cond;
037e8744
JB
434 /* "uncond_value" is set to the value in place of the conditional field in
435 unconditional versions of the instruction, or -1 if nothing is
436 appropriate. */
437 int uncond_value;
5287ad62 438 struct neon_type vectype;
88714cb8
DG
439 /* This does not indicate an actual NEON instruction, only that
440 the mnemonic accepts neon-style type suffixes. */
441 int is_neon;
0110f2b8
PB
442 /* Set to the opcode if the instruction needs relaxation.
443 Zero if the instruction is not relaxed. */
444 unsigned long relax;
b99bd4ef
NC
445 struct
446 {
447 bfd_reloc_code_real_type type;
c19d1205
ZW
448 expressionS exp;
449 int pc_rel;
b99bd4ef 450 } reloc;
b99bd4ef 451
e07e6e58
NC
452 enum it_instruction_type it_insn_type;
453
c19d1205
ZW
454 struct
455 {
456 unsigned reg;
ca3f61f7 457 signed int imm;
dcbf9037 458 struct neon_type_el vectype;
ca3f61f7
NC
459 unsigned present : 1; /* Operand present. */
460 unsigned isreg : 1; /* Operand was a register. */
461 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
462 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
463 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 464 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
465 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
466 instructions. This allows us to disambiguate ARM <-> vector insns. */
467 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 468 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 469 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 470 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
471 unsigned hasreloc : 1; /* Operand has relocation suffix. */
472 unsigned writeback : 1; /* Operand has trailing ! */
473 unsigned preind : 1; /* Preindexed address. */
474 unsigned postind : 1; /* Postindexed address. */
475 unsigned negative : 1; /* Index register was negated. */
476 unsigned shifted : 1; /* Shift applied to operation. */
477 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 478 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
479};
480
c19d1205 481static struct arm_it inst;
b99bd4ef
NC
482
483#define NUM_FLOAT_VALS 8
484
05d2d07e 485const char * fp_const[] =
b99bd4ef
NC
486{
487 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
488};
489
c19d1205 490/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
491#define MAX_LITTLENUMS 6
492
493LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
494
495#define FAIL (-1)
496#define SUCCESS (0)
497
498#define SUFF_S 1
499#define SUFF_D 2
500#define SUFF_E 3
501#define SUFF_P 4
502
c19d1205
ZW
503#define CP_T_X 0x00008000
504#define CP_T_Y 0x00400000
b99bd4ef 505
c19d1205
ZW
506#define CONDS_BIT 0x00100000
507#define LOAD_BIT 0x00100000
b99bd4ef
NC
508
509#define DOUBLE_LOAD_FLAG 0x00000001
510
511struct asm_cond
512{
d3ce72d0 513 const char * template_name;
c921be7d 514 unsigned long value;
b99bd4ef
NC
515};
516
c19d1205 517#define COND_ALWAYS 0xE
b99bd4ef 518
b99bd4ef
NC
519struct asm_psr
520{
d3ce72d0 521 const char * template_name;
c921be7d 522 unsigned long field;
b99bd4ef
NC
523};
524
62b3e311
PB
525struct asm_barrier_opt
526{
e797f7e0
MGD
527 const char * template_name;
528 unsigned long value;
529 const arm_feature_set arch;
62b3e311
PB
530};
531
2d2255b5 532/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
533#define SPSR_BIT (1 << 22)
534
c19d1205
ZW
535/* The individual PSR flag bits. */
536#define PSR_c (1 << 16)
537#define PSR_x (1 << 17)
538#define PSR_s (1 << 18)
539#define PSR_f (1 << 19)
b99bd4ef 540
c19d1205 541struct reloc_entry
bfae80f2 542{
e0471c16 543 const char * name;
c921be7d 544 bfd_reloc_code_real_type reloc;
bfae80f2
RE
545};
546
5287ad62 547enum vfp_reg_pos
bfae80f2 548{
5287ad62
JB
549 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
550 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
551};
552
553enum vfp_ldstm_type
554{
555 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
556};
557
dcbf9037
JB
558/* Bits for DEFINED field in neon_typed_alias. */
559#define NTA_HASTYPE 1
560#define NTA_HASINDEX 2
561
562struct neon_typed_alias
563{
c921be7d
NC
564 unsigned char defined;
565 unsigned char index;
566 struct neon_type_el eltype;
dcbf9037
JB
567};
568
c19d1205
ZW
569/* ARM register categories. This includes coprocessor numbers and various
570 architecture extensions' registers. */
571enum arm_reg_type
bfae80f2 572{
c19d1205
ZW
573 REG_TYPE_RN,
574 REG_TYPE_CP,
575 REG_TYPE_CN,
576 REG_TYPE_FN,
577 REG_TYPE_VFS,
578 REG_TYPE_VFD,
5287ad62 579 REG_TYPE_NQ,
037e8744 580 REG_TYPE_VFSD,
5287ad62 581 REG_TYPE_NDQ,
037e8744 582 REG_TYPE_NSDQ,
c19d1205
ZW
583 REG_TYPE_VFC,
584 REG_TYPE_MVF,
585 REG_TYPE_MVD,
586 REG_TYPE_MVFX,
587 REG_TYPE_MVDX,
588 REG_TYPE_MVAX,
589 REG_TYPE_DSPSC,
590 REG_TYPE_MMXWR,
591 REG_TYPE_MMXWC,
592 REG_TYPE_MMXWCG,
593 REG_TYPE_XSCALE,
90ec0d68 594 REG_TYPE_RNB
bfae80f2
RE
595};
596
dcbf9037
JB
597/* Structure for a hash table entry for a register.
598 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
599 information which states whether a vector type or index is specified (for a
600 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
601struct reg_entry
602{
c921be7d 603 const char * name;
90ec0d68 604 unsigned int number;
c921be7d
NC
605 unsigned char type;
606 unsigned char builtin;
607 struct neon_typed_alias * neon;
6c43fab6
RE
608};
609
c19d1205 610/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 611const char * const reg_expected_msgs[] =
c19d1205
ZW
612{
613 N_("ARM register expected"),
614 N_("bad or missing co-processor number"),
615 N_("co-processor register expected"),
616 N_("FPA register expected"),
617 N_("VFP single precision register expected"),
5287ad62
JB
618 N_("VFP/Neon double precision register expected"),
619 N_("Neon quad precision register expected"),
037e8744 620 N_("VFP single or double precision register expected"),
5287ad62 621 N_("Neon double or quad precision register expected"),
037e8744 622 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
623 N_("VFP system register expected"),
624 N_("Maverick MVF register expected"),
625 N_("Maverick MVD register expected"),
626 N_("Maverick MVFX register expected"),
627 N_("Maverick MVDX register expected"),
628 N_("Maverick MVAX register expected"),
629 N_("Maverick DSPSC register expected"),
630 N_("iWMMXt data register expected"),
631 N_("iWMMXt control register expected"),
632 N_("iWMMXt scalar register expected"),
633 N_("XScale accumulator register expected"),
6c43fab6
RE
634};
635
c19d1205 636/* Some well known registers that we refer to directly elsewhere. */
bd340a04 637#define REG_R12 12
c19d1205
ZW
638#define REG_SP 13
639#define REG_LR 14
640#define REG_PC 15
404ff6b5 641
b99bd4ef
NC
642/* ARM instructions take 4bytes in the object file, Thumb instructions
643 take 2: */
c19d1205 644#define INSN_SIZE 4
b99bd4ef
NC
645
646struct asm_opcode
647{
648 /* Basic string to match. */
d3ce72d0 649 const char * template_name;
c19d1205
ZW
650
651 /* Parameters to instruction. */
5be8be5d 652 unsigned int operands[8];
c19d1205
ZW
653
654 /* Conditional tag - see opcode_lookup. */
655 unsigned int tag : 4;
b99bd4ef
NC
656
657 /* Basic instruction code. */
c19d1205 658 unsigned int avalue : 28;
b99bd4ef 659
c19d1205
ZW
660 /* Thumb-format instruction code. */
661 unsigned int tvalue;
b99bd4ef 662
90e4755a 663 /* Which architecture variant provides this instruction. */
c921be7d
NC
664 const arm_feature_set * avariant;
665 const arm_feature_set * tvariant;
c19d1205
ZW
666
667 /* Function to call to encode instruction in ARM format. */
668 void (* aencode) (void);
b99bd4ef 669
c19d1205
ZW
670 /* Function to call to encode instruction in Thumb format. */
671 void (* tencode) (void);
b99bd4ef
NC
672};
673
a737bd4d
NC
674/* Defines for various bits that we will want to toggle. */
675#define INST_IMMEDIATE 0x02000000
676#define OFFSET_REG 0x02000000
c19d1205 677#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
678#define SHIFT_BY_REG 0x00000010
679#define PRE_INDEX 0x01000000
680#define INDEX_UP 0x00800000
681#define WRITE_BACK 0x00200000
682#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 683#define CPSI_MMOD 0x00020000
90e4755a 684
a737bd4d
NC
685#define LITERAL_MASK 0xf000f000
686#define OPCODE_MASK 0xfe1fffff
687#define V4_STR_BIT 0x00000020
8335d6aa 688#define VLDR_VMOV_SAME 0x0040f000
90e4755a 689
efd81785
PB
690#define T2_SUBS_PC_LR 0xf3de8f00
691
a737bd4d 692#define DATA_OP_SHIFT 21
bada4342 693#define SBIT_SHIFT 20
90e4755a 694
ef8d22e6
PB
695#define T2_OPCODE_MASK 0xfe1fffff
696#define T2_DATA_OP_SHIFT 21
bada4342 697#define T2_SBIT_SHIFT 20
ef8d22e6 698
6530b175
NC
699#define A_COND_MASK 0xf0000000
700#define A_PUSH_POP_OP_MASK 0x0fff0000
701
702/* Opcodes for pushing/poping registers to/from the stack. */
703#define A1_OPCODE_PUSH 0x092d0000
704#define A2_OPCODE_PUSH 0x052d0004
705#define A2_OPCODE_POP 0x049d0004
706
a737bd4d
NC
707/* Codes to distinguish the arithmetic instructions. */
708#define OPCODE_AND 0
709#define OPCODE_EOR 1
710#define OPCODE_SUB 2
711#define OPCODE_RSB 3
712#define OPCODE_ADD 4
713#define OPCODE_ADC 5
714#define OPCODE_SBC 6
715#define OPCODE_RSC 7
716#define OPCODE_TST 8
717#define OPCODE_TEQ 9
718#define OPCODE_CMP 10
719#define OPCODE_CMN 11
720#define OPCODE_ORR 12
721#define OPCODE_MOV 13
722#define OPCODE_BIC 14
723#define OPCODE_MVN 15
90e4755a 724
ef8d22e6
PB
725#define T2_OPCODE_AND 0
726#define T2_OPCODE_BIC 1
727#define T2_OPCODE_ORR 2
728#define T2_OPCODE_ORN 3
729#define T2_OPCODE_EOR 4
730#define T2_OPCODE_ADD 8
731#define T2_OPCODE_ADC 10
732#define T2_OPCODE_SBC 11
733#define T2_OPCODE_SUB 13
734#define T2_OPCODE_RSB 14
735
a737bd4d
NC
736#define T_OPCODE_MUL 0x4340
737#define T_OPCODE_TST 0x4200
738#define T_OPCODE_CMN 0x42c0
739#define T_OPCODE_NEG 0x4240
740#define T_OPCODE_MVN 0x43c0
90e4755a 741
a737bd4d
NC
742#define T_OPCODE_ADD_R3 0x1800
743#define T_OPCODE_SUB_R3 0x1a00
744#define T_OPCODE_ADD_HI 0x4400
745#define T_OPCODE_ADD_ST 0xb000
746#define T_OPCODE_SUB_ST 0xb080
747#define T_OPCODE_ADD_SP 0xa800
748#define T_OPCODE_ADD_PC 0xa000
749#define T_OPCODE_ADD_I8 0x3000
750#define T_OPCODE_SUB_I8 0x3800
751#define T_OPCODE_ADD_I3 0x1c00
752#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 753
a737bd4d
NC
754#define T_OPCODE_ASR_R 0x4100
755#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
756#define T_OPCODE_LSR_R 0x40c0
757#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
758#define T_OPCODE_ASR_I 0x1000
759#define T_OPCODE_LSL_I 0x0000
760#define T_OPCODE_LSR_I 0x0800
b99bd4ef 761
a737bd4d
NC
762#define T_OPCODE_MOV_I8 0x2000
763#define T_OPCODE_CMP_I8 0x2800
764#define T_OPCODE_CMP_LR 0x4280
765#define T_OPCODE_MOV_HR 0x4600
766#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 767
a737bd4d
NC
768#define T_OPCODE_LDR_PC 0x4800
769#define T_OPCODE_LDR_SP 0x9800
770#define T_OPCODE_STR_SP 0x9000
771#define T_OPCODE_LDR_IW 0x6800
772#define T_OPCODE_STR_IW 0x6000
773#define T_OPCODE_LDR_IH 0x8800
774#define T_OPCODE_STR_IH 0x8000
775#define T_OPCODE_LDR_IB 0x7800
776#define T_OPCODE_STR_IB 0x7000
777#define T_OPCODE_LDR_RW 0x5800
778#define T_OPCODE_STR_RW 0x5000
779#define T_OPCODE_LDR_RH 0x5a00
780#define T_OPCODE_STR_RH 0x5200
781#define T_OPCODE_LDR_RB 0x5c00
782#define T_OPCODE_STR_RB 0x5400
c9b604bd 783
a737bd4d
NC
784#define T_OPCODE_PUSH 0xb400
785#define T_OPCODE_POP 0xbc00
b99bd4ef 786
2fc8bdac 787#define T_OPCODE_BRANCH 0xe000
b99bd4ef 788
a737bd4d 789#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 790#define THUMB_PP_PC_LR 0x0100
c19d1205 791#define THUMB_LOAD_BIT 0x0800
53365c0d 792#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
793
794#define BAD_ARGS _("bad arguments to instruction")
fdfde340 795#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
796#define BAD_PC _("r15 not allowed here")
797#define BAD_COND _("instruction cannot be conditional")
798#define BAD_OVERLAP _("registers may not be the same")
799#define BAD_HIREG _("lo register required")
800#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 801#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
802#define BAD_BRANCH _("branch must be last instruction in IT block")
803#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 804#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
805#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
806#define BAD_IT_COND _("incorrect condition in IT block")
807#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 808#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
809#define BAD_PC_ADDRESSING \
810 _("cannot use register index with PC-relative addressing")
811#define BAD_PC_WRITEBACK \
812 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
813#define BAD_RANGE _("branch out of range")
814#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 815#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 816#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 817
c921be7d
NC
818static struct hash_control * arm_ops_hsh;
819static struct hash_control * arm_cond_hsh;
820static struct hash_control * arm_shift_hsh;
821static struct hash_control * arm_psr_hsh;
822static struct hash_control * arm_v7m_psr_hsh;
823static struct hash_control * arm_reg_hsh;
824static struct hash_control * arm_reloc_hsh;
825static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 826
b99bd4ef
NC
827/* Stuff needed to resolve the label ambiguity
828 As:
829 ...
830 label: <insn>
831 may differ from:
832 ...
833 label:
5f4273c7 834 <insn> */
b99bd4ef
NC
835
836symbolS * last_label_seen;
b34976b6 837static int label_is_thumb_function_name = FALSE;
e07e6e58 838
3d0c9500
NC
839/* Literal pool structure. Held on a per-section
840 and per-sub-section basis. */
a737bd4d 841
c19d1205 842#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 843typedef struct literal_pool
b99bd4ef 844{
c921be7d
NC
845 expressionS literals [MAX_LITERAL_POOL_SIZE];
846 unsigned int next_free_entry;
847 unsigned int id;
848 symbolS * symbol;
849 segT section;
850 subsegT sub_section;
a8040cf2
NC
851#ifdef OBJ_ELF
852 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
853#endif
c921be7d 854 struct literal_pool * next;
8335d6aa 855 unsigned int alignment;
3d0c9500 856} literal_pool;
b99bd4ef 857
3d0c9500
NC
858/* Pointer to a linked list of literal pools. */
859literal_pool * list_of_pools = NULL;
e27ec89e 860
2e6976a8
DG
861typedef enum asmfunc_states
862{
863 OUTSIDE_ASMFUNC,
864 WAITING_ASMFUNC_NAME,
865 WAITING_ENDASMFUNC
866} asmfunc_states;
867
868static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
869
e07e6e58
NC
870#ifdef OBJ_ELF
871# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
872#else
873static struct current_it now_it;
874#endif
875
876static inline int
877now_it_compatible (int cond)
878{
879 return (cond & ~1) == (now_it.cc & ~1);
880}
881
882static inline int
883conditional_insn (void)
884{
885 return inst.cond != COND_ALWAYS;
886}
887
888static int in_it_block (void);
889
890static int handle_it_state (void);
891
892static void force_automatic_it_block_close (void);
893
c921be7d
NC
894static void it_fsm_post_encode (void);
895
e07e6e58
NC
896#define set_it_insn_type(type) \
897 do \
898 { \
899 inst.it_insn_type = type; \
900 if (handle_it_state () == FAIL) \
477330fc 901 return; \
e07e6e58
NC
902 } \
903 while (0)
904
c921be7d
NC
905#define set_it_insn_type_nonvoid(type, failret) \
906 do \
907 { \
908 inst.it_insn_type = type; \
909 if (handle_it_state () == FAIL) \
477330fc 910 return failret; \
c921be7d
NC
911 } \
912 while(0)
913
e07e6e58
NC
914#define set_it_insn_type_last() \
915 do \
916 { \
917 if (inst.cond == COND_ALWAYS) \
477330fc 918 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 919 else \
477330fc 920 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
921 } \
922 while (0)
923
c19d1205 924/* Pure syntax. */
b99bd4ef 925
c19d1205
ZW
926/* This array holds the chars that always start a comment. If the
927 pre-processor is disabled, these aren't very useful. */
2e6976a8 928char arm_comment_chars[] = "@";
3d0c9500 929
c19d1205
ZW
930/* This array holds the chars that only start a comment at the beginning of
931 a line. If the line seems to have the form '# 123 filename'
932 .line and .file directives will appear in the pre-processed output. */
933/* Note that input_file.c hand checks for '#' at the beginning of the
934 first line of the input file. This is because the compiler outputs
935 #NO_APP at the beginning of its output. */
936/* Also note that comments like this one will always work. */
937const char line_comment_chars[] = "#";
3d0c9500 938
2e6976a8 939char arm_line_separator_chars[] = ";";
b99bd4ef 940
c19d1205
ZW
941/* Chars that can be used to separate mant
942 from exp in floating point numbers. */
943const char EXP_CHARS[] = "eE";
3d0c9500 944
c19d1205
ZW
945/* Chars that mean this number is a floating point constant. */
946/* As in 0f12.456 */
947/* or 0d1.2345e12 */
b99bd4ef 948
c19d1205 949const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 950
c19d1205
ZW
951/* Prefix characters that indicate the start of an immediate
952 value. */
953#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 954
c19d1205
ZW
955/* Separator character handling. */
956
957#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
958
959static inline int
960skip_past_char (char ** str, char c)
961{
8ab8155f
NC
962 /* PR gas/14987: Allow for whitespace before the expected character. */
963 skip_whitespace (*str);
427d0db6 964
c19d1205
ZW
965 if (**str == c)
966 {
967 (*str)++;
968 return SUCCESS;
3d0c9500 969 }
c19d1205
ZW
970 else
971 return FAIL;
972}
c921be7d 973
c19d1205 974#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 975
c19d1205
ZW
976/* Arithmetic expressions (possibly involving symbols). */
977
978/* Return TRUE if anything in the expression is a bignum. */
979
980static int
981walk_no_bignums (symbolS * sp)
982{
983 if (symbol_get_value_expression (sp)->X_op == O_big)
984 return 1;
985
986 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 987 {
c19d1205
ZW
988 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
989 || (symbol_get_value_expression (sp)->X_op_symbol
990 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
991 }
992
c19d1205 993 return 0;
3d0c9500
NC
994}
995
c19d1205
ZW
996static int in_my_get_expression = 0;
997
998/* Third argument to my_get_expression. */
999#define GE_NO_PREFIX 0
1000#define GE_IMM_PREFIX 1
1001#define GE_OPT_PREFIX 2
5287ad62
JB
1002/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1003 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1004#define GE_OPT_PREFIX_BIG 3
a737bd4d 1005
b99bd4ef 1006static int
c19d1205 1007my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1008{
c19d1205
ZW
1009 char * save_in;
1010 segT seg;
b99bd4ef 1011
c19d1205
ZW
1012 /* In unified syntax, all prefixes are optional. */
1013 if (unified_syntax)
5287ad62 1014 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1015 : GE_OPT_PREFIX;
b99bd4ef 1016
c19d1205 1017 switch (prefix_mode)
b99bd4ef 1018 {
c19d1205
ZW
1019 case GE_NO_PREFIX: break;
1020 case GE_IMM_PREFIX:
1021 if (!is_immediate_prefix (**str))
1022 {
1023 inst.error = _("immediate expression requires a # prefix");
1024 return FAIL;
1025 }
1026 (*str)++;
1027 break;
1028 case GE_OPT_PREFIX:
5287ad62 1029 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1030 if (is_immediate_prefix (**str))
1031 (*str)++;
1032 break;
1033 default: abort ();
1034 }
b99bd4ef 1035
c19d1205 1036 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1037
c19d1205
ZW
1038 save_in = input_line_pointer;
1039 input_line_pointer = *str;
1040 in_my_get_expression = 1;
1041 seg = expression (ep);
1042 in_my_get_expression = 0;
1043
f86adc07 1044 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1045 {
f86adc07 1046 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1047 *str = input_line_pointer;
1048 input_line_pointer = save_in;
1049 if (inst.error == NULL)
f86adc07
NS
1050 inst.error = (ep->X_op == O_absent
1051 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1052 return 1;
1053 }
b99bd4ef 1054
c19d1205
ZW
1055#ifdef OBJ_AOUT
1056 if (seg != absolute_section
1057 && seg != text_section
1058 && seg != data_section
1059 && seg != bss_section
1060 && seg != undefined_section)
1061 {
1062 inst.error = _("bad segment");
1063 *str = input_line_pointer;
1064 input_line_pointer = save_in;
1065 return 1;
b99bd4ef 1066 }
87975d2a
AM
1067#else
1068 (void) seg;
c19d1205 1069#endif
b99bd4ef 1070
c19d1205
ZW
1071 /* Get rid of any bignums now, so that we don't generate an error for which
1072 we can't establish a line number later on. Big numbers are never valid
1073 in instructions, which is where this routine is always called. */
5287ad62
JB
1074 if (prefix_mode != GE_OPT_PREFIX_BIG
1075 && (ep->X_op == O_big
477330fc 1076 || (ep->X_add_symbol
5287ad62 1077 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1078 || (ep->X_op_symbol
5287ad62 1079 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1080 {
1081 inst.error = _("invalid constant");
1082 *str = input_line_pointer;
1083 input_line_pointer = save_in;
1084 return 1;
1085 }
b99bd4ef 1086
c19d1205
ZW
1087 *str = input_line_pointer;
1088 input_line_pointer = save_in;
1089 return 0;
b99bd4ef
NC
1090}
1091
c19d1205
ZW
1092/* Turn a string in input_line_pointer into a floating point constant
1093 of type TYPE, and store the appropriate bytes in *LITP. The number
1094 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1095 returned, or NULL on OK.
b99bd4ef 1096
c19d1205
ZW
1097 Note that fp constants aren't represent in the normal way on the ARM.
1098 In big endian mode, things are as expected. However, in little endian
1099 mode fp constants are big-endian word-wise, and little-endian byte-wise
1100 within the words. For example, (double) 1.1 in big endian mode is
1101 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1102 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1103
c19d1205 1104 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1105
6d4af3c2 1106const char *
c19d1205
ZW
1107md_atof (int type, char * litP, int * sizeP)
1108{
1109 int prec;
1110 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1111 char *t;
1112 int i;
b99bd4ef 1113
c19d1205
ZW
1114 switch (type)
1115 {
1116 case 'f':
1117 case 'F':
1118 case 's':
1119 case 'S':
1120 prec = 2;
1121 break;
b99bd4ef 1122
c19d1205
ZW
1123 case 'd':
1124 case 'D':
1125 case 'r':
1126 case 'R':
1127 prec = 4;
1128 break;
b99bd4ef 1129
c19d1205
ZW
1130 case 'x':
1131 case 'X':
499ac353 1132 prec = 5;
c19d1205 1133 break;
b99bd4ef 1134
c19d1205
ZW
1135 case 'p':
1136 case 'P':
499ac353 1137 prec = 5;
c19d1205 1138 break;
a737bd4d 1139
c19d1205
ZW
1140 default:
1141 *sizeP = 0;
499ac353 1142 return _("Unrecognized or unsupported floating point constant");
c19d1205 1143 }
b99bd4ef 1144
c19d1205
ZW
1145 t = atof_ieee (input_line_pointer, type, words);
1146 if (t)
1147 input_line_pointer = t;
499ac353 1148 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1149
c19d1205
ZW
1150 if (target_big_endian)
1151 {
1152 for (i = 0; i < prec; i++)
1153 {
499ac353
NC
1154 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1155 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1156 }
1157 }
1158 else
1159 {
e74cfd16 1160 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1161 for (i = prec - 1; i >= 0; i--)
1162 {
499ac353
NC
1163 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1164 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1165 }
1166 else
1167 /* For a 4 byte float the order of elements in `words' is 1 0.
1168 For an 8 byte float the order is 1 0 3 2. */
1169 for (i = 0; i < prec; i += 2)
1170 {
499ac353
NC
1171 md_number_to_chars (litP, (valueT) words[i + 1],
1172 sizeof (LITTLENUM_TYPE));
1173 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1174 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1175 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1176 }
1177 }
b99bd4ef 1178
499ac353 1179 return NULL;
c19d1205 1180}
b99bd4ef 1181
c19d1205
ZW
1182/* We handle all bad expressions here, so that we can report the faulty
1183 instruction in the error message. */
1184void
91d6fa6a 1185md_operand (expressionS * exp)
c19d1205
ZW
1186{
1187 if (in_my_get_expression)
91d6fa6a 1188 exp->X_op = O_illegal;
b99bd4ef
NC
1189}
1190
c19d1205 1191/* Immediate values. */
b99bd4ef 1192
c19d1205
ZW
1193/* Generic immediate-value read function for use in directives.
1194 Accepts anything that 'expression' can fold to a constant.
1195 *val receives the number. */
1196#ifdef OBJ_ELF
1197static int
1198immediate_for_directive (int *val)
b99bd4ef 1199{
c19d1205
ZW
1200 expressionS exp;
1201 exp.X_op = O_illegal;
b99bd4ef 1202
c19d1205
ZW
1203 if (is_immediate_prefix (*input_line_pointer))
1204 {
1205 input_line_pointer++;
1206 expression (&exp);
1207 }
b99bd4ef 1208
c19d1205
ZW
1209 if (exp.X_op != O_constant)
1210 {
1211 as_bad (_("expected #constant"));
1212 ignore_rest_of_line ();
1213 return FAIL;
1214 }
1215 *val = exp.X_add_number;
1216 return SUCCESS;
b99bd4ef 1217}
c19d1205 1218#endif
b99bd4ef 1219
c19d1205 1220/* Register parsing. */
b99bd4ef 1221
c19d1205
ZW
1222/* Generic register parser. CCP points to what should be the
1223 beginning of a register name. If it is indeed a valid register
1224 name, advance CCP over it and return the reg_entry structure;
1225 otherwise return NULL. Does not issue diagnostics. */
1226
1227static struct reg_entry *
1228arm_reg_parse_multi (char **ccp)
b99bd4ef 1229{
c19d1205
ZW
1230 char *start = *ccp;
1231 char *p;
1232 struct reg_entry *reg;
b99bd4ef 1233
477330fc
RM
1234 skip_whitespace (start);
1235
c19d1205
ZW
1236#ifdef REGISTER_PREFIX
1237 if (*start != REGISTER_PREFIX)
01cfc07f 1238 return NULL;
c19d1205
ZW
1239 start++;
1240#endif
1241#ifdef OPTIONAL_REGISTER_PREFIX
1242 if (*start == OPTIONAL_REGISTER_PREFIX)
1243 start++;
1244#endif
b99bd4ef 1245
c19d1205
ZW
1246 p = start;
1247 if (!ISALPHA (*p) || !is_name_beginner (*p))
1248 return NULL;
b99bd4ef 1249
c19d1205
ZW
1250 do
1251 p++;
1252 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1253
1254 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1255
1256 if (!reg)
1257 return NULL;
1258
1259 *ccp = p;
1260 return reg;
b99bd4ef
NC
1261}
1262
1263static int
dcbf9037 1264arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1265 enum arm_reg_type type)
b99bd4ef 1266{
c19d1205
ZW
1267 /* Alternative syntaxes are accepted for a few register classes. */
1268 switch (type)
1269 {
1270 case REG_TYPE_MVF:
1271 case REG_TYPE_MVD:
1272 case REG_TYPE_MVFX:
1273 case REG_TYPE_MVDX:
1274 /* Generic coprocessor register names are allowed for these. */
79134647 1275 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1276 return reg->number;
1277 break;
69b97547 1278
c19d1205
ZW
1279 case REG_TYPE_CP:
1280 /* For backward compatibility, a bare number is valid here. */
1281 {
1282 unsigned long processor = strtoul (start, ccp, 10);
1283 if (*ccp != start && processor <= 15)
1284 return processor;
1285 }
1a0670f3 1286 /* Fall through. */
6057a28f 1287
c19d1205
ZW
1288 case REG_TYPE_MMXWC:
1289 /* WC includes WCG. ??? I'm not sure this is true for all
1290 instructions that take WC registers. */
79134647 1291 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1292 return reg->number;
6057a28f 1293 break;
c19d1205 1294
6057a28f 1295 default:
c19d1205 1296 break;
6057a28f
NC
1297 }
1298
dcbf9037
JB
1299 return FAIL;
1300}
1301
1302/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1303 return value is the register number or FAIL. */
1304
1305static int
1306arm_reg_parse (char **ccp, enum arm_reg_type type)
1307{
1308 char *start = *ccp;
1309 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1310 int ret;
1311
1312 /* Do not allow a scalar (reg+index) to parse as a register. */
1313 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1314 return FAIL;
1315
1316 if (reg && reg->type == type)
1317 return reg->number;
1318
1319 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1320 return ret;
1321
c19d1205
ZW
1322 *ccp = start;
1323 return FAIL;
1324}
69b97547 1325
dcbf9037
JB
1326/* Parse a Neon type specifier. *STR should point at the leading '.'
1327 character. Does no verification at this stage that the type fits the opcode
1328 properly. E.g.,
1329
1330 .i32.i32.s16
1331 .s32.f32
1332 .u16
1333
1334 Can all be legally parsed by this function.
1335
1336 Fills in neon_type struct pointer with parsed information, and updates STR
1337 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1338 type, FAIL if not. */
1339
1340static int
1341parse_neon_type (struct neon_type *type, char **str)
1342{
1343 char *ptr = *str;
1344
1345 if (type)
1346 type->elems = 0;
1347
1348 while (type->elems < NEON_MAX_TYPE_ELS)
1349 {
1350 enum neon_el_type thistype = NT_untyped;
1351 unsigned thissize = -1u;
1352
1353 if (*ptr != '.')
1354 break;
1355
1356 ptr++;
1357
1358 /* Just a size without an explicit type. */
1359 if (ISDIGIT (*ptr))
1360 goto parsesize;
1361
1362 switch (TOLOWER (*ptr))
1363 {
1364 case 'i': thistype = NT_integer; break;
1365 case 'f': thistype = NT_float; break;
1366 case 'p': thistype = NT_poly; break;
1367 case 's': thistype = NT_signed; break;
1368 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1369 case 'd':
1370 thistype = NT_float;
1371 thissize = 64;
1372 ptr++;
1373 goto done;
dcbf9037
JB
1374 default:
1375 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1376 return FAIL;
1377 }
1378
1379 ptr++;
1380
1381 /* .f is an abbreviation for .f32. */
1382 if (thistype == NT_float && !ISDIGIT (*ptr))
1383 thissize = 32;
1384 else
1385 {
1386 parsesize:
1387 thissize = strtoul (ptr, &ptr, 10);
1388
1389 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1390 && thissize != 64)
1391 {
1392 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1393 return FAIL;
1394 }
1395 }
1396
037e8744 1397 done:
dcbf9037 1398 if (type)
477330fc
RM
1399 {
1400 type->el[type->elems].type = thistype;
dcbf9037
JB
1401 type->el[type->elems].size = thissize;
1402 type->elems++;
1403 }
1404 }
1405
1406 /* Empty/missing type is not a successful parse. */
1407 if (type->elems == 0)
1408 return FAIL;
1409
1410 *str = ptr;
1411
1412 return SUCCESS;
1413}
1414
1415/* Errors may be set multiple times during parsing or bit encoding
1416 (particularly in the Neon bits), but usually the earliest error which is set
1417 will be the most meaningful. Avoid overwriting it with later (cascading)
1418 errors by calling this function. */
1419
1420static void
1421first_error (const char *err)
1422{
1423 if (!inst.error)
1424 inst.error = err;
1425}
1426
1427/* Parse a single type, e.g. ".s32", leading period included. */
1428static int
1429parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1430{
1431 char *str = *ccp;
1432 struct neon_type optype;
1433
1434 if (*str == '.')
1435 {
1436 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1437 {
1438 if (optype.elems == 1)
1439 *vectype = optype.el[0];
1440 else
1441 {
1442 first_error (_("only one type should be specified for operand"));
1443 return FAIL;
1444 }
1445 }
dcbf9037 1446 else
477330fc
RM
1447 {
1448 first_error (_("vector type expected"));
1449 return FAIL;
1450 }
dcbf9037
JB
1451 }
1452 else
1453 return FAIL;
5f4273c7 1454
dcbf9037 1455 *ccp = str;
5f4273c7 1456
dcbf9037
JB
1457 return SUCCESS;
1458}
1459
1460/* Special meanings for indices (which have a range of 0-7), which will fit into
1461 a 4-bit integer. */
1462
1463#define NEON_ALL_LANES 15
1464#define NEON_INTERLEAVE_LANES 14
1465
1466/* Parse either a register or a scalar, with an optional type. Return the
1467 register number, and optionally fill in the actual type of the register
1468 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1469 type/index information in *TYPEINFO. */
1470
1471static int
1472parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1473 enum arm_reg_type *rtype,
1474 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1475{
1476 char *str = *ccp;
1477 struct reg_entry *reg = arm_reg_parse_multi (&str);
1478 struct neon_typed_alias atype;
1479 struct neon_type_el parsetype;
1480
1481 atype.defined = 0;
1482 atype.index = -1;
1483 atype.eltype.type = NT_invtype;
1484 atype.eltype.size = -1;
1485
1486 /* Try alternate syntax for some types of register. Note these are mutually
1487 exclusive with the Neon syntax extensions. */
1488 if (reg == NULL)
1489 {
1490 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1491 if (altreg != FAIL)
477330fc 1492 *ccp = str;
dcbf9037 1493 if (typeinfo)
477330fc 1494 *typeinfo = atype;
dcbf9037
JB
1495 return altreg;
1496 }
1497
037e8744
JB
1498 /* Undo polymorphism when a set of register types may be accepted. */
1499 if ((type == REG_TYPE_NDQ
1500 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1501 || (type == REG_TYPE_VFSD
477330fc 1502 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1503 || (type == REG_TYPE_NSDQ
477330fc
RM
1504 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1505 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1506 || (type == REG_TYPE_MMXWC
1507 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1508 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1509
1510 if (type != reg->type)
1511 return FAIL;
1512
1513 if (reg->neon)
1514 atype = *reg->neon;
5f4273c7 1515
dcbf9037
JB
1516 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1517 {
1518 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1519 {
1520 first_error (_("can't redefine type for operand"));
1521 return FAIL;
1522 }
dcbf9037
JB
1523 atype.defined |= NTA_HASTYPE;
1524 atype.eltype = parsetype;
1525 }
5f4273c7 1526
dcbf9037
JB
1527 if (skip_past_char (&str, '[') == SUCCESS)
1528 {
1529 if (type != REG_TYPE_VFD)
477330fc
RM
1530 {
1531 first_error (_("only D registers may be indexed"));
1532 return FAIL;
1533 }
5f4273c7 1534
dcbf9037 1535 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1536 {
1537 first_error (_("can't change index for operand"));
1538 return FAIL;
1539 }
dcbf9037
JB
1540
1541 atype.defined |= NTA_HASINDEX;
1542
1543 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1544 atype.index = NEON_ALL_LANES;
dcbf9037 1545 else
477330fc
RM
1546 {
1547 expressionS exp;
dcbf9037 1548
477330fc 1549 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1550
477330fc
RM
1551 if (exp.X_op != O_constant)
1552 {
1553 first_error (_("constant expression required"));
1554 return FAIL;
1555 }
dcbf9037 1556
477330fc
RM
1557 if (skip_past_char (&str, ']') == FAIL)
1558 return FAIL;
dcbf9037 1559
477330fc
RM
1560 atype.index = exp.X_add_number;
1561 }
dcbf9037 1562 }
5f4273c7 1563
dcbf9037
JB
1564 if (typeinfo)
1565 *typeinfo = atype;
5f4273c7 1566
dcbf9037
JB
1567 if (rtype)
1568 *rtype = type;
5f4273c7 1569
dcbf9037 1570 *ccp = str;
5f4273c7 1571
dcbf9037
JB
1572 return reg->number;
1573}
1574
1575/* Like arm_reg_parse, but allow allow the following extra features:
1576 - If RTYPE is non-zero, return the (possibly restricted) type of the
1577 register (e.g. Neon double or quad reg when either has been requested).
1578 - If this is a Neon vector type with additional type information, fill
1579 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1580 This function will fault on encountering a scalar. */
dcbf9037
JB
1581
1582static int
1583arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1584 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1585{
1586 struct neon_typed_alias atype;
1587 char *str = *ccp;
1588 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1589
1590 if (reg == FAIL)
1591 return FAIL;
1592
0855e32b
NS
1593 /* Do not allow regname(... to parse as a register. */
1594 if (*str == '(')
1595 return FAIL;
1596
dcbf9037
JB
1597 /* Do not allow a scalar (reg+index) to parse as a register. */
1598 if ((atype.defined & NTA_HASINDEX) != 0)
1599 {
1600 first_error (_("register operand expected, but got scalar"));
1601 return FAIL;
1602 }
1603
1604 if (vectype)
1605 *vectype = atype.eltype;
1606
1607 *ccp = str;
1608
1609 return reg;
1610}
1611
1612#define NEON_SCALAR_REG(X) ((X) >> 4)
1613#define NEON_SCALAR_INDEX(X) ((X) & 15)
1614
5287ad62
JB
1615/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1616 have enough information to be able to do a good job bounds-checking. So, we
1617 just do easy checks here, and do further checks later. */
1618
1619static int
dcbf9037 1620parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1621{
dcbf9037 1622 int reg;
5287ad62 1623 char *str = *ccp;
dcbf9037 1624 struct neon_typed_alias atype;
5f4273c7 1625
dcbf9037 1626 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1627
dcbf9037 1628 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1629 return FAIL;
5f4273c7 1630
dcbf9037 1631 if (atype.index == NEON_ALL_LANES)
5287ad62 1632 {
dcbf9037 1633 first_error (_("scalar must have an index"));
5287ad62
JB
1634 return FAIL;
1635 }
dcbf9037 1636 else if (atype.index >= 64 / elsize)
5287ad62 1637 {
dcbf9037 1638 first_error (_("scalar index out of range"));
5287ad62
JB
1639 return FAIL;
1640 }
5f4273c7 1641
dcbf9037
JB
1642 if (type)
1643 *type = atype.eltype;
5f4273c7 1644
5287ad62 1645 *ccp = str;
5f4273c7 1646
dcbf9037 1647 return reg * 16 + atype.index;
5287ad62
JB
1648}
1649
c19d1205 1650/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1651
c19d1205
ZW
1652static long
1653parse_reg_list (char ** strp)
1654{
1655 char * str = * strp;
1656 long range = 0;
1657 int another_range;
a737bd4d 1658
c19d1205
ZW
1659 /* We come back here if we get ranges concatenated by '+' or '|'. */
1660 do
6057a28f 1661 {
477330fc
RM
1662 skip_whitespace (str);
1663
c19d1205 1664 another_range = 0;
a737bd4d 1665
c19d1205
ZW
1666 if (*str == '{')
1667 {
1668 int in_range = 0;
1669 int cur_reg = -1;
a737bd4d 1670
c19d1205
ZW
1671 str++;
1672 do
1673 {
1674 int reg;
6057a28f 1675
dcbf9037 1676 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1677 {
dcbf9037 1678 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1679 return FAIL;
1680 }
a737bd4d 1681
c19d1205
ZW
1682 if (in_range)
1683 {
1684 int i;
a737bd4d 1685
c19d1205
ZW
1686 if (reg <= cur_reg)
1687 {
dcbf9037 1688 first_error (_("bad range in register list"));
c19d1205
ZW
1689 return FAIL;
1690 }
40a18ebd 1691
c19d1205
ZW
1692 for (i = cur_reg + 1; i < reg; i++)
1693 {
1694 if (range & (1 << i))
1695 as_tsktsk
1696 (_("Warning: duplicated register (r%d) in register list"),
1697 i);
1698 else
1699 range |= 1 << i;
1700 }
1701 in_range = 0;
1702 }
a737bd4d 1703
c19d1205
ZW
1704 if (range & (1 << reg))
1705 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1706 reg);
1707 else if (reg <= cur_reg)
1708 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1709
c19d1205
ZW
1710 range |= 1 << reg;
1711 cur_reg = reg;
1712 }
1713 while (skip_past_comma (&str) != FAIL
1714 || (in_range = 1, *str++ == '-'));
1715 str--;
a737bd4d 1716
d996d970 1717 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1718 {
dcbf9037 1719 first_error (_("missing `}'"));
c19d1205
ZW
1720 return FAIL;
1721 }
1722 }
1723 else
1724 {
91d6fa6a 1725 expressionS exp;
40a18ebd 1726
91d6fa6a 1727 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1728 return FAIL;
40a18ebd 1729
91d6fa6a 1730 if (exp.X_op == O_constant)
c19d1205 1731 {
91d6fa6a
NC
1732 if (exp.X_add_number
1733 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1734 {
1735 inst.error = _("invalid register mask");
1736 return FAIL;
1737 }
a737bd4d 1738
91d6fa6a 1739 if ((range & exp.X_add_number) != 0)
c19d1205 1740 {
91d6fa6a 1741 int regno = range & exp.X_add_number;
a737bd4d 1742
c19d1205
ZW
1743 regno &= -regno;
1744 regno = (1 << regno) - 1;
1745 as_tsktsk
1746 (_("Warning: duplicated register (r%d) in register list"),
1747 regno);
1748 }
a737bd4d 1749
91d6fa6a 1750 range |= exp.X_add_number;
c19d1205
ZW
1751 }
1752 else
1753 {
1754 if (inst.reloc.type != 0)
1755 {
1756 inst.error = _("expression too complex");
1757 return FAIL;
1758 }
a737bd4d 1759
91d6fa6a 1760 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1761 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1762 inst.reloc.pc_rel = 0;
1763 }
1764 }
a737bd4d 1765
c19d1205
ZW
1766 if (*str == '|' || *str == '+')
1767 {
1768 str++;
1769 another_range = 1;
1770 }
a737bd4d 1771 }
c19d1205 1772 while (another_range);
a737bd4d 1773
c19d1205
ZW
1774 *strp = str;
1775 return range;
a737bd4d
NC
1776}
1777
5287ad62
JB
1778/* Types of registers in a list. */
1779
1780enum reg_list_els
1781{
1782 REGLIST_VFP_S,
1783 REGLIST_VFP_D,
1784 REGLIST_NEON_D
1785};
1786
c19d1205
ZW
1787/* Parse a VFP register list. If the string is invalid return FAIL.
1788 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1789 register. Parses registers of type ETYPE.
1790 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1791 - Q registers can be used to specify pairs of D registers
1792 - { } can be omitted from around a singleton register list
477330fc
RM
1793 FIXME: This is not implemented, as it would require backtracking in
1794 some cases, e.g.:
1795 vtbl.8 d3,d4,d5
1796 This could be done (the meaning isn't really ambiguous), but doesn't
1797 fit in well with the current parsing framework.
dcbf9037
JB
1798 - 32 D registers may be used (also true for VFPv3).
1799 FIXME: Types are ignored in these register lists, which is probably a
1800 bug. */
6057a28f 1801
c19d1205 1802static int
037e8744 1803parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1804{
037e8744 1805 char *str = *ccp;
c19d1205
ZW
1806 int base_reg;
1807 int new_base;
21d799b5 1808 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1809 int max_regs = 0;
c19d1205
ZW
1810 int count = 0;
1811 int warned = 0;
1812 unsigned long mask = 0;
a737bd4d 1813 int i;
6057a28f 1814
477330fc 1815 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1816 {
1817 inst.error = _("expecting {");
1818 return FAIL;
1819 }
6057a28f 1820
5287ad62 1821 switch (etype)
c19d1205 1822 {
5287ad62 1823 case REGLIST_VFP_S:
c19d1205
ZW
1824 regtype = REG_TYPE_VFS;
1825 max_regs = 32;
5287ad62 1826 break;
5f4273c7 1827
5287ad62
JB
1828 case REGLIST_VFP_D:
1829 regtype = REG_TYPE_VFD;
b7fc2769 1830 break;
5f4273c7 1831
b7fc2769
JB
1832 case REGLIST_NEON_D:
1833 regtype = REG_TYPE_NDQ;
1834 break;
1835 }
1836
1837 if (etype != REGLIST_VFP_S)
1838 {
b1cc4aeb
PB
1839 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1840 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1841 {
1842 max_regs = 32;
1843 if (thumb_mode)
1844 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1845 fpu_vfp_ext_d32);
1846 else
1847 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1848 fpu_vfp_ext_d32);
1849 }
5287ad62 1850 else
477330fc 1851 max_regs = 16;
c19d1205 1852 }
6057a28f 1853
c19d1205 1854 base_reg = max_regs;
a737bd4d 1855
c19d1205
ZW
1856 do
1857 {
5287ad62 1858 int setmask = 1, addregs = 1;
dcbf9037 1859
037e8744 1860 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1861
c19d1205 1862 if (new_base == FAIL)
a737bd4d 1863 {
dcbf9037 1864 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1865 return FAIL;
1866 }
5f4273c7 1867
b7fc2769 1868 if (new_base >= max_regs)
477330fc
RM
1869 {
1870 first_error (_("register out of range in list"));
1871 return FAIL;
1872 }
5f4273c7 1873
5287ad62
JB
1874 /* Note: a value of 2 * n is returned for the register Q<n>. */
1875 if (regtype == REG_TYPE_NQ)
477330fc
RM
1876 {
1877 setmask = 3;
1878 addregs = 2;
1879 }
5287ad62 1880
c19d1205
ZW
1881 if (new_base < base_reg)
1882 base_reg = new_base;
a737bd4d 1883
5287ad62 1884 if (mask & (setmask << new_base))
c19d1205 1885 {
dcbf9037 1886 first_error (_("invalid register list"));
c19d1205 1887 return FAIL;
a737bd4d 1888 }
a737bd4d 1889
c19d1205
ZW
1890 if ((mask >> new_base) != 0 && ! warned)
1891 {
1892 as_tsktsk (_("register list not in ascending order"));
1893 warned = 1;
1894 }
0bbf2aa4 1895
5287ad62
JB
1896 mask |= setmask << new_base;
1897 count += addregs;
0bbf2aa4 1898
037e8744 1899 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1900 {
1901 int high_range;
0bbf2aa4 1902
037e8744 1903 str++;
0bbf2aa4 1904
037e8744 1905 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1906 == FAIL)
c19d1205
ZW
1907 {
1908 inst.error = gettext (reg_expected_msgs[regtype]);
1909 return FAIL;
1910 }
0bbf2aa4 1911
477330fc
RM
1912 if (high_range >= max_regs)
1913 {
1914 first_error (_("register out of range in list"));
1915 return FAIL;
1916 }
b7fc2769 1917
477330fc
RM
1918 if (regtype == REG_TYPE_NQ)
1919 high_range = high_range + 1;
5287ad62 1920
c19d1205
ZW
1921 if (high_range <= new_base)
1922 {
1923 inst.error = _("register range not in ascending order");
1924 return FAIL;
1925 }
0bbf2aa4 1926
5287ad62 1927 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1928 {
5287ad62 1929 if (mask & (setmask << new_base))
0bbf2aa4 1930 {
c19d1205
ZW
1931 inst.error = _("invalid register list");
1932 return FAIL;
0bbf2aa4 1933 }
c19d1205 1934
5287ad62
JB
1935 mask |= setmask << new_base;
1936 count += addregs;
0bbf2aa4 1937 }
0bbf2aa4 1938 }
0bbf2aa4 1939 }
037e8744 1940 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1941
037e8744 1942 str++;
0bbf2aa4 1943
c19d1205
ZW
1944 /* Sanity check -- should have raised a parse error above. */
1945 if (count == 0 || count > max_regs)
1946 abort ();
1947
1948 *pbase = base_reg;
1949
1950 /* Final test -- the registers must be consecutive. */
1951 mask >>= base_reg;
1952 for (i = 0; i < count; i++)
1953 {
1954 if ((mask & (1u << i)) == 0)
1955 {
1956 inst.error = _("non-contiguous register range");
1957 return FAIL;
1958 }
1959 }
1960
037e8744
JB
1961 *ccp = str;
1962
c19d1205 1963 return count;
b99bd4ef
NC
1964}
1965
dcbf9037
JB
1966/* True if two alias types are the same. */
1967
c921be7d 1968static bfd_boolean
dcbf9037
JB
1969neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1970{
1971 if (!a && !b)
c921be7d 1972 return TRUE;
5f4273c7 1973
dcbf9037 1974 if (!a || !b)
c921be7d 1975 return FALSE;
dcbf9037
JB
1976
1977 if (a->defined != b->defined)
c921be7d 1978 return FALSE;
5f4273c7 1979
dcbf9037
JB
1980 if ((a->defined & NTA_HASTYPE) != 0
1981 && (a->eltype.type != b->eltype.type
477330fc 1982 || a->eltype.size != b->eltype.size))
c921be7d 1983 return FALSE;
dcbf9037
JB
1984
1985 if ((a->defined & NTA_HASINDEX) != 0
1986 && (a->index != b->index))
c921be7d 1987 return FALSE;
5f4273c7 1988
c921be7d 1989 return TRUE;
dcbf9037
JB
1990}
1991
5287ad62
JB
1992/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1993 The base register is put in *PBASE.
dcbf9037 1994 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1995 the return value.
1996 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1997 Bits [6:5] encode the list length (minus one).
1998 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1999
5287ad62 2000#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2001#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2002#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2003
2004static int
dcbf9037 2005parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2006 struct neon_type_el *eltype)
5287ad62
JB
2007{
2008 char *ptr = *str;
2009 int base_reg = -1;
2010 int reg_incr = -1;
2011 int count = 0;
2012 int lane = -1;
2013 int leading_brace = 0;
2014 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2015 const char *const incr_error = _("register stride must be 1 or 2");
2016 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2017 struct neon_typed_alias firsttype;
f85d59c3
KT
2018 firsttype.defined = 0;
2019 firsttype.eltype.type = NT_invtype;
2020 firsttype.eltype.size = -1;
2021 firsttype.index = -1;
5f4273c7 2022
5287ad62
JB
2023 if (skip_past_char (&ptr, '{') == SUCCESS)
2024 leading_brace = 1;
5f4273c7 2025
5287ad62
JB
2026 do
2027 {
dcbf9037
JB
2028 struct neon_typed_alias atype;
2029 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2030
5287ad62 2031 if (getreg == FAIL)
477330fc
RM
2032 {
2033 first_error (_(reg_expected_msgs[rtype]));
2034 return FAIL;
2035 }
5f4273c7 2036
5287ad62 2037 if (base_reg == -1)
477330fc
RM
2038 {
2039 base_reg = getreg;
2040 if (rtype == REG_TYPE_NQ)
2041 {
2042 reg_incr = 1;
2043 }
2044 firsttype = atype;
2045 }
5287ad62 2046 else if (reg_incr == -1)
477330fc
RM
2047 {
2048 reg_incr = getreg - base_reg;
2049 if (reg_incr < 1 || reg_incr > 2)
2050 {
2051 first_error (_(incr_error));
2052 return FAIL;
2053 }
2054 }
5287ad62 2055 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2056 {
2057 first_error (_(incr_error));
2058 return FAIL;
2059 }
dcbf9037 2060
c921be7d 2061 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2062 {
2063 first_error (_(type_error));
2064 return FAIL;
2065 }
5f4273c7 2066
5287ad62 2067 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2068 modes. */
5287ad62 2069 if (ptr[0] == '-')
477330fc
RM
2070 {
2071 struct neon_typed_alias htype;
2072 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2073 if (lane == -1)
2074 lane = NEON_INTERLEAVE_LANES;
2075 else if (lane != NEON_INTERLEAVE_LANES)
2076 {
2077 first_error (_(type_error));
2078 return FAIL;
2079 }
2080 if (reg_incr == -1)
2081 reg_incr = 1;
2082 else if (reg_incr != 1)
2083 {
2084 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2085 return FAIL;
2086 }
2087 ptr++;
2088 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2089 if (hireg == FAIL)
2090 {
2091 first_error (_(reg_expected_msgs[rtype]));
2092 return FAIL;
2093 }
2094 if (! neon_alias_types_same (&htype, &firsttype))
2095 {
2096 first_error (_(type_error));
2097 return FAIL;
2098 }
2099 count += hireg + dregs - getreg;
2100 continue;
2101 }
5f4273c7 2102
5287ad62
JB
2103 /* If we're using Q registers, we can't use [] or [n] syntax. */
2104 if (rtype == REG_TYPE_NQ)
477330fc
RM
2105 {
2106 count += 2;
2107 continue;
2108 }
5f4273c7 2109
dcbf9037 2110 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2111 {
2112 if (lane == -1)
2113 lane = atype.index;
2114 else if (lane != atype.index)
2115 {
2116 first_error (_(type_error));
2117 return FAIL;
2118 }
2119 }
5287ad62 2120 else if (lane == -1)
477330fc 2121 lane = NEON_INTERLEAVE_LANES;
5287ad62 2122 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2123 {
2124 first_error (_(type_error));
2125 return FAIL;
2126 }
5287ad62
JB
2127 count++;
2128 }
2129 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2130
5287ad62
JB
2131 /* No lane set by [x]. We must be interleaving structures. */
2132 if (lane == -1)
2133 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2134
5287ad62
JB
2135 /* Sanity check. */
2136 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2137 || (count > 1 && reg_incr == -1))
2138 {
dcbf9037 2139 first_error (_("error parsing element/structure list"));
5287ad62
JB
2140 return FAIL;
2141 }
2142
2143 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2144 {
dcbf9037 2145 first_error (_("expected }"));
5287ad62
JB
2146 return FAIL;
2147 }
5f4273c7 2148
5287ad62
JB
2149 if (reg_incr == -1)
2150 reg_incr = 1;
2151
dcbf9037
JB
2152 if (eltype)
2153 *eltype = firsttype.eltype;
2154
5287ad62
JB
2155 *pbase = base_reg;
2156 *str = ptr;
5f4273c7 2157
5287ad62
JB
2158 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2159}
2160
c19d1205
ZW
2161/* Parse an explicit relocation suffix on an expression. This is
2162 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2163 arm_reloc_hsh contains no entries, so this function can only
2164 succeed if there is no () after the word. Returns -1 on error,
2165 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2166
c19d1205
ZW
2167static int
2168parse_reloc (char **str)
b99bd4ef 2169{
c19d1205
ZW
2170 struct reloc_entry *r;
2171 char *p, *q;
b99bd4ef 2172
c19d1205
ZW
2173 if (**str != '(')
2174 return BFD_RELOC_UNUSED;
b99bd4ef 2175
c19d1205
ZW
2176 p = *str + 1;
2177 q = p;
2178
2179 while (*q && *q != ')' && *q != ',')
2180 q++;
2181 if (*q != ')')
2182 return -1;
2183
21d799b5
NC
2184 if ((r = (struct reloc_entry *)
2185 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2186 return -1;
2187
2188 *str = q + 1;
2189 return r->reloc;
b99bd4ef
NC
2190}
2191
c19d1205
ZW
2192/* Directives: register aliases. */
2193
dcbf9037 2194static struct reg_entry *
90ec0d68 2195insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2196{
d3ce72d0 2197 struct reg_entry *new_reg;
c19d1205 2198 const char *name;
b99bd4ef 2199
d3ce72d0 2200 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2201 {
d3ce72d0 2202 if (new_reg->builtin)
c19d1205 2203 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2204
c19d1205
ZW
2205 /* Only warn about a redefinition if it's not defined as the
2206 same register. */
d3ce72d0 2207 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2208 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2209
d929913e 2210 return NULL;
c19d1205 2211 }
b99bd4ef 2212
c19d1205 2213 name = xstrdup (str);
325801bd 2214 new_reg = XNEW (struct reg_entry);
b99bd4ef 2215
d3ce72d0
NC
2216 new_reg->name = name;
2217 new_reg->number = number;
2218 new_reg->type = type;
2219 new_reg->builtin = FALSE;
2220 new_reg->neon = NULL;
b99bd4ef 2221
d3ce72d0 2222 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2223 abort ();
5f4273c7 2224
d3ce72d0 2225 return new_reg;
dcbf9037
JB
2226}
2227
2228static void
2229insert_neon_reg_alias (char *str, int number, int type,
477330fc 2230 struct neon_typed_alias *atype)
dcbf9037
JB
2231{
2232 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2233
dcbf9037
JB
2234 if (!reg)
2235 {
2236 first_error (_("attempt to redefine typed alias"));
2237 return;
2238 }
5f4273c7 2239
dcbf9037
JB
2240 if (atype)
2241 {
325801bd 2242 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2243 *reg->neon = *atype;
2244 }
c19d1205 2245}
b99bd4ef 2246
c19d1205 2247/* Look for the .req directive. This is of the form:
b99bd4ef 2248
c19d1205 2249 new_register_name .req existing_register_name
b99bd4ef 2250
c19d1205 2251 If we find one, or if it looks sufficiently like one that we want to
d929913e 2252 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2253
d929913e 2254static bfd_boolean
c19d1205
ZW
2255create_register_alias (char * newname, char *p)
2256{
2257 struct reg_entry *old;
2258 char *oldname, *nbuf;
2259 size_t nlen;
b99bd4ef 2260
c19d1205
ZW
2261 /* The input scrubber ensures that whitespace after the mnemonic is
2262 collapsed to single spaces. */
2263 oldname = p;
2264 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2265 return FALSE;
b99bd4ef 2266
c19d1205
ZW
2267 oldname += 6;
2268 if (*oldname == '\0')
d929913e 2269 return FALSE;
b99bd4ef 2270
21d799b5 2271 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2272 if (!old)
b99bd4ef 2273 {
c19d1205 2274 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2275 return TRUE;
b99bd4ef
NC
2276 }
2277
c19d1205
ZW
2278 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2279 the desired alias name, and p points to its end. If not, then
2280 the desired alias name is in the global original_case_string. */
2281#ifdef TC_CASE_SENSITIVE
2282 nlen = p - newname;
2283#else
2284 newname = original_case_string;
2285 nlen = strlen (newname);
2286#endif
b99bd4ef 2287
29a2809e 2288 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2289
c19d1205
ZW
2290 /* Create aliases under the new name as stated; an all-lowercase
2291 version of the new name; and an all-uppercase version of the new
2292 name. */
d929913e
NC
2293 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2294 {
2295 for (p = nbuf; *p; p++)
2296 *p = TOUPPER (*p);
c19d1205 2297
d929913e
NC
2298 if (strncmp (nbuf, newname, nlen))
2299 {
2300 /* If this attempt to create an additional alias fails, do not bother
2301 trying to create the all-lower case alias. We will fail and issue
2302 a second, duplicate error message. This situation arises when the
2303 programmer does something like:
2304 foo .req r0
2305 Foo .req r1
2306 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2307 the artificial FOO alias because it has already been created by the
d929913e
NC
2308 first .req. */
2309 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2310 {
2311 free (nbuf);
2312 return TRUE;
2313 }
d929913e 2314 }
c19d1205 2315
d929913e
NC
2316 for (p = nbuf; *p; p++)
2317 *p = TOLOWER (*p);
c19d1205 2318
d929913e
NC
2319 if (strncmp (nbuf, newname, nlen))
2320 insert_reg_alias (nbuf, old->number, old->type);
2321 }
c19d1205 2322
e1fa0163 2323 free (nbuf);
d929913e 2324 return TRUE;
b99bd4ef
NC
2325}
2326
dcbf9037
JB
2327/* Create a Neon typed/indexed register alias using directives, e.g.:
2328 X .dn d5.s32[1]
2329 Y .qn 6.s16
2330 Z .dn d7
2331 T .dn Z[0]
2332 These typed registers can be used instead of the types specified after the
2333 Neon mnemonic, so long as all operands given have types. Types can also be
2334 specified directly, e.g.:
5f4273c7 2335 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2336
c921be7d 2337static bfd_boolean
dcbf9037
JB
2338create_neon_reg_alias (char *newname, char *p)
2339{
2340 enum arm_reg_type basetype;
2341 struct reg_entry *basereg;
2342 struct reg_entry mybasereg;
2343 struct neon_type ntype;
2344 struct neon_typed_alias typeinfo;
12d6b0b7 2345 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2346 int namelen;
5f4273c7 2347
dcbf9037
JB
2348 typeinfo.defined = 0;
2349 typeinfo.eltype.type = NT_invtype;
2350 typeinfo.eltype.size = -1;
2351 typeinfo.index = -1;
5f4273c7 2352
dcbf9037 2353 nameend = p;
5f4273c7 2354
dcbf9037
JB
2355 if (strncmp (p, " .dn ", 5) == 0)
2356 basetype = REG_TYPE_VFD;
2357 else if (strncmp (p, " .qn ", 5) == 0)
2358 basetype = REG_TYPE_NQ;
2359 else
c921be7d 2360 return FALSE;
5f4273c7 2361
dcbf9037 2362 p += 5;
5f4273c7 2363
dcbf9037 2364 if (*p == '\0')
c921be7d 2365 return FALSE;
5f4273c7 2366
dcbf9037
JB
2367 basereg = arm_reg_parse_multi (&p);
2368
2369 if (basereg && basereg->type != basetype)
2370 {
2371 as_bad (_("bad type for register"));
c921be7d 2372 return FALSE;
dcbf9037
JB
2373 }
2374
2375 if (basereg == NULL)
2376 {
2377 expressionS exp;
2378 /* Try parsing as an integer. */
2379 my_get_expression (&exp, &p, GE_NO_PREFIX);
2380 if (exp.X_op != O_constant)
477330fc
RM
2381 {
2382 as_bad (_("expression must be constant"));
2383 return FALSE;
2384 }
dcbf9037
JB
2385 basereg = &mybasereg;
2386 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2387 : exp.X_add_number;
dcbf9037
JB
2388 basereg->neon = 0;
2389 }
2390
2391 if (basereg->neon)
2392 typeinfo = *basereg->neon;
2393
2394 if (parse_neon_type (&ntype, &p) == SUCCESS)
2395 {
2396 /* We got a type. */
2397 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2398 {
2399 as_bad (_("can't redefine the type of a register alias"));
2400 return FALSE;
2401 }
5f4273c7 2402
dcbf9037
JB
2403 typeinfo.defined |= NTA_HASTYPE;
2404 if (ntype.elems != 1)
477330fc
RM
2405 {
2406 as_bad (_("you must specify a single type only"));
2407 return FALSE;
2408 }
dcbf9037
JB
2409 typeinfo.eltype = ntype.el[0];
2410 }
5f4273c7 2411
dcbf9037
JB
2412 if (skip_past_char (&p, '[') == SUCCESS)
2413 {
2414 expressionS exp;
2415 /* We got a scalar index. */
5f4273c7 2416
dcbf9037 2417 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2418 {
2419 as_bad (_("can't redefine the index of a scalar alias"));
2420 return FALSE;
2421 }
5f4273c7 2422
dcbf9037 2423 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2424
dcbf9037 2425 if (exp.X_op != O_constant)
477330fc
RM
2426 {
2427 as_bad (_("scalar index must be constant"));
2428 return FALSE;
2429 }
5f4273c7 2430
dcbf9037
JB
2431 typeinfo.defined |= NTA_HASINDEX;
2432 typeinfo.index = exp.X_add_number;
5f4273c7 2433
dcbf9037 2434 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2435 {
2436 as_bad (_("expecting ]"));
2437 return FALSE;
2438 }
dcbf9037
JB
2439 }
2440
15735687
NS
2441 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2442 the desired alias name, and p points to its end. If not, then
2443 the desired alias name is in the global original_case_string. */
2444#ifdef TC_CASE_SENSITIVE
dcbf9037 2445 namelen = nameend - newname;
15735687
NS
2446#else
2447 newname = original_case_string;
2448 namelen = strlen (newname);
2449#endif
2450
29a2809e 2451 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2452
dcbf9037 2453 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2454 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2455
dcbf9037
JB
2456 /* Insert name in all uppercase. */
2457 for (p = namebuf; *p; p++)
2458 *p = TOUPPER (*p);
5f4273c7 2459
dcbf9037
JB
2460 if (strncmp (namebuf, newname, namelen))
2461 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2462 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2463
dcbf9037
JB
2464 /* Insert name in all lowercase. */
2465 for (p = namebuf; *p; p++)
2466 *p = TOLOWER (*p);
5f4273c7 2467
dcbf9037
JB
2468 if (strncmp (namebuf, newname, namelen))
2469 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2470 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2471
e1fa0163 2472 free (namebuf);
c921be7d 2473 return TRUE;
dcbf9037
JB
2474}
2475
c19d1205
ZW
2476/* Should never be called, as .req goes between the alias and the
2477 register name, not at the beginning of the line. */
c921be7d 2478
b99bd4ef 2479static void
c19d1205 2480s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2481{
c19d1205
ZW
2482 as_bad (_("invalid syntax for .req directive"));
2483}
b99bd4ef 2484
dcbf9037
JB
2485static void
2486s_dn (int a ATTRIBUTE_UNUSED)
2487{
2488 as_bad (_("invalid syntax for .dn directive"));
2489}
2490
2491static void
2492s_qn (int a ATTRIBUTE_UNUSED)
2493{
2494 as_bad (_("invalid syntax for .qn directive"));
2495}
2496
c19d1205
ZW
2497/* The .unreq directive deletes an alias which was previously defined
2498 by .req. For example:
b99bd4ef 2499
c19d1205
ZW
2500 my_alias .req r11
2501 .unreq my_alias */
b99bd4ef
NC
2502
2503static void
c19d1205 2504s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2505{
c19d1205
ZW
2506 char * name;
2507 char saved_char;
b99bd4ef 2508
c19d1205
ZW
2509 name = input_line_pointer;
2510
2511 while (*input_line_pointer != 0
2512 && *input_line_pointer != ' '
2513 && *input_line_pointer != '\n')
2514 ++input_line_pointer;
2515
2516 saved_char = *input_line_pointer;
2517 *input_line_pointer = 0;
2518
2519 if (!*name)
2520 as_bad (_("invalid syntax for .unreq directive"));
2521 else
2522 {
21d799b5 2523 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2524 name);
c19d1205
ZW
2525
2526 if (!reg)
2527 as_bad (_("unknown register alias '%s'"), name);
2528 else if (reg->builtin)
a1727c1a 2529 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2530 name);
2531 else
2532 {
d929913e
NC
2533 char * p;
2534 char * nbuf;
2535
db0bc284 2536 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2537 free ((char *) reg->name);
477330fc
RM
2538 if (reg->neon)
2539 free (reg->neon);
c19d1205 2540 free (reg);
d929913e
NC
2541
2542 /* Also locate the all upper case and all lower case versions.
2543 Do not complain if we cannot find one or the other as it
2544 was probably deleted above. */
5f4273c7 2545
d929913e
NC
2546 nbuf = strdup (name);
2547 for (p = nbuf; *p; p++)
2548 *p = TOUPPER (*p);
21d799b5 2549 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2550 if (reg)
2551 {
db0bc284 2552 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2553 free ((char *) reg->name);
2554 if (reg->neon)
2555 free (reg->neon);
2556 free (reg);
2557 }
2558
2559 for (p = nbuf; *p; p++)
2560 *p = TOLOWER (*p);
21d799b5 2561 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2562 if (reg)
2563 {
db0bc284 2564 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2565 free ((char *) reg->name);
2566 if (reg->neon)
2567 free (reg->neon);
2568 free (reg);
2569 }
2570
2571 free (nbuf);
c19d1205
ZW
2572 }
2573 }
b99bd4ef 2574
c19d1205 2575 *input_line_pointer = saved_char;
b99bd4ef
NC
2576 demand_empty_rest_of_line ();
2577}
2578
c19d1205
ZW
2579/* Directives: Instruction set selection. */
2580
2581#ifdef OBJ_ELF
2582/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2583 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2584 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2585 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2586
cd000bff
DJ
2587/* Create a new mapping symbol for the transition to STATE. */
2588
2589static void
2590make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2591{
a737bd4d 2592 symbolS * symbolP;
c19d1205
ZW
2593 const char * symname;
2594 int type;
b99bd4ef 2595
c19d1205 2596 switch (state)
b99bd4ef 2597 {
c19d1205
ZW
2598 case MAP_DATA:
2599 symname = "$d";
2600 type = BSF_NO_FLAGS;
2601 break;
2602 case MAP_ARM:
2603 symname = "$a";
2604 type = BSF_NO_FLAGS;
2605 break;
2606 case MAP_THUMB:
2607 symname = "$t";
2608 type = BSF_NO_FLAGS;
2609 break;
c19d1205
ZW
2610 default:
2611 abort ();
2612 }
2613
cd000bff 2614 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2615 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2616
2617 switch (state)
2618 {
2619 case MAP_ARM:
2620 THUMB_SET_FUNC (symbolP, 0);
2621 ARM_SET_THUMB (symbolP, 0);
2622 ARM_SET_INTERWORK (symbolP, support_interwork);
2623 break;
2624
2625 case MAP_THUMB:
2626 THUMB_SET_FUNC (symbolP, 1);
2627 ARM_SET_THUMB (symbolP, 1);
2628 ARM_SET_INTERWORK (symbolP, support_interwork);
2629 break;
2630
2631 case MAP_DATA:
2632 default:
cd000bff
DJ
2633 break;
2634 }
2635
2636 /* Save the mapping symbols for future reference. Also check that
2637 we do not place two mapping symbols at the same offset within a
2638 frag. We'll handle overlap between frags in
2de7820f
JZ
2639 check_mapping_symbols.
2640
2641 If .fill or other data filling directive generates zero sized data,
2642 the mapping symbol for the following code will have the same value
2643 as the one generated for the data filling directive. In this case,
2644 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2645 if (value == 0)
2646 {
2de7820f
JZ
2647 if (frag->tc_frag_data.first_map != NULL)
2648 {
2649 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2650 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2651 }
cd000bff
DJ
2652 frag->tc_frag_data.first_map = symbolP;
2653 }
2654 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2655 {
2656 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2657 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2658 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2659 }
cd000bff
DJ
2660 frag->tc_frag_data.last_map = symbolP;
2661}
2662
2663/* We must sometimes convert a region marked as code to data during
2664 code alignment, if an odd number of bytes have to be padded. The
2665 code mapping symbol is pushed to an aligned address. */
2666
2667static void
2668insert_data_mapping_symbol (enum mstate state,
2669 valueT value, fragS *frag, offsetT bytes)
2670{
2671 /* If there was already a mapping symbol, remove it. */
2672 if (frag->tc_frag_data.last_map != NULL
2673 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2674 {
2675 symbolS *symp = frag->tc_frag_data.last_map;
2676
2677 if (value == 0)
2678 {
2679 know (frag->tc_frag_data.first_map == symp);
2680 frag->tc_frag_data.first_map = NULL;
2681 }
2682 frag->tc_frag_data.last_map = NULL;
2683 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2684 }
cd000bff
DJ
2685
2686 make_mapping_symbol (MAP_DATA, value, frag);
2687 make_mapping_symbol (state, value + bytes, frag);
2688}
2689
2690static void mapping_state_2 (enum mstate state, int max_chars);
2691
2692/* Set the mapping state to STATE. Only call this when about to
2693 emit some STATE bytes to the file. */
2694
4e9aaefb 2695#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2696void
2697mapping_state (enum mstate state)
2698{
940b5ce0
DJ
2699 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2700
cd000bff
DJ
2701 if (mapstate == state)
2702 /* The mapping symbol has already been emitted.
2703 There is nothing else to do. */
2704 return;
49c62a33
NC
2705
2706 if (state == MAP_ARM || state == MAP_THUMB)
2707 /* PR gas/12931
2708 All ARM instructions require 4-byte alignment.
2709 (Almost) all Thumb instructions require 2-byte alignment.
2710
2711 When emitting instructions into any section, mark the section
2712 appropriately.
2713
2714 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2715 but themselves require 2-byte alignment; this applies to some
33eaf5de 2716 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2717 literal pool generation or an explicit .align >=2, both of
2718 which will cause the section to me marked with sufficient
2719 alignment. Thus, we don't handle those cases here. */
2720 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2721
2722 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2723 /* This case will be evaluated later. */
cd000bff 2724 return;
cd000bff
DJ
2725
2726 mapping_state_2 (state, 0);
cd000bff
DJ
2727}
2728
2729/* Same as mapping_state, but MAX_CHARS bytes have already been
2730 allocated. Put the mapping symbol that far back. */
2731
2732static void
2733mapping_state_2 (enum mstate state, int max_chars)
2734{
940b5ce0
DJ
2735 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2736
2737 if (!SEG_NORMAL (now_seg))
2738 return;
2739
cd000bff
DJ
2740 if (mapstate == state)
2741 /* The mapping symbol has already been emitted.
2742 There is nothing else to do. */
2743 return;
2744
4e9aaefb
SA
2745 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2746 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2747 {
2748 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2749 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2750
2751 if (add_symbol)
2752 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2753 }
2754
cd000bff
DJ
2755 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2756 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2757}
4e9aaefb 2758#undef TRANSITION
c19d1205 2759#else
d3106081
NS
2760#define mapping_state(x) ((void)0)
2761#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2762#endif
2763
2764/* Find the real, Thumb encoded start of a Thumb function. */
2765
4343666d 2766#ifdef OBJ_COFF
c19d1205
ZW
2767static symbolS *
2768find_real_start (symbolS * symbolP)
2769{
2770 char * real_start;
2771 const char * name = S_GET_NAME (symbolP);
2772 symbolS * new_target;
2773
2774 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2775#define STUB_NAME ".real_start_of"
2776
2777 if (name == NULL)
2778 abort ();
2779
37f6032b
ZW
2780 /* The compiler may generate BL instructions to local labels because
2781 it needs to perform a branch to a far away location. These labels
2782 do not have a corresponding ".real_start_of" label. We check
2783 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2784 the ".real_start_of" convention for nonlocal branches. */
2785 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2786 return symbolP;
2787
e1fa0163 2788 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2789 new_target = symbol_find (real_start);
e1fa0163 2790 free (real_start);
c19d1205
ZW
2791
2792 if (new_target == NULL)
2793 {
bd3ba5d1 2794 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2795 new_target = symbolP;
2796 }
2797
c19d1205
ZW
2798 return new_target;
2799}
4343666d 2800#endif
c19d1205
ZW
2801
2802static void
2803opcode_select (int width)
2804{
2805 switch (width)
2806 {
2807 case 16:
2808 if (! thumb_mode)
2809 {
e74cfd16 2810 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2811 as_bad (_("selected processor does not support THUMB opcodes"));
2812
2813 thumb_mode = 1;
2814 /* No need to force the alignment, since we will have been
2815 coming from ARM mode, which is word-aligned. */
2816 record_alignment (now_seg, 1);
2817 }
c19d1205
ZW
2818 break;
2819
2820 case 32:
2821 if (thumb_mode)
2822 {
e74cfd16 2823 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2824 as_bad (_("selected processor does not support ARM opcodes"));
2825
2826 thumb_mode = 0;
2827
2828 if (!need_pass_2)
2829 frag_align (2, 0, 0);
2830
2831 record_alignment (now_seg, 1);
2832 }
c19d1205
ZW
2833 break;
2834
2835 default:
2836 as_bad (_("invalid instruction size selected (%d)"), width);
2837 }
2838}
2839
2840static void
2841s_arm (int ignore ATTRIBUTE_UNUSED)
2842{
2843 opcode_select (32);
2844 demand_empty_rest_of_line ();
2845}
2846
2847static void
2848s_thumb (int ignore ATTRIBUTE_UNUSED)
2849{
2850 opcode_select (16);
2851 demand_empty_rest_of_line ();
2852}
2853
2854static void
2855s_code (int unused ATTRIBUTE_UNUSED)
2856{
2857 int temp;
2858
2859 temp = get_absolute_expression ();
2860 switch (temp)
2861 {
2862 case 16:
2863 case 32:
2864 opcode_select (temp);
2865 break;
2866
2867 default:
2868 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2869 }
2870}
2871
2872static void
2873s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2874{
2875 /* If we are not already in thumb mode go into it, EVEN if
2876 the target processor does not support thumb instructions.
2877 This is used by gcc/config/arm/lib1funcs.asm for example
2878 to compile interworking support functions even if the
2879 target processor should not support interworking. */
2880 if (! thumb_mode)
2881 {
2882 thumb_mode = 2;
2883 record_alignment (now_seg, 1);
2884 }
2885
2886 demand_empty_rest_of_line ();
2887}
2888
2889static void
2890s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2891{
2892 s_thumb (0);
2893
2894 /* The following label is the name/address of the start of a Thumb function.
2895 We need to know this for the interworking support. */
2896 label_is_thumb_function_name = TRUE;
2897}
2898
2899/* Perform a .set directive, but also mark the alias as
2900 being a thumb function. */
2901
2902static void
2903s_thumb_set (int equiv)
2904{
2905 /* XXX the following is a duplicate of the code for s_set() in read.c
2906 We cannot just call that code as we need to get at the symbol that
2907 is created. */
2908 char * name;
2909 char delim;
2910 char * end_name;
2911 symbolS * symbolP;
2912
2913 /* Especial apologies for the random logic:
2914 This just grew, and could be parsed much more simply!
2915 Dean - in haste. */
d02603dc 2916 delim = get_symbol_name (& name);
c19d1205 2917 end_name = input_line_pointer;
d02603dc 2918 (void) restore_line_pointer (delim);
c19d1205
ZW
2919
2920 if (*input_line_pointer != ',')
2921 {
2922 *end_name = 0;
2923 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2924 *end_name = delim;
2925 ignore_rest_of_line ();
2926 return;
2927 }
2928
2929 input_line_pointer++;
2930 *end_name = 0;
2931
2932 if (name[0] == '.' && name[1] == '\0')
2933 {
2934 /* XXX - this should not happen to .thumb_set. */
2935 abort ();
2936 }
2937
2938 if ((symbolP = symbol_find (name)) == NULL
2939 && (symbolP = md_undefined_symbol (name)) == NULL)
2940 {
2941#ifndef NO_LISTING
2942 /* When doing symbol listings, play games with dummy fragments living
2943 outside the normal fragment chain to record the file and line info
c19d1205 2944 for this symbol. */
b99bd4ef
NC
2945 if (listing & LISTING_SYMBOLS)
2946 {
2947 extern struct list_info_struct * listing_tail;
21d799b5 2948 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2949
2950 memset (dummy_frag, 0, sizeof (fragS));
2951 dummy_frag->fr_type = rs_fill;
2952 dummy_frag->line = listing_tail;
2953 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2954 dummy_frag->fr_symbol = symbolP;
2955 }
2956 else
2957#endif
2958 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2959
2960#ifdef OBJ_COFF
2961 /* "set" symbols are local unless otherwise specified. */
2962 SF_SET_LOCAL (symbolP);
2963#endif /* OBJ_COFF */
2964 } /* Make a new symbol. */
2965
2966 symbol_table_insert (symbolP);
2967
2968 * end_name = delim;
2969
2970 if (equiv
2971 && S_IS_DEFINED (symbolP)
2972 && S_GET_SEGMENT (symbolP) != reg_section)
2973 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2974
2975 pseudo_set (symbolP);
2976
2977 demand_empty_rest_of_line ();
2978
c19d1205 2979 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2980
2981 THUMB_SET_FUNC (symbolP, 1);
2982 ARM_SET_THUMB (symbolP, 1);
2983#if defined OBJ_ELF || defined OBJ_COFF
2984 ARM_SET_INTERWORK (symbolP, support_interwork);
2985#endif
2986}
2987
c19d1205 2988/* Directives: Mode selection. */
b99bd4ef 2989
c19d1205
ZW
2990/* .syntax [unified|divided] - choose the new unified syntax
2991 (same for Arm and Thumb encoding, modulo slight differences in what
2992 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2993static void
c19d1205 2994s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2995{
c19d1205
ZW
2996 char *name, delim;
2997
d02603dc 2998 delim = get_symbol_name (& name);
c19d1205
ZW
2999
3000 if (!strcasecmp (name, "unified"))
3001 unified_syntax = TRUE;
3002 else if (!strcasecmp (name, "divided"))
3003 unified_syntax = FALSE;
3004 else
3005 {
3006 as_bad (_("unrecognized syntax mode \"%s\""), name);
3007 return;
3008 }
d02603dc 3009 (void) restore_line_pointer (delim);
b99bd4ef
NC
3010 demand_empty_rest_of_line ();
3011}
3012
c19d1205
ZW
3013/* Directives: sectioning and alignment. */
3014
c19d1205
ZW
3015static void
3016s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3017{
c19d1205
ZW
3018 /* We don't support putting frags in the BSS segment, we fake it by
3019 marking in_bss, then looking at s_skip for clues. */
3020 subseg_set (bss_section, 0);
3021 demand_empty_rest_of_line ();
cd000bff
DJ
3022
3023#ifdef md_elf_section_change_hook
3024 md_elf_section_change_hook ();
3025#endif
c19d1205 3026}
b99bd4ef 3027
c19d1205
ZW
3028static void
3029s_even (int ignore ATTRIBUTE_UNUSED)
3030{
3031 /* Never make frag if expect extra pass. */
3032 if (!need_pass_2)
3033 frag_align (1, 0, 0);
b99bd4ef 3034
c19d1205 3035 record_alignment (now_seg, 1);
b99bd4ef 3036
c19d1205 3037 demand_empty_rest_of_line ();
b99bd4ef
NC
3038}
3039
2e6976a8
DG
3040/* Directives: CodeComposer Studio. */
3041
3042/* .ref (for CodeComposer Studio syntax only). */
3043static void
3044s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3045{
3046 if (codecomposer_syntax)
3047 ignore_rest_of_line ();
3048 else
3049 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3050}
3051
3052/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3053 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3054static void
3055asmfunc_debug (const char * name)
3056{
3057 static const char * last_name = NULL;
3058
3059 if (name != NULL)
3060 {
3061 gas_assert (last_name == NULL);
3062 last_name = name;
3063
3064 if (debug_type == DEBUG_STABS)
3065 stabs_generate_asm_func (name, name);
3066 }
3067 else
3068 {
3069 gas_assert (last_name != NULL);
3070
3071 if (debug_type == DEBUG_STABS)
3072 stabs_generate_asm_endfunc (last_name, last_name);
3073
3074 last_name = NULL;
3075 }
3076}
3077
3078static void
3079s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3080{
3081 if (codecomposer_syntax)
3082 {
3083 switch (asmfunc_state)
3084 {
3085 case OUTSIDE_ASMFUNC:
3086 asmfunc_state = WAITING_ASMFUNC_NAME;
3087 break;
3088
3089 case WAITING_ASMFUNC_NAME:
3090 as_bad (_(".asmfunc repeated."));
3091 break;
3092
3093 case WAITING_ENDASMFUNC:
3094 as_bad (_(".asmfunc without function."));
3095 break;
3096 }
3097 demand_empty_rest_of_line ();
3098 }
3099 else
3100 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3101}
3102
3103static void
3104s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3105{
3106 if (codecomposer_syntax)
3107 {
3108 switch (asmfunc_state)
3109 {
3110 case OUTSIDE_ASMFUNC:
3111 as_bad (_(".endasmfunc without a .asmfunc."));
3112 break;
3113
3114 case WAITING_ASMFUNC_NAME:
3115 as_bad (_(".endasmfunc without function."));
3116 break;
3117
3118 case WAITING_ENDASMFUNC:
3119 asmfunc_state = OUTSIDE_ASMFUNC;
3120 asmfunc_debug (NULL);
3121 break;
3122 }
3123 demand_empty_rest_of_line ();
3124 }
3125 else
3126 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3127}
3128
3129static void
3130s_ccs_def (int name)
3131{
3132 if (codecomposer_syntax)
3133 s_globl (name);
3134 else
3135 as_bad (_(".def pseudo-op only available with -mccs flag."));
3136}
3137
c19d1205 3138/* Directives: Literal pools. */
a737bd4d 3139
c19d1205
ZW
3140static literal_pool *
3141find_literal_pool (void)
a737bd4d 3142{
c19d1205 3143 literal_pool * pool;
a737bd4d 3144
c19d1205 3145 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3146 {
c19d1205
ZW
3147 if (pool->section == now_seg
3148 && pool->sub_section == now_subseg)
3149 break;
a737bd4d
NC
3150 }
3151
c19d1205 3152 return pool;
a737bd4d
NC
3153}
3154
c19d1205
ZW
3155static literal_pool *
3156find_or_make_literal_pool (void)
a737bd4d 3157{
c19d1205
ZW
3158 /* Next literal pool ID number. */
3159 static unsigned int latest_pool_num = 1;
3160 literal_pool * pool;
a737bd4d 3161
c19d1205 3162 pool = find_literal_pool ();
a737bd4d 3163
c19d1205 3164 if (pool == NULL)
a737bd4d 3165 {
c19d1205 3166 /* Create a new pool. */
325801bd 3167 pool = XNEW (literal_pool);
c19d1205
ZW
3168 if (! pool)
3169 return NULL;
a737bd4d 3170
c19d1205
ZW
3171 pool->next_free_entry = 0;
3172 pool->section = now_seg;
3173 pool->sub_section = now_subseg;
3174 pool->next = list_of_pools;
3175 pool->symbol = NULL;
8335d6aa 3176 pool->alignment = 2;
c19d1205
ZW
3177
3178 /* Add it to the list. */
3179 list_of_pools = pool;
a737bd4d 3180 }
a737bd4d 3181
c19d1205
ZW
3182 /* New pools, and emptied pools, will have a NULL symbol. */
3183 if (pool->symbol == NULL)
a737bd4d 3184 {
c19d1205
ZW
3185 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3186 (valueT) 0, &zero_address_frag);
3187 pool->id = latest_pool_num ++;
a737bd4d
NC
3188 }
3189
c19d1205
ZW
3190 /* Done. */
3191 return pool;
a737bd4d
NC
3192}
3193
c19d1205 3194/* Add the literal in the global 'inst'
5f4273c7 3195 structure to the relevant literal pool. */
b99bd4ef
NC
3196
3197static int
8335d6aa 3198add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3199{
8335d6aa
JW
3200#define PADDING_SLOT 0x1
3201#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3202 literal_pool * pool;
8335d6aa
JW
3203 unsigned int entry, pool_size = 0;
3204 bfd_boolean padding_slot_p = FALSE;
e56c722b 3205 unsigned imm1 = 0;
8335d6aa
JW
3206 unsigned imm2 = 0;
3207
3208 if (nbytes == 8)
3209 {
3210 imm1 = inst.operands[1].imm;
3211 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3212 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3213 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3214 if (target_big_endian)
3215 {
3216 imm1 = imm2;
3217 imm2 = inst.operands[1].imm;
3218 }
3219 }
b99bd4ef 3220
c19d1205
ZW
3221 pool = find_or_make_literal_pool ();
3222
3223 /* Check if this literal value is already in the pool. */
3224 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3225 {
8335d6aa
JW
3226 if (nbytes == 4)
3227 {
3228 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3229 && (inst.reloc.exp.X_op == O_constant)
3230 && (pool->literals[entry].X_add_number
3231 == inst.reloc.exp.X_add_number)
3232 && (pool->literals[entry].X_md == nbytes)
3233 && (pool->literals[entry].X_unsigned
3234 == inst.reloc.exp.X_unsigned))
3235 break;
3236
3237 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3238 && (inst.reloc.exp.X_op == O_symbol)
3239 && (pool->literals[entry].X_add_number
3240 == inst.reloc.exp.X_add_number)
3241 && (pool->literals[entry].X_add_symbol
3242 == inst.reloc.exp.X_add_symbol)
3243 && (pool->literals[entry].X_op_symbol
3244 == inst.reloc.exp.X_op_symbol)
3245 && (pool->literals[entry].X_md == nbytes))
3246 break;
3247 }
3248 else if ((nbytes == 8)
3249 && !(pool_size & 0x7)
3250 && ((entry + 1) != pool->next_free_entry)
3251 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3252 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3253 && (pool->literals[entry].X_unsigned
3254 == inst.reloc.exp.X_unsigned)
3255 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3256 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3257 && (pool->literals[entry + 1].X_unsigned
3258 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3259 break;
3260
8335d6aa
JW
3261 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3262 if (padding_slot_p && (nbytes == 4))
c19d1205 3263 break;
8335d6aa
JW
3264
3265 pool_size += 4;
b99bd4ef
NC
3266 }
3267
c19d1205
ZW
3268 /* Do we need to create a new entry? */
3269 if (entry == pool->next_free_entry)
3270 {
3271 if (entry >= MAX_LITERAL_POOL_SIZE)
3272 {
3273 inst.error = _("literal pool overflow");
3274 return FAIL;
3275 }
3276
8335d6aa
JW
3277 if (nbytes == 8)
3278 {
3279 /* For 8-byte entries, we align to an 8-byte boundary,
3280 and split it into two 4-byte entries, because on 32-bit
3281 host, 8-byte constants are treated as big num, thus
3282 saved in "generic_bignum" which will be overwritten
3283 by later assignments.
3284
3285 We also need to make sure there is enough space for
3286 the split.
3287
3288 We also check to make sure the literal operand is a
3289 constant number. */
19f2f6a9
JW
3290 if (!(inst.reloc.exp.X_op == O_constant
3291 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3292 {
3293 inst.error = _("invalid type for literal pool");
3294 return FAIL;
3295 }
3296 else if (pool_size & 0x7)
3297 {
3298 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3299 {
3300 inst.error = _("literal pool overflow");
3301 return FAIL;
3302 }
3303
3304 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3305 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3306 pool->literals[entry].X_add_number = 0;
3307 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3308 pool->next_free_entry += 1;
3309 pool_size += 4;
3310 }
3311 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3312 {
3313 inst.error = _("literal pool overflow");
3314 return FAIL;
3315 }
3316
3317 pool->literals[entry] = inst.reloc.exp;
3318 pool->literals[entry].X_op = O_constant;
3319 pool->literals[entry].X_add_number = imm1;
3320 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3321 pool->literals[entry++].X_md = 4;
3322 pool->literals[entry] = inst.reloc.exp;
3323 pool->literals[entry].X_op = O_constant;
3324 pool->literals[entry].X_add_number = imm2;
3325 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3326 pool->literals[entry].X_md = 4;
3327 pool->alignment = 3;
3328 pool->next_free_entry += 1;
3329 }
3330 else
3331 {
3332 pool->literals[entry] = inst.reloc.exp;
3333 pool->literals[entry].X_md = 4;
3334 }
3335
a8040cf2
NC
3336#ifdef OBJ_ELF
3337 /* PR ld/12974: Record the location of the first source line to reference
3338 this entry in the literal pool. If it turns out during linking that the
3339 symbol does not exist we will be able to give an accurate line number for
3340 the (first use of the) missing reference. */
3341 if (debug_type == DEBUG_DWARF2)
3342 dwarf2_where (pool->locs + entry);
3343#endif
c19d1205
ZW
3344 pool->next_free_entry += 1;
3345 }
8335d6aa
JW
3346 else if (padding_slot_p)
3347 {
3348 pool->literals[entry] = inst.reloc.exp;
3349 pool->literals[entry].X_md = nbytes;
3350 }
b99bd4ef 3351
c19d1205 3352 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3353 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3354 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3355
c19d1205 3356 return SUCCESS;
b99bd4ef
NC
3357}
3358
2e6976a8 3359bfd_boolean
2e57ce7b 3360tc_start_label_without_colon (void)
2e6976a8
DG
3361{
3362 bfd_boolean ret = TRUE;
3363
3364 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3365 {
2e57ce7b 3366 const char *label = input_line_pointer;
2e6976a8
DG
3367
3368 while (!is_end_of_line[(int) label[-1]])
3369 --label;
3370
3371 if (*label == '.')
3372 {
3373 as_bad (_("Invalid label '%s'"), label);
3374 ret = FALSE;
3375 }
3376
3377 asmfunc_debug (label);
3378
3379 asmfunc_state = WAITING_ENDASMFUNC;
3380 }
3381
3382 return ret;
3383}
3384
c19d1205 3385/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3386 a later date assign it a value. That's what these functions do. */
e16bb312 3387
c19d1205
ZW
3388static void
3389symbol_locate (symbolS * symbolP,
3390 const char * name, /* It is copied, the caller can modify. */
3391 segT segment, /* Segment identifier (SEG_<something>). */
3392 valueT valu, /* Symbol value. */
3393 fragS * frag) /* Associated fragment. */
3394{
e57e6ddc 3395 size_t name_length;
c19d1205 3396 char * preserved_copy_of_name;
e16bb312 3397
c19d1205
ZW
3398 name_length = strlen (name) + 1; /* +1 for \0. */
3399 obstack_grow (&notes, name, name_length);
21d799b5 3400 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3401
c19d1205
ZW
3402#ifdef tc_canonicalize_symbol_name
3403 preserved_copy_of_name =
3404 tc_canonicalize_symbol_name (preserved_copy_of_name);
3405#endif
b99bd4ef 3406
c19d1205 3407 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3408
c19d1205
ZW
3409 S_SET_SEGMENT (symbolP, segment);
3410 S_SET_VALUE (symbolP, valu);
3411 symbol_clear_list_pointers (symbolP);
b99bd4ef 3412
c19d1205 3413 symbol_set_frag (symbolP, frag);
b99bd4ef 3414
c19d1205
ZW
3415 /* Link to end of symbol chain. */
3416 {
3417 extern int symbol_table_frozen;
b99bd4ef 3418
c19d1205
ZW
3419 if (symbol_table_frozen)
3420 abort ();
3421 }
b99bd4ef 3422
c19d1205 3423 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3424
c19d1205 3425 obj_symbol_new_hook (symbolP);
b99bd4ef 3426
c19d1205
ZW
3427#ifdef tc_symbol_new_hook
3428 tc_symbol_new_hook (symbolP);
3429#endif
3430
3431#ifdef DEBUG_SYMS
3432 verify_symbol_chain (symbol_rootP, symbol_lastP);
3433#endif /* DEBUG_SYMS */
b99bd4ef
NC
3434}
3435
c19d1205
ZW
3436static void
3437s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3438{
c19d1205
ZW
3439 unsigned int entry;
3440 literal_pool * pool;
3441 char sym_name[20];
b99bd4ef 3442
c19d1205
ZW
3443 pool = find_literal_pool ();
3444 if (pool == NULL
3445 || pool->symbol == NULL
3446 || pool->next_free_entry == 0)
3447 return;
b99bd4ef 3448
c19d1205
ZW
3449 /* Align pool as you have word accesses.
3450 Only make a frag if we have to. */
3451 if (!need_pass_2)
8335d6aa 3452 frag_align (pool->alignment, 0, 0);
b99bd4ef 3453
c19d1205 3454 record_alignment (now_seg, 2);
b99bd4ef 3455
aaca88ef 3456#ifdef OBJ_ELF
47fc6e36
WN
3457 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3458 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3459#endif
c19d1205 3460 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3461
c19d1205
ZW
3462 symbol_locate (pool->symbol, sym_name, now_seg,
3463 (valueT) frag_now_fix (), frag_now);
3464 symbol_table_insert (pool->symbol);
b99bd4ef 3465
c19d1205 3466 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3467
c19d1205
ZW
3468#if defined OBJ_COFF || defined OBJ_ELF
3469 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3470#endif
6c43fab6 3471
c19d1205 3472 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3473 {
3474#ifdef OBJ_ELF
3475 if (debug_type == DEBUG_DWARF2)
3476 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3477#endif
3478 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3479 emit_expr (&(pool->literals[entry]),
3480 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3481 }
b99bd4ef 3482
c19d1205
ZW
3483 /* Mark the pool as empty. */
3484 pool->next_free_entry = 0;
3485 pool->symbol = NULL;
b99bd4ef
NC
3486}
3487
c19d1205
ZW
3488#ifdef OBJ_ELF
3489/* Forward declarations for functions below, in the MD interface
3490 section. */
3491static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3492static valueT create_unwind_entry (int);
3493static void start_unwind_section (const segT, int);
3494static void add_unwind_opcode (valueT, int);
3495static void flush_pending_unwind (void);
b99bd4ef 3496
c19d1205 3497/* Directives: Data. */
b99bd4ef 3498
c19d1205
ZW
3499static void
3500s_arm_elf_cons (int nbytes)
3501{
3502 expressionS exp;
b99bd4ef 3503
c19d1205
ZW
3504#ifdef md_flush_pending_output
3505 md_flush_pending_output ();
3506#endif
b99bd4ef 3507
c19d1205 3508 if (is_it_end_of_statement ())
b99bd4ef 3509 {
c19d1205
ZW
3510 demand_empty_rest_of_line ();
3511 return;
b99bd4ef
NC
3512 }
3513
c19d1205
ZW
3514#ifdef md_cons_align
3515 md_cons_align (nbytes);
3516#endif
b99bd4ef 3517
c19d1205
ZW
3518 mapping_state (MAP_DATA);
3519 do
b99bd4ef 3520 {
c19d1205
ZW
3521 int reloc;
3522 char *base = input_line_pointer;
b99bd4ef 3523
c19d1205 3524 expression (& exp);
b99bd4ef 3525
c19d1205
ZW
3526 if (exp.X_op != O_symbol)
3527 emit_expr (&exp, (unsigned int) nbytes);
3528 else
3529 {
3530 char *before_reloc = input_line_pointer;
3531 reloc = parse_reloc (&input_line_pointer);
3532 if (reloc == -1)
3533 {
3534 as_bad (_("unrecognized relocation suffix"));
3535 ignore_rest_of_line ();
3536 return;
3537 }
3538 else if (reloc == BFD_RELOC_UNUSED)
3539 emit_expr (&exp, (unsigned int) nbytes);
3540 else
3541 {
21d799b5 3542 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3543 bfd_reloc_type_lookup (stdoutput,
3544 (bfd_reloc_code_real_type) reloc);
c19d1205 3545 int size = bfd_get_reloc_size (howto);
b99bd4ef 3546
2fc8bdac
ZW
3547 if (reloc == BFD_RELOC_ARM_PLT32)
3548 {
3549 as_bad (_("(plt) is only valid on branch targets"));
3550 reloc = BFD_RELOC_UNUSED;
3551 size = 0;
3552 }
3553
c19d1205 3554 if (size > nbytes)
2fc8bdac 3555 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3556 howto->name, nbytes);
3557 else
3558 {
3559 /* We've parsed an expression stopping at O_symbol.
3560 But there may be more expression left now that we
3561 have parsed the relocation marker. Parse it again.
3562 XXX Surely there is a cleaner way to do this. */
3563 char *p = input_line_pointer;
3564 int offset;
325801bd 3565 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3566
c19d1205
ZW
3567 memcpy (save_buf, base, input_line_pointer - base);
3568 memmove (base + (input_line_pointer - before_reloc),
3569 base, before_reloc - base);
3570
3571 input_line_pointer = base + (input_line_pointer-before_reloc);
3572 expression (&exp);
3573 memcpy (base, save_buf, p - base);
3574
3575 offset = nbytes - size;
4b1a927e
AM
3576 p = frag_more (nbytes);
3577 memset (p, 0, nbytes);
c19d1205 3578 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3579 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3580 free (save_buf);
c19d1205
ZW
3581 }
3582 }
3583 }
b99bd4ef 3584 }
c19d1205 3585 while (*input_line_pointer++ == ',');
b99bd4ef 3586
c19d1205
ZW
3587 /* Put terminator back into stream. */
3588 input_line_pointer --;
3589 demand_empty_rest_of_line ();
b99bd4ef
NC
3590}
3591
c921be7d
NC
3592/* Emit an expression containing a 32-bit thumb instruction.
3593 Implementation based on put_thumb32_insn. */
3594
3595static void
3596emit_thumb32_expr (expressionS * exp)
3597{
3598 expressionS exp_high = *exp;
3599
3600 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3601 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3602 exp->X_add_number &= 0xffff;
3603 emit_expr (exp, (unsigned int) THUMB_SIZE);
3604}
3605
3606/* Guess the instruction size based on the opcode. */
3607
3608static int
3609thumb_insn_size (int opcode)
3610{
3611 if ((unsigned int) opcode < 0xe800u)
3612 return 2;
3613 else if ((unsigned int) opcode >= 0xe8000000u)
3614 return 4;
3615 else
3616 return 0;
3617}
3618
3619static bfd_boolean
3620emit_insn (expressionS *exp, int nbytes)
3621{
3622 int size = 0;
3623
3624 if (exp->X_op == O_constant)
3625 {
3626 size = nbytes;
3627
3628 if (size == 0)
3629 size = thumb_insn_size (exp->X_add_number);
3630
3631 if (size != 0)
3632 {
3633 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3634 {
3635 as_bad (_(".inst.n operand too big. "\
3636 "Use .inst.w instead"));
3637 size = 0;
3638 }
3639 else
3640 {
3641 if (now_it.state == AUTOMATIC_IT_BLOCK)
3642 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3643 else
3644 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3645
3646 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3647 emit_thumb32_expr (exp);
3648 else
3649 emit_expr (exp, (unsigned int) size);
3650
3651 it_fsm_post_encode ();
3652 }
3653 }
3654 else
3655 as_bad (_("cannot determine Thumb instruction size. " \
3656 "Use .inst.n/.inst.w instead"));
3657 }
3658 else
3659 as_bad (_("constant expression required"));
3660
3661 return (size != 0);
3662}
3663
3664/* Like s_arm_elf_cons but do not use md_cons_align and
3665 set the mapping state to MAP_ARM/MAP_THUMB. */
3666
3667static void
3668s_arm_elf_inst (int nbytes)
3669{
3670 if (is_it_end_of_statement ())
3671 {
3672 demand_empty_rest_of_line ();
3673 return;
3674 }
3675
3676 /* Calling mapping_state () here will not change ARM/THUMB,
3677 but will ensure not to be in DATA state. */
3678
3679 if (thumb_mode)
3680 mapping_state (MAP_THUMB);
3681 else
3682 {
3683 if (nbytes != 0)
3684 {
3685 as_bad (_("width suffixes are invalid in ARM mode"));
3686 ignore_rest_of_line ();
3687 return;
3688 }
3689
3690 nbytes = 4;
3691
3692 mapping_state (MAP_ARM);
3693 }
3694
3695 do
3696 {
3697 expressionS exp;
3698
3699 expression (& exp);
3700
3701 if (! emit_insn (& exp, nbytes))
3702 {
3703 ignore_rest_of_line ();
3704 return;
3705 }
3706 }
3707 while (*input_line_pointer++ == ',');
3708
3709 /* Put terminator back into stream. */
3710 input_line_pointer --;
3711 demand_empty_rest_of_line ();
3712}
b99bd4ef 3713
c19d1205 3714/* Parse a .rel31 directive. */
b99bd4ef 3715
c19d1205
ZW
3716static void
3717s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3718{
3719 expressionS exp;
3720 char *p;
3721 valueT highbit;
b99bd4ef 3722
c19d1205
ZW
3723 highbit = 0;
3724 if (*input_line_pointer == '1')
3725 highbit = 0x80000000;
3726 else if (*input_line_pointer != '0')
3727 as_bad (_("expected 0 or 1"));
b99bd4ef 3728
c19d1205
ZW
3729 input_line_pointer++;
3730 if (*input_line_pointer != ',')
3731 as_bad (_("missing comma"));
3732 input_line_pointer++;
b99bd4ef 3733
c19d1205
ZW
3734#ifdef md_flush_pending_output
3735 md_flush_pending_output ();
3736#endif
b99bd4ef 3737
c19d1205
ZW
3738#ifdef md_cons_align
3739 md_cons_align (4);
3740#endif
b99bd4ef 3741
c19d1205 3742 mapping_state (MAP_DATA);
b99bd4ef 3743
c19d1205 3744 expression (&exp);
b99bd4ef 3745
c19d1205
ZW
3746 p = frag_more (4);
3747 md_number_to_chars (p, highbit, 4);
3748 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3749 BFD_RELOC_ARM_PREL31);
b99bd4ef 3750
c19d1205 3751 demand_empty_rest_of_line ();
b99bd4ef
NC
3752}
3753
c19d1205 3754/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3755
c19d1205 3756/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3757
c19d1205
ZW
3758static void
3759s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3760{
3761 demand_empty_rest_of_line ();
921e5f0a
PB
3762 if (unwind.proc_start)
3763 {
c921be7d 3764 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3765 return;
3766 }
3767
c19d1205
ZW
3768 /* Mark the start of the function. */
3769 unwind.proc_start = expr_build_dot ();
b99bd4ef 3770
c19d1205
ZW
3771 /* Reset the rest of the unwind info. */
3772 unwind.opcode_count = 0;
3773 unwind.table_entry = NULL;
3774 unwind.personality_routine = NULL;
3775 unwind.personality_index = -1;
3776 unwind.frame_size = 0;
3777 unwind.fp_offset = 0;
fdfde340 3778 unwind.fp_reg = REG_SP;
c19d1205
ZW
3779 unwind.fp_used = 0;
3780 unwind.sp_restored = 0;
3781}
b99bd4ef 3782
b99bd4ef 3783
c19d1205
ZW
3784/* Parse a handlerdata directive. Creates the exception handling table entry
3785 for the function. */
b99bd4ef 3786
c19d1205
ZW
3787static void
3788s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3789{
3790 demand_empty_rest_of_line ();
921e5f0a 3791 if (!unwind.proc_start)
c921be7d 3792 as_bad (MISSING_FNSTART);
921e5f0a 3793
c19d1205 3794 if (unwind.table_entry)
6decc662 3795 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3796
c19d1205
ZW
3797 create_unwind_entry (1);
3798}
a737bd4d 3799
c19d1205 3800/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3801
c19d1205
ZW
3802static void
3803s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3804{
3805 long where;
3806 char *ptr;
3807 valueT val;
940b5ce0 3808 unsigned int marked_pr_dependency;
f02232aa 3809
c19d1205 3810 demand_empty_rest_of_line ();
f02232aa 3811
921e5f0a
PB
3812 if (!unwind.proc_start)
3813 {
c921be7d 3814 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3815 return;
3816 }
3817
c19d1205
ZW
3818 /* Add eh table entry. */
3819 if (unwind.table_entry == NULL)
3820 val = create_unwind_entry (0);
3821 else
3822 val = 0;
f02232aa 3823
c19d1205
ZW
3824 /* Add index table entry. This is two words. */
3825 start_unwind_section (unwind.saved_seg, 1);
3826 frag_align (2, 0, 0);
3827 record_alignment (now_seg, 2);
b99bd4ef 3828
c19d1205 3829 ptr = frag_more (8);
5011093d 3830 memset (ptr, 0, 8);
c19d1205 3831 where = frag_now_fix () - 8;
f02232aa 3832
c19d1205
ZW
3833 /* Self relative offset of the function start. */
3834 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3835 BFD_RELOC_ARM_PREL31);
f02232aa 3836
c19d1205
ZW
3837 /* Indicate dependency on EHABI-defined personality routines to the
3838 linker, if it hasn't been done already. */
940b5ce0
DJ
3839 marked_pr_dependency
3840 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3841 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3842 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3843 {
5f4273c7
NC
3844 static const char *const name[] =
3845 {
3846 "__aeabi_unwind_cpp_pr0",
3847 "__aeabi_unwind_cpp_pr1",
3848 "__aeabi_unwind_cpp_pr2"
3849 };
c19d1205
ZW
3850 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3851 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3852 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3853 |= 1 << unwind.personality_index;
c19d1205 3854 }
f02232aa 3855
c19d1205
ZW
3856 if (val)
3857 /* Inline exception table entry. */
3858 md_number_to_chars (ptr + 4, val, 4);
3859 else
3860 /* Self relative offset of the table entry. */
3861 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3862 BFD_RELOC_ARM_PREL31);
f02232aa 3863
c19d1205
ZW
3864 /* Restore the original section. */
3865 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3866
3867 unwind.proc_start = NULL;
c19d1205 3868}
f02232aa 3869
f02232aa 3870
c19d1205 3871/* Parse an unwind_cantunwind directive. */
b99bd4ef 3872
c19d1205
ZW
3873static void
3874s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3875{
3876 demand_empty_rest_of_line ();
921e5f0a 3877 if (!unwind.proc_start)
c921be7d 3878 as_bad (MISSING_FNSTART);
921e5f0a 3879
c19d1205
ZW
3880 if (unwind.personality_routine || unwind.personality_index != -1)
3881 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3882
c19d1205
ZW
3883 unwind.personality_index = -2;
3884}
b99bd4ef 3885
b99bd4ef 3886
c19d1205 3887/* Parse a personalityindex directive. */
b99bd4ef 3888
c19d1205
ZW
3889static void
3890s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3891{
3892 expressionS exp;
b99bd4ef 3893
921e5f0a 3894 if (!unwind.proc_start)
c921be7d 3895 as_bad (MISSING_FNSTART);
921e5f0a 3896
c19d1205
ZW
3897 if (unwind.personality_routine || unwind.personality_index != -1)
3898 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3899
c19d1205 3900 expression (&exp);
b99bd4ef 3901
c19d1205
ZW
3902 if (exp.X_op != O_constant
3903 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3904 {
c19d1205
ZW
3905 as_bad (_("bad personality routine number"));
3906 ignore_rest_of_line ();
3907 return;
b99bd4ef
NC
3908 }
3909
c19d1205 3910 unwind.personality_index = exp.X_add_number;
b99bd4ef 3911
c19d1205
ZW
3912 demand_empty_rest_of_line ();
3913}
e16bb312 3914
e16bb312 3915
c19d1205 3916/* Parse a personality directive. */
e16bb312 3917
c19d1205
ZW
3918static void
3919s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3920{
3921 char *name, *p, c;
a737bd4d 3922
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 (_("duplicate .personality directive"));
a737bd4d 3928
d02603dc 3929 c = get_symbol_name (& name);
c19d1205 3930 p = input_line_pointer;
d02603dc
NC
3931 if (c == '"')
3932 ++ input_line_pointer;
c19d1205
ZW
3933 unwind.personality_routine = symbol_find_or_make (name);
3934 *p = c;
3935 demand_empty_rest_of_line ();
3936}
e16bb312 3937
e16bb312 3938
c19d1205 3939/* Parse a directive saving core registers. */
e16bb312 3940
c19d1205
ZW
3941static void
3942s_arm_unwind_save_core (void)
e16bb312 3943{
c19d1205
ZW
3944 valueT op;
3945 long range;
3946 int n;
e16bb312 3947
c19d1205
ZW
3948 range = parse_reg_list (&input_line_pointer);
3949 if (range == FAIL)
e16bb312 3950 {
c19d1205
ZW
3951 as_bad (_("expected register list"));
3952 ignore_rest_of_line ();
3953 return;
3954 }
e16bb312 3955
c19d1205 3956 demand_empty_rest_of_line ();
e16bb312 3957
c19d1205
ZW
3958 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3959 into .unwind_save {..., sp...}. We aren't bothered about the value of
3960 ip because it is clobbered by calls. */
3961 if (unwind.sp_restored && unwind.fp_reg == 12
3962 && (range & 0x3000) == 0x1000)
3963 {
3964 unwind.opcode_count--;
3965 unwind.sp_restored = 0;
3966 range = (range | 0x2000) & ~0x1000;
3967 unwind.pending_offset = 0;
3968 }
e16bb312 3969
01ae4198
DJ
3970 /* Pop r4-r15. */
3971 if (range & 0xfff0)
c19d1205 3972 {
01ae4198
DJ
3973 /* See if we can use the short opcodes. These pop a block of up to 8
3974 registers starting with r4, plus maybe r14. */
3975 for (n = 0; n < 8; n++)
3976 {
3977 /* Break at the first non-saved register. */
3978 if ((range & (1 << (n + 4))) == 0)
3979 break;
3980 }
3981 /* See if there are any other bits set. */
3982 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3983 {
3984 /* Use the long form. */
3985 op = 0x8000 | ((range >> 4) & 0xfff);
3986 add_unwind_opcode (op, 2);
3987 }
0dd132b6 3988 else
01ae4198
DJ
3989 {
3990 /* Use the short form. */
3991 if (range & 0x4000)
3992 op = 0xa8; /* Pop r14. */
3993 else
3994 op = 0xa0; /* Do not pop r14. */
3995 op |= (n - 1);
3996 add_unwind_opcode (op, 1);
3997 }
c19d1205 3998 }
0dd132b6 3999
c19d1205
ZW
4000 /* Pop r0-r3. */
4001 if (range & 0xf)
4002 {
4003 op = 0xb100 | (range & 0xf);
4004 add_unwind_opcode (op, 2);
0dd132b6
NC
4005 }
4006
c19d1205
ZW
4007 /* Record the number of bytes pushed. */
4008 for (n = 0; n < 16; n++)
4009 {
4010 if (range & (1 << n))
4011 unwind.frame_size += 4;
4012 }
0dd132b6
NC
4013}
4014
c19d1205
ZW
4015
4016/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4017
4018static void
c19d1205 4019s_arm_unwind_save_fpa (int reg)
b99bd4ef 4020{
c19d1205
ZW
4021 expressionS exp;
4022 int num_regs;
4023 valueT op;
b99bd4ef 4024
c19d1205
ZW
4025 /* Get Number of registers to transfer. */
4026 if (skip_past_comma (&input_line_pointer) != FAIL)
4027 expression (&exp);
4028 else
4029 exp.X_op = O_illegal;
b99bd4ef 4030
c19d1205 4031 if (exp.X_op != O_constant)
b99bd4ef 4032 {
c19d1205
ZW
4033 as_bad (_("expected , <constant>"));
4034 ignore_rest_of_line ();
b99bd4ef
NC
4035 return;
4036 }
4037
c19d1205
ZW
4038 num_regs = exp.X_add_number;
4039
4040 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4041 {
c19d1205
ZW
4042 as_bad (_("number of registers must be in the range [1:4]"));
4043 ignore_rest_of_line ();
b99bd4ef
NC
4044 return;
4045 }
4046
c19d1205 4047 demand_empty_rest_of_line ();
b99bd4ef 4048
c19d1205
ZW
4049 if (reg == 4)
4050 {
4051 /* Short form. */
4052 op = 0xb4 | (num_regs - 1);
4053 add_unwind_opcode (op, 1);
4054 }
b99bd4ef
NC
4055 else
4056 {
c19d1205
ZW
4057 /* Long form. */
4058 op = 0xc800 | (reg << 4) | (num_regs - 1);
4059 add_unwind_opcode (op, 2);
b99bd4ef 4060 }
c19d1205 4061 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4062}
4063
c19d1205 4064
fa073d69
MS
4065/* Parse a directive saving VFP registers for ARMv6 and above. */
4066
4067static void
4068s_arm_unwind_save_vfp_armv6 (void)
4069{
4070 int count;
4071 unsigned int start;
4072 valueT op;
4073 int num_vfpv3_regs = 0;
4074 int num_regs_below_16;
4075
4076 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4077 if (count == FAIL)
4078 {
4079 as_bad (_("expected register list"));
4080 ignore_rest_of_line ();
4081 return;
4082 }
4083
4084 demand_empty_rest_of_line ();
4085
4086 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4087 than FSTMX/FLDMX-style ones). */
4088
4089 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4090 if (start >= 16)
4091 num_vfpv3_regs = count;
4092 else if (start + count > 16)
4093 num_vfpv3_regs = start + count - 16;
4094
4095 if (num_vfpv3_regs > 0)
4096 {
4097 int start_offset = start > 16 ? start - 16 : 0;
4098 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4099 add_unwind_opcode (op, 2);
4100 }
4101
4102 /* Generate opcode for registers numbered in the range 0 .. 15. */
4103 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4104 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4105 if (num_regs_below_16 > 0)
4106 {
4107 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4108 add_unwind_opcode (op, 2);
4109 }
4110
4111 unwind.frame_size += count * 8;
4112}
4113
4114
4115/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4116
4117static void
c19d1205 4118s_arm_unwind_save_vfp (void)
b99bd4ef 4119{
c19d1205 4120 int count;
ca3f61f7 4121 unsigned int reg;
c19d1205 4122 valueT op;
b99bd4ef 4123
5287ad62 4124 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4125 if (count == FAIL)
b99bd4ef 4126 {
c19d1205
ZW
4127 as_bad (_("expected register list"));
4128 ignore_rest_of_line ();
b99bd4ef
NC
4129 return;
4130 }
4131
c19d1205 4132 demand_empty_rest_of_line ();
b99bd4ef 4133
c19d1205 4134 if (reg == 8)
b99bd4ef 4135 {
c19d1205
ZW
4136 /* Short form. */
4137 op = 0xb8 | (count - 1);
4138 add_unwind_opcode (op, 1);
b99bd4ef 4139 }
c19d1205 4140 else
b99bd4ef 4141 {
c19d1205
ZW
4142 /* Long form. */
4143 op = 0xb300 | (reg << 4) | (count - 1);
4144 add_unwind_opcode (op, 2);
b99bd4ef 4145 }
c19d1205
ZW
4146 unwind.frame_size += count * 8 + 4;
4147}
b99bd4ef 4148
b99bd4ef 4149
c19d1205
ZW
4150/* Parse a directive saving iWMMXt data registers. */
4151
4152static void
4153s_arm_unwind_save_mmxwr (void)
4154{
4155 int reg;
4156 int hi_reg;
4157 int i;
4158 unsigned mask = 0;
4159 valueT op;
b99bd4ef 4160
c19d1205
ZW
4161 if (*input_line_pointer == '{')
4162 input_line_pointer++;
b99bd4ef 4163
c19d1205 4164 do
b99bd4ef 4165 {
dcbf9037 4166 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4167
c19d1205 4168 if (reg == FAIL)
b99bd4ef 4169 {
9b7132d3 4170 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4171 goto error;
b99bd4ef
NC
4172 }
4173
c19d1205
ZW
4174 if (mask >> reg)
4175 as_tsktsk (_("register list not in ascending order"));
4176 mask |= 1 << reg;
b99bd4ef 4177
c19d1205
ZW
4178 if (*input_line_pointer == '-')
4179 {
4180 input_line_pointer++;
dcbf9037 4181 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4182 if (hi_reg == FAIL)
4183 {
9b7132d3 4184 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4185 goto error;
4186 }
4187 else if (reg >= hi_reg)
4188 {
4189 as_bad (_("bad register range"));
4190 goto error;
4191 }
4192 for (; reg < hi_reg; reg++)
4193 mask |= 1 << reg;
4194 }
4195 }
4196 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4197
d996d970 4198 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4199
c19d1205 4200 demand_empty_rest_of_line ();
b99bd4ef 4201
708587a4 4202 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4203 the list. */
4204 flush_pending_unwind ();
b99bd4ef 4205
c19d1205 4206 for (i = 0; i < 16; i++)
b99bd4ef 4207 {
c19d1205
ZW
4208 if (mask & (1 << i))
4209 unwind.frame_size += 8;
b99bd4ef
NC
4210 }
4211
c19d1205
ZW
4212 /* Attempt to combine with a previous opcode. We do this because gcc
4213 likes to output separate unwind directives for a single block of
4214 registers. */
4215 if (unwind.opcode_count > 0)
b99bd4ef 4216 {
c19d1205
ZW
4217 i = unwind.opcodes[unwind.opcode_count - 1];
4218 if ((i & 0xf8) == 0xc0)
4219 {
4220 i &= 7;
4221 /* Only merge if the blocks are contiguous. */
4222 if (i < 6)
4223 {
4224 if ((mask & 0xfe00) == (1 << 9))
4225 {
4226 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4227 unwind.opcode_count--;
4228 }
4229 }
4230 else if (i == 6 && unwind.opcode_count >= 2)
4231 {
4232 i = unwind.opcodes[unwind.opcode_count - 2];
4233 reg = i >> 4;
4234 i &= 0xf;
b99bd4ef 4235
c19d1205
ZW
4236 op = 0xffff << (reg - 1);
4237 if (reg > 0
87a1fd79 4238 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4239 {
4240 op = (1 << (reg + i + 1)) - 1;
4241 op &= ~((1 << reg) - 1);
4242 mask |= op;
4243 unwind.opcode_count -= 2;
4244 }
4245 }
4246 }
b99bd4ef
NC
4247 }
4248
c19d1205
ZW
4249 hi_reg = 15;
4250 /* We want to generate opcodes in the order the registers have been
4251 saved, ie. descending order. */
4252 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4253 {
c19d1205
ZW
4254 /* Save registers in blocks. */
4255 if (reg < 0
4256 || !(mask & (1 << reg)))
4257 {
4258 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4259 preceding block. */
c19d1205
ZW
4260 if (reg != hi_reg)
4261 {
4262 if (reg == 9)
4263 {
4264 /* Short form. */
4265 op = 0xc0 | (hi_reg - 10);
4266 add_unwind_opcode (op, 1);
4267 }
4268 else
4269 {
4270 /* Long form. */
4271 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4272 add_unwind_opcode (op, 2);
4273 }
4274 }
4275 hi_reg = reg - 1;
4276 }
b99bd4ef
NC
4277 }
4278
c19d1205
ZW
4279 return;
4280error:
4281 ignore_rest_of_line ();
b99bd4ef
NC
4282}
4283
4284static void
c19d1205 4285s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4286{
c19d1205
ZW
4287 int reg;
4288 int hi_reg;
4289 unsigned mask = 0;
4290 valueT op;
b99bd4ef 4291
c19d1205
ZW
4292 if (*input_line_pointer == '{')
4293 input_line_pointer++;
b99bd4ef 4294
477330fc
RM
4295 skip_whitespace (input_line_pointer);
4296
c19d1205 4297 do
b99bd4ef 4298 {
dcbf9037 4299 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4300
c19d1205
ZW
4301 if (reg == FAIL)
4302 {
9b7132d3 4303 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4304 goto error;
4305 }
b99bd4ef 4306
c19d1205
ZW
4307 reg -= 8;
4308 if (mask >> reg)
4309 as_tsktsk (_("register list not in ascending order"));
4310 mask |= 1 << reg;
b99bd4ef 4311
c19d1205
ZW
4312 if (*input_line_pointer == '-')
4313 {
4314 input_line_pointer++;
dcbf9037 4315 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4316 if (hi_reg == FAIL)
4317 {
9b7132d3 4318 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4319 goto error;
4320 }
4321 else if (reg >= hi_reg)
4322 {
4323 as_bad (_("bad register range"));
4324 goto error;
4325 }
4326 for (; reg < hi_reg; reg++)
4327 mask |= 1 << reg;
4328 }
b99bd4ef 4329 }
c19d1205 4330 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4331
d996d970 4332 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4333
c19d1205
ZW
4334 demand_empty_rest_of_line ();
4335
708587a4 4336 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4337 the list. */
4338 flush_pending_unwind ();
b99bd4ef 4339
c19d1205 4340 for (reg = 0; reg < 16; reg++)
b99bd4ef 4341 {
c19d1205
ZW
4342 if (mask & (1 << reg))
4343 unwind.frame_size += 4;
b99bd4ef 4344 }
c19d1205
ZW
4345 op = 0xc700 | mask;
4346 add_unwind_opcode (op, 2);
4347 return;
4348error:
4349 ignore_rest_of_line ();
b99bd4ef
NC
4350}
4351
c19d1205 4352
fa073d69
MS
4353/* Parse an unwind_save directive.
4354 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4355
b99bd4ef 4356static void
fa073d69 4357s_arm_unwind_save (int arch_v6)
b99bd4ef 4358{
c19d1205
ZW
4359 char *peek;
4360 struct reg_entry *reg;
4361 bfd_boolean had_brace = FALSE;
b99bd4ef 4362
921e5f0a 4363 if (!unwind.proc_start)
c921be7d 4364 as_bad (MISSING_FNSTART);
921e5f0a 4365
c19d1205
ZW
4366 /* Figure out what sort of save we have. */
4367 peek = input_line_pointer;
b99bd4ef 4368
c19d1205 4369 if (*peek == '{')
b99bd4ef 4370 {
c19d1205
ZW
4371 had_brace = TRUE;
4372 peek++;
b99bd4ef
NC
4373 }
4374
c19d1205 4375 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4376
c19d1205 4377 if (!reg)
b99bd4ef 4378 {
c19d1205
ZW
4379 as_bad (_("register expected"));
4380 ignore_rest_of_line ();
b99bd4ef
NC
4381 return;
4382 }
4383
c19d1205 4384 switch (reg->type)
b99bd4ef 4385 {
c19d1205
ZW
4386 case REG_TYPE_FN:
4387 if (had_brace)
4388 {
4389 as_bad (_("FPA .unwind_save does not take a register list"));
4390 ignore_rest_of_line ();
4391 return;
4392 }
93ac2687 4393 input_line_pointer = peek;
c19d1205 4394 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4395 return;
c19d1205 4396
1f5afe1c
NC
4397 case REG_TYPE_RN:
4398 s_arm_unwind_save_core ();
4399 return;
4400
fa073d69
MS
4401 case REG_TYPE_VFD:
4402 if (arch_v6)
477330fc 4403 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4404 else
477330fc 4405 s_arm_unwind_save_vfp ();
fa073d69 4406 return;
1f5afe1c
NC
4407
4408 case REG_TYPE_MMXWR:
4409 s_arm_unwind_save_mmxwr ();
4410 return;
4411
4412 case REG_TYPE_MMXWCG:
4413 s_arm_unwind_save_mmxwcg ();
4414 return;
c19d1205
ZW
4415
4416 default:
4417 as_bad (_(".unwind_save does not support this kind of register"));
4418 ignore_rest_of_line ();
b99bd4ef 4419 }
c19d1205 4420}
b99bd4ef 4421
b99bd4ef 4422
c19d1205
ZW
4423/* Parse an unwind_movsp directive. */
4424
4425static void
4426s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4427{
4428 int reg;
4429 valueT op;
4fa3602b 4430 int offset;
c19d1205 4431
921e5f0a 4432 if (!unwind.proc_start)
c921be7d 4433 as_bad (MISSING_FNSTART);
921e5f0a 4434
dcbf9037 4435 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4436 if (reg == FAIL)
b99bd4ef 4437 {
9b7132d3 4438 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4439 ignore_rest_of_line ();
b99bd4ef
NC
4440 return;
4441 }
4fa3602b
PB
4442
4443 /* Optional constant. */
4444 if (skip_past_comma (&input_line_pointer) != FAIL)
4445 {
4446 if (immediate_for_directive (&offset) == FAIL)
4447 return;
4448 }
4449 else
4450 offset = 0;
4451
c19d1205 4452 demand_empty_rest_of_line ();
b99bd4ef 4453
c19d1205 4454 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4455 {
c19d1205 4456 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4457 return;
4458 }
4459
c19d1205
ZW
4460 if (unwind.fp_reg != REG_SP)
4461 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4462
c19d1205
ZW
4463 /* Generate opcode to restore the value. */
4464 op = 0x90 | reg;
4465 add_unwind_opcode (op, 1);
4466
4467 /* Record the information for later. */
4468 unwind.fp_reg = reg;
4fa3602b 4469 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4470 unwind.sp_restored = 1;
b05fe5cf
ZW
4471}
4472
c19d1205
ZW
4473/* Parse an unwind_pad directive. */
4474
b05fe5cf 4475static void
c19d1205 4476s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4477{
c19d1205 4478 int offset;
b05fe5cf 4479
921e5f0a 4480 if (!unwind.proc_start)
c921be7d 4481 as_bad (MISSING_FNSTART);
921e5f0a 4482
c19d1205
ZW
4483 if (immediate_for_directive (&offset) == FAIL)
4484 return;
b99bd4ef 4485
c19d1205
ZW
4486 if (offset & 3)
4487 {
4488 as_bad (_("stack increment must be multiple of 4"));
4489 ignore_rest_of_line ();
4490 return;
4491 }
b99bd4ef 4492
c19d1205
ZW
4493 /* Don't generate any opcodes, just record the details for later. */
4494 unwind.frame_size += offset;
4495 unwind.pending_offset += offset;
4496
4497 demand_empty_rest_of_line ();
4498}
4499
4500/* Parse an unwind_setfp directive. */
4501
4502static void
4503s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4504{
c19d1205
ZW
4505 int sp_reg;
4506 int fp_reg;
4507 int offset;
4508
921e5f0a 4509 if (!unwind.proc_start)
c921be7d 4510 as_bad (MISSING_FNSTART);
921e5f0a 4511
dcbf9037 4512 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4513 if (skip_past_comma (&input_line_pointer) == FAIL)
4514 sp_reg = FAIL;
4515 else
dcbf9037 4516 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4517
c19d1205
ZW
4518 if (fp_reg == FAIL || sp_reg == FAIL)
4519 {
4520 as_bad (_("expected <reg>, <reg>"));
4521 ignore_rest_of_line ();
4522 return;
4523 }
b99bd4ef 4524
c19d1205
ZW
4525 /* Optional constant. */
4526 if (skip_past_comma (&input_line_pointer) != FAIL)
4527 {
4528 if (immediate_for_directive (&offset) == FAIL)
4529 return;
4530 }
4531 else
4532 offset = 0;
a737bd4d 4533
c19d1205 4534 demand_empty_rest_of_line ();
a737bd4d 4535
fdfde340 4536 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4537 {
c19d1205
ZW
4538 as_bad (_("register must be either sp or set by a previous"
4539 "unwind_movsp directive"));
4540 return;
a737bd4d
NC
4541 }
4542
c19d1205
ZW
4543 /* Don't generate any opcodes, just record the information for later. */
4544 unwind.fp_reg = fp_reg;
4545 unwind.fp_used = 1;
fdfde340 4546 if (sp_reg == REG_SP)
c19d1205
ZW
4547 unwind.fp_offset = unwind.frame_size - offset;
4548 else
4549 unwind.fp_offset -= offset;
a737bd4d
NC
4550}
4551
c19d1205
ZW
4552/* Parse an unwind_raw directive. */
4553
4554static void
4555s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4556{
c19d1205 4557 expressionS exp;
708587a4 4558 /* This is an arbitrary limit. */
c19d1205
ZW
4559 unsigned char op[16];
4560 int count;
a737bd4d 4561
921e5f0a 4562 if (!unwind.proc_start)
c921be7d 4563 as_bad (MISSING_FNSTART);
921e5f0a 4564
c19d1205
ZW
4565 expression (&exp);
4566 if (exp.X_op == O_constant
4567 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4568 {
c19d1205
ZW
4569 unwind.frame_size += exp.X_add_number;
4570 expression (&exp);
4571 }
4572 else
4573 exp.X_op = O_illegal;
a737bd4d 4574
c19d1205
ZW
4575 if (exp.X_op != O_constant)
4576 {
4577 as_bad (_("expected <offset>, <opcode>"));
4578 ignore_rest_of_line ();
4579 return;
4580 }
a737bd4d 4581
c19d1205 4582 count = 0;
a737bd4d 4583
c19d1205
ZW
4584 /* Parse the opcode. */
4585 for (;;)
4586 {
4587 if (count >= 16)
4588 {
4589 as_bad (_("unwind opcode too long"));
4590 ignore_rest_of_line ();
a737bd4d 4591 }
c19d1205 4592 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4593 {
c19d1205
ZW
4594 as_bad (_("invalid unwind opcode"));
4595 ignore_rest_of_line ();
4596 return;
a737bd4d 4597 }
c19d1205 4598 op[count++] = exp.X_add_number;
a737bd4d 4599
c19d1205
ZW
4600 /* Parse the next byte. */
4601 if (skip_past_comma (&input_line_pointer) == FAIL)
4602 break;
a737bd4d 4603
c19d1205
ZW
4604 expression (&exp);
4605 }
b99bd4ef 4606
c19d1205
ZW
4607 /* Add the opcode bytes in reverse order. */
4608 while (count--)
4609 add_unwind_opcode (op[count], 1);
b99bd4ef 4610
c19d1205 4611 demand_empty_rest_of_line ();
b99bd4ef 4612}
ee065d83
PB
4613
4614
4615/* Parse a .eabi_attribute directive. */
4616
4617static void
4618s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4619{
0420f52b 4620 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4621
4622 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4623 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4624}
4625
0855e32b
NS
4626/* Emit a tls fix for the symbol. */
4627
4628static void
4629s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4630{
4631 char *p;
4632 expressionS exp;
4633#ifdef md_flush_pending_output
4634 md_flush_pending_output ();
4635#endif
4636
4637#ifdef md_cons_align
4638 md_cons_align (4);
4639#endif
4640
4641 /* Since we're just labelling the code, there's no need to define a
4642 mapping symbol. */
4643 expression (&exp);
4644 p = obstack_next_free (&frchain_now->frch_obstack);
4645 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4646 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4647 : BFD_RELOC_ARM_TLS_DESCSEQ);
4648}
cdf9ccec 4649#endif /* OBJ_ELF */
0855e32b 4650
ee065d83 4651static void s_arm_arch (int);
7a1d4c38 4652static void s_arm_object_arch (int);
ee065d83
PB
4653static void s_arm_cpu (int);
4654static void s_arm_fpu (int);
69133863 4655static void s_arm_arch_extension (int);
b99bd4ef 4656
f0927246
NC
4657#ifdef TE_PE
4658
4659static void
5f4273c7 4660pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4661{
4662 expressionS exp;
4663
4664 do
4665 {
4666 expression (&exp);
4667 if (exp.X_op == O_symbol)
4668 exp.X_op = O_secrel;
4669
4670 emit_expr (&exp, 4);
4671 }
4672 while (*input_line_pointer++ == ',');
4673
4674 input_line_pointer--;
4675 demand_empty_rest_of_line ();
4676}
4677#endif /* TE_PE */
4678
c19d1205
ZW
4679/* This table describes all the machine specific pseudo-ops the assembler
4680 has to support. The fields are:
4681 pseudo-op name without dot
4682 function to call to execute this pseudo-op
4683 Integer arg to pass to the function. */
b99bd4ef 4684
c19d1205 4685const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4686{
c19d1205
ZW
4687 /* Never called because '.req' does not start a line. */
4688 { "req", s_req, 0 },
dcbf9037
JB
4689 /* Following two are likewise never called. */
4690 { "dn", s_dn, 0 },
4691 { "qn", s_qn, 0 },
c19d1205
ZW
4692 { "unreq", s_unreq, 0 },
4693 { "bss", s_bss, 0 },
db2ed2e0 4694 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4695 { "arm", s_arm, 0 },
4696 { "thumb", s_thumb, 0 },
4697 { "code", s_code, 0 },
4698 { "force_thumb", s_force_thumb, 0 },
4699 { "thumb_func", s_thumb_func, 0 },
4700 { "thumb_set", s_thumb_set, 0 },
4701 { "even", s_even, 0 },
4702 { "ltorg", s_ltorg, 0 },
4703 { "pool", s_ltorg, 0 },
4704 { "syntax", s_syntax, 0 },
8463be01
PB
4705 { "cpu", s_arm_cpu, 0 },
4706 { "arch", s_arm_arch, 0 },
7a1d4c38 4707 { "object_arch", s_arm_object_arch, 0 },
8463be01 4708 { "fpu", s_arm_fpu, 0 },
69133863 4709 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4710#ifdef OBJ_ELF
c921be7d
NC
4711 { "word", s_arm_elf_cons, 4 },
4712 { "long", s_arm_elf_cons, 4 },
4713 { "inst.n", s_arm_elf_inst, 2 },
4714 { "inst.w", s_arm_elf_inst, 4 },
4715 { "inst", s_arm_elf_inst, 0 },
4716 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4717 { "fnstart", s_arm_unwind_fnstart, 0 },
4718 { "fnend", s_arm_unwind_fnend, 0 },
4719 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4720 { "personality", s_arm_unwind_personality, 0 },
4721 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4722 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4723 { "save", s_arm_unwind_save, 0 },
fa073d69 4724 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4725 { "movsp", s_arm_unwind_movsp, 0 },
4726 { "pad", s_arm_unwind_pad, 0 },
4727 { "setfp", s_arm_unwind_setfp, 0 },
4728 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4729 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4730 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4731#else
4732 { "word", cons, 4},
f0927246
NC
4733
4734 /* These are used for dwarf. */
4735 {"2byte", cons, 2},
4736 {"4byte", cons, 4},
4737 {"8byte", cons, 8},
4738 /* These are used for dwarf2. */
4739 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4740 { "loc", dwarf2_directive_loc, 0 },
4741 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4742#endif
4743 { "extend", float_cons, 'x' },
4744 { "ldouble", float_cons, 'x' },
4745 { "packed", float_cons, 'p' },
f0927246
NC
4746#ifdef TE_PE
4747 {"secrel32", pe_directive_secrel, 0},
4748#endif
2e6976a8
DG
4749
4750 /* These are for compatibility with CodeComposer Studio. */
4751 {"ref", s_ccs_ref, 0},
4752 {"def", s_ccs_def, 0},
4753 {"asmfunc", s_ccs_asmfunc, 0},
4754 {"endasmfunc", s_ccs_endasmfunc, 0},
4755
c19d1205
ZW
4756 { 0, 0, 0 }
4757};
4758\f
4759/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4760
c19d1205
ZW
4761/* Generic immediate-value read function for use in insn parsing.
4762 STR points to the beginning of the immediate (the leading #);
4763 VAL receives the value; if the value is outside [MIN, MAX]
4764 issue an error. PREFIX_OPT is true if the immediate prefix is
4765 optional. */
b99bd4ef 4766
c19d1205
ZW
4767static int
4768parse_immediate (char **str, int *val, int min, int max,
4769 bfd_boolean prefix_opt)
4770{
4771 expressionS exp;
4772 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4773 if (exp.X_op != O_constant)
b99bd4ef 4774 {
c19d1205
ZW
4775 inst.error = _("constant expression required");
4776 return FAIL;
4777 }
b99bd4ef 4778
c19d1205
ZW
4779 if (exp.X_add_number < min || exp.X_add_number > max)
4780 {
4781 inst.error = _("immediate value out of range");
4782 return FAIL;
4783 }
b99bd4ef 4784
c19d1205
ZW
4785 *val = exp.X_add_number;
4786 return SUCCESS;
4787}
b99bd4ef 4788
5287ad62 4789/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4790 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4791 instructions. Puts the result directly in inst.operands[i]. */
4792
4793static int
8335d6aa
JW
4794parse_big_immediate (char **str, int i, expressionS *in_exp,
4795 bfd_boolean allow_symbol_p)
5287ad62
JB
4796{
4797 expressionS exp;
8335d6aa 4798 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4799 char *ptr = *str;
4800
8335d6aa 4801 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4802
8335d6aa 4803 if (exp_p->X_op == O_constant)
036dc3f7 4804 {
8335d6aa 4805 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4806 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4807 O_constant. We have to be careful not to break compilation for
4808 32-bit X_add_number, though. */
8335d6aa 4809 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4810 {
8335d6aa
JW
4811 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4812 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4813 & 0xffffffff);
036dc3f7
PB
4814 inst.operands[i].regisimm = 1;
4815 }
4816 }
8335d6aa
JW
4817 else if (exp_p->X_op == O_big
4818 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4819 {
4820 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4821
5287ad62 4822 /* Bignums have their least significant bits in
477330fc
RM
4823 generic_bignum[0]. Make sure we put 32 bits in imm and
4824 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4825 gas_assert (parts != 0);
95b75c01
NC
4826
4827 /* Make sure that the number is not too big.
4828 PR 11972: Bignums can now be sign-extended to the
4829 size of a .octa so check that the out of range bits
4830 are all zero or all one. */
8335d6aa 4831 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4832 {
4833 LITTLENUM_TYPE m = -1;
4834
4835 if (generic_bignum[parts * 2] != 0
4836 && generic_bignum[parts * 2] != m)
4837 return FAIL;
4838
8335d6aa 4839 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4840 if (generic_bignum[j] != generic_bignum[j-1])
4841 return FAIL;
4842 }
4843
5287ad62
JB
4844 inst.operands[i].imm = 0;
4845 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4846 inst.operands[i].imm |= generic_bignum[idx]
4847 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4848 inst.operands[i].reg = 0;
4849 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4850 inst.operands[i].reg |= generic_bignum[idx]
4851 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4852 inst.operands[i].regisimm = 1;
4853 }
8335d6aa 4854 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4855 return FAIL;
5f4273c7 4856
5287ad62
JB
4857 *str = ptr;
4858
4859 return SUCCESS;
4860}
4861
c19d1205
ZW
4862/* Returns the pseudo-register number of an FPA immediate constant,
4863 or FAIL if there isn't a valid constant here. */
b99bd4ef 4864
c19d1205
ZW
4865static int
4866parse_fpa_immediate (char ** str)
4867{
4868 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4869 char * save_in;
4870 expressionS exp;
4871 int i;
4872 int j;
b99bd4ef 4873
c19d1205
ZW
4874 /* First try and match exact strings, this is to guarantee
4875 that some formats will work even for cross assembly. */
b99bd4ef 4876
c19d1205
ZW
4877 for (i = 0; fp_const[i]; i++)
4878 {
4879 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4880 {
c19d1205 4881 char *start = *str;
b99bd4ef 4882
c19d1205
ZW
4883 *str += strlen (fp_const[i]);
4884 if (is_end_of_line[(unsigned char) **str])
4885 return i + 8;
4886 *str = start;
4887 }
4888 }
b99bd4ef 4889
c19d1205
ZW
4890 /* Just because we didn't get a match doesn't mean that the constant
4891 isn't valid, just that it is in a format that we don't
4892 automatically recognize. Try parsing it with the standard
4893 expression routines. */
b99bd4ef 4894
c19d1205 4895 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4896
c19d1205
ZW
4897 /* Look for a raw floating point number. */
4898 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4899 && is_end_of_line[(unsigned char) *save_in])
4900 {
4901 for (i = 0; i < NUM_FLOAT_VALS; i++)
4902 {
4903 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4904 {
c19d1205
ZW
4905 if (words[j] != fp_values[i][j])
4906 break;
b99bd4ef
NC
4907 }
4908
c19d1205 4909 if (j == MAX_LITTLENUMS)
b99bd4ef 4910 {
c19d1205
ZW
4911 *str = save_in;
4912 return i + 8;
b99bd4ef
NC
4913 }
4914 }
4915 }
b99bd4ef 4916
c19d1205
ZW
4917 /* Try and parse a more complex expression, this will probably fail
4918 unless the code uses a floating point prefix (eg "0f"). */
4919 save_in = input_line_pointer;
4920 input_line_pointer = *str;
4921 if (expression (&exp) == absolute_section
4922 && exp.X_op == O_big
4923 && exp.X_add_number < 0)
4924 {
4925 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4926 Ditto for 15. */
ba592044
AM
4927#define X_PRECISION 5
4928#define E_PRECISION 15L
4929 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4930 {
4931 for (i = 0; i < NUM_FLOAT_VALS; i++)
4932 {
4933 for (j = 0; j < MAX_LITTLENUMS; j++)
4934 {
4935 if (words[j] != fp_values[i][j])
4936 break;
4937 }
b99bd4ef 4938
c19d1205
ZW
4939 if (j == MAX_LITTLENUMS)
4940 {
4941 *str = input_line_pointer;
4942 input_line_pointer = save_in;
4943 return i + 8;
4944 }
4945 }
4946 }
b99bd4ef
NC
4947 }
4948
c19d1205
ZW
4949 *str = input_line_pointer;
4950 input_line_pointer = save_in;
4951 inst.error = _("invalid FPA immediate expression");
4952 return FAIL;
b99bd4ef
NC
4953}
4954
136da414
JB
4955/* Returns 1 if a number has "quarter-precision" float format
4956 0baBbbbbbc defgh000 00000000 00000000. */
4957
4958static int
4959is_quarter_float (unsigned imm)
4960{
4961 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4962 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4963}
4964
aacf0b33
KT
4965
4966/* Detect the presence of a floating point or integer zero constant,
4967 i.e. #0.0 or #0. */
4968
4969static bfd_boolean
4970parse_ifimm_zero (char **in)
4971{
4972 int error_code;
4973
4974 if (!is_immediate_prefix (**in))
3c6452ae
TP
4975 {
4976 /* In unified syntax, all prefixes are optional. */
4977 if (!unified_syntax)
4978 return FALSE;
4979 }
4980 else
4981 ++*in;
0900a05b
JW
4982
4983 /* Accept #0x0 as a synonym for #0. */
4984 if (strncmp (*in, "0x", 2) == 0)
4985 {
4986 int val;
4987 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4988 return FALSE;
4989 return TRUE;
4990 }
4991
aacf0b33
KT
4992 error_code = atof_generic (in, ".", EXP_CHARS,
4993 &generic_floating_point_number);
4994
4995 if (!error_code
4996 && generic_floating_point_number.sign == '+'
4997 && (generic_floating_point_number.low
4998 > generic_floating_point_number.leader))
4999 return TRUE;
5000
5001 return FALSE;
5002}
5003
136da414
JB
5004/* Parse an 8-bit "quarter-precision" floating point number of the form:
5005 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5006 The zero and minus-zero cases need special handling, since they can't be
5007 encoded in the "quarter-precision" float format, but can nonetheless be
5008 loaded as integer constants. */
136da414
JB
5009
5010static unsigned
5011parse_qfloat_immediate (char **ccp, int *immed)
5012{
5013 char *str = *ccp;
c96612cc 5014 char *fpnum;
136da414 5015 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5016 int found_fpchar = 0;
5f4273c7 5017
136da414 5018 skip_past_char (&str, '#');
5f4273c7 5019
c96612cc
JB
5020 /* We must not accidentally parse an integer as a floating-point number. Make
5021 sure that the value we parse is not an integer by checking for special
5022 characters '.' or 'e'.
5023 FIXME: This is a horrible hack, but doing better is tricky because type
5024 information isn't in a very usable state at parse time. */
5025 fpnum = str;
5026 skip_whitespace (fpnum);
5027
5028 if (strncmp (fpnum, "0x", 2) == 0)
5029 return FAIL;
5030 else
5031 {
5032 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5033 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5034 {
5035 found_fpchar = 1;
5036 break;
5037 }
c96612cc
JB
5038
5039 if (!found_fpchar)
477330fc 5040 return FAIL;
c96612cc 5041 }
5f4273c7 5042
136da414
JB
5043 if ((str = atof_ieee (str, 's', words)) != NULL)
5044 {
5045 unsigned fpword = 0;
5046 int i;
5f4273c7 5047
136da414
JB
5048 /* Our FP word must be 32 bits (single-precision FP). */
5049 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5050 {
5051 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5052 fpword |= words[i];
5053 }
5f4273c7 5054
c96612cc 5055 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5056 *immed = fpword;
136da414 5057 else
477330fc 5058 return FAIL;
136da414
JB
5059
5060 *ccp = str;
5f4273c7 5061
136da414
JB
5062 return SUCCESS;
5063 }
5f4273c7 5064
136da414
JB
5065 return FAIL;
5066}
5067
c19d1205
ZW
5068/* Shift operands. */
5069enum shift_kind
b99bd4ef 5070{
c19d1205
ZW
5071 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5072};
b99bd4ef 5073
c19d1205
ZW
5074struct asm_shift_name
5075{
5076 const char *name;
5077 enum shift_kind kind;
5078};
b99bd4ef 5079
c19d1205
ZW
5080/* Third argument to parse_shift. */
5081enum parse_shift_mode
5082{
5083 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5084 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5085 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5086 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5087 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5088};
b99bd4ef 5089
c19d1205
ZW
5090/* Parse a <shift> specifier on an ARM data processing instruction.
5091 This has three forms:
b99bd4ef 5092
c19d1205
ZW
5093 (LSL|LSR|ASL|ASR|ROR) Rs
5094 (LSL|LSR|ASL|ASR|ROR) #imm
5095 RRX
b99bd4ef 5096
c19d1205
ZW
5097 Note that ASL is assimilated to LSL in the instruction encoding, and
5098 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5099
c19d1205
ZW
5100static int
5101parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5102{
c19d1205
ZW
5103 const struct asm_shift_name *shift_name;
5104 enum shift_kind shift;
5105 char *s = *str;
5106 char *p = s;
5107 int reg;
b99bd4ef 5108
c19d1205
ZW
5109 for (p = *str; ISALPHA (*p); p++)
5110 ;
b99bd4ef 5111
c19d1205 5112 if (p == *str)
b99bd4ef 5113 {
c19d1205
ZW
5114 inst.error = _("shift expression expected");
5115 return FAIL;
b99bd4ef
NC
5116 }
5117
21d799b5 5118 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5119 p - *str);
c19d1205
ZW
5120
5121 if (shift_name == NULL)
b99bd4ef 5122 {
c19d1205
ZW
5123 inst.error = _("shift expression expected");
5124 return FAIL;
b99bd4ef
NC
5125 }
5126
c19d1205 5127 shift = shift_name->kind;
b99bd4ef 5128
c19d1205
ZW
5129 switch (mode)
5130 {
5131 case NO_SHIFT_RESTRICT:
5132 case SHIFT_IMMEDIATE: break;
b99bd4ef 5133
c19d1205
ZW
5134 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5135 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5136 {
5137 inst.error = _("'LSL' or 'ASR' required");
5138 return FAIL;
5139 }
5140 break;
b99bd4ef 5141
c19d1205
ZW
5142 case SHIFT_LSL_IMMEDIATE:
5143 if (shift != SHIFT_LSL)
5144 {
5145 inst.error = _("'LSL' required");
5146 return FAIL;
5147 }
5148 break;
b99bd4ef 5149
c19d1205
ZW
5150 case SHIFT_ASR_IMMEDIATE:
5151 if (shift != SHIFT_ASR)
5152 {
5153 inst.error = _("'ASR' required");
5154 return FAIL;
5155 }
5156 break;
b99bd4ef 5157
c19d1205
ZW
5158 default: abort ();
5159 }
b99bd4ef 5160
c19d1205
ZW
5161 if (shift != SHIFT_RRX)
5162 {
5163 /* Whitespace can appear here if the next thing is a bare digit. */
5164 skip_whitespace (p);
b99bd4ef 5165
c19d1205 5166 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5167 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5168 {
5169 inst.operands[i].imm = reg;
5170 inst.operands[i].immisreg = 1;
5171 }
5172 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5173 return FAIL;
5174 }
5175 inst.operands[i].shift_kind = shift;
5176 inst.operands[i].shifted = 1;
5177 *str = p;
5178 return SUCCESS;
b99bd4ef
NC
5179}
5180
c19d1205 5181/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5182
c19d1205
ZW
5183 #<immediate>
5184 #<immediate>, <rotate>
5185 <Rm>
5186 <Rm>, <shift>
b99bd4ef 5187
c19d1205
ZW
5188 where <shift> is defined by parse_shift above, and <rotate> is a
5189 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5190 is deferred to md_apply_fix. */
b99bd4ef 5191
c19d1205
ZW
5192static int
5193parse_shifter_operand (char **str, int i)
5194{
5195 int value;
91d6fa6a 5196 expressionS exp;
b99bd4ef 5197
dcbf9037 5198 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5199 {
5200 inst.operands[i].reg = value;
5201 inst.operands[i].isreg = 1;
b99bd4ef 5202
c19d1205
ZW
5203 /* parse_shift will override this if appropriate */
5204 inst.reloc.exp.X_op = O_constant;
5205 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5206
c19d1205
ZW
5207 if (skip_past_comma (str) == FAIL)
5208 return SUCCESS;
b99bd4ef 5209
c19d1205
ZW
5210 /* Shift operation on register. */
5211 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5212 }
5213
c19d1205
ZW
5214 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5215 return FAIL;
b99bd4ef 5216
c19d1205 5217 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5218 {
c19d1205 5219 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5220 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5221 return FAIL;
b99bd4ef 5222
91d6fa6a 5223 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5224 {
5225 inst.error = _("constant expression expected");
5226 return FAIL;
5227 }
b99bd4ef 5228
91d6fa6a 5229 value = exp.X_add_number;
c19d1205
ZW
5230 if (value < 0 || value > 30 || value % 2 != 0)
5231 {
5232 inst.error = _("invalid rotation");
5233 return FAIL;
5234 }
5235 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5236 {
5237 inst.error = _("invalid constant");
5238 return FAIL;
5239 }
09d92015 5240
a415b1cd
JB
5241 /* Encode as specified. */
5242 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5243 return SUCCESS;
09d92015
MM
5244 }
5245
c19d1205
ZW
5246 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5247 inst.reloc.pc_rel = 0;
5248 return SUCCESS;
09d92015
MM
5249}
5250
4962c51a
MS
5251/* Group relocation information. Each entry in the table contains the
5252 textual name of the relocation as may appear in assembler source
5253 and must end with a colon.
5254 Along with this textual name are the relocation codes to be used if
5255 the corresponding instruction is an ALU instruction (ADD or SUB only),
5256 an LDR, an LDRS, or an LDC. */
5257
5258struct group_reloc_table_entry
5259{
5260 const char *name;
5261 int alu_code;
5262 int ldr_code;
5263 int ldrs_code;
5264 int ldc_code;
5265};
5266
5267typedef enum
5268{
5269 /* Varieties of non-ALU group relocation. */
5270
5271 GROUP_LDR,
5272 GROUP_LDRS,
5273 GROUP_LDC
5274} group_reloc_type;
5275
5276static struct group_reloc_table_entry group_reloc_table[] =
5277 { /* Program counter relative: */
5278 { "pc_g0_nc",
5279 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5280 0, /* LDR */
5281 0, /* LDRS */
5282 0 }, /* LDC */
5283 { "pc_g0",
5284 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5285 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5286 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5287 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5288 { "pc_g1_nc",
5289 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5290 0, /* LDR */
5291 0, /* LDRS */
5292 0 }, /* LDC */
5293 { "pc_g1",
5294 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5295 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5296 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5297 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5298 { "pc_g2",
5299 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5300 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5301 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5302 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5303 /* Section base relative */
5304 { "sb_g0_nc",
5305 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5306 0, /* LDR */
5307 0, /* LDRS */
5308 0 }, /* LDC */
5309 { "sb_g0",
5310 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5311 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5312 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5313 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5314 { "sb_g1_nc",
5315 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5316 0, /* LDR */
5317 0, /* LDRS */
5318 0 }, /* LDC */
5319 { "sb_g1",
5320 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5321 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5322 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5323 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5324 { "sb_g2",
5325 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5326 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5327 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5328 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5329 /* Absolute thumb alu relocations. */
5330 { "lower0_7",
5331 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5332 0, /* LDR. */
5333 0, /* LDRS. */
5334 0 }, /* LDC. */
5335 { "lower8_15",
5336 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5337 0, /* LDR. */
5338 0, /* LDRS. */
5339 0 }, /* LDC. */
5340 { "upper0_7",
5341 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5342 0, /* LDR. */
5343 0, /* LDRS. */
5344 0 }, /* LDC. */
5345 { "upper8_15",
5346 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5347 0, /* LDR. */
5348 0, /* LDRS. */
5349 0 } }; /* LDC. */
4962c51a
MS
5350
5351/* Given the address of a pointer pointing to the textual name of a group
5352 relocation as may appear in assembler source, attempt to find its details
5353 in group_reloc_table. The pointer will be updated to the character after
5354 the trailing colon. On failure, FAIL will be returned; SUCCESS
5355 otherwise. On success, *entry will be updated to point at the relevant
5356 group_reloc_table entry. */
5357
5358static int
5359find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5360{
5361 unsigned int i;
5362 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5363 {
5364 int length = strlen (group_reloc_table[i].name);
5365
5f4273c7
NC
5366 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5367 && (*str)[length] == ':')
477330fc
RM
5368 {
5369 *out = &group_reloc_table[i];
5370 *str += (length + 1);
5371 return SUCCESS;
5372 }
4962c51a
MS
5373 }
5374
5375 return FAIL;
5376}
5377
5378/* Parse a <shifter_operand> for an ARM data processing instruction
5379 (as for parse_shifter_operand) where group relocations are allowed:
5380
5381 #<immediate>
5382 #<immediate>, <rotate>
5383 #:<group_reloc>:<expression>
5384 <Rm>
5385 <Rm>, <shift>
5386
5387 where <group_reloc> is one of the strings defined in group_reloc_table.
5388 The hashes are optional.
5389
5390 Everything else is as for parse_shifter_operand. */
5391
5392static parse_operand_result
5393parse_shifter_operand_group_reloc (char **str, int i)
5394{
5395 /* Determine if we have the sequence of characters #: or just :
5396 coming next. If we do, then we check for a group relocation.
5397 If we don't, punt the whole lot to parse_shifter_operand. */
5398
5399 if (((*str)[0] == '#' && (*str)[1] == ':')
5400 || (*str)[0] == ':')
5401 {
5402 struct group_reloc_table_entry *entry;
5403
5404 if ((*str)[0] == '#')
477330fc 5405 (*str) += 2;
4962c51a 5406 else
477330fc 5407 (*str)++;
4962c51a
MS
5408
5409 /* Try to parse a group relocation. Anything else is an error. */
5410 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5411 {
5412 inst.error = _("unknown group relocation");
5413 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5414 }
4962c51a
MS
5415
5416 /* We now have the group relocation table entry corresponding to
477330fc 5417 the name in the assembler source. Next, we parse the expression. */
4962c51a 5418 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5419 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5420
5421 /* Record the relocation type (always the ALU variant here). */
21d799b5 5422 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5423 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5424
5425 return PARSE_OPERAND_SUCCESS;
5426 }
5427 else
5428 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5429 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5430
5431 /* Never reached. */
5432}
5433
8e560766
MGD
5434/* Parse a Neon alignment expression. Information is written to
5435 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5436
8e560766
MGD
5437 align .imm = align << 8, .immisalign=1, .preind=0 */
5438static parse_operand_result
5439parse_neon_alignment (char **str, int i)
5440{
5441 char *p = *str;
5442 expressionS exp;
5443
5444 my_get_expression (&exp, &p, GE_NO_PREFIX);
5445
5446 if (exp.X_op != O_constant)
5447 {
5448 inst.error = _("alignment must be constant");
5449 return PARSE_OPERAND_FAIL;
5450 }
5451
5452 inst.operands[i].imm = exp.X_add_number << 8;
5453 inst.operands[i].immisalign = 1;
5454 /* Alignments are not pre-indexes. */
5455 inst.operands[i].preind = 0;
5456
5457 *str = p;
5458 return PARSE_OPERAND_SUCCESS;
5459}
5460
c19d1205
ZW
5461/* Parse all forms of an ARM address expression. Information is written
5462 to inst.operands[i] and/or inst.reloc.
09d92015 5463
c19d1205 5464 Preindexed addressing (.preind=1):
09d92015 5465
c19d1205
ZW
5466 [Rn, #offset] .reg=Rn .reloc.exp=offset
5467 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5468 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5469 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5470
c19d1205 5471 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5472
c19d1205 5473 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5474
c19d1205
ZW
5475 [Rn], #offset .reg=Rn .reloc.exp=offset
5476 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5477 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5478 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5479
c19d1205 5480 Unindexed addressing (.preind=0, .postind=0):
09d92015 5481
c19d1205 5482 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5483
c19d1205 5484 Other:
09d92015 5485
c19d1205
ZW
5486 [Rn]{!} shorthand for [Rn,#0]{!}
5487 =immediate .isreg=0 .reloc.exp=immediate
5488 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5489
c19d1205
ZW
5490 It is the caller's responsibility to check for addressing modes not
5491 supported by the instruction, and to set inst.reloc.type. */
5492
4962c51a
MS
5493static parse_operand_result
5494parse_address_main (char **str, int i, int group_relocations,
477330fc 5495 group_reloc_type group_type)
09d92015 5496{
c19d1205
ZW
5497 char *p = *str;
5498 int reg;
09d92015 5499
c19d1205 5500 if (skip_past_char (&p, '[') == FAIL)
09d92015 5501 {
c19d1205
ZW
5502 if (skip_past_char (&p, '=') == FAIL)
5503 {
974da60d 5504 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5505 inst.reloc.pc_rel = 1;
5506 inst.operands[i].reg = REG_PC;
5507 inst.operands[i].isreg = 1;
5508 inst.operands[i].preind = 1;
09d92015 5509
8335d6aa
JW
5510 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5511 return PARSE_OPERAND_FAIL;
5512 }
5513 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5514 /*allow_symbol_p=*/TRUE))
4962c51a 5515 return PARSE_OPERAND_FAIL;
09d92015 5516
c19d1205 5517 *str = p;
4962c51a 5518 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5519 }
5520
8ab8155f
NC
5521 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5522 skip_whitespace (p);
5523
dcbf9037 5524 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5525 {
c19d1205 5526 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5527 return PARSE_OPERAND_FAIL;
09d92015 5528 }
c19d1205
ZW
5529 inst.operands[i].reg = reg;
5530 inst.operands[i].isreg = 1;
09d92015 5531
c19d1205 5532 if (skip_past_comma (&p) == SUCCESS)
09d92015 5533 {
c19d1205 5534 inst.operands[i].preind = 1;
09d92015 5535
c19d1205
ZW
5536 if (*p == '+') p++;
5537 else if (*p == '-') p++, inst.operands[i].negative = 1;
5538
dcbf9037 5539 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5540 {
c19d1205
ZW
5541 inst.operands[i].imm = reg;
5542 inst.operands[i].immisreg = 1;
5543
5544 if (skip_past_comma (&p) == SUCCESS)
5545 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5546 return PARSE_OPERAND_FAIL;
c19d1205 5547 }
5287ad62 5548 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5549 {
5550 /* FIXME: '@' should be used here, but it's filtered out by generic
5551 code before we get to see it here. This may be subject to
5552 change. */
5553 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5554
8e560766
MGD
5555 if (result != PARSE_OPERAND_SUCCESS)
5556 return result;
5557 }
c19d1205
ZW
5558 else
5559 {
5560 if (inst.operands[i].negative)
5561 {
5562 inst.operands[i].negative = 0;
5563 p--;
5564 }
4962c51a 5565
5f4273c7
NC
5566 if (group_relocations
5567 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5568 {
5569 struct group_reloc_table_entry *entry;
5570
477330fc
RM
5571 /* Skip over the #: or : sequence. */
5572 if (*p == '#')
5573 p += 2;
5574 else
5575 p++;
4962c51a
MS
5576
5577 /* Try to parse a group relocation. Anything else is an
477330fc 5578 error. */
4962c51a
MS
5579 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5580 {
5581 inst.error = _("unknown group relocation");
5582 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5583 }
5584
5585 /* We now have the group relocation table entry corresponding to
5586 the name in the assembler source. Next, we parse the
477330fc 5587 expression. */
4962c51a
MS
5588 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5589 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5590
5591 /* Record the relocation type. */
477330fc
RM
5592 switch (group_type)
5593 {
5594 case GROUP_LDR:
5595 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5596 break;
4962c51a 5597
477330fc
RM
5598 case GROUP_LDRS:
5599 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5600 break;
4962c51a 5601
477330fc
RM
5602 case GROUP_LDC:
5603 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5604 break;
4962c51a 5605
477330fc
RM
5606 default:
5607 gas_assert (0);
5608 }
4962c51a 5609
477330fc 5610 if (inst.reloc.type == 0)
4962c51a
MS
5611 {
5612 inst.error = _("this group relocation is not allowed on this instruction");
5613 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5614 }
477330fc
RM
5615 }
5616 else
26d97720
NS
5617 {
5618 char *q = p;
5619 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5620 return PARSE_OPERAND_FAIL;
5621 /* If the offset is 0, find out if it's a +0 or -0. */
5622 if (inst.reloc.exp.X_op == O_constant
5623 && inst.reloc.exp.X_add_number == 0)
5624 {
5625 skip_whitespace (q);
5626 if (*q == '#')
5627 {
5628 q++;
5629 skip_whitespace (q);
5630 }
5631 if (*q == '-')
5632 inst.operands[i].negative = 1;
5633 }
5634 }
09d92015
MM
5635 }
5636 }
8e560766
MGD
5637 else if (skip_past_char (&p, ':') == SUCCESS)
5638 {
5639 /* FIXME: '@' should be used here, but it's filtered out by generic code
5640 before we get to see it here. This may be subject to change. */
5641 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5642
8e560766
MGD
5643 if (result != PARSE_OPERAND_SUCCESS)
5644 return result;
5645 }
09d92015 5646
c19d1205 5647 if (skip_past_char (&p, ']') == FAIL)
09d92015 5648 {
c19d1205 5649 inst.error = _("']' expected");
4962c51a 5650 return PARSE_OPERAND_FAIL;
09d92015
MM
5651 }
5652
c19d1205
ZW
5653 if (skip_past_char (&p, '!') == SUCCESS)
5654 inst.operands[i].writeback = 1;
09d92015 5655
c19d1205 5656 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5657 {
c19d1205
ZW
5658 if (skip_past_char (&p, '{') == SUCCESS)
5659 {
5660 /* [Rn], {expr} - unindexed, with option */
5661 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5662 0, 255, TRUE) == FAIL)
4962c51a 5663 return PARSE_OPERAND_FAIL;
09d92015 5664
c19d1205
ZW
5665 if (skip_past_char (&p, '}') == FAIL)
5666 {
5667 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5668 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5669 }
5670 if (inst.operands[i].preind)
5671 {
5672 inst.error = _("cannot combine index with option");
4962c51a 5673 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5674 }
5675 *str = p;
4962c51a 5676 return PARSE_OPERAND_SUCCESS;
09d92015 5677 }
c19d1205
ZW
5678 else
5679 {
5680 inst.operands[i].postind = 1;
5681 inst.operands[i].writeback = 1;
09d92015 5682
c19d1205
ZW
5683 if (inst.operands[i].preind)
5684 {
5685 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5686 return PARSE_OPERAND_FAIL;
c19d1205 5687 }
09d92015 5688
c19d1205
ZW
5689 if (*p == '+') p++;
5690 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5691
dcbf9037 5692 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5693 {
477330fc
RM
5694 /* We might be using the immediate for alignment already. If we
5695 are, OR the register number into the low-order bits. */
5696 if (inst.operands[i].immisalign)
5697 inst.operands[i].imm |= reg;
5698 else
5699 inst.operands[i].imm = reg;
c19d1205 5700 inst.operands[i].immisreg = 1;
a737bd4d 5701
c19d1205
ZW
5702 if (skip_past_comma (&p) == SUCCESS)
5703 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5704 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5705 }
5706 else
5707 {
26d97720 5708 char *q = p;
c19d1205
ZW
5709 if (inst.operands[i].negative)
5710 {
5711 inst.operands[i].negative = 0;
5712 p--;
5713 }
5714 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5715 return PARSE_OPERAND_FAIL;
26d97720
NS
5716 /* If the offset is 0, find out if it's a +0 or -0. */
5717 if (inst.reloc.exp.X_op == O_constant
5718 && inst.reloc.exp.X_add_number == 0)
5719 {
5720 skip_whitespace (q);
5721 if (*q == '#')
5722 {
5723 q++;
5724 skip_whitespace (q);
5725 }
5726 if (*q == '-')
5727 inst.operands[i].negative = 1;
5728 }
c19d1205
ZW
5729 }
5730 }
a737bd4d
NC
5731 }
5732
c19d1205
ZW
5733 /* If at this point neither .preind nor .postind is set, we have a
5734 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5735 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5736 {
5737 inst.operands[i].preind = 1;
5738 inst.reloc.exp.X_op = O_constant;
5739 inst.reloc.exp.X_add_number = 0;
5740 }
5741 *str = p;
4962c51a
MS
5742 return PARSE_OPERAND_SUCCESS;
5743}
5744
5745static int
5746parse_address (char **str, int i)
5747{
21d799b5 5748 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5749 ? SUCCESS : FAIL;
4962c51a
MS
5750}
5751
5752static parse_operand_result
5753parse_address_group_reloc (char **str, int i, group_reloc_type type)
5754{
5755 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5756}
5757
b6895b4f
PB
5758/* Parse an operand for a MOVW or MOVT instruction. */
5759static int
5760parse_half (char **str)
5761{
5762 char * p;
5f4273c7 5763
b6895b4f
PB
5764 p = *str;
5765 skip_past_char (&p, '#');
5f4273c7 5766 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5767 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5768 else if (strncasecmp (p, ":upper16:", 9) == 0)
5769 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5770
5771 if (inst.reloc.type != BFD_RELOC_UNUSED)
5772 {
5773 p += 9;
5f4273c7 5774 skip_whitespace (p);
b6895b4f
PB
5775 }
5776
5777 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5778 return FAIL;
5779
5780 if (inst.reloc.type == BFD_RELOC_UNUSED)
5781 {
5782 if (inst.reloc.exp.X_op != O_constant)
5783 {
5784 inst.error = _("constant expression expected");
5785 return FAIL;
5786 }
5787 if (inst.reloc.exp.X_add_number < 0
5788 || inst.reloc.exp.X_add_number > 0xffff)
5789 {
5790 inst.error = _("immediate value out of range");
5791 return FAIL;
5792 }
5793 }
5794 *str = p;
5795 return SUCCESS;
5796}
5797
c19d1205 5798/* Miscellaneous. */
a737bd4d 5799
c19d1205
ZW
5800/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5801 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5802static int
d2cd1205 5803parse_psr (char **str, bfd_boolean lhs)
09d92015 5804{
c19d1205
ZW
5805 char *p;
5806 unsigned long psr_field;
62b3e311
PB
5807 const struct asm_psr *psr;
5808 char *start;
d2cd1205 5809 bfd_boolean is_apsr = FALSE;
ac7f631b 5810 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5811
a4482bb6
NC
5812 /* PR gas/12698: If the user has specified -march=all then m_profile will
5813 be TRUE, but we want to ignore it in this case as we are building for any
5814 CPU type, including non-m variants. */
823d2571 5815 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5816 m_profile = FALSE;
5817
c19d1205
ZW
5818 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5819 feature for ease of use and backwards compatibility. */
5820 p = *str;
62b3e311 5821 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5822 {
5823 if (m_profile)
5824 goto unsupported_psr;
fa94de6b 5825
d2cd1205
JB
5826 psr_field = SPSR_BIT;
5827 }
5828 else if (strncasecmp (p, "CPSR", 4) == 0)
5829 {
5830 if (m_profile)
5831 goto unsupported_psr;
5832
5833 psr_field = 0;
5834 }
5835 else if (strncasecmp (p, "APSR", 4) == 0)
5836 {
5837 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5838 and ARMv7-R architecture CPUs. */
5839 is_apsr = TRUE;
5840 psr_field = 0;
5841 }
5842 else if (m_profile)
62b3e311
PB
5843 {
5844 start = p;
5845 do
5846 p++;
5847 while (ISALNUM (*p) || *p == '_');
5848
d2cd1205
JB
5849 if (strncasecmp (start, "iapsr", 5) == 0
5850 || strncasecmp (start, "eapsr", 5) == 0
5851 || strncasecmp (start, "xpsr", 4) == 0
5852 || strncasecmp (start, "psr", 3) == 0)
5853 p = start + strcspn (start, "rR") + 1;
5854
21d799b5 5855 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5856 p - start);
d2cd1205 5857
62b3e311
PB
5858 if (!psr)
5859 return FAIL;
09d92015 5860
d2cd1205
JB
5861 /* If APSR is being written, a bitfield may be specified. Note that
5862 APSR itself is handled above. */
5863 if (psr->field <= 3)
5864 {
5865 psr_field = psr->field;
5866 is_apsr = TRUE;
5867 goto check_suffix;
5868 }
5869
62b3e311 5870 *str = p;
d2cd1205
JB
5871 /* M-profile MSR instructions have the mask field set to "10", except
5872 *PSR variants which modify APSR, which may use a different mask (and
5873 have been handled already). Do that by setting the PSR_f field
5874 here. */
5875 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5876 }
d2cd1205
JB
5877 else
5878 goto unsupported_psr;
09d92015 5879
62b3e311 5880 p += 4;
d2cd1205 5881check_suffix:
c19d1205
ZW
5882 if (*p == '_')
5883 {
5884 /* A suffix follows. */
c19d1205
ZW
5885 p++;
5886 start = p;
a737bd4d 5887
c19d1205
ZW
5888 do
5889 p++;
5890 while (ISALNUM (*p) || *p == '_');
a737bd4d 5891
d2cd1205
JB
5892 if (is_apsr)
5893 {
5894 /* APSR uses a notation for bits, rather than fields. */
5895 unsigned int nzcvq_bits = 0;
5896 unsigned int g_bit = 0;
5897 char *bit;
fa94de6b 5898
d2cd1205
JB
5899 for (bit = start; bit != p; bit++)
5900 {
5901 switch (TOLOWER (*bit))
477330fc 5902 {
d2cd1205
JB
5903 case 'n':
5904 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5905 break;
5906
5907 case 'z':
5908 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5909 break;
5910
5911 case 'c':
5912 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5913 break;
5914
5915 case 'v':
5916 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5917 break;
fa94de6b 5918
d2cd1205
JB
5919 case 'q':
5920 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5921 break;
fa94de6b 5922
d2cd1205
JB
5923 case 'g':
5924 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5925 break;
fa94de6b 5926
d2cd1205
JB
5927 default:
5928 inst.error = _("unexpected bit specified after APSR");
5929 return FAIL;
5930 }
5931 }
fa94de6b 5932
d2cd1205
JB
5933 if (nzcvq_bits == 0x1f)
5934 psr_field |= PSR_f;
fa94de6b 5935
d2cd1205
JB
5936 if (g_bit == 0x1)
5937 {
5938 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5939 {
d2cd1205
JB
5940 inst.error = _("selected processor does not "
5941 "support DSP extension");
5942 return FAIL;
5943 }
5944
5945 psr_field |= PSR_s;
5946 }
fa94de6b 5947
d2cd1205
JB
5948 if ((nzcvq_bits & 0x20) != 0
5949 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5950 || (g_bit & 0x2) != 0)
5951 {
5952 inst.error = _("bad bitmask specified after APSR");
5953 return FAIL;
5954 }
5955 }
5956 else
477330fc 5957 {
d2cd1205 5958 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5959 p - start);
d2cd1205 5960 if (!psr)
477330fc 5961 goto error;
a737bd4d 5962
d2cd1205
JB
5963 psr_field |= psr->field;
5964 }
a737bd4d 5965 }
c19d1205 5966 else
a737bd4d 5967 {
c19d1205
ZW
5968 if (ISALNUM (*p))
5969 goto error; /* Garbage after "[CS]PSR". */
5970
d2cd1205 5971 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5972 is deprecated, but allow it anyway. */
d2cd1205
JB
5973 if (is_apsr && lhs)
5974 {
5975 psr_field |= PSR_f;
5976 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5977 "deprecated"));
5978 }
5979 else if (!m_profile)
5980 /* These bits are never right for M-profile devices: don't set them
5981 (only code paths which read/write APSR reach here). */
5982 psr_field |= (PSR_c | PSR_f);
a737bd4d 5983 }
c19d1205
ZW
5984 *str = p;
5985 return psr_field;
a737bd4d 5986
d2cd1205
JB
5987 unsupported_psr:
5988 inst.error = _("selected processor does not support requested special "
5989 "purpose register");
5990 return FAIL;
5991
c19d1205
ZW
5992 error:
5993 inst.error = _("flag for {c}psr instruction expected");
5994 return FAIL;
a737bd4d
NC
5995}
5996
c19d1205
ZW
5997/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5998 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5999
c19d1205
ZW
6000static int
6001parse_cps_flags (char **str)
a737bd4d 6002{
c19d1205
ZW
6003 int val = 0;
6004 int saw_a_flag = 0;
6005 char *s = *str;
a737bd4d 6006
c19d1205
ZW
6007 for (;;)
6008 switch (*s++)
6009 {
6010 case '\0': case ',':
6011 goto done;
a737bd4d 6012
c19d1205
ZW
6013 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6014 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6015 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6016
c19d1205
ZW
6017 default:
6018 inst.error = _("unrecognized CPS flag");
6019 return FAIL;
6020 }
a737bd4d 6021
c19d1205
ZW
6022 done:
6023 if (saw_a_flag == 0)
a737bd4d 6024 {
c19d1205
ZW
6025 inst.error = _("missing CPS flags");
6026 return FAIL;
a737bd4d 6027 }
a737bd4d 6028
c19d1205
ZW
6029 *str = s - 1;
6030 return val;
a737bd4d
NC
6031}
6032
c19d1205
ZW
6033/* Parse an endian specifier ("BE" or "LE", case insensitive);
6034 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6035
6036static int
c19d1205 6037parse_endian_specifier (char **str)
a737bd4d 6038{
c19d1205
ZW
6039 int little_endian;
6040 char *s = *str;
a737bd4d 6041
c19d1205
ZW
6042 if (strncasecmp (s, "BE", 2))
6043 little_endian = 0;
6044 else if (strncasecmp (s, "LE", 2))
6045 little_endian = 1;
6046 else
a737bd4d 6047 {
c19d1205 6048 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6049 return FAIL;
6050 }
6051
c19d1205 6052 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6053 {
c19d1205 6054 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6055 return FAIL;
6056 }
6057
c19d1205
ZW
6058 *str = s + 2;
6059 return little_endian;
6060}
a737bd4d 6061
c19d1205
ZW
6062/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6063 value suitable for poking into the rotate field of an sxt or sxta
6064 instruction, or FAIL on error. */
6065
6066static int
6067parse_ror (char **str)
6068{
6069 int rot;
6070 char *s = *str;
6071
6072 if (strncasecmp (s, "ROR", 3) == 0)
6073 s += 3;
6074 else
a737bd4d 6075 {
c19d1205 6076 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6077 return FAIL;
6078 }
c19d1205
ZW
6079
6080 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6081 return FAIL;
6082
6083 switch (rot)
a737bd4d 6084 {
c19d1205
ZW
6085 case 0: *str = s; return 0x0;
6086 case 8: *str = s; return 0x1;
6087 case 16: *str = s; return 0x2;
6088 case 24: *str = s; return 0x3;
6089
6090 default:
6091 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6092 return FAIL;
6093 }
c19d1205 6094}
a737bd4d 6095
c19d1205
ZW
6096/* Parse a conditional code (from conds[] below). The value returned is in the
6097 range 0 .. 14, or FAIL. */
6098static int
6099parse_cond (char **str)
6100{
c462b453 6101 char *q;
c19d1205 6102 const struct asm_cond *c;
c462b453
PB
6103 int n;
6104 /* Condition codes are always 2 characters, so matching up to
6105 3 characters is sufficient. */
6106 char cond[3];
a737bd4d 6107
c462b453
PB
6108 q = *str;
6109 n = 0;
6110 while (ISALPHA (*q) && n < 3)
6111 {
e07e6e58 6112 cond[n] = TOLOWER (*q);
c462b453
PB
6113 q++;
6114 n++;
6115 }
a737bd4d 6116
21d799b5 6117 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6118 if (!c)
a737bd4d 6119 {
c19d1205 6120 inst.error = _("condition required");
a737bd4d
NC
6121 return FAIL;
6122 }
6123
c19d1205
ZW
6124 *str = q;
6125 return c->value;
6126}
6127
643afb90
MW
6128/* Record a use of the given feature. */
6129static void
6130record_feature_use (const arm_feature_set *feature)
6131{
6132 if (thumb_mode)
6133 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6134 else
6135 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6136}
6137
e797f7e0
MGD
6138/* If the given feature available in the selected CPU, mark it as used.
6139 Returns TRUE iff feature is available. */
6140static bfd_boolean
6141mark_feature_used (const arm_feature_set *feature)
6142{
6143 /* Ensure the option is valid on the current architecture. */
6144 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6145 return FALSE;
6146
6147 /* Add the appropriate architecture feature for the barrier option used.
6148 */
643afb90 6149 record_feature_use (feature);
e797f7e0
MGD
6150
6151 return TRUE;
6152}
6153
62b3e311
PB
6154/* Parse an option for a barrier instruction. Returns the encoding for the
6155 option, or FAIL. */
6156static int
6157parse_barrier (char **str)
6158{
6159 char *p, *q;
6160 const struct asm_barrier_opt *o;
6161
6162 p = q = *str;
6163 while (ISALPHA (*q))
6164 q++;
6165
21d799b5 6166 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6167 q - p);
62b3e311
PB
6168 if (!o)
6169 return FAIL;
6170
e797f7e0
MGD
6171 if (!mark_feature_used (&o->arch))
6172 return FAIL;
6173
62b3e311
PB
6174 *str = q;
6175 return o->value;
6176}
6177
92e90b6e
PB
6178/* Parse the operands of a table branch instruction. Similar to a memory
6179 operand. */
6180static int
6181parse_tb (char **str)
6182{
6183 char * p = *str;
6184 int reg;
6185
6186 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6187 {
6188 inst.error = _("'[' expected");
6189 return FAIL;
6190 }
92e90b6e 6191
dcbf9037 6192 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6193 {
6194 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6195 return FAIL;
6196 }
6197 inst.operands[0].reg = reg;
6198
6199 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6200 {
6201 inst.error = _("',' expected");
6202 return FAIL;
6203 }
5f4273c7 6204
dcbf9037 6205 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6206 {
6207 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6208 return FAIL;
6209 }
6210 inst.operands[0].imm = reg;
6211
6212 if (skip_past_comma (&p) == SUCCESS)
6213 {
6214 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6215 return FAIL;
6216 if (inst.reloc.exp.X_add_number != 1)
6217 {
6218 inst.error = _("invalid shift");
6219 return FAIL;
6220 }
6221 inst.operands[0].shifted = 1;
6222 }
6223
6224 if (skip_past_char (&p, ']') == FAIL)
6225 {
6226 inst.error = _("']' expected");
6227 return FAIL;
6228 }
6229 *str = p;
6230 return SUCCESS;
6231}
6232
5287ad62
JB
6233/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6234 information on the types the operands can take and how they are encoded.
037e8744
JB
6235 Up to four operands may be read; this function handles setting the
6236 ".present" field for each read operand itself.
5287ad62
JB
6237 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6238 else returns FAIL. */
6239
6240static int
6241parse_neon_mov (char **str, int *which_operand)
6242{
6243 int i = *which_operand, val;
6244 enum arm_reg_type rtype;
6245 char *ptr = *str;
dcbf9037 6246 struct neon_type_el optype;
5f4273c7 6247
dcbf9037 6248 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6249 {
6250 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6251 inst.operands[i].reg = val;
6252 inst.operands[i].isscalar = 1;
dcbf9037 6253 inst.operands[i].vectype = optype;
5287ad62
JB
6254 inst.operands[i++].present = 1;
6255
6256 if (skip_past_comma (&ptr) == FAIL)
477330fc 6257 goto wanted_comma;
5f4273c7 6258
dcbf9037 6259 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6260 goto wanted_arm;
5f4273c7 6261
5287ad62
JB
6262 inst.operands[i].reg = val;
6263 inst.operands[i].isreg = 1;
6264 inst.operands[i].present = 1;
6265 }
037e8744 6266 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6267 != FAIL)
5287ad62
JB
6268 {
6269 /* Cases 0, 1, 2, 3, 5 (D only). */
6270 if (skip_past_comma (&ptr) == FAIL)
477330fc 6271 goto wanted_comma;
5f4273c7 6272
5287ad62
JB
6273 inst.operands[i].reg = val;
6274 inst.operands[i].isreg = 1;
6275 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6276 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6277 inst.operands[i].isvec = 1;
dcbf9037 6278 inst.operands[i].vectype = optype;
5287ad62
JB
6279 inst.operands[i++].present = 1;
6280
dcbf9037 6281 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6282 {
6283 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6284 Case 13: VMOV <Sd>, <Rm> */
6285 inst.operands[i].reg = val;
6286 inst.operands[i].isreg = 1;
6287 inst.operands[i].present = 1;
6288
6289 if (rtype == REG_TYPE_NQ)
6290 {
6291 first_error (_("can't use Neon quad register here"));
6292 return FAIL;
6293 }
6294 else if (rtype != REG_TYPE_VFS)
6295 {
6296 i++;
6297 if (skip_past_comma (&ptr) == FAIL)
6298 goto wanted_comma;
6299 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6300 goto wanted_arm;
6301 inst.operands[i].reg = val;
6302 inst.operands[i].isreg = 1;
6303 inst.operands[i].present = 1;
6304 }
6305 }
037e8744 6306 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6307 &optype)) != FAIL)
6308 {
6309 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6310 Case 1: VMOV<c><q> <Dd>, <Dm>
6311 Case 8: VMOV.F32 <Sd>, <Sm>
6312 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6313
6314 inst.operands[i].reg = val;
6315 inst.operands[i].isreg = 1;
6316 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6317 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6318 inst.operands[i].isvec = 1;
6319 inst.operands[i].vectype = optype;
6320 inst.operands[i].present = 1;
6321
6322 if (skip_past_comma (&ptr) == SUCCESS)
6323 {
6324 /* Case 15. */
6325 i++;
6326
6327 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6328 goto wanted_arm;
6329
6330 inst.operands[i].reg = val;
6331 inst.operands[i].isreg = 1;
6332 inst.operands[i++].present = 1;
6333
6334 if (skip_past_comma (&ptr) == FAIL)
6335 goto wanted_comma;
6336
6337 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6338 goto wanted_arm;
6339
6340 inst.operands[i].reg = val;
6341 inst.operands[i].isreg = 1;
6342 inst.operands[i].present = 1;
6343 }
6344 }
4641781c 6345 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6346 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6347 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6348 Case 10: VMOV.F32 <Sd>, #<imm>
6349 Case 11: VMOV.F64 <Dd>, #<imm> */
6350 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6351 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6352 == SUCCESS)
477330fc
RM
6353 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6354 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6355 ;
5287ad62 6356 else
477330fc
RM
6357 {
6358 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6359 return FAIL;
6360 }
5287ad62 6361 }
dcbf9037 6362 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6363 {
6364 /* Cases 6, 7. */
6365 inst.operands[i].reg = val;
6366 inst.operands[i].isreg = 1;
6367 inst.operands[i++].present = 1;
5f4273c7 6368
5287ad62 6369 if (skip_past_comma (&ptr) == FAIL)
477330fc 6370 goto wanted_comma;
5f4273c7 6371
dcbf9037 6372 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6373 {
6374 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6375 inst.operands[i].reg = val;
6376 inst.operands[i].isscalar = 1;
6377 inst.operands[i].present = 1;
6378 inst.operands[i].vectype = optype;
6379 }
dcbf9037 6380 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6381 {
6382 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6383 inst.operands[i].reg = val;
6384 inst.operands[i].isreg = 1;
6385 inst.operands[i++].present = 1;
6386
6387 if (skip_past_comma (&ptr) == FAIL)
6388 goto wanted_comma;
6389
6390 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6391 == FAIL)
6392 {
6393 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6394 return FAIL;
6395 }
6396
6397 inst.operands[i].reg = val;
6398 inst.operands[i].isreg = 1;
6399 inst.operands[i].isvec = 1;
6400 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6401 inst.operands[i].vectype = optype;
6402 inst.operands[i].present = 1;
6403
6404 if (rtype == REG_TYPE_VFS)
6405 {
6406 /* Case 14. */
6407 i++;
6408 if (skip_past_comma (&ptr) == FAIL)
6409 goto wanted_comma;
6410 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6411 &optype)) == FAIL)
6412 {
6413 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6414 return FAIL;
6415 }
6416 inst.operands[i].reg = val;
6417 inst.operands[i].isreg = 1;
6418 inst.operands[i].isvec = 1;
6419 inst.operands[i].issingle = 1;
6420 inst.operands[i].vectype = optype;
6421 inst.operands[i].present = 1;
6422 }
6423 }
037e8744 6424 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6425 != FAIL)
6426 {
6427 /* Case 13. */
6428 inst.operands[i].reg = val;
6429 inst.operands[i].isreg = 1;
6430 inst.operands[i].isvec = 1;
6431 inst.operands[i].issingle = 1;
6432 inst.operands[i].vectype = optype;
6433 inst.operands[i].present = 1;
6434 }
5287ad62
JB
6435 }
6436 else
6437 {
dcbf9037 6438 first_error (_("parse error"));
5287ad62
JB
6439 return FAIL;
6440 }
6441
6442 /* Successfully parsed the operands. Update args. */
6443 *which_operand = i;
6444 *str = ptr;
6445 return SUCCESS;
6446
5f4273c7 6447 wanted_comma:
dcbf9037 6448 first_error (_("expected comma"));
5287ad62 6449 return FAIL;
5f4273c7
NC
6450
6451 wanted_arm:
dcbf9037 6452 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6453 return FAIL;
5287ad62
JB
6454}
6455
5be8be5d
DG
6456/* Use this macro when the operand constraints are different
6457 for ARM and THUMB (e.g. ldrd). */
6458#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6459 ((arm_operand) | ((thumb_operand) << 16))
6460
c19d1205
ZW
6461/* Matcher codes for parse_operands. */
6462enum operand_parse_code
6463{
6464 OP_stop, /* end of line */
6465
6466 OP_RR, /* ARM register */
6467 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6468 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6469 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6470 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6471 optional trailing ! */
c19d1205
ZW
6472 OP_RRw, /* ARM register, not r15, optional trailing ! */
6473 OP_RCP, /* Coprocessor number */
6474 OP_RCN, /* Coprocessor register */
6475 OP_RF, /* FPA register */
6476 OP_RVS, /* VFP single precision register */
5287ad62
JB
6477 OP_RVD, /* VFP double precision register (0..15) */
6478 OP_RND, /* Neon double precision register (0..31) */
6479 OP_RNQ, /* Neon quad precision register */
037e8744 6480 OP_RVSD, /* VFP single or double precision register */
5287ad62 6481 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6482 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6483 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6484 OP_RVC, /* VFP control register */
6485 OP_RMF, /* Maverick F register */
6486 OP_RMD, /* Maverick D register */
6487 OP_RMFX, /* Maverick FX register */
6488 OP_RMDX, /* Maverick DX register */
6489 OP_RMAX, /* Maverick AX register */
6490 OP_RMDS, /* Maverick DSPSC register */
6491 OP_RIWR, /* iWMMXt wR register */
6492 OP_RIWC, /* iWMMXt wC register */
6493 OP_RIWG, /* iWMMXt wCG register */
6494 OP_RXA, /* XScale accumulator register */
6495
6496 OP_REGLST, /* ARM register list */
6497 OP_VRSLST, /* VFP single-precision register list */
6498 OP_VRDLST, /* VFP double-precision register list */
037e8744 6499 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6500 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6501 OP_NSTRLST, /* Neon element/structure list */
6502
5287ad62 6503 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6504 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6505 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6506 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6507 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6508 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6509 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6510 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6511 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6512 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6513 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6514
6515 OP_I0, /* immediate zero */
c19d1205
ZW
6516 OP_I7, /* immediate value 0 .. 7 */
6517 OP_I15, /* 0 .. 15 */
6518 OP_I16, /* 1 .. 16 */
5287ad62 6519 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6520 OP_I31, /* 0 .. 31 */
6521 OP_I31w, /* 0 .. 31, optional trailing ! */
6522 OP_I32, /* 1 .. 32 */
5287ad62
JB
6523 OP_I32z, /* 0 .. 32 */
6524 OP_I63, /* 0 .. 63 */
c19d1205 6525 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6526 OP_I64, /* 1 .. 64 */
6527 OP_I64z, /* 0 .. 64 */
c19d1205 6528 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6529
6530 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6531 OP_I7b, /* 0 .. 7 */
6532 OP_I15b, /* 0 .. 15 */
6533 OP_I31b, /* 0 .. 31 */
6534
6535 OP_SH, /* shifter operand */
4962c51a 6536 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6537 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6538 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6539 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6540 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6541 OP_EXP, /* arbitrary expression */
6542 OP_EXPi, /* same, with optional immediate prefix */
6543 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6544 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6545 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6546 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6547
6548 OP_CPSF, /* CPS flags */
6549 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6550 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6551 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6552 OP_COND, /* conditional code */
92e90b6e 6553 OP_TB, /* Table branch. */
c19d1205 6554
037e8744
JB
6555 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6556
c19d1205 6557 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6558 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6559 OP_RR_EXi, /* ARM register or expression with imm prefix */
6560 OP_RF_IF, /* FPA register or immediate */
6561 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6562 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6563
6564 /* Optional operands. */
6565 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6566 OP_oI31b, /* 0 .. 31 */
5287ad62 6567 OP_oI32b, /* 1 .. 32 */
5f1af56b 6568 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6569 OP_oIffffb, /* 0 .. 65535 */
6570 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6571
6572 OP_oRR, /* ARM register */
6573 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6574 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6575 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6576 OP_oRND, /* Optional Neon double precision register */
6577 OP_oRNQ, /* Optional Neon quad precision register */
6578 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6579 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6580 OP_oSHll, /* LSL immediate */
6581 OP_oSHar, /* ASR immediate */
6582 OP_oSHllar, /* LSL or ASR immediate */
6583 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6584 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6585
5be8be5d
DG
6586 /* Some pre-defined mixed (ARM/THUMB) operands. */
6587 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6588 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6589 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6590
c19d1205
ZW
6591 OP_FIRST_OPTIONAL = OP_oI7b
6592};
a737bd4d 6593
c19d1205
ZW
6594/* Generic instruction operand parser. This does no encoding and no
6595 semantic validation; it merely squirrels values away in the inst
6596 structure. Returns SUCCESS or FAIL depending on whether the
6597 specified grammar matched. */
6598static int
5be8be5d 6599parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6600{
5be8be5d 6601 unsigned const int *upat = pattern;
c19d1205
ZW
6602 char *backtrack_pos = 0;
6603 const char *backtrack_error = 0;
99aad254 6604 int i, val = 0, backtrack_index = 0;
5287ad62 6605 enum arm_reg_type rtype;
4962c51a 6606 parse_operand_result result;
5be8be5d 6607 unsigned int op_parse_code;
c19d1205 6608
e07e6e58
NC
6609#define po_char_or_fail(chr) \
6610 do \
6611 { \
6612 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6613 goto bad_args; \
e07e6e58
NC
6614 } \
6615 while (0)
c19d1205 6616
e07e6e58
NC
6617#define po_reg_or_fail(regtype) \
6618 do \
dcbf9037 6619 { \
e07e6e58 6620 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6621 & inst.operands[i].vectype); \
e07e6e58 6622 if (val == FAIL) \
477330fc
RM
6623 { \
6624 first_error (_(reg_expected_msgs[regtype])); \
6625 goto failure; \
6626 } \
e07e6e58
NC
6627 inst.operands[i].reg = val; \
6628 inst.operands[i].isreg = 1; \
6629 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6630 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6631 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6632 || rtype == REG_TYPE_VFD \
6633 || rtype == REG_TYPE_NQ); \
dcbf9037 6634 } \
e07e6e58
NC
6635 while (0)
6636
6637#define po_reg_or_goto(regtype, label) \
6638 do \
6639 { \
6640 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6641 & inst.operands[i].vectype); \
6642 if (val == FAIL) \
6643 goto label; \
dcbf9037 6644 \
e07e6e58
NC
6645 inst.operands[i].reg = val; \
6646 inst.operands[i].isreg = 1; \
6647 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6648 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6649 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6650 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6651 || rtype == REG_TYPE_NQ); \
6652 } \
6653 while (0)
6654
6655#define po_imm_or_fail(min, max, popt) \
6656 do \
6657 { \
6658 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6659 goto failure; \
6660 inst.operands[i].imm = val; \
6661 } \
6662 while (0)
6663
6664#define po_scalar_or_goto(elsz, label) \
6665 do \
6666 { \
6667 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6668 if (val == FAIL) \
6669 goto label; \
6670 inst.operands[i].reg = val; \
6671 inst.operands[i].isscalar = 1; \
6672 } \
6673 while (0)
6674
6675#define po_misc_or_fail(expr) \
6676 do \
6677 { \
6678 if (expr) \
6679 goto failure; \
6680 } \
6681 while (0)
6682
6683#define po_misc_or_fail_no_backtrack(expr) \
6684 do \
6685 { \
6686 result = expr; \
6687 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6688 backtrack_pos = 0; \
6689 if (result != PARSE_OPERAND_SUCCESS) \
6690 goto failure; \
6691 } \
6692 while (0)
4962c51a 6693
52e7f43d
RE
6694#define po_barrier_or_imm(str) \
6695 do \
6696 { \
6697 val = parse_barrier (&str); \
ccb84d65
JB
6698 if (val == FAIL && ! ISALPHA (*str)) \
6699 goto immediate; \
6700 if (val == FAIL \
6701 /* ISB can only take SY as an option. */ \
6702 || ((inst.instruction & 0xf0) == 0x60 \
6703 && val != 0xf)) \
52e7f43d 6704 { \
ccb84d65
JB
6705 inst.error = _("invalid barrier type"); \
6706 backtrack_pos = 0; \
6707 goto failure; \
52e7f43d
RE
6708 } \
6709 } \
6710 while (0)
6711
c19d1205
ZW
6712 skip_whitespace (str);
6713
6714 for (i = 0; upat[i] != OP_stop; i++)
6715 {
5be8be5d
DG
6716 op_parse_code = upat[i];
6717 if (op_parse_code >= 1<<16)
6718 op_parse_code = thumb ? (op_parse_code >> 16)
6719 : (op_parse_code & ((1<<16)-1));
6720
6721 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6722 {
6723 /* Remember where we are in case we need to backtrack. */
9c2799c2 6724 gas_assert (!backtrack_pos);
c19d1205
ZW
6725 backtrack_pos = str;
6726 backtrack_error = inst.error;
6727 backtrack_index = i;
6728 }
6729
b6702015 6730 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6731 po_char_or_fail (',');
6732
5be8be5d 6733 switch (op_parse_code)
c19d1205
ZW
6734 {
6735 /* Registers */
6736 case OP_oRRnpc:
5be8be5d 6737 case OP_oRRnpcsp:
c19d1205 6738 case OP_RRnpc:
5be8be5d 6739 case OP_RRnpcsp:
c19d1205
ZW
6740 case OP_oRR:
6741 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6742 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6743 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6744 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6745 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6746 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6747 case OP_oRND:
5287ad62 6748 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6749 case OP_RVC:
6750 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6751 break;
6752 /* Also accept generic coprocessor regs for unknown registers. */
6753 coproc_reg:
6754 po_reg_or_fail (REG_TYPE_CN);
6755 break;
c19d1205
ZW
6756 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6757 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6758 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6759 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6760 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6761 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6762 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6763 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6764 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6765 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6766 case OP_oRNQ:
5287ad62 6767 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6768 case OP_oRNDQ:
5287ad62 6769 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6770 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6771 case OP_oRNSDQ:
6772 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6773
6774 /* Neon scalar. Using an element size of 8 means that some invalid
6775 scalars are accepted here, so deal with those in later code. */
6776 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6777
6778 case OP_RNDQ_I0:
6779 {
6780 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6781 break;
6782 try_imm0:
6783 po_imm_or_fail (0, 0, TRUE);
6784 }
6785 break;
6786
6787 case OP_RVSD_I0:
6788 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6789 break;
6790
aacf0b33
KT
6791 case OP_RSVD_FI0:
6792 {
6793 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6794 break;
6795 try_ifimm0:
6796 if (parse_ifimm_zero (&str))
6797 inst.operands[i].imm = 0;
6798 else
6799 {
6800 inst.error
6801 = _("only floating point zero is allowed as immediate value");
6802 goto failure;
6803 }
6804 }
6805 break;
6806
477330fc
RM
6807 case OP_RR_RNSC:
6808 {
6809 po_scalar_or_goto (8, try_rr);
6810 break;
6811 try_rr:
6812 po_reg_or_fail (REG_TYPE_RN);
6813 }
6814 break;
6815
6816 case OP_RNSDQ_RNSC:
6817 {
6818 po_scalar_or_goto (8, try_nsdq);
6819 break;
6820 try_nsdq:
6821 po_reg_or_fail (REG_TYPE_NSDQ);
6822 }
6823 break;
6824
6825 case OP_RNDQ_RNSC:
6826 {
6827 po_scalar_or_goto (8, try_ndq);
6828 break;
6829 try_ndq:
6830 po_reg_or_fail (REG_TYPE_NDQ);
6831 }
6832 break;
6833
6834 case OP_RND_RNSC:
6835 {
6836 po_scalar_or_goto (8, try_vfd);
6837 break;
6838 try_vfd:
6839 po_reg_or_fail (REG_TYPE_VFD);
6840 }
6841 break;
6842
6843 case OP_VMOV:
6844 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6845 not careful then bad things might happen. */
6846 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6847 break;
6848
6849 case OP_RNDQ_Ibig:
6850 {
6851 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6852 break;
6853 try_immbig:
6854 /* There's a possibility of getting a 64-bit immediate here, so
6855 we need special handling. */
8335d6aa
JW
6856 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6857 == FAIL)
477330fc
RM
6858 {
6859 inst.error = _("immediate value is out of range");
6860 goto failure;
6861 }
6862 }
6863 break;
6864
6865 case OP_RNDQ_I63b:
6866 {
6867 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6868 break;
6869 try_shimm:
6870 po_imm_or_fail (0, 63, TRUE);
6871 }
6872 break;
c19d1205
ZW
6873
6874 case OP_RRnpcb:
6875 po_char_or_fail ('[');
6876 po_reg_or_fail (REG_TYPE_RN);
6877 po_char_or_fail (']');
6878 break;
a737bd4d 6879
55881a11 6880 case OP_RRnpctw:
c19d1205 6881 case OP_RRw:
b6702015 6882 case OP_oRRw:
c19d1205
ZW
6883 po_reg_or_fail (REG_TYPE_RN);
6884 if (skip_past_char (&str, '!') == SUCCESS)
6885 inst.operands[i].writeback = 1;
6886 break;
6887
6888 /* Immediates */
6889 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6890 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6891 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6892 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6893 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6894 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6895 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6896 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6897 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6898 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6899 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6900 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6901
6902 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6903 case OP_oI7b:
6904 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6905 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6906 case OP_oI31b:
6907 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6908 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6909 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6910 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6911
6912 /* Immediate variants */
6913 case OP_oI255c:
6914 po_char_or_fail ('{');
6915 po_imm_or_fail (0, 255, TRUE);
6916 po_char_or_fail ('}');
6917 break;
6918
6919 case OP_I31w:
6920 /* The expression parser chokes on a trailing !, so we have
6921 to find it first and zap it. */
6922 {
6923 char *s = str;
6924 while (*s && *s != ',')
6925 s++;
6926 if (s[-1] == '!')
6927 {
6928 s[-1] = '\0';
6929 inst.operands[i].writeback = 1;
6930 }
6931 po_imm_or_fail (0, 31, TRUE);
6932 if (str == s - 1)
6933 str = s;
6934 }
6935 break;
6936
6937 /* Expressions */
6938 case OP_EXPi: EXPi:
6939 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6940 GE_OPT_PREFIX));
6941 break;
6942
6943 case OP_EXP:
6944 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6945 GE_NO_PREFIX));
6946 break;
6947
6948 case OP_EXPr: EXPr:
6949 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6950 GE_NO_PREFIX));
6951 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6952 {
c19d1205
ZW
6953 val = parse_reloc (&str);
6954 if (val == -1)
6955 {
6956 inst.error = _("unrecognized relocation suffix");
6957 goto failure;
6958 }
6959 else if (val != BFD_RELOC_UNUSED)
6960 {
6961 inst.operands[i].imm = val;
6962 inst.operands[i].hasreloc = 1;
6963 }
a737bd4d 6964 }
c19d1205 6965 break;
a737bd4d 6966
b6895b4f
PB
6967 /* Operand for MOVW or MOVT. */
6968 case OP_HALF:
6969 po_misc_or_fail (parse_half (&str));
6970 break;
6971
e07e6e58 6972 /* Register or expression. */
c19d1205
ZW
6973 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6974 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6975
e07e6e58 6976 /* Register or immediate. */
c19d1205
ZW
6977 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6978 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6979
c19d1205
ZW
6980 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6981 IF:
6982 if (!is_immediate_prefix (*str))
6983 goto bad_args;
6984 str++;
6985 val = parse_fpa_immediate (&str);
6986 if (val == FAIL)
6987 goto failure;
6988 /* FPA immediates are encoded as registers 8-15.
6989 parse_fpa_immediate has already applied the offset. */
6990 inst.operands[i].reg = val;
6991 inst.operands[i].isreg = 1;
6992 break;
09d92015 6993
2d447fca
JM
6994 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6995 I32z: po_imm_or_fail (0, 32, FALSE); break;
6996
e07e6e58 6997 /* Two kinds of register. */
c19d1205
ZW
6998 case OP_RIWR_RIWC:
6999 {
7000 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7001 if (!rege
7002 || (rege->type != REG_TYPE_MMXWR
7003 && rege->type != REG_TYPE_MMXWC
7004 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7005 {
7006 inst.error = _("iWMMXt data or control register expected");
7007 goto failure;
7008 }
7009 inst.operands[i].reg = rege->number;
7010 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7011 }
7012 break;
09d92015 7013
41adaa5c
JM
7014 case OP_RIWC_RIWG:
7015 {
7016 struct reg_entry *rege = arm_reg_parse_multi (&str);
7017 if (!rege
7018 || (rege->type != REG_TYPE_MMXWC
7019 && rege->type != REG_TYPE_MMXWCG))
7020 {
7021 inst.error = _("iWMMXt control register expected");
7022 goto failure;
7023 }
7024 inst.operands[i].reg = rege->number;
7025 inst.operands[i].isreg = 1;
7026 }
7027 break;
7028
c19d1205
ZW
7029 /* Misc */
7030 case OP_CPSF: val = parse_cps_flags (&str); break;
7031 case OP_ENDI: val = parse_endian_specifier (&str); break;
7032 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7033 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7034 case OP_oBARRIER_I15:
7035 po_barrier_or_imm (str); break;
7036 immediate:
7037 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7038 goto failure;
52e7f43d 7039 break;
c19d1205 7040
fa94de6b 7041 case OP_wPSR:
d2cd1205 7042 case OP_rPSR:
90ec0d68
MGD
7043 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7044 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7045 {
7046 inst.error = _("Banked registers are not available with this "
7047 "architecture.");
7048 goto failure;
7049 }
7050 break;
d2cd1205
JB
7051 try_psr:
7052 val = parse_psr (&str, op_parse_code == OP_wPSR);
7053 break;
037e8744 7054
477330fc
RM
7055 case OP_APSR_RR:
7056 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7057 break;
7058 try_apsr:
7059 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7060 instruction). */
7061 if (strncasecmp (str, "APSR_", 5) == 0)
7062 {
7063 unsigned found = 0;
7064 str += 5;
7065 while (found < 15)
7066 switch (*str++)
7067 {
7068 case 'c': found = (found & 1) ? 16 : found | 1; break;
7069 case 'n': found = (found & 2) ? 16 : found | 2; break;
7070 case 'z': found = (found & 4) ? 16 : found | 4; break;
7071 case 'v': found = (found & 8) ? 16 : found | 8; break;
7072 default: found = 16;
7073 }
7074 if (found != 15)
7075 goto failure;
7076 inst.operands[i].isvec = 1;
f7c21dc7
NC
7077 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7078 inst.operands[i].reg = REG_PC;
477330fc
RM
7079 }
7080 else
7081 goto failure;
7082 break;
037e8744 7083
92e90b6e
PB
7084 case OP_TB:
7085 po_misc_or_fail (parse_tb (&str));
7086 break;
7087
e07e6e58 7088 /* Register lists. */
c19d1205
ZW
7089 case OP_REGLST:
7090 val = parse_reg_list (&str);
7091 if (*str == '^')
7092 {
5e0d7f77 7093 inst.operands[i].writeback = 1;
c19d1205
ZW
7094 str++;
7095 }
7096 break;
09d92015 7097
c19d1205 7098 case OP_VRSLST:
5287ad62 7099 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7100 break;
09d92015 7101
c19d1205 7102 case OP_VRDLST:
5287ad62 7103 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7104 break;
a737bd4d 7105
477330fc
RM
7106 case OP_VRSDLST:
7107 /* Allow Q registers too. */
7108 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7109 REGLIST_NEON_D);
7110 if (val == FAIL)
7111 {
7112 inst.error = NULL;
7113 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7114 REGLIST_VFP_S);
7115 inst.operands[i].issingle = 1;
7116 }
7117 break;
7118
7119 case OP_NRDLST:
7120 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7121 REGLIST_NEON_D);
7122 break;
5287ad62
JB
7123
7124 case OP_NSTRLST:
477330fc
RM
7125 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7126 &inst.operands[i].vectype);
7127 break;
5287ad62 7128
c19d1205
ZW
7129 /* Addressing modes */
7130 case OP_ADDR:
7131 po_misc_or_fail (parse_address (&str, i));
7132 break;
09d92015 7133
4962c51a
MS
7134 case OP_ADDRGLDR:
7135 po_misc_or_fail_no_backtrack (
477330fc 7136 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7137 break;
7138
7139 case OP_ADDRGLDRS:
7140 po_misc_or_fail_no_backtrack (
477330fc 7141 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7142 break;
7143
7144 case OP_ADDRGLDC:
7145 po_misc_or_fail_no_backtrack (
477330fc 7146 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7147 break;
7148
c19d1205
ZW
7149 case OP_SH:
7150 po_misc_or_fail (parse_shifter_operand (&str, i));
7151 break;
09d92015 7152
4962c51a
MS
7153 case OP_SHG:
7154 po_misc_or_fail_no_backtrack (
477330fc 7155 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7156 break;
7157
c19d1205
ZW
7158 case OP_oSHll:
7159 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7160 break;
09d92015 7161
c19d1205
ZW
7162 case OP_oSHar:
7163 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7164 break;
09d92015 7165
c19d1205
ZW
7166 case OP_oSHllar:
7167 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7168 break;
09d92015 7169
c19d1205 7170 default:
5be8be5d 7171 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7172 }
09d92015 7173
c19d1205
ZW
7174 /* Various value-based sanity checks and shared operations. We
7175 do not signal immediate failures for the register constraints;
7176 this allows a syntax error to take precedence. */
5be8be5d 7177 switch (op_parse_code)
c19d1205
ZW
7178 {
7179 case OP_oRRnpc:
7180 case OP_RRnpc:
7181 case OP_RRnpcb:
7182 case OP_RRw:
b6702015 7183 case OP_oRRw:
c19d1205
ZW
7184 case OP_RRnpc_I0:
7185 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7186 inst.error = BAD_PC;
7187 break;
09d92015 7188
5be8be5d
DG
7189 case OP_oRRnpcsp:
7190 case OP_RRnpcsp:
7191 if (inst.operands[i].isreg)
7192 {
7193 if (inst.operands[i].reg == REG_PC)
7194 inst.error = BAD_PC;
5c8ed6a4
JW
7195 else if (inst.operands[i].reg == REG_SP
7196 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7197 relaxed since ARMv8-A. */
7198 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7199 {
7200 gas_assert (thumb);
7201 inst.error = BAD_SP;
7202 }
5be8be5d
DG
7203 }
7204 break;
7205
55881a11 7206 case OP_RRnpctw:
fa94de6b
RM
7207 if (inst.operands[i].isreg
7208 && inst.operands[i].reg == REG_PC
55881a11
MGD
7209 && (inst.operands[i].writeback || thumb))
7210 inst.error = BAD_PC;
7211 break;
7212
c19d1205
ZW
7213 case OP_CPSF:
7214 case OP_ENDI:
7215 case OP_oROR:
d2cd1205
JB
7216 case OP_wPSR:
7217 case OP_rPSR:
c19d1205 7218 case OP_COND:
52e7f43d 7219 case OP_oBARRIER_I15:
c19d1205
ZW
7220 case OP_REGLST:
7221 case OP_VRSLST:
7222 case OP_VRDLST:
477330fc
RM
7223 case OP_VRSDLST:
7224 case OP_NRDLST:
7225 case OP_NSTRLST:
c19d1205
ZW
7226 if (val == FAIL)
7227 goto failure;
7228 inst.operands[i].imm = val;
7229 break;
a737bd4d 7230
c19d1205
ZW
7231 default:
7232 break;
7233 }
09d92015 7234
c19d1205
ZW
7235 /* If we get here, this operand was successfully parsed. */
7236 inst.operands[i].present = 1;
7237 continue;
09d92015 7238
c19d1205 7239 bad_args:
09d92015 7240 inst.error = BAD_ARGS;
c19d1205
ZW
7241
7242 failure:
7243 if (!backtrack_pos)
d252fdde
PB
7244 {
7245 /* The parse routine should already have set inst.error, but set a
5f4273c7 7246 default here just in case. */
d252fdde
PB
7247 if (!inst.error)
7248 inst.error = _("syntax error");
7249 return FAIL;
7250 }
c19d1205
ZW
7251
7252 /* Do not backtrack over a trailing optional argument that
7253 absorbed some text. We will only fail again, with the
7254 'garbage following instruction' error message, which is
7255 probably less helpful than the current one. */
7256 if (backtrack_index == i && backtrack_pos != str
7257 && upat[i+1] == OP_stop)
d252fdde
PB
7258 {
7259 if (!inst.error)
7260 inst.error = _("syntax error");
7261 return FAIL;
7262 }
c19d1205
ZW
7263
7264 /* Try again, skipping the optional argument at backtrack_pos. */
7265 str = backtrack_pos;
7266 inst.error = backtrack_error;
7267 inst.operands[backtrack_index].present = 0;
7268 i = backtrack_index;
7269 backtrack_pos = 0;
09d92015 7270 }
09d92015 7271
c19d1205
ZW
7272 /* Check that we have parsed all the arguments. */
7273 if (*str != '\0' && !inst.error)
7274 inst.error = _("garbage following instruction");
09d92015 7275
c19d1205 7276 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7277}
7278
c19d1205
ZW
7279#undef po_char_or_fail
7280#undef po_reg_or_fail
7281#undef po_reg_or_goto
7282#undef po_imm_or_fail
5287ad62 7283#undef po_scalar_or_fail
52e7f43d 7284#undef po_barrier_or_imm
e07e6e58 7285
c19d1205 7286/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7287#define constraint(expr, err) \
7288 do \
c19d1205 7289 { \
e07e6e58
NC
7290 if (expr) \
7291 { \
7292 inst.error = err; \
7293 return; \
7294 } \
c19d1205 7295 } \
e07e6e58 7296 while (0)
c19d1205 7297
fdfde340
JM
7298/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7299 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7300 is the BadReg predicate in ARM's Thumb-2 documentation.
7301
7302 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7303 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7304#define reject_bad_reg(reg) \
7305 do \
7306 if (reg == REG_PC) \
7307 { \
7308 inst.error = BAD_PC; \
7309 return; \
7310 } \
7311 else if (reg == REG_SP \
7312 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7313 { \
7314 inst.error = BAD_SP; \
7315 return; \
7316 } \
fdfde340
JM
7317 while (0)
7318
94206790
MM
7319/* If REG is R13 (the stack pointer), warn that its use is
7320 deprecated. */
7321#define warn_deprecated_sp(reg) \
7322 do \
7323 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7324 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7325 while (0)
7326
c19d1205
ZW
7327/* Functions for operand encoding. ARM, then Thumb. */
7328
d840c081 7329#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7330
9db2f6b4
RL
7331/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7332
7333 The only binary encoding difference is the Coprocessor number. Coprocessor
7334 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7335 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7336 exists for Single-Precision operation. */
7337
7338static void
7339do_scalar_fp16_v82_encode (void)
7340{
7341 if (inst.cond != COND_ALWAYS)
7342 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7343 " the behaviour is UNPREDICTABLE"));
7344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7345 _(BAD_FP16));
7346
7347 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7348 mark_feature_used (&arm_ext_fp16);
7349}
7350
c19d1205
ZW
7351/* If VAL can be encoded in the immediate field of an ARM instruction,
7352 return the encoded form. Otherwise, return FAIL. */
7353
7354static unsigned int
7355encode_arm_immediate (unsigned int val)
09d92015 7356{
c19d1205
ZW
7357 unsigned int a, i;
7358
4f1d6205
L
7359 if (val <= 0xff)
7360 return val;
7361
7362 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7363 if ((a = rotate_left (val, i)) <= 0xff)
7364 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7365
7366 return FAIL;
09d92015
MM
7367}
7368
c19d1205
ZW
7369/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7370 return the encoded form. Otherwise, return FAIL. */
7371static unsigned int
7372encode_thumb32_immediate (unsigned int val)
09d92015 7373{
c19d1205 7374 unsigned int a, i;
09d92015 7375
9c3c69f2 7376 if (val <= 0xff)
c19d1205 7377 return val;
a737bd4d 7378
9c3c69f2 7379 for (i = 1; i <= 24; i++)
09d92015 7380 {
9c3c69f2
PB
7381 a = val >> i;
7382 if ((val & ~(0xff << i)) == 0)
7383 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7384 }
a737bd4d 7385
c19d1205
ZW
7386 a = val & 0xff;
7387 if (val == ((a << 16) | a))
7388 return 0x100 | a;
7389 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7390 return 0x300 | a;
09d92015 7391
c19d1205
ZW
7392 a = val & 0xff00;
7393 if (val == ((a << 16) | a))
7394 return 0x200 | (a >> 8);
a737bd4d 7395
c19d1205 7396 return FAIL;
09d92015 7397}
5287ad62 7398/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7399
7400static void
5287ad62
JB
7401encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7402{
7403 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7404 && reg > 15)
7405 {
b1cc4aeb 7406 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7407 {
7408 if (thumb_mode)
7409 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7410 fpu_vfp_ext_d32);
7411 else
7412 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7413 fpu_vfp_ext_d32);
7414 }
5287ad62 7415 else
477330fc
RM
7416 {
7417 first_error (_("D register out of range for selected VFP version"));
7418 return;
7419 }
5287ad62
JB
7420 }
7421
c19d1205 7422 switch (pos)
09d92015 7423 {
c19d1205
ZW
7424 case VFP_REG_Sd:
7425 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7426 break;
7427
7428 case VFP_REG_Sn:
7429 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7430 break;
7431
7432 case VFP_REG_Sm:
7433 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7434 break;
7435
5287ad62
JB
7436 case VFP_REG_Dd:
7437 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7438 break;
5f4273c7 7439
5287ad62
JB
7440 case VFP_REG_Dn:
7441 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7442 break;
5f4273c7 7443
5287ad62
JB
7444 case VFP_REG_Dm:
7445 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7446 break;
7447
c19d1205
ZW
7448 default:
7449 abort ();
09d92015 7450 }
09d92015
MM
7451}
7452
c19d1205 7453/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7454 if any, is handled by md_apply_fix. */
09d92015 7455static void
c19d1205 7456encode_arm_shift (int i)
09d92015 7457{
008a97ef
RL
7458 /* register-shifted register. */
7459 if (inst.operands[i].immisreg)
7460 {
bf355b69
MR
7461 int op_index;
7462 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7463 {
5689c942
RL
7464 /* Check the operand only when it's presented. In pre-UAL syntax,
7465 if the destination register is the same as the first operand, two
7466 register form of the instruction can be used. */
bf355b69
MR
7467 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7468 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7469 as_warn (UNPRED_REG ("r15"));
7470 }
7471
7472 if (inst.operands[i].imm == REG_PC)
7473 as_warn (UNPRED_REG ("r15"));
7474 }
7475
c19d1205
ZW
7476 if (inst.operands[i].shift_kind == SHIFT_RRX)
7477 inst.instruction |= SHIFT_ROR << 5;
7478 else
09d92015 7479 {
c19d1205
ZW
7480 inst.instruction |= inst.operands[i].shift_kind << 5;
7481 if (inst.operands[i].immisreg)
7482 {
7483 inst.instruction |= SHIFT_BY_REG;
7484 inst.instruction |= inst.operands[i].imm << 8;
7485 }
7486 else
7487 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7488 }
c19d1205 7489}
09d92015 7490
c19d1205
ZW
7491static void
7492encode_arm_shifter_operand (int i)
7493{
7494 if (inst.operands[i].isreg)
09d92015 7495 {
c19d1205
ZW
7496 inst.instruction |= inst.operands[i].reg;
7497 encode_arm_shift (i);
09d92015 7498 }
c19d1205 7499 else
a415b1cd
JB
7500 {
7501 inst.instruction |= INST_IMMEDIATE;
7502 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7503 inst.instruction |= inst.operands[i].imm;
7504 }
09d92015
MM
7505}
7506
c19d1205 7507/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7508static void
c19d1205 7509encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7510{
2b2f5df9
NC
7511 /* PR 14260:
7512 Generate an error if the operand is not a register. */
7513 constraint (!inst.operands[i].isreg,
7514 _("Instruction does not support =N addresses"));
7515
c19d1205 7516 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7517
c19d1205 7518 if (inst.operands[i].preind)
09d92015 7519 {
c19d1205
ZW
7520 if (is_t)
7521 {
7522 inst.error = _("instruction does not accept preindexed addressing");
7523 return;
7524 }
7525 inst.instruction |= PRE_INDEX;
7526 if (inst.operands[i].writeback)
7527 inst.instruction |= WRITE_BACK;
09d92015 7528
c19d1205
ZW
7529 }
7530 else if (inst.operands[i].postind)
7531 {
9c2799c2 7532 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7533 if (is_t)
7534 inst.instruction |= WRITE_BACK;
7535 }
7536 else /* unindexed - only for coprocessor */
09d92015 7537 {
c19d1205 7538 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7539 return;
7540 }
7541
c19d1205
ZW
7542 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7543 && (((inst.instruction & 0x000f0000) >> 16)
7544 == ((inst.instruction & 0x0000f000) >> 12)))
7545 as_warn ((inst.instruction & LOAD_BIT)
7546 ? _("destination register same as write-back base")
7547 : _("source register same as write-back base"));
09d92015
MM
7548}
7549
c19d1205
ZW
7550/* inst.operands[i] was set up by parse_address. Encode it into an
7551 ARM-format mode 2 load or store instruction. If is_t is true,
7552 reject forms that cannot be used with a T instruction (i.e. not
7553 post-indexed). */
a737bd4d 7554static void
c19d1205 7555encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7556{
5be8be5d
DG
7557 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7558
c19d1205 7559 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7560
c19d1205 7561 if (inst.operands[i].immisreg)
09d92015 7562 {
5be8be5d
DG
7563 constraint ((inst.operands[i].imm == REG_PC
7564 || (is_pc && inst.operands[i].writeback)),
7565 BAD_PC_ADDRESSING);
c19d1205
ZW
7566 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7567 inst.instruction |= inst.operands[i].imm;
7568 if (!inst.operands[i].negative)
7569 inst.instruction |= INDEX_UP;
7570 if (inst.operands[i].shifted)
7571 {
7572 if (inst.operands[i].shift_kind == SHIFT_RRX)
7573 inst.instruction |= SHIFT_ROR << 5;
7574 else
7575 {
7576 inst.instruction |= inst.operands[i].shift_kind << 5;
7577 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7578 }
7579 }
09d92015 7580 }
c19d1205 7581 else /* immediate offset in inst.reloc */
09d92015 7582 {
5be8be5d
DG
7583 if (is_pc && !inst.reloc.pc_rel)
7584 {
7585 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7586
7587 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7588 cannot use PC in addressing.
7589 PC cannot be used in writeback addressing, either. */
7590 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7591 BAD_PC_ADDRESSING);
23a10334 7592
dc5ec521 7593 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7594 if (warn_on_deprecated
7595 && !is_load
7596 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7597 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7598 }
7599
c19d1205 7600 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7601 {
7602 /* Prefer + for zero encoded value. */
7603 if (!inst.operands[i].negative)
7604 inst.instruction |= INDEX_UP;
7605 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7606 }
09d92015 7607 }
09d92015
MM
7608}
7609
c19d1205
ZW
7610/* inst.operands[i] was set up by parse_address. Encode it into an
7611 ARM-format mode 3 load or store instruction. Reject forms that
7612 cannot be used with such instructions. If is_t is true, reject
7613 forms that cannot be used with a T instruction (i.e. not
7614 post-indexed). */
7615static void
7616encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7617{
c19d1205 7618 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7619 {
c19d1205
ZW
7620 inst.error = _("instruction does not accept scaled register index");
7621 return;
09d92015 7622 }
a737bd4d 7623
c19d1205 7624 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7625
c19d1205
ZW
7626 if (inst.operands[i].immisreg)
7627 {
5be8be5d 7628 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7629 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7630 BAD_PC_ADDRESSING);
eb9f3f00
JB
7631 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7632 BAD_PC_WRITEBACK);
c19d1205
ZW
7633 inst.instruction |= inst.operands[i].imm;
7634 if (!inst.operands[i].negative)
7635 inst.instruction |= INDEX_UP;
7636 }
7637 else /* immediate offset in inst.reloc */
7638 {
5be8be5d
DG
7639 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7640 && inst.operands[i].writeback),
7641 BAD_PC_WRITEBACK);
c19d1205
ZW
7642 inst.instruction |= HWOFFSET_IMM;
7643 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7644 {
7645 /* Prefer + for zero encoded value. */
7646 if (!inst.operands[i].negative)
7647 inst.instruction |= INDEX_UP;
7648
7649 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7650 }
c19d1205 7651 }
a737bd4d
NC
7652}
7653
8335d6aa
JW
7654/* Write immediate bits [7:0] to the following locations:
7655
7656 |28/24|23 19|18 16|15 4|3 0|
7657 | 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|
7658
7659 This function is used by VMOV/VMVN/VORR/VBIC. */
7660
7661static void
7662neon_write_immbits (unsigned immbits)
7663{
7664 inst.instruction |= immbits & 0xf;
7665 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7666 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7667}
7668
7669/* Invert low-order SIZE bits of XHI:XLO. */
7670
7671static void
7672neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7673{
7674 unsigned immlo = xlo ? *xlo : 0;
7675 unsigned immhi = xhi ? *xhi : 0;
7676
7677 switch (size)
7678 {
7679 case 8:
7680 immlo = (~immlo) & 0xff;
7681 break;
7682
7683 case 16:
7684 immlo = (~immlo) & 0xffff;
7685 break;
7686
7687 case 64:
7688 immhi = (~immhi) & 0xffffffff;
7689 /* fall through. */
7690
7691 case 32:
7692 immlo = (~immlo) & 0xffffffff;
7693 break;
7694
7695 default:
7696 abort ();
7697 }
7698
7699 if (xlo)
7700 *xlo = immlo;
7701
7702 if (xhi)
7703 *xhi = immhi;
7704}
7705
7706/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7707 A, B, C, D. */
09d92015 7708
c19d1205 7709static int
8335d6aa 7710neon_bits_same_in_bytes (unsigned imm)
09d92015 7711{
8335d6aa
JW
7712 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7713 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7714 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7715 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7716}
a737bd4d 7717
8335d6aa 7718/* For immediate of above form, return 0bABCD. */
09d92015 7719
8335d6aa
JW
7720static unsigned
7721neon_squash_bits (unsigned imm)
7722{
7723 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7724 | ((imm & 0x01000000) >> 21);
7725}
7726
7727/* Compress quarter-float representation to 0b...000 abcdefgh. */
7728
7729static unsigned
7730neon_qfloat_bits (unsigned imm)
7731{
7732 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7733}
7734
7735/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7736 the instruction. *OP is passed as the initial value of the op field, and
7737 may be set to a different value depending on the constant (i.e.
7738 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7739 MVN). If the immediate looks like a repeated pattern then also
7740 try smaller element sizes. */
7741
7742static int
7743neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7744 unsigned *immbits, int *op, int size,
7745 enum neon_el_type type)
7746{
7747 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7748 float. */
7749 if (type == NT_float && !float_p)
7750 return FAIL;
7751
7752 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7753 {
8335d6aa
JW
7754 if (size != 32 || *op == 1)
7755 return FAIL;
7756 *immbits = neon_qfloat_bits (immlo);
7757 return 0xf;
7758 }
7759
7760 if (size == 64)
7761 {
7762 if (neon_bits_same_in_bytes (immhi)
7763 && neon_bits_same_in_bytes (immlo))
c19d1205 7764 {
8335d6aa
JW
7765 if (*op == 1)
7766 return FAIL;
7767 *immbits = (neon_squash_bits (immhi) << 4)
7768 | neon_squash_bits (immlo);
7769 *op = 1;
7770 return 0xe;
c19d1205 7771 }
a737bd4d 7772
8335d6aa
JW
7773 if (immhi != immlo)
7774 return FAIL;
7775 }
a737bd4d 7776
8335d6aa 7777 if (size >= 32)
09d92015 7778 {
8335d6aa 7779 if (immlo == (immlo & 0x000000ff))
c19d1205 7780 {
8335d6aa
JW
7781 *immbits = immlo;
7782 return 0x0;
c19d1205 7783 }
8335d6aa 7784 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7785 {
8335d6aa
JW
7786 *immbits = immlo >> 8;
7787 return 0x2;
c19d1205 7788 }
8335d6aa
JW
7789 else if (immlo == (immlo & 0x00ff0000))
7790 {
7791 *immbits = immlo >> 16;
7792 return 0x4;
7793 }
7794 else if (immlo == (immlo & 0xff000000))
7795 {
7796 *immbits = immlo >> 24;
7797 return 0x6;
7798 }
7799 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7800 {
7801 *immbits = (immlo >> 8) & 0xff;
7802 return 0xc;
7803 }
7804 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7805 {
7806 *immbits = (immlo >> 16) & 0xff;
7807 return 0xd;
7808 }
7809
7810 if ((immlo & 0xffff) != (immlo >> 16))
7811 return FAIL;
7812 immlo &= 0xffff;
09d92015 7813 }
a737bd4d 7814
8335d6aa 7815 if (size >= 16)
4962c51a 7816 {
8335d6aa
JW
7817 if (immlo == (immlo & 0x000000ff))
7818 {
7819 *immbits = immlo;
7820 return 0x8;
7821 }
7822 else if (immlo == (immlo & 0x0000ff00))
7823 {
7824 *immbits = immlo >> 8;
7825 return 0xa;
7826 }
7827
7828 if ((immlo & 0xff) != (immlo >> 8))
7829 return FAIL;
7830 immlo &= 0xff;
4962c51a
MS
7831 }
7832
8335d6aa
JW
7833 if (immlo == (immlo & 0x000000ff))
7834 {
7835 /* Don't allow MVN with 8-bit immediate. */
7836 if (*op == 1)
7837 return FAIL;
7838 *immbits = immlo;
7839 return 0xe;
7840 }
26d97720 7841
8335d6aa 7842 return FAIL;
c19d1205 7843}
a737bd4d 7844
5fc177c8 7845#if defined BFD_HOST_64_BIT
ba592044
AM
7846/* Returns TRUE if double precision value V may be cast
7847 to single precision without loss of accuracy. */
7848
7849static bfd_boolean
5fc177c8 7850is_double_a_single (bfd_int64_t v)
ba592044 7851{
5fc177c8 7852 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7853 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7854
7855 return (exp == 0 || exp == 0x7FF
7856 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7857 && (mantissa & 0x1FFFFFFFl) == 0;
7858}
7859
3739860c 7860/* Returns a double precision value casted to single precision
ba592044
AM
7861 (ignoring the least significant bits in exponent and mantissa). */
7862
7863static int
5fc177c8 7864double_to_single (bfd_int64_t v)
ba592044
AM
7865{
7866 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7867 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7868 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7869
7870 if (exp == 0x7FF)
7871 exp = 0xFF;
7872 else
7873 {
7874 exp = exp - 1023 + 127;
7875 if (exp >= 0xFF)
7876 {
7877 /* Infinity. */
7878 exp = 0x7F;
7879 mantissa = 0;
7880 }
7881 else if (exp < 0)
7882 {
7883 /* No denormalized numbers. */
7884 exp = 0;
7885 mantissa = 0;
7886 }
7887 }
7888 mantissa >>= 29;
7889 return (sign << 31) | (exp << 23) | mantissa;
7890}
5fc177c8 7891#endif /* BFD_HOST_64_BIT */
ba592044 7892
8335d6aa
JW
7893enum lit_type
7894{
7895 CONST_THUMB,
7896 CONST_ARM,
7897 CONST_VEC
7898};
7899
ba592044
AM
7900static void do_vfp_nsyn_opcode (const char *);
7901
c19d1205
ZW
7902/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7903 Determine whether it can be performed with a move instruction; if
7904 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7905 return TRUE; if it can't, convert inst.instruction to a literal-pool
7906 load and return FALSE. If this is not a valid thing to do in the
7907 current context, set inst.error and return TRUE.
a737bd4d 7908
c19d1205
ZW
7909 inst.operands[i] describes the destination register. */
7910
c921be7d 7911static bfd_boolean
8335d6aa 7912move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7913{
53365c0d 7914 unsigned long tbit;
8335d6aa
JW
7915 bfd_boolean thumb_p = (t == CONST_THUMB);
7916 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7917
7918 if (thumb_p)
7919 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7920 else
7921 tbit = LOAD_BIT;
7922
7923 if ((inst.instruction & tbit) == 0)
09d92015 7924 {
c19d1205 7925 inst.error = _("invalid pseudo operation");
c921be7d 7926 return TRUE;
09d92015 7927 }
ba592044 7928
8335d6aa
JW
7929 if (inst.reloc.exp.X_op != O_constant
7930 && inst.reloc.exp.X_op != O_symbol
7931 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7932 {
7933 inst.error = _("constant expression expected");
c921be7d 7934 return TRUE;
09d92015 7935 }
ba592044
AM
7936
7937 if (inst.reloc.exp.X_op == O_constant
7938 || inst.reloc.exp.X_op == O_big)
8335d6aa 7939 {
5fc177c8
NC
7940#if defined BFD_HOST_64_BIT
7941 bfd_int64_t v;
7942#else
ba592044 7943 offsetT v;
5fc177c8 7944#endif
ba592044 7945 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7946 {
ba592044
AM
7947 LITTLENUM_TYPE w[X_PRECISION];
7948 LITTLENUM_TYPE * l;
7949
7950 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7951 {
ba592044
AM
7952 gen_to_words (w, X_PRECISION, E_PRECISION);
7953 l = w;
7954 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7955 }
ba592044
AM
7956 else
7957 l = generic_bignum;
3739860c 7958
5fc177c8
NC
7959#if defined BFD_HOST_64_BIT
7960 v =
7961 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7962 << LITTLENUM_NUMBER_OF_BITS)
7963 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7964 << LITTLENUM_NUMBER_OF_BITS)
7965 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7966 << LITTLENUM_NUMBER_OF_BITS)
7967 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7968#else
ba592044
AM
7969 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7970 | (l[0] & LITTLENUM_MASK);
5fc177c8 7971#endif
8335d6aa 7972 }
ba592044
AM
7973 else
7974 v = inst.reloc.exp.X_add_number;
7975
7976 if (!inst.operands[i].issingle)
8335d6aa 7977 {
12569877 7978 if (thumb_p)
8335d6aa 7979 {
53445554
TP
7980 /* LDR should not use lead in a flag-setting instruction being
7981 chosen so we do not check whether movs can be used. */
12569877 7982
53445554 7983 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 7984 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
7985 && inst.operands[i].reg != 13
7986 && inst.operands[i].reg != 15)
12569877 7987 {
fc289b0a
TP
7988 /* Check if on thumb2 it can be done with a mov.w, mvn or
7989 movw instruction. */
12569877
AM
7990 unsigned int newimm;
7991 bfd_boolean isNegated;
7992
7993 newimm = encode_thumb32_immediate (v);
7994 if (newimm != (unsigned int) FAIL)
7995 isNegated = FALSE;
7996 else
7997 {
582cfe03 7998 newimm = encode_thumb32_immediate (~v);
12569877
AM
7999 if (newimm != (unsigned int) FAIL)
8000 isNegated = TRUE;
8001 }
8002
fc289b0a
TP
8003 /* The number can be loaded with a mov.w or mvn
8004 instruction. */
ff8646ee
TP
8005 if (newimm != (unsigned int) FAIL
8006 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8007 {
fc289b0a 8008 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8009 | (inst.operands[i].reg << 8));
fc289b0a 8010 /* Change to MOVN. */
582cfe03 8011 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8012 inst.instruction |= (newimm & 0x800) << 15;
8013 inst.instruction |= (newimm & 0x700) << 4;
8014 inst.instruction |= (newimm & 0x0ff);
8015 return TRUE;
8016 }
fc289b0a 8017 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8018 else if ((v & ~0xFFFF) == 0
8019 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8020 {
582cfe03 8021 int imm = v & 0xFFFF;
12569877 8022
582cfe03 8023 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8024 inst.instruction |= (inst.operands[i].reg << 8);
8025 inst.instruction |= (imm & 0xf000) << 4;
8026 inst.instruction |= (imm & 0x0800) << 15;
8027 inst.instruction |= (imm & 0x0700) << 4;
8028 inst.instruction |= (imm & 0x00ff);
8029 return TRUE;
8030 }
8031 }
8335d6aa 8032 }
12569877 8033 else if (arm_p)
ba592044
AM
8034 {
8035 int value = encode_arm_immediate (v);
12569877 8036
ba592044
AM
8037 if (value != FAIL)
8038 {
8039 /* This can be done with a mov instruction. */
8040 inst.instruction &= LITERAL_MASK;
8041 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8042 inst.instruction |= value & 0xfff;
8043 return TRUE;
8044 }
8335d6aa 8045
ba592044
AM
8046 value = encode_arm_immediate (~ v);
8047 if (value != FAIL)
8048 {
8049 /* This can be done with a mvn instruction. */
8050 inst.instruction &= LITERAL_MASK;
8051 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8052 inst.instruction |= value & 0xfff;
8053 return TRUE;
8054 }
8055 }
934c2632 8056 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8057 {
ba592044
AM
8058 int op = 0;
8059 unsigned immbits = 0;
8060 unsigned immlo = inst.operands[1].imm;
8061 unsigned immhi = inst.operands[1].regisimm
8062 ? inst.operands[1].reg
8063 : inst.reloc.exp.X_unsigned
8064 ? 0
8065 : ((bfd_int64_t)((int) immlo)) >> 32;
8066 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8067 &op, 64, NT_invtype);
8068
8069 if (cmode == FAIL)
8070 {
8071 neon_invert_size (&immlo, &immhi, 64);
8072 op = !op;
8073 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8074 &op, 64, NT_invtype);
8075 }
8076
8077 if (cmode != FAIL)
8078 {
8079 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8080 | (1 << 23)
8081 | (cmode << 8)
8082 | (op << 5)
8083 | (1 << 4);
8084
8085 /* Fill other bits in vmov encoding for both thumb and arm. */
8086 if (thumb_mode)
eff0bc54 8087 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8088 else
eff0bc54 8089 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8090 neon_write_immbits (immbits);
8091 return TRUE;
8092 }
8335d6aa
JW
8093 }
8094 }
8335d6aa 8095
ba592044
AM
8096 if (t == CONST_VEC)
8097 {
8098 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8099 if (inst.operands[i].issingle
8100 && is_quarter_float (inst.operands[1].imm)
8101 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8102 {
ba592044
AM
8103 inst.operands[1].imm =
8104 neon_qfloat_bits (v);
8105 do_vfp_nsyn_opcode ("fconsts");
8106 return TRUE;
8335d6aa 8107 }
5fc177c8
NC
8108
8109 /* If our host does not support a 64-bit type then we cannot perform
8110 the following optimization. This mean that there will be a
8111 discrepancy between the output produced by an assembler built for
8112 a 32-bit-only host and the output produced from a 64-bit host, but
8113 this cannot be helped. */
8114#if defined BFD_HOST_64_BIT
ba592044
AM
8115 else if (!inst.operands[1].issingle
8116 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8117 {
ba592044
AM
8118 if (is_double_a_single (v)
8119 && is_quarter_float (double_to_single (v)))
8120 {
8121 inst.operands[1].imm =
8122 neon_qfloat_bits (double_to_single (v));
8123 do_vfp_nsyn_opcode ("fconstd");
8124 return TRUE;
8125 }
8335d6aa 8126 }
5fc177c8 8127#endif
8335d6aa
JW
8128 }
8129 }
8130
8131 if (add_to_lit_pool ((!inst.operands[i].isvec
8132 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8133 return TRUE;
8134
8135 inst.operands[1].reg = REG_PC;
8136 inst.operands[1].isreg = 1;
8137 inst.operands[1].preind = 1;
8138 inst.reloc.pc_rel = 1;
8139 inst.reloc.type = (thumb_p
8140 ? BFD_RELOC_ARM_THUMB_OFFSET
8141 : (mode_3
8142 ? BFD_RELOC_ARM_HWLITERAL
8143 : BFD_RELOC_ARM_LITERAL));
8144 return FALSE;
8145}
8146
8147/* inst.operands[i] was set up by parse_address. Encode it into an
8148 ARM-format instruction. Reject all forms which cannot be encoded
8149 into a coprocessor load/store instruction. If wb_ok is false,
8150 reject use of writeback; if unind_ok is false, reject use of
8151 unindexed addressing. If reloc_override is not 0, use it instead
8152 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8153 (in which case it is preserved). */
8154
8155static int
8156encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8157{
8158 if (!inst.operands[i].isreg)
8159 {
99b2a2dd
NC
8160 /* PR 18256 */
8161 if (! inst.operands[0].isvec)
8162 {
8163 inst.error = _("invalid co-processor operand");
8164 return FAIL;
8165 }
8335d6aa
JW
8166 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8167 return SUCCESS;
8168 }
8169
8170 inst.instruction |= inst.operands[i].reg << 16;
8171
8172 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8173
8174 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8175 {
8176 gas_assert (!inst.operands[i].writeback);
8177 if (!unind_ok)
8178 {
8179 inst.error = _("instruction does not support unindexed addressing");
8180 return FAIL;
8181 }
8182 inst.instruction |= inst.operands[i].imm;
8183 inst.instruction |= INDEX_UP;
8184 return SUCCESS;
8185 }
8186
8187 if (inst.operands[i].preind)
8188 inst.instruction |= PRE_INDEX;
8189
8190 if (inst.operands[i].writeback)
09d92015 8191 {
8335d6aa 8192 if (inst.operands[i].reg == REG_PC)
c19d1205 8193 {
8335d6aa
JW
8194 inst.error = _("pc may not be used with write-back");
8195 return FAIL;
c19d1205 8196 }
8335d6aa 8197 if (!wb_ok)
c19d1205 8198 {
8335d6aa
JW
8199 inst.error = _("instruction does not support writeback");
8200 return FAIL;
c19d1205 8201 }
8335d6aa 8202 inst.instruction |= WRITE_BACK;
09d92015
MM
8203 }
8204
8335d6aa
JW
8205 if (reloc_override)
8206 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8207 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8208 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8209 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8210 {
8335d6aa
JW
8211 if (thumb_mode)
8212 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8213 else
8214 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8215 }
8335d6aa
JW
8216
8217 /* Prefer + for zero encoded value. */
8218 if (!inst.operands[i].negative)
8219 inst.instruction |= INDEX_UP;
8220
8221 return SUCCESS;
09d92015
MM
8222}
8223
5f4273c7 8224/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8225 First some generics; their names are taken from the conventional
8226 bit positions for register arguments in ARM format instructions. */
09d92015 8227
a737bd4d 8228static void
c19d1205 8229do_noargs (void)
09d92015 8230{
c19d1205 8231}
a737bd4d 8232
c19d1205
ZW
8233static void
8234do_rd (void)
8235{
8236 inst.instruction |= inst.operands[0].reg << 12;
8237}
a737bd4d 8238
16a1fa25
TP
8239static void
8240do_rn (void)
8241{
8242 inst.instruction |= inst.operands[0].reg << 16;
8243}
8244
c19d1205
ZW
8245static void
8246do_rd_rm (void)
8247{
8248 inst.instruction |= inst.operands[0].reg << 12;
8249 inst.instruction |= inst.operands[1].reg;
8250}
09d92015 8251
9eb6c0f1
MGD
8252static void
8253do_rm_rn (void)
8254{
8255 inst.instruction |= inst.operands[0].reg;
8256 inst.instruction |= inst.operands[1].reg << 16;
8257}
8258
c19d1205
ZW
8259static void
8260do_rd_rn (void)
8261{
8262 inst.instruction |= inst.operands[0].reg << 12;
8263 inst.instruction |= inst.operands[1].reg << 16;
8264}
a737bd4d 8265
c19d1205
ZW
8266static void
8267do_rn_rd (void)
8268{
8269 inst.instruction |= inst.operands[0].reg << 16;
8270 inst.instruction |= inst.operands[1].reg << 12;
8271}
09d92015 8272
4ed7ed8d
TP
8273static void
8274do_tt (void)
8275{
8276 inst.instruction |= inst.operands[0].reg << 8;
8277 inst.instruction |= inst.operands[1].reg << 16;
8278}
8279
59d09be6
MGD
8280static bfd_boolean
8281check_obsolete (const arm_feature_set *feature, const char *msg)
8282{
8283 if (ARM_CPU_IS_ANY (cpu_variant))
8284 {
5c3696f8 8285 as_tsktsk ("%s", msg);
59d09be6
MGD
8286 return TRUE;
8287 }
8288 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8289 {
8290 as_bad ("%s", msg);
8291 return TRUE;
8292 }
8293
8294 return FALSE;
8295}
8296
c19d1205
ZW
8297static void
8298do_rd_rm_rn (void)
8299{
9a64e435 8300 unsigned Rn = inst.operands[2].reg;
708587a4 8301 /* Enforce restrictions on SWP instruction. */
9a64e435 8302 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8303 {
8304 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8305 _("Rn must not overlap other operands"));
8306
59d09be6
MGD
8307 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8308 */
8309 if (!check_obsolete (&arm_ext_v8,
8310 _("swp{b} use is obsoleted for ARMv8 and later"))
8311 && warn_on_deprecated
8312 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8313 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8314 }
59d09be6 8315
c19d1205
ZW
8316 inst.instruction |= inst.operands[0].reg << 12;
8317 inst.instruction |= inst.operands[1].reg;
9a64e435 8318 inst.instruction |= Rn << 16;
c19d1205 8319}
09d92015 8320
c19d1205
ZW
8321static void
8322do_rd_rn_rm (void)
8323{
8324 inst.instruction |= inst.operands[0].reg << 12;
8325 inst.instruction |= inst.operands[1].reg << 16;
8326 inst.instruction |= inst.operands[2].reg;
8327}
a737bd4d 8328
c19d1205
ZW
8329static void
8330do_rm_rd_rn (void)
8331{
5be8be5d
DG
8332 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8333 constraint (((inst.reloc.exp.X_op != O_constant
8334 && inst.reloc.exp.X_op != O_illegal)
8335 || inst.reloc.exp.X_add_number != 0),
8336 BAD_ADDR_MODE);
c19d1205
ZW
8337 inst.instruction |= inst.operands[0].reg;
8338 inst.instruction |= inst.operands[1].reg << 12;
8339 inst.instruction |= inst.operands[2].reg << 16;
8340}
09d92015 8341
c19d1205
ZW
8342static void
8343do_imm0 (void)
8344{
8345 inst.instruction |= inst.operands[0].imm;
8346}
09d92015 8347
c19d1205
ZW
8348static void
8349do_rd_cpaddr (void)
8350{
8351 inst.instruction |= inst.operands[0].reg << 12;
8352 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8353}
a737bd4d 8354
c19d1205
ZW
8355/* ARM instructions, in alphabetical order by function name (except
8356 that wrapper functions appear immediately after the function they
8357 wrap). */
09d92015 8358
c19d1205
ZW
8359/* This is a pseudo-op of the form "adr rd, label" to be converted
8360 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8361
8362static void
c19d1205 8363do_adr (void)
09d92015 8364{
c19d1205 8365 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8366
c19d1205
ZW
8367 /* Frag hacking will turn this into a sub instruction if the offset turns
8368 out to be negative. */
8369 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8370 inst.reloc.pc_rel = 1;
2fc8bdac 8371 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8372
8373 if (inst.reloc.exp.X_op == O_symbol
8374 && inst.reloc.exp.X_add_symbol != NULL
8375 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8376 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8377 inst.reloc.exp.X_add_number += 1;
c19d1205 8378}
b99bd4ef 8379
c19d1205
ZW
8380/* This is a pseudo-op of the form "adrl rd, label" to be converted
8381 into a relative address of the form:
8382 add rd, pc, #low(label-.-8)"
8383 add rd, rd, #high(label-.-8)" */
b99bd4ef 8384
c19d1205
ZW
8385static void
8386do_adrl (void)
8387{
8388 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8389
c19d1205
ZW
8390 /* Frag hacking will turn this into a sub instruction if the offset turns
8391 out to be negative. */
8392 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8393 inst.reloc.pc_rel = 1;
8394 inst.size = INSN_SIZE * 2;
2fc8bdac 8395 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8396
8397 if (inst.reloc.exp.X_op == O_symbol
8398 && inst.reloc.exp.X_add_symbol != NULL
8399 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8400 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8401 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8402}
8403
b99bd4ef 8404static void
c19d1205 8405do_arit (void)
b99bd4ef 8406{
a9f02af8
MG
8407 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8408 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8409 THUMB1_RELOC_ONLY);
c19d1205
ZW
8410 if (!inst.operands[1].present)
8411 inst.operands[1].reg = inst.operands[0].reg;
8412 inst.instruction |= inst.operands[0].reg << 12;
8413 inst.instruction |= inst.operands[1].reg << 16;
8414 encode_arm_shifter_operand (2);
8415}
b99bd4ef 8416
62b3e311
PB
8417static void
8418do_barrier (void)
8419{
8420 if (inst.operands[0].present)
ccb84d65 8421 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8422 else
8423 inst.instruction |= 0xf;
8424}
8425
c19d1205
ZW
8426static void
8427do_bfc (void)
8428{
8429 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8430 constraint (msb > 32, _("bit-field extends past end of register"));
8431 /* The instruction encoding stores the LSB and MSB,
8432 not the LSB and width. */
8433 inst.instruction |= inst.operands[0].reg << 12;
8434 inst.instruction |= inst.operands[1].imm << 7;
8435 inst.instruction |= (msb - 1) << 16;
8436}
b99bd4ef 8437
c19d1205
ZW
8438static void
8439do_bfi (void)
8440{
8441 unsigned int msb;
b99bd4ef 8442
c19d1205
ZW
8443 /* #0 in second position is alternative syntax for bfc, which is
8444 the same instruction but with REG_PC in the Rm field. */
8445 if (!inst.operands[1].isreg)
8446 inst.operands[1].reg = REG_PC;
b99bd4ef 8447
c19d1205
ZW
8448 msb = inst.operands[2].imm + inst.operands[3].imm;
8449 constraint (msb > 32, _("bit-field extends past end of register"));
8450 /* The instruction encoding stores the LSB and MSB,
8451 not the LSB and width. */
8452 inst.instruction |= inst.operands[0].reg << 12;
8453 inst.instruction |= inst.operands[1].reg;
8454 inst.instruction |= inst.operands[2].imm << 7;
8455 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8456}
8457
b99bd4ef 8458static void
c19d1205 8459do_bfx (void)
b99bd4ef 8460{
c19d1205
ZW
8461 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8462 _("bit-field extends past end of register"));
8463 inst.instruction |= inst.operands[0].reg << 12;
8464 inst.instruction |= inst.operands[1].reg;
8465 inst.instruction |= inst.operands[2].imm << 7;
8466 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8467}
09d92015 8468
c19d1205
ZW
8469/* ARM V5 breakpoint instruction (argument parse)
8470 BKPT <16 bit unsigned immediate>
8471 Instruction is not conditional.
8472 The bit pattern given in insns[] has the COND_ALWAYS condition,
8473 and it is an error if the caller tried to override that. */
b99bd4ef 8474
c19d1205
ZW
8475static void
8476do_bkpt (void)
8477{
8478 /* Top 12 of 16 bits to bits 19:8. */
8479 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8480
c19d1205
ZW
8481 /* Bottom 4 of 16 bits to bits 3:0. */
8482 inst.instruction |= inst.operands[0].imm & 0xf;
8483}
09d92015 8484
c19d1205
ZW
8485static void
8486encode_branch (int default_reloc)
8487{
8488 if (inst.operands[0].hasreloc)
8489 {
0855e32b
NS
8490 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8491 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8492 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8493 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8494 ? BFD_RELOC_ARM_PLT32
8495 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8496 }
b99bd4ef 8497 else
9ae92b05 8498 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8499 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8500}
8501
b99bd4ef 8502static void
c19d1205 8503do_branch (void)
b99bd4ef 8504{
39b41c9c
PB
8505#ifdef OBJ_ELF
8506 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8507 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8508 else
8509#endif
8510 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8511}
8512
8513static void
8514do_bl (void)
8515{
8516#ifdef OBJ_ELF
8517 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8518 {
8519 if (inst.cond == COND_ALWAYS)
8520 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8521 else
8522 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8523 }
8524 else
8525#endif
8526 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8527}
b99bd4ef 8528
c19d1205
ZW
8529/* ARM V5 branch-link-exchange instruction (argument parse)
8530 BLX <target_addr> ie BLX(1)
8531 BLX{<condition>} <Rm> ie BLX(2)
8532 Unfortunately, there are two different opcodes for this mnemonic.
8533 So, the insns[].value is not used, and the code here zaps values
8534 into inst.instruction.
8535 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8536
c19d1205
ZW
8537static void
8538do_blx (void)
8539{
8540 if (inst.operands[0].isreg)
b99bd4ef 8541 {
c19d1205
ZW
8542 /* Arg is a register; the opcode provided by insns[] is correct.
8543 It is not illegal to do "blx pc", just useless. */
8544 if (inst.operands[0].reg == REG_PC)
8545 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8546
c19d1205
ZW
8547 inst.instruction |= inst.operands[0].reg;
8548 }
8549 else
b99bd4ef 8550 {
c19d1205 8551 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8552 conditionally, and the opcode must be adjusted.
8553 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8554 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8555 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8556 inst.instruction = 0xfa000000;
267bf995 8557 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8558 }
c19d1205
ZW
8559}
8560
8561static void
8562do_bx (void)
8563{
845b51d6
PB
8564 bfd_boolean want_reloc;
8565
c19d1205
ZW
8566 if (inst.operands[0].reg == REG_PC)
8567 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8568
c19d1205 8569 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8570 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8571 it is for ARMv4t or earlier. */
8572 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8573 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8574 want_reloc = TRUE;
8575
5ad34203 8576#ifdef OBJ_ELF
845b51d6 8577 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8578#endif
584206db 8579 want_reloc = FALSE;
845b51d6
PB
8580
8581 if (want_reloc)
8582 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8583}
8584
c19d1205
ZW
8585
8586/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8587
8588static void
c19d1205 8589do_bxj (void)
a737bd4d 8590{
c19d1205
ZW
8591 if (inst.operands[0].reg == REG_PC)
8592 as_tsktsk (_("use of r15 in bxj is not really useful"));
8593
8594 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8595}
8596
c19d1205
ZW
8597/* Co-processor data operation:
8598 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8599 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8600static void
8601do_cdp (void)
8602{
8603 inst.instruction |= inst.operands[0].reg << 8;
8604 inst.instruction |= inst.operands[1].imm << 20;
8605 inst.instruction |= inst.operands[2].reg << 12;
8606 inst.instruction |= inst.operands[3].reg << 16;
8607 inst.instruction |= inst.operands[4].reg;
8608 inst.instruction |= inst.operands[5].imm << 5;
8609}
a737bd4d
NC
8610
8611static void
c19d1205 8612do_cmp (void)
a737bd4d 8613{
c19d1205
ZW
8614 inst.instruction |= inst.operands[0].reg << 16;
8615 encode_arm_shifter_operand (1);
a737bd4d
NC
8616}
8617
c19d1205
ZW
8618/* Transfer between coprocessor and ARM registers.
8619 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8620 MRC2
8621 MCR{cond}
8622 MCR2
8623
8624 No special properties. */
09d92015 8625
dcbd0d71
MGD
8626struct deprecated_coproc_regs_s
8627{
8628 unsigned cp;
8629 int opc1;
8630 unsigned crn;
8631 unsigned crm;
8632 int opc2;
8633 arm_feature_set deprecated;
8634 arm_feature_set obsoleted;
8635 const char *dep_msg;
8636 const char *obs_msg;
8637};
8638
8639#define DEPR_ACCESS_V8 \
8640 N_("This coprocessor register access is deprecated in ARMv8")
8641
8642/* Table of all deprecated coprocessor registers. */
8643static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8644{
8645 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8646 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8647 DEPR_ACCESS_V8, NULL},
8648 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8649 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8650 DEPR_ACCESS_V8, NULL},
8651 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8652 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8653 DEPR_ACCESS_V8, NULL},
8654 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8655 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8656 DEPR_ACCESS_V8, NULL},
8657 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8658 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8659 DEPR_ACCESS_V8, NULL},
8660};
8661
8662#undef DEPR_ACCESS_V8
8663
8664static const size_t deprecated_coproc_reg_count =
8665 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8666
09d92015 8667static void
c19d1205 8668do_co_reg (void)
09d92015 8669{
fdfde340 8670 unsigned Rd;
dcbd0d71 8671 size_t i;
fdfde340
JM
8672
8673 Rd = inst.operands[2].reg;
8674 if (thumb_mode)
8675 {
8676 if (inst.instruction == 0xee000010
8677 || inst.instruction == 0xfe000010)
8678 /* MCR, MCR2 */
8679 reject_bad_reg (Rd);
5c8ed6a4 8680 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8681 /* MRC, MRC2 */
8682 constraint (Rd == REG_SP, BAD_SP);
8683 }
8684 else
8685 {
8686 /* MCR */
8687 if (inst.instruction == 0xe000010)
8688 constraint (Rd == REG_PC, BAD_PC);
8689 }
8690
dcbd0d71
MGD
8691 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8692 {
8693 const struct deprecated_coproc_regs_s *r =
8694 deprecated_coproc_regs + i;
8695
8696 if (inst.operands[0].reg == r->cp
8697 && inst.operands[1].imm == r->opc1
8698 && inst.operands[3].reg == r->crn
8699 && inst.operands[4].reg == r->crm
8700 && inst.operands[5].imm == r->opc2)
8701 {
b10bf8c5 8702 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8703 && warn_on_deprecated
dcbd0d71 8704 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8705 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8706 }
8707 }
fdfde340 8708
c19d1205
ZW
8709 inst.instruction |= inst.operands[0].reg << 8;
8710 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8711 inst.instruction |= Rd << 12;
c19d1205
ZW
8712 inst.instruction |= inst.operands[3].reg << 16;
8713 inst.instruction |= inst.operands[4].reg;
8714 inst.instruction |= inst.operands[5].imm << 5;
8715}
09d92015 8716
c19d1205
ZW
8717/* Transfer between coprocessor register and pair of ARM registers.
8718 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8719 MCRR2
8720 MRRC{cond}
8721 MRRC2
b99bd4ef 8722
c19d1205 8723 Two XScale instructions are special cases of these:
09d92015 8724
c19d1205
ZW
8725 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8726 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8727
5f4273c7 8728 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8729
c19d1205
ZW
8730static void
8731do_co_reg2c (void)
8732{
fdfde340
JM
8733 unsigned Rd, Rn;
8734
8735 Rd = inst.operands[2].reg;
8736 Rn = inst.operands[3].reg;
8737
8738 if (thumb_mode)
8739 {
8740 reject_bad_reg (Rd);
8741 reject_bad_reg (Rn);
8742 }
8743 else
8744 {
8745 constraint (Rd == REG_PC, BAD_PC);
8746 constraint (Rn == REG_PC, BAD_PC);
8747 }
8748
873f10f0
TC
8749 /* Only check the MRRC{2} variants. */
8750 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8751 {
8752 /* If Rd == Rn, error that the operation is
8753 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8754 constraint (Rd == Rn, BAD_OVERLAP);
8755 }
8756
c19d1205
ZW
8757 inst.instruction |= inst.operands[0].reg << 8;
8758 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8759 inst.instruction |= Rd << 12;
8760 inst.instruction |= Rn << 16;
c19d1205 8761 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8762}
8763
c19d1205
ZW
8764static void
8765do_cpsi (void)
8766{
8767 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8768 if (inst.operands[1].present)
8769 {
8770 inst.instruction |= CPSI_MMOD;
8771 inst.instruction |= inst.operands[1].imm;
8772 }
c19d1205 8773}
b99bd4ef 8774
62b3e311
PB
8775static void
8776do_dbg (void)
8777{
8778 inst.instruction |= inst.operands[0].imm;
8779}
8780
eea54501
MGD
8781static void
8782do_div (void)
8783{
8784 unsigned Rd, Rn, Rm;
8785
8786 Rd = inst.operands[0].reg;
8787 Rn = (inst.operands[1].present
8788 ? inst.operands[1].reg : Rd);
8789 Rm = inst.operands[2].reg;
8790
8791 constraint ((Rd == REG_PC), BAD_PC);
8792 constraint ((Rn == REG_PC), BAD_PC);
8793 constraint ((Rm == REG_PC), BAD_PC);
8794
8795 inst.instruction |= Rd << 16;
8796 inst.instruction |= Rn << 0;
8797 inst.instruction |= Rm << 8;
8798}
8799
b99bd4ef 8800static void
c19d1205 8801do_it (void)
b99bd4ef 8802{
c19d1205 8803 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8804 process it to do the validation as if in
8805 thumb mode, just in case the code gets
8806 assembled for thumb using the unified syntax. */
8807
c19d1205 8808 inst.size = 0;
e07e6e58
NC
8809 if (unified_syntax)
8810 {
8811 set_it_insn_type (IT_INSN);
8812 now_it.mask = (inst.instruction & 0xf) | 0x10;
8813 now_it.cc = inst.operands[0].imm;
8814 }
09d92015 8815}
b99bd4ef 8816
6530b175
NC
8817/* If there is only one register in the register list,
8818 then return its register number. Otherwise return -1. */
8819static int
8820only_one_reg_in_list (int range)
8821{
8822 int i = ffs (range) - 1;
8823 return (i > 15 || range != (1 << i)) ? -1 : i;
8824}
8825
09d92015 8826static void
6530b175 8827encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8828{
c19d1205
ZW
8829 int base_reg = inst.operands[0].reg;
8830 int range = inst.operands[1].imm;
6530b175 8831 int one_reg;
ea6ef066 8832
c19d1205
ZW
8833 inst.instruction |= base_reg << 16;
8834 inst.instruction |= range;
ea6ef066 8835
c19d1205
ZW
8836 if (inst.operands[1].writeback)
8837 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8838
c19d1205 8839 if (inst.operands[0].writeback)
ea6ef066 8840 {
c19d1205
ZW
8841 inst.instruction |= WRITE_BACK;
8842 /* Check for unpredictable uses of writeback. */
8843 if (inst.instruction & LOAD_BIT)
09d92015 8844 {
c19d1205
ZW
8845 /* Not allowed in LDM type 2. */
8846 if ((inst.instruction & LDM_TYPE_2_OR_3)
8847 && ((range & (1 << REG_PC)) == 0))
8848 as_warn (_("writeback of base register is UNPREDICTABLE"));
8849 /* Only allowed if base reg not in list for other types. */
8850 else if (range & (1 << base_reg))
8851 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8852 }
8853 else /* STM. */
8854 {
8855 /* Not allowed for type 2. */
8856 if (inst.instruction & LDM_TYPE_2_OR_3)
8857 as_warn (_("writeback of base register is UNPREDICTABLE"));
8858 /* Only allowed if base reg not in list, or first in list. */
8859 else if ((range & (1 << base_reg))
8860 && (range & ((1 << base_reg) - 1)))
8861 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8862 }
ea6ef066 8863 }
6530b175
NC
8864
8865 /* If PUSH/POP has only one register, then use the A2 encoding. */
8866 one_reg = only_one_reg_in_list (range);
8867 if (from_push_pop_mnem && one_reg >= 0)
8868 {
8869 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8870
8871 inst.instruction &= A_COND_MASK;
8872 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8873 inst.instruction |= one_reg << 12;
8874 }
8875}
8876
8877static void
8878do_ldmstm (void)
8879{
8880 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8881}
8882
c19d1205
ZW
8883/* ARMv5TE load-consecutive (argument parse)
8884 Mode is like LDRH.
8885
8886 LDRccD R, mode
8887 STRccD R, mode. */
8888
a737bd4d 8889static void
c19d1205 8890do_ldrd (void)
a737bd4d 8891{
c19d1205 8892 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8893 _("first transfer register must be even"));
c19d1205
ZW
8894 constraint (inst.operands[1].present
8895 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8896 _("can only transfer two consecutive registers"));
c19d1205
ZW
8897 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8898 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8899
c19d1205
ZW
8900 if (!inst.operands[1].present)
8901 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8902
c56791bb
RE
8903 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8904 register and the first register written; we have to diagnose
8905 overlap between the base and the second register written here. */
ea6ef066 8906
c56791bb
RE
8907 if (inst.operands[2].reg == inst.operands[1].reg
8908 && (inst.operands[2].writeback || inst.operands[2].postind))
8909 as_warn (_("base register written back, and overlaps "
8910 "second transfer register"));
b05fe5cf 8911
c56791bb
RE
8912 if (!(inst.instruction & V4_STR_BIT))
8913 {
c19d1205 8914 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8915 destination (even if not write-back). */
8916 if (inst.operands[2].immisreg
8917 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8918 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8919 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8920 }
c19d1205
ZW
8921 inst.instruction |= inst.operands[0].reg << 12;
8922 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8923}
8924
8925static void
c19d1205 8926do_ldrex (void)
b05fe5cf 8927{
c19d1205
ZW
8928 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8929 || inst.operands[1].postind || inst.operands[1].writeback
8930 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8931 || inst.operands[1].negative
8932 /* This can arise if the programmer has written
8933 strex rN, rM, foo
8934 or if they have mistakenly used a register name as the last
8935 operand, eg:
8936 strex rN, rM, rX
8937 It is very difficult to distinguish between these two cases
8938 because "rX" might actually be a label. ie the register
8939 name has been occluded by a symbol of the same name. So we
8940 just generate a general 'bad addressing mode' type error
8941 message and leave it up to the programmer to discover the
8942 true cause and fix their mistake. */
8943 || (inst.operands[1].reg == REG_PC),
8944 BAD_ADDR_MODE);
b05fe5cf 8945
c19d1205
ZW
8946 constraint (inst.reloc.exp.X_op != O_constant
8947 || inst.reloc.exp.X_add_number != 0,
8948 _("offset must be zero in ARM encoding"));
b05fe5cf 8949
5be8be5d
DG
8950 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8951
c19d1205
ZW
8952 inst.instruction |= inst.operands[0].reg << 12;
8953 inst.instruction |= inst.operands[1].reg << 16;
8954 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8955}
8956
8957static void
c19d1205 8958do_ldrexd (void)
b05fe5cf 8959{
c19d1205
ZW
8960 constraint (inst.operands[0].reg % 2 != 0,
8961 _("even register required"));
8962 constraint (inst.operands[1].present
8963 && inst.operands[1].reg != inst.operands[0].reg + 1,
8964 _("can only load two consecutive registers"));
8965 /* If op 1 were present and equal to PC, this function wouldn't
8966 have been called in the first place. */
8967 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8968
c19d1205
ZW
8969 inst.instruction |= inst.operands[0].reg << 12;
8970 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8971}
8972
1be5fd2e
NC
8973/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8974 which is not a multiple of four is UNPREDICTABLE. */
8975static void
8976check_ldr_r15_aligned (void)
8977{
8978 constraint (!(inst.operands[1].immisreg)
8979 && (inst.operands[0].reg == REG_PC
8980 && inst.operands[1].reg == REG_PC
8981 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 8982 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
8983}
8984
b05fe5cf 8985static void
c19d1205 8986do_ldst (void)
b05fe5cf 8987{
c19d1205
ZW
8988 inst.instruction |= inst.operands[0].reg << 12;
8989 if (!inst.operands[1].isreg)
8335d6aa 8990 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8991 return;
c19d1205 8992 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8993 check_ldr_r15_aligned ();
b05fe5cf
ZW
8994}
8995
8996static void
c19d1205 8997do_ldstt (void)
b05fe5cf 8998{
c19d1205
ZW
8999 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9000 reject [Rn,...]. */
9001 if (inst.operands[1].preind)
b05fe5cf 9002 {
bd3ba5d1
NC
9003 constraint (inst.reloc.exp.X_op != O_constant
9004 || inst.reloc.exp.X_add_number != 0,
c19d1205 9005 _("this instruction requires a post-indexed address"));
b05fe5cf 9006
c19d1205
ZW
9007 inst.operands[1].preind = 0;
9008 inst.operands[1].postind = 1;
9009 inst.operands[1].writeback = 1;
b05fe5cf 9010 }
c19d1205
ZW
9011 inst.instruction |= inst.operands[0].reg << 12;
9012 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9013}
b05fe5cf 9014
c19d1205 9015/* Halfword and signed-byte load/store operations. */
b05fe5cf 9016
c19d1205
ZW
9017static void
9018do_ldstv4 (void)
9019{
ff4a8d2b 9020 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9021 inst.instruction |= inst.operands[0].reg << 12;
9022 if (!inst.operands[1].isreg)
8335d6aa 9023 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9024 return;
c19d1205 9025 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9026}
9027
9028static void
c19d1205 9029do_ldsttv4 (void)
b05fe5cf 9030{
c19d1205
ZW
9031 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9032 reject [Rn,...]. */
9033 if (inst.operands[1].preind)
b05fe5cf 9034 {
bd3ba5d1
NC
9035 constraint (inst.reloc.exp.X_op != O_constant
9036 || inst.reloc.exp.X_add_number != 0,
c19d1205 9037 _("this instruction requires a post-indexed address"));
b05fe5cf 9038
c19d1205
ZW
9039 inst.operands[1].preind = 0;
9040 inst.operands[1].postind = 1;
9041 inst.operands[1].writeback = 1;
b05fe5cf 9042 }
c19d1205
ZW
9043 inst.instruction |= inst.operands[0].reg << 12;
9044 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9045}
b05fe5cf 9046
c19d1205
ZW
9047/* Co-processor register load/store.
9048 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9049static void
9050do_lstc (void)
9051{
9052 inst.instruction |= inst.operands[0].reg << 8;
9053 inst.instruction |= inst.operands[1].reg << 12;
9054 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9055}
9056
b05fe5cf 9057static void
c19d1205 9058do_mlas (void)
b05fe5cf 9059{
8fb9d7b9 9060 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9061 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9062 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9063 && !(inst.instruction & 0x00400000))
8fb9d7b9 9064 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9065
c19d1205
ZW
9066 inst.instruction |= inst.operands[0].reg << 16;
9067 inst.instruction |= inst.operands[1].reg;
9068 inst.instruction |= inst.operands[2].reg << 8;
9069 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9070}
b05fe5cf 9071
c19d1205
ZW
9072static void
9073do_mov (void)
9074{
a9f02af8
MG
9075 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9076 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9077 THUMB1_RELOC_ONLY);
c19d1205
ZW
9078 inst.instruction |= inst.operands[0].reg << 12;
9079 encode_arm_shifter_operand (1);
9080}
b05fe5cf 9081
c19d1205
ZW
9082/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9083static void
9084do_mov16 (void)
9085{
b6895b4f
PB
9086 bfd_vma imm;
9087 bfd_boolean top;
9088
9089 top = (inst.instruction & 0x00400000) != 0;
9090 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9091 _(":lower16: not allowed in this instruction"));
b6895b4f 9092 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9093 _(":upper16: not allowed in this instruction"));
c19d1205 9094 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9095 if (inst.reloc.type == BFD_RELOC_UNUSED)
9096 {
9097 imm = inst.reloc.exp.X_add_number;
9098 /* The value is in two pieces: 0:11, 16:19. */
9099 inst.instruction |= (imm & 0x00000fff);
9100 inst.instruction |= (imm & 0x0000f000) << 4;
9101 }
b05fe5cf 9102}
b99bd4ef 9103
037e8744
JB
9104static int
9105do_vfp_nsyn_mrs (void)
9106{
9107 if (inst.operands[0].isvec)
9108 {
9109 if (inst.operands[1].reg != 1)
477330fc 9110 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9111 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9112 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9113 do_vfp_nsyn_opcode ("fmstat");
9114 }
9115 else if (inst.operands[1].isvec)
9116 do_vfp_nsyn_opcode ("fmrx");
9117 else
9118 return FAIL;
5f4273c7 9119
037e8744
JB
9120 return SUCCESS;
9121}
9122
9123static int
9124do_vfp_nsyn_msr (void)
9125{
9126 if (inst.operands[0].isvec)
9127 do_vfp_nsyn_opcode ("fmxr");
9128 else
9129 return FAIL;
9130
9131 return SUCCESS;
9132}
9133
f7c21dc7
NC
9134static void
9135do_vmrs (void)
9136{
9137 unsigned Rt = inst.operands[0].reg;
fa94de6b 9138
16d02dc9 9139 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9140 {
9141 inst.error = BAD_SP;
9142 return;
9143 }
9144
40c7d507
RR
9145 /* MVFR2 is only valid at ARMv8-A. */
9146 if (inst.operands[1].reg == 5)
9147 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9148 _(BAD_FPU));
9149
f7c21dc7 9150 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9151 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9152 {
9153 inst.error = BAD_PC;
9154 return;
9155 }
9156
16d02dc9
JB
9157 /* If we get through parsing the register name, we just insert the number
9158 generated into the instruction without further validation. */
9159 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9160 inst.instruction |= (Rt << 12);
9161}
9162
9163static void
9164do_vmsr (void)
9165{
9166 unsigned Rt = inst.operands[1].reg;
fa94de6b 9167
f7c21dc7
NC
9168 if (thumb_mode)
9169 reject_bad_reg (Rt);
9170 else if (Rt == REG_PC)
9171 {
9172 inst.error = BAD_PC;
9173 return;
9174 }
9175
40c7d507
RR
9176 /* MVFR2 is only valid for ARMv8-A. */
9177 if (inst.operands[0].reg == 5)
9178 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9179 _(BAD_FPU));
9180
16d02dc9
JB
9181 /* If we get through parsing the register name, we just insert the number
9182 generated into the instruction without further validation. */
9183 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9184 inst.instruction |= (Rt << 12);
9185}
9186
b99bd4ef 9187static void
c19d1205 9188do_mrs (void)
b99bd4ef 9189{
90ec0d68
MGD
9190 unsigned br;
9191
037e8744
JB
9192 if (do_vfp_nsyn_mrs () == SUCCESS)
9193 return;
9194
ff4a8d2b 9195 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9196 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9197
9198 if (inst.operands[1].isreg)
9199 {
9200 br = inst.operands[1].reg;
9201 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9202 as_bad (_("bad register for mrs"));
9203 }
9204 else
9205 {
9206 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9207 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9208 != (PSR_c|PSR_f),
d2cd1205 9209 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9210 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9211 }
9212
9213 inst.instruction |= br;
c19d1205 9214}
b99bd4ef 9215
c19d1205
ZW
9216/* Two possible forms:
9217 "{C|S}PSR_<field>, Rm",
9218 "{C|S}PSR_f, #expression". */
b99bd4ef 9219
c19d1205
ZW
9220static void
9221do_msr (void)
9222{
037e8744
JB
9223 if (do_vfp_nsyn_msr () == SUCCESS)
9224 return;
9225
c19d1205
ZW
9226 inst.instruction |= inst.operands[0].imm;
9227 if (inst.operands[1].isreg)
9228 inst.instruction |= inst.operands[1].reg;
9229 else
b99bd4ef 9230 {
c19d1205
ZW
9231 inst.instruction |= INST_IMMEDIATE;
9232 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9233 inst.reloc.pc_rel = 0;
b99bd4ef 9234 }
b99bd4ef
NC
9235}
9236
c19d1205
ZW
9237static void
9238do_mul (void)
a737bd4d 9239{
ff4a8d2b
NC
9240 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9241
c19d1205
ZW
9242 if (!inst.operands[2].present)
9243 inst.operands[2].reg = inst.operands[0].reg;
9244 inst.instruction |= inst.operands[0].reg << 16;
9245 inst.instruction |= inst.operands[1].reg;
9246 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9247
8fb9d7b9
MS
9248 if (inst.operands[0].reg == inst.operands[1].reg
9249 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9250 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9251}
9252
c19d1205
ZW
9253/* Long Multiply Parser
9254 UMULL RdLo, RdHi, Rm, Rs
9255 SMULL RdLo, RdHi, Rm, Rs
9256 UMLAL RdLo, RdHi, Rm, Rs
9257 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9258
9259static void
c19d1205 9260do_mull (void)
b99bd4ef 9261{
c19d1205
ZW
9262 inst.instruction |= inst.operands[0].reg << 12;
9263 inst.instruction |= inst.operands[1].reg << 16;
9264 inst.instruction |= inst.operands[2].reg;
9265 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9266
682b27ad
PB
9267 /* rdhi and rdlo must be different. */
9268 if (inst.operands[0].reg == inst.operands[1].reg)
9269 as_tsktsk (_("rdhi and rdlo must be different"));
9270
9271 /* rdhi, rdlo and rm must all be different before armv6. */
9272 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9273 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9274 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9275 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9276}
b99bd4ef 9277
c19d1205
ZW
9278static void
9279do_nop (void)
9280{
e7495e45
NS
9281 if (inst.operands[0].present
9282 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9283 {
9284 /* Architectural NOP hints are CPSR sets with no bits selected. */
9285 inst.instruction &= 0xf0000000;
e7495e45
NS
9286 inst.instruction |= 0x0320f000;
9287 if (inst.operands[0].present)
9288 inst.instruction |= inst.operands[0].imm;
c19d1205 9289 }
b99bd4ef
NC
9290}
9291
c19d1205
ZW
9292/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9293 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9294 Condition defaults to COND_ALWAYS.
9295 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9296
9297static void
c19d1205 9298do_pkhbt (void)
b99bd4ef 9299{
c19d1205
ZW
9300 inst.instruction |= inst.operands[0].reg << 12;
9301 inst.instruction |= inst.operands[1].reg << 16;
9302 inst.instruction |= inst.operands[2].reg;
9303 if (inst.operands[3].present)
9304 encode_arm_shift (3);
9305}
b99bd4ef 9306
c19d1205 9307/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9308
c19d1205
ZW
9309static void
9310do_pkhtb (void)
9311{
9312 if (!inst.operands[3].present)
b99bd4ef 9313 {
c19d1205
ZW
9314 /* If the shift specifier is omitted, turn the instruction
9315 into pkhbt rd, rm, rn. */
9316 inst.instruction &= 0xfff00010;
9317 inst.instruction |= inst.operands[0].reg << 12;
9318 inst.instruction |= inst.operands[1].reg;
9319 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9320 }
9321 else
9322 {
c19d1205
ZW
9323 inst.instruction |= inst.operands[0].reg << 12;
9324 inst.instruction |= inst.operands[1].reg << 16;
9325 inst.instruction |= inst.operands[2].reg;
9326 encode_arm_shift (3);
b99bd4ef
NC
9327 }
9328}
9329
c19d1205 9330/* ARMv5TE: Preload-Cache
60e5ef9f 9331 MP Extensions: Preload for write
c19d1205 9332
60e5ef9f 9333 PLD(W) <addr_mode>
c19d1205
ZW
9334
9335 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9336
9337static void
c19d1205 9338do_pld (void)
b99bd4ef 9339{
c19d1205
ZW
9340 constraint (!inst.operands[0].isreg,
9341 _("'[' expected after PLD mnemonic"));
9342 constraint (inst.operands[0].postind,
9343 _("post-indexed expression used in preload instruction"));
9344 constraint (inst.operands[0].writeback,
9345 _("writeback used in preload instruction"));
9346 constraint (!inst.operands[0].preind,
9347 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9348 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9349}
b99bd4ef 9350
62b3e311
PB
9351/* ARMv7: PLI <addr_mode> */
9352static void
9353do_pli (void)
9354{
9355 constraint (!inst.operands[0].isreg,
9356 _("'[' expected after PLI mnemonic"));
9357 constraint (inst.operands[0].postind,
9358 _("post-indexed expression used in preload instruction"));
9359 constraint (inst.operands[0].writeback,
9360 _("writeback used in preload instruction"));
9361 constraint (!inst.operands[0].preind,
9362 _("unindexed addressing used in preload instruction"));
9363 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9364 inst.instruction &= ~PRE_INDEX;
9365}
9366
c19d1205
ZW
9367static void
9368do_push_pop (void)
9369{
5e0d7f77
MP
9370 constraint (inst.operands[0].writeback,
9371 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9372 inst.operands[1] = inst.operands[0];
9373 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9374 inst.operands[0].isreg = 1;
9375 inst.operands[0].writeback = 1;
9376 inst.operands[0].reg = REG_SP;
6530b175 9377 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9378}
b99bd4ef 9379
c19d1205
ZW
9380/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9381 word at the specified address and the following word
9382 respectively.
9383 Unconditionally executed.
9384 Error if Rn is R15. */
b99bd4ef 9385
c19d1205
ZW
9386static void
9387do_rfe (void)
9388{
9389 inst.instruction |= inst.operands[0].reg << 16;
9390 if (inst.operands[0].writeback)
9391 inst.instruction |= WRITE_BACK;
9392}
b99bd4ef 9393
c19d1205 9394/* ARM V6 ssat (argument parse). */
b99bd4ef 9395
c19d1205
ZW
9396static void
9397do_ssat (void)
9398{
9399 inst.instruction |= inst.operands[0].reg << 12;
9400 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9401 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9402
c19d1205
ZW
9403 if (inst.operands[3].present)
9404 encode_arm_shift (3);
b99bd4ef
NC
9405}
9406
c19d1205 9407/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9408
9409static void
c19d1205 9410do_usat (void)
b99bd4ef 9411{
c19d1205
ZW
9412 inst.instruction |= inst.operands[0].reg << 12;
9413 inst.instruction |= inst.operands[1].imm << 16;
9414 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9415
c19d1205
ZW
9416 if (inst.operands[3].present)
9417 encode_arm_shift (3);
b99bd4ef
NC
9418}
9419
c19d1205 9420/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9421
9422static void
c19d1205 9423do_ssat16 (void)
09d92015 9424{
c19d1205
ZW
9425 inst.instruction |= inst.operands[0].reg << 12;
9426 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9427 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9428}
9429
c19d1205
ZW
9430static void
9431do_usat16 (void)
a737bd4d 9432{
c19d1205
ZW
9433 inst.instruction |= inst.operands[0].reg << 12;
9434 inst.instruction |= inst.operands[1].imm << 16;
9435 inst.instruction |= inst.operands[2].reg;
9436}
a737bd4d 9437
c19d1205
ZW
9438/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9439 preserving the other bits.
a737bd4d 9440
c19d1205
ZW
9441 setend <endian_specifier>, where <endian_specifier> is either
9442 BE or LE. */
a737bd4d 9443
c19d1205
ZW
9444static void
9445do_setend (void)
9446{
12e37cbc
MGD
9447 if (warn_on_deprecated
9448 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9449 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9450
c19d1205
ZW
9451 if (inst.operands[0].imm)
9452 inst.instruction |= 0x200;
a737bd4d
NC
9453}
9454
9455static void
c19d1205 9456do_shift (void)
a737bd4d 9457{
c19d1205
ZW
9458 unsigned int Rm = (inst.operands[1].present
9459 ? inst.operands[1].reg
9460 : inst.operands[0].reg);
a737bd4d 9461
c19d1205
ZW
9462 inst.instruction |= inst.operands[0].reg << 12;
9463 inst.instruction |= Rm;
9464 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9465 {
c19d1205
ZW
9466 inst.instruction |= inst.operands[2].reg << 8;
9467 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9468 /* PR 12854: Error on extraneous shifts. */
9469 constraint (inst.operands[2].shifted,
9470 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9471 }
9472 else
c19d1205 9473 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9474}
9475
09d92015 9476static void
3eb17e6b 9477do_smc (void)
09d92015 9478{
3eb17e6b 9479 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9480 inst.reloc.pc_rel = 0;
09d92015
MM
9481}
9482
90ec0d68
MGD
9483static void
9484do_hvc (void)
9485{
9486 inst.reloc.type = BFD_RELOC_ARM_HVC;
9487 inst.reloc.pc_rel = 0;
9488}
9489
09d92015 9490static void
c19d1205 9491do_swi (void)
09d92015 9492{
c19d1205
ZW
9493 inst.reloc.type = BFD_RELOC_ARM_SWI;
9494 inst.reloc.pc_rel = 0;
09d92015
MM
9495}
9496
ddfded2f
MW
9497static void
9498do_setpan (void)
9499{
9500 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9501 _("selected processor does not support SETPAN instruction"));
9502
9503 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9504}
9505
9506static void
9507do_t_setpan (void)
9508{
9509 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9510 _("selected processor does not support SETPAN instruction"));
9511
9512 inst.instruction |= (inst.operands[0].imm << 3);
9513}
9514
c19d1205
ZW
9515/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9516 SMLAxy{cond} Rd,Rm,Rs,Rn
9517 SMLAWy{cond} Rd,Rm,Rs,Rn
9518 Error if any register is R15. */
e16bb312 9519
c19d1205
ZW
9520static void
9521do_smla (void)
e16bb312 9522{
c19d1205
ZW
9523 inst.instruction |= inst.operands[0].reg << 16;
9524 inst.instruction |= inst.operands[1].reg;
9525 inst.instruction |= inst.operands[2].reg << 8;
9526 inst.instruction |= inst.operands[3].reg << 12;
9527}
a737bd4d 9528
c19d1205
ZW
9529/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9530 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9531 Error if any register is R15.
9532 Warning if Rdlo == Rdhi. */
a737bd4d 9533
c19d1205
ZW
9534static void
9535do_smlal (void)
9536{
9537 inst.instruction |= inst.operands[0].reg << 12;
9538 inst.instruction |= inst.operands[1].reg << 16;
9539 inst.instruction |= inst.operands[2].reg;
9540 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9541
c19d1205
ZW
9542 if (inst.operands[0].reg == inst.operands[1].reg)
9543 as_tsktsk (_("rdhi and rdlo must be different"));
9544}
a737bd4d 9545
c19d1205
ZW
9546/* ARM V5E (El Segundo) signed-multiply (argument parse)
9547 SMULxy{cond} Rd,Rm,Rs
9548 Error if any register is R15. */
a737bd4d 9549
c19d1205
ZW
9550static void
9551do_smul (void)
9552{
9553 inst.instruction |= inst.operands[0].reg << 16;
9554 inst.instruction |= inst.operands[1].reg;
9555 inst.instruction |= inst.operands[2].reg << 8;
9556}
a737bd4d 9557
b6702015
PB
9558/* ARM V6 srs (argument parse). The variable fields in the encoding are
9559 the same for both ARM and Thumb-2. */
a737bd4d 9560
c19d1205
ZW
9561static void
9562do_srs (void)
9563{
b6702015
PB
9564 int reg;
9565
9566 if (inst.operands[0].present)
9567 {
9568 reg = inst.operands[0].reg;
fdfde340 9569 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9570 }
9571 else
fdfde340 9572 reg = REG_SP;
b6702015
PB
9573
9574 inst.instruction |= reg << 16;
9575 inst.instruction |= inst.operands[1].imm;
9576 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9577 inst.instruction |= WRITE_BACK;
9578}
a737bd4d 9579
c19d1205 9580/* ARM V6 strex (argument parse). */
a737bd4d 9581
c19d1205
ZW
9582static void
9583do_strex (void)
9584{
9585 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9586 || inst.operands[2].postind || inst.operands[2].writeback
9587 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9588 || inst.operands[2].negative
9589 /* See comment in do_ldrex(). */
9590 || (inst.operands[2].reg == REG_PC),
9591 BAD_ADDR_MODE);
a737bd4d 9592
c19d1205
ZW
9593 constraint (inst.operands[0].reg == inst.operands[1].reg
9594 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9595
c19d1205
ZW
9596 constraint (inst.reloc.exp.X_op != O_constant
9597 || inst.reloc.exp.X_add_number != 0,
9598 _("offset must be zero in ARM encoding"));
a737bd4d 9599
c19d1205
ZW
9600 inst.instruction |= inst.operands[0].reg << 12;
9601 inst.instruction |= inst.operands[1].reg;
9602 inst.instruction |= inst.operands[2].reg << 16;
9603 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9604}
9605
877807f8
NC
9606static void
9607do_t_strexbh (void)
9608{
9609 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9610 || inst.operands[2].postind || inst.operands[2].writeback
9611 || inst.operands[2].immisreg || inst.operands[2].shifted
9612 || inst.operands[2].negative,
9613 BAD_ADDR_MODE);
9614
9615 constraint (inst.operands[0].reg == inst.operands[1].reg
9616 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9617
9618 do_rm_rd_rn ();
9619}
9620
e16bb312 9621static void
c19d1205 9622do_strexd (void)
e16bb312 9623{
c19d1205
ZW
9624 constraint (inst.operands[1].reg % 2 != 0,
9625 _("even register required"));
9626 constraint (inst.operands[2].present
9627 && inst.operands[2].reg != inst.operands[1].reg + 1,
9628 _("can only store two consecutive registers"));
9629 /* If op 2 were present and equal to PC, this function wouldn't
9630 have been called in the first place. */
9631 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9632
c19d1205
ZW
9633 constraint (inst.operands[0].reg == inst.operands[1].reg
9634 || inst.operands[0].reg == inst.operands[1].reg + 1
9635 || inst.operands[0].reg == inst.operands[3].reg,
9636 BAD_OVERLAP);
e16bb312 9637
c19d1205
ZW
9638 inst.instruction |= inst.operands[0].reg << 12;
9639 inst.instruction |= inst.operands[1].reg;
9640 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9641}
9642
9eb6c0f1
MGD
9643/* ARM V8 STRL. */
9644static void
4b8c8c02 9645do_stlex (void)
9eb6c0f1
MGD
9646{
9647 constraint (inst.operands[0].reg == inst.operands[1].reg
9648 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9649
9650 do_rd_rm_rn ();
9651}
9652
9653static void
4b8c8c02 9654do_t_stlex (void)
9eb6c0f1
MGD
9655{
9656 constraint (inst.operands[0].reg == inst.operands[1].reg
9657 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9658
9659 do_rm_rd_rn ();
9660}
9661
c19d1205
ZW
9662/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9663 extends it to 32-bits, and adds the result to a value in another
9664 register. You can specify a rotation by 0, 8, 16, or 24 bits
9665 before extracting the 16-bit value.
9666 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9667 Condition defaults to COND_ALWAYS.
9668 Error if any register uses R15. */
9669
e16bb312 9670static void
c19d1205 9671do_sxtah (void)
e16bb312 9672{
c19d1205
ZW
9673 inst.instruction |= inst.operands[0].reg << 12;
9674 inst.instruction |= inst.operands[1].reg << 16;
9675 inst.instruction |= inst.operands[2].reg;
9676 inst.instruction |= inst.operands[3].imm << 10;
9677}
e16bb312 9678
c19d1205 9679/* ARM V6 SXTH.
e16bb312 9680
c19d1205
ZW
9681 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9682 Condition defaults to COND_ALWAYS.
9683 Error if any register uses R15. */
e16bb312
NC
9684
9685static void
c19d1205 9686do_sxth (void)
e16bb312 9687{
c19d1205
ZW
9688 inst.instruction |= inst.operands[0].reg << 12;
9689 inst.instruction |= inst.operands[1].reg;
9690 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9691}
c19d1205
ZW
9692\f
9693/* VFP instructions. In a logical order: SP variant first, monad
9694 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9695
9696static void
c19d1205 9697do_vfp_sp_monadic (void)
e16bb312 9698{
5287ad62
JB
9699 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9700 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9701}
9702
9703static void
c19d1205 9704do_vfp_sp_dyadic (void)
e16bb312 9705{
5287ad62
JB
9706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9707 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9708 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9709}
9710
9711static void
c19d1205 9712do_vfp_sp_compare_z (void)
e16bb312 9713{
5287ad62 9714 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9715}
9716
9717static void
c19d1205 9718do_vfp_dp_sp_cvt (void)
e16bb312 9719{
5287ad62
JB
9720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9721 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9722}
9723
9724static void
c19d1205 9725do_vfp_sp_dp_cvt (void)
e16bb312 9726{
5287ad62
JB
9727 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9728 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9729}
9730
9731static void
c19d1205 9732do_vfp_reg_from_sp (void)
e16bb312 9733{
c19d1205 9734 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9736}
9737
9738static void
c19d1205 9739do_vfp_reg2_from_sp2 (void)
e16bb312 9740{
c19d1205
ZW
9741 constraint (inst.operands[2].imm != 2,
9742 _("only two consecutive VFP SP registers allowed here"));
9743 inst.instruction |= inst.operands[0].reg << 12;
9744 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9745 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9746}
9747
9748static void
c19d1205 9749do_vfp_sp_from_reg (void)
e16bb312 9750{
5287ad62 9751 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9752 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9753}
9754
9755static void
c19d1205 9756do_vfp_sp2_from_reg2 (void)
e16bb312 9757{
c19d1205
ZW
9758 constraint (inst.operands[0].imm != 2,
9759 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9760 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9761 inst.instruction |= inst.operands[1].reg << 12;
9762 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9763}
9764
9765static void
c19d1205 9766do_vfp_sp_ldst (void)
e16bb312 9767{
5287ad62 9768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9769 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9770}
9771
9772static void
c19d1205 9773do_vfp_dp_ldst (void)
e16bb312 9774{
5287ad62 9775 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9776 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9777}
9778
c19d1205 9779
e16bb312 9780static void
c19d1205 9781vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9782{
c19d1205
ZW
9783 if (inst.operands[0].writeback)
9784 inst.instruction |= WRITE_BACK;
9785 else
9786 constraint (ldstm_type != VFP_LDSTMIA,
9787 _("this addressing mode requires base-register writeback"));
9788 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9789 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9790 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9791}
9792
9793static void
c19d1205 9794vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9795{
c19d1205 9796 int count;
e16bb312 9797
c19d1205
ZW
9798 if (inst.operands[0].writeback)
9799 inst.instruction |= WRITE_BACK;
9800 else
9801 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9802 _("this addressing mode requires base-register writeback"));
e16bb312 9803
c19d1205 9804 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9805 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9806
c19d1205
ZW
9807 count = inst.operands[1].imm << 1;
9808 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9809 count += 1;
e16bb312 9810
c19d1205 9811 inst.instruction |= count;
e16bb312
NC
9812}
9813
9814static void
c19d1205 9815do_vfp_sp_ldstmia (void)
e16bb312 9816{
c19d1205 9817 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9818}
9819
9820static void
c19d1205 9821do_vfp_sp_ldstmdb (void)
e16bb312 9822{
c19d1205 9823 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9824}
9825
9826static void
c19d1205 9827do_vfp_dp_ldstmia (void)
e16bb312 9828{
c19d1205 9829 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9830}
9831
9832static void
c19d1205 9833do_vfp_dp_ldstmdb (void)
e16bb312 9834{
c19d1205 9835 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9836}
9837
9838static void
c19d1205 9839do_vfp_xp_ldstmia (void)
e16bb312 9840{
c19d1205
ZW
9841 vfp_dp_ldstm (VFP_LDSTMIAX);
9842}
e16bb312 9843
c19d1205
ZW
9844static void
9845do_vfp_xp_ldstmdb (void)
9846{
9847 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9848}
5287ad62
JB
9849
9850static void
9851do_vfp_dp_rd_rm (void)
9852{
9853 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9854 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9855}
9856
9857static void
9858do_vfp_dp_rn_rd (void)
9859{
9860 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9861 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9862}
9863
9864static void
9865do_vfp_dp_rd_rn (void)
9866{
9867 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9868 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9869}
9870
9871static void
9872do_vfp_dp_rd_rn_rm (void)
9873{
9874 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9875 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9876 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9877}
9878
9879static void
9880do_vfp_dp_rd (void)
9881{
9882 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9883}
9884
9885static void
9886do_vfp_dp_rm_rd_rn (void)
9887{
9888 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9889 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9890 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9891}
9892
9893/* VFPv3 instructions. */
9894static void
9895do_vfp_sp_const (void)
9896{
9897 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9898 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9899 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9900}
9901
9902static void
9903do_vfp_dp_const (void)
9904{
9905 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9906 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9907 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9908}
9909
9910static void
9911vfp_conv (int srcsize)
9912{
5f1af56b
MGD
9913 int immbits = srcsize - inst.operands[1].imm;
9914
fa94de6b
RM
9915 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9916 {
5f1af56b 9917 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9918 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9919 inst.error = _("immediate value out of range, expected range [0, 16]");
9920 return;
9921 }
fa94de6b 9922 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9923 {
9924 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9925 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9926 inst.error = _("immediate value out of range, expected range [1, 32]");
9927 return;
9928 }
9929
5287ad62
JB
9930 inst.instruction |= (immbits & 1) << 5;
9931 inst.instruction |= (immbits >> 1);
9932}
9933
9934static void
9935do_vfp_sp_conv_16 (void)
9936{
9937 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9938 vfp_conv (16);
9939}
9940
9941static void
9942do_vfp_dp_conv_16 (void)
9943{
9944 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9945 vfp_conv (16);
9946}
9947
9948static void
9949do_vfp_sp_conv_32 (void)
9950{
9951 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9952 vfp_conv (32);
9953}
9954
9955static void
9956do_vfp_dp_conv_32 (void)
9957{
9958 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9959 vfp_conv (32);
9960}
c19d1205
ZW
9961\f
9962/* FPA instructions. Also in a logical order. */
e16bb312 9963
c19d1205
ZW
9964static void
9965do_fpa_cmp (void)
9966{
9967 inst.instruction |= inst.operands[0].reg << 16;
9968 inst.instruction |= inst.operands[1].reg;
9969}
b99bd4ef
NC
9970
9971static void
c19d1205 9972do_fpa_ldmstm (void)
b99bd4ef 9973{
c19d1205
ZW
9974 inst.instruction |= inst.operands[0].reg << 12;
9975 switch (inst.operands[1].imm)
9976 {
9977 case 1: inst.instruction |= CP_T_X; break;
9978 case 2: inst.instruction |= CP_T_Y; break;
9979 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9980 case 4: break;
9981 default: abort ();
9982 }
b99bd4ef 9983
c19d1205
ZW
9984 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9985 {
9986 /* The instruction specified "ea" or "fd", so we can only accept
9987 [Rn]{!}. The instruction does not really support stacking or
9988 unstacking, so we have to emulate these by setting appropriate
9989 bits and offsets. */
9990 constraint (inst.reloc.exp.X_op != O_constant
9991 || inst.reloc.exp.X_add_number != 0,
9992 _("this instruction does not support indexing"));
b99bd4ef 9993
c19d1205
ZW
9994 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9995 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9996
c19d1205
ZW
9997 if (!(inst.instruction & INDEX_UP))
9998 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9999
c19d1205
ZW
10000 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10001 {
10002 inst.operands[2].preind = 0;
10003 inst.operands[2].postind = 1;
10004 }
10005 }
b99bd4ef 10006
c19d1205 10007 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10008}
c19d1205
ZW
10009\f
10010/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10011
c19d1205
ZW
10012static void
10013do_iwmmxt_tandorc (void)
10014{
10015 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10016}
b99bd4ef 10017
c19d1205
ZW
10018static void
10019do_iwmmxt_textrc (void)
10020{
10021 inst.instruction |= inst.operands[0].reg << 12;
10022 inst.instruction |= inst.operands[1].imm;
10023}
b99bd4ef
NC
10024
10025static void
c19d1205 10026do_iwmmxt_textrm (void)
b99bd4ef 10027{
c19d1205
ZW
10028 inst.instruction |= inst.operands[0].reg << 12;
10029 inst.instruction |= inst.operands[1].reg << 16;
10030 inst.instruction |= inst.operands[2].imm;
10031}
b99bd4ef 10032
c19d1205
ZW
10033static void
10034do_iwmmxt_tinsr (void)
10035{
10036 inst.instruction |= inst.operands[0].reg << 16;
10037 inst.instruction |= inst.operands[1].reg << 12;
10038 inst.instruction |= inst.operands[2].imm;
10039}
b99bd4ef 10040
c19d1205
ZW
10041static void
10042do_iwmmxt_tmia (void)
10043{
10044 inst.instruction |= inst.operands[0].reg << 5;
10045 inst.instruction |= inst.operands[1].reg;
10046 inst.instruction |= inst.operands[2].reg << 12;
10047}
b99bd4ef 10048
c19d1205
ZW
10049static void
10050do_iwmmxt_waligni (void)
10051{
10052 inst.instruction |= inst.operands[0].reg << 12;
10053 inst.instruction |= inst.operands[1].reg << 16;
10054 inst.instruction |= inst.operands[2].reg;
10055 inst.instruction |= inst.operands[3].imm << 20;
10056}
b99bd4ef 10057
2d447fca
JM
10058static void
10059do_iwmmxt_wmerge (void)
10060{
10061 inst.instruction |= inst.operands[0].reg << 12;
10062 inst.instruction |= inst.operands[1].reg << 16;
10063 inst.instruction |= inst.operands[2].reg;
10064 inst.instruction |= inst.operands[3].imm << 21;
10065}
10066
c19d1205
ZW
10067static void
10068do_iwmmxt_wmov (void)
10069{
10070 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10071 inst.instruction |= inst.operands[0].reg << 12;
10072 inst.instruction |= inst.operands[1].reg << 16;
10073 inst.instruction |= inst.operands[1].reg;
10074}
b99bd4ef 10075
c19d1205
ZW
10076static void
10077do_iwmmxt_wldstbh (void)
10078{
8f06b2d8 10079 int reloc;
c19d1205 10080 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10081 if (thumb_mode)
10082 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10083 else
10084 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10085 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10086}
10087
c19d1205
ZW
10088static void
10089do_iwmmxt_wldstw (void)
10090{
10091 /* RIWR_RIWC clears .isreg for a control register. */
10092 if (!inst.operands[0].isreg)
10093 {
10094 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10095 inst.instruction |= 0xf0000000;
10096 }
b99bd4ef 10097
c19d1205
ZW
10098 inst.instruction |= inst.operands[0].reg << 12;
10099 encode_arm_cp_address (1, TRUE, TRUE, 0);
10100}
b99bd4ef
NC
10101
10102static void
c19d1205 10103do_iwmmxt_wldstd (void)
b99bd4ef 10104{
c19d1205 10105 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10106 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10107 && inst.operands[1].immisreg)
10108 {
10109 inst.instruction &= ~0x1a000ff;
eff0bc54 10110 inst.instruction |= (0xfU << 28);
2d447fca
JM
10111 if (inst.operands[1].preind)
10112 inst.instruction |= PRE_INDEX;
10113 if (!inst.operands[1].negative)
10114 inst.instruction |= INDEX_UP;
10115 if (inst.operands[1].writeback)
10116 inst.instruction |= WRITE_BACK;
10117 inst.instruction |= inst.operands[1].reg << 16;
10118 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10119 inst.instruction |= inst.operands[1].imm;
10120 }
10121 else
10122 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10123}
b99bd4ef 10124
c19d1205
ZW
10125static void
10126do_iwmmxt_wshufh (void)
10127{
10128 inst.instruction |= inst.operands[0].reg << 12;
10129 inst.instruction |= inst.operands[1].reg << 16;
10130 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10131 inst.instruction |= (inst.operands[2].imm & 0x0f);
10132}
b99bd4ef 10133
c19d1205
ZW
10134static void
10135do_iwmmxt_wzero (void)
10136{
10137 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10138 inst.instruction |= inst.operands[0].reg;
10139 inst.instruction |= inst.operands[0].reg << 12;
10140 inst.instruction |= inst.operands[0].reg << 16;
10141}
2d447fca
JM
10142
10143static void
10144do_iwmmxt_wrwrwr_or_imm5 (void)
10145{
10146 if (inst.operands[2].isreg)
10147 do_rd_rn_rm ();
10148 else {
10149 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10150 _("immediate operand requires iWMMXt2"));
10151 do_rd_rn ();
10152 if (inst.operands[2].imm == 0)
10153 {
10154 switch ((inst.instruction >> 20) & 0xf)
10155 {
10156 case 4:
10157 case 5:
10158 case 6:
5f4273c7 10159 case 7:
2d447fca
JM
10160 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10161 inst.operands[2].imm = 16;
10162 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10163 break;
10164 case 8:
10165 case 9:
10166 case 10:
10167 case 11:
10168 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10169 inst.operands[2].imm = 32;
10170 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10171 break;
10172 case 12:
10173 case 13:
10174 case 14:
10175 case 15:
10176 {
10177 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10178 unsigned long wrn;
10179 wrn = (inst.instruction >> 16) & 0xf;
10180 inst.instruction &= 0xff0fff0f;
10181 inst.instruction |= wrn;
10182 /* Bail out here; the instruction is now assembled. */
10183 return;
10184 }
10185 }
10186 }
10187 /* Map 32 -> 0, etc. */
10188 inst.operands[2].imm &= 0x1f;
eff0bc54 10189 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10190 }
10191}
c19d1205
ZW
10192\f
10193/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10194 operations first, then control, shift, and load/store. */
b99bd4ef 10195
c19d1205 10196/* Insns like "foo X,Y,Z". */
b99bd4ef 10197
c19d1205
ZW
10198static void
10199do_mav_triple (void)
10200{
10201 inst.instruction |= inst.operands[0].reg << 16;
10202 inst.instruction |= inst.operands[1].reg;
10203 inst.instruction |= inst.operands[2].reg << 12;
10204}
b99bd4ef 10205
c19d1205
ZW
10206/* Insns like "foo W,X,Y,Z".
10207 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10208
c19d1205
ZW
10209static void
10210do_mav_quad (void)
10211{
10212 inst.instruction |= inst.operands[0].reg << 5;
10213 inst.instruction |= inst.operands[1].reg << 12;
10214 inst.instruction |= inst.operands[2].reg << 16;
10215 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10216}
10217
c19d1205
ZW
10218/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10219static void
10220do_mav_dspsc (void)
a737bd4d 10221{
c19d1205
ZW
10222 inst.instruction |= inst.operands[1].reg << 12;
10223}
a737bd4d 10224
c19d1205
ZW
10225/* Maverick shift immediate instructions.
10226 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10227 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10228
c19d1205
ZW
10229static void
10230do_mav_shift (void)
10231{
10232 int imm = inst.operands[2].imm;
a737bd4d 10233
c19d1205
ZW
10234 inst.instruction |= inst.operands[0].reg << 12;
10235 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10236
c19d1205
ZW
10237 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10238 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10239 Bit 4 should be 0. */
10240 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10241
c19d1205
ZW
10242 inst.instruction |= imm;
10243}
10244\f
10245/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10246
c19d1205
ZW
10247/* Xscale multiply-accumulate (argument parse)
10248 MIAcc acc0,Rm,Rs
10249 MIAPHcc acc0,Rm,Rs
10250 MIAxycc acc0,Rm,Rs. */
a737bd4d 10251
c19d1205
ZW
10252static void
10253do_xsc_mia (void)
10254{
10255 inst.instruction |= inst.operands[1].reg;
10256 inst.instruction |= inst.operands[2].reg << 12;
10257}
a737bd4d 10258
c19d1205 10259/* Xscale move-accumulator-register (argument parse)
a737bd4d 10260
c19d1205 10261 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10262
c19d1205
ZW
10263static void
10264do_xsc_mar (void)
10265{
10266 inst.instruction |= inst.operands[1].reg << 12;
10267 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10268}
10269
c19d1205 10270/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10271
c19d1205 10272 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10273
10274static void
c19d1205 10275do_xsc_mra (void)
b99bd4ef 10276{
c19d1205
ZW
10277 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10278 inst.instruction |= inst.operands[0].reg << 12;
10279 inst.instruction |= inst.operands[1].reg << 16;
10280}
10281\f
10282/* Encoding functions relevant only to Thumb. */
b99bd4ef 10283
c19d1205
ZW
10284/* inst.operands[i] is a shifted-register operand; encode
10285 it into inst.instruction in the format used by Thumb32. */
10286
10287static void
10288encode_thumb32_shifted_operand (int i)
10289{
10290 unsigned int value = inst.reloc.exp.X_add_number;
10291 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10292
9c3c69f2
PB
10293 constraint (inst.operands[i].immisreg,
10294 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10295 inst.instruction |= inst.operands[i].reg;
10296 if (shift == SHIFT_RRX)
10297 inst.instruction |= SHIFT_ROR << 4;
10298 else
b99bd4ef 10299 {
c19d1205
ZW
10300 constraint (inst.reloc.exp.X_op != O_constant,
10301 _("expression too complex"));
10302
10303 constraint (value > 32
10304 || (value == 32 && (shift == SHIFT_LSL
10305 || shift == SHIFT_ROR)),
10306 _("shift expression is too large"));
10307
10308 if (value == 0)
10309 shift = SHIFT_LSL;
10310 else if (value == 32)
10311 value = 0;
10312
10313 inst.instruction |= shift << 4;
10314 inst.instruction |= (value & 0x1c) << 10;
10315 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10316 }
c19d1205 10317}
b99bd4ef 10318
b99bd4ef 10319
c19d1205
ZW
10320/* inst.operands[i] was set up by parse_address. Encode it into a
10321 Thumb32 format load or store instruction. Reject forms that cannot
10322 be used with such instructions. If is_t is true, reject forms that
10323 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10324 that cannot be used with a D instruction. If it is a store insn,
10325 reject PC in Rn. */
b99bd4ef 10326
c19d1205
ZW
10327static void
10328encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10329{
5be8be5d 10330 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10331
10332 constraint (!inst.operands[i].isreg,
53365c0d 10333 _("Instruction does not support =N addresses"));
b99bd4ef 10334
c19d1205
ZW
10335 inst.instruction |= inst.operands[i].reg << 16;
10336 if (inst.operands[i].immisreg)
b99bd4ef 10337 {
5be8be5d 10338 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10339 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10340 constraint (inst.operands[i].negative,
10341 _("Thumb does not support negative register indexing"));
10342 constraint (inst.operands[i].postind,
10343 _("Thumb does not support register post-indexing"));
10344 constraint (inst.operands[i].writeback,
10345 _("Thumb does not support register indexing with writeback"));
10346 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10347 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10348
f40d1643 10349 inst.instruction |= inst.operands[i].imm;
c19d1205 10350 if (inst.operands[i].shifted)
b99bd4ef 10351 {
c19d1205
ZW
10352 constraint (inst.reloc.exp.X_op != O_constant,
10353 _("expression too complex"));
9c3c69f2
PB
10354 constraint (inst.reloc.exp.X_add_number < 0
10355 || inst.reloc.exp.X_add_number > 3,
c19d1205 10356 _("shift out of range"));
9c3c69f2 10357 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10358 }
10359 inst.reloc.type = BFD_RELOC_UNUSED;
10360 }
10361 else if (inst.operands[i].preind)
10362 {
5be8be5d 10363 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10364 constraint (is_t && inst.operands[i].writeback,
c19d1205 10365 _("cannot use writeback with this instruction"));
4755303e
WN
10366 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10367 BAD_PC_ADDRESSING);
c19d1205
ZW
10368
10369 if (is_d)
10370 {
10371 inst.instruction |= 0x01000000;
10372 if (inst.operands[i].writeback)
10373 inst.instruction |= 0x00200000;
b99bd4ef 10374 }
c19d1205 10375 else
b99bd4ef 10376 {
c19d1205
ZW
10377 inst.instruction |= 0x00000c00;
10378 if (inst.operands[i].writeback)
10379 inst.instruction |= 0x00000100;
b99bd4ef 10380 }
c19d1205 10381 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10382 }
c19d1205 10383 else if (inst.operands[i].postind)
b99bd4ef 10384 {
9c2799c2 10385 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10386 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10387 constraint (is_t, _("cannot use post-indexing with this instruction"));
10388
10389 if (is_d)
10390 inst.instruction |= 0x00200000;
10391 else
10392 inst.instruction |= 0x00000900;
10393 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10394 }
10395 else /* unindexed - only for coprocessor */
10396 inst.error = _("instruction does not accept unindexed addressing");
10397}
10398
10399/* Table of Thumb instructions which exist in both 16- and 32-bit
10400 encodings (the latter only in post-V6T2 cores). The index is the
10401 value used in the insns table below. When there is more than one
10402 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10403 holds variant (1).
10404 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10405#define T16_32_TAB \
21d799b5
NC
10406 X(_adc, 4140, eb400000), \
10407 X(_adcs, 4140, eb500000), \
10408 X(_add, 1c00, eb000000), \
10409 X(_adds, 1c00, eb100000), \
10410 X(_addi, 0000, f1000000), \
10411 X(_addis, 0000, f1100000), \
10412 X(_add_pc,000f, f20f0000), \
10413 X(_add_sp,000d, f10d0000), \
10414 X(_adr, 000f, f20f0000), \
10415 X(_and, 4000, ea000000), \
10416 X(_ands, 4000, ea100000), \
10417 X(_asr, 1000, fa40f000), \
10418 X(_asrs, 1000, fa50f000), \
10419 X(_b, e000, f000b000), \
10420 X(_bcond, d000, f0008000), \
10421 X(_bic, 4380, ea200000), \
10422 X(_bics, 4380, ea300000), \
10423 X(_cmn, 42c0, eb100f00), \
10424 X(_cmp, 2800, ebb00f00), \
10425 X(_cpsie, b660, f3af8400), \
10426 X(_cpsid, b670, f3af8600), \
10427 X(_cpy, 4600, ea4f0000), \
10428 X(_dec_sp,80dd, f1ad0d00), \
10429 X(_eor, 4040, ea800000), \
10430 X(_eors, 4040, ea900000), \
10431 X(_inc_sp,00dd, f10d0d00), \
10432 X(_ldmia, c800, e8900000), \
10433 X(_ldr, 6800, f8500000), \
10434 X(_ldrb, 7800, f8100000), \
10435 X(_ldrh, 8800, f8300000), \
10436 X(_ldrsb, 5600, f9100000), \
10437 X(_ldrsh, 5e00, f9300000), \
10438 X(_ldr_pc,4800, f85f0000), \
10439 X(_ldr_pc2,4800, f85f0000), \
10440 X(_ldr_sp,9800, f85d0000), \
10441 X(_lsl, 0000, fa00f000), \
10442 X(_lsls, 0000, fa10f000), \
10443 X(_lsr, 0800, fa20f000), \
10444 X(_lsrs, 0800, fa30f000), \
10445 X(_mov, 2000, ea4f0000), \
10446 X(_movs, 2000, ea5f0000), \
10447 X(_mul, 4340, fb00f000), \
10448 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10449 X(_mvn, 43c0, ea6f0000), \
10450 X(_mvns, 43c0, ea7f0000), \
10451 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10452 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10453 X(_orr, 4300, ea400000), \
10454 X(_orrs, 4300, ea500000), \
10455 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10456 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10457 X(_rev, ba00, fa90f080), \
10458 X(_rev16, ba40, fa90f090), \
10459 X(_revsh, bac0, fa90f0b0), \
10460 X(_ror, 41c0, fa60f000), \
10461 X(_rors, 41c0, fa70f000), \
10462 X(_sbc, 4180, eb600000), \
10463 X(_sbcs, 4180, eb700000), \
10464 X(_stmia, c000, e8800000), \
10465 X(_str, 6000, f8400000), \
10466 X(_strb, 7000, f8000000), \
10467 X(_strh, 8000, f8200000), \
10468 X(_str_sp,9000, f84d0000), \
10469 X(_sub, 1e00, eba00000), \
10470 X(_subs, 1e00, ebb00000), \
10471 X(_subi, 8000, f1a00000), \
10472 X(_subis, 8000, f1b00000), \
10473 X(_sxtb, b240, fa4ff080), \
10474 X(_sxth, b200, fa0ff080), \
10475 X(_tst, 4200, ea100f00), \
10476 X(_uxtb, b2c0, fa5ff080), \
10477 X(_uxth, b280, fa1ff080), \
10478 X(_nop, bf00, f3af8000), \
10479 X(_yield, bf10, f3af8001), \
10480 X(_wfe, bf20, f3af8002), \
10481 X(_wfi, bf30, f3af8003), \
53c4b28b 10482 X(_sev, bf40, f3af8004), \
74db7efb
NC
10483 X(_sevl, bf50, f3af8005), \
10484 X(_udf, de00, f7f0a000)
c19d1205
ZW
10485
10486/* To catch errors in encoding functions, the codes are all offset by
10487 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10488 as 16-bit instructions. */
21d799b5 10489#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10490enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10491#undef X
10492
10493#define X(a,b,c) 0x##b
10494static const unsigned short thumb_op16[] = { T16_32_TAB };
10495#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10496#undef X
10497
10498#define X(a,b,c) 0x##c
10499static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10500#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10501#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10502#undef X
10503#undef T16_32_TAB
10504
10505/* Thumb instruction encoders, in alphabetical order. */
10506
92e90b6e 10507/* ADDW or SUBW. */
c921be7d 10508
92e90b6e
PB
10509static void
10510do_t_add_sub_w (void)
10511{
10512 int Rd, Rn;
10513
10514 Rd = inst.operands[0].reg;
10515 Rn = inst.operands[1].reg;
10516
539d4391
NC
10517 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10518 is the SP-{plus,minus}-immediate form of the instruction. */
10519 if (Rn == REG_SP)
10520 constraint (Rd == REG_PC, BAD_PC);
10521 else
10522 reject_bad_reg (Rd);
fdfde340 10523
92e90b6e
PB
10524 inst.instruction |= (Rn << 16) | (Rd << 8);
10525 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10526}
10527
c19d1205 10528/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10529 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10530
10531static void
10532do_t_add_sub (void)
10533{
10534 int Rd, Rs, Rn;
10535
10536 Rd = inst.operands[0].reg;
10537 Rs = (inst.operands[1].present
10538 ? inst.operands[1].reg /* Rd, Rs, foo */
10539 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10540
e07e6e58
NC
10541 if (Rd == REG_PC)
10542 set_it_insn_type_last ();
10543
c19d1205
ZW
10544 if (unified_syntax)
10545 {
0110f2b8
PB
10546 bfd_boolean flags;
10547 bfd_boolean narrow;
10548 int opcode;
10549
10550 flags = (inst.instruction == T_MNEM_adds
10551 || inst.instruction == T_MNEM_subs);
10552 if (flags)
e07e6e58 10553 narrow = !in_it_block ();
0110f2b8 10554 else
e07e6e58 10555 narrow = in_it_block ();
c19d1205 10556 if (!inst.operands[2].isreg)
b99bd4ef 10557 {
16805f35
PB
10558 int add;
10559
5c8ed6a4
JW
10560 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10561 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10562
16805f35
PB
10563 add = (inst.instruction == T_MNEM_add
10564 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10565 opcode = 0;
10566 if (inst.size_req != 4)
10567 {
0110f2b8 10568 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10569 appropriate. */
0110f2b8
PB
10570 if (Rd == REG_SP && Rs == REG_SP && !flags)
10571 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10572 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10573 opcode = T_MNEM_add_sp;
10574 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10575 opcode = T_MNEM_add_pc;
10576 else if (Rd <= 7 && Rs <= 7 && narrow)
10577 {
10578 if (flags)
10579 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10580 else
10581 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10582 }
10583 if (opcode)
10584 {
10585 inst.instruction = THUMB_OP16(opcode);
10586 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10587 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10588 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10589 {
10590 if (inst.size_req == 2)
10591 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10592 else
10593 inst.relax = opcode;
10594 }
0110f2b8
PB
10595 }
10596 else
10597 constraint (inst.size_req == 2, BAD_HIREG);
10598 }
10599 if (inst.size_req == 4
10600 || (inst.size_req != 2 && !opcode))
10601 {
a9f02af8
MG
10602 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10603 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10604 THUMB1_RELOC_ONLY);
efd81785
PB
10605 if (Rd == REG_PC)
10606 {
fdfde340 10607 constraint (add, BAD_PC);
efd81785
PB
10608 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10609 _("only SUBS PC, LR, #const allowed"));
10610 constraint (inst.reloc.exp.X_op != O_constant,
10611 _("expression too complex"));
10612 constraint (inst.reloc.exp.X_add_number < 0
10613 || inst.reloc.exp.X_add_number > 0xff,
10614 _("immediate value out of range"));
10615 inst.instruction = T2_SUBS_PC_LR
10616 | inst.reloc.exp.X_add_number;
10617 inst.reloc.type = BFD_RELOC_UNUSED;
10618 return;
10619 }
10620 else if (Rs == REG_PC)
16805f35
PB
10621 {
10622 /* Always use addw/subw. */
10623 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10624 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10625 }
10626 else
10627 {
10628 inst.instruction = THUMB_OP32 (inst.instruction);
10629 inst.instruction = (inst.instruction & 0xe1ffffff)
10630 | 0x10000000;
10631 if (flags)
10632 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10633 else
10634 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10635 }
dc4503c6
PB
10636 inst.instruction |= Rd << 8;
10637 inst.instruction |= Rs << 16;
0110f2b8 10638 }
b99bd4ef 10639 }
c19d1205
ZW
10640 else
10641 {
5f4cb198
NC
10642 unsigned int value = inst.reloc.exp.X_add_number;
10643 unsigned int shift = inst.operands[2].shift_kind;
10644
c19d1205
ZW
10645 Rn = inst.operands[2].reg;
10646 /* See if we can do this with a 16-bit instruction. */
10647 if (!inst.operands[2].shifted && inst.size_req != 4)
10648 {
e27ec89e
PB
10649 if (Rd > 7 || Rs > 7 || Rn > 7)
10650 narrow = FALSE;
10651
10652 if (narrow)
c19d1205 10653 {
e27ec89e
PB
10654 inst.instruction = ((inst.instruction == T_MNEM_adds
10655 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10656 ? T_OPCODE_ADD_R3
10657 : T_OPCODE_SUB_R3);
10658 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10659 return;
10660 }
b99bd4ef 10661
7e806470 10662 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10663 {
7e806470
PB
10664 /* Thumb-1 cores (except v6-M) require at least one high
10665 register in a narrow non flag setting add. */
10666 if (Rd > 7 || Rn > 7
10667 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10668 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10669 {
7e806470
PB
10670 if (Rd == Rn)
10671 {
10672 Rn = Rs;
10673 Rs = Rd;
10674 }
c19d1205
ZW
10675 inst.instruction = T_OPCODE_ADD_HI;
10676 inst.instruction |= (Rd & 8) << 4;
10677 inst.instruction |= (Rd & 7);
10678 inst.instruction |= Rn << 3;
10679 return;
10680 }
c19d1205
ZW
10681 }
10682 }
c921be7d 10683
fdfde340 10684 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10685 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10686 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10687 constraint (Rs == REG_PC, BAD_PC);
10688 reject_bad_reg (Rn);
10689
c19d1205
ZW
10690 /* If we get here, it can't be done in 16 bits. */
10691 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10692 _("shift must be constant"));
10693 inst.instruction = THUMB_OP32 (inst.instruction);
10694 inst.instruction |= Rd << 8;
10695 inst.instruction |= Rs << 16;
5f4cb198
NC
10696 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10697 _("shift value over 3 not allowed in thumb mode"));
10698 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10699 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10700 encode_thumb32_shifted_operand (2);
10701 }
10702 }
10703 else
10704 {
10705 constraint (inst.instruction == T_MNEM_adds
10706 || inst.instruction == T_MNEM_subs,
10707 BAD_THUMB32);
b99bd4ef 10708
c19d1205 10709 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10710 {
c19d1205
ZW
10711 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10712 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10713 BAD_HIREG);
10714
10715 inst.instruction = (inst.instruction == T_MNEM_add
10716 ? 0x0000 : 0x8000);
10717 inst.instruction |= (Rd << 4) | Rs;
10718 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10719 return;
10720 }
10721
c19d1205
ZW
10722 Rn = inst.operands[2].reg;
10723 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10724
c19d1205
ZW
10725 /* We now have Rd, Rs, and Rn set to registers. */
10726 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10727 {
c19d1205
ZW
10728 /* Can't do this for SUB. */
10729 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10730 inst.instruction = T_OPCODE_ADD_HI;
10731 inst.instruction |= (Rd & 8) << 4;
10732 inst.instruction |= (Rd & 7);
10733 if (Rs == Rd)
10734 inst.instruction |= Rn << 3;
10735 else if (Rn == Rd)
10736 inst.instruction |= Rs << 3;
10737 else
10738 constraint (1, _("dest must overlap one source register"));
10739 }
10740 else
10741 {
10742 inst.instruction = (inst.instruction == T_MNEM_add
10743 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10744 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10745 }
b99bd4ef 10746 }
b99bd4ef
NC
10747}
10748
c19d1205
ZW
10749static void
10750do_t_adr (void)
10751{
fdfde340
JM
10752 unsigned Rd;
10753
10754 Rd = inst.operands[0].reg;
10755 reject_bad_reg (Rd);
10756
10757 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10758 {
10759 /* Defer to section relaxation. */
10760 inst.relax = inst.instruction;
10761 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10762 inst.instruction |= Rd << 4;
0110f2b8
PB
10763 }
10764 else if (unified_syntax && inst.size_req != 2)
e9f89963 10765 {
0110f2b8 10766 /* Generate a 32-bit opcode. */
e9f89963 10767 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10768 inst.instruction |= Rd << 8;
e9f89963
PB
10769 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10770 inst.reloc.pc_rel = 1;
10771 }
10772 else
10773 {
0110f2b8 10774 /* Generate a 16-bit opcode. */
e9f89963
PB
10775 inst.instruction = THUMB_OP16 (inst.instruction);
10776 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10777 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10778 inst.reloc.pc_rel = 1;
fdfde340 10779 inst.instruction |= Rd << 4;
e9f89963 10780 }
52a86f84
NC
10781
10782 if (inst.reloc.exp.X_op == O_symbol
10783 && inst.reloc.exp.X_add_symbol != NULL
10784 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10785 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10786 inst.reloc.exp.X_add_number += 1;
c19d1205 10787}
b99bd4ef 10788
c19d1205
ZW
10789/* Arithmetic instructions for which there is just one 16-bit
10790 instruction encoding, and it allows only two low registers.
10791 For maximal compatibility with ARM syntax, we allow three register
10792 operands even when Thumb-32 instructions are not available, as long
10793 as the first two are identical. For instance, both "sbc r0,r1" and
10794 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10795static void
c19d1205 10796do_t_arit3 (void)
b99bd4ef 10797{
c19d1205 10798 int Rd, Rs, Rn;
b99bd4ef 10799
c19d1205
ZW
10800 Rd = inst.operands[0].reg;
10801 Rs = (inst.operands[1].present
10802 ? inst.operands[1].reg /* Rd, Rs, foo */
10803 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10804 Rn = inst.operands[2].reg;
b99bd4ef 10805
fdfde340
JM
10806 reject_bad_reg (Rd);
10807 reject_bad_reg (Rs);
10808 if (inst.operands[2].isreg)
10809 reject_bad_reg (Rn);
10810
c19d1205 10811 if (unified_syntax)
b99bd4ef 10812 {
c19d1205
ZW
10813 if (!inst.operands[2].isreg)
10814 {
10815 /* For an immediate, we always generate a 32-bit opcode;
10816 section relaxation will shrink it later if possible. */
10817 inst.instruction = THUMB_OP32 (inst.instruction);
10818 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10819 inst.instruction |= Rd << 8;
10820 inst.instruction |= Rs << 16;
10821 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10822 }
10823 else
10824 {
e27ec89e
PB
10825 bfd_boolean narrow;
10826
c19d1205 10827 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10828 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10829 narrow = !in_it_block ();
e27ec89e 10830 else
e07e6e58 10831 narrow = in_it_block ();
e27ec89e
PB
10832
10833 if (Rd > 7 || Rn > 7 || Rs > 7)
10834 narrow = FALSE;
10835 if (inst.operands[2].shifted)
10836 narrow = FALSE;
10837 if (inst.size_req == 4)
10838 narrow = FALSE;
10839
10840 if (narrow
c19d1205
ZW
10841 && Rd == Rs)
10842 {
10843 inst.instruction = THUMB_OP16 (inst.instruction);
10844 inst.instruction |= Rd;
10845 inst.instruction |= Rn << 3;
10846 return;
10847 }
b99bd4ef 10848
c19d1205
ZW
10849 /* If we get here, it can't be done in 16 bits. */
10850 constraint (inst.operands[2].shifted
10851 && inst.operands[2].immisreg,
10852 _("shift must be constant"));
10853 inst.instruction = THUMB_OP32 (inst.instruction);
10854 inst.instruction |= Rd << 8;
10855 inst.instruction |= Rs << 16;
10856 encode_thumb32_shifted_operand (2);
10857 }
a737bd4d 10858 }
c19d1205 10859 else
b99bd4ef 10860 {
c19d1205
ZW
10861 /* On its face this is a lie - the instruction does set the
10862 flags. However, the only supported mnemonic in this mode
10863 says it doesn't. */
10864 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10865
c19d1205
ZW
10866 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10867 _("unshifted register required"));
10868 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10869 constraint (Rd != Rs,
10870 _("dest and source1 must be the same register"));
a737bd4d 10871
c19d1205
ZW
10872 inst.instruction = THUMB_OP16 (inst.instruction);
10873 inst.instruction |= Rd;
10874 inst.instruction |= Rn << 3;
b99bd4ef 10875 }
a737bd4d 10876}
b99bd4ef 10877
c19d1205
ZW
10878/* Similarly, but for instructions where the arithmetic operation is
10879 commutative, so we can allow either of them to be different from
10880 the destination operand in a 16-bit instruction. For instance, all
10881 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10882 accepted. */
10883static void
10884do_t_arit3c (void)
a737bd4d 10885{
c19d1205 10886 int Rd, Rs, Rn;
b99bd4ef 10887
c19d1205
ZW
10888 Rd = inst.operands[0].reg;
10889 Rs = (inst.operands[1].present
10890 ? inst.operands[1].reg /* Rd, Rs, foo */
10891 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10892 Rn = inst.operands[2].reg;
c921be7d 10893
fdfde340
JM
10894 reject_bad_reg (Rd);
10895 reject_bad_reg (Rs);
10896 if (inst.operands[2].isreg)
10897 reject_bad_reg (Rn);
a737bd4d 10898
c19d1205 10899 if (unified_syntax)
a737bd4d 10900 {
c19d1205 10901 if (!inst.operands[2].isreg)
b99bd4ef 10902 {
c19d1205
ZW
10903 /* For an immediate, we always generate a 32-bit opcode;
10904 section relaxation will shrink it later if possible. */
10905 inst.instruction = THUMB_OP32 (inst.instruction);
10906 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10907 inst.instruction |= Rd << 8;
10908 inst.instruction |= Rs << 16;
10909 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10910 }
c19d1205 10911 else
a737bd4d 10912 {
e27ec89e
PB
10913 bfd_boolean narrow;
10914
c19d1205 10915 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10916 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10917 narrow = !in_it_block ();
e27ec89e 10918 else
e07e6e58 10919 narrow = in_it_block ();
e27ec89e
PB
10920
10921 if (Rd > 7 || Rn > 7 || Rs > 7)
10922 narrow = FALSE;
10923 if (inst.operands[2].shifted)
10924 narrow = FALSE;
10925 if (inst.size_req == 4)
10926 narrow = FALSE;
10927
10928 if (narrow)
a737bd4d 10929 {
c19d1205 10930 if (Rd == Rs)
a737bd4d 10931 {
c19d1205
ZW
10932 inst.instruction = THUMB_OP16 (inst.instruction);
10933 inst.instruction |= Rd;
10934 inst.instruction |= Rn << 3;
10935 return;
a737bd4d 10936 }
c19d1205 10937 if (Rd == Rn)
a737bd4d 10938 {
c19d1205
ZW
10939 inst.instruction = THUMB_OP16 (inst.instruction);
10940 inst.instruction |= Rd;
10941 inst.instruction |= Rs << 3;
10942 return;
a737bd4d
NC
10943 }
10944 }
c19d1205
ZW
10945
10946 /* If we get here, it can't be done in 16 bits. */
10947 constraint (inst.operands[2].shifted
10948 && inst.operands[2].immisreg,
10949 _("shift must be constant"));
10950 inst.instruction = THUMB_OP32 (inst.instruction);
10951 inst.instruction |= Rd << 8;
10952 inst.instruction |= Rs << 16;
10953 encode_thumb32_shifted_operand (2);
a737bd4d 10954 }
b99bd4ef 10955 }
c19d1205
ZW
10956 else
10957 {
10958 /* On its face this is a lie - the instruction does set the
10959 flags. However, the only supported mnemonic in this mode
10960 says it doesn't. */
10961 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10962
c19d1205
ZW
10963 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10964 _("unshifted register required"));
10965 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10966
10967 inst.instruction = THUMB_OP16 (inst.instruction);
10968 inst.instruction |= Rd;
10969
10970 if (Rd == Rs)
10971 inst.instruction |= Rn << 3;
10972 else if (Rd == Rn)
10973 inst.instruction |= Rs << 3;
10974 else
10975 constraint (1, _("dest must overlap one source register"));
10976 }
a737bd4d
NC
10977}
10978
c19d1205
ZW
10979static void
10980do_t_bfc (void)
a737bd4d 10981{
fdfde340 10982 unsigned Rd;
c19d1205
ZW
10983 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10984 constraint (msb > 32, _("bit-field extends past end of register"));
10985 /* The instruction encoding stores the LSB and MSB,
10986 not the LSB and width. */
fdfde340
JM
10987 Rd = inst.operands[0].reg;
10988 reject_bad_reg (Rd);
10989 inst.instruction |= Rd << 8;
c19d1205
ZW
10990 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10991 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10992 inst.instruction |= msb - 1;
b99bd4ef
NC
10993}
10994
c19d1205
ZW
10995static void
10996do_t_bfi (void)
b99bd4ef 10997{
fdfde340 10998 int Rd, Rn;
c19d1205 10999 unsigned int msb;
b99bd4ef 11000
fdfde340
JM
11001 Rd = inst.operands[0].reg;
11002 reject_bad_reg (Rd);
11003
c19d1205
ZW
11004 /* #0 in second position is alternative syntax for bfc, which is
11005 the same instruction but with REG_PC in the Rm field. */
11006 if (!inst.operands[1].isreg)
fdfde340
JM
11007 Rn = REG_PC;
11008 else
11009 {
11010 Rn = inst.operands[1].reg;
11011 reject_bad_reg (Rn);
11012 }
b99bd4ef 11013
c19d1205
ZW
11014 msb = inst.operands[2].imm + inst.operands[3].imm;
11015 constraint (msb > 32, _("bit-field extends past end of register"));
11016 /* The instruction encoding stores the LSB and MSB,
11017 not the LSB and width. */
fdfde340
JM
11018 inst.instruction |= Rd << 8;
11019 inst.instruction |= Rn << 16;
c19d1205
ZW
11020 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11021 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11022 inst.instruction |= msb - 1;
b99bd4ef
NC
11023}
11024
c19d1205
ZW
11025static void
11026do_t_bfx (void)
b99bd4ef 11027{
fdfde340
JM
11028 unsigned Rd, Rn;
11029
11030 Rd = inst.operands[0].reg;
11031 Rn = inst.operands[1].reg;
11032
11033 reject_bad_reg (Rd);
11034 reject_bad_reg (Rn);
11035
c19d1205
ZW
11036 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11037 _("bit-field extends past end of register"));
fdfde340
JM
11038 inst.instruction |= Rd << 8;
11039 inst.instruction |= Rn << 16;
c19d1205
ZW
11040 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11041 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11042 inst.instruction |= inst.operands[3].imm - 1;
11043}
b99bd4ef 11044
c19d1205
ZW
11045/* ARM V5 Thumb BLX (argument parse)
11046 BLX <target_addr> which is BLX(1)
11047 BLX <Rm> which is BLX(2)
11048 Unfortunately, there are two different opcodes for this mnemonic.
11049 So, the insns[].value is not used, and the code here zaps values
11050 into inst.instruction.
b99bd4ef 11051
c19d1205
ZW
11052 ??? How to take advantage of the additional two bits of displacement
11053 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11054
c19d1205
ZW
11055static void
11056do_t_blx (void)
11057{
e07e6e58
NC
11058 set_it_insn_type_last ();
11059
c19d1205 11060 if (inst.operands[0].isreg)
fdfde340
JM
11061 {
11062 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11063 /* We have a register, so this is BLX(2). */
11064 inst.instruction |= inst.operands[0].reg << 3;
11065 }
b99bd4ef
NC
11066 else
11067 {
c19d1205 11068 /* No register. This must be BLX(1). */
2fc8bdac 11069 inst.instruction = 0xf000e800;
0855e32b 11070 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11071 }
11072}
11073
c19d1205
ZW
11074static void
11075do_t_branch (void)
b99bd4ef 11076{
0110f2b8 11077 int opcode;
dfa9f0d5 11078 int cond;
2fe88214 11079 bfd_reloc_code_real_type reloc;
dfa9f0d5 11080
e07e6e58
NC
11081 cond = inst.cond;
11082 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11083
11084 if (in_it_block ())
dfa9f0d5
PB
11085 {
11086 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11087 branches. */
dfa9f0d5 11088 cond = COND_ALWAYS;
dfa9f0d5
PB
11089 }
11090 else
11091 cond = inst.cond;
11092
11093 if (cond != COND_ALWAYS)
0110f2b8
PB
11094 opcode = T_MNEM_bcond;
11095 else
11096 opcode = inst.instruction;
11097
12d6b0b7
RS
11098 if (unified_syntax
11099 && (inst.size_req == 4
10960bfb
PB
11100 || (inst.size_req != 2
11101 && (inst.operands[0].hasreloc
11102 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11103 {
0110f2b8 11104 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11105 if (cond == COND_ALWAYS)
9ae92b05 11106 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11107 else
11108 {
ff8646ee
TP
11109 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11110 _("selected architecture does not support "
11111 "wide conditional branch instruction"));
11112
9c2799c2 11113 gas_assert (cond != 0xF);
dfa9f0d5 11114 inst.instruction |= cond << 22;
9ae92b05 11115 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11116 }
11117 }
b99bd4ef
NC
11118 else
11119 {
0110f2b8 11120 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11121 if (cond == COND_ALWAYS)
9ae92b05 11122 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11123 else
b99bd4ef 11124 {
dfa9f0d5 11125 inst.instruction |= cond << 8;
9ae92b05 11126 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11127 }
0110f2b8
PB
11128 /* Allow section relaxation. */
11129 if (unified_syntax && inst.size_req != 2)
11130 inst.relax = opcode;
b99bd4ef 11131 }
9ae92b05 11132 inst.reloc.type = reloc;
c19d1205 11133 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11134}
11135
8884b720 11136/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11137 between the two is the maximum immediate allowed - which is passed in
8884b720 11138 RANGE. */
b99bd4ef 11139static void
8884b720 11140do_t_bkpt_hlt1 (int range)
b99bd4ef 11141{
dfa9f0d5
PB
11142 constraint (inst.cond != COND_ALWAYS,
11143 _("instruction is always unconditional"));
c19d1205 11144 if (inst.operands[0].present)
b99bd4ef 11145 {
8884b720 11146 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11147 _("immediate value out of range"));
11148 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11149 }
8884b720
MGD
11150
11151 set_it_insn_type (NEUTRAL_IT_INSN);
11152}
11153
11154static void
11155do_t_hlt (void)
11156{
11157 do_t_bkpt_hlt1 (63);
11158}
11159
11160static void
11161do_t_bkpt (void)
11162{
11163 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11164}
11165
11166static void
c19d1205 11167do_t_branch23 (void)
b99bd4ef 11168{
e07e6e58 11169 set_it_insn_type_last ();
0855e32b 11170 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11171
0855e32b
NS
11172 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11173 this file. We used to simply ignore the PLT reloc type here --
11174 the branch encoding is now needed to deal with TLSCALL relocs.
11175 So if we see a PLT reloc now, put it back to how it used to be to
11176 keep the preexisting behaviour. */
11177 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11178 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11179
4343666d 11180#if defined(OBJ_COFF)
c19d1205
ZW
11181 /* If the destination of the branch is a defined symbol which does not have
11182 the THUMB_FUNC attribute, then we must be calling a function which has
11183 the (interfacearm) attribute. We look for the Thumb entry point to that
11184 function and change the branch to refer to that function instead. */
11185 if ( inst.reloc.exp.X_op == O_symbol
11186 && inst.reloc.exp.X_add_symbol != NULL
11187 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11188 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11189 inst.reloc.exp.X_add_symbol =
11190 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11191#endif
90e4755a
RE
11192}
11193
11194static void
c19d1205 11195do_t_bx (void)
90e4755a 11196{
e07e6e58 11197 set_it_insn_type_last ();
c19d1205
ZW
11198 inst.instruction |= inst.operands[0].reg << 3;
11199 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11200 should cause the alignment to be checked once it is known. This is
11201 because BX PC only works if the instruction is word aligned. */
11202}
90e4755a 11203
c19d1205
ZW
11204static void
11205do_t_bxj (void)
11206{
fdfde340 11207 int Rm;
90e4755a 11208
e07e6e58 11209 set_it_insn_type_last ();
fdfde340
JM
11210 Rm = inst.operands[0].reg;
11211 reject_bad_reg (Rm);
11212 inst.instruction |= Rm << 16;
90e4755a
RE
11213}
11214
11215static void
c19d1205 11216do_t_clz (void)
90e4755a 11217{
fdfde340
JM
11218 unsigned Rd;
11219 unsigned Rm;
11220
11221 Rd = inst.operands[0].reg;
11222 Rm = inst.operands[1].reg;
11223
11224 reject_bad_reg (Rd);
11225 reject_bad_reg (Rm);
11226
11227 inst.instruction |= Rd << 8;
11228 inst.instruction |= Rm << 16;
11229 inst.instruction |= Rm;
c19d1205 11230}
90e4755a 11231
dfa9f0d5
PB
11232static void
11233do_t_cps (void)
11234{
e07e6e58 11235 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11236 inst.instruction |= inst.operands[0].imm;
11237}
11238
c19d1205
ZW
11239static void
11240do_t_cpsi (void)
11241{
e07e6e58 11242 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11243 if (unified_syntax
62b3e311
PB
11244 && (inst.operands[1].present || inst.size_req == 4)
11245 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11246 {
c19d1205
ZW
11247 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11248 inst.instruction = 0xf3af8000;
11249 inst.instruction |= imod << 9;
11250 inst.instruction |= inst.operands[0].imm << 5;
11251 if (inst.operands[1].present)
11252 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11253 }
c19d1205 11254 else
90e4755a 11255 {
62b3e311
PB
11256 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11257 && (inst.operands[0].imm & 4),
11258 _("selected processor does not support 'A' form "
11259 "of this instruction"));
11260 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11261 _("Thumb does not support the 2-argument "
11262 "form of this instruction"));
11263 inst.instruction |= inst.operands[0].imm;
90e4755a 11264 }
90e4755a
RE
11265}
11266
c19d1205
ZW
11267/* THUMB CPY instruction (argument parse). */
11268
90e4755a 11269static void
c19d1205 11270do_t_cpy (void)
90e4755a 11271{
c19d1205 11272 if (inst.size_req == 4)
90e4755a 11273 {
c19d1205
ZW
11274 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11275 inst.instruction |= inst.operands[0].reg << 8;
11276 inst.instruction |= inst.operands[1].reg;
90e4755a 11277 }
c19d1205 11278 else
90e4755a 11279 {
c19d1205
ZW
11280 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11281 inst.instruction |= (inst.operands[0].reg & 0x7);
11282 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11283 }
90e4755a
RE
11284}
11285
90e4755a 11286static void
25fe350b 11287do_t_cbz (void)
90e4755a 11288{
e07e6e58 11289 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11290 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11291 inst.instruction |= inst.operands[0].reg;
11292 inst.reloc.pc_rel = 1;
11293 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11294}
90e4755a 11295
62b3e311
PB
11296static void
11297do_t_dbg (void)
11298{
11299 inst.instruction |= inst.operands[0].imm;
11300}
11301
11302static void
11303do_t_div (void)
11304{
fdfde340
JM
11305 unsigned Rd, Rn, Rm;
11306
11307 Rd = inst.operands[0].reg;
11308 Rn = (inst.operands[1].present
11309 ? inst.operands[1].reg : Rd);
11310 Rm = inst.operands[2].reg;
11311
11312 reject_bad_reg (Rd);
11313 reject_bad_reg (Rn);
11314 reject_bad_reg (Rm);
11315
11316 inst.instruction |= Rd << 8;
11317 inst.instruction |= Rn << 16;
11318 inst.instruction |= Rm;
62b3e311
PB
11319}
11320
c19d1205
ZW
11321static void
11322do_t_hint (void)
11323{
11324 if (unified_syntax && inst.size_req == 4)
11325 inst.instruction = THUMB_OP32 (inst.instruction);
11326 else
11327 inst.instruction = THUMB_OP16 (inst.instruction);
11328}
90e4755a 11329
c19d1205
ZW
11330static void
11331do_t_it (void)
11332{
11333 unsigned int cond = inst.operands[0].imm;
e27ec89e 11334
e07e6e58
NC
11335 set_it_insn_type (IT_INSN);
11336 now_it.mask = (inst.instruction & 0xf) | 0x10;
11337 now_it.cc = cond;
5a01bb1d 11338 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11339
11340 /* If the condition is a negative condition, invert the mask. */
c19d1205 11341 if ((cond & 0x1) == 0x0)
90e4755a 11342 {
c19d1205 11343 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11344
c19d1205 11345 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11346 {
11347 /* No conversion needed. */
11348 now_it.block_length = 1;
11349 }
c19d1205 11350 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11351 {
11352 mask ^= 0x8;
11353 now_it.block_length = 2;
11354 }
e27ec89e 11355 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11356 {
11357 mask ^= 0xC;
11358 now_it.block_length = 3;
11359 }
c19d1205 11360 else
5a01bb1d
MGD
11361 {
11362 mask ^= 0xE;
11363 now_it.block_length = 4;
11364 }
90e4755a 11365
e27ec89e
PB
11366 inst.instruction &= 0xfff0;
11367 inst.instruction |= mask;
c19d1205 11368 }
90e4755a 11369
c19d1205
ZW
11370 inst.instruction |= cond << 4;
11371}
90e4755a 11372
3c707909
PB
11373/* Helper function used for both push/pop and ldm/stm. */
11374static void
11375encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11376{
11377 bfd_boolean load;
11378
11379 load = (inst.instruction & (1 << 20)) != 0;
11380
11381 if (mask & (1 << 13))
11382 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11383
11384 if ((mask & (1 << base)) != 0
11385 && writeback)
11386 inst.error = _("having the base register in the register list when "
11387 "using write back is UNPREDICTABLE");
11388
3c707909
PB
11389 if (load)
11390 {
e07e6e58 11391 if (mask & (1 << 15))
477330fc
RM
11392 {
11393 if (mask & (1 << 14))
11394 inst.error = _("LR and PC should not both be in register list");
11395 else
11396 set_it_insn_type_last ();
11397 }
3c707909
PB
11398 }
11399 else
11400 {
11401 if (mask & (1 << 15))
11402 inst.error = _("PC not allowed in register list");
3c707909
PB
11403 }
11404
11405 if ((mask & (mask - 1)) == 0)
11406 {
11407 /* Single register transfers implemented as str/ldr. */
11408 if (writeback)
11409 {
11410 if (inst.instruction & (1 << 23))
11411 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11412 else
11413 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11414 }
11415 else
11416 {
11417 if (inst.instruction & (1 << 23))
11418 inst.instruction = 0x00800000; /* ia -> [base] */
11419 else
11420 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11421 }
11422
11423 inst.instruction |= 0xf8400000;
11424 if (load)
11425 inst.instruction |= 0x00100000;
11426
5f4273c7 11427 mask = ffs (mask) - 1;
3c707909
PB
11428 mask <<= 12;
11429 }
11430 else if (writeback)
11431 inst.instruction |= WRITE_BACK;
11432
11433 inst.instruction |= mask;
11434 inst.instruction |= base << 16;
11435}
11436
c19d1205
ZW
11437static void
11438do_t_ldmstm (void)
11439{
11440 /* This really doesn't seem worth it. */
11441 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11442 _("expression too complex"));
11443 constraint (inst.operands[1].writeback,
11444 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11445
c19d1205
ZW
11446 if (unified_syntax)
11447 {
3c707909
PB
11448 bfd_boolean narrow;
11449 unsigned mask;
11450
11451 narrow = FALSE;
c19d1205
ZW
11452 /* See if we can use a 16-bit instruction. */
11453 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11454 && inst.size_req != 4
3c707909 11455 && !(inst.operands[1].imm & ~0xff))
90e4755a 11456 {
3c707909 11457 mask = 1 << inst.operands[0].reg;
90e4755a 11458
eab4f823 11459 if (inst.operands[0].reg <= 7)
90e4755a 11460 {
3c707909 11461 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11462 ? inst.operands[0].writeback
11463 : (inst.operands[0].writeback
11464 == !(inst.operands[1].imm & mask)))
477330fc 11465 {
eab4f823
MGD
11466 if (inst.instruction == T_MNEM_stmia
11467 && (inst.operands[1].imm & mask)
11468 && (inst.operands[1].imm & (mask - 1)))
11469 as_warn (_("value stored for r%d is UNKNOWN"),
11470 inst.operands[0].reg);
3c707909 11471
eab4f823
MGD
11472 inst.instruction = THUMB_OP16 (inst.instruction);
11473 inst.instruction |= inst.operands[0].reg << 8;
11474 inst.instruction |= inst.operands[1].imm;
11475 narrow = TRUE;
11476 }
11477 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11478 {
11479 /* This means 1 register in reg list one of 3 situations:
11480 1. Instruction is stmia, but without writeback.
11481 2. lmdia without writeback, but with Rn not in
477330fc 11482 reglist.
eab4f823
MGD
11483 3. ldmia with writeback, but with Rn in reglist.
11484 Case 3 is UNPREDICTABLE behaviour, so we handle
11485 case 1 and 2 which can be converted into a 16-bit
11486 str or ldr. The SP cases are handled below. */
11487 unsigned long opcode;
11488 /* First, record an error for Case 3. */
11489 if (inst.operands[1].imm & mask
11490 && inst.operands[0].writeback)
fa94de6b 11491 inst.error =
eab4f823
MGD
11492 _("having the base register in the register list when "
11493 "using write back is UNPREDICTABLE");
fa94de6b
RM
11494
11495 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11496 : T_MNEM_ldr);
11497 inst.instruction = THUMB_OP16 (opcode);
11498 inst.instruction |= inst.operands[0].reg << 3;
11499 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11500 narrow = TRUE;
11501 }
90e4755a 11502 }
eab4f823 11503 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11504 {
eab4f823
MGD
11505 if (inst.operands[0].writeback)
11506 {
fa94de6b 11507 inst.instruction =
eab4f823 11508 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11509 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11510 inst.instruction |= inst.operands[1].imm;
477330fc 11511 narrow = TRUE;
eab4f823
MGD
11512 }
11513 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11514 {
fa94de6b 11515 inst.instruction =
eab4f823 11516 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11517 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11518 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11519 narrow = TRUE;
eab4f823 11520 }
90e4755a 11521 }
3c707909
PB
11522 }
11523
11524 if (!narrow)
11525 {
c19d1205
ZW
11526 if (inst.instruction < 0xffff)
11527 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11528
5f4273c7
NC
11529 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11530 inst.operands[0].writeback);
90e4755a
RE
11531 }
11532 }
c19d1205 11533 else
90e4755a 11534 {
c19d1205
ZW
11535 constraint (inst.operands[0].reg > 7
11536 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11537 constraint (inst.instruction != T_MNEM_ldmia
11538 && inst.instruction != T_MNEM_stmia,
11539 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11540 if (inst.instruction == T_MNEM_stmia)
f03698e6 11541 {
c19d1205
ZW
11542 if (!inst.operands[0].writeback)
11543 as_warn (_("this instruction will write back the base register"));
11544 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11545 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11546 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11547 inst.operands[0].reg);
f03698e6 11548 }
c19d1205 11549 else
90e4755a 11550 {
c19d1205
ZW
11551 if (!inst.operands[0].writeback
11552 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11553 as_warn (_("this instruction will write back the base register"));
11554 else if (inst.operands[0].writeback
11555 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11556 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11557 }
11558
c19d1205
ZW
11559 inst.instruction = THUMB_OP16 (inst.instruction);
11560 inst.instruction |= inst.operands[0].reg << 8;
11561 inst.instruction |= inst.operands[1].imm;
11562 }
11563}
e28cd48c 11564
c19d1205
ZW
11565static void
11566do_t_ldrex (void)
11567{
11568 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11569 || inst.operands[1].postind || inst.operands[1].writeback
11570 || inst.operands[1].immisreg || inst.operands[1].shifted
11571 || inst.operands[1].negative,
01cfc07f 11572 BAD_ADDR_MODE);
e28cd48c 11573
5be8be5d
DG
11574 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11575
c19d1205
ZW
11576 inst.instruction |= inst.operands[0].reg << 12;
11577 inst.instruction |= inst.operands[1].reg << 16;
11578 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11579}
e28cd48c 11580
c19d1205
ZW
11581static void
11582do_t_ldrexd (void)
11583{
11584 if (!inst.operands[1].present)
1cac9012 11585 {
c19d1205
ZW
11586 constraint (inst.operands[0].reg == REG_LR,
11587 _("r14 not allowed as first register "
11588 "when second register is omitted"));
11589 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11590 }
c19d1205
ZW
11591 constraint (inst.operands[0].reg == inst.operands[1].reg,
11592 BAD_OVERLAP);
b99bd4ef 11593
c19d1205
ZW
11594 inst.instruction |= inst.operands[0].reg << 12;
11595 inst.instruction |= inst.operands[1].reg << 8;
11596 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11597}
11598
11599static void
c19d1205 11600do_t_ldst (void)
b99bd4ef 11601{
0110f2b8
PB
11602 unsigned long opcode;
11603 int Rn;
11604
e07e6e58
NC
11605 if (inst.operands[0].isreg
11606 && !inst.operands[0].preind
11607 && inst.operands[0].reg == REG_PC)
11608 set_it_insn_type_last ();
11609
0110f2b8 11610 opcode = inst.instruction;
c19d1205 11611 if (unified_syntax)
b99bd4ef 11612 {
53365c0d
PB
11613 if (!inst.operands[1].isreg)
11614 {
11615 if (opcode <= 0xffff)
11616 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11617 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11618 return;
11619 }
0110f2b8
PB
11620 if (inst.operands[1].isreg
11621 && !inst.operands[1].writeback
c19d1205
ZW
11622 && !inst.operands[1].shifted && !inst.operands[1].postind
11623 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11624 && opcode <= 0xffff
11625 && inst.size_req != 4)
c19d1205 11626 {
0110f2b8
PB
11627 /* Insn may have a 16-bit form. */
11628 Rn = inst.operands[1].reg;
11629 if (inst.operands[1].immisreg)
11630 {
11631 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11632 /* [Rn, Rik] */
0110f2b8
PB
11633 if (Rn <= 7 && inst.operands[1].imm <= 7)
11634 goto op16;
5be8be5d
DG
11635 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11636 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11637 }
11638 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11639 && opcode != T_MNEM_ldrsb)
11640 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11641 || (Rn == REG_SP && opcode == T_MNEM_str))
11642 {
11643 /* [Rn, #const] */
11644 if (Rn > 7)
11645 {
11646 if (Rn == REG_PC)
11647 {
11648 if (inst.reloc.pc_rel)
11649 opcode = T_MNEM_ldr_pc2;
11650 else
11651 opcode = T_MNEM_ldr_pc;
11652 }
11653 else
11654 {
11655 if (opcode == T_MNEM_ldr)
11656 opcode = T_MNEM_ldr_sp;
11657 else
11658 opcode = T_MNEM_str_sp;
11659 }
11660 inst.instruction = inst.operands[0].reg << 8;
11661 }
11662 else
11663 {
11664 inst.instruction = inst.operands[0].reg;
11665 inst.instruction |= inst.operands[1].reg << 3;
11666 }
11667 inst.instruction |= THUMB_OP16 (opcode);
11668 if (inst.size_req == 2)
11669 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11670 else
11671 inst.relax = opcode;
11672 return;
11673 }
c19d1205 11674 }
0110f2b8 11675 /* Definitely a 32-bit variant. */
5be8be5d 11676
8d67f500
NC
11677 /* Warning for Erratum 752419. */
11678 if (opcode == T_MNEM_ldr
11679 && inst.operands[0].reg == REG_SP
11680 && inst.operands[1].writeback == 1
11681 && !inst.operands[1].immisreg)
11682 {
11683 if (no_cpu_selected ()
11684 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11685 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11686 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11687 as_warn (_("This instruction may be unpredictable "
11688 "if executed on M-profile cores "
11689 "with interrupts enabled."));
11690 }
11691
5be8be5d 11692 /* Do some validations regarding addressing modes. */
1be5fd2e 11693 if (inst.operands[1].immisreg)
5be8be5d
DG
11694 reject_bad_reg (inst.operands[1].imm);
11695
1be5fd2e
NC
11696 constraint (inst.operands[1].writeback == 1
11697 && inst.operands[0].reg == inst.operands[1].reg,
11698 BAD_OVERLAP);
11699
0110f2b8 11700 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11701 inst.instruction |= inst.operands[0].reg << 12;
11702 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11703 check_ldr_r15_aligned ();
b99bd4ef
NC
11704 return;
11705 }
11706
c19d1205
ZW
11707 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11708
11709 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11710 {
c19d1205
ZW
11711 /* Only [Rn,Rm] is acceptable. */
11712 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11713 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11714 || inst.operands[1].postind || inst.operands[1].shifted
11715 || inst.operands[1].negative,
11716 _("Thumb does not support this addressing mode"));
11717 inst.instruction = THUMB_OP16 (inst.instruction);
11718 goto op16;
b99bd4ef 11719 }
5f4273c7 11720
c19d1205
ZW
11721 inst.instruction = THUMB_OP16 (inst.instruction);
11722 if (!inst.operands[1].isreg)
8335d6aa 11723 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11724 return;
b99bd4ef 11725
c19d1205
ZW
11726 constraint (!inst.operands[1].preind
11727 || inst.operands[1].shifted
11728 || inst.operands[1].writeback,
11729 _("Thumb does not support this addressing mode"));
11730 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11731 {
c19d1205
ZW
11732 constraint (inst.instruction & 0x0600,
11733 _("byte or halfword not valid for base register"));
11734 constraint (inst.operands[1].reg == REG_PC
11735 && !(inst.instruction & THUMB_LOAD_BIT),
11736 _("r15 based store not allowed"));
11737 constraint (inst.operands[1].immisreg,
11738 _("invalid base register for register offset"));
b99bd4ef 11739
c19d1205
ZW
11740 if (inst.operands[1].reg == REG_PC)
11741 inst.instruction = T_OPCODE_LDR_PC;
11742 else if (inst.instruction & THUMB_LOAD_BIT)
11743 inst.instruction = T_OPCODE_LDR_SP;
11744 else
11745 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11746
c19d1205
ZW
11747 inst.instruction |= inst.operands[0].reg << 8;
11748 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11749 return;
11750 }
90e4755a 11751
c19d1205
ZW
11752 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11753 if (!inst.operands[1].immisreg)
11754 {
11755 /* Immediate offset. */
11756 inst.instruction |= inst.operands[0].reg;
11757 inst.instruction |= inst.operands[1].reg << 3;
11758 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11759 return;
11760 }
90e4755a 11761
c19d1205
ZW
11762 /* Register offset. */
11763 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11764 constraint (inst.operands[1].negative,
11765 _("Thumb does not support this addressing mode"));
90e4755a 11766
c19d1205
ZW
11767 op16:
11768 switch (inst.instruction)
11769 {
11770 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11771 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11772 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11773 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11774 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11775 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11776 case 0x5600 /* ldrsb */:
11777 case 0x5e00 /* ldrsh */: break;
11778 default: abort ();
11779 }
90e4755a 11780
c19d1205
ZW
11781 inst.instruction |= inst.operands[0].reg;
11782 inst.instruction |= inst.operands[1].reg << 3;
11783 inst.instruction |= inst.operands[1].imm << 6;
11784}
90e4755a 11785
c19d1205
ZW
11786static void
11787do_t_ldstd (void)
11788{
11789 if (!inst.operands[1].present)
b99bd4ef 11790 {
c19d1205
ZW
11791 inst.operands[1].reg = inst.operands[0].reg + 1;
11792 constraint (inst.operands[0].reg == REG_LR,
11793 _("r14 not allowed here"));
bd340a04 11794 constraint (inst.operands[0].reg == REG_R12,
477330fc 11795 _("r12 not allowed here"));
b99bd4ef 11796 }
bd340a04
MGD
11797
11798 if (inst.operands[2].writeback
11799 && (inst.operands[0].reg == inst.operands[2].reg
11800 || inst.operands[1].reg == inst.operands[2].reg))
11801 as_warn (_("base register written back, and overlaps "
477330fc 11802 "one of transfer registers"));
bd340a04 11803
c19d1205
ZW
11804 inst.instruction |= inst.operands[0].reg << 12;
11805 inst.instruction |= inst.operands[1].reg << 8;
11806 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11807}
11808
c19d1205
ZW
11809static void
11810do_t_ldstt (void)
11811{
11812 inst.instruction |= inst.operands[0].reg << 12;
11813 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11814}
a737bd4d 11815
b99bd4ef 11816static void
c19d1205 11817do_t_mla (void)
b99bd4ef 11818{
fdfde340 11819 unsigned Rd, Rn, Rm, Ra;
c921be7d 11820
fdfde340
JM
11821 Rd = inst.operands[0].reg;
11822 Rn = inst.operands[1].reg;
11823 Rm = inst.operands[2].reg;
11824 Ra = inst.operands[3].reg;
11825
11826 reject_bad_reg (Rd);
11827 reject_bad_reg (Rn);
11828 reject_bad_reg (Rm);
11829 reject_bad_reg (Ra);
11830
11831 inst.instruction |= Rd << 8;
11832 inst.instruction |= Rn << 16;
11833 inst.instruction |= Rm;
11834 inst.instruction |= Ra << 12;
c19d1205 11835}
b99bd4ef 11836
c19d1205
ZW
11837static void
11838do_t_mlal (void)
11839{
fdfde340
JM
11840 unsigned RdLo, RdHi, Rn, Rm;
11841
11842 RdLo = inst.operands[0].reg;
11843 RdHi = inst.operands[1].reg;
11844 Rn = inst.operands[2].reg;
11845 Rm = inst.operands[3].reg;
11846
11847 reject_bad_reg (RdLo);
11848 reject_bad_reg (RdHi);
11849 reject_bad_reg (Rn);
11850 reject_bad_reg (Rm);
11851
11852 inst.instruction |= RdLo << 12;
11853 inst.instruction |= RdHi << 8;
11854 inst.instruction |= Rn << 16;
11855 inst.instruction |= Rm;
c19d1205 11856}
b99bd4ef 11857
c19d1205
ZW
11858static void
11859do_t_mov_cmp (void)
11860{
fdfde340
JM
11861 unsigned Rn, Rm;
11862
11863 Rn = inst.operands[0].reg;
11864 Rm = inst.operands[1].reg;
11865
e07e6e58
NC
11866 if (Rn == REG_PC)
11867 set_it_insn_type_last ();
11868
c19d1205 11869 if (unified_syntax)
b99bd4ef 11870 {
c19d1205
ZW
11871 int r0off = (inst.instruction == T_MNEM_mov
11872 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11873 unsigned long opcode;
3d388997
PB
11874 bfd_boolean narrow;
11875 bfd_boolean low_regs;
11876
fdfde340 11877 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11878 opcode = inst.instruction;
e07e6e58 11879 if (in_it_block ())
0110f2b8 11880 narrow = opcode != T_MNEM_movs;
3d388997 11881 else
0110f2b8 11882 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11883 if (inst.size_req == 4
11884 || inst.operands[1].shifted)
11885 narrow = FALSE;
11886
efd81785
PB
11887 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11888 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11889 && !inst.operands[1].shifted
fdfde340
JM
11890 && Rn == REG_PC
11891 && Rm == REG_LR)
efd81785
PB
11892 {
11893 inst.instruction = T2_SUBS_PC_LR;
11894 return;
11895 }
11896
fdfde340
JM
11897 if (opcode == T_MNEM_cmp)
11898 {
11899 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11900 if (narrow)
11901 {
11902 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11903 but valid. */
11904 warn_deprecated_sp (Rm);
11905 /* R15 was documented as a valid choice for Rm in ARMv6,
11906 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11907 tools reject R15, so we do too. */
11908 constraint (Rm == REG_PC, BAD_PC);
11909 }
11910 else
11911 reject_bad_reg (Rm);
fdfde340
JM
11912 }
11913 else if (opcode == T_MNEM_mov
11914 || opcode == T_MNEM_movs)
11915 {
11916 if (inst.operands[1].isreg)
11917 {
11918 if (opcode == T_MNEM_movs)
11919 {
11920 reject_bad_reg (Rn);
11921 reject_bad_reg (Rm);
11922 }
76fa04a4
MGD
11923 else if (narrow)
11924 {
11925 /* This is mov.n. */
11926 if ((Rn == REG_SP || Rn == REG_PC)
11927 && (Rm == REG_SP || Rm == REG_PC))
11928 {
5c3696f8 11929 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11930 "deprecated when r%u is the destination "
11931 "register."), Rm, Rn);
11932 }
11933 }
11934 else
11935 {
11936 /* This is mov.w. */
11937 constraint (Rn == REG_PC, BAD_PC);
11938 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
11939 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11940 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 11941 }
fdfde340
JM
11942 }
11943 else
11944 reject_bad_reg (Rn);
11945 }
11946
c19d1205
ZW
11947 if (!inst.operands[1].isreg)
11948 {
0110f2b8 11949 /* Immediate operand. */
e07e6e58 11950 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11951 narrow = 0;
11952 if (low_regs && narrow)
11953 {
11954 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11955 inst.instruction |= Rn << 8;
a9f02af8
MG
11956 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11957 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11958 {
a9f02af8 11959 if (inst.size_req == 2)
72d98d16 11960 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11961 else
11962 inst.relax = opcode;
72d98d16 11963 }
0110f2b8
PB
11964 }
11965 else
11966 {
a9f02af8
MG
11967 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11968 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11969 THUMB1_RELOC_ONLY);
11970
0110f2b8
PB
11971 inst.instruction = THUMB_OP32 (inst.instruction);
11972 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11973 inst.instruction |= Rn << r0off;
0110f2b8
PB
11974 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11975 }
c19d1205 11976 }
728ca7c9
PB
11977 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11978 && (inst.instruction == T_MNEM_mov
11979 || inst.instruction == T_MNEM_movs))
11980 {
11981 /* Register shifts are encoded as separate shift instructions. */
11982 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11983
e07e6e58 11984 if (in_it_block ())
728ca7c9
PB
11985 narrow = !flags;
11986 else
11987 narrow = flags;
11988
11989 if (inst.size_req == 4)
11990 narrow = FALSE;
11991
11992 if (!low_regs || inst.operands[1].imm > 7)
11993 narrow = FALSE;
11994
fdfde340 11995 if (Rn != Rm)
728ca7c9
PB
11996 narrow = FALSE;
11997
11998 switch (inst.operands[1].shift_kind)
11999 {
12000 case SHIFT_LSL:
12001 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12002 break;
12003 case SHIFT_ASR:
12004 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12005 break;
12006 case SHIFT_LSR:
12007 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12008 break;
12009 case SHIFT_ROR:
12010 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12011 break;
12012 default:
5f4273c7 12013 abort ();
728ca7c9
PB
12014 }
12015
12016 inst.instruction = opcode;
12017 if (narrow)
12018 {
fdfde340 12019 inst.instruction |= Rn;
728ca7c9
PB
12020 inst.instruction |= inst.operands[1].imm << 3;
12021 }
12022 else
12023 {
12024 if (flags)
12025 inst.instruction |= CONDS_BIT;
12026
fdfde340
JM
12027 inst.instruction |= Rn << 8;
12028 inst.instruction |= Rm << 16;
728ca7c9
PB
12029 inst.instruction |= inst.operands[1].imm;
12030 }
12031 }
3d388997 12032 else if (!narrow)
c19d1205 12033 {
728ca7c9
PB
12034 /* Some mov with immediate shift have narrow variants.
12035 Register shifts are handled above. */
12036 if (low_regs && inst.operands[1].shifted
12037 && (inst.instruction == T_MNEM_mov
12038 || inst.instruction == T_MNEM_movs))
12039 {
e07e6e58 12040 if (in_it_block ())
728ca7c9
PB
12041 narrow = (inst.instruction == T_MNEM_mov);
12042 else
12043 narrow = (inst.instruction == T_MNEM_movs);
12044 }
12045
12046 if (narrow)
12047 {
12048 switch (inst.operands[1].shift_kind)
12049 {
12050 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12051 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12052 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12053 default: narrow = FALSE; break;
12054 }
12055 }
12056
12057 if (narrow)
12058 {
fdfde340
JM
12059 inst.instruction |= Rn;
12060 inst.instruction |= Rm << 3;
728ca7c9
PB
12061 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12062 }
12063 else
12064 {
12065 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12066 inst.instruction |= Rn << r0off;
728ca7c9
PB
12067 encode_thumb32_shifted_operand (1);
12068 }
c19d1205
ZW
12069 }
12070 else
12071 switch (inst.instruction)
12072 {
12073 case T_MNEM_mov:
837b3435 12074 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12075 results. Don't allow this. */
12076 if (low_regs)
12077 {
12078 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12079 "MOV Rd, Rs with two low registers is not "
12080 "permitted on this architecture");
fa94de6b 12081 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12082 arm_ext_v6);
12083 }
12084
c19d1205 12085 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12086 inst.instruction |= (Rn & 0x8) << 4;
12087 inst.instruction |= (Rn & 0x7);
12088 inst.instruction |= Rm << 3;
c19d1205 12089 break;
b99bd4ef 12090
c19d1205
ZW
12091 case T_MNEM_movs:
12092 /* We know we have low registers at this point.
941a8a52
MGD
12093 Generate LSLS Rd, Rs, #0. */
12094 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12095 inst.instruction |= Rn;
12096 inst.instruction |= Rm << 3;
c19d1205
ZW
12097 break;
12098
12099 case T_MNEM_cmp:
3d388997 12100 if (low_regs)
c19d1205
ZW
12101 {
12102 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12103 inst.instruction |= Rn;
12104 inst.instruction |= Rm << 3;
c19d1205
ZW
12105 }
12106 else
12107 {
12108 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12109 inst.instruction |= (Rn & 0x8) << 4;
12110 inst.instruction |= (Rn & 0x7);
12111 inst.instruction |= Rm << 3;
c19d1205
ZW
12112 }
12113 break;
12114 }
b99bd4ef
NC
12115 return;
12116 }
12117
c19d1205 12118 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12119
12120 /* PR 10443: Do not silently ignore shifted operands. */
12121 constraint (inst.operands[1].shifted,
12122 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12123
c19d1205 12124 if (inst.operands[1].isreg)
b99bd4ef 12125 {
fdfde340 12126 if (Rn < 8 && Rm < 8)
b99bd4ef 12127 {
c19d1205
ZW
12128 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12129 since a MOV instruction produces unpredictable results. */
12130 if (inst.instruction == T_OPCODE_MOV_I8)
12131 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12132 else
c19d1205 12133 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12134
fdfde340
JM
12135 inst.instruction |= Rn;
12136 inst.instruction |= Rm << 3;
b99bd4ef
NC
12137 }
12138 else
12139 {
c19d1205
ZW
12140 if (inst.instruction == T_OPCODE_MOV_I8)
12141 inst.instruction = T_OPCODE_MOV_HR;
12142 else
12143 inst.instruction = T_OPCODE_CMP_HR;
12144 do_t_cpy ();
b99bd4ef
NC
12145 }
12146 }
c19d1205 12147 else
b99bd4ef 12148 {
fdfde340 12149 constraint (Rn > 7,
c19d1205 12150 _("only lo regs allowed with immediate"));
fdfde340 12151 inst.instruction |= Rn << 8;
c19d1205
ZW
12152 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12153 }
12154}
b99bd4ef 12155
c19d1205
ZW
12156static void
12157do_t_mov16 (void)
12158{
fdfde340 12159 unsigned Rd;
b6895b4f
PB
12160 bfd_vma imm;
12161 bfd_boolean top;
12162
12163 top = (inst.instruction & 0x00800000) != 0;
12164 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12165 {
33eaf5de 12166 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12167 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12168 }
12169 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12170 {
33eaf5de 12171 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12172 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12173 }
12174
fdfde340
JM
12175 Rd = inst.operands[0].reg;
12176 reject_bad_reg (Rd);
12177
12178 inst.instruction |= Rd << 8;
b6895b4f
PB
12179 if (inst.reloc.type == BFD_RELOC_UNUSED)
12180 {
12181 imm = inst.reloc.exp.X_add_number;
12182 inst.instruction |= (imm & 0xf000) << 4;
12183 inst.instruction |= (imm & 0x0800) << 15;
12184 inst.instruction |= (imm & 0x0700) << 4;
12185 inst.instruction |= (imm & 0x00ff);
12186 }
c19d1205 12187}
b99bd4ef 12188
c19d1205
ZW
12189static void
12190do_t_mvn_tst (void)
12191{
fdfde340 12192 unsigned Rn, Rm;
c921be7d 12193
fdfde340
JM
12194 Rn = inst.operands[0].reg;
12195 Rm = inst.operands[1].reg;
12196
12197 if (inst.instruction == T_MNEM_cmp
12198 || inst.instruction == T_MNEM_cmn)
12199 constraint (Rn == REG_PC, BAD_PC);
12200 else
12201 reject_bad_reg (Rn);
12202 reject_bad_reg (Rm);
12203
c19d1205
ZW
12204 if (unified_syntax)
12205 {
12206 int r0off = (inst.instruction == T_MNEM_mvn
12207 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12208 bfd_boolean narrow;
12209
12210 if (inst.size_req == 4
12211 || inst.instruction > 0xffff
12212 || inst.operands[1].shifted
fdfde340 12213 || Rn > 7 || Rm > 7)
3d388997 12214 narrow = FALSE;
fe8b4cc3
KT
12215 else if (inst.instruction == T_MNEM_cmn
12216 || inst.instruction == T_MNEM_tst)
3d388997
PB
12217 narrow = TRUE;
12218 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12219 narrow = !in_it_block ();
3d388997 12220 else
e07e6e58 12221 narrow = in_it_block ();
3d388997 12222
c19d1205 12223 if (!inst.operands[1].isreg)
b99bd4ef 12224 {
c19d1205
ZW
12225 /* For an immediate, we always generate a 32-bit opcode;
12226 section relaxation will shrink it later if possible. */
12227 if (inst.instruction < 0xffff)
12228 inst.instruction = THUMB_OP32 (inst.instruction);
12229 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12230 inst.instruction |= Rn << r0off;
c19d1205 12231 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12232 }
c19d1205 12233 else
b99bd4ef 12234 {
c19d1205 12235 /* See if we can do this with a 16-bit instruction. */
3d388997 12236 if (narrow)
b99bd4ef 12237 {
c19d1205 12238 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12239 inst.instruction |= Rn;
12240 inst.instruction |= Rm << 3;
b99bd4ef 12241 }
c19d1205 12242 else
b99bd4ef 12243 {
c19d1205
ZW
12244 constraint (inst.operands[1].shifted
12245 && inst.operands[1].immisreg,
12246 _("shift must be constant"));
12247 if (inst.instruction < 0xffff)
12248 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12249 inst.instruction |= Rn << r0off;
c19d1205 12250 encode_thumb32_shifted_operand (1);
b99bd4ef 12251 }
b99bd4ef
NC
12252 }
12253 }
12254 else
12255 {
c19d1205
ZW
12256 constraint (inst.instruction > 0xffff
12257 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12258 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12259 _("unshifted register required"));
fdfde340 12260 constraint (Rn > 7 || Rm > 7,
c19d1205 12261 BAD_HIREG);
b99bd4ef 12262
c19d1205 12263 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12264 inst.instruction |= Rn;
12265 inst.instruction |= Rm << 3;
b99bd4ef 12266 }
b99bd4ef
NC
12267}
12268
b05fe5cf 12269static void
c19d1205 12270do_t_mrs (void)
b05fe5cf 12271{
fdfde340 12272 unsigned Rd;
037e8744
JB
12273
12274 if (do_vfp_nsyn_mrs () == SUCCESS)
12275 return;
12276
90ec0d68
MGD
12277 Rd = inst.operands[0].reg;
12278 reject_bad_reg (Rd);
12279 inst.instruction |= Rd << 8;
12280
12281 if (inst.operands[1].isreg)
62b3e311 12282 {
90ec0d68
MGD
12283 unsigned br = inst.operands[1].reg;
12284 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12285 as_bad (_("bad register for mrs"));
12286
12287 inst.instruction |= br & (0xf << 16);
12288 inst.instruction |= (br & 0x300) >> 4;
12289 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12290 }
12291 else
12292 {
90ec0d68 12293 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12294
d2cd1205 12295 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12296 {
12297 /* PR gas/12698: The constraint is only applied for m_profile.
12298 If the user has specified -march=all, we want to ignore it as
12299 we are building for any CPU type, including non-m variants. */
823d2571
TG
12300 bfd_boolean m_profile =
12301 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12302 constraint ((flags != 0) && m_profile, _("selected processor does "
12303 "not support requested special purpose register"));
12304 }
90ec0d68 12305 else
d2cd1205
JB
12306 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12307 devices). */
12308 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12309 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12310
90ec0d68
MGD
12311 inst.instruction |= (flags & SPSR_BIT) >> 2;
12312 inst.instruction |= inst.operands[1].imm & 0xff;
12313 inst.instruction |= 0xf0000;
12314 }
c19d1205 12315}
b05fe5cf 12316
c19d1205
ZW
12317static void
12318do_t_msr (void)
12319{
62b3e311 12320 int flags;
fdfde340 12321 unsigned Rn;
62b3e311 12322
037e8744
JB
12323 if (do_vfp_nsyn_msr () == SUCCESS)
12324 return;
12325
c19d1205
ZW
12326 constraint (!inst.operands[1].isreg,
12327 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12328
12329 if (inst.operands[0].isreg)
12330 flags = (int)(inst.operands[0].reg);
12331 else
12332 flags = inst.operands[0].imm;
12333
d2cd1205 12334 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12335 {
d2cd1205
JB
12336 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12337
1a43faaf 12338 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12339 If the user has specified -march=all, we want to ignore it as
12340 we are building for any CPU type, including non-m variants. */
823d2571
TG
12341 bfd_boolean m_profile =
12342 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12343 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12344 && (bits & ~(PSR_s | PSR_f)) != 0)
12345 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12346 && bits != PSR_f)) && m_profile,
12347 _("selected processor does not support requested special "
12348 "purpose register"));
62b3e311
PB
12349 }
12350 else
d2cd1205
JB
12351 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12352 "requested special purpose register"));
c921be7d 12353
fdfde340
JM
12354 Rn = inst.operands[1].reg;
12355 reject_bad_reg (Rn);
12356
62b3e311 12357 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12358 inst.instruction |= (flags & 0xf0000) >> 8;
12359 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12360 inst.instruction |= (flags & 0xff);
fdfde340 12361 inst.instruction |= Rn << 16;
c19d1205 12362}
b05fe5cf 12363
c19d1205
ZW
12364static void
12365do_t_mul (void)
12366{
17828f45 12367 bfd_boolean narrow;
fdfde340 12368 unsigned Rd, Rn, Rm;
17828f45 12369
c19d1205
ZW
12370 if (!inst.operands[2].present)
12371 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12372
fdfde340
JM
12373 Rd = inst.operands[0].reg;
12374 Rn = inst.operands[1].reg;
12375 Rm = inst.operands[2].reg;
12376
17828f45 12377 if (unified_syntax)
b05fe5cf 12378 {
17828f45 12379 if (inst.size_req == 4
fdfde340
JM
12380 || (Rd != Rn
12381 && Rd != Rm)
12382 || Rn > 7
12383 || Rm > 7)
17828f45
JM
12384 narrow = FALSE;
12385 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12386 narrow = !in_it_block ();
17828f45 12387 else
e07e6e58 12388 narrow = in_it_block ();
b05fe5cf 12389 }
c19d1205 12390 else
b05fe5cf 12391 {
17828f45 12392 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12393 constraint (Rn > 7 || Rm > 7,
c19d1205 12394 BAD_HIREG);
17828f45
JM
12395 narrow = TRUE;
12396 }
b05fe5cf 12397
17828f45
JM
12398 if (narrow)
12399 {
12400 /* 16-bit MULS/Conditional MUL. */
c19d1205 12401 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12402 inst.instruction |= Rd;
b05fe5cf 12403
fdfde340
JM
12404 if (Rd == Rn)
12405 inst.instruction |= Rm << 3;
12406 else if (Rd == Rm)
12407 inst.instruction |= Rn << 3;
c19d1205
ZW
12408 else
12409 constraint (1, _("dest must overlap one source register"));
12410 }
17828f45
JM
12411 else
12412 {
e07e6e58
NC
12413 constraint (inst.instruction != T_MNEM_mul,
12414 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12415 /* 32-bit MUL. */
12416 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12417 inst.instruction |= Rd << 8;
12418 inst.instruction |= Rn << 16;
12419 inst.instruction |= Rm << 0;
12420
12421 reject_bad_reg (Rd);
12422 reject_bad_reg (Rn);
12423 reject_bad_reg (Rm);
17828f45 12424 }
c19d1205 12425}
b05fe5cf 12426
c19d1205
ZW
12427static void
12428do_t_mull (void)
12429{
fdfde340 12430 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12431
fdfde340
JM
12432 RdLo = inst.operands[0].reg;
12433 RdHi = inst.operands[1].reg;
12434 Rn = inst.operands[2].reg;
12435 Rm = inst.operands[3].reg;
12436
12437 reject_bad_reg (RdLo);
12438 reject_bad_reg (RdHi);
12439 reject_bad_reg (Rn);
12440 reject_bad_reg (Rm);
12441
12442 inst.instruction |= RdLo << 12;
12443 inst.instruction |= RdHi << 8;
12444 inst.instruction |= Rn << 16;
12445 inst.instruction |= Rm;
12446
12447 if (RdLo == RdHi)
c19d1205
ZW
12448 as_tsktsk (_("rdhi and rdlo must be different"));
12449}
b05fe5cf 12450
c19d1205
ZW
12451static void
12452do_t_nop (void)
12453{
e07e6e58
NC
12454 set_it_insn_type (NEUTRAL_IT_INSN);
12455
c19d1205
ZW
12456 if (unified_syntax)
12457 {
12458 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12459 {
c19d1205
ZW
12460 inst.instruction = THUMB_OP32 (inst.instruction);
12461 inst.instruction |= inst.operands[0].imm;
12462 }
12463 else
12464 {
bc2d1808
NC
12465 /* PR9722: Check for Thumb2 availability before
12466 generating a thumb2 nop instruction. */
afa62d5e 12467 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12468 {
12469 inst.instruction = THUMB_OP16 (inst.instruction);
12470 inst.instruction |= inst.operands[0].imm << 4;
12471 }
12472 else
12473 inst.instruction = 0x46c0;
c19d1205
ZW
12474 }
12475 }
12476 else
12477 {
12478 constraint (inst.operands[0].present,
12479 _("Thumb does not support NOP with hints"));
12480 inst.instruction = 0x46c0;
12481 }
12482}
b05fe5cf 12483
c19d1205
ZW
12484static void
12485do_t_neg (void)
12486{
12487 if (unified_syntax)
12488 {
3d388997
PB
12489 bfd_boolean narrow;
12490
12491 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12492 narrow = !in_it_block ();
3d388997 12493 else
e07e6e58 12494 narrow = in_it_block ();
3d388997
PB
12495 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12496 narrow = FALSE;
12497 if (inst.size_req == 4)
12498 narrow = FALSE;
12499
12500 if (!narrow)
c19d1205
ZW
12501 {
12502 inst.instruction = THUMB_OP32 (inst.instruction);
12503 inst.instruction |= inst.operands[0].reg << 8;
12504 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12505 }
12506 else
12507 {
c19d1205
ZW
12508 inst.instruction = THUMB_OP16 (inst.instruction);
12509 inst.instruction |= inst.operands[0].reg;
12510 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12511 }
12512 }
12513 else
12514 {
c19d1205
ZW
12515 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12516 BAD_HIREG);
12517 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12518
12519 inst.instruction = THUMB_OP16 (inst.instruction);
12520 inst.instruction |= inst.operands[0].reg;
12521 inst.instruction |= inst.operands[1].reg << 3;
12522 }
12523}
12524
1c444d06
JM
12525static void
12526do_t_orn (void)
12527{
12528 unsigned Rd, Rn;
12529
12530 Rd = inst.operands[0].reg;
12531 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12532
fdfde340
JM
12533 reject_bad_reg (Rd);
12534 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12535 reject_bad_reg (Rn);
12536
1c444d06
JM
12537 inst.instruction |= Rd << 8;
12538 inst.instruction |= Rn << 16;
12539
12540 if (!inst.operands[2].isreg)
12541 {
12542 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12543 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12544 }
12545 else
12546 {
12547 unsigned Rm;
12548
12549 Rm = inst.operands[2].reg;
fdfde340 12550 reject_bad_reg (Rm);
1c444d06
JM
12551
12552 constraint (inst.operands[2].shifted
12553 && inst.operands[2].immisreg,
12554 _("shift must be constant"));
12555 encode_thumb32_shifted_operand (2);
12556 }
12557}
12558
c19d1205
ZW
12559static void
12560do_t_pkhbt (void)
12561{
fdfde340
JM
12562 unsigned Rd, Rn, Rm;
12563
12564 Rd = inst.operands[0].reg;
12565 Rn = inst.operands[1].reg;
12566 Rm = inst.operands[2].reg;
12567
12568 reject_bad_reg (Rd);
12569 reject_bad_reg (Rn);
12570 reject_bad_reg (Rm);
12571
12572 inst.instruction |= Rd << 8;
12573 inst.instruction |= Rn << 16;
12574 inst.instruction |= Rm;
c19d1205
ZW
12575 if (inst.operands[3].present)
12576 {
12577 unsigned int val = inst.reloc.exp.X_add_number;
12578 constraint (inst.reloc.exp.X_op != O_constant,
12579 _("expression too complex"));
12580 inst.instruction |= (val & 0x1c) << 10;
12581 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12582 }
c19d1205 12583}
b05fe5cf 12584
c19d1205
ZW
12585static void
12586do_t_pkhtb (void)
12587{
12588 if (!inst.operands[3].present)
1ef52f49
NC
12589 {
12590 unsigned Rtmp;
12591
12592 inst.instruction &= ~0x00000020;
12593
12594 /* PR 10168. Swap the Rm and Rn registers. */
12595 Rtmp = inst.operands[1].reg;
12596 inst.operands[1].reg = inst.operands[2].reg;
12597 inst.operands[2].reg = Rtmp;
12598 }
c19d1205 12599 do_t_pkhbt ();
b05fe5cf
ZW
12600}
12601
c19d1205
ZW
12602static void
12603do_t_pld (void)
12604{
fdfde340
JM
12605 if (inst.operands[0].immisreg)
12606 reject_bad_reg (inst.operands[0].imm);
12607
c19d1205
ZW
12608 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12609}
b05fe5cf 12610
c19d1205
ZW
12611static void
12612do_t_push_pop (void)
b99bd4ef 12613{
e9f89963 12614 unsigned mask;
5f4273c7 12615
c19d1205
ZW
12616 constraint (inst.operands[0].writeback,
12617 _("push/pop do not support {reglist}^"));
12618 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12619 _("expression too complex"));
b99bd4ef 12620
e9f89963 12621 mask = inst.operands[0].imm;
d3bfe16e 12622 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12623 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12624 else if (inst.size_req != 4
c6025a80 12625 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12626 ? REG_LR : REG_PC)))
b99bd4ef 12627 {
c19d1205
ZW
12628 inst.instruction = THUMB_OP16 (inst.instruction);
12629 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12630 inst.instruction |= mask & 0xff;
c19d1205
ZW
12631 }
12632 else if (unified_syntax)
12633 {
3c707909 12634 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12635 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12636 }
12637 else
12638 {
12639 inst.error = _("invalid register list to push/pop instruction");
12640 return;
12641 }
c19d1205 12642}
b99bd4ef 12643
c19d1205
ZW
12644static void
12645do_t_rbit (void)
12646{
fdfde340
JM
12647 unsigned Rd, Rm;
12648
12649 Rd = inst.operands[0].reg;
12650 Rm = inst.operands[1].reg;
12651
12652 reject_bad_reg (Rd);
12653 reject_bad_reg (Rm);
12654
12655 inst.instruction |= Rd << 8;
12656 inst.instruction |= Rm << 16;
12657 inst.instruction |= Rm;
c19d1205 12658}
b99bd4ef 12659
c19d1205
ZW
12660static void
12661do_t_rev (void)
12662{
fdfde340
JM
12663 unsigned Rd, Rm;
12664
12665 Rd = inst.operands[0].reg;
12666 Rm = inst.operands[1].reg;
12667
12668 reject_bad_reg (Rd);
12669 reject_bad_reg (Rm);
12670
12671 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12672 && inst.size_req != 4)
12673 {
12674 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12675 inst.instruction |= Rd;
12676 inst.instruction |= Rm << 3;
c19d1205
ZW
12677 }
12678 else if (unified_syntax)
12679 {
12680 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12681 inst.instruction |= Rd << 8;
12682 inst.instruction |= Rm << 16;
12683 inst.instruction |= Rm;
c19d1205
ZW
12684 }
12685 else
12686 inst.error = BAD_HIREG;
12687}
b99bd4ef 12688
1c444d06
JM
12689static void
12690do_t_rrx (void)
12691{
12692 unsigned Rd, Rm;
12693
12694 Rd = inst.operands[0].reg;
12695 Rm = inst.operands[1].reg;
12696
fdfde340
JM
12697 reject_bad_reg (Rd);
12698 reject_bad_reg (Rm);
c921be7d 12699
1c444d06
JM
12700 inst.instruction |= Rd << 8;
12701 inst.instruction |= Rm;
12702}
12703
c19d1205
ZW
12704static void
12705do_t_rsb (void)
12706{
fdfde340 12707 unsigned Rd, Rs;
b99bd4ef 12708
c19d1205
ZW
12709 Rd = inst.operands[0].reg;
12710 Rs = (inst.operands[1].present
12711 ? inst.operands[1].reg /* Rd, Rs, foo */
12712 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12713
fdfde340
JM
12714 reject_bad_reg (Rd);
12715 reject_bad_reg (Rs);
12716 if (inst.operands[2].isreg)
12717 reject_bad_reg (inst.operands[2].reg);
12718
c19d1205
ZW
12719 inst.instruction |= Rd << 8;
12720 inst.instruction |= Rs << 16;
12721 if (!inst.operands[2].isreg)
12722 {
026d3abb
PB
12723 bfd_boolean narrow;
12724
12725 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12726 narrow = !in_it_block ();
026d3abb 12727 else
e07e6e58 12728 narrow = in_it_block ();
026d3abb
PB
12729
12730 if (Rd > 7 || Rs > 7)
12731 narrow = FALSE;
12732
12733 if (inst.size_req == 4 || !unified_syntax)
12734 narrow = FALSE;
12735
12736 if (inst.reloc.exp.X_op != O_constant
12737 || inst.reloc.exp.X_add_number != 0)
12738 narrow = FALSE;
12739
12740 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12741 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12742 if (narrow)
12743 {
12744 inst.reloc.type = BFD_RELOC_UNUSED;
12745 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12746 inst.instruction |= Rs << 3;
12747 inst.instruction |= Rd;
12748 }
12749 else
12750 {
12751 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12752 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12753 }
c19d1205
ZW
12754 }
12755 else
12756 encode_thumb32_shifted_operand (2);
12757}
b99bd4ef 12758
c19d1205
ZW
12759static void
12760do_t_setend (void)
12761{
12e37cbc
MGD
12762 if (warn_on_deprecated
12763 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12764 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12765
e07e6e58 12766 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12767 if (inst.operands[0].imm)
12768 inst.instruction |= 0x8;
12769}
b99bd4ef 12770
c19d1205
ZW
12771static void
12772do_t_shift (void)
12773{
12774 if (!inst.operands[1].present)
12775 inst.operands[1].reg = inst.operands[0].reg;
12776
12777 if (unified_syntax)
12778 {
3d388997
PB
12779 bfd_boolean narrow;
12780 int shift_kind;
12781
12782 switch (inst.instruction)
12783 {
12784 case T_MNEM_asr:
12785 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12786 case T_MNEM_lsl:
12787 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12788 case T_MNEM_lsr:
12789 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12790 case T_MNEM_ror:
12791 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12792 default: abort ();
12793 }
12794
12795 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12796 narrow = !in_it_block ();
3d388997 12797 else
e07e6e58 12798 narrow = in_it_block ();
3d388997
PB
12799 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12800 narrow = FALSE;
12801 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12802 narrow = FALSE;
12803 if (inst.operands[2].isreg
12804 && (inst.operands[1].reg != inst.operands[0].reg
12805 || inst.operands[2].reg > 7))
12806 narrow = FALSE;
12807 if (inst.size_req == 4)
12808 narrow = FALSE;
12809
fdfde340
JM
12810 reject_bad_reg (inst.operands[0].reg);
12811 reject_bad_reg (inst.operands[1].reg);
c921be7d 12812
3d388997 12813 if (!narrow)
c19d1205
ZW
12814 {
12815 if (inst.operands[2].isreg)
b99bd4ef 12816 {
fdfde340 12817 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12818 inst.instruction = THUMB_OP32 (inst.instruction);
12819 inst.instruction |= inst.operands[0].reg << 8;
12820 inst.instruction |= inst.operands[1].reg << 16;
12821 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12822
12823 /* PR 12854: Error on extraneous shifts. */
12824 constraint (inst.operands[2].shifted,
12825 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12826 }
12827 else
12828 {
12829 inst.operands[1].shifted = 1;
3d388997 12830 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12831 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12832 ? T_MNEM_movs : T_MNEM_mov);
12833 inst.instruction |= inst.operands[0].reg << 8;
12834 encode_thumb32_shifted_operand (1);
12835 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12836 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12837 }
12838 }
12839 else
12840 {
c19d1205 12841 if (inst.operands[2].isreg)
b99bd4ef 12842 {
3d388997 12843 switch (shift_kind)
b99bd4ef 12844 {
3d388997
PB
12845 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12846 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12847 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12848 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12849 default: abort ();
b99bd4ef 12850 }
5f4273c7 12851
c19d1205
ZW
12852 inst.instruction |= inst.operands[0].reg;
12853 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12854
12855 /* PR 12854: Error on extraneous shifts. */
12856 constraint (inst.operands[2].shifted,
12857 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12858 }
12859 else
12860 {
3d388997 12861 switch (shift_kind)
b99bd4ef 12862 {
3d388997
PB
12863 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12864 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12865 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12866 default: abort ();
b99bd4ef 12867 }
c19d1205
ZW
12868 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12869 inst.instruction |= inst.operands[0].reg;
12870 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12871 }
12872 }
c19d1205
ZW
12873 }
12874 else
12875 {
12876 constraint (inst.operands[0].reg > 7
12877 || inst.operands[1].reg > 7, BAD_HIREG);
12878 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12879
c19d1205
ZW
12880 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12881 {
12882 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12883 constraint (inst.operands[0].reg != inst.operands[1].reg,
12884 _("source1 and dest must be same register"));
b99bd4ef 12885
c19d1205
ZW
12886 switch (inst.instruction)
12887 {
12888 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12889 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12890 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12891 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12892 default: abort ();
12893 }
5f4273c7 12894
c19d1205
ZW
12895 inst.instruction |= inst.operands[0].reg;
12896 inst.instruction |= inst.operands[2].reg << 3;
af199b06
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
b99bd4ef 12903 {
c19d1205
ZW
12904 switch (inst.instruction)
12905 {
12906 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12907 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12908 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12909 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12910 default: abort ();
12911 }
12912 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12913 inst.instruction |= inst.operands[0].reg;
12914 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12915 }
12916 }
b99bd4ef
NC
12917}
12918
12919static void
c19d1205 12920do_t_simd (void)
b99bd4ef 12921{
fdfde340
JM
12922 unsigned Rd, Rn, Rm;
12923
12924 Rd = inst.operands[0].reg;
12925 Rn = inst.operands[1].reg;
12926 Rm = inst.operands[2].reg;
12927
12928 reject_bad_reg (Rd);
12929 reject_bad_reg (Rn);
12930 reject_bad_reg (Rm);
12931
12932 inst.instruction |= Rd << 8;
12933 inst.instruction |= Rn << 16;
12934 inst.instruction |= Rm;
c19d1205 12935}
b99bd4ef 12936
03ee1b7f
NC
12937static void
12938do_t_simd2 (void)
12939{
12940 unsigned Rd, Rn, Rm;
12941
12942 Rd = inst.operands[0].reg;
12943 Rm = inst.operands[1].reg;
12944 Rn = inst.operands[2].reg;
12945
12946 reject_bad_reg (Rd);
12947 reject_bad_reg (Rn);
12948 reject_bad_reg (Rm);
12949
12950 inst.instruction |= Rd << 8;
12951 inst.instruction |= Rn << 16;
12952 inst.instruction |= Rm;
12953}
12954
c19d1205 12955static void
3eb17e6b 12956do_t_smc (void)
c19d1205
ZW
12957{
12958 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12959 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12960 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12961 constraint (inst.reloc.exp.X_op != O_constant,
12962 _("expression too complex"));
12963 inst.reloc.type = BFD_RELOC_UNUSED;
12964 inst.instruction |= (value & 0xf000) >> 12;
12965 inst.instruction |= (value & 0x0ff0);
12966 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12967 /* PR gas/15623: SMC instructions must be last in an IT block. */
12968 set_it_insn_type_last ();
c19d1205 12969}
b99bd4ef 12970
90ec0d68
MGD
12971static void
12972do_t_hvc (void)
12973{
12974 unsigned int value = inst.reloc.exp.X_add_number;
12975
12976 inst.reloc.type = BFD_RELOC_UNUSED;
12977 inst.instruction |= (value & 0x0fff);
12978 inst.instruction |= (value & 0xf000) << 4;
12979}
12980
c19d1205 12981static void
3a21c15a 12982do_t_ssat_usat (int bias)
c19d1205 12983{
fdfde340
JM
12984 unsigned Rd, Rn;
12985
12986 Rd = inst.operands[0].reg;
12987 Rn = inst.operands[2].reg;
12988
12989 reject_bad_reg (Rd);
12990 reject_bad_reg (Rn);
12991
12992 inst.instruction |= Rd << 8;
3a21c15a 12993 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12994 inst.instruction |= Rn << 16;
b99bd4ef 12995
c19d1205 12996 if (inst.operands[3].present)
b99bd4ef 12997 {
3a21c15a
NC
12998 offsetT shift_amount = inst.reloc.exp.X_add_number;
12999
13000 inst.reloc.type = BFD_RELOC_UNUSED;
13001
c19d1205
ZW
13002 constraint (inst.reloc.exp.X_op != O_constant,
13003 _("expression too complex"));
b99bd4ef 13004
3a21c15a 13005 if (shift_amount != 0)
6189168b 13006 {
3a21c15a
NC
13007 constraint (shift_amount > 31,
13008 _("shift expression is too large"));
13009
c19d1205 13010 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13011 inst.instruction |= 0x00200000; /* sh bit. */
13012
13013 inst.instruction |= (shift_amount & 0x1c) << 10;
13014 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13015 }
13016 }
b99bd4ef 13017}
c921be7d 13018
3a21c15a
NC
13019static void
13020do_t_ssat (void)
13021{
13022 do_t_ssat_usat (1);
13023}
b99bd4ef 13024
0dd132b6 13025static void
c19d1205 13026do_t_ssat16 (void)
0dd132b6 13027{
fdfde340
JM
13028 unsigned Rd, Rn;
13029
13030 Rd = inst.operands[0].reg;
13031 Rn = inst.operands[2].reg;
13032
13033 reject_bad_reg (Rd);
13034 reject_bad_reg (Rn);
13035
13036 inst.instruction |= Rd << 8;
c19d1205 13037 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13038 inst.instruction |= Rn << 16;
c19d1205 13039}
0dd132b6 13040
c19d1205
ZW
13041static void
13042do_t_strex (void)
13043{
13044 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13045 || inst.operands[2].postind || inst.operands[2].writeback
13046 || inst.operands[2].immisreg || inst.operands[2].shifted
13047 || inst.operands[2].negative,
01cfc07f 13048 BAD_ADDR_MODE);
0dd132b6 13049
5be8be5d
DG
13050 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13051
c19d1205
ZW
13052 inst.instruction |= inst.operands[0].reg << 8;
13053 inst.instruction |= inst.operands[1].reg << 12;
13054 inst.instruction |= inst.operands[2].reg << 16;
13055 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13056}
13057
b99bd4ef 13058static void
c19d1205 13059do_t_strexd (void)
b99bd4ef 13060{
c19d1205
ZW
13061 if (!inst.operands[2].present)
13062 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13063
c19d1205
ZW
13064 constraint (inst.operands[0].reg == inst.operands[1].reg
13065 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13066 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13067 BAD_OVERLAP);
b99bd4ef 13068
c19d1205
ZW
13069 inst.instruction |= inst.operands[0].reg;
13070 inst.instruction |= inst.operands[1].reg << 12;
13071 inst.instruction |= inst.operands[2].reg << 8;
13072 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13073}
13074
13075static void
c19d1205 13076do_t_sxtah (void)
b99bd4ef 13077{
fdfde340
JM
13078 unsigned Rd, Rn, Rm;
13079
13080 Rd = inst.operands[0].reg;
13081 Rn = inst.operands[1].reg;
13082 Rm = inst.operands[2].reg;
13083
13084 reject_bad_reg (Rd);
13085 reject_bad_reg (Rn);
13086 reject_bad_reg (Rm);
13087
13088 inst.instruction |= Rd << 8;
13089 inst.instruction |= Rn << 16;
13090 inst.instruction |= Rm;
c19d1205
ZW
13091 inst.instruction |= inst.operands[3].imm << 4;
13092}
b99bd4ef 13093
c19d1205
ZW
13094static void
13095do_t_sxth (void)
13096{
fdfde340
JM
13097 unsigned Rd, Rm;
13098
13099 Rd = inst.operands[0].reg;
13100 Rm = inst.operands[1].reg;
13101
13102 reject_bad_reg (Rd);
13103 reject_bad_reg (Rm);
c921be7d
NC
13104
13105 if (inst.instruction <= 0xffff
13106 && inst.size_req != 4
fdfde340 13107 && Rd <= 7 && Rm <= 7
c19d1205 13108 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13109 {
c19d1205 13110 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13111 inst.instruction |= Rd;
13112 inst.instruction |= Rm << 3;
b99bd4ef 13113 }
c19d1205 13114 else if (unified_syntax)
b99bd4ef 13115 {
c19d1205
ZW
13116 if (inst.instruction <= 0xffff)
13117 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13118 inst.instruction |= Rd << 8;
13119 inst.instruction |= Rm;
c19d1205 13120 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13121 }
c19d1205 13122 else
b99bd4ef 13123 {
c19d1205
ZW
13124 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13125 _("Thumb encoding does not support rotation"));
13126 constraint (1, BAD_HIREG);
b99bd4ef 13127 }
c19d1205 13128}
b99bd4ef 13129
c19d1205
ZW
13130static void
13131do_t_swi (void)
13132{
13133 inst.reloc.type = BFD_RELOC_ARM_SWI;
13134}
b99bd4ef 13135
92e90b6e
PB
13136static void
13137do_t_tb (void)
13138{
fdfde340 13139 unsigned Rn, Rm;
92e90b6e
PB
13140 int half;
13141
13142 half = (inst.instruction & 0x10) != 0;
e07e6e58 13143 set_it_insn_type_last ();
dfa9f0d5
PB
13144 constraint (inst.operands[0].immisreg,
13145 _("instruction requires register index"));
fdfde340
JM
13146
13147 Rn = inst.operands[0].reg;
13148 Rm = inst.operands[0].imm;
c921be7d 13149
5c8ed6a4
JW
13150 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13151 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13152 reject_bad_reg (Rm);
13153
92e90b6e
PB
13154 constraint (!half && inst.operands[0].shifted,
13155 _("instruction does not allow shifted index"));
fdfde340 13156 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13157}
13158
74db7efb
NC
13159static void
13160do_t_udf (void)
13161{
13162 if (!inst.operands[0].present)
13163 inst.operands[0].imm = 0;
13164
13165 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13166 {
13167 constraint (inst.size_req == 2,
13168 _("immediate value out of range"));
13169 inst.instruction = THUMB_OP32 (inst.instruction);
13170 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13171 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13172 }
13173 else
13174 {
13175 inst.instruction = THUMB_OP16 (inst.instruction);
13176 inst.instruction |= inst.operands[0].imm;
13177 }
13178
13179 set_it_insn_type (NEUTRAL_IT_INSN);
13180}
13181
13182
c19d1205
ZW
13183static void
13184do_t_usat (void)
13185{
3a21c15a 13186 do_t_ssat_usat (0);
b99bd4ef
NC
13187}
13188
13189static void
c19d1205 13190do_t_usat16 (void)
b99bd4ef 13191{
fdfde340
JM
13192 unsigned Rd, Rn;
13193
13194 Rd = inst.operands[0].reg;
13195 Rn = inst.operands[2].reg;
13196
13197 reject_bad_reg (Rd);
13198 reject_bad_reg (Rn);
13199
13200 inst.instruction |= Rd << 8;
c19d1205 13201 inst.instruction |= inst.operands[1].imm;
fdfde340 13202 inst.instruction |= Rn << 16;
b99bd4ef 13203}
c19d1205 13204
5287ad62 13205/* Neon instruction encoder helpers. */
5f4273c7 13206
5287ad62 13207/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13208
5287ad62
JB
13209/* An "invalid" code for the following tables. */
13210#define N_INV -1u
13211
13212struct neon_tab_entry
b99bd4ef 13213{
5287ad62
JB
13214 unsigned integer;
13215 unsigned float_or_poly;
13216 unsigned scalar_or_imm;
13217};
5f4273c7 13218
5287ad62
JB
13219/* Map overloaded Neon opcodes to their respective encodings. */
13220#define NEON_ENC_TAB \
13221 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13222 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13223 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13224 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13225 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13226 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13227 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13228 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13229 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13230 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13231 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13232 /* Register variants of the following two instructions are encoded as
e07e6e58 13233 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13234 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13235 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13236 X(vfma, N_INV, 0x0000c10, N_INV), \
13237 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13238 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13239 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13240 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13241 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13242 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13243 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13244 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13245 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13246 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13247 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13248 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13249 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13250 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13251 X(vshl, 0x0000400, N_INV, 0x0800510), \
13252 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13253 X(vand, 0x0000110, N_INV, 0x0800030), \
13254 X(vbic, 0x0100110, N_INV, 0x0800030), \
13255 X(veor, 0x1000110, N_INV, N_INV), \
13256 X(vorn, 0x0300110, N_INV, 0x0800010), \
13257 X(vorr, 0x0200110, N_INV, 0x0800010), \
13258 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13259 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13260 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13261 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13262 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13263 X(vst1, 0x0000000, 0x0800000, N_INV), \
13264 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13265 X(vst2, 0x0000100, 0x0800100, N_INV), \
13266 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13267 X(vst3, 0x0000200, 0x0800200, N_INV), \
13268 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13269 X(vst4, 0x0000300, 0x0800300, N_INV), \
13270 X(vmovn, 0x1b20200, N_INV, N_INV), \
13271 X(vtrn, 0x1b20080, N_INV, N_INV), \
13272 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13273 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13274 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13275 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13276 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13277 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13278 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13279 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13280 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13281 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13282 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13283 X(vseleq, 0xe000a00, N_INV, N_INV), \
13284 X(vselvs, 0xe100a00, N_INV, N_INV), \
13285 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13286 X(vselgt, 0xe300a00, N_INV, N_INV), \
13287 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13288 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13289 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13290 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13291 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13292 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13293 X(sha3op, 0x2000c00, N_INV, N_INV), \
13294 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13295 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13296
13297enum neon_opc
13298{
13299#define X(OPC,I,F,S) N_MNEM_##OPC
13300NEON_ENC_TAB
13301#undef X
13302};
b99bd4ef 13303
5287ad62
JB
13304static const struct neon_tab_entry neon_enc_tab[] =
13305{
13306#define X(OPC,I,F,S) { (I), (F), (S) }
13307NEON_ENC_TAB
13308#undef X
13309};
b99bd4ef 13310
88714cb8
DG
13311/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13312#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13313#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13314#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13315#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13316#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13317#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13318#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13319#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13320#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13321#define NEON_ENC_SINGLE_(X) \
037e8744 13322 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13323#define NEON_ENC_DOUBLE_(X) \
037e8744 13324 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13325#define NEON_ENC_FPV8_(X) \
13326 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13327
88714cb8
DG
13328#define NEON_ENCODE(type, inst) \
13329 do \
13330 { \
13331 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13332 inst.is_neon = 1; \
13333 } \
13334 while (0)
13335
13336#define check_neon_suffixes \
13337 do \
13338 { \
13339 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13340 { \
13341 as_bad (_("invalid neon suffix for non neon instruction")); \
13342 return; \
13343 } \
13344 } \
13345 while (0)
13346
037e8744
JB
13347/* Define shapes for instruction operands. The following mnemonic characters
13348 are used in this table:
5287ad62 13349
037e8744 13350 F - VFP S<n> register
5287ad62
JB
13351 D - Neon D<n> register
13352 Q - Neon Q<n> register
13353 I - Immediate
13354 S - Scalar
13355 R - ARM register
13356 L - D<n> register list
5f4273c7 13357
037e8744
JB
13358 This table is used to generate various data:
13359 - enumerations of the form NS_DDR to be used as arguments to
13360 neon_select_shape.
13361 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13362 - a table used to drive neon_select_shape. */
b99bd4ef 13363
037e8744
JB
13364#define NEON_SHAPE_DEF \
13365 X(3, (D, D, D), DOUBLE), \
13366 X(3, (Q, Q, Q), QUAD), \
13367 X(3, (D, D, I), DOUBLE), \
13368 X(3, (Q, Q, I), QUAD), \
13369 X(3, (D, D, S), DOUBLE), \
13370 X(3, (Q, Q, S), QUAD), \
13371 X(2, (D, D), DOUBLE), \
13372 X(2, (Q, Q), QUAD), \
13373 X(2, (D, S), DOUBLE), \
13374 X(2, (Q, S), QUAD), \
13375 X(2, (D, R), DOUBLE), \
13376 X(2, (Q, R), QUAD), \
13377 X(2, (D, I), DOUBLE), \
13378 X(2, (Q, I), QUAD), \
13379 X(3, (D, L, D), DOUBLE), \
13380 X(2, (D, Q), MIXED), \
13381 X(2, (Q, D), MIXED), \
13382 X(3, (D, Q, I), MIXED), \
13383 X(3, (Q, D, I), MIXED), \
13384 X(3, (Q, D, D), MIXED), \
13385 X(3, (D, Q, Q), MIXED), \
13386 X(3, (Q, Q, D), MIXED), \
13387 X(3, (Q, D, S), MIXED), \
13388 X(3, (D, Q, S), MIXED), \
13389 X(4, (D, D, D, I), DOUBLE), \
13390 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13391 X(4, (D, D, S, I), DOUBLE), \
13392 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13393 X(2, (F, F), SINGLE), \
13394 X(3, (F, F, F), SINGLE), \
13395 X(2, (F, I), SINGLE), \
13396 X(2, (F, D), MIXED), \
13397 X(2, (D, F), MIXED), \
13398 X(3, (F, F, I), MIXED), \
13399 X(4, (R, R, F, F), SINGLE), \
13400 X(4, (F, F, R, R), SINGLE), \
13401 X(3, (D, R, R), DOUBLE), \
13402 X(3, (R, R, D), DOUBLE), \
13403 X(2, (S, R), SINGLE), \
13404 X(2, (R, S), SINGLE), \
13405 X(2, (F, R), SINGLE), \
d54af2d0
RL
13406 X(2, (R, F), SINGLE), \
13407/* Half float shape supported so far. */\
13408 X (2, (H, D), MIXED), \
13409 X (2, (D, H), MIXED), \
13410 X (2, (H, F), MIXED), \
13411 X (2, (F, H), MIXED), \
13412 X (2, (H, H), HALF), \
13413 X (2, (H, R), HALF), \
13414 X (2, (R, H), HALF), \
13415 X (2, (H, I), HALF), \
13416 X (3, (H, H, H), HALF), \
13417 X (3, (H, F, I), MIXED), \
13418 X (3, (F, H, I), MIXED)
037e8744
JB
13419
13420#define S2(A,B) NS_##A##B
13421#define S3(A,B,C) NS_##A##B##C
13422#define S4(A,B,C,D) NS_##A##B##C##D
13423
13424#define X(N, L, C) S##N L
13425
5287ad62
JB
13426enum neon_shape
13427{
037e8744
JB
13428 NEON_SHAPE_DEF,
13429 NS_NULL
5287ad62 13430};
b99bd4ef 13431
037e8744
JB
13432#undef X
13433#undef S2
13434#undef S3
13435#undef S4
13436
13437enum neon_shape_class
13438{
d54af2d0 13439 SC_HALF,
037e8744
JB
13440 SC_SINGLE,
13441 SC_DOUBLE,
13442 SC_QUAD,
13443 SC_MIXED
13444};
13445
13446#define X(N, L, C) SC_##C
13447
13448static enum neon_shape_class neon_shape_class[] =
13449{
13450 NEON_SHAPE_DEF
13451};
13452
13453#undef X
13454
13455enum neon_shape_el
13456{
d54af2d0 13457 SE_H,
037e8744
JB
13458 SE_F,
13459 SE_D,
13460 SE_Q,
13461 SE_I,
13462 SE_S,
13463 SE_R,
13464 SE_L
13465};
13466
13467/* Register widths of above. */
13468static unsigned neon_shape_el_size[] =
13469{
d54af2d0 13470 16,
037e8744
JB
13471 32,
13472 64,
13473 128,
13474 0,
13475 32,
13476 32,
13477 0
13478};
13479
13480struct neon_shape_info
13481{
13482 unsigned els;
13483 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13484};
13485
13486#define S2(A,B) { SE_##A, SE_##B }
13487#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13488#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13489
13490#define X(N, L, C) { N, S##N L }
13491
13492static struct neon_shape_info neon_shape_tab[] =
13493{
13494 NEON_SHAPE_DEF
13495};
13496
13497#undef X
13498#undef S2
13499#undef S3
13500#undef S4
13501
5287ad62
JB
13502/* Bit masks used in type checking given instructions.
13503 'N_EQK' means the type must be the same as (or based on in some way) the key
13504 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13505 set, various other bits can be set as well in order to modify the meaning of
13506 the type constraint. */
13507
13508enum neon_type_mask
13509{
8e79c3df
CM
13510 N_S8 = 0x0000001,
13511 N_S16 = 0x0000002,
13512 N_S32 = 0x0000004,
13513 N_S64 = 0x0000008,
13514 N_U8 = 0x0000010,
13515 N_U16 = 0x0000020,
13516 N_U32 = 0x0000040,
13517 N_U64 = 0x0000080,
13518 N_I8 = 0x0000100,
13519 N_I16 = 0x0000200,
13520 N_I32 = 0x0000400,
13521 N_I64 = 0x0000800,
13522 N_8 = 0x0001000,
13523 N_16 = 0x0002000,
13524 N_32 = 0x0004000,
13525 N_64 = 0x0008000,
13526 N_P8 = 0x0010000,
13527 N_P16 = 0x0020000,
13528 N_F16 = 0x0040000,
13529 N_F32 = 0x0080000,
13530 N_F64 = 0x0100000,
4f51b4bd 13531 N_P64 = 0x0200000,
c921be7d
NC
13532 N_KEY = 0x1000000, /* Key element (main type specifier). */
13533 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13534 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13535 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13536 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13537 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13538 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13539 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13540 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13541 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13542 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13543 N_UTYP = 0,
4f51b4bd 13544 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13545};
13546
dcbf9037
JB
13547#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13548
5287ad62
JB
13549#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13550#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13551#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13552#define N_S_32 (N_S8 | N_S16 | N_S32)
13553#define N_F_16_32 (N_F16 | N_F32)
13554#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13555#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13556#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13557#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13558
13559/* Pass this as the first type argument to neon_check_type to ignore types
13560 altogether. */
13561#define N_IGNORE_TYPE (N_KEY | N_EQK)
13562
037e8744
JB
13563/* Select a "shape" for the current instruction (describing register types or
13564 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13565 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13566 function of operand parsing, so this function doesn't need to be called.
13567 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13568
13569static enum neon_shape
037e8744 13570neon_select_shape (enum neon_shape shape, ...)
5287ad62 13571{
037e8744
JB
13572 va_list ap;
13573 enum neon_shape first_shape = shape;
5287ad62
JB
13574
13575 /* Fix missing optional operands. FIXME: we don't know at this point how
13576 many arguments we should have, so this makes the assumption that we have
13577 > 1. This is true of all current Neon opcodes, I think, but may not be
13578 true in the future. */
13579 if (!inst.operands[1].present)
13580 inst.operands[1] = inst.operands[0];
13581
037e8744 13582 va_start (ap, shape);
5f4273c7 13583
21d799b5 13584 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13585 {
13586 unsigned j;
13587 int matches = 1;
13588
13589 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13590 {
13591 if (!inst.operands[j].present)
13592 {
13593 matches = 0;
13594 break;
13595 }
13596
13597 switch (neon_shape_tab[shape].el[j])
13598 {
d54af2d0
RL
13599 /* If a .f16, .16, .u16, .s16 type specifier is given over
13600 a VFP single precision register operand, it's essentially
13601 means only half of the register is used.
13602
13603 If the type specifier is given after the mnemonics, the
13604 information is stored in inst.vectype. If the type specifier
13605 is given after register operand, the information is stored
13606 in inst.operands[].vectype.
13607
13608 When there is only one type specifier, and all the register
13609 operands are the same type of hardware register, the type
13610 specifier applies to all register operands.
13611
13612 If no type specifier is given, the shape is inferred from
13613 operand information.
13614
13615 for example:
13616 vadd.f16 s0, s1, s2: NS_HHH
13617 vabs.f16 s0, s1: NS_HH
13618 vmov.f16 s0, r1: NS_HR
13619 vmov.f16 r0, s1: NS_RH
13620 vcvt.f16 r0, s1: NS_RH
13621 vcvt.f16.s32 s2, s2, #29: NS_HFI
13622 vcvt.f16.s32 s2, s2: NS_HF
13623 */
13624 case SE_H:
13625 if (!(inst.operands[j].isreg
13626 && inst.operands[j].isvec
13627 && inst.operands[j].issingle
13628 && !inst.operands[j].isquad
13629 && ((inst.vectype.elems == 1
13630 && inst.vectype.el[0].size == 16)
13631 || (inst.vectype.elems > 1
13632 && inst.vectype.el[j].size == 16)
13633 || (inst.vectype.elems == 0
13634 && inst.operands[j].vectype.type != NT_invtype
13635 && inst.operands[j].vectype.size == 16))))
13636 matches = 0;
13637 break;
13638
477330fc
RM
13639 case SE_F:
13640 if (!(inst.operands[j].isreg
13641 && inst.operands[j].isvec
13642 && inst.operands[j].issingle
d54af2d0
RL
13643 && !inst.operands[j].isquad
13644 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13645 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13646 || (inst.vectype.elems == 0
13647 && (inst.operands[j].vectype.size == 32
13648 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13649 matches = 0;
13650 break;
13651
13652 case SE_D:
13653 if (!(inst.operands[j].isreg
13654 && inst.operands[j].isvec
13655 && !inst.operands[j].isquad
13656 && !inst.operands[j].issingle))
13657 matches = 0;
13658 break;
13659
13660 case SE_R:
13661 if (!(inst.operands[j].isreg
13662 && !inst.operands[j].isvec))
13663 matches = 0;
13664 break;
13665
13666 case SE_Q:
13667 if (!(inst.operands[j].isreg
13668 && inst.operands[j].isvec
13669 && inst.operands[j].isquad
13670 && !inst.operands[j].issingle))
13671 matches = 0;
13672 break;
13673
13674 case SE_I:
13675 if (!(!inst.operands[j].isreg
13676 && !inst.operands[j].isscalar))
13677 matches = 0;
13678 break;
13679
13680 case SE_S:
13681 if (!(!inst.operands[j].isreg
13682 && inst.operands[j].isscalar))
13683 matches = 0;
13684 break;
13685
13686 case SE_L:
13687 break;
13688 }
3fde54a2
JZ
13689 if (!matches)
13690 break;
477330fc 13691 }
ad6cec43
MGD
13692 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13693 /* We've matched all the entries in the shape table, and we don't
13694 have any left over operands which have not been matched. */
477330fc 13695 break;
037e8744 13696 }
5f4273c7 13697
037e8744 13698 va_end (ap);
5287ad62 13699
037e8744
JB
13700 if (shape == NS_NULL && first_shape != NS_NULL)
13701 first_error (_("invalid instruction shape"));
5287ad62 13702
037e8744
JB
13703 return shape;
13704}
5287ad62 13705
037e8744
JB
13706/* True if SHAPE is predominantly a quadword operation (most of the time, this
13707 means the Q bit should be set). */
13708
13709static int
13710neon_quad (enum neon_shape shape)
13711{
13712 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13713}
037e8744 13714
5287ad62
JB
13715static void
13716neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13717 unsigned *g_size)
5287ad62
JB
13718{
13719 /* Allow modification to be made to types which are constrained to be
13720 based on the key element, based on bits set alongside N_EQK. */
13721 if ((typebits & N_EQK) != 0)
13722 {
13723 if ((typebits & N_HLF) != 0)
13724 *g_size /= 2;
13725 else if ((typebits & N_DBL) != 0)
13726 *g_size *= 2;
13727 if ((typebits & N_SGN) != 0)
13728 *g_type = NT_signed;
13729 else if ((typebits & N_UNS) != 0)
477330fc 13730 *g_type = NT_unsigned;
5287ad62 13731 else if ((typebits & N_INT) != 0)
477330fc 13732 *g_type = NT_integer;
5287ad62 13733 else if ((typebits & N_FLT) != 0)
477330fc 13734 *g_type = NT_float;
dcbf9037 13735 else if ((typebits & N_SIZ) != 0)
477330fc 13736 *g_type = NT_untyped;
5287ad62
JB
13737 }
13738}
5f4273c7 13739
5287ad62
JB
13740/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13741 operand type, i.e. the single type specified in a Neon instruction when it
13742 is the only one given. */
13743
13744static struct neon_type_el
13745neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13746{
13747 struct neon_type_el dest = *key;
5f4273c7 13748
9c2799c2 13749 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13750
5287ad62
JB
13751 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13752
13753 return dest;
13754}
13755
13756/* Convert Neon type and size into compact bitmask representation. */
13757
13758static enum neon_type_mask
13759type_chk_of_el_type (enum neon_el_type type, unsigned size)
13760{
13761 switch (type)
13762 {
13763 case NT_untyped:
13764 switch (size)
477330fc
RM
13765 {
13766 case 8: return N_8;
13767 case 16: return N_16;
13768 case 32: return N_32;
13769 case 64: return N_64;
13770 default: ;
13771 }
5287ad62
JB
13772 break;
13773
13774 case NT_integer:
13775 switch (size)
477330fc
RM
13776 {
13777 case 8: return N_I8;
13778 case 16: return N_I16;
13779 case 32: return N_I32;
13780 case 64: return N_I64;
13781 default: ;
13782 }
5287ad62
JB
13783 break;
13784
13785 case NT_float:
037e8744 13786 switch (size)
477330fc 13787 {
8e79c3df 13788 case 16: return N_F16;
477330fc
RM
13789 case 32: return N_F32;
13790 case 64: return N_F64;
13791 default: ;
13792 }
5287ad62
JB
13793 break;
13794
13795 case NT_poly:
13796 switch (size)
477330fc
RM
13797 {
13798 case 8: return N_P8;
13799 case 16: return N_P16;
4f51b4bd 13800 case 64: return N_P64;
477330fc
RM
13801 default: ;
13802 }
5287ad62
JB
13803 break;
13804
13805 case NT_signed:
13806 switch (size)
477330fc
RM
13807 {
13808 case 8: return N_S8;
13809 case 16: return N_S16;
13810 case 32: return N_S32;
13811 case 64: return N_S64;
13812 default: ;
13813 }
5287ad62
JB
13814 break;
13815
13816 case NT_unsigned:
13817 switch (size)
477330fc
RM
13818 {
13819 case 8: return N_U8;
13820 case 16: return N_U16;
13821 case 32: return N_U32;
13822 case 64: return N_U64;
13823 default: ;
13824 }
5287ad62
JB
13825 break;
13826
13827 default: ;
13828 }
5f4273c7 13829
5287ad62
JB
13830 return N_UTYP;
13831}
13832
13833/* Convert compact Neon bitmask type representation to a type and size. Only
13834 handles the case where a single bit is set in the mask. */
13835
dcbf9037 13836static int
5287ad62 13837el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13838 enum neon_type_mask mask)
5287ad62 13839{
dcbf9037
JB
13840 if ((mask & N_EQK) != 0)
13841 return FAIL;
13842
5287ad62
JB
13843 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13844 *size = 8;
c70a8987 13845 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13846 *size = 16;
dcbf9037 13847 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13848 *size = 32;
4f51b4bd 13849 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13850 *size = 64;
dcbf9037
JB
13851 else
13852 return FAIL;
13853
5287ad62
JB
13854 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13855 *type = NT_signed;
dcbf9037 13856 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13857 *type = NT_unsigned;
dcbf9037 13858 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13859 *type = NT_integer;
dcbf9037 13860 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13861 *type = NT_untyped;
4f51b4bd 13862 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13863 *type = NT_poly;
d54af2d0 13864 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13865 *type = NT_float;
dcbf9037
JB
13866 else
13867 return FAIL;
5f4273c7 13868
dcbf9037 13869 return SUCCESS;
5287ad62
JB
13870}
13871
13872/* Modify a bitmask of allowed types. This is only needed for type
13873 relaxation. */
13874
13875static unsigned
13876modify_types_allowed (unsigned allowed, unsigned mods)
13877{
13878 unsigned size;
13879 enum neon_el_type type;
13880 unsigned destmask;
13881 int i;
5f4273c7 13882
5287ad62 13883 destmask = 0;
5f4273c7 13884
5287ad62
JB
13885 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13886 {
21d799b5 13887 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13888 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13889 {
13890 neon_modify_type_size (mods, &type, &size);
13891 destmask |= type_chk_of_el_type (type, size);
13892 }
5287ad62 13893 }
5f4273c7 13894
5287ad62
JB
13895 return destmask;
13896}
13897
13898/* Check type and return type classification.
13899 The manual states (paraphrase): If one datatype is given, it indicates the
13900 type given in:
13901 - the second operand, if there is one
13902 - the operand, if there is no second operand
13903 - the result, if there are no operands.
13904 This isn't quite good enough though, so we use a concept of a "key" datatype
13905 which is set on a per-instruction basis, which is the one which matters when
13906 only one data type is written.
13907 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13908 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13909
13910static struct neon_type_el
13911neon_check_type (unsigned els, enum neon_shape ns, ...)
13912{
13913 va_list ap;
13914 unsigned i, pass, key_el = 0;
13915 unsigned types[NEON_MAX_TYPE_ELS];
13916 enum neon_el_type k_type = NT_invtype;
13917 unsigned k_size = -1u;
13918 struct neon_type_el badtype = {NT_invtype, -1};
13919 unsigned key_allowed = 0;
13920
13921 /* Optional registers in Neon instructions are always (not) in operand 1.
13922 Fill in the missing operand here, if it was omitted. */
13923 if (els > 1 && !inst.operands[1].present)
13924 inst.operands[1] = inst.operands[0];
13925
13926 /* Suck up all the varargs. */
13927 va_start (ap, ns);
13928 for (i = 0; i < els; i++)
13929 {
13930 unsigned thisarg = va_arg (ap, unsigned);
13931 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13932 {
13933 va_end (ap);
13934 return badtype;
13935 }
5287ad62
JB
13936 types[i] = thisarg;
13937 if ((thisarg & N_KEY) != 0)
477330fc 13938 key_el = i;
5287ad62
JB
13939 }
13940 va_end (ap);
13941
dcbf9037
JB
13942 if (inst.vectype.elems > 0)
13943 for (i = 0; i < els; i++)
13944 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13945 {
13946 first_error (_("types specified in both the mnemonic and operands"));
13947 return badtype;
13948 }
dcbf9037 13949
5287ad62
JB
13950 /* Duplicate inst.vectype elements here as necessary.
13951 FIXME: No idea if this is exactly the same as the ARM assembler,
13952 particularly when an insn takes one register and one non-register
13953 operand. */
13954 if (inst.vectype.elems == 1 && els > 1)
13955 {
13956 unsigned j;
13957 inst.vectype.elems = els;
13958 inst.vectype.el[key_el] = inst.vectype.el[0];
13959 for (j = 0; j < els; j++)
477330fc
RM
13960 if (j != key_el)
13961 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13962 types[j]);
dcbf9037
JB
13963 }
13964 else if (inst.vectype.elems == 0 && els > 0)
13965 {
13966 unsigned j;
13967 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13968 after each operand. We allow some flexibility here; as long as the
13969 "key" operand has a type, we can infer the others. */
dcbf9037 13970 for (j = 0; j < els; j++)
477330fc
RM
13971 if (inst.operands[j].vectype.type != NT_invtype)
13972 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13973
13974 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13975 {
13976 for (j = 0; j < els; j++)
13977 if (inst.operands[j].vectype.type == NT_invtype)
13978 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13979 types[j]);
13980 }
dcbf9037 13981 else
477330fc
RM
13982 {
13983 first_error (_("operand types can't be inferred"));
13984 return badtype;
13985 }
5287ad62
JB
13986 }
13987 else if (inst.vectype.elems != els)
13988 {
dcbf9037 13989 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13990 return badtype;
13991 }
13992
13993 for (pass = 0; pass < 2; pass++)
13994 {
13995 for (i = 0; i < els; i++)
477330fc
RM
13996 {
13997 unsigned thisarg = types[i];
13998 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13999 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14000 enum neon_el_type g_type = inst.vectype.el[i].type;
14001 unsigned g_size = inst.vectype.el[i].size;
14002
14003 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14004 integer types if sign-specific variants are unavailable. */
477330fc 14005 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14006 && (types_allowed & N_SU_ALL) == 0)
14007 g_type = NT_integer;
14008
477330fc 14009 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14010 them. Some instructions only care about signs for some element
14011 sizes, so handle that properly. */
477330fc 14012 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14013 && ((g_size == 8 && (types_allowed & N_8) != 0)
14014 || (g_size == 16 && (types_allowed & N_16) != 0)
14015 || (g_size == 32 && (types_allowed & N_32) != 0)
14016 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14017 g_type = NT_untyped;
14018
477330fc
RM
14019 if (pass == 0)
14020 {
14021 if ((thisarg & N_KEY) != 0)
14022 {
14023 k_type = g_type;
14024 k_size = g_size;
14025 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14026
14027 /* Check architecture constraint on FP16 extension. */
14028 if (k_size == 16
14029 && k_type == NT_float
14030 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14031 {
14032 inst.error = _(BAD_FP16);
14033 return badtype;
14034 }
477330fc
RM
14035 }
14036 }
14037 else
14038 {
14039 if ((thisarg & N_VFP) != 0)
14040 {
14041 enum neon_shape_el regshape;
14042 unsigned regwidth, match;
99b253c5
NC
14043
14044 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14045 if (ns == NS_NULL)
14046 {
14047 first_error (_("invalid instruction shape"));
14048 return badtype;
14049 }
477330fc
RM
14050 regshape = neon_shape_tab[ns].el[i];
14051 regwidth = neon_shape_el_size[regshape];
14052
14053 /* In VFP mode, operands must match register widths. If we
14054 have a key operand, use its width, else use the width of
14055 the current operand. */
14056 if (k_size != -1u)
14057 match = k_size;
14058 else
14059 match = g_size;
14060
9db2f6b4
RL
14061 /* FP16 will use a single precision register. */
14062 if (regwidth == 32 && match == 16)
14063 {
14064 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14065 match = regwidth;
14066 else
14067 {
14068 inst.error = _(BAD_FP16);
14069 return badtype;
14070 }
14071 }
14072
477330fc
RM
14073 if (regwidth != match)
14074 {
14075 first_error (_("operand size must match register width"));
14076 return badtype;
14077 }
14078 }
14079
14080 if ((thisarg & N_EQK) == 0)
14081 {
14082 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14083
14084 if ((given_type & types_allowed) == 0)
14085 {
14086 first_error (_("bad type in Neon instruction"));
14087 return badtype;
14088 }
14089 }
14090 else
14091 {
14092 enum neon_el_type mod_k_type = k_type;
14093 unsigned mod_k_size = k_size;
14094 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14095 if (g_type != mod_k_type || g_size != mod_k_size)
14096 {
14097 first_error (_("inconsistent types in Neon instruction"));
14098 return badtype;
14099 }
14100 }
14101 }
14102 }
5287ad62
JB
14103 }
14104
14105 return inst.vectype.el[key_el];
14106}
14107
037e8744 14108/* Neon-style VFP instruction forwarding. */
5287ad62 14109
037e8744
JB
14110/* Thumb VFP instructions have 0xE in the condition field. */
14111
14112static void
14113do_vfp_cond_or_thumb (void)
5287ad62 14114{
88714cb8
DG
14115 inst.is_neon = 1;
14116
5287ad62 14117 if (thumb_mode)
037e8744 14118 inst.instruction |= 0xe0000000;
5287ad62 14119 else
037e8744 14120 inst.instruction |= inst.cond << 28;
5287ad62
JB
14121}
14122
037e8744
JB
14123/* Look up and encode a simple mnemonic, for use as a helper function for the
14124 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14125 etc. It is assumed that operand parsing has already been done, and that the
14126 operands are in the form expected by the given opcode (this isn't necessarily
14127 the same as the form in which they were parsed, hence some massaging must
14128 take place before this function is called).
14129 Checks current arch version against that in the looked-up opcode. */
5287ad62 14130
037e8744
JB
14131static void
14132do_vfp_nsyn_opcode (const char *opname)
5287ad62 14133{
037e8744 14134 const struct asm_opcode *opcode;
5f4273c7 14135
21d799b5 14136 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14137
037e8744
JB
14138 if (!opcode)
14139 abort ();
5287ad62 14140
037e8744 14141 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14142 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14143 _(BAD_FPU));
5287ad62 14144
88714cb8
DG
14145 inst.is_neon = 1;
14146
037e8744
JB
14147 if (thumb_mode)
14148 {
14149 inst.instruction = opcode->tvalue;
14150 opcode->tencode ();
14151 }
14152 else
14153 {
14154 inst.instruction = (inst.cond << 28) | opcode->avalue;
14155 opcode->aencode ();
14156 }
14157}
5287ad62
JB
14158
14159static void
037e8744 14160do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14161{
037e8744
JB
14162 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14163
9db2f6b4 14164 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14165 {
14166 if (is_add)
477330fc 14167 do_vfp_nsyn_opcode ("fadds");
037e8744 14168 else
477330fc 14169 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14170
14171 /* ARMv8.2 fp16 instruction. */
14172 if (rs == NS_HHH)
14173 do_scalar_fp16_v82_encode ();
037e8744
JB
14174 }
14175 else
14176 {
14177 if (is_add)
477330fc 14178 do_vfp_nsyn_opcode ("faddd");
037e8744 14179 else
477330fc 14180 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14181 }
14182}
14183
14184/* Check operand types to see if this is a VFP instruction, and if so call
14185 PFN (). */
14186
14187static int
14188try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14189{
14190 enum neon_shape rs;
14191 struct neon_type_el et;
14192
14193 switch (args)
14194 {
14195 case 2:
9db2f6b4
RL
14196 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14197 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14198 break;
5f4273c7 14199
037e8744 14200 case 3:
9db2f6b4
RL
14201 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14202 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14203 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14204 break;
14205
14206 default:
14207 abort ();
14208 }
14209
14210 if (et.type != NT_invtype)
14211 {
14212 pfn (rs);
14213 return SUCCESS;
14214 }
037e8744 14215
99b253c5 14216 inst.error = NULL;
037e8744
JB
14217 return FAIL;
14218}
14219
14220static void
14221do_vfp_nsyn_mla_mls (enum neon_shape rs)
14222{
14223 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14224
9db2f6b4 14225 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14226 {
14227 if (is_mla)
477330fc 14228 do_vfp_nsyn_opcode ("fmacs");
037e8744 14229 else
477330fc 14230 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14231
14232 /* ARMv8.2 fp16 instruction. */
14233 if (rs == NS_HHH)
14234 do_scalar_fp16_v82_encode ();
037e8744
JB
14235 }
14236 else
14237 {
14238 if (is_mla)
477330fc 14239 do_vfp_nsyn_opcode ("fmacd");
037e8744 14240 else
477330fc 14241 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14242 }
14243}
14244
62f3b8c8
PB
14245static void
14246do_vfp_nsyn_fma_fms (enum neon_shape rs)
14247{
14248 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14249
9db2f6b4 14250 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14251 {
14252 if (is_fma)
477330fc 14253 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14254 else
477330fc 14255 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14256
14257 /* ARMv8.2 fp16 instruction. */
14258 if (rs == NS_HHH)
14259 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14260 }
14261 else
14262 {
14263 if (is_fma)
477330fc 14264 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14265 else
477330fc 14266 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14267 }
14268}
14269
037e8744
JB
14270static void
14271do_vfp_nsyn_mul (enum neon_shape rs)
14272{
9db2f6b4
RL
14273 if (rs == NS_FFF || rs == NS_HHH)
14274 {
14275 do_vfp_nsyn_opcode ("fmuls");
14276
14277 /* ARMv8.2 fp16 instruction. */
14278 if (rs == NS_HHH)
14279 do_scalar_fp16_v82_encode ();
14280 }
037e8744
JB
14281 else
14282 do_vfp_nsyn_opcode ("fmuld");
14283}
14284
14285static void
14286do_vfp_nsyn_abs_neg (enum neon_shape rs)
14287{
14288 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14289 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14290
9db2f6b4 14291 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14292 {
14293 if (is_neg)
477330fc 14294 do_vfp_nsyn_opcode ("fnegs");
037e8744 14295 else
477330fc 14296 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14297
14298 /* ARMv8.2 fp16 instruction. */
14299 if (rs == NS_HH)
14300 do_scalar_fp16_v82_encode ();
037e8744
JB
14301 }
14302 else
14303 {
14304 if (is_neg)
477330fc 14305 do_vfp_nsyn_opcode ("fnegd");
037e8744 14306 else
477330fc 14307 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14308 }
14309}
14310
14311/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14312 insns belong to Neon, and are handled elsewhere. */
14313
14314static void
14315do_vfp_nsyn_ldm_stm (int is_dbmode)
14316{
14317 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14318 if (is_ldm)
14319 {
14320 if (is_dbmode)
477330fc 14321 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14322 else
477330fc 14323 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14324 }
14325 else
14326 {
14327 if (is_dbmode)
477330fc 14328 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14329 else
477330fc 14330 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14331 }
14332}
14333
037e8744
JB
14334static void
14335do_vfp_nsyn_sqrt (void)
14336{
9db2f6b4
RL
14337 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14338 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14339
9db2f6b4
RL
14340 if (rs == NS_FF || rs == NS_HH)
14341 {
14342 do_vfp_nsyn_opcode ("fsqrts");
14343
14344 /* ARMv8.2 fp16 instruction. */
14345 if (rs == NS_HH)
14346 do_scalar_fp16_v82_encode ();
14347 }
037e8744
JB
14348 else
14349 do_vfp_nsyn_opcode ("fsqrtd");
14350}
14351
14352static void
14353do_vfp_nsyn_div (void)
14354{
9db2f6b4 14355 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14356 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14357 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14358
9db2f6b4
RL
14359 if (rs == NS_FFF || rs == NS_HHH)
14360 {
14361 do_vfp_nsyn_opcode ("fdivs");
14362
14363 /* ARMv8.2 fp16 instruction. */
14364 if (rs == NS_HHH)
14365 do_scalar_fp16_v82_encode ();
14366 }
037e8744
JB
14367 else
14368 do_vfp_nsyn_opcode ("fdivd");
14369}
14370
14371static void
14372do_vfp_nsyn_nmul (void)
14373{
9db2f6b4 14374 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14375 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14376 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14377
9db2f6b4 14378 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14379 {
88714cb8 14380 NEON_ENCODE (SINGLE, inst);
037e8744 14381 do_vfp_sp_dyadic ();
9db2f6b4
RL
14382
14383 /* ARMv8.2 fp16 instruction. */
14384 if (rs == NS_HHH)
14385 do_scalar_fp16_v82_encode ();
037e8744
JB
14386 }
14387 else
14388 {
88714cb8 14389 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14390 do_vfp_dp_rd_rn_rm ();
14391 }
14392 do_vfp_cond_or_thumb ();
9db2f6b4 14393
037e8744
JB
14394}
14395
14396static void
14397do_vfp_nsyn_cmp (void)
14398{
9db2f6b4 14399 enum neon_shape rs;
037e8744
JB
14400 if (inst.operands[1].isreg)
14401 {
9db2f6b4
RL
14402 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14403 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14404
9db2f6b4 14405 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14406 {
14407 NEON_ENCODE (SINGLE, inst);
14408 do_vfp_sp_monadic ();
14409 }
037e8744 14410 else
477330fc
RM
14411 {
14412 NEON_ENCODE (DOUBLE, inst);
14413 do_vfp_dp_rd_rm ();
14414 }
037e8744
JB
14415 }
14416 else
14417 {
9db2f6b4
RL
14418 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14419 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14420
14421 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14422 {
14423 case N_MNEM_vcmp:
14424 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14425 break;
14426 case N_MNEM_vcmpe:
14427 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14428 break;
14429 default:
14430 abort ();
14431 }
5f4273c7 14432
9db2f6b4 14433 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14434 {
14435 NEON_ENCODE (SINGLE, inst);
14436 do_vfp_sp_compare_z ();
14437 }
037e8744 14438 else
477330fc
RM
14439 {
14440 NEON_ENCODE (DOUBLE, inst);
14441 do_vfp_dp_rd ();
14442 }
037e8744
JB
14443 }
14444 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14445
14446 /* ARMv8.2 fp16 instruction. */
14447 if (rs == NS_HI || rs == NS_HH)
14448 do_scalar_fp16_v82_encode ();
037e8744
JB
14449}
14450
14451static void
14452nsyn_insert_sp (void)
14453{
14454 inst.operands[1] = inst.operands[0];
14455 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14456 inst.operands[0].reg = REG_SP;
037e8744
JB
14457 inst.operands[0].isreg = 1;
14458 inst.operands[0].writeback = 1;
14459 inst.operands[0].present = 1;
14460}
14461
14462static void
14463do_vfp_nsyn_push (void)
14464{
14465 nsyn_insert_sp ();
b126985e
NC
14466
14467 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14468 _("register list must contain at least 1 and at most 16 "
14469 "registers"));
14470
037e8744
JB
14471 if (inst.operands[1].issingle)
14472 do_vfp_nsyn_opcode ("fstmdbs");
14473 else
14474 do_vfp_nsyn_opcode ("fstmdbd");
14475}
14476
14477static void
14478do_vfp_nsyn_pop (void)
14479{
14480 nsyn_insert_sp ();
b126985e
NC
14481
14482 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14483 _("register list must contain at least 1 and at most 16 "
14484 "registers"));
14485
037e8744 14486 if (inst.operands[1].issingle)
22b5b651 14487 do_vfp_nsyn_opcode ("fldmias");
037e8744 14488 else
22b5b651 14489 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14490}
14491
14492/* Fix up Neon data-processing instructions, ORing in the correct bits for
14493 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14494
88714cb8
DG
14495static void
14496neon_dp_fixup (struct arm_it* insn)
037e8744 14497{
88714cb8
DG
14498 unsigned int i = insn->instruction;
14499 insn->is_neon = 1;
14500
037e8744
JB
14501 if (thumb_mode)
14502 {
14503 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14504 if (i & (1 << 24))
477330fc 14505 i |= 1 << 28;
5f4273c7 14506
037e8744 14507 i &= ~(1 << 24);
5f4273c7 14508
037e8744
JB
14509 i |= 0xef000000;
14510 }
14511 else
14512 i |= 0xf2000000;
5f4273c7 14513
88714cb8 14514 insn->instruction = i;
037e8744
JB
14515}
14516
14517/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14518 (0, 1, 2, 3). */
14519
14520static unsigned
14521neon_logbits (unsigned x)
14522{
14523 return ffs (x) - 4;
14524}
14525
14526#define LOW4(R) ((R) & 0xf)
14527#define HI1(R) (((R) >> 4) & 1)
14528
14529/* Encode insns with bit pattern:
14530
14531 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14532 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14533
037e8744
JB
14534 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14535 different meaning for some instruction. */
14536
14537static void
14538neon_three_same (int isquad, int ubit, int size)
14539{
14540 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14541 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14542 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14543 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14544 inst.instruction |= LOW4 (inst.operands[2].reg);
14545 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14546 inst.instruction |= (isquad != 0) << 6;
14547 inst.instruction |= (ubit != 0) << 24;
14548 if (size != -1)
14549 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14550
88714cb8 14551 neon_dp_fixup (&inst);
037e8744
JB
14552}
14553
14554/* Encode instructions of the form:
14555
14556 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14557 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14558
14559 Don't write size if SIZE == -1. */
14560
14561static void
14562neon_two_same (int qbit, int ubit, int size)
14563{
14564 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14565 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14566 inst.instruction |= LOW4 (inst.operands[1].reg);
14567 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14568 inst.instruction |= (qbit != 0) << 6;
14569 inst.instruction |= (ubit != 0) << 24;
14570
14571 if (size != -1)
14572 inst.instruction |= neon_logbits (size) << 18;
14573
88714cb8 14574 neon_dp_fixup (&inst);
5287ad62
JB
14575}
14576
14577/* Neon instruction encoders, in approximate order of appearance. */
14578
14579static void
14580do_neon_dyadic_i_su (void)
14581{
037e8744 14582 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14583 struct neon_type_el et = neon_check_type (3, rs,
14584 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14585 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14586}
14587
14588static void
14589do_neon_dyadic_i64_su (void)
14590{
037e8744 14591 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14592 struct neon_type_el et = neon_check_type (3, rs,
14593 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14594 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14595}
14596
14597static void
14598neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14599 unsigned immbits)
5287ad62
JB
14600{
14601 unsigned size = et.size >> 3;
14602 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14603 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14604 inst.instruction |= LOW4 (inst.operands[1].reg);
14605 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14606 inst.instruction |= (isquad != 0) << 6;
14607 inst.instruction |= immbits << 16;
14608 inst.instruction |= (size >> 3) << 7;
14609 inst.instruction |= (size & 0x7) << 19;
14610 if (write_ubit)
14611 inst.instruction |= (uval != 0) << 24;
14612
88714cb8 14613 neon_dp_fixup (&inst);
5287ad62
JB
14614}
14615
14616static void
14617do_neon_shl_imm (void)
14618{
14619 if (!inst.operands[2].isreg)
14620 {
037e8744 14621 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14622 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14623 int imm = inst.operands[2].imm;
14624
14625 constraint (imm < 0 || (unsigned)imm >= et.size,
14626 _("immediate out of range for shift"));
88714cb8 14627 NEON_ENCODE (IMMED, inst);
cb3b1e65 14628 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14629 }
14630 else
14631 {
037e8744 14632 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14633 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14634 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14635 unsigned int tmp;
14636
14637 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14638 vshl.xx Dd, Dm, Dn
14639 whereas other 3-register operations encoded by neon_three_same have
14640 syntax like:
14641 vadd.xx Dd, Dn, Dm
14642 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14643 here. */
627907b7
JB
14644 tmp = inst.operands[2].reg;
14645 inst.operands[2].reg = inst.operands[1].reg;
14646 inst.operands[1].reg = tmp;
88714cb8 14647 NEON_ENCODE (INTEGER, inst);
037e8744 14648 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14649 }
14650}
14651
14652static void
14653do_neon_qshl_imm (void)
14654{
14655 if (!inst.operands[2].isreg)
14656 {
037e8744 14657 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14658 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14659 int imm = inst.operands[2].imm;
627907b7 14660
cb3b1e65
JB
14661 constraint (imm < 0 || (unsigned)imm >= et.size,
14662 _("immediate out of range for shift"));
88714cb8 14663 NEON_ENCODE (IMMED, inst);
cb3b1e65 14664 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14665 }
14666 else
14667 {
037e8744 14668 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14669 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14670 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14671 unsigned int tmp;
14672
14673 /* See note in do_neon_shl_imm. */
14674 tmp = inst.operands[2].reg;
14675 inst.operands[2].reg = inst.operands[1].reg;
14676 inst.operands[1].reg = tmp;
88714cb8 14677 NEON_ENCODE (INTEGER, inst);
037e8744 14678 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14679 }
14680}
14681
627907b7
JB
14682static void
14683do_neon_rshl (void)
14684{
14685 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14686 struct neon_type_el et = neon_check_type (3, rs,
14687 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14688 unsigned int tmp;
14689
14690 tmp = inst.operands[2].reg;
14691 inst.operands[2].reg = inst.operands[1].reg;
14692 inst.operands[1].reg = tmp;
14693 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14694}
14695
5287ad62
JB
14696static int
14697neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14698{
036dc3f7
PB
14699 /* Handle .I8 pseudo-instructions. */
14700 if (size == 8)
5287ad62 14701 {
5287ad62 14702 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14703 FIXME is this the intended semantics? There doesn't seem much point in
14704 accepting .I8 if so. */
5287ad62
JB
14705 immediate |= immediate << 8;
14706 size = 16;
036dc3f7
PB
14707 }
14708
14709 if (size >= 32)
14710 {
14711 if (immediate == (immediate & 0x000000ff))
14712 {
14713 *immbits = immediate;
14714 return 0x1;
14715 }
14716 else if (immediate == (immediate & 0x0000ff00))
14717 {
14718 *immbits = immediate >> 8;
14719 return 0x3;
14720 }
14721 else if (immediate == (immediate & 0x00ff0000))
14722 {
14723 *immbits = immediate >> 16;
14724 return 0x5;
14725 }
14726 else if (immediate == (immediate & 0xff000000))
14727 {
14728 *immbits = immediate >> 24;
14729 return 0x7;
14730 }
14731 if ((immediate & 0xffff) != (immediate >> 16))
14732 goto bad_immediate;
14733 immediate &= 0xffff;
5287ad62
JB
14734 }
14735
14736 if (immediate == (immediate & 0x000000ff))
14737 {
14738 *immbits = immediate;
036dc3f7 14739 return 0x9;
5287ad62
JB
14740 }
14741 else if (immediate == (immediate & 0x0000ff00))
14742 {
14743 *immbits = immediate >> 8;
036dc3f7 14744 return 0xb;
5287ad62
JB
14745 }
14746
14747 bad_immediate:
dcbf9037 14748 first_error (_("immediate value out of range"));
5287ad62
JB
14749 return FAIL;
14750}
14751
5287ad62
JB
14752static void
14753do_neon_logic (void)
14754{
14755 if (inst.operands[2].present && inst.operands[2].isreg)
14756 {
037e8744 14757 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14758 neon_check_type (3, rs, N_IGNORE_TYPE);
14759 /* U bit and size field were set as part of the bitmask. */
88714cb8 14760 NEON_ENCODE (INTEGER, inst);
037e8744 14761 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14762 }
14763 else
14764 {
4316f0d2
DG
14765 const int three_ops_form = (inst.operands[2].present
14766 && !inst.operands[2].isreg);
14767 const int immoperand = (three_ops_form ? 2 : 1);
14768 enum neon_shape rs = (three_ops_form
14769 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14770 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14771 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14772 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14773 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14774 unsigned immbits;
14775 int cmode;
5f4273c7 14776
5287ad62 14777 if (et.type == NT_invtype)
477330fc 14778 return;
5f4273c7 14779
4316f0d2
DG
14780 if (three_ops_form)
14781 constraint (inst.operands[0].reg != inst.operands[1].reg,
14782 _("first and second operands shall be the same register"));
14783
88714cb8 14784 NEON_ENCODE (IMMED, inst);
5287ad62 14785
4316f0d2 14786 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14787 if (et.size == 64)
14788 {
14789 /* .i64 is a pseudo-op, so the immediate must be a repeating
14790 pattern. */
4316f0d2
DG
14791 if (immbits != (inst.operands[immoperand].regisimm ?
14792 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14793 {
14794 /* Set immbits to an invalid constant. */
14795 immbits = 0xdeadbeef;
14796 }
14797 }
14798
5287ad62 14799 switch (opcode)
477330fc
RM
14800 {
14801 case N_MNEM_vbic:
14802 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14803 break;
14804
14805 case N_MNEM_vorr:
14806 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14807 break;
14808
14809 case N_MNEM_vand:
14810 /* Pseudo-instruction for VBIC. */
14811 neon_invert_size (&immbits, 0, et.size);
14812 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14813 break;
14814
14815 case N_MNEM_vorn:
14816 /* Pseudo-instruction for VORR. */
14817 neon_invert_size (&immbits, 0, et.size);
14818 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14819 break;
14820
14821 default:
14822 abort ();
14823 }
5287ad62
JB
14824
14825 if (cmode == FAIL)
477330fc 14826 return;
5287ad62 14827
037e8744 14828 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14829 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14830 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14831 inst.instruction |= cmode << 8;
14832 neon_write_immbits (immbits);
5f4273c7 14833
88714cb8 14834 neon_dp_fixup (&inst);
5287ad62
JB
14835 }
14836}
14837
14838static void
14839do_neon_bitfield (void)
14840{
037e8744 14841 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14842 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14843 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14844}
14845
14846static void
dcbf9037 14847neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14848 unsigned destbits)
5287ad62 14849{
037e8744 14850 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14851 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14852 types | N_KEY);
5287ad62
JB
14853 if (et.type == NT_float)
14854 {
88714cb8 14855 NEON_ENCODE (FLOAT, inst);
cc933301 14856 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14857 }
14858 else
14859 {
88714cb8 14860 NEON_ENCODE (INTEGER, inst);
037e8744 14861 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14862 }
14863}
14864
14865static void
14866do_neon_dyadic_if_su (void)
14867{
dcbf9037 14868 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14869}
14870
14871static void
14872do_neon_dyadic_if_su_d (void)
14873{
14874 /* This version only allow D registers, but that constraint is enforced during
14875 operand parsing so we don't need to do anything extra here. */
dcbf9037 14876 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14877}
14878
5287ad62
JB
14879static void
14880do_neon_dyadic_if_i_d (void)
14881{
428e3f1f
PB
14882 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14883 affected if we specify unsigned args. */
14884 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14885}
14886
037e8744
JB
14887enum vfp_or_neon_is_neon_bits
14888{
14889 NEON_CHECK_CC = 1,
73924fbc
MGD
14890 NEON_CHECK_ARCH = 2,
14891 NEON_CHECK_ARCH8 = 4
037e8744
JB
14892};
14893
14894/* Call this function if an instruction which may have belonged to the VFP or
14895 Neon instruction sets, but turned out to be a Neon instruction (due to the
14896 operand types involved, etc.). We have to check and/or fix-up a couple of
14897 things:
14898
14899 - Make sure the user hasn't attempted to make a Neon instruction
14900 conditional.
14901 - Alter the value in the condition code field if necessary.
14902 - Make sure that the arch supports Neon instructions.
14903
14904 Which of these operations take place depends on bits from enum
14905 vfp_or_neon_is_neon_bits.
14906
14907 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14908 current instruction's condition is COND_ALWAYS, the condition field is
14909 changed to inst.uncond_value. This is necessary because instructions shared
14910 between VFP and Neon may be conditional for the VFP variants only, and the
14911 unconditional Neon version must have, e.g., 0xF in the condition field. */
14912
14913static int
14914vfp_or_neon_is_neon (unsigned check)
14915{
14916 /* Conditions are always legal in Thumb mode (IT blocks). */
14917 if (!thumb_mode && (check & NEON_CHECK_CC))
14918 {
14919 if (inst.cond != COND_ALWAYS)
477330fc
RM
14920 {
14921 first_error (_(BAD_COND));
14922 return FAIL;
14923 }
037e8744 14924 if (inst.uncond_value != -1)
477330fc 14925 inst.instruction |= inst.uncond_value << 28;
037e8744 14926 }
5f4273c7 14927
037e8744 14928 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14929 && !mark_feature_used (&fpu_neon_ext_v1))
14930 {
14931 first_error (_(BAD_FPU));
14932 return FAIL;
14933 }
14934
14935 if ((check & NEON_CHECK_ARCH8)
14936 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14937 {
14938 first_error (_(BAD_FPU));
14939 return FAIL;
14940 }
5f4273c7 14941
037e8744
JB
14942 return SUCCESS;
14943}
14944
5287ad62
JB
14945static void
14946do_neon_addsub_if_i (void)
14947{
037e8744
JB
14948 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14949 return;
14950
14951 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14952 return;
14953
5287ad62
JB
14954 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14955 affected if we specify unsigned args. */
dcbf9037 14956 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14957}
14958
14959/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14960 result to be:
14961 V<op> A,B (A is operand 0, B is operand 2)
14962 to mean:
14963 V<op> A,B,A
14964 not:
14965 V<op> A,B,B
14966 so handle that case specially. */
14967
14968static void
14969neon_exchange_operands (void)
14970{
5287ad62
JB
14971 if (inst.operands[1].present)
14972 {
e1fa0163
NC
14973 void *scratch = xmalloc (sizeof (inst.operands[0]));
14974
5287ad62
JB
14975 /* Swap operands[1] and operands[2]. */
14976 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14977 inst.operands[1] = inst.operands[2];
14978 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14979 free (scratch);
5287ad62
JB
14980 }
14981 else
14982 {
14983 inst.operands[1] = inst.operands[2];
14984 inst.operands[2] = inst.operands[0];
14985 }
14986}
14987
14988static void
14989neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14990{
14991 if (inst.operands[2].isreg)
14992 {
14993 if (invert)
477330fc 14994 neon_exchange_operands ();
dcbf9037 14995 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14996 }
14997 else
14998 {
037e8744 14999 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15000 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15001 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15002
88714cb8 15003 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15004 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15005 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15006 inst.instruction |= LOW4 (inst.operands[1].reg);
15007 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15008 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15009 inst.instruction |= (et.type == NT_float) << 10;
15010 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15011
88714cb8 15012 neon_dp_fixup (&inst);
5287ad62
JB
15013 }
15014}
15015
15016static void
15017do_neon_cmp (void)
15018{
cc933301 15019 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15020}
15021
15022static void
15023do_neon_cmp_inv (void)
15024{
cc933301 15025 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15026}
15027
15028static void
15029do_neon_ceq (void)
15030{
15031 neon_compare (N_IF_32, N_IF_32, FALSE);
15032}
15033
15034/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15035 scalars, which are encoded in 5 bits, M : Rm.
15036 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15037 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15038 index in M.
15039
15040 Dot Product instructions are similar to multiply instructions except elsize
15041 should always be 32.
15042
15043 This function translates SCALAR, which is GAS's internal encoding of indexed
15044 scalar register, to raw encoding. There is also register and index range
15045 check based on ELSIZE. */
5287ad62
JB
15046
15047static unsigned
15048neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15049{
dcbf9037
JB
15050 unsigned regno = NEON_SCALAR_REG (scalar);
15051 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15052
15053 switch (elsize)
15054 {
15055 case 16:
15056 if (regno > 7 || elno > 3)
477330fc 15057 goto bad_scalar;
5287ad62 15058 return regno | (elno << 3);
5f4273c7 15059
5287ad62
JB
15060 case 32:
15061 if (regno > 15 || elno > 1)
477330fc 15062 goto bad_scalar;
5287ad62
JB
15063 return regno | (elno << 4);
15064
15065 default:
15066 bad_scalar:
dcbf9037 15067 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15068 }
15069
15070 return 0;
15071}
15072
15073/* Encode multiply / multiply-accumulate scalar instructions. */
15074
15075static void
15076neon_mul_mac (struct neon_type_el et, int ubit)
15077{
dcbf9037
JB
15078 unsigned scalar;
15079
15080 /* Give a more helpful error message if we have an invalid type. */
15081 if (et.type == NT_invtype)
15082 return;
5f4273c7 15083
dcbf9037 15084 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15085 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15086 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15087 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15088 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15089 inst.instruction |= LOW4 (scalar);
15090 inst.instruction |= HI1 (scalar) << 5;
15091 inst.instruction |= (et.type == NT_float) << 8;
15092 inst.instruction |= neon_logbits (et.size) << 20;
15093 inst.instruction |= (ubit != 0) << 24;
15094
88714cb8 15095 neon_dp_fixup (&inst);
5287ad62
JB
15096}
15097
15098static void
15099do_neon_mac_maybe_scalar (void)
15100{
037e8744
JB
15101 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15102 return;
15103
15104 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15105 return;
15106
5287ad62
JB
15107 if (inst.operands[2].isscalar)
15108 {
037e8744 15109 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15110 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15111 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15112 NEON_ENCODE (SCALAR, inst);
037e8744 15113 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15114 }
15115 else
428e3f1f
PB
15116 {
15117 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15118 affected if we specify unsigned args. */
15119 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15120 }
5287ad62
JB
15121}
15122
62f3b8c8
PB
15123static void
15124do_neon_fmac (void)
15125{
15126 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15127 return;
15128
15129 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15130 return;
15131
15132 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15133}
15134
5287ad62
JB
15135static void
15136do_neon_tst (void)
15137{
037e8744 15138 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15139 struct neon_type_el et = neon_check_type (3, rs,
15140 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15141 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15142}
15143
15144/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15145 same types as the MAC equivalents. The polynomial type for this instruction
15146 is encoded the same as the integer type. */
15147
15148static void
15149do_neon_mul (void)
15150{
037e8744
JB
15151 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15152 return;
15153
15154 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15155 return;
15156
5287ad62
JB
15157 if (inst.operands[2].isscalar)
15158 do_neon_mac_maybe_scalar ();
15159 else
cc933301 15160 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15161}
15162
15163static void
15164do_neon_qdmulh (void)
15165{
15166 if (inst.operands[2].isscalar)
15167 {
037e8744 15168 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15169 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15170 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15171 NEON_ENCODE (SCALAR, inst);
037e8744 15172 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15173 }
15174 else
15175 {
037e8744 15176 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15177 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15178 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15179 NEON_ENCODE (INTEGER, inst);
5287ad62 15180 /* The U bit (rounding) comes from bit mask. */
037e8744 15181 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15182 }
15183}
15184
643afb90
MW
15185static void
15186do_neon_qrdmlah (void)
15187{
15188 /* Check we're on the correct architecture. */
15189 if (!mark_feature_used (&fpu_neon_ext_armv8))
15190 inst.error =
15191 _("instruction form not available on this architecture.");
15192 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15193 {
15194 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15195 record_feature_use (&fpu_neon_ext_v8_1);
15196 }
15197
15198 if (inst.operands[2].isscalar)
15199 {
15200 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15201 struct neon_type_el et = neon_check_type (3, rs,
15202 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15203 NEON_ENCODE (SCALAR, inst);
15204 neon_mul_mac (et, neon_quad (rs));
15205 }
15206 else
15207 {
15208 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15209 struct neon_type_el et = neon_check_type (3, rs,
15210 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15211 NEON_ENCODE (INTEGER, inst);
15212 /* The U bit (rounding) comes from bit mask. */
15213 neon_three_same (neon_quad (rs), 0, et.size);
15214 }
15215}
15216
5287ad62
JB
15217static void
15218do_neon_fcmp_absolute (void)
15219{
037e8744 15220 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15221 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15222 N_F_16_32 | N_KEY);
5287ad62 15223 /* Size field comes from bit mask. */
cc933301 15224 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15225}
15226
15227static void
15228do_neon_fcmp_absolute_inv (void)
15229{
15230 neon_exchange_operands ();
15231 do_neon_fcmp_absolute ();
15232}
15233
15234static void
15235do_neon_step (void)
15236{
037e8744 15237 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15238 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15239 N_F_16_32 | N_KEY);
15240 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15241}
15242
15243static void
15244do_neon_abs_neg (void)
15245{
037e8744
JB
15246 enum neon_shape rs;
15247 struct neon_type_el et;
5f4273c7 15248
037e8744
JB
15249 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15250 return;
15251
15252 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15253 return;
15254
15255 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15256 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15257
5287ad62
JB
15258 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15259 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15260 inst.instruction |= LOW4 (inst.operands[1].reg);
15261 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15262 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15263 inst.instruction |= (et.type == NT_float) << 10;
15264 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15265
88714cb8 15266 neon_dp_fixup (&inst);
5287ad62
JB
15267}
15268
15269static void
15270do_neon_sli (void)
15271{
037e8744 15272 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15273 struct neon_type_el et = neon_check_type (2, rs,
15274 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15275 int imm = inst.operands[2].imm;
15276 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15277 _("immediate out of range for insert"));
037e8744 15278 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15279}
15280
15281static void
15282do_neon_sri (void)
15283{
037e8744 15284 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15285 struct neon_type_el et = neon_check_type (2, rs,
15286 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15287 int imm = inst.operands[2].imm;
15288 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15289 _("immediate out of range for insert"));
037e8744 15290 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15291}
15292
15293static void
15294do_neon_qshlu_imm (void)
15295{
037e8744 15296 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15297 struct neon_type_el et = neon_check_type (2, rs,
15298 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15299 int imm = inst.operands[2].imm;
15300 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15301 _("immediate out of range for shift"));
5287ad62
JB
15302 /* Only encodes the 'U present' variant of the instruction.
15303 In this case, signed types have OP (bit 8) set to 0.
15304 Unsigned types have OP set to 1. */
15305 inst.instruction |= (et.type == NT_unsigned) << 8;
15306 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15307 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15308}
15309
15310static void
15311do_neon_qmovn (void)
15312{
15313 struct neon_type_el et = neon_check_type (2, NS_DQ,
15314 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15315 /* Saturating move where operands can be signed or unsigned, and the
15316 destination has the same signedness. */
88714cb8 15317 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15318 if (et.type == NT_unsigned)
15319 inst.instruction |= 0xc0;
15320 else
15321 inst.instruction |= 0x80;
15322 neon_two_same (0, 1, et.size / 2);
15323}
15324
15325static void
15326do_neon_qmovun (void)
15327{
15328 struct neon_type_el et = neon_check_type (2, NS_DQ,
15329 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15330 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15331 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15332 neon_two_same (0, 1, et.size / 2);
15333}
15334
15335static void
15336do_neon_rshift_sat_narrow (void)
15337{
15338 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15339 or unsigned. If operands are unsigned, results must also be unsigned. */
15340 struct neon_type_el et = neon_check_type (2, NS_DQI,
15341 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15342 int imm = inst.operands[2].imm;
15343 /* This gets the bounds check, size encoding and immediate bits calculation
15344 right. */
15345 et.size /= 2;
5f4273c7 15346
5287ad62
JB
15347 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15348 VQMOVN.I<size> <Dd>, <Qm>. */
15349 if (imm == 0)
15350 {
15351 inst.operands[2].present = 0;
15352 inst.instruction = N_MNEM_vqmovn;
15353 do_neon_qmovn ();
15354 return;
15355 }
5f4273c7 15356
5287ad62 15357 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15358 _("immediate out of range"));
5287ad62
JB
15359 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15360}
15361
15362static void
15363do_neon_rshift_sat_narrow_u (void)
15364{
15365 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15366 or unsigned. If operands are unsigned, results must also be unsigned. */
15367 struct neon_type_el et = neon_check_type (2, NS_DQI,
15368 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15369 int imm = inst.operands[2].imm;
15370 /* This gets the bounds check, size encoding and immediate bits calculation
15371 right. */
15372 et.size /= 2;
15373
15374 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15375 VQMOVUN.I<size> <Dd>, <Qm>. */
15376 if (imm == 0)
15377 {
15378 inst.operands[2].present = 0;
15379 inst.instruction = N_MNEM_vqmovun;
15380 do_neon_qmovun ();
15381 return;
15382 }
15383
15384 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15385 _("immediate out of range"));
5287ad62
JB
15386 /* FIXME: The manual is kind of unclear about what value U should have in
15387 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15388 must be 1. */
15389 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15390}
15391
15392static void
15393do_neon_movn (void)
15394{
15395 struct neon_type_el et = neon_check_type (2, NS_DQ,
15396 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15397 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15398 neon_two_same (0, 1, et.size / 2);
15399}
15400
15401static void
15402do_neon_rshift_narrow (void)
15403{
15404 struct neon_type_el et = neon_check_type (2, NS_DQI,
15405 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15406 int imm = inst.operands[2].imm;
15407 /* This gets the bounds check, size encoding and immediate bits calculation
15408 right. */
15409 et.size /= 2;
5f4273c7 15410
5287ad62
JB
15411 /* If immediate is zero then we are a pseudo-instruction for
15412 VMOVN.I<size> <Dd>, <Qm> */
15413 if (imm == 0)
15414 {
15415 inst.operands[2].present = 0;
15416 inst.instruction = N_MNEM_vmovn;
15417 do_neon_movn ();
15418 return;
15419 }
5f4273c7 15420
5287ad62 15421 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15422 _("immediate out of range for narrowing operation"));
5287ad62
JB
15423 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15424}
15425
15426static void
15427do_neon_shll (void)
15428{
15429 /* FIXME: Type checking when lengthening. */
15430 struct neon_type_el et = neon_check_type (2, NS_QDI,
15431 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15432 unsigned imm = inst.operands[2].imm;
15433
15434 if (imm == et.size)
15435 {
15436 /* Maximum shift variant. */
88714cb8 15437 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15438 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15439 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15440 inst.instruction |= LOW4 (inst.operands[1].reg);
15441 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15442 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15443
88714cb8 15444 neon_dp_fixup (&inst);
5287ad62
JB
15445 }
15446 else
15447 {
15448 /* A more-specific type check for non-max versions. */
15449 et = neon_check_type (2, NS_QDI,
477330fc 15450 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15451 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15452 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15453 }
15454}
15455
037e8744 15456/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15457 the current instruction is. */
15458
6b9a8b67
MGD
15459#define CVT_FLAVOUR_VAR \
15460 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15461 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15462 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15463 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15464 /* Half-precision conversions. */ \
cc933301
JW
15465 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15466 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15467 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15468 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15469 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15470 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15471 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15472 Compared with single/double precision variants, only the co-processor \
15473 field is different, so the encoding flow is reused here. */ \
15474 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15475 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15476 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15477 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15478 /* VFP instructions. */ \
15479 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15480 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15481 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15482 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15483 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15484 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15485 /* VFP instructions with bitshift. */ \
15486 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15487 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15488 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15489 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15490 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15491 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15492 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15493 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15494
15495#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15496 neon_cvt_flavour_##C,
15497
15498/* The different types of conversions we can do. */
15499enum neon_cvt_flavour
15500{
15501 CVT_FLAVOUR_VAR
15502 neon_cvt_flavour_invalid,
15503 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15504};
15505
15506#undef CVT_VAR
15507
15508static enum neon_cvt_flavour
15509get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15510{
6b9a8b67
MGD
15511#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15512 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15513 if (et.type != NT_invtype) \
15514 { \
15515 inst.error = NULL; \
15516 return (neon_cvt_flavour_##C); \
5287ad62 15517 }
6b9a8b67 15518
5287ad62 15519 struct neon_type_el et;
037e8744 15520 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15521 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15522 /* The instruction versions which take an immediate take one register
15523 argument, which is extended to the width of the full register. Thus the
15524 "source" and "destination" registers must have the same width. Hack that
15525 here by making the size equal to the key (wider, in this case) operand. */
15526 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15527
6b9a8b67
MGD
15528 CVT_FLAVOUR_VAR;
15529
15530 return neon_cvt_flavour_invalid;
5287ad62
JB
15531#undef CVT_VAR
15532}
15533
7e8e6784
MGD
15534enum neon_cvt_mode
15535{
15536 neon_cvt_mode_a,
15537 neon_cvt_mode_n,
15538 neon_cvt_mode_p,
15539 neon_cvt_mode_m,
15540 neon_cvt_mode_z,
30bdf752
MGD
15541 neon_cvt_mode_x,
15542 neon_cvt_mode_r
7e8e6784
MGD
15543};
15544
037e8744
JB
15545/* Neon-syntax VFP conversions. */
15546
5287ad62 15547static void
6b9a8b67 15548do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15549{
037e8744 15550 const char *opname = 0;
5f4273c7 15551
d54af2d0
RL
15552 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15553 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15554 {
037e8744
JB
15555 /* Conversions with immediate bitshift. */
15556 const char *enc[] =
477330fc 15557 {
6b9a8b67
MGD
15558#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15559 CVT_FLAVOUR_VAR
15560 NULL
15561#undef CVT_VAR
477330fc 15562 };
037e8744 15563
6b9a8b67 15564 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15565 {
15566 opname = enc[flavour];
15567 constraint (inst.operands[0].reg != inst.operands[1].reg,
15568 _("operands 0 and 1 must be the same register"));
15569 inst.operands[1] = inst.operands[2];
15570 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15571 }
5287ad62
JB
15572 }
15573 else
15574 {
037e8744
JB
15575 /* Conversions without bitshift. */
15576 const char *enc[] =
477330fc 15577 {
6b9a8b67
MGD
15578#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15579 CVT_FLAVOUR_VAR
15580 NULL
15581#undef CVT_VAR
477330fc 15582 };
037e8744 15583
6b9a8b67 15584 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15585 opname = enc[flavour];
037e8744
JB
15586 }
15587
15588 if (opname)
15589 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15590
15591 /* ARMv8.2 fp16 VCVT instruction. */
15592 if (flavour == neon_cvt_flavour_s32_f16
15593 || flavour == neon_cvt_flavour_u32_f16
15594 || flavour == neon_cvt_flavour_f16_u32
15595 || flavour == neon_cvt_flavour_f16_s32)
15596 do_scalar_fp16_v82_encode ();
037e8744
JB
15597}
15598
15599static void
15600do_vfp_nsyn_cvtz (void)
15601{
d54af2d0 15602 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15603 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15604 const char *enc[] =
15605 {
6b9a8b67
MGD
15606#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15607 CVT_FLAVOUR_VAR
15608 NULL
15609#undef CVT_VAR
037e8744
JB
15610 };
15611
6b9a8b67 15612 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15613 do_vfp_nsyn_opcode (enc[flavour]);
15614}
f31fef98 15615
037e8744 15616static void
bacebabc 15617do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15618 enum neon_cvt_mode mode)
15619{
15620 int sz, op;
15621 int rm;
15622
a715796b
TG
15623 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15624 D register operands. */
15625 if (flavour == neon_cvt_flavour_s32_f64
15626 || flavour == neon_cvt_flavour_u32_f64)
15627 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15628 _(BAD_FPU));
15629
9db2f6b4
RL
15630 if (flavour == neon_cvt_flavour_s32_f16
15631 || flavour == neon_cvt_flavour_u32_f16)
15632 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15633 _(BAD_FP16));
15634
7e8e6784
MGD
15635 set_it_insn_type (OUTSIDE_IT_INSN);
15636
15637 switch (flavour)
15638 {
15639 case neon_cvt_flavour_s32_f64:
15640 sz = 1;
827f64ff 15641 op = 1;
7e8e6784
MGD
15642 break;
15643 case neon_cvt_flavour_s32_f32:
15644 sz = 0;
15645 op = 1;
15646 break;
9db2f6b4
RL
15647 case neon_cvt_flavour_s32_f16:
15648 sz = 0;
15649 op = 1;
15650 break;
7e8e6784
MGD
15651 case neon_cvt_flavour_u32_f64:
15652 sz = 1;
15653 op = 0;
15654 break;
15655 case neon_cvt_flavour_u32_f32:
15656 sz = 0;
15657 op = 0;
15658 break;
9db2f6b4
RL
15659 case neon_cvt_flavour_u32_f16:
15660 sz = 0;
15661 op = 0;
15662 break;
7e8e6784
MGD
15663 default:
15664 first_error (_("invalid instruction shape"));
15665 return;
15666 }
15667
15668 switch (mode)
15669 {
15670 case neon_cvt_mode_a: rm = 0; break;
15671 case neon_cvt_mode_n: rm = 1; break;
15672 case neon_cvt_mode_p: rm = 2; break;
15673 case neon_cvt_mode_m: rm = 3; break;
15674 default: first_error (_("invalid rounding mode")); return;
15675 }
15676
15677 NEON_ENCODE (FPV8, inst);
15678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15679 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15680 inst.instruction |= sz << 8;
9db2f6b4
RL
15681
15682 /* ARMv8.2 fp16 VCVT instruction. */
15683 if (flavour == neon_cvt_flavour_s32_f16
15684 ||flavour == neon_cvt_flavour_u32_f16)
15685 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15686 inst.instruction |= op << 7;
15687 inst.instruction |= rm << 16;
15688 inst.instruction |= 0xf0000000;
15689 inst.is_neon = TRUE;
15690}
15691
15692static void
15693do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15694{
15695 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15696 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15697 NS_FH, NS_HF, NS_FHI, NS_HFI,
15698 NS_NULL);
6b9a8b67 15699 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15700
cc933301
JW
15701 if (flavour == neon_cvt_flavour_invalid)
15702 return;
15703
e3e535bc 15704 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15705 if (mode == neon_cvt_mode_z
e3e535bc 15706 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15707 && (flavour == neon_cvt_flavour_s16_f16
15708 || flavour == neon_cvt_flavour_u16_f16
15709 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15710 || flavour == neon_cvt_flavour_u32_f32
15711 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15712 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15713 && (rs == NS_FD || rs == NS_FF))
15714 {
15715 do_vfp_nsyn_cvtz ();
15716 return;
15717 }
15718
9db2f6b4
RL
15719 /* ARMv8.2 fp16 VCVT conversions. */
15720 if (mode == neon_cvt_mode_z
15721 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15722 && (flavour == neon_cvt_flavour_s32_f16
15723 || flavour == neon_cvt_flavour_u32_f16)
15724 && (rs == NS_FH))
15725 {
15726 do_vfp_nsyn_cvtz ();
15727 do_scalar_fp16_v82_encode ();
15728 return;
15729 }
15730
037e8744 15731 /* VFP rather than Neon conversions. */
6b9a8b67 15732 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15733 {
7e8e6784
MGD
15734 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15735 do_vfp_nsyn_cvt (rs, flavour);
15736 else
15737 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15738
037e8744
JB
15739 return;
15740 }
15741
15742 switch (rs)
15743 {
15744 case NS_DDI:
15745 case NS_QQI:
15746 {
477330fc 15747 unsigned immbits;
cc933301
JW
15748 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15749 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15750
477330fc
RM
15751 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15752 return;
037e8744 15753
477330fc
RM
15754 /* Fixed-point conversion with #0 immediate is encoded as an
15755 integer conversion. */
15756 if (inst.operands[2].present && inst.operands[2].imm == 0)
15757 goto int_encode;
477330fc
RM
15758 NEON_ENCODE (IMMED, inst);
15759 if (flavour != neon_cvt_flavour_invalid)
15760 inst.instruction |= enctab[flavour];
15761 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15762 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15763 inst.instruction |= LOW4 (inst.operands[1].reg);
15764 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15765 inst.instruction |= neon_quad (rs) << 6;
15766 inst.instruction |= 1 << 21;
cc933301
JW
15767 if (flavour < neon_cvt_flavour_s16_f16)
15768 {
15769 inst.instruction |= 1 << 21;
15770 immbits = 32 - inst.operands[2].imm;
15771 inst.instruction |= immbits << 16;
15772 }
15773 else
15774 {
15775 inst.instruction |= 3 << 20;
15776 immbits = 16 - inst.operands[2].imm;
15777 inst.instruction |= immbits << 16;
15778 inst.instruction &= ~(1 << 9);
15779 }
477330fc
RM
15780
15781 neon_dp_fixup (&inst);
037e8744
JB
15782 }
15783 break;
15784
15785 case NS_DD:
15786 case NS_QQ:
7e8e6784
MGD
15787 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15788 {
15789 NEON_ENCODE (FLOAT, inst);
15790 set_it_insn_type (OUTSIDE_IT_INSN);
15791
15792 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15793 return;
15794
15795 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15796 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15797 inst.instruction |= LOW4 (inst.operands[1].reg);
15798 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15799 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15800 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15801 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15802 inst.instruction |= mode << 8;
cc933301
JW
15803 if (flavour == neon_cvt_flavour_u16_f16
15804 || flavour == neon_cvt_flavour_s16_f16)
15805 /* Mask off the original size bits and reencode them. */
15806 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15807
7e8e6784
MGD
15808 if (thumb_mode)
15809 inst.instruction |= 0xfc000000;
15810 else
15811 inst.instruction |= 0xf0000000;
15812 }
15813 else
15814 {
037e8744 15815 int_encode:
7e8e6784 15816 {
cc933301
JW
15817 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15818 0x100, 0x180, 0x0, 0x080};
037e8744 15819
7e8e6784 15820 NEON_ENCODE (INTEGER, inst);
037e8744 15821
7e8e6784
MGD
15822 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15823 return;
037e8744 15824
7e8e6784
MGD
15825 if (flavour != neon_cvt_flavour_invalid)
15826 inst.instruction |= enctab[flavour];
037e8744 15827
7e8e6784
MGD
15828 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15829 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15830 inst.instruction |= LOW4 (inst.operands[1].reg);
15831 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15832 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15833 if (flavour >= neon_cvt_flavour_s16_f16
15834 && flavour <= neon_cvt_flavour_f16_u16)
15835 /* Half precision. */
15836 inst.instruction |= 1 << 18;
15837 else
15838 inst.instruction |= 2 << 18;
037e8744 15839
7e8e6784
MGD
15840 neon_dp_fixup (&inst);
15841 }
15842 }
15843 break;
037e8744 15844
8e79c3df
CM
15845 /* Half-precision conversions for Advanced SIMD -- neon. */
15846 case NS_QD:
15847 case NS_DQ:
15848
15849 if ((rs == NS_DQ)
15850 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15851 {
15852 as_bad (_("operand size must match register width"));
15853 break;
15854 }
15855
15856 if ((rs == NS_QD)
15857 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15858 {
15859 as_bad (_("operand size must match register width"));
15860 break;
15861 }
15862
15863 if (rs == NS_DQ)
477330fc 15864 inst.instruction = 0x3b60600;
8e79c3df
CM
15865 else
15866 inst.instruction = 0x3b60700;
15867
15868 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15869 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15870 inst.instruction |= LOW4 (inst.operands[1].reg);
15871 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15872 neon_dp_fixup (&inst);
8e79c3df
CM
15873 break;
15874
037e8744
JB
15875 default:
15876 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15877 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15878 do_vfp_nsyn_cvt (rs, flavour);
15879 else
15880 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15881 }
5287ad62
JB
15882}
15883
e3e535bc
NC
15884static void
15885do_neon_cvtr (void)
15886{
7e8e6784 15887 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15888}
15889
15890static void
15891do_neon_cvt (void)
15892{
7e8e6784
MGD
15893 do_neon_cvt_1 (neon_cvt_mode_z);
15894}
15895
15896static void
15897do_neon_cvta (void)
15898{
15899 do_neon_cvt_1 (neon_cvt_mode_a);
15900}
15901
15902static void
15903do_neon_cvtn (void)
15904{
15905 do_neon_cvt_1 (neon_cvt_mode_n);
15906}
15907
15908static void
15909do_neon_cvtp (void)
15910{
15911 do_neon_cvt_1 (neon_cvt_mode_p);
15912}
15913
15914static void
15915do_neon_cvtm (void)
15916{
15917 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15918}
15919
8e79c3df 15920static void
c70a8987 15921do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15922{
c70a8987
MGD
15923 if (is_double)
15924 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15925
c70a8987
MGD
15926 encode_arm_vfp_reg (inst.operands[0].reg,
15927 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15928 encode_arm_vfp_reg (inst.operands[1].reg,
15929 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15930 inst.instruction |= to ? 0x10000 : 0;
15931 inst.instruction |= t ? 0x80 : 0;
15932 inst.instruction |= is_double ? 0x100 : 0;
15933 do_vfp_cond_or_thumb ();
15934}
8e79c3df 15935
c70a8987
MGD
15936static void
15937do_neon_cvttb_1 (bfd_boolean t)
15938{
d54af2d0
RL
15939 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15940 NS_DF, NS_DH, NS_NULL);
8e79c3df 15941
c70a8987
MGD
15942 if (rs == NS_NULL)
15943 return;
15944 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15945 {
15946 inst.error = NULL;
15947 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15948 }
15949 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15950 {
15951 inst.error = NULL;
15952 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15953 }
15954 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15955 {
a715796b
TG
15956 /* The VCVTB and VCVTT instructions with D-register operands
15957 don't work for SP only targets. */
15958 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15959 _(BAD_FPU));
15960
c70a8987
MGD
15961 inst.error = NULL;
15962 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15963 }
15964 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15965 {
a715796b
TG
15966 /* The VCVTB and VCVTT instructions with D-register operands
15967 don't work for SP only targets. */
15968 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15969 _(BAD_FPU));
15970
c70a8987
MGD
15971 inst.error = NULL;
15972 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15973 }
15974 else
15975 return;
15976}
15977
15978static void
15979do_neon_cvtb (void)
15980{
15981 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15982}
15983
15984
15985static void
15986do_neon_cvtt (void)
15987{
c70a8987 15988 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15989}
15990
5287ad62
JB
15991static void
15992neon_move_immediate (void)
15993{
037e8744
JB
15994 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15995 struct neon_type_el et = neon_check_type (2, rs,
15996 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15997 unsigned immlo, immhi = 0, immbits;
c96612cc 15998 int op, cmode, float_p;
5287ad62 15999
037e8744 16000 constraint (et.type == NT_invtype,
477330fc 16001 _("operand size must be specified for immediate VMOV"));
037e8744 16002
5287ad62
JB
16003 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16004 op = (inst.instruction & (1 << 5)) != 0;
16005
16006 immlo = inst.operands[1].imm;
16007 if (inst.operands[1].regisimm)
16008 immhi = inst.operands[1].reg;
16009
16010 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16011 _("immediate has bits set outside the operand size"));
5287ad62 16012
c96612cc
JB
16013 float_p = inst.operands[1].immisfloat;
16014
16015 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16016 et.size, et.type)) == FAIL)
5287ad62
JB
16017 {
16018 /* Invert relevant bits only. */
16019 neon_invert_size (&immlo, &immhi, et.size);
16020 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16021 with one or the other; those cases are caught by
16022 neon_cmode_for_move_imm. */
5287ad62 16023 op = !op;
c96612cc
JB
16024 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16025 &op, et.size, et.type)) == FAIL)
477330fc
RM
16026 {
16027 first_error (_("immediate out of range"));
16028 return;
16029 }
5287ad62
JB
16030 }
16031
16032 inst.instruction &= ~(1 << 5);
16033 inst.instruction |= op << 5;
16034
16035 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16036 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16037 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16038 inst.instruction |= cmode << 8;
16039
16040 neon_write_immbits (immbits);
16041}
16042
16043static void
16044do_neon_mvn (void)
16045{
16046 if (inst.operands[1].isreg)
16047 {
037e8744 16048 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16049
88714cb8 16050 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16051 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16052 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16053 inst.instruction |= LOW4 (inst.operands[1].reg);
16054 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16055 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16056 }
16057 else
16058 {
88714cb8 16059 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16060 neon_move_immediate ();
16061 }
16062
88714cb8 16063 neon_dp_fixup (&inst);
5287ad62
JB
16064}
16065
16066/* Encode instructions of form:
16067
16068 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16069 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16070
16071static void
16072neon_mixed_length (struct neon_type_el et, unsigned size)
16073{
16074 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16075 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16076 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16077 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16078 inst.instruction |= LOW4 (inst.operands[2].reg);
16079 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16080 inst.instruction |= (et.type == NT_unsigned) << 24;
16081 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16082
88714cb8 16083 neon_dp_fixup (&inst);
5287ad62
JB
16084}
16085
16086static void
16087do_neon_dyadic_long (void)
16088{
16089 /* FIXME: Type checking for lengthening op. */
16090 struct neon_type_el et = neon_check_type (3, NS_QDD,
16091 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16092 neon_mixed_length (et, et.size);
16093}
16094
16095static void
16096do_neon_abal (void)
16097{
16098 struct neon_type_el et = neon_check_type (3, NS_QDD,
16099 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16100 neon_mixed_length (et, et.size);
16101}
16102
16103static void
16104neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16105{
16106 if (inst.operands[2].isscalar)
16107 {
dcbf9037 16108 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16109 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16110 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16111 neon_mul_mac (et, et.type == NT_unsigned);
16112 }
16113 else
16114 {
16115 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16116 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16117 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16118 neon_mixed_length (et, et.size);
16119 }
16120}
16121
16122static void
16123do_neon_mac_maybe_scalar_long (void)
16124{
16125 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16126}
16127
16128static void
16129do_neon_dyadic_wide (void)
16130{
16131 struct neon_type_el et = neon_check_type (3, NS_QQD,
16132 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16133 neon_mixed_length (et, et.size);
16134}
16135
16136static void
16137do_neon_dyadic_narrow (void)
16138{
16139 struct neon_type_el et = neon_check_type (3, NS_QDD,
16140 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16141 /* Operand sign is unimportant, and the U bit is part of the opcode,
16142 so force the operand type to integer. */
16143 et.type = NT_integer;
5287ad62
JB
16144 neon_mixed_length (et, et.size / 2);
16145}
16146
16147static void
16148do_neon_mul_sat_scalar_long (void)
16149{
16150 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16151}
16152
16153static void
16154do_neon_vmull (void)
16155{
16156 if (inst.operands[2].isscalar)
16157 do_neon_mac_maybe_scalar_long ();
16158 else
16159 {
16160 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16161 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16162
5287ad62 16163 if (et.type == NT_poly)
477330fc 16164 NEON_ENCODE (POLY, inst);
5287ad62 16165 else
477330fc 16166 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16167
16168 /* For polynomial encoding the U bit must be zero, and the size must
16169 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16170 obviously, as 0b10). */
16171 if (et.size == 64)
16172 {
16173 /* Check we're on the correct architecture. */
16174 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16175 inst.error =
16176 _("Instruction form not available on this architecture.");
16177
16178 et.size = 32;
16179 }
16180
5287ad62
JB
16181 neon_mixed_length (et, et.size);
16182 }
16183}
16184
16185static void
16186do_neon_ext (void)
16187{
037e8744 16188 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16189 struct neon_type_el et = neon_check_type (3, rs,
16190 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16191 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16192
16193 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16194 _("shift out of range"));
5287ad62
JB
16195 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16196 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16197 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16198 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16199 inst.instruction |= LOW4 (inst.operands[2].reg);
16200 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16201 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16202 inst.instruction |= imm << 8;
5f4273c7 16203
88714cb8 16204 neon_dp_fixup (&inst);
5287ad62
JB
16205}
16206
16207static void
16208do_neon_rev (void)
16209{
037e8744 16210 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16211 struct neon_type_el et = neon_check_type (2, rs,
16212 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16213 unsigned op = (inst.instruction >> 7) & 3;
16214 /* N (width of reversed regions) is encoded as part of the bitmask. We
16215 extract it here to check the elements to be reversed are smaller.
16216 Otherwise we'd get a reserved instruction. */
16217 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16218 gas_assert (elsize != 0);
5287ad62 16219 constraint (et.size >= elsize,
477330fc 16220 _("elements must be smaller than reversal region"));
037e8744 16221 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16222}
16223
16224static void
16225do_neon_dup (void)
16226{
16227 if (inst.operands[1].isscalar)
16228 {
037e8744 16229 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16230 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16231 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16232 unsigned sizebits = et.size >> 3;
dcbf9037 16233 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16234 int logsize = neon_logbits (et.size);
dcbf9037 16235 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16236
16237 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16238 return;
037e8744 16239
88714cb8 16240 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16241 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16242 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16243 inst.instruction |= LOW4 (dm);
16244 inst.instruction |= HI1 (dm) << 5;
037e8744 16245 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16246 inst.instruction |= x << 17;
16247 inst.instruction |= sizebits << 16;
5f4273c7 16248
88714cb8 16249 neon_dp_fixup (&inst);
5287ad62
JB
16250 }
16251 else
16252 {
037e8744
JB
16253 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16254 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16255 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16256 /* Duplicate ARM register to lanes of vector. */
88714cb8 16257 NEON_ENCODE (ARMREG, inst);
5287ad62 16258 switch (et.size)
477330fc
RM
16259 {
16260 case 8: inst.instruction |= 0x400000; break;
16261 case 16: inst.instruction |= 0x000020; break;
16262 case 32: inst.instruction |= 0x000000; break;
16263 default: break;
16264 }
5287ad62
JB
16265 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16266 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16267 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16268 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16269 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16270 variants, except for the condition field. */
037e8744 16271 do_vfp_cond_or_thumb ();
5287ad62
JB
16272 }
16273}
16274
16275/* VMOV has particularly many variations. It can be one of:
16276 0. VMOV<c><q> <Qd>, <Qm>
16277 1. VMOV<c><q> <Dd>, <Dm>
16278 (Register operations, which are VORR with Rm = Rn.)
16279 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16280 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16281 (Immediate loads.)
16282 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16283 (ARM register to scalar.)
16284 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16285 (Two ARM registers to vector.)
16286 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16287 (Scalar to ARM register.)
16288 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16289 (Vector to two ARM registers.)
037e8744
JB
16290 8. VMOV.F32 <Sd>, <Sm>
16291 9. VMOV.F64 <Dd>, <Dm>
16292 (VFP register moves.)
16293 10. VMOV.F32 <Sd>, #imm
16294 11. VMOV.F64 <Dd>, #imm
16295 (VFP float immediate load.)
16296 12. VMOV <Rd>, <Sm>
16297 (VFP single to ARM reg.)
16298 13. VMOV <Sd>, <Rm>
16299 (ARM reg to VFP single.)
16300 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16301 (Two ARM regs to two VFP singles.)
16302 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16303 (Two VFP singles to two ARM regs.)
5f4273c7 16304
037e8744
JB
16305 These cases can be disambiguated using neon_select_shape, except cases 1/9
16306 and 3/11 which depend on the operand type too.
5f4273c7 16307
5287ad62 16308 All the encoded bits are hardcoded by this function.
5f4273c7 16309
b7fc2769
JB
16310 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16311 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16312
5287ad62 16313 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16314 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16315
16316static void
16317do_neon_mov (void)
16318{
037e8744 16319 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16320 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16321 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16322 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16323 struct neon_type_el et;
16324 const char *ldconst = 0;
5287ad62 16325
037e8744 16326 switch (rs)
5287ad62 16327 {
037e8744
JB
16328 case NS_DD: /* case 1/9. */
16329 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16330 /* It is not an error here if no type is given. */
16331 inst.error = NULL;
16332 if (et.type == NT_float && et.size == 64)
477330fc
RM
16333 {
16334 do_vfp_nsyn_opcode ("fcpyd");
16335 break;
16336 }
037e8744 16337 /* fall through. */
5287ad62 16338
037e8744
JB
16339 case NS_QQ: /* case 0/1. */
16340 {
477330fc
RM
16341 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16342 return;
16343 /* The architecture manual I have doesn't explicitly state which
16344 value the U bit should have for register->register moves, but
16345 the equivalent VORR instruction has U = 0, so do that. */
16346 inst.instruction = 0x0200110;
16347 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16348 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16349 inst.instruction |= LOW4 (inst.operands[1].reg);
16350 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16351 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16352 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16353 inst.instruction |= neon_quad (rs) << 6;
16354
16355 neon_dp_fixup (&inst);
037e8744
JB
16356 }
16357 break;
5f4273c7 16358
037e8744
JB
16359 case NS_DI: /* case 3/11. */
16360 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16361 inst.error = NULL;
16362 if (et.type == NT_float && et.size == 64)
477330fc
RM
16363 {
16364 /* case 11 (fconstd). */
16365 ldconst = "fconstd";
16366 goto encode_fconstd;
16367 }
037e8744
JB
16368 /* fall through. */
16369
16370 case NS_QI: /* case 2/3. */
16371 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16372 return;
037e8744
JB
16373 inst.instruction = 0x0800010;
16374 neon_move_immediate ();
88714cb8 16375 neon_dp_fixup (&inst);
5287ad62 16376 break;
5f4273c7 16377
037e8744
JB
16378 case NS_SR: /* case 4. */
16379 {
477330fc
RM
16380 unsigned bcdebits = 0;
16381 int logsize;
16382 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16383 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16384
05ac0ffb
JB
16385 /* .<size> is optional here, defaulting to .32. */
16386 if (inst.vectype.elems == 0
16387 && inst.operands[0].vectype.type == NT_invtype
16388 && inst.operands[1].vectype.type == NT_invtype)
16389 {
16390 inst.vectype.el[0].type = NT_untyped;
16391 inst.vectype.el[0].size = 32;
16392 inst.vectype.elems = 1;
16393 }
16394
477330fc
RM
16395 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16396 logsize = neon_logbits (et.size);
16397
16398 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16399 _(BAD_FPU));
16400 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16401 && et.size != 32, _(BAD_FPU));
16402 constraint (et.type == NT_invtype, _("bad type for scalar"));
16403 constraint (x >= 64 / et.size, _("scalar index out of range"));
16404
16405 switch (et.size)
16406 {
16407 case 8: bcdebits = 0x8; break;
16408 case 16: bcdebits = 0x1; break;
16409 case 32: bcdebits = 0x0; break;
16410 default: ;
16411 }
16412
16413 bcdebits |= x << logsize;
16414
16415 inst.instruction = 0xe000b10;
16416 do_vfp_cond_or_thumb ();
16417 inst.instruction |= LOW4 (dn) << 16;
16418 inst.instruction |= HI1 (dn) << 7;
16419 inst.instruction |= inst.operands[1].reg << 12;
16420 inst.instruction |= (bcdebits & 3) << 5;
16421 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16422 }
16423 break;
5f4273c7 16424
037e8744 16425 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16426 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16427 _(BAD_FPU));
b7fc2769 16428
037e8744
JB
16429 inst.instruction = 0xc400b10;
16430 do_vfp_cond_or_thumb ();
16431 inst.instruction |= LOW4 (inst.operands[0].reg);
16432 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16433 inst.instruction |= inst.operands[1].reg << 12;
16434 inst.instruction |= inst.operands[2].reg << 16;
16435 break;
5f4273c7 16436
037e8744
JB
16437 case NS_RS: /* case 6. */
16438 {
477330fc
RM
16439 unsigned logsize;
16440 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16441 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16442 unsigned abcdebits = 0;
037e8744 16443
05ac0ffb
JB
16444 /* .<dt> is optional here, defaulting to .32. */
16445 if (inst.vectype.elems == 0
16446 && inst.operands[0].vectype.type == NT_invtype
16447 && inst.operands[1].vectype.type == NT_invtype)
16448 {
16449 inst.vectype.el[0].type = NT_untyped;
16450 inst.vectype.el[0].size = 32;
16451 inst.vectype.elems = 1;
16452 }
16453
91d6fa6a
NC
16454 et = neon_check_type (2, NS_NULL,
16455 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16456 logsize = neon_logbits (et.size);
16457
16458 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16459 _(BAD_FPU));
16460 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16461 && et.size != 32, _(BAD_FPU));
16462 constraint (et.type == NT_invtype, _("bad type for scalar"));
16463 constraint (x >= 64 / et.size, _("scalar index out of range"));
16464
16465 switch (et.size)
16466 {
16467 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16468 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16469 case 32: abcdebits = 0x00; break;
16470 default: ;
16471 }
16472
16473 abcdebits |= x << logsize;
16474 inst.instruction = 0xe100b10;
16475 do_vfp_cond_or_thumb ();
16476 inst.instruction |= LOW4 (dn) << 16;
16477 inst.instruction |= HI1 (dn) << 7;
16478 inst.instruction |= inst.operands[0].reg << 12;
16479 inst.instruction |= (abcdebits & 3) << 5;
16480 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16481 }
16482 break;
5f4273c7 16483
037e8744
JB
16484 case NS_RRD: /* case 7 (fmrrd). */
16485 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16486 _(BAD_FPU));
037e8744
JB
16487
16488 inst.instruction = 0xc500b10;
16489 do_vfp_cond_or_thumb ();
16490 inst.instruction |= inst.operands[0].reg << 12;
16491 inst.instruction |= inst.operands[1].reg << 16;
16492 inst.instruction |= LOW4 (inst.operands[2].reg);
16493 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16494 break;
5f4273c7 16495
037e8744
JB
16496 case NS_FF: /* case 8 (fcpys). */
16497 do_vfp_nsyn_opcode ("fcpys");
16498 break;
5f4273c7 16499
9db2f6b4 16500 case NS_HI:
037e8744
JB
16501 case NS_FI: /* case 10 (fconsts). */
16502 ldconst = "fconsts";
16503 encode_fconstd:
16504 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16505 {
16506 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16507 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16508
16509 /* ARMv8.2 fp16 vmov.f16 instruction. */
16510 if (rs == NS_HI)
16511 do_scalar_fp16_v82_encode ();
477330fc 16512 }
5287ad62 16513 else
477330fc 16514 first_error (_("immediate out of range"));
037e8744 16515 break;
5f4273c7 16516
9db2f6b4 16517 case NS_RH:
037e8744
JB
16518 case NS_RF: /* case 12 (fmrs). */
16519 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16520 /* ARMv8.2 fp16 vmov.f16 instruction. */
16521 if (rs == NS_RH)
16522 do_scalar_fp16_v82_encode ();
037e8744 16523 break;
5f4273c7 16524
9db2f6b4 16525 case NS_HR:
037e8744
JB
16526 case NS_FR: /* case 13 (fmsr). */
16527 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16528 /* ARMv8.2 fp16 vmov.f16 instruction. */
16529 if (rs == NS_HR)
16530 do_scalar_fp16_v82_encode ();
037e8744 16531 break;
5f4273c7 16532
037e8744
JB
16533 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16534 (one of which is a list), but we have parsed four. Do some fiddling to
16535 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16536 expect. */
16537 case NS_RRFF: /* case 14 (fmrrs). */
16538 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16539 _("VFP registers must be adjacent"));
037e8744
JB
16540 inst.operands[2].imm = 2;
16541 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16542 do_vfp_nsyn_opcode ("fmrrs");
16543 break;
5f4273c7 16544
037e8744
JB
16545 case NS_FFRR: /* case 15 (fmsrr). */
16546 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16547 _("VFP registers must be adjacent"));
037e8744
JB
16548 inst.operands[1] = inst.operands[2];
16549 inst.operands[2] = inst.operands[3];
16550 inst.operands[0].imm = 2;
16551 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16552 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16553 break;
5f4273c7 16554
4c261dff
NC
16555 case NS_NULL:
16556 /* neon_select_shape has determined that the instruction
16557 shape is wrong and has already set the error message. */
16558 break;
16559
5287ad62
JB
16560 default:
16561 abort ();
16562 }
16563}
16564
16565static void
16566do_neon_rshift_round_imm (void)
16567{
037e8744 16568 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16569 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16570 int imm = inst.operands[2].imm;
16571
16572 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16573 if (imm == 0)
16574 {
16575 inst.operands[2].present = 0;
16576 do_neon_mov ();
16577 return;
16578 }
16579
16580 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16581 _("immediate out of range for shift"));
037e8744 16582 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16583 et.size - imm);
5287ad62
JB
16584}
16585
9db2f6b4
RL
16586static void
16587do_neon_movhf (void)
16588{
16589 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16590 constraint (rs != NS_HH, _("invalid suffix"));
16591
16592 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16593 _(BAD_FPU));
16594
16595 do_vfp_sp_monadic ();
16596
16597 inst.is_neon = 1;
16598 inst.instruction |= 0xf0000000;
16599}
16600
5287ad62
JB
16601static void
16602do_neon_movl (void)
16603{
16604 struct neon_type_el et = neon_check_type (2, NS_QD,
16605 N_EQK | N_DBL, N_SU_32 | N_KEY);
16606 unsigned sizebits = et.size >> 3;
16607 inst.instruction |= sizebits << 19;
16608 neon_two_same (0, et.type == NT_unsigned, -1);
16609}
16610
16611static void
16612do_neon_trn (void)
16613{
037e8744 16614 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16615 struct neon_type_el et = neon_check_type (2, rs,
16616 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16617 NEON_ENCODE (INTEGER, inst);
037e8744 16618 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16619}
16620
16621static void
16622do_neon_zip_uzp (void)
16623{
037e8744 16624 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16625 struct neon_type_el et = neon_check_type (2, rs,
16626 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16627 if (rs == NS_DD && et.size == 32)
16628 {
16629 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16630 inst.instruction = N_MNEM_vtrn;
16631 do_neon_trn ();
16632 return;
16633 }
037e8744 16634 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16635}
16636
16637static void
16638do_neon_sat_abs_neg (void)
16639{
037e8744 16640 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16641 struct neon_type_el et = neon_check_type (2, rs,
16642 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16643 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16644}
16645
16646static void
16647do_neon_pair_long (void)
16648{
037e8744 16649 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16650 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16651 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16652 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16653 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16654}
16655
16656static void
16657do_neon_recip_est (void)
16658{
037e8744 16659 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16660 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16661 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16662 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16663 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16664}
16665
16666static void
16667do_neon_cls (void)
16668{
037e8744 16669 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16670 struct neon_type_el et = neon_check_type (2, rs,
16671 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16672 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16673}
16674
16675static void
16676do_neon_clz (void)
16677{
037e8744 16678 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16679 struct neon_type_el et = neon_check_type (2, rs,
16680 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16681 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16682}
16683
16684static void
16685do_neon_cnt (void)
16686{
037e8744 16687 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16688 struct neon_type_el et = neon_check_type (2, rs,
16689 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16690 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16691}
16692
16693static void
16694do_neon_swp (void)
16695{
037e8744
JB
16696 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16697 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16698}
16699
16700static void
16701do_neon_tbl_tbx (void)
16702{
16703 unsigned listlenbits;
dcbf9037 16704 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16705
5287ad62
JB
16706 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16707 {
dcbf9037 16708 first_error (_("bad list length for table lookup"));
5287ad62
JB
16709 return;
16710 }
5f4273c7 16711
5287ad62
JB
16712 listlenbits = inst.operands[1].imm - 1;
16713 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16714 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16715 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16716 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16717 inst.instruction |= LOW4 (inst.operands[2].reg);
16718 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16719 inst.instruction |= listlenbits << 8;
5f4273c7 16720
88714cb8 16721 neon_dp_fixup (&inst);
5287ad62
JB
16722}
16723
16724static void
16725do_neon_ldm_stm (void)
16726{
16727 /* P, U and L bits are part of bitmask. */
16728 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16729 unsigned offsetbits = inst.operands[1].imm * 2;
16730
037e8744
JB
16731 if (inst.operands[1].issingle)
16732 {
16733 do_vfp_nsyn_ldm_stm (is_dbmode);
16734 return;
16735 }
16736
5287ad62 16737 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16738 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16739
16740 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16741 _("register list must contain at least 1 and at most 16 "
16742 "registers"));
5287ad62
JB
16743
16744 inst.instruction |= inst.operands[0].reg << 16;
16745 inst.instruction |= inst.operands[0].writeback << 21;
16746 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16747 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16748
16749 inst.instruction |= offsetbits;
5f4273c7 16750
037e8744 16751 do_vfp_cond_or_thumb ();
5287ad62
JB
16752}
16753
16754static void
16755do_neon_ldr_str (void)
16756{
5287ad62 16757 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16758
6844b2c2
MGD
16759 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16760 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16761 if (!is_ldr
6844b2c2 16762 && inst.operands[1].reg == REG_PC
ba86b375 16763 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16764 {
94dcf8bf 16765 if (thumb_mode)
6844b2c2 16766 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16767 else if (warn_on_deprecated)
5c3696f8 16768 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16769 }
16770
037e8744
JB
16771 if (inst.operands[0].issingle)
16772 {
cd2f129f 16773 if (is_ldr)
477330fc 16774 do_vfp_nsyn_opcode ("flds");
cd2f129f 16775 else
477330fc 16776 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16777
16778 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16779 if (inst.vectype.el[0].size == 16)
16780 do_scalar_fp16_v82_encode ();
5287ad62
JB
16781 }
16782 else
5287ad62 16783 {
cd2f129f 16784 if (is_ldr)
477330fc 16785 do_vfp_nsyn_opcode ("fldd");
5287ad62 16786 else
477330fc 16787 do_vfp_nsyn_opcode ("fstd");
5287ad62 16788 }
5287ad62
JB
16789}
16790
16791/* "interleave" version also handles non-interleaving register VLD1/VST1
16792 instructions. */
16793
16794static void
16795do_neon_ld_st_interleave (void)
16796{
037e8744 16797 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16798 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16799 unsigned alignbits = 0;
16800 unsigned idx;
16801 /* The bits in this table go:
16802 0: register stride of one (0) or two (1)
16803 1,2: register list length, minus one (1, 2, 3, 4).
16804 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16805 We use -1 for invalid entries. */
16806 const int typetable[] =
16807 {
16808 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16809 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16810 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16811 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16812 };
16813 int typebits;
16814
dcbf9037
JB
16815 if (et.type == NT_invtype)
16816 return;
16817
5287ad62
JB
16818 if (inst.operands[1].immisalign)
16819 switch (inst.operands[1].imm >> 8)
16820 {
16821 case 64: alignbits = 1; break;
16822 case 128:
477330fc 16823 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16824 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16825 goto bad_alignment;
16826 alignbits = 2;
16827 break;
5287ad62 16828 case 256:
477330fc
RM
16829 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16830 goto bad_alignment;
16831 alignbits = 3;
16832 break;
5287ad62
JB
16833 default:
16834 bad_alignment:
477330fc
RM
16835 first_error (_("bad alignment"));
16836 return;
5287ad62
JB
16837 }
16838
16839 inst.instruction |= alignbits << 4;
16840 inst.instruction |= neon_logbits (et.size) << 6;
16841
16842 /* Bits [4:6] of the immediate in a list specifier encode register stride
16843 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16844 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16845 up the right value for "type" in a table based on this value and the given
16846 list style, then stick it back. */
16847 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16848 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16849
16850 typebits = typetable[idx];
5f4273c7 16851
5287ad62 16852 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16853 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16854 _("bad element type for instruction"));
5287ad62
JB
16855
16856 inst.instruction &= ~0xf00;
16857 inst.instruction |= typebits << 8;
16858}
16859
16860/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16861 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16862 otherwise. The variable arguments are a list of pairs of legal (size, align)
16863 values, terminated with -1. */
16864
16865static int
aa8a0863 16866neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16867{
16868 va_list ap;
16869 int result = FAIL, thissize, thisalign;
5f4273c7 16870
5287ad62
JB
16871 if (!inst.operands[1].immisalign)
16872 {
aa8a0863 16873 *do_alignment = 0;
5287ad62
JB
16874 return SUCCESS;
16875 }
5f4273c7 16876
aa8a0863 16877 va_start (ap, do_alignment);
5287ad62
JB
16878
16879 do
16880 {
16881 thissize = va_arg (ap, int);
16882 if (thissize == -1)
477330fc 16883 break;
5287ad62
JB
16884 thisalign = va_arg (ap, int);
16885
16886 if (size == thissize && align == thisalign)
477330fc 16887 result = SUCCESS;
5287ad62
JB
16888 }
16889 while (result != SUCCESS);
16890
16891 va_end (ap);
16892
16893 if (result == SUCCESS)
aa8a0863 16894 *do_alignment = 1;
5287ad62 16895 else
dcbf9037 16896 first_error (_("unsupported alignment for instruction"));
5f4273c7 16897
5287ad62
JB
16898 return result;
16899}
16900
16901static void
16902do_neon_ld_st_lane (void)
16903{
037e8744 16904 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16905 int align_good, do_alignment = 0;
5287ad62
JB
16906 int logsize = neon_logbits (et.size);
16907 int align = inst.operands[1].imm >> 8;
16908 int n = (inst.instruction >> 8) & 3;
16909 int max_el = 64 / et.size;
5f4273c7 16910
dcbf9037
JB
16911 if (et.type == NT_invtype)
16912 return;
5f4273c7 16913
5287ad62 16914 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16915 _("bad list length"));
5287ad62 16916 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16917 _("scalar index out of range"));
5287ad62 16918 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16919 && et.size == 8,
16920 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16921
5287ad62
JB
16922 switch (n)
16923 {
16924 case 0: /* VLD1 / VST1. */
aa8a0863 16925 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16926 32, 32, -1);
5287ad62 16927 if (align_good == FAIL)
477330fc 16928 return;
aa8a0863 16929 if (do_alignment)
477330fc
RM
16930 {
16931 unsigned alignbits = 0;
16932 switch (et.size)
16933 {
16934 case 16: alignbits = 0x1; break;
16935 case 32: alignbits = 0x3; break;
16936 default: ;
16937 }
16938 inst.instruction |= alignbits << 4;
16939 }
5287ad62
JB
16940 break;
16941
16942 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16943 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16944 16, 32, 32, 64, -1);
5287ad62 16945 if (align_good == FAIL)
477330fc 16946 return;
aa8a0863 16947 if (do_alignment)
477330fc 16948 inst.instruction |= 1 << 4;
5287ad62
JB
16949 break;
16950
16951 case 2: /* VLD3 / VST3. */
16952 constraint (inst.operands[1].immisalign,
477330fc 16953 _("can't use alignment with this instruction"));
5287ad62
JB
16954 break;
16955
16956 case 3: /* VLD4 / VST4. */
aa8a0863 16957 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16958 16, 64, 32, 64, 32, 128, -1);
5287ad62 16959 if (align_good == FAIL)
477330fc 16960 return;
aa8a0863 16961 if (do_alignment)
477330fc
RM
16962 {
16963 unsigned alignbits = 0;
16964 switch (et.size)
16965 {
16966 case 8: alignbits = 0x1; break;
16967 case 16: alignbits = 0x1; break;
16968 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16969 default: ;
16970 }
16971 inst.instruction |= alignbits << 4;
16972 }
5287ad62
JB
16973 break;
16974
16975 default: ;
16976 }
16977
16978 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16979 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16980 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16981
5287ad62
JB
16982 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16983 inst.instruction |= logsize << 10;
16984}
16985
16986/* Encode single n-element structure to all lanes VLD<n> instructions. */
16987
16988static void
16989do_neon_ld_dup (void)
16990{
037e8744 16991 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16992 int align_good, do_alignment = 0;
5287ad62 16993
dcbf9037
JB
16994 if (et.type == NT_invtype)
16995 return;
16996
5287ad62
JB
16997 switch ((inst.instruction >> 8) & 3)
16998 {
16999 case 0: /* VLD1. */
9c2799c2 17000 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17001 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17002 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17003 if (align_good == FAIL)
477330fc 17004 return;
5287ad62 17005 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17006 {
17007 case 1: break;
17008 case 2: inst.instruction |= 1 << 5; break;
17009 default: first_error (_("bad list length")); return;
17010 }
5287ad62
JB
17011 inst.instruction |= neon_logbits (et.size) << 6;
17012 break;
17013
17014 case 1: /* VLD2. */
17015 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17016 &do_alignment, 8, 16, 16, 32, 32, 64,
17017 -1);
5287ad62 17018 if (align_good == FAIL)
477330fc 17019 return;
5287ad62 17020 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17021 _("bad list length"));
5287ad62 17022 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17023 inst.instruction |= 1 << 5;
5287ad62
JB
17024 inst.instruction |= neon_logbits (et.size) << 6;
17025 break;
17026
17027 case 2: /* VLD3. */
17028 constraint (inst.operands[1].immisalign,
477330fc 17029 _("can't use alignment with this instruction"));
5287ad62 17030 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17031 _("bad list length"));
5287ad62 17032 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17033 inst.instruction |= 1 << 5;
5287ad62
JB
17034 inst.instruction |= neon_logbits (et.size) << 6;
17035 break;
17036
17037 case 3: /* VLD4. */
17038 {
477330fc 17039 int align = inst.operands[1].imm >> 8;
aa8a0863 17040 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17041 16, 64, 32, 64, 32, 128, -1);
17042 if (align_good == FAIL)
17043 return;
17044 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17045 _("bad list length"));
17046 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17047 inst.instruction |= 1 << 5;
17048 if (et.size == 32 && align == 128)
17049 inst.instruction |= 0x3 << 6;
17050 else
17051 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17052 }
17053 break;
17054
17055 default: ;
17056 }
17057
aa8a0863 17058 inst.instruction |= do_alignment << 4;
5287ad62
JB
17059}
17060
17061/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17062 apart from bits [11:4]. */
17063
17064static void
17065do_neon_ldx_stx (void)
17066{
b1a769ed
DG
17067 if (inst.operands[1].isreg)
17068 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17069
5287ad62
JB
17070 switch (NEON_LANE (inst.operands[0].imm))
17071 {
17072 case NEON_INTERLEAVE_LANES:
88714cb8 17073 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17074 do_neon_ld_st_interleave ();
17075 break;
5f4273c7 17076
5287ad62 17077 case NEON_ALL_LANES:
88714cb8 17078 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17079 if (inst.instruction == N_INV)
17080 {
17081 first_error ("only loads support such operands");
17082 break;
17083 }
5287ad62
JB
17084 do_neon_ld_dup ();
17085 break;
5f4273c7 17086
5287ad62 17087 default:
88714cb8 17088 NEON_ENCODE (LANE, inst);
5287ad62
JB
17089 do_neon_ld_st_lane ();
17090 }
17091
17092 /* L bit comes from bit mask. */
17093 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17094 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17095 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17096
5287ad62
JB
17097 if (inst.operands[1].postind)
17098 {
17099 int postreg = inst.operands[1].imm & 0xf;
17100 constraint (!inst.operands[1].immisreg,
477330fc 17101 _("post-index must be a register"));
5287ad62 17102 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17103 _("bad register for post-index"));
5287ad62
JB
17104 inst.instruction |= postreg;
17105 }
4f2374c7 17106 else
5287ad62 17107 {
4f2374c7
WN
17108 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17109 constraint (inst.reloc.exp.X_op != O_constant
17110 || inst.reloc.exp.X_add_number != 0,
17111 BAD_ADDR_MODE);
17112
17113 if (inst.operands[1].writeback)
17114 {
17115 inst.instruction |= 0xd;
17116 }
17117 else
17118 inst.instruction |= 0xf;
5287ad62 17119 }
5f4273c7 17120
5287ad62
JB
17121 if (thumb_mode)
17122 inst.instruction |= 0xf9000000;
17123 else
17124 inst.instruction |= 0xf4000000;
17125}
33399f07
MGD
17126
17127/* FP v8. */
17128static void
17129do_vfp_nsyn_fpv8 (enum neon_shape rs)
17130{
a715796b
TG
17131 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17132 D register operands. */
17133 if (neon_shape_class[rs] == SC_DOUBLE)
17134 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17135 _(BAD_FPU));
17136
33399f07
MGD
17137 NEON_ENCODE (FPV8, inst);
17138
9db2f6b4
RL
17139 if (rs == NS_FFF || rs == NS_HHH)
17140 {
17141 do_vfp_sp_dyadic ();
17142
17143 /* ARMv8.2 fp16 instruction. */
17144 if (rs == NS_HHH)
17145 do_scalar_fp16_v82_encode ();
17146 }
33399f07
MGD
17147 else
17148 do_vfp_dp_rd_rn_rm ();
17149
17150 if (rs == NS_DDD)
17151 inst.instruction |= 0x100;
17152
17153 inst.instruction |= 0xf0000000;
17154}
17155
17156static void
17157do_vsel (void)
17158{
17159 set_it_insn_type (OUTSIDE_IT_INSN);
17160
17161 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17162 first_error (_("invalid instruction shape"));
17163}
17164
73924fbc
MGD
17165static void
17166do_vmaxnm (void)
17167{
17168 set_it_insn_type (OUTSIDE_IT_INSN);
17169
17170 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17171 return;
17172
17173 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17174 return;
17175
cc933301 17176 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17177}
17178
30bdf752
MGD
17179static void
17180do_vrint_1 (enum neon_cvt_mode mode)
17181{
9db2f6b4 17182 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17183 struct neon_type_el et;
17184
17185 if (rs == NS_NULL)
17186 return;
17187
a715796b
TG
17188 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17189 D register operands. */
17190 if (neon_shape_class[rs] == SC_DOUBLE)
17191 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17192 _(BAD_FPU));
17193
9db2f6b4
RL
17194 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17195 | N_VFP);
30bdf752
MGD
17196 if (et.type != NT_invtype)
17197 {
17198 /* VFP encodings. */
17199 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17200 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17201 set_it_insn_type (OUTSIDE_IT_INSN);
17202
17203 NEON_ENCODE (FPV8, inst);
9db2f6b4 17204 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17205 do_vfp_sp_monadic ();
17206 else
17207 do_vfp_dp_rd_rm ();
17208
17209 switch (mode)
17210 {
17211 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17212 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17213 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17214 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17215 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17216 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17217 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17218 default: abort ();
17219 }
17220
17221 inst.instruction |= (rs == NS_DD) << 8;
17222 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17223
17224 /* ARMv8.2 fp16 vrint instruction. */
17225 if (rs == NS_HH)
17226 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17227 }
17228 else
17229 {
17230 /* Neon encodings (or something broken...). */
17231 inst.error = NULL;
cc933301 17232 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17233
17234 if (et.type == NT_invtype)
17235 return;
17236
17237 set_it_insn_type (OUTSIDE_IT_INSN);
17238 NEON_ENCODE (FLOAT, inst);
17239
17240 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17241 return;
17242
17243 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17244 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17245 inst.instruction |= LOW4 (inst.operands[1].reg);
17246 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17247 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17248 /* Mask off the original size bits and reencode them. */
17249 inst.instruction = ((inst.instruction & 0xfff3ffff)
17250 | neon_logbits (et.size) << 18);
17251
30bdf752
MGD
17252 switch (mode)
17253 {
17254 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17255 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17256 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17257 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17258 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17259 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17260 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17261 default: abort ();
17262 }
17263
17264 if (thumb_mode)
17265 inst.instruction |= 0xfc000000;
17266 else
17267 inst.instruction |= 0xf0000000;
17268 }
17269}
17270
17271static void
17272do_vrintx (void)
17273{
17274 do_vrint_1 (neon_cvt_mode_x);
17275}
17276
17277static void
17278do_vrintz (void)
17279{
17280 do_vrint_1 (neon_cvt_mode_z);
17281}
17282
17283static void
17284do_vrintr (void)
17285{
17286 do_vrint_1 (neon_cvt_mode_r);
17287}
17288
17289static void
17290do_vrinta (void)
17291{
17292 do_vrint_1 (neon_cvt_mode_a);
17293}
17294
17295static void
17296do_vrintn (void)
17297{
17298 do_vrint_1 (neon_cvt_mode_n);
17299}
17300
17301static void
17302do_vrintp (void)
17303{
17304 do_vrint_1 (neon_cvt_mode_p);
17305}
17306
17307static void
17308do_vrintm (void)
17309{
17310 do_vrint_1 (neon_cvt_mode_m);
17311}
17312
c28eeff2
SN
17313static unsigned
17314neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17315{
17316 unsigned regno = NEON_SCALAR_REG (opnd);
17317 unsigned elno = NEON_SCALAR_INDEX (opnd);
17318
17319 if (elsize == 16 && elno < 2 && regno < 16)
17320 return regno | (elno << 4);
17321 else if (elsize == 32 && elno == 0)
17322 return regno;
17323
17324 first_error (_("scalar out of range"));
17325 return 0;
17326}
17327
17328static void
17329do_vcmla (void)
17330{
17331 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17332 _(BAD_FPU));
17333 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17334 unsigned rot = inst.reloc.exp.X_add_number;
17335 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17336 _("immediate out of range"));
17337 rot /= 90;
17338 if (inst.operands[2].isscalar)
17339 {
17340 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17341 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17342 N_KEY | N_F16 | N_F32).size;
17343 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17344 inst.is_neon = 1;
17345 inst.instruction = 0xfe000800;
17346 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17347 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17348 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17349 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17350 inst.instruction |= LOW4 (m);
17351 inst.instruction |= HI1 (m) << 5;
17352 inst.instruction |= neon_quad (rs) << 6;
17353 inst.instruction |= rot << 20;
17354 inst.instruction |= (size == 32) << 23;
17355 }
17356 else
17357 {
17358 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17359 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17360 N_KEY | N_F16 | N_F32).size;
17361 neon_three_same (neon_quad (rs), 0, -1);
17362 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17363 inst.instruction |= 0xfc200800;
17364 inst.instruction |= rot << 23;
17365 inst.instruction |= (size == 32) << 20;
17366 }
17367}
17368
17369static void
17370do_vcadd (void)
17371{
17372 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17373 _(BAD_FPU));
17374 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17375 unsigned rot = inst.reloc.exp.X_add_number;
17376 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17377 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17378 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17379 N_KEY | N_F16 | N_F32).size;
17380 neon_three_same (neon_quad (rs), 0, -1);
17381 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17382 inst.instruction |= 0xfc800800;
17383 inst.instruction |= (rot == 270) << 24;
17384 inst.instruction |= (size == 32) << 20;
17385}
17386
c604a79a
JW
17387/* Dot Product instructions encoding support. */
17388
17389static void
17390do_neon_dotproduct (int unsigned_p)
17391{
17392 enum neon_shape rs;
17393 unsigned scalar_oprd2 = 0;
17394 int high8;
17395
17396 if (inst.cond != COND_ALWAYS)
17397 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17398 "is UNPREDICTABLE"));
17399
17400 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17401 _(BAD_FPU));
17402
17403 /* Dot Product instructions are in three-same D/Q register format or the third
17404 operand can be a scalar index register. */
17405 if (inst.operands[2].isscalar)
17406 {
17407 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17408 high8 = 0xfe000000;
17409 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17410 }
17411 else
17412 {
17413 high8 = 0xfc000000;
17414 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17415 }
17416
17417 if (unsigned_p)
17418 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17419 else
17420 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17421
17422 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17423 Product instruction, so we pass 0 as the "ubit" parameter. And the
17424 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17425 neon_three_same (neon_quad (rs), 0, 32);
17426
17427 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17428 different NEON three-same encoding. */
17429 inst.instruction &= 0x00ffffff;
17430 inst.instruction |= high8;
17431 /* Encode 'U' bit which indicates signedness. */
17432 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17433 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17434 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17435 the instruction encoding. */
17436 if (inst.operands[2].isscalar)
17437 {
17438 inst.instruction &= 0xffffffd0;
17439 inst.instruction |= LOW4 (scalar_oprd2);
17440 inst.instruction |= HI1 (scalar_oprd2) << 5;
17441 }
17442}
17443
17444/* Dot Product instructions for signed integer. */
17445
17446static void
17447do_neon_dotproduct_s (void)
17448{
17449 return do_neon_dotproduct (0);
17450}
17451
17452/* Dot Product instructions for unsigned integer. */
17453
17454static void
17455do_neon_dotproduct_u (void)
17456{
17457 return do_neon_dotproduct (1);
17458}
17459
91ff7894
MGD
17460/* Crypto v1 instructions. */
17461static void
17462do_crypto_2op_1 (unsigned elttype, int op)
17463{
17464 set_it_insn_type (OUTSIDE_IT_INSN);
17465
17466 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17467 == NT_invtype)
17468 return;
17469
17470 inst.error = NULL;
17471
17472 NEON_ENCODE (INTEGER, inst);
17473 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17474 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17475 inst.instruction |= LOW4 (inst.operands[1].reg);
17476 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17477 if (op != -1)
17478 inst.instruction |= op << 6;
17479
17480 if (thumb_mode)
17481 inst.instruction |= 0xfc000000;
17482 else
17483 inst.instruction |= 0xf0000000;
17484}
17485
48adcd8e
MGD
17486static void
17487do_crypto_3op_1 (int u, int op)
17488{
17489 set_it_insn_type (OUTSIDE_IT_INSN);
17490
17491 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17492 N_32 | N_UNT | N_KEY).type == NT_invtype)
17493 return;
17494
17495 inst.error = NULL;
17496
17497 NEON_ENCODE (INTEGER, inst);
17498 neon_three_same (1, u, 8 << op);
17499}
17500
91ff7894
MGD
17501static void
17502do_aese (void)
17503{
17504 do_crypto_2op_1 (N_8, 0);
17505}
17506
17507static void
17508do_aesd (void)
17509{
17510 do_crypto_2op_1 (N_8, 1);
17511}
17512
17513static void
17514do_aesmc (void)
17515{
17516 do_crypto_2op_1 (N_8, 2);
17517}
17518
17519static void
17520do_aesimc (void)
17521{
17522 do_crypto_2op_1 (N_8, 3);
17523}
17524
48adcd8e
MGD
17525static void
17526do_sha1c (void)
17527{
17528 do_crypto_3op_1 (0, 0);
17529}
17530
17531static void
17532do_sha1p (void)
17533{
17534 do_crypto_3op_1 (0, 1);
17535}
17536
17537static void
17538do_sha1m (void)
17539{
17540 do_crypto_3op_1 (0, 2);
17541}
17542
17543static void
17544do_sha1su0 (void)
17545{
17546 do_crypto_3op_1 (0, 3);
17547}
91ff7894 17548
48adcd8e
MGD
17549static void
17550do_sha256h (void)
17551{
17552 do_crypto_3op_1 (1, 0);
17553}
17554
17555static void
17556do_sha256h2 (void)
17557{
17558 do_crypto_3op_1 (1, 1);
17559}
17560
17561static void
17562do_sha256su1 (void)
17563{
17564 do_crypto_3op_1 (1, 2);
17565}
3c9017d2
MGD
17566
17567static void
17568do_sha1h (void)
17569{
17570 do_crypto_2op_1 (N_32, -1);
17571}
17572
17573static void
17574do_sha1su1 (void)
17575{
17576 do_crypto_2op_1 (N_32, 0);
17577}
17578
17579static void
17580do_sha256su0 (void)
17581{
17582 do_crypto_2op_1 (N_32, 1);
17583}
dd5181d5
KT
17584
17585static void
17586do_crc32_1 (unsigned int poly, unsigned int sz)
17587{
17588 unsigned int Rd = inst.operands[0].reg;
17589 unsigned int Rn = inst.operands[1].reg;
17590 unsigned int Rm = inst.operands[2].reg;
17591
17592 set_it_insn_type (OUTSIDE_IT_INSN);
17593 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17594 inst.instruction |= LOW4 (Rn) << 16;
17595 inst.instruction |= LOW4 (Rm);
17596 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17597 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17598
17599 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17600 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17601}
17602
17603static void
17604do_crc32b (void)
17605{
17606 do_crc32_1 (0, 0);
17607}
17608
17609static void
17610do_crc32h (void)
17611{
17612 do_crc32_1 (0, 1);
17613}
17614
17615static void
17616do_crc32w (void)
17617{
17618 do_crc32_1 (0, 2);
17619}
17620
17621static void
17622do_crc32cb (void)
17623{
17624 do_crc32_1 (1, 0);
17625}
17626
17627static void
17628do_crc32ch (void)
17629{
17630 do_crc32_1 (1, 1);
17631}
17632
17633static void
17634do_crc32cw (void)
17635{
17636 do_crc32_1 (1, 2);
17637}
17638
49e8a725
SN
17639static void
17640do_vjcvt (void)
17641{
17642 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17643 _(BAD_FPU));
17644 neon_check_type (2, NS_FD, N_S32, N_F64);
17645 do_vfp_sp_dp_cvt ();
17646 do_vfp_cond_or_thumb ();
17647}
17648
5287ad62
JB
17649\f
17650/* Overall per-instruction processing. */
17651
17652/* We need to be able to fix up arbitrary expressions in some statements.
17653 This is so that we can handle symbols that are an arbitrary distance from
17654 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17655 which returns part of an address in a form which will be valid for
17656 a data instruction. We do this by pushing the expression into a symbol
17657 in the expr_section, and creating a fix for that. */
17658
17659static void
17660fix_new_arm (fragS * frag,
17661 int where,
17662 short int size,
17663 expressionS * exp,
17664 int pc_rel,
17665 int reloc)
17666{
17667 fixS * new_fix;
17668
17669 switch (exp->X_op)
17670 {
17671 case O_constant:
6e7ce2cd
PB
17672 if (pc_rel)
17673 {
17674 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17675 refer to in the object file. Unfortunately for us, gas's
17676 generic expression parsing will already have folded out
17677 any use of .set foo/.type foo %function that may have
17678 been used to set type information of the target location,
17679 that's being specified symbolically. We have to presume
17680 the user knows what they are doing. */
6e7ce2cd
PB
17681 char name[16 + 8];
17682 symbolS *symbol;
17683
17684 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17685
17686 symbol = symbol_find_or_make (name);
17687 S_SET_SEGMENT (symbol, absolute_section);
17688 symbol_set_frag (symbol, &zero_address_frag);
17689 S_SET_VALUE (symbol, exp->X_add_number);
17690 exp->X_op = O_symbol;
17691 exp->X_add_symbol = symbol;
17692 exp->X_add_number = 0;
17693 }
17694 /* FALLTHROUGH */
5287ad62
JB
17695 case O_symbol:
17696 case O_add:
17697 case O_subtract:
21d799b5 17698 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17699 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17700 break;
17701
17702 default:
21d799b5 17703 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17704 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17705 break;
17706 }
17707
17708 /* Mark whether the fix is to a THUMB instruction, or an ARM
17709 instruction. */
17710 new_fix->tc_fix_data = thumb_mode;
17711}
17712
17713/* Create a frg for an instruction requiring relaxation. */
17714static void
17715output_relax_insn (void)
17716{
17717 char * to;
17718 symbolS *sym;
0110f2b8
PB
17719 int offset;
17720
6e1cb1a6
PB
17721 /* The size of the instruction is unknown, so tie the debug info to the
17722 start of the instruction. */
17723 dwarf2_emit_insn (0);
6e1cb1a6 17724
0110f2b8
PB
17725 switch (inst.reloc.exp.X_op)
17726 {
17727 case O_symbol:
17728 sym = inst.reloc.exp.X_add_symbol;
17729 offset = inst.reloc.exp.X_add_number;
17730 break;
17731 case O_constant:
17732 sym = NULL;
17733 offset = inst.reloc.exp.X_add_number;
17734 break;
17735 default:
17736 sym = make_expr_symbol (&inst.reloc.exp);
17737 offset = 0;
17738 break;
17739 }
17740 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17741 inst.relax, sym, offset, NULL/*offset, opcode*/);
17742 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17743}
17744
17745/* Write a 32-bit thumb instruction to buf. */
17746static void
17747put_thumb32_insn (char * buf, unsigned long insn)
17748{
17749 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17750 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17751}
17752
b99bd4ef 17753static void
c19d1205 17754output_inst (const char * str)
b99bd4ef 17755{
c19d1205 17756 char * to = NULL;
b99bd4ef 17757
c19d1205 17758 if (inst.error)
b99bd4ef 17759 {
c19d1205 17760 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17761 return;
17762 }
5f4273c7
NC
17763 if (inst.relax)
17764 {
17765 output_relax_insn ();
0110f2b8 17766 return;
5f4273c7 17767 }
c19d1205
ZW
17768 if (inst.size == 0)
17769 return;
b99bd4ef 17770
c19d1205 17771 to = frag_more (inst.size);
8dc2430f
NC
17772 /* PR 9814: Record the thumb mode into the current frag so that we know
17773 what type of NOP padding to use, if necessary. We override any previous
17774 setting so that if the mode has changed then the NOPS that we use will
17775 match the encoding of the last instruction in the frag. */
cd000bff 17776 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17777
17778 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17779 {
9c2799c2 17780 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17781 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17782 }
c19d1205 17783 else if (inst.size > INSN_SIZE)
b99bd4ef 17784 {
9c2799c2 17785 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17786 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17787 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17788 }
c19d1205
ZW
17789 else
17790 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17791
c19d1205
ZW
17792 if (inst.reloc.type != BFD_RELOC_UNUSED)
17793 fix_new_arm (frag_now, to - frag_now->fr_literal,
17794 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17795 inst.reloc.type);
b99bd4ef 17796
c19d1205 17797 dwarf2_emit_insn (inst.size);
c19d1205 17798}
b99bd4ef 17799
e07e6e58
NC
17800static char *
17801output_it_inst (int cond, int mask, char * to)
17802{
17803 unsigned long instruction = 0xbf00;
17804
17805 mask &= 0xf;
17806 instruction |= mask;
17807 instruction |= cond << 4;
17808
17809 if (to == NULL)
17810 {
17811 to = frag_more (2);
17812#ifdef OBJ_ELF
17813 dwarf2_emit_insn (2);
17814#endif
17815 }
17816
17817 md_number_to_chars (to, instruction, 2);
17818
17819 return to;
17820}
17821
c19d1205
ZW
17822/* Tag values used in struct asm_opcode's tag field. */
17823enum opcode_tag
17824{
17825 OT_unconditional, /* Instruction cannot be conditionalized.
17826 The ARM condition field is still 0xE. */
17827 OT_unconditionalF, /* Instruction cannot be conditionalized
17828 and carries 0xF in its ARM condition field. */
17829 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17830 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17831 suffix, others place 0xF where the condition field
17832 would be. */
c19d1205
ZW
17833 OT_cinfix3, /* Instruction takes a conditional infix,
17834 beginning at character index 3. (In
17835 unified mode, it becomes a suffix.) */
088fa78e
KH
17836 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17837 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17838 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17839 character index 3, even in unified mode. Used for
17840 legacy instructions where suffix and infix forms
17841 may be ambiguous. */
c19d1205 17842 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17843 suffix or an infix at character index 3. */
c19d1205
ZW
17844 OT_odd_infix_unc, /* This is the unconditional variant of an
17845 instruction that takes a conditional infix
17846 at an unusual position. In unified mode,
17847 this variant will accept a suffix. */
17848 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17849 are the conditional variants of instructions that
17850 take conditional infixes in unusual positions.
17851 The infix appears at character index
17852 (tag - OT_odd_infix_0). These are not accepted
17853 in unified mode. */
17854};
b99bd4ef 17855
c19d1205
ZW
17856/* Subroutine of md_assemble, responsible for looking up the primary
17857 opcode from the mnemonic the user wrote. STR points to the
17858 beginning of the mnemonic.
17859
17860 This is not simply a hash table lookup, because of conditional
17861 variants. Most instructions have conditional variants, which are
17862 expressed with a _conditional affix_ to the mnemonic. If we were
17863 to encode each conditional variant as a literal string in the opcode
17864 table, it would have approximately 20,000 entries.
17865
17866 Most mnemonics take this affix as a suffix, and in unified syntax,
17867 'most' is upgraded to 'all'. However, in the divided syntax, some
17868 instructions take the affix as an infix, notably the s-variants of
17869 the arithmetic instructions. Of those instructions, all but six
17870 have the infix appear after the third character of the mnemonic.
17871
17872 Accordingly, the algorithm for looking up primary opcodes given
17873 an identifier is:
17874
17875 1. Look up the identifier in the opcode table.
17876 If we find a match, go to step U.
17877
17878 2. Look up the last two characters of the identifier in the
17879 conditions table. If we find a match, look up the first N-2
17880 characters of the identifier in the opcode table. If we
17881 find a match, go to step CE.
17882
17883 3. Look up the fourth and fifth characters of the identifier in
17884 the conditions table. If we find a match, extract those
17885 characters from the identifier, and look up the remaining
17886 characters in the opcode table. If we find a match, go
17887 to step CM.
17888
17889 4. Fail.
17890
17891 U. Examine the tag field of the opcode structure, in case this is
17892 one of the six instructions with its conditional infix in an
17893 unusual place. If it is, the tag tells us where to find the
17894 infix; look it up in the conditions table and set inst.cond
17895 accordingly. Otherwise, this is an unconditional instruction.
17896 Again set inst.cond accordingly. Return the opcode structure.
17897
17898 CE. Examine the tag field to make sure this is an instruction that
17899 should receive a conditional suffix. If it is not, fail.
17900 Otherwise, set inst.cond from the suffix we already looked up,
17901 and return the opcode structure.
17902
17903 CM. Examine the tag field to make sure this is an instruction that
17904 should receive a conditional infix after the third character.
17905 If it is not, fail. Otherwise, undo the edits to the current
17906 line of input and proceed as for case CE. */
17907
17908static const struct asm_opcode *
17909opcode_lookup (char **str)
17910{
17911 char *end, *base;
17912 char *affix;
17913 const struct asm_opcode *opcode;
17914 const struct asm_cond *cond;
e3cb604e 17915 char save[2];
c19d1205
ZW
17916
17917 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17918 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17919 for (base = end = *str; *end != '\0'; end++)
721a8186 17920 if (*end == ' ' || *end == '.')
c19d1205 17921 break;
b99bd4ef 17922
c19d1205 17923 if (end == base)
c921be7d 17924 return NULL;
b99bd4ef 17925
5287ad62 17926 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17927 if (end[0] == '.')
b99bd4ef 17928 {
5287ad62 17929 int offset = 2;
5f4273c7 17930
267d2029 17931 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17932 use. */
267d2029 17933 if (unified_syntax && end[1] == 'w')
c19d1205 17934 inst.size_req = 4;
267d2029 17935 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17936 inst.size_req = 2;
17937 else
477330fc 17938 offset = 0;
5287ad62
JB
17939
17940 inst.vectype.elems = 0;
17941
17942 *str = end + offset;
b99bd4ef 17943
5f4273c7 17944 if (end[offset] == '.')
5287ad62 17945 {
267d2029 17946 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17947 non-unified ARM syntax mode). */
17948 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17949 return NULL;
477330fc 17950 }
5287ad62 17951 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17952 return NULL;
b99bd4ef 17953 }
c19d1205
ZW
17954 else
17955 *str = end;
b99bd4ef 17956
c19d1205 17957 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17958 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17959 end - base);
c19d1205 17960 if (opcode)
b99bd4ef 17961 {
c19d1205
ZW
17962 /* step U */
17963 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17964 {
c19d1205
ZW
17965 inst.cond = COND_ALWAYS;
17966 return opcode;
b99bd4ef 17967 }
b99bd4ef 17968
278df34e 17969 if (warn_on_deprecated && unified_syntax)
5c3696f8 17970 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17971 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17972 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17973 gas_assert (cond);
b99bd4ef 17974
c19d1205
ZW
17975 inst.cond = cond->value;
17976 return opcode;
17977 }
b99bd4ef 17978
c19d1205
ZW
17979 /* Cannot have a conditional suffix on a mnemonic of less than two
17980 characters. */
17981 if (end - base < 3)
c921be7d 17982 return NULL;
b99bd4ef 17983
c19d1205
ZW
17984 /* Look for suffixed mnemonic. */
17985 affix = end - 2;
21d799b5
NC
17986 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17987 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17988 affix - base);
c19d1205
ZW
17989 if (opcode && cond)
17990 {
17991 /* step CE */
17992 switch (opcode->tag)
17993 {
e3cb604e
PB
17994 case OT_cinfix3_legacy:
17995 /* Ignore conditional suffixes matched on infix only mnemonics. */
17996 break;
17997
c19d1205 17998 case OT_cinfix3:
088fa78e 17999 case OT_cinfix3_deprecated:
c19d1205
ZW
18000 case OT_odd_infix_unc:
18001 if (!unified_syntax)
e3cb604e 18002 return 0;
1a0670f3 18003 /* Fall through. */
c19d1205
ZW
18004
18005 case OT_csuffix:
477330fc 18006 case OT_csuffixF:
c19d1205
ZW
18007 case OT_csuf_or_in3:
18008 inst.cond = cond->value;
18009 return opcode;
18010
18011 case OT_unconditional:
18012 case OT_unconditionalF:
dfa9f0d5 18013 if (thumb_mode)
c921be7d 18014 inst.cond = cond->value;
dfa9f0d5
PB
18015 else
18016 {
c921be7d 18017 /* Delayed diagnostic. */
dfa9f0d5
PB
18018 inst.error = BAD_COND;
18019 inst.cond = COND_ALWAYS;
18020 }
c19d1205 18021 return opcode;
b99bd4ef 18022
c19d1205 18023 default:
c921be7d 18024 return NULL;
c19d1205
ZW
18025 }
18026 }
b99bd4ef 18027
c19d1205
ZW
18028 /* Cannot have a usual-position infix on a mnemonic of less than
18029 six characters (five would be a suffix). */
18030 if (end - base < 6)
c921be7d 18031 return NULL;
b99bd4ef 18032
c19d1205
ZW
18033 /* Look for infixed mnemonic in the usual position. */
18034 affix = base + 3;
21d799b5 18035 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18036 if (!cond)
c921be7d 18037 return NULL;
e3cb604e
PB
18038
18039 memcpy (save, affix, 2);
18040 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18041 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18042 (end - base) - 2);
e3cb604e
PB
18043 memmove (affix + 2, affix, (end - affix) - 2);
18044 memcpy (affix, save, 2);
18045
088fa78e
KH
18046 if (opcode
18047 && (opcode->tag == OT_cinfix3
18048 || opcode->tag == OT_cinfix3_deprecated
18049 || opcode->tag == OT_csuf_or_in3
18050 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18051 {
c921be7d 18052 /* Step CM. */
278df34e 18053 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18054 && (opcode->tag == OT_cinfix3
18055 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18056 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18057
18058 inst.cond = cond->value;
18059 return opcode;
b99bd4ef
NC
18060 }
18061
c921be7d 18062 return NULL;
b99bd4ef
NC
18063}
18064
e07e6e58
NC
18065/* This function generates an initial IT instruction, leaving its block
18066 virtually open for the new instructions. Eventually,
18067 the mask will be updated by now_it_add_mask () each time
18068 a new instruction needs to be included in the IT block.
18069 Finally, the block is closed with close_automatic_it_block ().
18070 The block closure can be requested either from md_assemble (),
18071 a tencode (), or due to a label hook. */
18072
18073static void
18074new_automatic_it_block (int cond)
18075{
18076 now_it.state = AUTOMATIC_IT_BLOCK;
18077 now_it.mask = 0x18;
18078 now_it.cc = cond;
18079 now_it.block_length = 1;
cd000bff 18080 mapping_state (MAP_THUMB);
e07e6e58 18081 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18082 now_it.warn_deprecated = FALSE;
18083 now_it.insn_cond = TRUE;
e07e6e58
NC
18084}
18085
18086/* Close an automatic IT block.
18087 See comments in new_automatic_it_block (). */
18088
18089static void
18090close_automatic_it_block (void)
18091{
18092 now_it.mask = 0x10;
18093 now_it.block_length = 0;
18094}
18095
18096/* Update the mask of the current automatically-generated IT
18097 instruction. See comments in new_automatic_it_block (). */
18098
18099static void
18100now_it_add_mask (int cond)
18101{
18102#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18103#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18104 | ((bitvalue) << (nbit)))
e07e6e58 18105 const int resulting_bit = (cond & 1);
c921be7d 18106
e07e6e58
NC
18107 now_it.mask &= 0xf;
18108 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18109 resulting_bit,
18110 (5 - now_it.block_length));
e07e6e58 18111 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18112 1,
18113 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18114 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18115
18116#undef CLEAR_BIT
18117#undef SET_BIT_VALUE
e07e6e58
NC
18118}
18119
18120/* The IT blocks handling machinery is accessed through the these functions:
18121 it_fsm_pre_encode () from md_assemble ()
18122 set_it_insn_type () optional, from the tencode functions
18123 set_it_insn_type_last () ditto
18124 in_it_block () ditto
18125 it_fsm_post_encode () from md_assemble ()
33eaf5de 18126 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18127
18128 Rationale:
18129 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18130 initializing the IT insn type with a generic initial value depending
18131 on the inst.condition.
e07e6e58 18132 2) During the tencode function, two things may happen:
477330fc
RM
18133 a) The tencode function overrides the IT insn type by
18134 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18135 b) The tencode function queries the IT block state by
18136 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18137
18138 Both set_it_insn_type and in_it_block run the internal FSM state
18139 handling function (handle_it_state), because: a) setting the IT insn
18140 type may incur in an invalid state (exiting the function),
18141 and b) querying the state requires the FSM to be updated.
18142 Specifically we want to avoid creating an IT block for conditional
18143 branches, so it_fsm_pre_encode is actually a guess and we can't
18144 determine whether an IT block is required until the tencode () routine
18145 has decided what type of instruction this actually it.
18146 Because of this, if set_it_insn_type and in_it_block have to be used,
18147 set_it_insn_type has to be called first.
18148
18149 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18150 determines the insn IT type depending on the inst.cond code.
18151 When a tencode () routine encodes an instruction that can be
18152 either outside an IT block, or, in the case of being inside, has to be
18153 the last one, set_it_insn_type_last () will determine the proper
18154 IT instruction type based on the inst.cond code. Otherwise,
18155 set_it_insn_type can be called for overriding that logic or
18156 for covering other cases.
18157
18158 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18159 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18160 still queried. Instead, if the FSM determines that the state should
18161 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18162 after the tencode () function: that's what it_fsm_post_encode () does.
18163
18164 Since in_it_block () calls the state handling function to get an
18165 updated state, an error may occur (due to invalid insns combination).
18166 In that case, inst.error is set.
18167 Therefore, inst.error has to be checked after the execution of
18168 the tencode () routine.
e07e6e58
NC
18169
18170 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18171 any pending state change (if any) that didn't take place in
18172 handle_it_state () as explained above. */
e07e6e58
NC
18173
18174static void
18175it_fsm_pre_encode (void)
18176{
18177 if (inst.cond != COND_ALWAYS)
18178 inst.it_insn_type = INSIDE_IT_INSN;
18179 else
18180 inst.it_insn_type = OUTSIDE_IT_INSN;
18181
18182 now_it.state_handled = 0;
18183}
18184
18185/* IT state FSM handling function. */
18186
18187static int
18188handle_it_state (void)
18189{
18190 now_it.state_handled = 1;
5a01bb1d 18191 now_it.insn_cond = FALSE;
e07e6e58
NC
18192
18193 switch (now_it.state)
18194 {
18195 case OUTSIDE_IT_BLOCK:
18196 switch (inst.it_insn_type)
18197 {
18198 case OUTSIDE_IT_INSN:
18199 break;
18200
18201 case INSIDE_IT_INSN:
18202 case INSIDE_IT_LAST_INSN:
18203 if (thumb_mode == 0)
18204 {
c921be7d 18205 if (unified_syntax
e07e6e58
NC
18206 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18207 as_tsktsk (_("Warning: conditional outside an IT block"\
18208 " for Thumb."));
18209 }
18210 else
18211 {
18212 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18213 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18214 {
18215 /* Automatically generate the IT instruction. */
18216 new_automatic_it_block (inst.cond);
18217 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18218 close_automatic_it_block ();
18219 }
18220 else
18221 {
18222 inst.error = BAD_OUT_IT;
18223 return FAIL;
18224 }
18225 }
18226 break;
18227
18228 case IF_INSIDE_IT_LAST_INSN:
18229 case NEUTRAL_IT_INSN:
18230 break;
18231
18232 case IT_INSN:
18233 now_it.state = MANUAL_IT_BLOCK;
18234 now_it.block_length = 0;
18235 break;
18236 }
18237 break;
18238
18239 case AUTOMATIC_IT_BLOCK:
18240 /* Three things may happen now:
18241 a) We should increment current it block size;
18242 b) We should close current it block (closing insn or 4 insns);
18243 c) We should close current it block and start a new one (due
18244 to incompatible conditions or
18245 4 insns-length block reached). */
18246
18247 switch (inst.it_insn_type)
18248 {
18249 case OUTSIDE_IT_INSN:
2b0f3761 18250 /* The closure of the block shall happen immediately,
e07e6e58
NC
18251 so any in_it_block () call reports the block as closed. */
18252 force_automatic_it_block_close ();
18253 break;
18254
18255 case INSIDE_IT_INSN:
18256 case INSIDE_IT_LAST_INSN:
18257 case IF_INSIDE_IT_LAST_INSN:
18258 now_it.block_length++;
18259
18260 if (now_it.block_length > 4
18261 || !now_it_compatible (inst.cond))
18262 {
18263 force_automatic_it_block_close ();
18264 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18265 new_automatic_it_block (inst.cond);
18266 }
18267 else
18268 {
5a01bb1d 18269 now_it.insn_cond = TRUE;
e07e6e58
NC
18270 now_it_add_mask (inst.cond);
18271 }
18272
18273 if (now_it.state == AUTOMATIC_IT_BLOCK
18274 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18275 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18276 close_automatic_it_block ();
18277 break;
18278
18279 case NEUTRAL_IT_INSN:
18280 now_it.block_length++;
5a01bb1d 18281 now_it.insn_cond = TRUE;
e07e6e58
NC
18282
18283 if (now_it.block_length > 4)
18284 force_automatic_it_block_close ();
18285 else
18286 now_it_add_mask (now_it.cc & 1);
18287 break;
18288
18289 case IT_INSN:
18290 close_automatic_it_block ();
18291 now_it.state = MANUAL_IT_BLOCK;
18292 break;
18293 }
18294 break;
18295
18296 case MANUAL_IT_BLOCK:
18297 {
18298 /* Check conditional suffixes. */
18299 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18300 int is_last;
18301 now_it.mask <<= 1;
18302 now_it.mask &= 0x1f;
18303 is_last = (now_it.mask == 0x10);
5a01bb1d 18304 now_it.insn_cond = TRUE;
e07e6e58
NC
18305
18306 switch (inst.it_insn_type)
18307 {
18308 case OUTSIDE_IT_INSN:
18309 inst.error = BAD_NOT_IT;
18310 return FAIL;
18311
18312 case INSIDE_IT_INSN:
18313 if (cond != inst.cond)
18314 {
18315 inst.error = BAD_IT_COND;
18316 return FAIL;
18317 }
18318 break;
18319
18320 case INSIDE_IT_LAST_INSN:
18321 case IF_INSIDE_IT_LAST_INSN:
18322 if (cond != inst.cond)
18323 {
18324 inst.error = BAD_IT_COND;
18325 return FAIL;
18326 }
18327 if (!is_last)
18328 {
18329 inst.error = BAD_BRANCH;
18330 return FAIL;
18331 }
18332 break;
18333
18334 case NEUTRAL_IT_INSN:
18335 /* The BKPT instruction is unconditional even in an IT block. */
18336 break;
18337
18338 case IT_INSN:
18339 inst.error = BAD_IT_IT;
18340 return FAIL;
18341 }
18342 }
18343 break;
18344 }
18345
18346 return SUCCESS;
18347}
18348
5a01bb1d
MGD
18349struct depr_insn_mask
18350{
18351 unsigned long pattern;
18352 unsigned long mask;
18353 const char* description;
18354};
18355
18356/* List of 16-bit instruction patterns deprecated in an IT block in
18357 ARMv8. */
18358static const struct depr_insn_mask depr_it_insns[] = {
18359 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18360 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18361 { 0xa000, 0xb800, N_("ADR") },
18362 { 0x4800, 0xf800, N_("Literal loads") },
18363 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18364 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18365 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18366 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18367 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18368 { 0, 0, NULL }
18369};
18370
e07e6e58
NC
18371static void
18372it_fsm_post_encode (void)
18373{
18374 int is_last;
18375
18376 if (!now_it.state_handled)
18377 handle_it_state ();
18378
5a01bb1d
MGD
18379 if (now_it.insn_cond
18380 && !now_it.warn_deprecated
18381 && warn_on_deprecated
18382 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18383 {
18384 if (inst.instruction >= 0x10000)
18385 {
5c3696f8 18386 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18387 "deprecated in ARMv8"));
18388 now_it.warn_deprecated = TRUE;
18389 }
18390 else
18391 {
18392 const struct depr_insn_mask *p = depr_it_insns;
18393
18394 while (p->mask != 0)
18395 {
18396 if ((inst.instruction & p->mask) == p->pattern)
18397 {
5c3696f8 18398 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18399 "of the following class are deprecated in ARMv8: "
18400 "%s"), p->description);
18401 now_it.warn_deprecated = TRUE;
18402 break;
18403 }
18404
18405 ++p;
18406 }
18407 }
18408
18409 if (now_it.block_length > 1)
18410 {
5c3696f8 18411 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18412 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18413 now_it.warn_deprecated = TRUE;
18414 }
18415 }
18416
e07e6e58
NC
18417 is_last = (now_it.mask == 0x10);
18418 if (is_last)
18419 {
18420 now_it.state = OUTSIDE_IT_BLOCK;
18421 now_it.mask = 0;
18422 }
18423}
18424
18425static void
18426force_automatic_it_block_close (void)
18427{
18428 if (now_it.state == AUTOMATIC_IT_BLOCK)
18429 {
18430 close_automatic_it_block ();
18431 now_it.state = OUTSIDE_IT_BLOCK;
18432 now_it.mask = 0;
18433 }
18434}
18435
18436static int
18437in_it_block (void)
18438{
18439 if (!now_it.state_handled)
18440 handle_it_state ();
18441
18442 return now_it.state != OUTSIDE_IT_BLOCK;
18443}
18444
ff8646ee
TP
18445/* Whether OPCODE only has T32 encoding. Since this function is only used by
18446 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18447 here, hence the "known" in the function name. */
fc289b0a
TP
18448
18449static bfd_boolean
ff8646ee 18450known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18451{
18452 /* Original Thumb-1 wide instruction. */
18453 if (opcode->tencode == do_t_blx
18454 || opcode->tencode == do_t_branch23
18455 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18456 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18457 return TRUE;
18458
16a1fa25
TP
18459 /* Wide-only instruction added to ARMv8-M Baseline. */
18460 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18461 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18462 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18463 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18464 return TRUE;
18465
18466 return FALSE;
18467}
18468
18469/* Whether wide instruction variant can be used if available for a valid OPCODE
18470 in ARCH. */
18471
18472static bfd_boolean
18473t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18474{
18475 if (known_t32_only_insn (opcode))
18476 return TRUE;
18477
18478 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18479 of variant T3 of B.W is checked in do_t_branch. */
18480 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18481 && opcode->tencode == do_t_branch)
18482 return TRUE;
18483
bada4342
JW
18484 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18485 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18486 && opcode->tencode == do_t_mov_cmp
18487 /* Make sure CMP instruction is not affected. */
18488 && opcode->aencode == do_mov)
18489 return TRUE;
18490
ff8646ee
TP
18491 /* Wide instruction variants of all instructions with narrow *and* wide
18492 variants become available with ARMv6t2. Other opcodes are either
18493 narrow-only or wide-only and are thus available if OPCODE is valid. */
18494 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18495 return TRUE;
18496
18497 /* OPCODE with narrow only instruction variant or wide variant not
18498 available. */
fc289b0a
TP
18499 return FALSE;
18500}
18501
c19d1205
ZW
18502void
18503md_assemble (char *str)
b99bd4ef 18504{
c19d1205
ZW
18505 char *p = str;
18506 const struct asm_opcode * opcode;
b99bd4ef 18507
c19d1205
ZW
18508 /* Align the previous label if needed. */
18509 if (last_label_seen != NULL)
b99bd4ef 18510 {
c19d1205
ZW
18511 symbol_set_frag (last_label_seen, frag_now);
18512 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18513 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18514 }
18515
c19d1205
ZW
18516 memset (&inst, '\0', sizeof (inst));
18517 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18518
c19d1205
ZW
18519 opcode = opcode_lookup (&p);
18520 if (!opcode)
b99bd4ef 18521 {
c19d1205 18522 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18523 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18524 if (! create_register_alias (str, p)
477330fc 18525 && ! create_neon_reg_alias (str, p))
c19d1205 18526 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18527
b99bd4ef
NC
18528 return;
18529 }
18530
278df34e 18531 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18532 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18533
037e8744
JB
18534 /* The value which unconditional instructions should have in place of the
18535 condition field. */
18536 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18537
c19d1205 18538 if (thumb_mode)
b99bd4ef 18539 {
e74cfd16 18540 arm_feature_set variant;
8f06b2d8
PB
18541
18542 variant = cpu_variant;
18543 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18544 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18545 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18546 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18547 if (!opcode->tvariant
18548 || (thumb_mode == 1
18549 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18550 {
173205ca
TP
18551 if (opcode->tencode == do_t_swi)
18552 as_bad (_("SVC is not permitted on this architecture"));
18553 else
18554 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18555 return;
18556 }
c19d1205
ZW
18557 if (inst.cond != COND_ALWAYS && !unified_syntax
18558 && opcode->tencode != do_t_branch)
b99bd4ef 18559 {
c19d1205 18560 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18561 return;
18562 }
18563
fc289b0a
TP
18564 /* Two things are addressed here:
18565 1) Implicit require narrow instructions on Thumb-1.
18566 This avoids relaxation accidentally introducing Thumb-2
18567 instructions.
18568 2) Reject wide instructions in non Thumb-2 cores.
18569
18570 Only instructions with narrow and wide variants need to be handled
18571 but selecting all non wide-only instructions is easier. */
18572 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18573 && !t32_insn_ok (variant, opcode))
076d447c 18574 {
fc289b0a
TP
18575 if (inst.size_req == 0)
18576 inst.size_req = 2;
18577 else if (inst.size_req == 4)
752d5da4 18578 {
ff8646ee
TP
18579 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18580 as_bad (_("selected processor does not support 32bit wide "
18581 "variant of instruction `%s'"), str);
18582 else
18583 as_bad (_("selected processor does not support `%s' in "
18584 "Thumb-2 mode"), str);
fc289b0a 18585 return;
752d5da4 18586 }
076d447c
PB
18587 }
18588
c19d1205
ZW
18589 inst.instruction = opcode->tvalue;
18590
5be8be5d 18591 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18592 {
18593 /* Prepare the it_insn_type for those encodings that don't set
18594 it. */
18595 it_fsm_pre_encode ();
c19d1205 18596
477330fc 18597 opcode->tencode ();
e07e6e58 18598
477330fc
RM
18599 it_fsm_post_encode ();
18600 }
e27ec89e 18601
0110f2b8 18602 if (!(inst.error || inst.relax))
b99bd4ef 18603 {
9c2799c2 18604 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18605 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18606 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18607 {
c19d1205 18608 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18609 return;
18610 }
18611 }
076d447c
PB
18612
18613 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18614 instruction. */
9c2799c2 18615 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18616
e74cfd16
PB
18617 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18618 *opcode->tvariant);
ee065d83 18619 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18620 set those bits when Thumb-2 32-bit instructions are seen. The impact
18621 of relaxable instructions will be considered later after we finish all
18622 relaxation. */
ff8646ee
TP
18623 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18624 variant = arm_arch_none;
18625 else
18626 variant = cpu_variant;
18627 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18628 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18629 arm_ext_v6t2);
cd000bff 18630
88714cb8
DG
18631 check_neon_suffixes;
18632
cd000bff 18633 if (!inst.error)
c877a2f2
NC
18634 {
18635 mapping_state (MAP_THUMB);
18636 }
c19d1205 18637 }
3e9e4fcf 18638 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18639 {
845b51d6
PB
18640 bfd_boolean is_bx;
18641
18642 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18643 is_bx = (opcode->aencode == do_bx);
18644
c19d1205 18645 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18646 if (!(is_bx && fix_v4bx)
18647 && !(opcode->avariant &&
18648 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18649 {
84b52b66 18650 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18651 return;
b99bd4ef 18652 }
c19d1205 18653 if (inst.size_req)
b99bd4ef 18654 {
c19d1205
ZW
18655 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18656 return;
b99bd4ef
NC
18657 }
18658
c19d1205
ZW
18659 inst.instruction = opcode->avalue;
18660 if (opcode->tag == OT_unconditionalF)
eff0bc54 18661 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18662 else
18663 inst.instruction |= inst.cond << 28;
18664 inst.size = INSN_SIZE;
5be8be5d 18665 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18666 {
18667 it_fsm_pre_encode ();
18668 opcode->aencode ();
18669 it_fsm_post_encode ();
18670 }
ee065d83 18671 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18672 on a hypothetical non-thumb v5 core. */
845b51d6 18673 if (is_bx)
e74cfd16 18674 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18675 else
e74cfd16
PB
18676 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18677 *opcode->avariant);
88714cb8
DG
18678
18679 check_neon_suffixes;
18680
cd000bff 18681 if (!inst.error)
c877a2f2
NC
18682 {
18683 mapping_state (MAP_ARM);
18684 }
b99bd4ef 18685 }
3e9e4fcf
JB
18686 else
18687 {
18688 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18689 "-- `%s'"), str);
18690 return;
18691 }
c19d1205
ZW
18692 output_inst (str);
18693}
b99bd4ef 18694
e07e6e58
NC
18695static void
18696check_it_blocks_finished (void)
18697{
18698#ifdef OBJ_ELF
18699 asection *sect;
18700
18701 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18702 if (seg_info (sect)->tc_segment_info_data.current_it.state
18703 == MANUAL_IT_BLOCK)
18704 {
18705 as_warn (_("section '%s' finished with an open IT block."),
18706 sect->name);
18707 }
18708#else
18709 if (now_it.state == MANUAL_IT_BLOCK)
18710 as_warn (_("file finished with an open IT block."));
18711#endif
18712}
18713
c19d1205
ZW
18714/* Various frobbings of labels and their addresses. */
18715
18716void
18717arm_start_line_hook (void)
18718{
18719 last_label_seen = NULL;
b99bd4ef
NC
18720}
18721
c19d1205
ZW
18722void
18723arm_frob_label (symbolS * sym)
b99bd4ef 18724{
c19d1205 18725 last_label_seen = sym;
b99bd4ef 18726
c19d1205 18727 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18728
c19d1205
ZW
18729#if defined OBJ_COFF || defined OBJ_ELF
18730 ARM_SET_INTERWORK (sym, support_interwork);
18731#endif
b99bd4ef 18732
e07e6e58
NC
18733 force_automatic_it_block_close ();
18734
5f4273c7 18735 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18736 as Thumb functions. This is because these labels, whilst
18737 they exist inside Thumb code, are not the entry points for
18738 possible ARM->Thumb calls. Also, these labels can be used
18739 as part of a computed goto or switch statement. eg gcc
18740 can generate code that looks like this:
b99bd4ef 18741
c19d1205
ZW
18742 ldr r2, [pc, .Laaa]
18743 lsl r3, r3, #2
18744 ldr r2, [r3, r2]
18745 mov pc, r2
b99bd4ef 18746
c19d1205
ZW
18747 .Lbbb: .word .Lxxx
18748 .Lccc: .word .Lyyy
18749 ..etc...
18750 .Laaa: .word Lbbb
b99bd4ef 18751
c19d1205
ZW
18752 The first instruction loads the address of the jump table.
18753 The second instruction converts a table index into a byte offset.
18754 The third instruction gets the jump address out of the table.
18755 The fourth instruction performs the jump.
b99bd4ef 18756
c19d1205
ZW
18757 If the address stored at .Laaa is that of a symbol which has the
18758 Thumb_Func bit set, then the linker will arrange for this address
18759 to have the bottom bit set, which in turn would mean that the
18760 address computation performed by the third instruction would end
18761 up with the bottom bit set. Since the ARM is capable of unaligned
18762 word loads, the instruction would then load the incorrect address
18763 out of the jump table, and chaos would ensue. */
18764 if (label_is_thumb_function_name
18765 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18766 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18767 {
c19d1205
ZW
18768 /* When the address of a Thumb function is taken the bottom
18769 bit of that address should be set. This will allow
18770 interworking between Arm and Thumb functions to work
18771 correctly. */
b99bd4ef 18772
c19d1205 18773 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18774
c19d1205 18775 label_is_thumb_function_name = FALSE;
b99bd4ef 18776 }
07a53e5c 18777
07a53e5c 18778 dwarf2_emit_label (sym);
b99bd4ef
NC
18779}
18780
c921be7d 18781bfd_boolean
c19d1205 18782arm_data_in_code (void)
b99bd4ef 18783{
c19d1205 18784 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18785 {
c19d1205
ZW
18786 *input_line_pointer = '/';
18787 input_line_pointer += 5;
18788 *input_line_pointer = 0;
c921be7d 18789 return TRUE;
b99bd4ef
NC
18790 }
18791
c921be7d 18792 return FALSE;
b99bd4ef
NC
18793}
18794
c19d1205
ZW
18795char *
18796arm_canonicalize_symbol_name (char * name)
b99bd4ef 18797{
c19d1205 18798 int len;
b99bd4ef 18799
c19d1205
ZW
18800 if (thumb_mode && (len = strlen (name)) > 5
18801 && streq (name + len - 5, "/data"))
18802 *(name + len - 5) = 0;
b99bd4ef 18803
c19d1205 18804 return name;
b99bd4ef 18805}
c19d1205
ZW
18806\f
18807/* Table of all register names defined by default. The user can
18808 define additional names with .req. Note that all register names
18809 should appear in both upper and lowercase variants. Some registers
18810 also have mixed-case names. */
b99bd4ef 18811
dcbf9037 18812#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18813#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18814#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18815#define REGSET(p,t) \
18816 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18817 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18818 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18819 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18820#define REGSETH(p,t) \
18821 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18822 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18823 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18824 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18825#define REGSET2(p,t) \
18826 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18827 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18828 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18829 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18830#define SPLRBANK(base,bank,t) \
18831 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18832 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18833 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18834 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18835 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18836 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18837
c19d1205 18838static const struct reg_entry reg_names[] =
7ed4c4c5 18839{
c19d1205
ZW
18840 /* ARM integer registers. */
18841 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18842
c19d1205
ZW
18843 /* ATPCS synonyms. */
18844 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18845 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18846 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18847
c19d1205
ZW
18848 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18849 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18850 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18851
c19d1205
ZW
18852 /* Well-known aliases. */
18853 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18854 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18855
18856 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18857 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18858
18859 /* Coprocessor numbers. */
18860 REGSET(p, CP), REGSET(P, CP),
18861
18862 /* Coprocessor register numbers. The "cr" variants are for backward
18863 compatibility. */
18864 REGSET(c, CN), REGSET(C, CN),
18865 REGSET(cr, CN), REGSET(CR, CN),
18866
90ec0d68
MGD
18867 /* ARM banked registers. */
18868 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18869 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18870 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18871 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18872 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18873 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18874 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18875
18876 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18877 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18878 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18879 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18880 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18881 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18882 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18883 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18884
18885 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18886 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18887 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18888 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18889 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18890 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18891 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18892 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18893 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18894
c19d1205
ZW
18895 /* FPA registers. */
18896 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18897 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18898
18899 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18900 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18901
18902 /* VFP SP registers. */
5287ad62
JB
18903 REGSET(s,VFS), REGSET(S,VFS),
18904 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18905
18906 /* VFP DP Registers. */
5287ad62
JB
18907 REGSET(d,VFD), REGSET(D,VFD),
18908 /* Extra Neon DP registers. */
18909 REGSETH(d,VFD), REGSETH(D,VFD),
18910
18911 /* Neon QP registers. */
18912 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18913
18914 /* VFP control registers. */
18915 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18916 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18917 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18918 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18919 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18920 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 18921 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
18922
18923 /* Maverick DSP coprocessor registers. */
18924 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18925 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18926
18927 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18928 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18929 REGDEF(dspsc,0,DSPSC),
18930
18931 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18932 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18933 REGDEF(DSPSC,0,DSPSC),
18934
18935 /* iWMMXt data registers - p0, c0-15. */
18936 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18937
18938 /* iWMMXt control registers - p1, c0-3. */
18939 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18940 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18941 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18942 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18943
18944 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18945 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18946 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18947 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18948 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18949
18950 /* XScale accumulator registers. */
18951 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18952};
18953#undef REGDEF
18954#undef REGNUM
18955#undef REGSET
7ed4c4c5 18956
c19d1205
ZW
18957/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18958 within psr_required_here. */
18959static const struct asm_psr psrs[] =
18960{
18961 /* Backward compatibility notation. Note that "all" is no longer
18962 truly all possible PSR bits. */
18963 {"all", PSR_c | PSR_f},
18964 {"flg", PSR_f},
18965 {"ctl", PSR_c},
18966
18967 /* Individual flags. */
18968 {"f", PSR_f},
18969 {"c", PSR_c},
18970 {"x", PSR_x},
18971 {"s", PSR_s},
59b42a0d 18972
c19d1205
ZW
18973 /* Combinations of flags. */
18974 {"fs", PSR_f | PSR_s},
18975 {"fx", PSR_f | PSR_x},
18976 {"fc", PSR_f | PSR_c},
18977 {"sf", PSR_s | PSR_f},
18978 {"sx", PSR_s | PSR_x},
18979 {"sc", PSR_s | PSR_c},
18980 {"xf", PSR_x | PSR_f},
18981 {"xs", PSR_x | PSR_s},
18982 {"xc", PSR_x | PSR_c},
18983 {"cf", PSR_c | PSR_f},
18984 {"cs", PSR_c | PSR_s},
18985 {"cx", PSR_c | PSR_x},
18986 {"fsx", PSR_f | PSR_s | PSR_x},
18987 {"fsc", PSR_f | PSR_s | PSR_c},
18988 {"fxs", PSR_f | PSR_x | PSR_s},
18989 {"fxc", PSR_f | PSR_x | PSR_c},
18990 {"fcs", PSR_f | PSR_c | PSR_s},
18991 {"fcx", PSR_f | PSR_c | PSR_x},
18992 {"sfx", PSR_s | PSR_f | PSR_x},
18993 {"sfc", PSR_s | PSR_f | PSR_c},
18994 {"sxf", PSR_s | PSR_x | PSR_f},
18995 {"sxc", PSR_s | PSR_x | PSR_c},
18996 {"scf", PSR_s | PSR_c | PSR_f},
18997 {"scx", PSR_s | PSR_c | PSR_x},
18998 {"xfs", PSR_x | PSR_f | PSR_s},
18999 {"xfc", PSR_x | PSR_f | PSR_c},
19000 {"xsf", PSR_x | PSR_s | PSR_f},
19001 {"xsc", PSR_x | PSR_s | PSR_c},
19002 {"xcf", PSR_x | PSR_c | PSR_f},
19003 {"xcs", PSR_x | PSR_c | PSR_s},
19004 {"cfs", PSR_c | PSR_f | PSR_s},
19005 {"cfx", PSR_c | PSR_f | PSR_x},
19006 {"csf", PSR_c | PSR_s | PSR_f},
19007 {"csx", PSR_c | PSR_s | PSR_x},
19008 {"cxf", PSR_c | PSR_x | PSR_f},
19009 {"cxs", PSR_c | PSR_x | PSR_s},
19010 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19011 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19012 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19013 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19014 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19015 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19016 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19017 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19018 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19019 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19020 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19021 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19022 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19023 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19024 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19025 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19026 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19027 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19028 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19029 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19030 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19031 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19032 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19033 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19034};
19035
62b3e311
PB
19036/* Table of V7M psr names. */
19037static const struct asm_psr v7m_psrs[] =
19038{
1a336194
TP
19039 {"apsr", 0x0 }, {"APSR", 0x0 },
19040 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19041 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19042 {"psr", 0x3 }, {"PSR", 0x3 },
19043 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19044 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19045 {"epsr", 0x6 }, {"EPSR", 0x6 },
19046 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19047 {"msp", 0x8 }, {"MSP", 0x8 },
19048 {"psp", 0x9 }, {"PSP", 0x9 },
19049 {"msplim", 0xa }, {"MSPLIM", 0xa },
19050 {"psplim", 0xb }, {"PSPLIM", 0xb },
19051 {"primask", 0x10}, {"PRIMASK", 0x10},
19052 {"basepri", 0x11}, {"BASEPRI", 0x11},
19053 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19054 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19055 {"control", 0x14}, {"CONTROL", 0x14},
19056 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19057 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19058 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19059 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19060 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19061 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19062 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19063 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19064 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19065};
19066
c19d1205
ZW
19067/* Table of all shift-in-operand names. */
19068static const struct asm_shift_name shift_names [] =
b99bd4ef 19069{
c19d1205
ZW
19070 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19071 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19072 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19073 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19074 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19075 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19076};
b99bd4ef 19077
c19d1205
ZW
19078/* Table of all explicit relocation names. */
19079#ifdef OBJ_ELF
19080static struct reloc_entry reloc_names[] =
19081{
19082 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19083 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19084 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19085 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19086 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19087 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19088 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19089 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19090 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19091 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19092 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19093 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19094 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19095 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19096 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19097 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19098 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19099 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19100};
19101#endif
b99bd4ef 19102
c19d1205
ZW
19103/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19104static const struct asm_cond conds[] =
19105{
19106 {"eq", 0x0},
19107 {"ne", 0x1},
19108 {"cs", 0x2}, {"hs", 0x2},
19109 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19110 {"mi", 0x4},
19111 {"pl", 0x5},
19112 {"vs", 0x6},
19113 {"vc", 0x7},
19114 {"hi", 0x8},
19115 {"ls", 0x9},
19116 {"ge", 0xa},
19117 {"lt", 0xb},
19118 {"gt", 0xc},
19119 {"le", 0xd},
19120 {"al", 0xe}
19121};
bfae80f2 19122
e797f7e0 19123#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19124 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19125 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19126
62b3e311
PB
19127static struct asm_barrier_opt barrier_opt_names[] =
19128{
e797f7e0
MGD
19129 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19130 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19131 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19132 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19133 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19134 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19135 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19136 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19137 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19138 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19139 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19140 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19141 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19142 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19143 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19144 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19145};
19146
e797f7e0
MGD
19147#undef UL_BARRIER
19148
c19d1205
ZW
19149/* Table of ARM-format instructions. */
19150
19151/* Macros for gluing together operand strings. N.B. In all cases
19152 other than OPS0, the trailing OP_stop comes from default
19153 zero-initialization of the unspecified elements of the array. */
19154#define OPS0() { OP_stop, }
19155#define OPS1(a) { OP_##a, }
19156#define OPS2(a,b) { OP_##a,OP_##b, }
19157#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19158#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19159#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19160#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19161
5be8be5d
DG
19162/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19163 This is useful when mixing operands for ARM and THUMB, i.e. using the
19164 MIX_ARM_THUMB_OPERANDS macro.
19165 In order to use these macros, prefix the number of operands with _
19166 e.g. _3. */
19167#define OPS_1(a) { a, }
19168#define OPS_2(a,b) { a,b, }
19169#define OPS_3(a,b,c) { a,b,c, }
19170#define OPS_4(a,b,c,d) { a,b,c,d, }
19171#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19172#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19173
c19d1205
ZW
19174/* These macros abstract out the exact format of the mnemonic table and
19175 save some repeated characters. */
19176
19177/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19178#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19179 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19180 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19181
19182/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19183 a T_MNEM_xyz enumerator. */
19184#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19185 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19186#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19187 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19188
19189/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19190 infix after the third character. */
19191#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19192 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19193 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19194#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19195 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19196 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19197#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19198 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19199#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19200 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19201#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19202 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19203#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19204 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19205
c19d1205 19206/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19207 field is still 0xE. Many of the Thumb variants can be executed
19208 conditionally, so this is checked separately. */
c19d1205 19209#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19210 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19211 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19212
dd5181d5
KT
19213/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19214 Used by mnemonics that have very minimal differences in the encoding for
19215 ARM and Thumb variants and can be handled in a common function. */
19216#define TUEc(mnem, op, top, nops, ops, en) \
19217 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19218 THUMB_VARIANT, do_##en, do_##en }
19219
c19d1205
ZW
19220/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19221 condition code field. */
19222#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19223 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19224 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19225
19226/* ARM-only variants of all the above. */
6a86118a 19227#define CE(mnem, op, nops, ops, ae) \
21d799b5 19228 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19229
19230#define C3(mnem, op, nops, ops, ae) \
19231 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19232
e3cb604e
PB
19233/* Legacy mnemonics that always have conditional infix after the third
19234 character. */
19235#define CL(mnem, op, nops, ops, ae) \
21d799b5 19236 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19237 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19238
8f06b2d8
PB
19239/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19240#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19241 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19242
e3cb604e
PB
19243/* Legacy coprocessor instructions where conditional infix and conditional
19244 suffix are ambiguous. For consistency this includes all FPA instructions,
19245 not just the potentially ambiguous ones. */
19246#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19247 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19248 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19249
19250/* Coprocessor, takes either a suffix or a position-3 infix
19251 (for an FPA corner case). */
19252#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19253 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19254 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19255
6a86118a 19256#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19257 { m1 #m2 m3, OPS##nops ops, \
19258 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19259 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19260
19261#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19262 xCM_ (m1, , m2, op, nops, ops, ae), \
19263 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19264 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19265 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19266 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19267 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19268 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19269 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19270 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19271 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19272 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19273 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19274 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19275 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19276 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19277 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19278 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19279 xCM_ (m1, le, m2, op, nops, ops, ae), \
19280 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19281
19282#define UE(mnem, op, nops, ops, ae) \
19283 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19284
19285#define UF(mnem, op, nops, ops, ae) \
19286 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19287
5287ad62
JB
19288/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19289 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19290 use the same encoding function for each. */
19291#define NUF(mnem, op, nops, ops, enc) \
19292 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19293 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19294
19295/* Neon data processing, version which indirects through neon_enc_tab for
19296 the various overloaded versions of opcodes. */
19297#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19298 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19299 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19300
19301/* Neon insn with conditional suffix for the ARM version, non-overloaded
19302 version. */
037e8744
JB
19303#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19304 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19305 THUMB_VARIANT, do_##enc, do_##enc }
19306
037e8744 19307#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19308 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19309
19310#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19311 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19312
5287ad62 19313/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19314#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19315 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19316 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19317
037e8744 19318#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19319 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19320
19321#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19322 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19323
c19d1205
ZW
19324#define do_0 0
19325
c19d1205 19326static const struct asm_opcode insns[] =
bfae80f2 19327{
74db7efb
NC
19328#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19329#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19330 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19331 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19332 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19333 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19334 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19335 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19336 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19337 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19338 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19339 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19340 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19341 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19342 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19343 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19344 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19345 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19346
19347 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19348 for setting PSR flag bits. They are obsolete in V6 and do not
19349 have Thumb equivalents. */
21d799b5
NC
19350 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19351 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19352 CL("tstp", 110f000, 2, (RR, SH), cmp),
19353 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19354 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19355 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19356 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19357 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19358 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19359
19360 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19361 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19362 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19363 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19364
19365 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19366 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19367 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19368 OP_RRnpc),
19369 OP_ADDRGLDR),ldst, t_ldst),
19370 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19371
19372 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19373 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19374 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19375 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19376 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19377 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19378
21d799b5
NC
19379 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19380 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19381
c19d1205 19382 /* Pseudo ops. */
21d799b5 19383 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19384 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19385 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19386 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19387
19388 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19389 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19390 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19391 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19392 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19393 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19394 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19395 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19396 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19397 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19398 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19399 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19400 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19401
16a4cf17 19402 /* These may simplify to neg. */
21d799b5
NC
19403 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19404 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19405
173205ca
TP
19406#undef THUMB_VARIANT
19407#define THUMB_VARIANT & arm_ext_os
19408
19409 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19410 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19411
c921be7d
NC
19412#undef THUMB_VARIANT
19413#define THUMB_VARIANT & arm_ext_v6
19414
21d799b5 19415 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19416
19417 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19418#undef THUMB_VARIANT
19419#define THUMB_VARIANT & arm_ext_v6t2
19420
21d799b5
NC
19421 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19422 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19423 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19424
5be8be5d
DG
19425 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19426 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19427 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19428 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19429
21d799b5
NC
19430 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19431 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19432
21d799b5
NC
19433 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19434 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19435
19436 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19437 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19438 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19439
19440 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19441 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19442 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19443 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19444 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19445 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19446 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19447 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19448
c921be7d
NC
19449#undef ARM_VARIANT
19450#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19451#undef THUMB_VARIANT
19452#define THUMB_VARIANT & arm_ext_v4t
19453
21d799b5
NC
19454 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19455 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19456
c921be7d
NC
19457#undef THUMB_VARIANT
19458#define THUMB_VARIANT & arm_ext_v6t2
19459
21d799b5 19460 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19461 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19462
19463 /* Generic coprocessor instructions. */
21d799b5
NC
19464 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19465 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19466 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19467 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19468 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19469 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19470 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19471
c921be7d
NC
19472#undef ARM_VARIANT
19473#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19474
21d799b5 19475 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19476 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19477
c921be7d
NC
19478#undef ARM_VARIANT
19479#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19480#undef THUMB_VARIANT
19481#define THUMB_VARIANT & arm_ext_msr
19482
d2cd1205
JB
19483 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19484 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19485
c921be7d
NC
19486#undef ARM_VARIANT
19487#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19488#undef THUMB_VARIANT
19489#define THUMB_VARIANT & arm_ext_v6t2
19490
21d799b5
NC
19491 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19492 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19493 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19494 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19495 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19496 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19497 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19498 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19499
c921be7d
NC
19500#undef ARM_VARIANT
19501#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19502#undef THUMB_VARIANT
19503#define THUMB_VARIANT & arm_ext_v4t
19504
5be8be5d
DG
19505 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19506 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19507 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19508 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19509 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19510 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19511
c921be7d
NC
19512#undef ARM_VARIANT
19513#define ARM_VARIANT & arm_ext_v4t_5
19514
c19d1205
ZW
19515 /* ARM Architecture 4T. */
19516 /* Note: bx (and blx) are required on V5, even if the processor does
19517 not support Thumb. */
21d799b5 19518 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19519
c921be7d
NC
19520#undef ARM_VARIANT
19521#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19522#undef THUMB_VARIANT
19523#define THUMB_VARIANT & arm_ext_v5t
19524
c19d1205
ZW
19525 /* Note: blx has 2 variants; the .value coded here is for
19526 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19527 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19528 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19529
c921be7d
NC
19530#undef THUMB_VARIANT
19531#define THUMB_VARIANT & arm_ext_v6t2
19532
21d799b5
NC
19533 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19534 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19535 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19536 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19537 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19538 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19539 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19540 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19541
c921be7d 19542#undef ARM_VARIANT
74db7efb
NC
19543#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19544#undef THUMB_VARIANT
19545#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19546
21d799b5
NC
19547 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19548 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19549 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19550 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19551
21d799b5
NC
19552 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19553 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19554
21d799b5
NC
19555 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19556 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19557 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19558 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19559
21d799b5
NC
19560 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19561 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19562 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19563 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19564
21d799b5
NC
19565 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19566 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19567
03ee1b7f
NC
19568 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19569 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19570 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19571 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19572
c921be7d 19573#undef ARM_VARIANT
74db7efb
NC
19574#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19575#undef THUMB_VARIANT
19576#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19577
21d799b5 19578 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19579 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19580 ldrd, t_ldstd),
19581 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19582 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19583
21d799b5
NC
19584 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19585 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19586
c921be7d
NC
19587#undef ARM_VARIANT
19588#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19589
21d799b5 19590 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19591
c921be7d
NC
19592#undef ARM_VARIANT
19593#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19594#undef THUMB_VARIANT
19595#define THUMB_VARIANT & arm_ext_v6
19596
21d799b5
NC
19597 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19598 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19599 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19600 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19601 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19602 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19603 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19604 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19605 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19606 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19607
c921be7d 19608#undef THUMB_VARIANT
ff8646ee 19609#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19610
5be8be5d
DG
19611 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19612 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19613 strex, t_strex),
ff8646ee
TP
19614#undef THUMB_VARIANT
19615#define THUMB_VARIANT & arm_ext_v6t2
19616
21d799b5
NC
19617 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19618 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19619
21d799b5
NC
19620 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19621 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19622
9e3c6df6 19623/* ARM V6 not included in V7M. */
c921be7d
NC
19624#undef THUMB_VARIANT
19625#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19626 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19627 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19628 UF(rfeib, 9900a00, 1, (RRw), rfe),
19629 UF(rfeda, 8100a00, 1, (RRw), rfe),
19630 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19631 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19632 UF(rfefa, 8100a00, 1, (RRw), rfe),
19633 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19634 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19635 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19636 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19637 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19638 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19639 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19640 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19641 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19642 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19643 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19644 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19645
9e3c6df6
PB
19646/* ARM V6 not included in V7M (eg. integer SIMD). */
19647#undef THUMB_VARIANT
19648#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19649 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19650 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19651 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19652 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19653 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19654 /* Old name for QASX. */
74db7efb 19655 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19656 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19657 /* Old name for QSAX. */
74db7efb 19658 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19659 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19660 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19661 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19662 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19663 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19664 /* Old name for SASX. */
74db7efb 19665 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19666 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19667 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19668 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19669 /* Old name for SHASX. */
21d799b5 19670 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19671 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19672 /* Old name for SHSAX. */
21d799b5
NC
19673 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19674 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19675 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19676 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19677 /* Old name for SSAX. */
74db7efb 19678 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19679 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19680 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19681 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19682 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19683 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19684 /* Old name for UASX. */
74db7efb 19685 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19686 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19687 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19688 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19689 /* Old name for UHASX. */
21d799b5
NC
19690 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19691 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19692 /* Old name for UHSAX. */
21d799b5
NC
19693 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19694 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19695 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19696 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19697 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19698 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19699 /* Old name for UQASX. */
21d799b5
NC
19700 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19701 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19702 /* Old name for UQSAX. */
21d799b5
NC
19703 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19704 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19705 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19706 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19707 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19708 /* Old name for USAX. */
74db7efb 19709 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19710 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19711 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19712 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19713 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19714 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19715 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19716 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19717 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19718 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19719 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19720 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19721 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19722 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19723 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19724 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19725 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19726 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19727 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19728 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19729 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19730 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19731 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19732 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19733 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19734 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19735 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19736 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19737 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19738 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19739 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19740 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19741 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19742 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19743
c921be7d
NC
19744#undef ARM_VARIANT
19745#define ARM_VARIANT & arm_ext_v6k
19746#undef THUMB_VARIANT
19747#define THUMB_VARIANT & arm_ext_v6k
19748
21d799b5
NC
19749 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19750 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19751 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19752 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19753
c921be7d
NC
19754#undef THUMB_VARIANT
19755#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19756 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19757 ldrexd, t_ldrexd),
19758 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19759 RRnpcb), strexd, t_strexd),
ebdca51a 19760
c921be7d 19761#undef THUMB_VARIANT
ff8646ee 19762#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19763 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19764 rd_rn, rd_rn),
19765 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19766 rd_rn, rd_rn),
19767 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19768 strex, t_strexbh),
5be8be5d 19769 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19770 strex, t_strexbh),
21d799b5 19771 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19772
c921be7d 19773#undef ARM_VARIANT
f4c65163 19774#define ARM_VARIANT & arm_ext_sec
74db7efb 19775#undef THUMB_VARIANT
f4c65163 19776#define THUMB_VARIANT & arm_ext_sec
c921be7d 19777
21d799b5 19778 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19779
90ec0d68
MGD
19780#undef ARM_VARIANT
19781#define ARM_VARIANT & arm_ext_virt
19782#undef THUMB_VARIANT
19783#define THUMB_VARIANT & arm_ext_virt
19784
19785 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19786 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19787
ddfded2f
MW
19788#undef ARM_VARIANT
19789#define ARM_VARIANT & arm_ext_pan
19790#undef THUMB_VARIANT
19791#define THUMB_VARIANT & arm_ext_pan
19792
19793 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19794
c921be7d 19795#undef ARM_VARIANT
74db7efb 19796#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19797#undef THUMB_VARIANT
19798#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19799
21d799b5
NC
19800 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19801 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19802 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19803 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19804
21d799b5 19805 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19806 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19807
5be8be5d
DG
19808 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19809 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19810 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19811 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19812
ff8646ee
TP
19813#undef THUMB_VARIANT
19814#define THUMB_VARIANT & arm_ext_v6t2_v8m
19815 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19816 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19817
bf3eeda7 19818 /* Thumb-only instructions. */
74db7efb 19819#undef ARM_VARIANT
bf3eeda7
NS
19820#define ARM_VARIANT NULL
19821 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19822 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19823
19824 /* ARM does not really have an IT instruction, so always allow it.
19825 The opcode is copied from Thumb in order to allow warnings in
19826 -mimplicit-it=[never | arm] modes. */
19827#undef ARM_VARIANT
19828#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19829#undef THUMB_VARIANT
19830#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19831
21d799b5
NC
19832 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19833 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19834 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19835 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19836 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19837 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19838 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19839 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19840 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19841 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19842 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19843 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19844 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19845 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19846 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19847 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19848 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19849 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19850
92e90b6e 19851 /* Thumb2 only instructions. */
c921be7d
NC
19852#undef ARM_VARIANT
19853#define ARM_VARIANT NULL
92e90b6e 19854
21d799b5
NC
19855 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19856 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19857 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19858 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19859 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19860 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19861
eea54501
MGD
19862 /* Hardware division instructions. */
19863#undef ARM_VARIANT
19864#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19865#undef THUMB_VARIANT
19866#define THUMB_VARIANT & arm_ext_div
19867
eea54501
MGD
19868 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19869 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19870
7e806470 19871 /* ARM V6M/V7 instructions. */
c921be7d
NC
19872#undef ARM_VARIANT
19873#define ARM_VARIANT & arm_ext_barrier
19874#undef THUMB_VARIANT
19875#define THUMB_VARIANT & arm_ext_barrier
19876
ccb84d65
JB
19877 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19878 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19879 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19880
62b3e311 19881 /* ARM V7 instructions. */
c921be7d
NC
19882#undef ARM_VARIANT
19883#define ARM_VARIANT & arm_ext_v7
19884#undef THUMB_VARIANT
19885#define THUMB_VARIANT & arm_ext_v7
19886
21d799b5
NC
19887 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19888 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19889
74db7efb 19890#undef ARM_VARIANT
60e5ef9f 19891#define ARM_VARIANT & arm_ext_mp
74db7efb 19892#undef THUMB_VARIANT
60e5ef9f
MGD
19893#define THUMB_VARIANT & arm_ext_mp
19894
19895 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19896
53c4b28b
MGD
19897 /* AArchv8 instructions. */
19898#undef ARM_VARIANT
19899#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19900
19901/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19902#undef THUMB_VARIANT
4ed7ed8d 19903#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19904
4ed7ed8d
TP
19905 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19906 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19907 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19908 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19909 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19910 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19911 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19912 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19913 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19914 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19915 stlex, t_stlex),
4b8c8c02
RE
19916 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19917 stlex, t_stlex),
19918 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19919 stlex, t_stlex),
4ed7ed8d
TP
19920#undef THUMB_VARIANT
19921#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19922
4ed7ed8d
TP
19923 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19924 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19925 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19926 ldrexd, t_ldrexd),
19927 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19928 strexd, t_strexd),
8884b720 19929 /* ARMv8 T32 only. */
74db7efb 19930#undef ARM_VARIANT
b79f7053
MGD
19931#define ARM_VARIANT NULL
19932 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19933 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19934 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19935
33399f07
MGD
19936 /* FP for ARMv8. */
19937#undef ARM_VARIANT
a715796b 19938#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19939#undef THUMB_VARIANT
a715796b 19940#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19941
19942 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19943 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19944 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19945 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19946 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19947 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19948 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19949 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19950 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19951 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19952 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19953 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19954 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19955 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19956 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19957 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19958 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19959
91ff7894
MGD
19960 /* Crypto v1 extensions. */
19961#undef ARM_VARIANT
19962#define ARM_VARIANT & fpu_crypto_ext_armv8
19963#undef THUMB_VARIANT
19964#define THUMB_VARIANT & fpu_crypto_ext_armv8
19965
19966 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19967 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19968 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19969 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19970 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19971 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19972 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19973 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19974 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19975 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19976 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19977 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19978 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19979 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19980
dd5181d5 19981#undef ARM_VARIANT
74db7efb 19982#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19983#undef THUMB_VARIANT
19984#define THUMB_VARIANT & crc_ext_armv8
19985 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19986 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19987 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19988 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19989 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19990 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19991
105bde57
MW
19992 /* ARMv8.2 RAS extension. */
19993#undef ARM_VARIANT
4d1464f2 19994#define ARM_VARIANT & arm_ext_ras
105bde57 19995#undef THUMB_VARIANT
4d1464f2 19996#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19997 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19998
49e8a725
SN
19999#undef ARM_VARIANT
20000#define ARM_VARIANT & arm_ext_v8_3
20001#undef THUMB_VARIANT
20002#define THUMB_VARIANT & arm_ext_v8_3
20003 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20004 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20005 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20006
c604a79a
JW
20007#undef ARM_VARIANT
20008#define ARM_VARIANT & fpu_neon_ext_dotprod
20009#undef THUMB_VARIANT
20010#define THUMB_VARIANT & fpu_neon_ext_dotprod
20011 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20012 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20013
c921be7d
NC
20014#undef ARM_VARIANT
20015#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20016#undef THUMB_VARIANT
20017#define THUMB_VARIANT NULL
c921be7d 20018
21d799b5
NC
20019 cCE("wfs", e200110, 1, (RR), rd),
20020 cCE("rfs", e300110, 1, (RR), rd),
20021 cCE("wfc", e400110, 1, (RR), rd),
20022 cCE("rfc", e500110, 1, (RR), rd),
20023
20024 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20025 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20026 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20027 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20028
20029 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20030 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20031 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20032 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20033
20034 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20035 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20036 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20037 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20038 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20039 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20040 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20041 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20042 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20043 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20044 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20045 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20046
20047 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20048 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20049 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20050 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20051 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20052 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20053 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20054 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20055 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20056 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20057 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20058 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20059
20060 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20061 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20062 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20063 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20064 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20065 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20066 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20067 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20068 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20069 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20070 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20071 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20072
20073 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20074 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20075 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20076 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20077 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20078 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20079 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20080 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20081 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20082 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20083 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20084 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20085
20086 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20087 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20088 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20089 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20090 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20091 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20092 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20093 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20094 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20095 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20096 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20097 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20098
20099 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20100 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20101 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20102 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20103 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20104 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20105 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20106 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20107 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20108 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20109 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20110 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20111
20112 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20113 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20114 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20115 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20116 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20117 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20118 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20119 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20120 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20121 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20122 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20123 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20124
20125 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20126 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20127 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20128 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20129 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20130 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20131 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20132 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20133 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20134 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20135 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20136 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20137
20138 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20139 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20140 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20141 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20142 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20143 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20144 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20145 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20146 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20147 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20148 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20149 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20150
20151 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20152 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20153 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20154 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20155 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20156 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20157 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20158 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20159 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20160 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20161 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20162 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20163
20164 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20165 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20166 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20167 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20168 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20169 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20170 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20171 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20172 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20173 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20174 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20175 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20176
20177 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20178 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20179 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20180 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20181 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20182 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20183 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20184 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20185 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20186 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20187 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20188 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20189
20190 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20191 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20192 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20193 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20194 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20195 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20196 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20197 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20198 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20199 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20200 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20201 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20202
20203 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20204 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20205 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20206 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20207 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20208 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20209 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20210 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20211 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20212 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20213 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20214 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20215
20216 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20217 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20218 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20219 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20220 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20221 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20222 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20223 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20224 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20225 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20226 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20227 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20228
20229 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20230 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20231 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20232 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20233 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20234 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20235 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20236 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20237 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20238 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20239 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20240 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20241
20242 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20243 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20244 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20245 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20246 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20247 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20248 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20249 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20250 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20251 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20252 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20253 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20254
20255 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20256 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20257 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20258 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20259 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20260 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20261 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20262 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20263 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20264 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20265 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20266 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20267
20268 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20269 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20270 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20271 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20272 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20273 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20274 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20275 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20276 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20277 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20278 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20279 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20280
20281 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20282 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20283 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20284 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20285 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20286 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20287 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20288 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20289 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20290 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20291 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20292 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20293
20294 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20295 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20296 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20297 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20298 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20299 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20300 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20301 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20302 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20303 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20304 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20305 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20306
20307 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20308 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20309 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20310 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20311 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20312 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20313 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20314 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20315 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20316 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20317 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20318 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20319
20320 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20321 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20322 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20323 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20324 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20325 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20326 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20327 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20328 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20329 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20330 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20331 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20332
20333 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20334 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20335 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20336 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20337 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20338 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20339 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20340 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20341 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20342 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20343 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20344 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20345
20346 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20347 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20348 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20349 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20350 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20351 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20352 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20353 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20354 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20355 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20356 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20357 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20358
20359 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20360 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20361 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20362 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20363 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20364 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20365 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20366 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20367 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20368 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20369 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20370 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20371
20372 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20373 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20374 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20375 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20376 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20377 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20378 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20379 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20380 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20381 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20382 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20383 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20384
20385 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20386 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20387 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20388 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20389 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20390 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20391 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20392 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20393 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20394 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20395 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20396 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20397
20398 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20399 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20400 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20401 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20402 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20403 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20404 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20405 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20406 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20407 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20408 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20409 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20410
20411 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20412 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20413 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20414 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20415
20416 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20417 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20418 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20419 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20420 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20421 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20422 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20423 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20424 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20425 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20426 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20427 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20428
c19d1205
ZW
20429 /* The implementation of the FIX instruction is broken on some
20430 assemblers, in that it accepts a precision specifier as well as a
20431 rounding specifier, despite the fact that this is meaningless.
20432 To be more compatible, we accept it as well, though of course it
20433 does not set any bits. */
21d799b5
NC
20434 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20435 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20436 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20437 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20438 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20439 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20440 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20441 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20442 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20443 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20444 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20445 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20446 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20447
c19d1205 20448 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20449#undef ARM_VARIANT
20450#define ARM_VARIANT & fpu_fpa_ext_v2
20451
21d799b5
NC
20452 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20453 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20454 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20455 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20456 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20457 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20458
c921be7d
NC
20459#undef ARM_VARIANT
20460#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20461
c19d1205 20462 /* Moves and type conversions. */
21d799b5
NC
20463 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20464 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20465 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20466 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20467 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20468 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20469 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20470 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20471 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20472 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20473 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20474 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20475 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20476 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20477
20478 /* Memory operations. */
21d799b5
NC
20479 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20480 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20481 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20482 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20483 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20484 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20485 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20486 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20487 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20488 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20489 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20490 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20491 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20492 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20493 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20494 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20495 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20496 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20497
c19d1205 20498 /* Monadic operations. */
21d799b5
NC
20499 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20500 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20501 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20502
20503 /* Dyadic operations. */
21d799b5
NC
20504 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20505 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20506 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20507 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20508 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20509 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20510 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20511 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20512 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20513
c19d1205 20514 /* Comparisons. */
21d799b5
NC
20515 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20516 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20517 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20518 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20519
62f3b8c8
PB
20520 /* Double precision load/store are still present on single precision
20521 implementations. */
20522 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20523 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20524 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20525 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20526 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20527 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20528 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20529 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20530 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20531 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20532
c921be7d
NC
20533#undef ARM_VARIANT
20534#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20535
c19d1205 20536 /* Moves and type conversions. */
21d799b5
NC
20537 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20538 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20539 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20540 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20541 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20542 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20543 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20544 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20545 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20546 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20547 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20548 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20549 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20550
c19d1205 20551 /* Monadic operations. */
21d799b5
NC
20552 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20553 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20554 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20555
20556 /* Dyadic operations. */
21d799b5
NC
20557 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20558 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20559 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20560 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20561 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20562 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20563 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20564 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20565 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20566
c19d1205 20567 /* Comparisons. */
21d799b5
NC
20568 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20569 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20570 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20571 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20572
c921be7d
NC
20573#undef ARM_VARIANT
20574#define ARM_VARIANT & fpu_vfp_ext_v2
20575
21d799b5
NC
20576 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20577 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20578 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20579 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20580
037e8744
JB
20581/* Instructions which may belong to either the Neon or VFP instruction sets.
20582 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20583#undef ARM_VARIANT
20584#define ARM_VARIANT & fpu_vfp_ext_v1xd
20585#undef THUMB_VARIANT
20586#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20587
037e8744
JB
20588 /* These mnemonics are unique to VFP. */
20589 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20590 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20591 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20592 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20593 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20594 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20595 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20596 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20597 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20598 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20599
20600 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20601 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20602 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20603 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20604
21d799b5
NC
20605 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20606 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20607
20608 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20609 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20610
55881a11
MGD
20611 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20612 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20613 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20614 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20615 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20616 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20617 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20618 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20619
5f1af56b 20620 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20621 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20622 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20623 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20624
037e8744
JB
20625
20626 /* NOTE: All VMOV encoding is special-cased! */
20627 NCE(vmov, 0, 1, (VMOV), neon_mov),
20628 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20629
9db2f6b4
RL
20630#undef ARM_VARIANT
20631#define ARM_VARIANT & arm_ext_fp16
20632#undef THUMB_VARIANT
20633#define THUMB_VARIANT & arm_ext_fp16
20634 /* New instructions added from v8.2, allowing the extraction and insertion of
20635 the upper 16 bits of a 32-bit vector register. */
20636 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20637 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20638
c921be7d
NC
20639#undef THUMB_VARIANT
20640#define THUMB_VARIANT & fpu_neon_ext_v1
20641#undef ARM_VARIANT
20642#define ARM_VARIANT & fpu_neon_ext_v1
20643
5287ad62
JB
20644 /* Data processing with three registers of the same length. */
20645 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20646 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20647 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20648 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20649 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20650 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20651 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20652 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20653 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20654 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20655 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20656 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20657 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20658 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20659 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20660 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20661 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20662 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20663 /* If not immediate, fall back to neon_dyadic_i64_su.
20664 shl_imm should accept I8 I16 I32 I64,
20665 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20666 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20667 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20668 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20669 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20670 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20671 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20672 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20673 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20674 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20675 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20676 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20677 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20678 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20679 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20680 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20681 /* Bitfield ops, untyped. */
20682 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20683 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20684 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20685 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20686 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20687 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20688 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20689 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20690 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20691 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20692 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20693 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20694 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20695 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20696 back to neon_dyadic_if_su. */
21d799b5
NC
20697 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20698 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20699 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20700 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20701 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20702 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20703 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20704 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20705 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20706 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20707 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20708 /* As above, D registers only. */
21d799b5
NC
20709 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20710 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20711 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20712 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20713 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20714 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20715 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20716 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20717 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20718 /* vtst takes sizes 8, 16, 32. */
20719 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20720 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20721 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20722 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20723 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20724 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20725 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20726 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20727 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20728 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20729 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20730 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20731 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20732 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20733 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20734 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20735 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20736 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20737 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20738 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20739 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20740 /* ARM v8.1 extension. */
643afb90
MW
20741 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20742 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20743 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20744 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20745
20746 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20747 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20748 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20749
20750 /* Data processing with two registers and a shift amount. */
20751 /* Right shifts, and variants with rounding.
20752 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20753 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20754 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20755 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20756 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20757 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20758 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20759 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20760 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20761 /* Shift and insert. Sizes accepted 8 16 32 64. */
20762 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20763 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20764 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20765 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20766 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20767 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20768 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20769 /* Right shift immediate, saturating & narrowing, with rounding variants.
20770 Types accepted S16 S32 S64 U16 U32 U64. */
20771 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20772 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20773 /* As above, unsigned. Types accepted S16 S32 S64. */
20774 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20775 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20776 /* Right shift narrowing. Types accepted I16 I32 I64. */
20777 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20778 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20779 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20780 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20781 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20782 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20783
4316f0d2
DG
20784 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20785 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20786
20787 /* Data processing, three registers of different lengths. */
20788 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20789 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20790 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20791 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20792 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20793 /* If not scalar, fall back to neon_dyadic_long.
20794 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20795 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20796 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20797 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20798 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20799 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20800 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20801 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20802 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20803 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20804 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20805 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20806 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20807 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20808 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20809 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20810 S16 S32 U16 U32. */
21d799b5 20811 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20812
20813 /* Extract. Size 8. */
3b8d421e
PB
20814 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20815 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20816
20817 /* Two registers, miscellaneous. */
20818 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20819 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20820 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20821 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20822 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20823 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20824 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20825 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20826 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20827 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20828 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20829 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20830 /* VMOVN. Types I16 I32 I64. */
21d799b5 20831 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20832 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20833 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20834 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20835 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20836 /* VZIP / VUZP. Sizes 8 16 32. */
20837 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20838 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20839 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20840 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20841 /* VQABS / VQNEG. Types S8 S16 S32. */
20842 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20843 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20844 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20845 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20846 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20847 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20848 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20849 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20850 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20851 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20852 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20853 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20854 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20855 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20856 /* VCLS. Types S8 S16 S32. */
20857 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20858 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20859 /* VCLZ. Types I8 I16 I32. */
20860 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20861 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20862 /* VCNT. Size 8. */
20863 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20864 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20865 /* Two address, untyped. */
20866 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20867 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20868 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20869 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20870 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20871
20872 /* Table lookup. Size 8. */
20873 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20874 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20875
c921be7d
NC
20876#undef THUMB_VARIANT
20877#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20878#undef ARM_VARIANT
20879#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20880
5287ad62 20881 /* Neon element/structure load/store. */
21d799b5
NC
20882 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20883 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20884 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20885 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20886 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20887 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20888 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20889 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20890
c921be7d 20891#undef THUMB_VARIANT
74db7efb
NC
20892#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20893#undef ARM_VARIANT
20894#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20895 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20896 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20897 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20898 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20899 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20900 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20901 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20902 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20903 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20904
74db7efb 20905#undef THUMB_VARIANT
c921be7d
NC
20906#define THUMB_VARIANT & fpu_vfp_ext_v3
20907#undef ARM_VARIANT
20908#define ARM_VARIANT & fpu_vfp_ext_v3
20909
21d799b5 20910 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20911 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20912 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20913 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20914 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20915 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20916 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20917 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20918 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20919
74db7efb
NC
20920#undef ARM_VARIANT
20921#define ARM_VARIANT & fpu_vfp_ext_fma
20922#undef THUMB_VARIANT
20923#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20924 /* Mnemonics shared by Neon and VFP. These are included in the
20925 VFP FMA variant; NEON and VFP FMA always includes the NEON
20926 FMA instructions. */
20927 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20928 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20929 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20930 the v form should always be used. */
20931 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20932 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20933 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20934 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20935 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20936 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20937
5287ad62 20938#undef THUMB_VARIANT
c921be7d
NC
20939#undef ARM_VARIANT
20940#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20941
21d799b5
NC
20942 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20943 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20944 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20945 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20946 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20947 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20948 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20949 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20950
c921be7d
NC
20951#undef ARM_VARIANT
20952#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20953
21d799b5
NC
20954 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20955 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20956 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20957 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20958 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20959 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20960 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20961 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20962 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20963 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20964 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20965 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20966 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20967 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20968 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20969 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20970 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20971 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20972 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20973 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20974 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20975 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20976 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20977 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20978 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20979 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20980 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20981 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20982 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20983 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20984 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20985 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20986 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20987 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20988 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20989 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20990 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20991 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20992 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20993 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20994 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20995 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20996 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20997 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20998 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20999 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21000 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21001 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21002 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21003 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21004 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21005 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21006 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21007 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21008 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21009 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21010 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21011 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21012 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21013 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21014 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21015 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21016 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21017 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21018 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21019 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21020 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21021 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21022 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21023 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21024 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21025 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21026 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21027 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21028 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21029 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21030 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21031 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21032 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21033 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21034 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21035 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21036 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21037 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21038 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21039 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21040 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21041 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21042 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21043 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21044 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21045 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21046 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21047 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21048 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21049 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21050 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21051 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21052 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21053 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21054 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21055 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21056 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21057 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21058 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21059 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21060 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21061 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21062 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21063 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21064 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21065 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21066 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21067 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21068 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21069 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21070 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21071 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21072 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21073 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21074 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21075 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21076 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21077 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21078 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21079 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21080 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21081 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21082 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21083 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21084 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21085 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21086 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21087 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21088 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21089 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21090 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21091 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21092 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21093 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21094 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21095 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21096 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21097 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21098 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21099 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21100 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21101 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21102 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21103 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21104 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21105 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21106 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21107 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21108 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21109 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21110 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21111 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21112 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21113 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21114 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21115 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21116
c921be7d
NC
21117#undef ARM_VARIANT
21118#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21119
21d799b5
NC
21120 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21121 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21122 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21123 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21124 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21125 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21126 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21127 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21128 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21129 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21130 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21131 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21132 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21133 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21134 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21135 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21136 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21137 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21138 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21139 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21140 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21141 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21142 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21143 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21144 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21145 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21146 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21147 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21148 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21149 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21150 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21151 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21152 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21153 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21154 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21155 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21156 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21157 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21158 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21159 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21160 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21161 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21162 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21163 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21164 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21165 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21166 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21167 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21168 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21169 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21170 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21171 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21172 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21173 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21174 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21175 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21176 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21177
c921be7d
NC
21178#undef ARM_VARIANT
21179#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21180
21d799b5
NC
21181 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21182 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21183 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21184 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21185 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21186 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21187 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21188 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21189 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21190 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21191 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21192 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21193 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21194 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21195 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21196 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21197 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21198 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21199 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21200 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21201 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21202 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21203 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21204 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21205 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21206 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21207 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21208 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21209 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21210 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21211 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21212 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21213 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21214 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21215 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21216 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21217 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21218 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21219 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21220 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21221 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21222 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21223 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21224 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21225 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21226 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21227 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21228 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21229 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21230 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21231 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21232 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21233 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21234 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21235 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21236 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21237 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21238 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21239 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21240 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21241 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21242 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21243 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21244 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21245 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21246 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21247 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21248 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21249 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21250 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21251 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21252 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21253 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21254 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21255 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21256 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21257
16a1fa25 21258 /* ARMv8-M instructions. */
4ed7ed8d
TP
21259#undef ARM_VARIANT
21260#define ARM_VARIANT NULL
21261#undef THUMB_VARIANT
21262#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21263 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21264 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21265 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21266 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21267 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21268 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21269 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21270
21271 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21272 instructions behave as nop if no VFP is present. */
21273#undef THUMB_VARIANT
21274#define THUMB_VARIANT & arm_ext_v8m_main
21275 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21276 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21277};
21278#undef ARM_VARIANT
21279#undef THUMB_VARIANT
21280#undef TCE
c19d1205
ZW
21281#undef TUE
21282#undef TUF
21283#undef TCC
8f06b2d8 21284#undef cCE
e3cb604e
PB
21285#undef cCL
21286#undef C3E
c19d1205
ZW
21287#undef CE
21288#undef CM
21289#undef UE
21290#undef UF
21291#undef UT
5287ad62
JB
21292#undef NUF
21293#undef nUF
21294#undef NCE
21295#undef nCE
c19d1205
ZW
21296#undef OPS0
21297#undef OPS1
21298#undef OPS2
21299#undef OPS3
21300#undef OPS4
21301#undef OPS5
21302#undef OPS6
21303#undef do_0
21304\f
21305/* MD interface: bits in the object file. */
bfae80f2 21306
c19d1205
ZW
21307/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21308 for use in the a.out file, and stores them in the array pointed to by buf.
21309 This knows about the endian-ness of the target machine and does
21310 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21311 2 (short) and 4 (long) Floating numbers are put out as a series of
21312 LITTLENUMS (shorts, here at least). */
b99bd4ef 21313
c19d1205
ZW
21314void
21315md_number_to_chars (char * buf, valueT val, int n)
21316{
21317 if (target_big_endian)
21318 number_to_chars_bigendian (buf, val, n);
21319 else
21320 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21321}
21322
c19d1205
ZW
21323static valueT
21324md_chars_to_number (char * buf, int n)
bfae80f2 21325{
c19d1205
ZW
21326 valueT result = 0;
21327 unsigned char * where = (unsigned char *) buf;
bfae80f2 21328
c19d1205 21329 if (target_big_endian)
b99bd4ef 21330 {
c19d1205
ZW
21331 while (n--)
21332 {
21333 result <<= 8;
21334 result |= (*where++ & 255);
21335 }
b99bd4ef 21336 }
c19d1205 21337 else
b99bd4ef 21338 {
c19d1205
ZW
21339 while (n--)
21340 {
21341 result <<= 8;
21342 result |= (where[n] & 255);
21343 }
bfae80f2 21344 }
b99bd4ef 21345
c19d1205 21346 return result;
bfae80f2 21347}
b99bd4ef 21348
c19d1205 21349/* MD interface: Sections. */
b99bd4ef 21350
fa94de6b
RM
21351/* Calculate the maximum variable size (i.e., excluding fr_fix)
21352 that an rs_machine_dependent frag may reach. */
21353
21354unsigned int
21355arm_frag_max_var (fragS *fragp)
21356{
21357 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21358 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21359
21360 Note that we generate relaxable instructions even for cases that don't
21361 really need it, like an immediate that's a trivial constant. So we're
21362 overestimating the instruction size for some of those cases. Rather
21363 than putting more intelligence here, it would probably be better to
21364 avoid generating a relaxation frag in the first place when it can be
21365 determined up front that a short instruction will suffice. */
21366
21367 gas_assert (fragp->fr_type == rs_machine_dependent);
21368 return INSN_SIZE;
21369}
21370
0110f2b8
PB
21371/* Estimate the size of a frag before relaxing. Assume everything fits in
21372 2 bytes. */
21373
c19d1205 21374int
0110f2b8 21375md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21376 segT segtype ATTRIBUTE_UNUSED)
21377{
0110f2b8
PB
21378 fragp->fr_var = 2;
21379 return 2;
21380}
21381
21382/* Convert a machine dependent frag. */
21383
21384void
21385md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21386{
21387 unsigned long insn;
21388 unsigned long old_op;
21389 char *buf;
21390 expressionS exp;
21391 fixS *fixp;
21392 int reloc_type;
21393 int pc_rel;
21394 int opcode;
21395
21396 buf = fragp->fr_literal + fragp->fr_fix;
21397
21398 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21399 if (fragp->fr_symbol)
21400 {
0110f2b8
PB
21401 exp.X_op = O_symbol;
21402 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21403 }
21404 else
21405 {
0110f2b8 21406 exp.X_op = O_constant;
5f4273c7 21407 }
0110f2b8
PB
21408 exp.X_add_number = fragp->fr_offset;
21409 opcode = fragp->fr_subtype;
21410 switch (opcode)
21411 {
21412 case T_MNEM_ldr_pc:
21413 case T_MNEM_ldr_pc2:
21414 case T_MNEM_ldr_sp:
21415 case T_MNEM_str_sp:
21416 case T_MNEM_ldr:
21417 case T_MNEM_ldrb:
21418 case T_MNEM_ldrh:
21419 case T_MNEM_str:
21420 case T_MNEM_strb:
21421 case T_MNEM_strh:
21422 if (fragp->fr_var == 4)
21423 {
5f4273c7 21424 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21425 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21426 {
21427 insn |= (old_op & 0x700) << 4;
21428 }
21429 else
21430 {
21431 insn |= (old_op & 7) << 12;
21432 insn |= (old_op & 0x38) << 13;
21433 }
21434 insn |= 0x00000c00;
21435 put_thumb32_insn (buf, insn);
21436 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21437 }
21438 else
21439 {
21440 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21441 }
21442 pc_rel = (opcode == T_MNEM_ldr_pc2);
21443 break;
21444 case T_MNEM_adr:
21445 if (fragp->fr_var == 4)
21446 {
21447 insn = THUMB_OP32 (opcode);
21448 insn |= (old_op & 0xf0) << 4;
21449 put_thumb32_insn (buf, insn);
21450 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21451 }
21452 else
21453 {
21454 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21455 exp.X_add_number -= 4;
21456 }
21457 pc_rel = 1;
21458 break;
21459 case T_MNEM_mov:
21460 case T_MNEM_movs:
21461 case T_MNEM_cmp:
21462 case T_MNEM_cmn:
21463 if (fragp->fr_var == 4)
21464 {
21465 int r0off = (opcode == T_MNEM_mov
21466 || opcode == T_MNEM_movs) ? 0 : 8;
21467 insn = THUMB_OP32 (opcode);
21468 insn = (insn & 0xe1ffffff) | 0x10000000;
21469 insn |= (old_op & 0x700) << r0off;
21470 put_thumb32_insn (buf, insn);
21471 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21472 }
21473 else
21474 {
21475 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21476 }
21477 pc_rel = 0;
21478 break;
21479 case T_MNEM_b:
21480 if (fragp->fr_var == 4)
21481 {
21482 insn = THUMB_OP32(opcode);
21483 put_thumb32_insn (buf, insn);
21484 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21485 }
21486 else
21487 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21488 pc_rel = 1;
21489 break;
21490 case T_MNEM_bcond:
21491 if (fragp->fr_var == 4)
21492 {
21493 insn = THUMB_OP32(opcode);
21494 insn |= (old_op & 0xf00) << 14;
21495 put_thumb32_insn (buf, insn);
21496 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21497 }
21498 else
21499 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21500 pc_rel = 1;
21501 break;
21502 case T_MNEM_add_sp:
21503 case T_MNEM_add_pc:
21504 case T_MNEM_inc_sp:
21505 case T_MNEM_dec_sp:
21506 if (fragp->fr_var == 4)
21507 {
21508 /* ??? Choose between add and addw. */
21509 insn = THUMB_OP32 (opcode);
21510 insn |= (old_op & 0xf0) << 4;
21511 put_thumb32_insn (buf, insn);
16805f35
PB
21512 if (opcode == T_MNEM_add_pc)
21513 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21514 else
21515 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21516 }
21517 else
21518 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21519 pc_rel = 0;
21520 break;
21521
21522 case T_MNEM_addi:
21523 case T_MNEM_addis:
21524 case T_MNEM_subi:
21525 case T_MNEM_subis:
21526 if (fragp->fr_var == 4)
21527 {
21528 insn = THUMB_OP32 (opcode);
21529 insn |= (old_op & 0xf0) << 4;
21530 insn |= (old_op & 0xf) << 16;
21531 put_thumb32_insn (buf, insn);
16805f35
PB
21532 if (insn & (1 << 20))
21533 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21534 else
21535 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21536 }
21537 else
21538 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21539 pc_rel = 0;
21540 break;
21541 default:
5f4273c7 21542 abort ();
0110f2b8
PB
21543 }
21544 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21545 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21546 fixp->fx_file = fragp->fr_file;
21547 fixp->fx_line = fragp->fr_line;
21548 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21549
21550 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21551 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21552 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21553 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21554}
21555
21556/* Return the size of a relaxable immediate operand instruction.
21557 SHIFT and SIZE specify the form of the allowable immediate. */
21558static int
21559relax_immediate (fragS *fragp, int size, int shift)
21560{
21561 offsetT offset;
21562 offsetT mask;
21563 offsetT low;
21564
21565 /* ??? Should be able to do better than this. */
21566 if (fragp->fr_symbol)
21567 return 4;
21568
21569 low = (1 << shift) - 1;
21570 mask = (1 << (shift + size)) - (1 << shift);
21571 offset = fragp->fr_offset;
21572 /* Force misaligned offsets to 32-bit variant. */
21573 if (offset & low)
5e77afaa 21574 return 4;
0110f2b8
PB
21575 if (offset & ~mask)
21576 return 4;
21577 return 2;
21578}
21579
5e77afaa
PB
21580/* Get the address of a symbol during relaxation. */
21581static addressT
5f4273c7 21582relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21583{
21584 fragS *sym_frag;
21585 addressT addr;
21586 symbolS *sym;
21587
21588 sym = fragp->fr_symbol;
21589 sym_frag = symbol_get_frag (sym);
21590 know (S_GET_SEGMENT (sym) != absolute_section
21591 || sym_frag == &zero_address_frag);
21592 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21593
21594 /* If frag has yet to be reached on this pass, assume it will
21595 move by STRETCH just as we did. If this is not so, it will
21596 be because some frag between grows, and that will force
21597 another pass. */
21598
21599 if (stretch != 0
21600 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21601 {
21602 fragS *f;
21603
21604 /* Adjust stretch for any alignment frag. Note that if have
21605 been expanding the earlier code, the symbol may be
21606 defined in what appears to be an earlier frag. FIXME:
21607 This doesn't handle the fr_subtype field, which specifies
21608 a maximum number of bytes to skip when doing an
21609 alignment. */
21610 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21611 {
21612 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21613 {
21614 if (stretch < 0)
21615 stretch = - ((- stretch)
21616 & ~ ((1 << (int) f->fr_offset) - 1));
21617 else
21618 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21619 if (stretch == 0)
21620 break;
21621 }
21622 }
21623 if (f != NULL)
21624 addr += stretch;
21625 }
5e77afaa
PB
21626
21627 return addr;
21628}
21629
0110f2b8
PB
21630/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21631 load. */
21632static int
5e77afaa 21633relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21634{
21635 addressT addr;
21636 offsetT val;
21637
21638 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21639 if (fragp->fr_symbol == NULL
21640 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21641 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21642 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21643 return 4;
21644
5f4273c7 21645 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21646 addr = fragp->fr_address + fragp->fr_fix;
21647 addr = (addr + 4) & ~3;
5e77afaa 21648 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21649 if (val & 3)
5e77afaa 21650 return 4;
0110f2b8
PB
21651 val -= addr;
21652 if (val < 0 || val > 1020)
21653 return 4;
21654 return 2;
21655}
21656
21657/* Return the size of a relaxable add/sub immediate instruction. */
21658static int
21659relax_addsub (fragS *fragp, asection *sec)
21660{
21661 char *buf;
21662 int op;
21663
21664 buf = fragp->fr_literal + fragp->fr_fix;
21665 op = bfd_get_16(sec->owner, buf);
21666 if ((op & 0xf) == ((op >> 4) & 0xf))
21667 return relax_immediate (fragp, 8, 0);
21668 else
21669 return relax_immediate (fragp, 3, 0);
21670}
21671
e83a675f
RE
21672/* Return TRUE iff the definition of symbol S could be pre-empted
21673 (overridden) at link or load time. */
21674static bfd_boolean
21675symbol_preemptible (symbolS *s)
21676{
21677 /* Weak symbols can always be pre-empted. */
21678 if (S_IS_WEAK (s))
21679 return TRUE;
21680
21681 /* Non-global symbols cannot be pre-empted. */
21682 if (! S_IS_EXTERNAL (s))
21683 return FALSE;
21684
21685#ifdef OBJ_ELF
21686 /* In ELF, a global symbol can be marked protected, or private. In that
21687 case it can't be pre-empted (other definitions in the same link unit
21688 would violate the ODR). */
21689 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21690 return FALSE;
21691#endif
21692
21693 /* Other global symbols might be pre-empted. */
21694 return TRUE;
21695}
0110f2b8
PB
21696
21697/* Return the size of a relaxable branch instruction. BITS is the
21698 size of the offset field in the narrow instruction. */
21699
21700static int
5e77afaa 21701relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21702{
21703 addressT addr;
21704 offsetT val;
21705 offsetT limit;
21706
21707 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21708 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21709 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21710 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21711 return 4;
21712
267bf995 21713#ifdef OBJ_ELF
e83a675f 21714 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21715 if (S_IS_DEFINED (fragp->fr_symbol)
21716 && ARM_IS_FUNC (fragp->fr_symbol))
21717 return 4;
e83a675f 21718#endif
0d9b4b55 21719
e83a675f 21720 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21721 return 4;
267bf995 21722
5f4273c7 21723 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21724 addr = fragp->fr_address + fragp->fr_fix + 4;
21725 val -= addr;
21726
21727 /* Offset is a signed value *2 */
21728 limit = 1 << bits;
21729 if (val >= limit || val < -limit)
21730 return 4;
21731 return 2;
21732}
21733
21734
21735/* Relax a machine dependent frag. This returns the amount by which
21736 the current size of the frag should change. */
21737
21738int
5e77afaa 21739arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21740{
21741 int oldsize;
21742 int newsize;
21743
21744 oldsize = fragp->fr_var;
21745 switch (fragp->fr_subtype)
21746 {
21747 case T_MNEM_ldr_pc2:
5f4273c7 21748 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21749 break;
21750 case T_MNEM_ldr_pc:
21751 case T_MNEM_ldr_sp:
21752 case T_MNEM_str_sp:
5f4273c7 21753 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21754 break;
21755 case T_MNEM_ldr:
21756 case T_MNEM_str:
5f4273c7 21757 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21758 break;
21759 case T_MNEM_ldrh:
21760 case T_MNEM_strh:
5f4273c7 21761 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21762 break;
21763 case T_MNEM_ldrb:
21764 case T_MNEM_strb:
5f4273c7 21765 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21766 break;
21767 case T_MNEM_adr:
5f4273c7 21768 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21769 break;
21770 case T_MNEM_mov:
21771 case T_MNEM_movs:
21772 case T_MNEM_cmp:
21773 case T_MNEM_cmn:
5f4273c7 21774 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21775 break;
21776 case T_MNEM_b:
5f4273c7 21777 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21778 break;
21779 case T_MNEM_bcond:
5f4273c7 21780 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21781 break;
21782 case T_MNEM_add_sp:
21783 case T_MNEM_add_pc:
21784 newsize = relax_immediate (fragp, 8, 2);
21785 break;
21786 case T_MNEM_inc_sp:
21787 case T_MNEM_dec_sp:
21788 newsize = relax_immediate (fragp, 7, 2);
21789 break;
21790 case T_MNEM_addi:
21791 case T_MNEM_addis:
21792 case T_MNEM_subi:
21793 case T_MNEM_subis:
21794 newsize = relax_addsub (fragp, sec);
21795 break;
21796 default:
5f4273c7 21797 abort ();
0110f2b8 21798 }
5e77afaa
PB
21799
21800 fragp->fr_var = newsize;
21801 /* Freeze wide instructions that are at or before the same location as
21802 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21803 Don't freeze them unconditionally because targets may be artificially
21804 misaligned by the expansion of preceding frags. */
5e77afaa 21805 if (stretch <= 0 && newsize > 2)
0110f2b8 21806 {
0110f2b8 21807 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21808 frag_wane (fragp);
0110f2b8 21809 }
5e77afaa 21810
0110f2b8 21811 return newsize - oldsize;
c19d1205 21812}
b99bd4ef 21813
c19d1205 21814/* Round up a section size to the appropriate boundary. */
b99bd4ef 21815
c19d1205
ZW
21816valueT
21817md_section_align (segT segment ATTRIBUTE_UNUSED,
21818 valueT size)
21819{
f0927246
NC
21820#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21821 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21822 {
21823 /* For a.out, force the section size to be aligned. If we don't do
21824 this, BFD will align it for us, but it will not write out the
21825 final bytes of the section. This may be a bug in BFD, but it is
21826 easier to fix it here since that is how the other a.out targets
21827 work. */
21828 int align;
21829
21830 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21831 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21832 }
c19d1205 21833#endif
f0927246 21834
6844c0cc 21835 return size;
bfae80f2 21836}
b99bd4ef 21837
c19d1205
ZW
21838/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21839 of an rs_align_code fragment. */
21840
21841void
21842arm_handle_align (fragS * fragP)
bfae80f2 21843{
d9235011 21844 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21845 {
21846 { /* ARMv1 */
21847 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21848 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21849 },
21850 { /* ARMv6k */
21851 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21852 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21853 },
21854 };
d9235011 21855 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21856 {
21857 { /* Thumb-1 */
21858 {0xc0, 0x46}, /* LE */
21859 {0x46, 0xc0}, /* BE */
21860 },
21861 { /* Thumb-2 */
21862 {0x00, 0xbf}, /* LE */
21863 {0xbf, 0x00} /* BE */
21864 }
21865 };
d9235011 21866 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21867 { /* Wide Thumb-2 */
21868 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21869 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21870 };
c921be7d 21871
e7495e45 21872 unsigned bytes, fix, noop_size;
c19d1205 21873 char * p;
d9235011
TS
21874 const unsigned char * noop;
21875 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21876#ifdef OBJ_ELF
21877 enum mstate state;
21878#endif
bfae80f2 21879
c19d1205 21880 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21881 return;
21882
c19d1205
ZW
21883 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21884 p = fragP->fr_literal + fragP->fr_fix;
21885 fix = 0;
bfae80f2 21886
c19d1205
ZW
21887 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21888 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21889
cd000bff 21890 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21891
cd000bff 21892 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21893 {
7f78eb34
JW
21894 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21895 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21896 {
21897 narrow_noop = thumb_noop[1][target_big_endian];
21898 noop = wide_thumb_noop[target_big_endian];
21899 }
c19d1205 21900 else
e7495e45
NS
21901 noop = thumb_noop[0][target_big_endian];
21902 noop_size = 2;
cd000bff
DJ
21903#ifdef OBJ_ELF
21904 state = MAP_THUMB;
21905#endif
7ed4c4c5
NC
21906 }
21907 else
21908 {
7f78eb34
JW
21909 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21910 ? selected_cpu : arm_arch_none,
21911 arm_ext_v6k) != 0]
e7495e45
NS
21912 [target_big_endian];
21913 noop_size = 4;
cd000bff
DJ
21914#ifdef OBJ_ELF
21915 state = MAP_ARM;
21916#endif
7ed4c4c5 21917 }
c921be7d 21918
e7495e45 21919 fragP->fr_var = noop_size;
c921be7d 21920
c19d1205 21921 if (bytes & (noop_size - 1))
7ed4c4c5 21922 {
c19d1205 21923 fix = bytes & (noop_size - 1);
cd000bff
DJ
21924#ifdef OBJ_ELF
21925 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21926#endif
c19d1205
ZW
21927 memset (p, 0, fix);
21928 p += fix;
21929 bytes -= fix;
a737bd4d 21930 }
a737bd4d 21931
e7495e45
NS
21932 if (narrow_noop)
21933 {
21934 if (bytes & noop_size)
21935 {
21936 /* Insert a narrow noop. */
21937 memcpy (p, narrow_noop, noop_size);
21938 p += noop_size;
21939 bytes -= noop_size;
21940 fix += noop_size;
21941 }
21942
21943 /* Use wide noops for the remainder */
21944 noop_size = 4;
21945 }
21946
c19d1205 21947 while (bytes >= noop_size)
a737bd4d 21948 {
c19d1205
ZW
21949 memcpy (p, noop, noop_size);
21950 p += noop_size;
21951 bytes -= noop_size;
21952 fix += noop_size;
a737bd4d
NC
21953 }
21954
c19d1205 21955 fragP->fr_fix += fix;
a737bd4d
NC
21956}
21957
c19d1205
ZW
21958/* Called from md_do_align. Used to create an alignment
21959 frag in a code section. */
21960
21961void
21962arm_frag_align_code (int n, int max)
bfae80f2 21963{
c19d1205 21964 char * p;
7ed4c4c5 21965
c19d1205 21966 /* We assume that there will never be a requirement
6ec8e702 21967 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21968 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21969 {
21970 char err_msg[128];
21971
fa94de6b 21972 sprintf (err_msg,
477330fc
RM
21973 _("alignments greater than %d bytes not supported in .text sections."),
21974 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21975 as_fatal ("%s", err_msg);
6ec8e702 21976 }
bfae80f2 21977
c19d1205
ZW
21978 p = frag_var (rs_align_code,
21979 MAX_MEM_FOR_RS_ALIGN_CODE,
21980 1,
21981 (relax_substateT) max,
21982 (symbolS *) NULL,
21983 (offsetT) n,
21984 (char *) NULL);
21985 *p = 0;
21986}
bfae80f2 21987
8dc2430f
NC
21988/* Perform target specific initialisation of a frag.
21989 Note - despite the name this initialisation is not done when the frag
21990 is created, but only when its type is assigned. A frag can be created
21991 and used a long time before its type is set, so beware of assuming that
33eaf5de 21992 this initialisation is performed first. */
bfae80f2 21993
cd000bff
DJ
21994#ifndef OBJ_ELF
21995void
21996arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21997{
21998 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21999 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22000}
22001
22002#else /* OBJ_ELF is defined. */
c19d1205 22003void
cd000bff 22004arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22005{
e8d84ca1 22006 bfd_boolean frag_thumb_mode;
b968d18a 22007
8dc2430f
NC
22008 /* If the current ARM vs THUMB mode has not already
22009 been recorded into this frag then do so now. */
cd000bff 22010 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22011 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22012
e8d84ca1
NC
22013 /* PR 21809: Do not set a mapping state for debug sections
22014 - it just confuses other tools. */
22015 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22016 return;
22017
b968d18a 22018 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22019
f9c1b181
RL
22020 /* Record a mapping symbol for alignment frags. We will delete this
22021 later if the alignment ends up empty. */
22022 switch (fragP->fr_type)
22023 {
22024 case rs_align:
22025 case rs_align_test:
22026 case rs_fill:
22027 mapping_state_2 (MAP_DATA, max_chars);
22028 break;
22029 case rs_align_code:
b968d18a 22030 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22031 break;
22032 default:
22033 break;
cd000bff 22034 }
bfae80f2
RE
22035}
22036
c19d1205
ZW
22037/* When we change sections we need to issue a new mapping symbol. */
22038
22039void
22040arm_elf_change_section (void)
bfae80f2 22041{
c19d1205
ZW
22042 /* Link an unlinked unwind index table section to the .text section. */
22043 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22044 && elf_linked_to_section (now_seg) == NULL)
22045 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22046}
22047
c19d1205
ZW
22048int
22049arm_elf_section_type (const char * str, size_t len)
e45d0630 22050{
c19d1205
ZW
22051 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22052 return SHT_ARM_EXIDX;
e45d0630 22053
c19d1205
ZW
22054 return -1;
22055}
22056\f
22057/* Code to deal with unwinding tables. */
e45d0630 22058
c19d1205 22059static void add_unwind_adjustsp (offsetT);
e45d0630 22060
5f4273c7 22061/* Generate any deferred unwind frame offset. */
e45d0630 22062
bfae80f2 22063static void
c19d1205 22064flush_pending_unwind (void)
bfae80f2 22065{
c19d1205 22066 offsetT offset;
bfae80f2 22067
c19d1205
ZW
22068 offset = unwind.pending_offset;
22069 unwind.pending_offset = 0;
22070 if (offset != 0)
22071 add_unwind_adjustsp (offset);
bfae80f2
RE
22072}
22073
c19d1205
ZW
22074/* Add an opcode to this list for this function. Two-byte opcodes should
22075 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22076 order. */
22077
bfae80f2 22078static void
c19d1205 22079add_unwind_opcode (valueT op, int length)
bfae80f2 22080{
c19d1205
ZW
22081 /* Add any deferred stack adjustment. */
22082 if (unwind.pending_offset)
22083 flush_pending_unwind ();
bfae80f2 22084
c19d1205 22085 unwind.sp_restored = 0;
bfae80f2 22086
c19d1205 22087 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22088 {
c19d1205
ZW
22089 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22090 if (unwind.opcodes)
325801bd
TS
22091 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22092 unwind.opcode_alloc);
c19d1205 22093 else
325801bd 22094 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22095 }
c19d1205 22096 while (length > 0)
bfae80f2 22097 {
c19d1205
ZW
22098 length--;
22099 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22100 op >>= 8;
22101 unwind.opcode_count++;
bfae80f2 22102 }
bfae80f2
RE
22103}
22104
c19d1205
ZW
22105/* Add unwind opcodes to adjust the stack pointer. */
22106
bfae80f2 22107static void
c19d1205 22108add_unwind_adjustsp (offsetT offset)
bfae80f2 22109{
c19d1205 22110 valueT op;
bfae80f2 22111
c19d1205 22112 if (offset > 0x200)
bfae80f2 22113 {
c19d1205
ZW
22114 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22115 char bytes[5];
22116 int n;
22117 valueT o;
bfae80f2 22118
c19d1205
ZW
22119 /* Long form: 0xb2, uleb128. */
22120 /* This might not fit in a word so add the individual bytes,
22121 remembering the list is built in reverse order. */
22122 o = (valueT) ((offset - 0x204) >> 2);
22123 if (o == 0)
22124 add_unwind_opcode (0, 1);
bfae80f2 22125
c19d1205
ZW
22126 /* Calculate the uleb128 encoding of the offset. */
22127 n = 0;
22128 while (o)
22129 {
22130 bytes[n] = o & 0x7f;
22131 o >>= 7;
22132 if (o)
22133 bytes[n] |= 0x80;
22134 n++;
22135 }
22136 /* Add the insn. */
22137 for (; n; n--)
22138 add_unwind_opcode (bytes[n - 1], 1);
22139 add_unwind_opcode (0xb2, 1);
22140 }
22141 else if (offset > 0x100)
bfae80f2 22142 {
c19d1205
ZW
22143 /* Two short opcodes. */
22144 add_unwind_opcode (0x3f, 1);
22145 op = (offset - 0x104) >> 2;
22146 add_unwind_opcode (op, 1);
bfae80f2 22147 }
c19d1205
ZW
22148 else if (offset > 0)
22149 {
22150 /* Short opcode. */
22151 op = (offset - 4) >> 2;
22152 add_unwind_opcode (op, 1);
22153 }
22154 else if (offset < 0)
bfae80f2 22155 {
c19d1205
ZW
22156 offset = -offset;
22157 while (offset > 0x100)
bfae80f2 22158 {
c19d1205
ZW
22159 add_unwind_opcode (0x7f, 1);
22160 offset -= 0x100;
bfae80f2 22161 }
c19d1205
ZW
22162 op = ((offset - 4) >> 2) | 0x40;
22163 add_unwind_opcode (op, 1);
bfae80f2 22164 }
bfae80f2
RE
22165}
22166
c19d1205
ZW
22167/* Finish the list of unwind opcodes for this function. */
22168static void
22169finish_unwind_opcodes (void)
bfae80f2 22170{
c19d1205 22171 valueT op;
bfae80f2 22172
c19d1205 22173 if (unwind.fp_used)
bfae80f2 22174 {
708587a4 22175 /* Adjust sp as necessary. */
c19d1205
ZW
22176 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22177 flush_pending_unwind ();
bfae80f2 22178
c19d1205
ZW
22179 /* After restoring sp from the frame pointer. */
22180 op = 0x90 | unwind.fp_reg;
22181 add_unwind_opcode (op, 1);
22182 }
22183 else
22184 flush_pending_unwind ();
bfae80f2
RE
22185}
22186
bfae80f2 22187
c19d1205
ZW
22188/* Start an exception table entry. If idx is nonzero this is an index table
22189 entry. */
bfae80f2
RE
22190
22191static void
c19d1205 22192start_unwind_section (const segT text_seg, int idx)
bfae80f2 22193{
c19d1205
ZW
22194 const char * text_name;
22195 const char * prefix;
22196 const char * prefix_once;
22197 const char * group_name;
c19d1205 22198 char * sec_name;
c19d1205
ZW
22199 int type;
22200 int flags;
22201 int linkonce;
bfae80f2 22202
c19d1205 22203 if (idx)
bfae80f2 22204 {
c19d1205
ZW
22205 prefix = ELF_STRING_ARM_unwind;
22206 prefix_once = ELF_STRING_ARM_unwind_once;
22207 type = SHT_ARM_EXIDX;
bfae80f2 22208 }
c19d1205 22209 else
bfae80f2 22210 {
c19d1205
ZW
22211 prefix = ELF_STRING_ARM_unwind_info;
22212 prefix_once = ELF_STRING_ARM_unwind_info_once;
22213 type = SHT_PROGBITS;
bfae80f2
RE
22214 }
22215
c19d1205
ZW
22216 text_name = segment_name (text_seg);
22217 if (streq (text_name, ".text"))
22218 text_name = "";
22219
22220 if (strncmp (text_name, ".gnu.linkonce.t.",
22221 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22222 {
c19d1205
ZW
22223 prefix = prefix_once;
22224 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22225 }
22226
29a2809e 22227 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22228
c19d1205
ZW
22229 flags = SHF_ALLOC;
22230 linkonce = 0;
22231 group_name = 0;
bfae80f2 22232
c19d1205
ZW
22233 /* Handle COMDAT group. */
22234 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22235 {
c19d1205
ZW
22236 group_name = elf_group_name (text_seg);
22237 if (group_name == NULL)
22238 {
bd3ba5d1 22239 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22240 segment_name (text_seg));
22241 ignore_rest_of_line ();
22242 return;
22243 }
22244 flags |= SHF_GROUP;
22245 linkonce = 1;
bfae80f2
RE
22246 }
22247
a91e1603
L
22248 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22249 linkonce, 0);
bfae80f2 22250
5f4273c7 22251 /* Set the section link for index tables. */
c19d1205
ZW
22252 if (idx)
22253 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22254}
22255
bfae80f2 22256
c19d1205
ZW
22257/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22258 personality routine data. Returns zero, or the index table value for
cad0da33 22259 an inline entry. */
c19d1205
ZW
22260
22261static valueT
22262create_unwind_entry (int have_data)
bfae80f2 22263{
c19d1205
ZW
22264 int size;
22265 addressT where;
22266 char *ptr;
22267 /* The current word of data. */
22268 valueT data;
22269 /* The number of bytes left in this word. */
22270 int n;
bfae80f2 22271
c19d1205 22272 finish_unwind_opcodes ();
bfae80f2 22273
c19d1205
ZW
22274 /* Remember the current text section. */
22275 unwind.saved_seg = now_seg;
22276 unwind.saved_subseg = now_subseg;
bfae80f2 22277
c19d1205 22278 start_unwind_section (now_seg, 0);
bfae80f2 22279
c19d1205 22280 if (unwind.personality_routine == NULL)
bfae80f2 22281 {
c19d1205
ZW
22282 if (unwind.personality_index == -2)
22283 {
22284 if (have_data)
5f4273c7 22285 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22286 return 1; /* EXIDX_CANTUNWIND. */
22287 }
bfae80f2 22288
c19d1205
ZW
22289 /* Use a default personality routine if none is specified. */
22290 if (unwind.personality_index == -1)
22291 {
22292 if (unwind.opcode_count > 3)
22293 unwind.personality_index = 1;
22294 else
22295 unwind.personality_index = 0;
22296 }
bfae80f2 22297
c19d1205
ZW
22298 /* Space for the personality routine entry. */
22299 if (unwind.personality_index == 0)
22300 {
22301 if (unwind.opcode_count > 3)
22302 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22303
c19d1205
ZW
22304 if (!have_data)
22305 {
22306 /* All the data is inline in the index table. */
22307 data = 0x80;
22308 n = 3;
22309 while (unwind.opcode_count > 0)
22310 {
22311 unwind.opcode_count--;
22312 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22313 n--;
22314 }
bfae80f2 22315
c19d1205
ZW
22316 /* Pad with "finish" opcodes. */
22317 while (n--)
22318 data = (data << 8) | 0xb0;
bfae80f2 22319
c19d1205
ZW
22320 return data;
22321 }
22322 size = 0;
22323 }
22324 else
22325 /* We get two opcodes "free" in the first word. */
22326 size = unwind.opcode_count - 2;
22327 }
22328 else
5011093d 22329 {
cad0da33
NC
22330 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22331 if (unwind.personality_index != -1)
22332 {
22333 as_bad (_("attempt to recreate an unwind entry"));
22334 return 1;
22335 }
5011093d
NC
22336
22337 /* An extra byte is required for the opcode count. */
22338 size = unwind.opcode_count + 1;
22339 }
bfae80f2 22340
c19d1205
ZW
22341 size = (size + 3) >> 2;
22342 if (size > 0xff)
22343 as_bad (_("too many unwind opcodes"));
bfae80f2 22344
c19d1205
ZW
22345 frag_align (2, 0, 0);
22346 record_alignment (now_seg, 2);
22347 unwind.table_entry = expr_build_dot ();
22348
22349 /* Allocate the table entry. */
22350 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22351 /* PR 13449: Zero the table entries in case some of them are not used. */
22352 memset (ptr, 0, (size << 2) + 4);
c19d1205 22353 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22354
c19d1205 22355 switch (unwind.personality_index)
bfae80f2 22356 {
c19d1205
ZW
22357 case -1:
22358 /* ??? Should this be a PLT generating relocation? */
22359 /* Custom personality routine. */
22360 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22361 BFD_RELOC_ARM_PREL31);
bfae80f2 22362
c19d1205
ZW
22363 where += 4;
22364 ptr += 4;
bfae80f2 22365
c19d1205 22366 /* Set the first byte to the number of additional words. */
5011093d 22367 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22368 n = 3;
22369 break;
bfae80f2 22370
c19d1205
ZW
22371 /* ABI defined personality routines. */
22372 case 0:
22373 /* Three opcodes bytes are packed into the first word. */
22374 data = 0x80;
22375 n = 3;
22376 break;
bfae80f2 22377
c19d1205
ZW
22378 case 1:
22379 case 2:
22380 /* The size and first two opcode bytes go in the first word. */
22381 data = ((0x80 + unwind.personality_index) << 8) | size;
22382 n = 2;
22383 break;
bfae80f2 22384
c19d1205
ZW
22385 default:
22386 /* Should never happen. */
22387 abort ();
22388 }
bfae80f2 22389
c19d1205
ZW
22390 /* Pack the opcodes into words (MSB first), reversing the list at the same
22391 time. */
22392 while (unwind.opcode_count > 0)
22393 {
22394 if (n == 0)
22395 {
22396 md_number_to_chars (ptr, data, 4);
22397 ptr += 4;
22398 n = 4;
22399 data = 0;
22400 }
22401 unwind.opcode_count--;
22402 n--;
22403 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22404 }
22405
22406 /* Finish off the last word. */
22407 if (n < 4)
22408 {
22409 /* Pad with "finish" opcodes. */
22410 while (n--)
22411 data = (data << 8) | 0xb0;
22412
22413 md_number_to_chars (ptr, data, 4);
22414 }
22415
22416 if (!have_data)
22417 {
22418 /* Add an empty descriptor if there is no user-specified data. */
22419 ptr = frag_more (4);
22420 md_number_to_chars (ptr, 0, 4);
22421 }
22422
22423 return 0;
bfae80f2
RE
22424}
22425
f0927246
NC
22426
22427/* Initialize the DWARF-2 unwind information for this procedure. */
22428
22429void
22430tc_arm_frame_initial_instructions (void)
22431{
22432 cfi_add_CFA_def_cfa (REG_SP, 0);
22433}
22434#endif /* OBJ_ELF */
22435
c19d1205
ZW
22436/* Convert REGNAME to a DWARF-2 register number. */
22437
22438int
1df69f4f 22439tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22440{
1df69f4f 22441 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22442 if (reg != FAIL)
22443 return reg;
c19d1205 22444
1f5afe1c
NC
22445 /* PR 16694: Allow VFP registers as well. */
22446 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22447 if (reg != FAIL)
22448 return 64 + reg;
c19d1205 22449
1f5afe1c
NC
22450 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22451 if (reg != FAIL)
22452 return reg + 256;
22453
22454 return -1;
bfae80f2
RE
22455}
22456
f0927246 22457#ifdef TE_PE
c19d1205 22458void
f0927246 22459tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22460{
91d6fa6a 22461 expressionS exp;
bfae80f2 22462
91d6fa6a
NC
22463 exp.X_op = O_secrel;
22464 exp.X_add_symbol = symbol;
22465 exp.X_add_number = 0;
22466 emit_expr (&exp, size);
f0927246
NC
22467}
22468#endif
bfae80f2 22469
c19d1205 22470/* MD interface: Symbol and relocation handling. */
bfae80f2 22471
2fc8bdac
ZW
22472/* Return the address within the segment that a PC-relative fixup is
22473 relative to. For ARM, PC-relative fixups applied to instructions
22474 are generally relative to the location of the fixup plus 8 bytes.
22475 Thumb branches are offset by 4, and Thumb loads relative to PC
22476 require special handling. */
bfae80f2 22477
c19d1205 22478long
2fc8bdac 22479md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22480{
2fc8bdac
ZW
22481 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22482
22483 /* If this is pc-relative and we are going to emit a relocation
22484 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22485 will need. Otherwise we want to use the calculated base.
22486 For WinCE we skip the bias for externals as well, since this
22487 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22488 if (fixP->fx_pcrel
2fc8bdac 22489 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22490 || (arm_force_relocation (fixP)
22491#ifdef TE_WINCE
22492 && !S_IS_EXTERNAL (fixP->fx_addsy)
22493#endif
22494 )))
2fc8bdac 22495 base = 0;
bfae80f2 22496
267bf995 22497
c19d1205 22498 switch (fixP->fx_r_type)
bfae80f2 22499 {
2fc8bdac
ZW
22500 /* PC relative addressing on the Thumb is slightly odd as the
22501 bottom two bits of the PC are forced to zero for the
22502 calculation. This happens *after* application of the
22503 pipeline offset. However, Thumb adrl already adjusts for
22504 this, so we need not do it again. */
c19d1205 22505 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22506 return base & ~3;
c19d1205
ZW
22507
22508 case BFD_RELOC_ARM_THUMB_OFFSET:
22509 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22510 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22511 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22512 return (base + 4) & ~3;
c19d1205 22513
2fc8bdac
ZW
22514 /* Thumb branches are simply offset by +4. */
22515 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22516 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22517 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22518 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22519 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22520 return base + 4;
bfae80f2 22521
267bf995 22522 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22523 if (fixP->fx_addsy
22524 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22525 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22526 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22527 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22528 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22529 return base + 4;
22530
00adf2d4
JB
22531 /* BLX is like branches above, but forces the low two bits of PC to
22532 zero. */
486499d0
CL
22533 case BFD_RELOC_THUMB_PCREL_BLX:
22534 if (fixP->fx_addsy
22535 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22536 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22537 && THUMB_IS_FUNC (fixP->fx_addsy)
22538 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22539 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22540 return (base + 4) & ~3;
22541
2fc8bdac
ZW
22542 /* ARM mode branches are offset by +8. However, the Windows CE
22543 loader expects the relocation not to take this into account. */
267bf995 22544 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22545 if (fixP->fx_addsy
22546 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22547 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22548 && ARM_IS_FUNC (fixP->fx_addsy)
22549 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22550 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22551 return base + 8;
267bf995 22552
486499d0
CL
22553 case BFD_RELOC_ARM_PCREL_CALL:
22554 if (fixP->fx_addsy
22555 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22556 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22557 && THUMB_IS_FUNC (fixP->fx_addsy)
22558 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22559 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22560 return base + 8;
267bf995 22561
2fc8bdac 22562 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22563 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22564 case BFD_RELOC_ARM_PLT32:
c19d1205 22565#ifdef TE_WINCE
5f4273c7 22566 /* When handling fixups immediately, because we have already
477330fc 22567 discovered the value of a symbol, or the address of the frag involved
53baae48 22568 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22569 see fixup_segment() in write.c
22570 The S_IS_EXTERNAL test handles the case of global symbols.
22571 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22572 if (fixP->fx_pcrel
22573 && fixP->fx_addsy != NULL
22574 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22575 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22576 return base + 8;
2fc8bdac 22577 return base;
c19d1205 22578#else
2fc8bdac 22579 return base + 8;
c19d1205 22580#endif
2fc8bdac 22581
267bf995 22582
2fc8bdac
ZW
22583 /* ARM mode loads relative to PC are also offset by +8. Unlike
22584 branches, the Windows CE loader *does* expect the relocation
22585 to take this into account. */
22586 case BFD_RELOC_ARM_OFFSET_IMM:
22587 case BFD_RELOC_ARM_OFFSET_IMM8:
22588 case BFD_RELOC_ARM_HWLITERAL:
22589 case BFD_RELOC_ARM_LITERAL:
22590 case BFD_RELOC_ARM_CP_OFF_IMM:
22591 return base + 8;
22592
22593
22594 /* Other PC-relative relocations are un-offset. */
22595 default:
22596 return base;
22597 }
bfae80f2
RE
22598}
22599
8b2d793c
NC
22600static bfd_boolean flag_warn_syms = TRUE;
22601
ae8714c2
NC
22602bfd_boolean
22603arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22604{
8b2d793c
NC
22605 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22606 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22607 does mean that the resulting code might be very confusing to the reader.
22608 Also this warning can be triggered if the user omits an operand before
22609 an immediate address, eg:
22610
22611 LDR =foo
22612
22613 GAS treats this as an assignment of the value of the symbol foo to a
22614 symbol LDR, and so (without this code) it will not issue any kind of
22615 warning or error message.
22616
22617 Note - ARM instructions are case-insensitive but the strings in the hash
22618 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22619 lower case too. */
22620 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22621 {
22622 char * nbuf = strdup (name);
22623 char * p;
22624
22625 for (p = nbuf; *p; p++)
22626 *p = TOLOWER (*p);
22627 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22628 {
22629 static struct hash_control * already_warned = NULL;
22630
22631 if (already_warned == NULL)
22632 already_warned = hash_new ();
22633 /* Only warn about the symbol once. To keep the code
22634 simple we let hash_insert do the lookup for us. */
22635 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22636 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22637 }
22638 else
22639 free (nbuf);
22640 }
3739860c 22641
ae8714c2
NC
22642 return FALSE;
22643}
22644
22645/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22646 Otherwise we have no need to default values of symbols. */
22647
22648symbolS *
22649md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22650{
22651#ifdef OBJ_ELF
22652 if (name[0] == '_' && name[1] == 'G'
22653 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22654 {
22655 if (!GOT_symbol)
22656 {
22657 if (symbol_find (name))
22658 as_bad (_("GOT already in the symbol table"));
22659
22660 GOT_symbol = symbol_new (name, undefined_section,
22661 (valueT) 0, & zero_address_frag);
22662 }
22663
22664 return GOT_symbol;
22665 }
22666#endif
22667
c921be7d 22668 return NULL;
bfae80f2
RE
22669}
22670
55cf6793 22671/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22672 computed as two separate immediate values, added together. We
22673 already know that this value cannot be computed by just one ARM
22674 instruction. */
22675
22676static unsigned int
22677validate_immediate_twopart (unsigned int val,
22678 unsigned int * highpart)
bfae80f2 22679{
c19d1205
ZW
22680 unsigned int a;
22681 unsigned int i;
bfae80f2 22682
c19d1205
ZW
22683 for (i = 0; i < 32; i += 2)
22684 if (((a = rotate_left (val, i)) & 0xff) != 0)
22685 {
22686 if (a & 0xff00)
22687 {
22688 if (a & ~ 0xffff)
22689 continue;
22690 * highpart = (a >> 8) | ((i + 24) << 7);
22691 }
22692 else if (a & 0xff0000)
22693 {
22694 if (a & 0xff000000)
22695 continue;
22696 * highpart = (a >> 16) | ((i + 16) << 7);
22697 }
22698 else
22699 {
9c2799c2 22700 gas_assert (a & 0xff000000);
c19d1205
ZW
22701 * highpart = (a >> 24) | ((i + 8) << 7);
22702 }
bfae80f2 22703
c19d1205
ZW
22704 return (a & 0xff) | (i << 7);
22705 }
bfae80f2 22706
c19d1205 22707 return FAIL;
bfae80f2
RE
22708}
22709
c19d1205
ZW
22710static int
22711validate_offset_imm (unsigned int val, int hwse)
22712{
22713 if ((hwse && val > 255) || val > 4095)
22714 return FAIL;
22715 return val;
22716}
bfae80f2 22717
55cf6793 22718/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22719 negative immediate constant by altering the instruction. A bit of
22720 a hack really.
22721 MOV <-> MVN
22722 AND <-> BIC
22723 ADC <-> SBC
22724 by inverting the second operand, and
22725 ADD <-> SUB
22726 CMP <-> CMN
22727 by negating the second operand. */
bfae80f2 22728
c19d1205
ZW
22729static int
22730negate_data_op (unsigned long * instruction,
22731 unsigned long value)
bfae80f2 22732{
c19d1205
ZW
22733 int op, new_inst;
22734 unsigned long negated, inverted;
bfae80f2 22735
c19d1205
ZW
22736 negated = encode_arm_immediate (-value);
22737 inverted = encode_arm_immediate (~value);
bfae80f2 22738
c19d1205
ZW
22739 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22740 switch (op)
bfae80f2 22741 {
c19d1205
ZW
22742 /* First negates. */
22743 case OPCODE_SUB: /* ADD <-> SUB */
22744 new_inst = OPCODE_ADD;
22745 value = negated;
22746 break;
bfae80f2 22747
c19d1205
ZW
22748 case OPCODE_ADD:
22749 new_inst = OPCODE_SUB;
22750 value = negated;
22751 break;
bfae80f2 22752
c19d1205
ZW
22753 case OPCODE_CMP: /* CMP <-> CMN */
22754 new_inst = OPCODE_CMN;
22755 value = negated;
22756 break;
bfae80f2 22757
c19d1205
ZW
22758 case OPCODE_CMN:
22759 new_inst = OPCODE_CMP;
22760 value = negated;
22761 break;
bfae80f2 22762
c19d1205
ZW
22763 /* Now Inverted ops. */
22764 case OPCODE_MOV: /* MOV <-> MVN */
22765 new_inst = OPCODE_MVN;
22766 value = inverted;
22767 break;
bfae80f2 22768
c19d1205
ZW
22769 case OPCODE_MVN:
22770 new_inst = OPCODE_MOV;
22771 value = inverted;
22772 break;
bfae80f2 22773
c19d1205
ZW
22774 case OPCODE_AND: /* AND <-> BIC */
22775 new_inst = OPCODE_BIC;
22776 value = inverted;
22777 break;
bfae80f2 22778
c19d1205
ZW
22779 case OPCODE_BIC:
22780 new_inst = OPCODE_AND;
22781 value = inverted;
22782 break;
bfae80f2 22783
c19d1205
ZW
22784 case OPCODE_ADC: /* ADC <-> SBC */
22785 new_inst = OPCODE_SBC;
22786 value = inverted;
22787 break;
bfae80f2 22788
c19d1205
ZW
22789 case OPCODE_SBC:
22790 new_inst = OPCODE_ADC;
22791 value = inverted;
22792 break;
bfae80f2 22793
c19d1205
ZW
22794 /* We cannot do anything. */
22795 default:
22796 return FAIL;
b99bd4ef
NC
22797 }
22798
c19d1205
ZW
22799 if (value == (unsigned) FAIL)
22800 return FAIL;
22801
22802 *instruction &= OPCODE_MASK;
22803 *instruction |= new_inst << DATA_OP_SHIFT;
22804 return value;
b99bd4ef
NC
22805}
22806
ef8d22e6
PB
22807/* Like negate_data_op, but for Thumb-2. */
22808
22809static unsigned int
16dd5e42 22810thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22811{
22812 int op, new_inst;
22813 int rd;
16dd5e42 22814 unsigned int negated, inverted;
ef8d22e6
PB
22815
22816 negated = encode_thumb32_immediate (-value);
22817 inverted = encode_thumb32_immediate (~value);
22818
22819 rd = (*instruction >> 8) & 0xf;
22820 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22821 switch (op)
22822 {
22823 /* ADD <-> SUB. Includes CMP <-> CMN. */
22824 case T2_OPCODE_SUB:
22825 new_inst = T2_OPCODE_ADD;
22826 value = negated;
22827 break;
22828
22829 case T2_OPCODE_ADD:
22830 new_inst = T2_OPCODE_SUB;
22831 value = negated;
22832 break;
22833
22834 /* ORR <-> ORN. Includes MOV <-> MVN. */
22835 case T2_OPCODE_ORR:
22836 new_inst = T2_OPCODE_ORN;
22837 value = inverted;
22838 break;
22839
22840 case T2_OPCODE_ORN:
22841 new_inst = T2_OPCODE_ORR;
22842 value = inverted;
22843 break;
22844
22845 /* AND <-> BIC. TST has no inverted equivalent. */
22846 case T2_OPCODE_AND:
22847 new_inst = T2_OPCODE_BIC;
22848 if (rd == 15)
22849 value = FAIL;
22850 else
22851 value = inverted;
22852 break;
22853
22854 case T2_OPCODE_BIC:
22855 new_inst = T2_OPCODE_AND;
22856 value = inverted;
22857 break;
22858
22859 /* ADC <-> SBC */
22860 case T2_OPCODE_ADC:
22861 new_inst = T2_OPCODE_SBC;
22862 value = inverted;
22863 break;
22864
22865 case T2_OPCODE_SBC:
22866 new_inst = T2_OPCODE_ADC;
22867 value = inverted;
22868 break;
22869
22870 /* We cannot do anything. */
22871 default:
22872 return FAIL;
22873 }
22874
16dd5e42 22875 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22876 return FAIL;
22877
22878 *instruction &= T2_OPCODE_MASK;
22879 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22880 return value;
22881}
22882
8f06b2d8
PB
22883/* Read a 32-bit thumb instruction from buf. */
22884static unsigned long
22885get_thumb32_insn (char * buf)
22886{
22887 unsigned long insn;
22888 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22889 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22890
22891 return insn;
22892}
22893
a8bc6c78
PB
22894
22895/* We usually want to set the low bit on the address of thumb function
22896 symbols. In particular .word foo - . should have the low bit set.
22897 Generic code tries to fold the difference of two symbols to
22898 a constant. Prevent this and force a relocation when the first symbols
22899 is a thumb function. */
c921be7d
NC
22900
22901bfd_boolean
a8bc6c78
PB
22902arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22903{
22904 if (op == O_subtract
22905 && l->X_op == O_symbol
22906 && r->X_op == O_symbol
22907 && THUMB_IS_FUNC (l->X_add_symbol))
22908 {
22909 l->X_op = O_subtract;
22910 l->X_op_symbol = r->X_add_symbol;
22911 l->X_add_number -= r->X_add_number;
c921be7d 22912 return TRUE;
a8bc6c78 22913 }
c921be7d 22914
a8bc6c78 22915 /* Process as normal. */
c921be7d 22916 return FALSE;
a8bc6c78
PB
22917}
22918
4a42ebbc
RR
22919/* Encode Thumb2 unconditional branches and calls. The encoding
22920 for the 2 are identical for the immediate values. */
22921
22922static void
22923encode_thumb2_b_bl_offset (char * buf, offsetT value)
22924{
22925#define T2I1I2MASK ((1 << 13) | (1 << 11))
22926 offsetT newval;
22927 offsetT newval2;
22928 addressT S, I1, I2, lo, hi;
22929
22930 S = (value >> 24) & 0x01;
22931 I1 = (value >> 23) & 0x01;
22932 I2 = (value >> 22) & 0x01;
22933 hi = (value >> 12) & 0x3ff;
fa94de6b 22934 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22935 newval = md_chars_to_number (buf, THUMB_SIZE);
22936 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22937 newval |= (S << 10) | hi;
22938 newval2 &= ~T2I1I2MASK;
22939 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22940 md_number_to_chars (buf, newval, THUMB_SIZE);
22941 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22942}
22943
c19d1205 22944void
55cf6793 22945md_apply_fix (fixS * fixP,
c19d1205
ZW
22946 valueT * valP,
22947 segT seg)
22948{
22949 offsetT value = * valP;
22950 offsetT newval;
22951 unsigned int newimm;
22952 unsigned long temp;
22953 int sign;
22954 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22955
9c2799c2 22956 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22957
c19d1205 22958 /* Note whether this will delete the relocation. */
4962c51a 22959
c19d1205
ZW
22960 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22961 fixP->fx_done = 1;
b99bd4ef 22962
adbaf948 22963 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22964 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22965 for emit_reloc. */
22966 value &= 0xffffffff;
22967 value ^= 0x80000000;
5f4273c7 22968 value -= 0x80000000;
adbaf948
ZW
22969
22970 *valP = value;
c19d1205 22971 fixP->fx_addnumber = value;
b99bd4ef 22972
adbaf948
ZW
22973 /* Same treatment for fixP->fx_offset. */
22974 fixP->fx_offset &= 0xffffffff;
22975 fixP->fx_offset ^= 0x80000000;
22976 fixP->fx_offset -= 0x80000000;
22977
c19d1205 22978 switch (fixP->fx_r_type)
b99bd4ef 22979 {
c19d1205
ZW
22980 case BFD_RELOC_NONE:
22981 /* This will need to go in the object file. */
22982 fixP->fx_done = 0;
22983 break;
b99bd4ef 22984
c19d1205
ZW
22985 case BFD_RELOC_ARM_IMMEDIATE:
22986 /* We claim that this fixup has been processed here,
22987 even if in fact we generate an error because we do
22988 not have a reloc for it, so tc_gen_reloc will reject it. */
22989 fixP->fx_done = 1;
b99bd4ef 22990
77db8e2e 22991 if (fixP->fx_addsy)
b99bd4ef 22992 {
77db8e2e 22993 const char *msg = 0;
b99bd4ef 22994
77db8e2e
NC
22995 if (! S_IS_DEFINED (fixP->fx_addsy))
22996 msg = _("undefined symbol %s used as an immediate value");
22997 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22998 msg = _("symbol %s is in a different section");
22999 else if (S_IS_WEAK (fixP->fx_addsy))
23000 msg = _("symbol %s is weak and may be overridden later");
23001
23002 if (msg)
23003 {
23004 as_bad_where (fixP->fx_file, fixP->fx_line,
23005 msg, S_GET_NAME (fixP->fx_addsy));
23006 break;
23007 }
42e5fcbf
AS
23008 }
23009
c19d1205
ZW
23010 temp = md_chars_to_number (buf, INSN_SIZE);
23011
5e73442d
SL
23012 /* If the offset is negative, we should use encoding A2 for ADR. */
23013 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23014 newimm = negate_data_op (&temp, value);
23015 else
23016 {
23017 newimm = encode_arm_immediate (value);
23018
23019 /* If the instruction will fail, see if we can fix things up by
23020 changing the opcode. */
23021 if (newimm == (unsigned int) FAIL)
23022 newimm = negate_data_op (&temp, value);
bada4342
JW
23023 /* MOV accepts both ARM modified immediate (A1 encoding) and
23024 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23025 When disassembling, MOV is preferred when there is no encoding
23026 overlap. */
23027 if (newimm == (unsigned int) FAIL
23028 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23029 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23030 && !((temp >> SBIT_SHIFT) & 0x1)
23031 && value >= 0 && value <= 0xffff)
23032 {
23033 /* Clear bits[23:20] to change encoding from A1 to A2. */
23034 temp &= 0xff0fffff;
23035 /* Encoding high 4bits imm. Code below will encode the remaining
23036 low 12bits. */
23037 temp |= (value & 0x0000f000) << 4;
23038 newimm = value & 0x00000fff;
23039 }
5e73442d
SL
23040 }
23041
23042 if (newimm == (unsigned int) FAIL)
b99bd4ef 23043 {
c19d1205
ZW
23044 as_bad_where (fixP->fx_file, fixP->fx_line,
23045 _("invalid constant (%lx) after fixup"),
23046 (unsigned long) value);
23047 break;
b99bd4ef 23048 }
b99bd4ef 23049
c19d1205
ZW
23050 newimm |= (temp & 0xfffff000);
23051 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23052 break;
b99bd4ef 23053
c19d1205
ZW
23054 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23055 {
23056 unsigned int highpart = 0;
23057 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23058
77db8e2e 23059 if (fixP->fx_addsy)
42e5fcbf 23060 {
77db8e2e 23061 const char *msg = 0;
42e5fcbf 23062
77db8e2e
NC
23063 if (! S_IS_DEFINED (fixP->fx_addsy))
23064 msg = _("undefined symbol %s used as an immediate value");
23065 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23066 msg = _("symbol %s is in a different section");
23067 else if (S_IS_WEAK (fixP->fx_addsy))
23068 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23069
77db8e2e
NC
23070 if (msg)
23071 {
23072 as_bad_where (fixP->fx_file, fixP->fx_line,
23073 msg, S_GET_NAME (fixP->fx_addsy));
23074 break;
23075 }
23076 }
fa94de6b 23077
c19d1205
ZW
23078 newimm = encode_arm_immediate (value);
23079 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23080
c19d1205
ZW
23081 /* If the instruction will fail, see if we can fix things up by
23082 changing the opcode. */
23083 if (newimm == (unsigned int) FAIL
23084 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23085 {
23086 /* No ? OK - try using two ADD instructions to generate
23087 the value. */
23088 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23089
c19d1205
ZW
23090 /* Yes - then make sure that the second instruction is
23091 also an add. */
23092 if (newimm != (unsigned int) FAIL)
23093 newinsn = temp;
23094 /* Still No ? Try using a negated value. */
23095 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23096 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23097 /* Otherwise - give up. */
23098 else
23099 {
23100 as_bad_where (fixP->fx_file, fixP->fx_line,
23101 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23102 (long) value);
23103 break;
23104 }
b99bd4ef 23105
c19d1205
ZW
23106 /* Replace the first operand in the 2nd instruction (which
23107 is the PC) with the destination register. We have
23108 already added in the PC in the first instruction and we
23109 do not want to do it again. */
23110 newinsn &= ~ 0xf0000;
23111 newinsn |= ((newinsn & 0x0f000) << 4);
23112 }
b99bd4ef 23113
c19d1205
ZW
23114 newimm |= (temp & 0xfffff000);
23115 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23116
c19d1205
ZW
23117 highpart |= (newinsn & 0xfffff000);
23118 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23119 }
23120 break;
b99bd4ef 23121
c19d1205 23122 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23123 if (!fixP->fx_done && seg->use_rela_p)
23124 value = 0;
1a0670f3 23125 /* Fall through. */
00a97672 23126
c19d1205 23127 case BFD_RELOC_ARM_LITERAL:
26d97720 23128 sign = value > 0;
b99bd4ef 23129
c19d1205
ZW
23130 if (value < 0)
23131 value = - value;
b99bd4ef 23132
c19d1205 23133 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23134 {
c19d1205
ZW
23135 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23136 as_bad_where (fixP->fx_file, fixP->fx_line,
23137 _("invalid literal constant: pool needs to be closer"));
23138 else
23139 as_bad_where (fixP->fx_file, fixP->fx_line,
23140 _("bad immediate value for offset (%ld)"),
23141 (long) value);
23142 break;
f03698e6
RE
23143 }
23144
c19d1205 23145 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23146 if (value == 0)
23147 newval &= 0xfffff000;
23148 else
23149 {
23150 newval &= 0xff7ff000;
23151 newval |= value | (sign ? INDEX_UP : 0);
23152 }
c19d1205
ZW
23153 md_number_to_chars (buf, newval, INSN_SIZE);
23154 break;
b99bd4ef 23155
c19d1205
ZW
23156 case BFD_RELOC_ARM_OFFSET_IMM8:
23157 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23158 sign = value > 0;
b99bd4ef 23159
c19d1205
ZW
23160 if (value < 0)
23161 value = - value;
b99bd4ef 23162
c19d1205 23163 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23164 {
c19d1205
ZW
23165 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23166 as_bad_where (fixP->fx_file, fixP->fx_line,
23167 _("invalid literal constant: pool needs to be closer"));
23168 else
427d0db6
RM
23169 as_bad_where (fixP->fx_file, fixP->fx_line,
23170 _("bad immediate value for 8-bit offset (%ld)"),
23171 (long) value);
c19d1205 23172 break;
b99bd4ef
NC
23173 }
23174
c19d1205 23175 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23176 if (value == 0)
23177 newval &= 0xfffff0f0;
23178 else
23179 {
23180 newval &= 0xff7ff0f0;
23181 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23182 }
c19d1205
ZW
23183 md_number_to_chars (buf, newval, INSN_SIZE);
23184 break;
b99bd4ef 23185
c19d1205
ZW
23186 case BFD_RELOC_ARM_T32_OFFSET_U8:
23187 if (value < 0 || value > 1020 || value % 4 != 0)
23188 as_bad_where (fixP->fx_file, fixP->fx_line,
23189 _("bad immediate value for offset (%ld)"), (long) value);
23190 value /= 4;
b99bd4ef 23191
c19d1205 23192 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23193 newval |= value;
23194 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23195 break;
b99bd4ef 23196
c19d1205
ZW
23197 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23198 /* This is a complicated relocation used for all varieties of Thumb32
23199 load/store instruction with immediate offset:
23200
23201 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23202 *4, optional writeback(W)
c19d1205
ZW
23203 (doubleword load/store)
23204
23205 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23206 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23207 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23208 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23209 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23210
23211 Uppercase letters indicate bits that are already encoded at
23212 this point. Lowercase letters are our problem. For the
23213 second block of instructions, the secondary opcode nybble
23214 (bits 8..11) is present, and bit 23 is zero, even if this is
23215 a PC-relative operation. */
23216 newval = md_chars_to_number (buf, THUMB_SIZE);
23217 newval <<= 16;
23218 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23219
c19d1205 23220 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23221 {
c19d1205
ZW
23222 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23223 if (value >= 0)
23224 newval |= (1 << 23);
23225 else
23226 value = -value;
23227 if (value % 4 != 0)
23228 {
23229 as_bad_where (fixP->fx_file, fixP->fx_line,
23230 _("offset not a multiple of 4"));
23231 break;
23232 }
23233 value /= 4;
216d22bc 23234 if (value > 0xff)
c19d1205
ZW
23235 {
23236 as_bad_where (fixP->fx_file, fixP->fx_line,
23237 _("offset out of range"));
23238 break;
23239 }
23240 newval &= ~0xff;
b99bd4ef 23241 }
c19d1205 23242 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23243 {
c19d1205
ZW
23244 /* PC-relative, 12-bit offset. */
23245 if (value >= 0)
23246 newval |= (1 << 23);
23247 else
23248 value = -value;
216d22bc 23249 if (value > 0xfff)
c19d1205
ZW
23250 {
23251 as_bad_where (fixP->fx_file, fixP->fx_line,
23252 _("offset out of range"));
23253 break;
23254 }
23255 newval &= ~0xfff;
b99bd4ef 23256 }
c19d1205 23257 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23258 {
c19d1205
ZW
23259 /* Writeback: 8-bit, +/- offset. */
23260 if (value >= 0)
23261 newval |= (1 << 9);
23262 else
23263 value = -value;
216d22bc 23264 if (value > 0xff)
c19d1205
ZW
23265 {
23266 as_bad_where (fixP->fx_file, fixP->fx_line,
23267 _("offset out of range"));
23268 break;
23269 }
23270 newval &= ~0xff;
b99bd4ef 23271 }
c19d1205 23272 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23273 {
c19d1205 23274 /* T-instruction: positive 8-bit offset. */
216d22bc 23275 if (value < 0 || value > 0xff)
b99bd4ef 23276 {
c19d1205
ZW
23277 as_bad_where (fixP->fx_file, fixP->fx_line,
23278 _("offset out of range"));
23279 break;
b99bd4ef 23280 }
c19d1205
ZW
23281 newval &= ~0xff;
23282 newval |= value;
b99bd4ef
NC
23283 }
23284 else
b99bd4ef 23285 {
c19d1205
ZW
23286 /* Positive 12-bit or negative 8-bit offset. */
23287 int limit;
23288 if (value >= 0)
b99bd4ef 23289 {
c19d1205
ZW
23290 newval |= (1 << 23);
23291 limit = 0xfff;
23292 }
23293 else
23294 {
23295 value = -value;
23296 limit = 0xff;
23297 }
23298 if (value > limit)
23299 {
23300 as_bad_where (fixP->fx_file, fixP->fx_line,
23301 _("offset out of range"));
23302 break;
b99bd4ef 23303 }
c19d1205 23304 newval &= ~limit;
b99bd4ef 23305 }
b99bd4ef 23306
c19d1205
ZW
23307 newval |= value;
23308 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23309 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23310 break;
404ff6b5 23311
c19d1205
ZW
23312 case BFD_RELOC_ARM_SHIFT_IMM:
23313 newval = md_chars_to_number (buf, INSN_SIZE);
23314 if (((unsigned long) value) > 32
23315 || (value == 32
23316 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23317 {
23318 as_bad_where (fixP->fx_file, fixP->fx_line,
23319 _("shift expression is too large"));
23320 break;
23321 }
404ff6b5 23322
c19d1205
ZW
23323 if (value == 0)
23324 /* Shifts of zero must be done as lsl. */
23325 newval &= ~0x60;
23326 else if (value == 32)
23327 value = 0;
23328 newval &= 0xfffff07f;
23329 newval |= (value & 0x1f) << 7;
23330 md_number_to_chars (buf, newval, INSN_SIZE);
23331 break;
404ff6b5 23332
c19d1205 23333 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23334 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23335 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23336 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23337 /* We claim that this fixup has been processed here,
23338 even if in fact we generate an error because we do
23339 not have a reloc for it, so tc_gen_reloc will reject it. */
23340 fixP->fx_done = 1;
404ff6b5 23341
c19d1205
ZW
23342 if (fixP->fx_addsy
23343 && ! S_IS_DEFINED (fixP->fx_addsy))
23344 {
23345 as_bad_where (fixP->fx_file, fixP->fx_line,
23346 _("undefined symbol %s used as an immediate value"),
23347 S_GET_NAME (fixP->fx_addsy));
23348 break;
23349 }
404ff6b5 23350
c19d1205
ZW
23351 newval = md_chars_to_number (buf, THUMB_SIZE);
23352 newval <<= 16;
23353 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23354
16805f35 23355 newimm = FAIL;
bada4342
JW
23356 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23357 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23358 Thumb2 modified immediate encoding (T2). */
23359 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23360 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23361 {
23362 newimm = encode_thumb32_immediate (value);
23363 if (newimm == (unsigned int) FAIL)
23364 newimm = thumb32_negate_data_op (&newval, value);
23365 }
bada4342 23366 if (newimm == (unsigned int) FAIL)
92e90b6e 23367 {
bada4342 23368 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23369 {
bada4342
JW
23370 /* Turn add/sum into addw/subw. */
23371 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23372 newval = (newval & 0xfeffffff) | 0x02000000;
23373 /* No flat 12-bit imm encoding for addsw/subsw. */
23374 if ((newval & 0x00100000) == 0)
40f246e3 23375 {
bada4342
JW
23376 /* 12 bit immediate for addw/subw. */
23377 if (value < 0)
23378 {
23379 value = -value;
23380 newval ^= 0x00a00000;
23381 }
23382 if (value > 0xfff)
23383 newimm = (unsigned int) FAIL;
23384 else
23385 newimm = value;
23386 }
23387 }
23388 else
23389 {
23390 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23391 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23392 disassembling, MOV is preferred when there is no encoding
23393 overlap.
23394 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23395 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23396 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23397 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23398 && value >= 0 && value <=0xffff)
23399 {
23400 /* Toggle bit[25] to change encoding from T2 to T3. */
23401 newval ^= 1 << 25;
23402 /* Clear bits[19:16]. */
23403 newval &= 0xfff0ffff;
23404 /* Encoding high 4bits imm. Code below will encode the
23405 remaining low 12bits. */
23406 newval |= (value & 0x0000f000) << 4;
23407 newimm = value & 0x00000fff;
40f246e3 23408 }
e9f89963 23409 }
92e90b6e 23410 }
cc8a6dd0 23411
c19d1205 23412 if (newimm == (unsigned int)FAIL)
3631a3c8 23413 {
c19d1205
ZW
23414 as_bad_where (fixP->fx_file, fixP->fx_line,
23415 _("invalid constant (%lx) after fixup"),
23416 (unsigned long) value);
23417 break;
3631a3c8
NC
23418 }
23419
c19d1205
ZW
23420 newval |= (newimm & 0x800) << 15;
23421 newval |= (newimm & 0x700) << 4;
23422 newval |= (newimm & 0x0ff);
cc8a6dd0 23423
c19d1205
ZW
23424 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23425 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23426 break;
a737bd4d 23427
3eb17e6b 23428 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23429 if (((unsigned long) value) > 0xffff)
23430 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23431 _("invalid smc expression"));
2fc8bdac 23432 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23433 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23434 md_number_to_chars (buf, newval, INSN_SIZE);
23435 break;
a737bd4d 23436
90ec0d68
MGD
23437 case BFD_RELOC_ARM_HVC:
23438 if (((unsigned long) value) > 0xffff)
23439 as_bad_where (fixP->fx_file, fixP->fx_line,
23440 _("invalid hvc expression"));
23441 newval = md_chars_to_number (buf, INSN_SIZE);
23442 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23443 md_number_to_chars (buf, newval, INSN_SIZE);
23444 break;
23445
c19d1205 23446 case BFD_RELOC_ARM_SWI:
adbaf948 23447 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23448 {
23449 if (((unsigned long) value) > 0xff)
23450 as_bad_where (fixP->fx_file, fixP->fx_line,
23451 _("invalid swi expression"));
2fc8bdac 23452 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23453 newval |= value;
23454 md_number_to_chars (buf, newval, THUMB_SIZE);
23455 }
23456 else
23457 {
23458 if (((unsigned long) value) > 0x00ffffff)
23459 as_bad_where (fixP->fx_file, fixP->fx_line,
23460 _("invalid swi expression"));
2fc8bdac 23461 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23462 newval |= value;
23463 md_number_to_chars (buf, newval, INSN_SIZE);
23464 }
23465 break;
a737bd4d 23466
c19d1205
ZW
23467 case BFD_RELOC_ARM_MULTI:
23468 if (((unsigned long) value) > 0xffff)
23469 as_bad_where (fixP->fx_file, fixP->fx_line,
23470 _("invalid expression in load/store multiple"));
23471 newval = value | md_chars_to_number (buf, INSN_SIZE);
23472 md_number_to_chars (buf, newval, INSN_SIZE);
23473 break;
a737bd4d 23474
c19d1205 23475#ifdef OBJ_ELF
39b41c9c 23476 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23477
23478 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23479 && fixP->fx_addsy
34e77a92 23480 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23481 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23482 && THUMB_IS_FUNC (fixP->fx_addsy))
23483 /* Flip the bl to blx. This is a simple flip
23484 bit here because we generate PCREL_CALL for
23485 unconditional bls. */
23486 {
23487 newval = md_chars_to_number (buf, INSN_SIZE);
23488 newval = newval | 0x10000000;
23489 md_number_to_chars (buf, newval, INSN_SIZE);
23490 temp = 1;
23491 fixP->fx_done = 1;
23492 }
39b41c9c
PB
23493 else
23494 temp = 3;
23495 goto arm_branch_common;
23496
23497 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23498 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23499 && fixP->fx_addsy
34e77a92 23500 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23501 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23502 && THUMB_IS_FUNC (fixP->fx_addsy))
23503 {
23504 /* This would map to a bl<cond>, b<cond>,
23505 b<always> to a Thumb function. We
23506 need to force a relocation for this particular
23507 case. */
23508 newval = md_chars_to_number (buf, INSN_SIZE);
23509 fixP->fx_done = 0;
23510 }
1a0670f3 23511 /* Fall through. */
267bf995 23512
2fc8bdac 23513 case BFD_RELOC_ARM_PLT32:
c19d1205 23514#endif
39b41c9c
PB
23515 case BFD_RELOC_ARM_PCREL_BRANCH:
23516 temp = 3;
23517 goto arm_branch_common;
a737bd4d 23518
39b41c9c 23519 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23520
39b41c9c 23521 temp = 1;
267bf995
RR
23522 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23523 && fixP->fx_addsy
34e77a92 23524 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23525 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23526 && ARM_IS_FUNC (fixP->fx_addsy))
23527 {
23528 /* Flip the blx to a bl and warn. */
23529 const char *name = S_GET_NAME (fixP->fx_addsy);
23530 newval = 0xeb000000;
23531 as_warn_where (fixP->fx_file, fixP->fx_line,
23532 _("blx to '%s' an ARM ISA state function changed to bl"),
23533 name);
23534 md_number_to_chars (buf, newval, INSN_SIZE);
23535 temp = 3;
23536 fixP->fx_done = 1;
23537 }
23538
23539#ifdef OBJ_ELF
23540 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23541 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23542#endif
23543
39b41c9c 23544 arm_branch_common:
c19d1205 23545 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23546 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23547 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23548 also be clear. */
39b41c9c 23549 if (value & temp)
c19d1205 23550 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23551 _("misaligned branch destination"));
23552 if ((value & (offsetT)0xfe000000) != (offsetT)0
23553 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23554 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23555
2fc8bdac 23556 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23557 {
2fc8bdac
ZW
23558 newval = md_chars_to_number (buf, INSN_SIZE);
23559 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23560 /* Set the H bit on BLX instructions. */
23561 if (temp == 1)
23562 {
23563 if (value & 2)
23564 newval |= 0x01000000;
23565 else
23566 newval &= ~0x01000000;
23567 }
2fc8bdac 23568 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23569 }
c19d1205 23570 break;
a737bd4d 23571
25fe350b
MS
23572 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23573 /* CBZ can only branch forward. */
a737bd4d 23574
738755b0 23575 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23576 (which, strictly speaking, are prohibited) will be turned into
23577 no-ops.
738755b0
MS
23578
23579 FIXME: It may be better to remove the instruction completely and
23580 perform relaxation. */
23581 if (value == -2)
2fc8bdac
ZW
23582 {
23583 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23584 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23585 md_number_to_chars (buf, newval, THUMB_SIZE);
23586 }
738755b0
MS
23587 else
23588 {
23589 if (value & ~0x7e)
08f10d51 23590 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23591
477330fc 23592 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23593 {
23594 newval = md_chars_to_number (buf, THUMB_SIZE);
23595 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23596 md_number_to_chars (buf, newval, THUMB_SIZE);
23597 }
23598 }
c19d1205 23599 break;
a737bd4d 23600
c19d1205 23601 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23602 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23603 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23604
2fc8bdac
ZW
23605 if (fixP->fx_done || !seg->use_rela_p)
23606 {
23607 newval = md_chars_to_number (buf, THUMB_SIZE);
23608 newval |= (value & 0x1ff) >> 1;
23609 md_number_to_chars (buf, newval, THUMB_SIZE);
23610 }
c19d1205 23611 break;
a737bd4d 23612
c19d1205 23613 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23614 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23615 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23616
2fc8bdac
ZW
23617 if (fixP->fx_done || !seg->use_rela_p)
23618 {
23619 newval = md_chars_to_number (buf, THUMB_SIZE);
23620 newval |= (value & 0xfff) >> 1;
23621 md_number_to_chars (buf, newval, THUMB_SIZE);
23622 }
c19d1205 23623 break;
a737bd4d 23624
c19d1205 23625 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23626 if (fixP->fx_addsy
23627 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23628 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23629 && ARM_IS_FUNC (fixP->fx_addsy)
23630 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23631 {
23632 /* Force a relocation for a branch 20 bits wide. */
23633 fixP->fx_done = 0;
23634 }
08f10d51 23635 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23636 as_bad_where (fixP->fx_file, fixP->fx_line,
23637 _("conditional branch out of range"));
404ff6b5 23638
2fc8bdac
ZW
23639 if (fixP->fx_done || !seg->use_rela_p)
23640 {
23641 offsetT newval2;
23642 addressT S, J1, J2, lo, hi;
404ff6b5 23643
2fc8bdac
ZW
23644 S = (value & 0x00100000) >> 20;
23645 J2 = (value & 0x00080000) >> 19;
23646 J1 = (value & 0x00040000) >> 18;
23647 hi = (value & 0x0003f000) >> 12;
23648 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23649
2fc8bdac
ZW
23650 newval = md_chars_to_number (buf, THUMB_SIZE);
23651 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23652 newval |= (S << 10) | hi;
23653 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23654 md_number_to_chars (buf, newval, THUMB_SIZE);
23655 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23656 }
c19d1205 23657 break;
6c43fab6 23658
c19d1205 23659 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23660 /* If there is a blx from a thumb state function to
23661 another thumb function flip this to a bl and warn
23662 about it. */
23663
23664 if (fixP->fx_addsy
34e77a92 23665 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23666 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23667 && THUMB_IS_FUNC (fixP->fx_addsy))
23668 {
23669 const char *name = S_GET_NAME (fixP->fx_addsy);
23670 as_warn_where (fixP->fx_file, fixP->fx_line,
23671 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23672 name);
23673 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23674 newval = newval | 0x1000;
23675 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23676 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23677 fixP->fx_done = 1;
23678 }
23679
23680
23681 goto thumb_bl_common;
23682
c19d1205 23683 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23684 /* A bl from Thumb state ISA to an internal ARM state function
23685 is converted to a blx. */
23686 if (fixP->fx_addsy
23687 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23688 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23689 && ARM_IS_FUNC (fixP->fx_addsy)
23690 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23691 {
23692 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23693 newval = newval & ~0x1000;
23694 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23695 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23696 fixP->fx_done = 1;
23697 }
23698
23699 thumb_bl_common:
23700
2fc8bdac
ZW
23701 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23702 /* For a BLX instruction, make sure that the relocation is rounded up
23703 to a word boundary. This follows the semantics of the instruction
23704 which specifies that bit 1 of the target address will come from bit
23705 1 of the base address. */
d406f3e4
JB
23706 value = (value + 3) & ~ 3;
23707
23708#ifdef OBJ_ELF
23709 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23710 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23711 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23712#endif
404ff6b5 23713
2b2f5df9
NC
23714 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23715 {
fc289b0a 23716 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23717 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23718 else if ((value & ~0x1ffffff)
23719 && ((value & ~0x1ffffff) != ~0x1ffffff))
23720 as_bad_where (fixP->fx_file, fixP->fx_line,
23721 _("Thumb2 branch out of range"));
23722 }
4a42ebbc
RR
23723
23724 if (fixP->fx_done || !seg->use_rela_p)
23725 encode_thumb2_b_bl_offset (buf, value);
23726
c19d1205 23727 break;
404ff6b5 23728
c19d1205 23729 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23730 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23731 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23732
2fc8bdac 23733 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23734 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23735
2fc8bdac 23736 break;
a737bd4d 23737
2fc8bdac
ZW
23738 case BFD_RELOC_8:
23739 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23740 *buf = value;
c19d1205 23741 break;
a737bd4d 23742
c19d1205 23743 case BFD_RELOC_16:
2fc8bdac 23744 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23745 md_number_to_chars (buf, value, 2);
c19d1205 23746 break;
a737bd4d 23747
c19d1205 23748#ifdef OBJ_ELF
0855e32b
NS
23749 case BFD_RELOC_ARM_TLS_CALL:
23750 case BFD_RELOC_ARM_THM_TLS_CALL:
23751 case BFD_RELOC_ARM_TLS_DESCSEQ:
23752 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23753 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23754 case BFD_RELOC_ARM_TLS_GD32:
23755 case BFD_RELOC_ARM_TLS_LE32:
23756 case BFD_RELOC_ARM_TLS_IE32:
23757 case BFD_RELOC_ARM_TLS_LDM32:
23758 case BFD_RELOC_ARM_TLS_LDO32:
23759 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23760 break;
6c43fab6 23761
c19d1205
ZW
23762 case BFD_RELOC_ARM_GOT32:
23763 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23764 break;
b43420e6
NC
23765
23766 case BFD_RELOC_ARM_GOT_PREL:
23767 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23768 md_number_to_chars (buf, value, 4);
b43420e6
NC
23769 break;
23770
9a6f4e97
NS
23771 case BFD_RELOC_ARM_TARGET2:
23772 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23773 addend here for REL targets, because it won't be written out
23774 during reloc processing later. */
9a6f4e97
NS
23775 if (fixP->fx_done || !seg->use_rela_p)
23776 md_number_to_chars (buf, fixP->fx_offset, 4);
23777 break;
c19d1205 23778#endif
6c43fab6 23779
c19d1205
ZW
23780 case BFD_RELOC_RVA:
23781 case BFD_RELOC_32:
23782 case BFD_RELOC_ARM_TARGET1:
23783 case BFD_RELOC_ARM_ROSEGREL32:
23784 case BFD_RELOC_ARM_SBREL32:
23785 case BFD_RELOC_32_PCREL:
f0927246
NC
23786#ifdef TE_PE
23787 case BFD_RELOC_32_SECREL:
23788#endif
2fc8bdac 23789 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23790#ifdef TE_WINCE
23791 /* For WinCE we only do this for pcrel fixups. */
23792 if (fixP->fx_done || fixP->fx_pcrel)
23793#endif
23794 md_number_to_chars (buf, value, 4);
c19d1205 23795 break;
6c43fab6 23796
c19d1205
ZW
23797#ifdef OBJ_ELF
23798 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23799 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23800 {
23801 newval = md_chars_to_number (buf, 4) & 0x80000000;
23802 if ((value ^ (value >> 1)) & 0x40000000)
23803 {
23804 as_bad_where (fixP->fx_file, fixP->fx_line,
23805 _("rel31 relocation overflow"));
23806 }
23807 newval |= value & 0x7fffffff;
23808 md_number_to_chars (buf, newval, 4);
23809 }
23810 break;
c19d1205 23811#endif
a737bd4d 23812
c19d1205 23813 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23814 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23815 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23816 newval = md_chars_to_number (buf, INSN_SIZE);
23817 else
23818 newval = get_thumb32_insn (buf);
23819 if ((newval & 0x0f200f00) == 0x0d000900)
23820 {
23821 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23822 has permitted values that are multiples of 2, in the range 0
23823 to 510. */
23824 if (value < -510 || value > 510 || (value & 1))
23825 as_bad_where (fixP->fx_file, fixP->fx_line,
23826 _("co-processor offset out of range"));
23827 }
23828 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23829 as_bad_where (fixP->fx_file, fixP->fx_line,
23830 _("co-processor offset out of range"));
23831 cp_off_common:
26d97720 23832 sign = value > 0;
c19d1205
ZW
23833 if (value < 0)
23834 value = -value;
8f06b2d8
PB
23835 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23836 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23837 newval = md_chars_to_number (buf, INSN_SIZE);
23838 else
23839 newval = get_thumb32_insn (buf);
26d97720
NS
23840 if (value == 0)
23841 newval &= 0xffffff00;
23842 else
23843 {
23844 newval &= 0xff7fff00;
9db2f6b4
RL
23845 if ((newval & 0x0f200f00) == 0x0d000900)
23846 {
23847 /* This is a fp16 vstr/vldr.
23848
23849 It requires the immediate offset in the instruction is shifted
23850 left by 1 to be a half-word offset.
23851
23852 Here, left shift by 1 first, and later right shift by 2
23853 should get the right offset. */
23854 value <<= 1;
23855 }
26d97720
NS
23856 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23857 }
8f06b2d8
PB
23858 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23859 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23860 md_number_to_chars (buf, newval, INSN_SIZE);
23861 else
23862 put_thumb32_insn (buf, newval);
c19d1205 23863 break;
a737bd4d 23864
c19d1205 23865 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23866 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23867 if (value < -255 || value > 255)
23868 as_bad_where (fixP->fx_file, fixP->fx_line,
23869 _("co-processor offset out of range"));
df7849c5 23870 value *= 4;
c19d1205 23871 goto cp_off_common;
6c43fab6 23872
c19d1205
ZW
23873 case BFD_RELOC_ARM_THUMB_OFFSET:
23874 newval = md_chars_to_number (buf, THUMB_SIZE);
23875 /* Exactly what ranges, and where the offset is inserted depends
23876 on the type of instruction, we can establish this from the
23877 top 4 bits. */
23878 switch (newval >> 12)
23879 {
23880 case 4: /* PC load. */
23881 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23882 forced to zero for these loads; md_pcrel_from has already
23883 compensated for this. */
23884 if (value & 3)
23885 as_bad_where (fixP->fx_file, fixP->fx_line,
23886 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23887 (((unsigned long) fixP->fx_frag->fr_address
23888 + (unsigned long) fixP->fx_where) & ~3)
23889 + (unsigned long) value);
a737bd4d 23890
c19d1205
ZW
23891 if (value & ~0x3fc)
23892 as_bad_where (fixP->fx_file, fixP->fx_line,
23893 _("invalid offset, value too big (0x%08lX)"),
23894 (long) value);
a737bd4d 23895
c19d1205
ZW
23896 newval |= value >> 2;
23897 break;
a737bd4d 23898
c19d1205
ZW
23899 case 9: /* SP load/store. */
23900 if (value & ~0x3fc)
23901 as_bad_where (fixP->fx_file, fixP->fx_line,
23902 _("invalid offset, value too big (0x%08lX)"),
23903 (long) value);
23904 newval |= value >> 2;
23905 break;
6c43fab6 23906
c19d1205
ZW
23907 case 6: /* Word load/store. */
23908 if (value & ~0x7c)
23909 as_bad_where (fixP->fx_file, fixP->fx_line,
23910 _("invalid offset, value too big (0x%08lX)"),
23911 (long) value);
23912 newval |= value << 4; /* 6 - 2. */
23913 break;
a737bd4d 23914
c19d1205
ZW
23915 case 7: /* Byte load/store. */
23916 if (value & ~0x1f)
23917 as_bad_where (fixP->fx_file, fixP->fx_line,
23918 _("invalid offset, value too big (0x%08lX)"),
23919 (long) value);
23920 newval |= value << 6;
23921 break;
a737bd4d 23922
c19d1205
ZW
23923 case 8: /* Halfword load/store. */
23924 if (value & ~0x3e)
23925 as_bad_where (fixP->fx_file, fixP->fx_line,
23926 _("invalid offset, value too big (0x%08lX)"),
23927 (long) value);
23928 newval |= value << 5; /* 6 - 1. */
23929 break;
a737bd4d 23930
c19d1205
ZW
23931 default:
23932 as_bad_where (fixP->fx_file, fixP->fx_line,
23933 "Unable to process relocation for thumb opcode: %lx",
23934 (unsigned long) newval);
23935 break;
23936 }
23937 md_number_to_chars (buf, newval, THUMB_SIZE);
23938 break;
a737bd4d 23939
c19d1205
ZW
23940 case BFD_RELOC_ARM_THUMB_ADD:
23941 /* This is a complicated relocation, since we use it for all of
23942 the following immediate relocations:
a737bd4d 23943
c19d1205
ZW
23944 3bit ADD/SUB
23945 8bit ADD/SUB
23946 9bit ADD/SUB SP word-aligned
23947 10bit ADD PC/SP word-aligned
a737bd4d 23948
c19d1205
ZW
23949 The type of instruction being processed is encoded in the
23950 instruction field:
a737bd4d 23951
c19d1205
ZW
23952 0x8000 SUB
23953 0x00F0 Rd
23954 0x000F Rs
23955 */
23956 newval = md_chars_to_number (buf, THUMB_SIZE);
23957 {
23958 int rd = (newval >> 4) & 0xf;
23959 int rs = newval & 0xf;
23960 int subtract = !!(newval & 0x8000);
a737bd4d 23961
c19d1205
ZW
23962 /* Check for HI regs, only very restricted cases allowed:
23963 Adjusting SP, and using PC or SP to get an address. */
23964 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23965 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23966 as_bad_where (fixP->fx_file, fixP->fx_line,
23967 _("invalid Hi register with immediate"));
a737bd4d 23968
c19d1205
ZW
23969 /* If value is negative, choose the opposite instruction. */
23970 if (value < 0)
23971 {
23972 value = -value;
23973 subtract = !subtract;
23974 if (value < 0)
23975 as_bad_where (fixP->fx_file, fixP->fx_line,
23976 _("immediate value out of range"));
23977 }
a737bd4d 23978
c19d1205
ZW
23979 if (rd == REG_SP)
23980 {
75c11999 23981 if (value & ~0x1fc)
c19d1205
ZW
23982 as_bad_where (fixP->fx_file, fixP->fx_line,
23983 _("invalid immediate for stack address calculation"));
23984 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23985 newval |= value >> 2;
23986 }
23987 else if (rs == REG_PC || rs == REG_SP)
23988 {
c12d2c9d
NC
23989 /* PR gas/18541. If the addition is for a defined symbol
23990 within range of an ADR instruction then accept it. */
23991 if (subtract
23992 && value == 4
23993 && fixP->fx_addsy != NULL)
23994 {
23995 subtract = 0;
23996
23997 if (! S_IS_DEFINED (fixP->fx_addsy)
23998 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23999 || S_IS_WEAK (fixP->fx_addsy))
24000 {
24001 as_bad_where (fixP->fx_file, fixP->fx_line,
24002 _("address calculation needs a strongly defined nearby symbol"));
24003 }
24004 else
24005 {
24006 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24007
24008 /* Round up to the next 4-byte boundary. */
24009 if (v & 3)
24010 v = (v + 3) & ~ 3;
24011 else
24012 v += 4;
24013 v = S_GET_VALUE (fixP->fx_addsy) - v;
24014
24015 if (v & ~0x3fc)
24016 {
24017 as_bad_where (fixP->fx_file, fixP->fx_line,
24018 _("symbol too far away"));
24019 }
24020 else
24021 {
24022 fixP->fx_done = 1;
24023 value = v;
24024 }
24025 }
24026 }
24027
c19d1205
ZW
24028 if (subtract || value & ~0x3fc)
24029 as_bad_where (fixP->fx_file, fixP->fx_line,
24030 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24031 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24032 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24033 newval |= rd << 8;
24034 newval |= value >> 2;
24035 }
24036 else if (rs == rd)
24037 {
24038 if (value & ~0xff)
24039 as_bad_where (fixP->fx_file, fixP->fx_line,
24040 _("immediate value out of range"));
24041 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24042 newval |= (rd << 8) | value;
24043 }
24044 else
24045 {
24046 if (value & ~0x7)
24047 as_bad_where (fixP->fx_file, fixP->fx_line,
24048 _("immediate value out of range"));
24049 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24050 newval |= rd | (rs << 3) | (value << 6);
24051 }
24052 }
24053 md_number_to_chars (buf, newval, THUMB_SIZE);
24054 break;
a737bd4d 24055
c19d1205
ZW
24056 case BFD_RELOC_ARM_THUMB_IMM:
24057 newval = md_chars_to_number (buf, THUMB_SIZE);
24058 if (value < 0 || value > 255)
24059 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24060 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24061 (long) value);
24062 newval |= value;
24063 md_number_to_chars (buf, newval, THUMB_SIZE);
24064 break;
a737bd4d 24065
c19d1205
ZW
24066 case BFD_RELOC_ARM_THUMB_SHIFT:
24067 /* 5bit shift value (0..32). LSL cannot take 32. */
24068 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24069 temp = newval & 0xf800;
24070 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24071 as_bad_where (fixP->fx_file, fixP->fx_line,
24072 _("invalid shift value: %ld"), (long) value);
24073 /* Shifts of zero must be encoded as LSL. */
24074 if (value == 0)
24075 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24076 /* Shifts of 32 are encoded as zero. */
24077 else if (value == 32)
24078 value = 0;
24079 newval |= value << 6;
24080 md_number_to_chars (buf, newval, THUMB_SIZE);
24081 break;
a737bd4d 24082
c19d1205
ZW
24083 case BFD_RELOC_VTABLE_INHERIT:
24084 case BFD_RELOC_VTABLE_ENTRY:
24085 fixP->fx_done = 0;
24086 return;
6c43fab6 24087
b6895b4f
PB
24088 case BFD_RELOC_ARM_MOVW:
24089 case BFD_RELOC_ARM_MOVT:
24090 case BFD_RELOC_ARM_THUMB_MOVW:
24091 case BFD_RELOC_ARM_THUMB_MOVT:
24092 if (fixP->fx_done || !seg->use_rela_p)
24093 {
24094 /* REL format relocations are limited to a 16-bit addend. */
24095 if (!fixP->fx_done)
24096 {
39623e12 24097 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24098 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24099 _("offset out of range"));
b6895b4f
PB
24100 }
24101 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24102 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24103 {
24104 value >>= 16;
24105 }
24106
24107 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24108 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24109 {
24110 newval = get_thumb32_insn (buf);
24111 newval &= 0xfbf08f00;
24112 newval |= (value & 0xf000) << 4;
24113 newval |= (value & 0x0800) << 15;
24114 newval |= (value & 0x0700) << 4;
24115 newval |= (value & 0x00ff);
24116 put_thumb32_insn (buf, newval);
24117 }
24118 else
24119 {
24120 newval = md_chars_to_number (buf, 4);
24121 newval &= 0xfff0f000;
24122 newval |= value & 0x0fff;
24123 newval |= (value & 0xf000) << 4;
24124 md_number_to_chars (buf, newval, 4);
24125 }
24126 }
24127 return;
24128
72d98d16
MG
24129 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24130 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24131 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24132 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24133 gas_assert (!fixP->fx_done);
24134 {
24135 bfd_vma insn;
24136 bfd_boolean is_mov;
24137 bfd_vma encoded_addend = value;
24138
24139 /* Check that addend can be encoded in instruction. */
24140 if (!seg->use_rela_p && (value < 0 || value > 255))
24141 as_bad_where (fixP->fx_file, fixP->fx_line,
24142 _("the offset 0x%08lX is not representable"),
24143 (unsigned long) encoded_addend);
24144
24145 /* Extract the instruction. */
24146 insn = md_chars_to_number (buf, THUMB_SIZE);
24147 is_mov = (insn & 0xf800) == 0x2000;
24148
24149 /* Encode insn. */
24150 if (is_mov)
24151 {
24152 if (!seg->use_rela_p)
24153 insn |= encoded_addend;
24154 }
24155 else
24156 {
24157 int rd, rs;
24158
24159 /* Extract the instruction. */
24160 /* Encoding is the following
24161 0x8000 SUB
24162 0x00F0 Rd
24163 0x000F Rs
24164 */
24165 /* The following conditions must be true :
24166 - ADD
24167 - Rd == Rs
24168 - Rd <= 7
24169 */
24170 rd = (insn >> 4) & 0xf;
24171 rs = insn & 0xf;
24172 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24173 as_bad_where (fixP->fx_file, fixP->fx_line,
24174 _("Unable to process relocation for thumb opcode: %lx"),
24175 (unsigned long) insn);
24176
24177 /* Encode as ADD immediate8 thumb 1 code. */
24178 insn = 0x3000 | (rd << 8);
24179
24180 /* Place the encoded addend into the first 8 bits of the
24181 instruction. */
24182 if (!seg->use_rela_p)
24183 insn |= encoded_addend;
24184 }
24185
24186 /* Update the instruction. */
24187 md_number_to_chars (buf, insn, THUMB_SIZE);
24188 }
24189 break;
24190
4962c51a
MS
24191 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24192 case BFD_RELOC_ARM_ALU_PC_G0:
24193 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24194 case BFD_RELOC_ARM_ALU_PC_G1:
24195 case BFD_RELOC_ARM_ALU_PC_G2:
24196 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24197 case BFD_RELOC_ARM_ALU_SB_G0:
24198 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24199 case BFD_RELOC_ARM_ALU_SB_G1:
24200 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24201 gas_assert (!fixP->fx_done);
4962c51a
MS
24202 if (!seg->use_rela_p)
24203 {
477330fc
RM
24204 bfd_vma insn;
24205 bfd_vma encoded_addend;
24206 bfd_vma addend_abs = abs (value);
24207
24208 /* Check that the absolute value of the addend can be
24209 expressed as an 8-bit constant plus a rotation. */
24210 encoded_addend = encode_arm_immediate (addend_abs);
24211 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24212 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24213 _("the offset 0x%08lX is not representable"),
24214 (unsigned long) addend_abs);
24215
24216 /* Extract the instruction. */
24217 insn = md_chars_to_number (buf, INSN_SIZE);
24218
24219 /* If the addend is positive, use an ADD instruction.
24220 Otherwise use a SUB. Take care not to destroy the S bit. */
24221 insn &= 0xff1fffff;
24222 if (value < 0)
24223 insn |= 1 << 22;
24224 else
24225 insn |= 1 << 23;
24226
24227 /* Place the encoded addend into the first 12 bits of the
24228 instruction. */
24229 insn &= 0xfffff000;
24230 insn |= encoded_addend;
24231
24232 /* Update the instruction. */
24233 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24234 }
24235 break;
24236
24237 case BFD_RELOC_ARM_LDR_PC_G0:
24238 case BFD_RELOC_ARM_LDR_PC_G1:
24239 case BFD_RELOC_ARM_LDR_PC_G2:
24240 case BFD_RELOC_ARM_LDR_SB_G0:
24241 case BFD_RELOC_ARM_LDR_SB_G1:
24242 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24243 gas_assert (!fixP->fx_done);
4962c51a 24244 if (!seg->use_rela_p)
477330fc
RM
24245 {
24246 bfd_vma insn;
24247 bfd_vma addend_abs = abs (value);
4962c51a 24248
477330fc
RM
24249 /* Check that the absolute value of the addend can be
24250 encoded in 12 bits. */
24251 if (addend_abs >= 0x1000)
4962c51a 24252 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24253 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24254 (unsigned long) addend_abs);
24255
24256 /* Extract the instruction. */
24257 insn = md_chars_to_number (buf, INSN_SIZE);
24258
24259 /* If the addend is negative, clear bit 23 of the instruction.
24260 Otherwise set it. */
24261 if (value < 0)
24262 insn &= ~(1 << 23);
24263 else
24264 insn |= 1 << 23;
24265
24266 /* Place the absolute value of the addend into the first 12 bits
24267 of the instruction. */
24268 insn &= 0xfffff000;
24269 insn |= addend_abs;
24270
24271 /* Update the instruction. */
24272 md_number_to_chars (buf, insn, INSN_SIZE);
24273 }
4962c51a
MS
24274 break;
24275
24276 case BFD_RELOC_ARM_LDRS_PC_G0:
24277 case BFD_RELOC_ARM_LDRS_PC_G1:
24278 case BFD_RELOC_ARM_LDRS_PC_G2:
24279 case BFD_RELOC_ARM_LDRS_SB_G0:
24280 case BFD_RELOC_ARM_LDRS_SB_G1:
24281 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24282 gas_assert (!fixP->fx_done);
4962c51a 24283 if (!seg->use_rela_p)
477330fc
RM
24284 {
24285 bfd_vma insn;
24286 bfd_vma addend_abs = abs (value);
4962c51a 24287
477330fc
RM
24288 /* Check that the absolute value of the addend can be
24289 encoded in 8 bits. */
24290 if (addend_abs >= 0x100)
4962c51a 24291 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24292 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24293 (unsigned long) addend_abs);
24294
24295 /* Extract the instruction. */
24296 insn = md_chars_to_number (buf, INSN_SIZE);
24297
24298 /* If the addend is negative, clear bit 23 of the instruction.
24299 Otherwise set it. */
24300 if (value < 0)
24301 insn &= ~(1 << 23);
24302 else
24303 insn |= 1 << 23;
24304
24305 /* Place the first four bits of the absolute value of the addend
24306 into the first 4 bits of the instruction, and the remaining
24307 four into bits 8 .. 11. */
24308 insn &= 0xfffff0f0;
24309 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24310
24311 /* Update the instruction. */
24312 md_number_to_chars (buf, insn, INSN_SIZE);
24313 }
4962c51a
MS
24314 break;
24315
24316 case BFD_RELOC_ARM_LDC_PC_G0:
24317 case BFD_RELOC_ARM_LDC_PC_G1:
24318 case BFD_RELOC_ARM_LDC_PC_G2:
24319 case BFD_RELOC_ARM_LDC_SB_G0:
24320 case BFD_RELOC_ARM_LDC_SB_G1:
24321 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24322 gas_assert (!fixP->fx_done);
4962c51a 24323 if (!seg->use_rela_p)
477330fc
RM
24324 {
24325 bfd_vma insn;
24326 bfd_vma addend_abs = abs (value);
4962c51a 24327
477330fc
RM
24328 /* Check that the absolute value of the addend is a multiple of
24329 four and, when divided by four, fits in 8 bits. */
24330 if (addend_abs & 0x3)
4962c51a 24331 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24332 _("bad offset 0x%08lX (must be word-aligned)"),
24333 (unsigned long) addend_abs);
4962c51a 24334
477330fc 24335 if ((addend_abs >> 2) > 0xff)
4962c51a 24336 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24337 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24338 (unsigned long) addend_abs);
24339
24340 /* Extract the instruction. */
24341 insn = md_chars_to_number (buf, INSN_SIZE);
24342
24343 /* If the addend is negative, clear bit 23 of the instruction.
24344 Otherwise set it. */
24345 if (value < 0)
24346 insn &= ~(1 << 23);
24347 else
24348 insn |= 1 << 23;
24349
24350 /* Place the addend (divided by four) into the first eight
24351 bits of the instruction. */
24352 insn &= 0xfffffff0;
24353 insn |= addend_abs >> 2;
24354
24355 /* Update the instruction. */
24356 md_number_to_chars (buf, insn, INSN_SIZE);
24357 }
4962c51a
MS
24358 break;
24359
845b51d6
PB
24360 case BFD_RELOC_ARM_V4BX:
24361 /* This will need to go in the object file. */
24362 fixP->fx_done = 0;
24363 break;
24364
c19d1205
ZW
24365 case BFD_RELOC_UNUSED:
24366 default:
24367 as_bad_where (fixP->fx_file, fixP->fx_line,
24368 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24369 }
6c43fab6
RE
24370}
24371
c19d1205
ZW
24372/* Translate internal representation of relocation info to BFD target
24373 format. */
a737bd4d 24374
c19d1205 24375arelent *
00a97672 24376tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24377{
c19d1205
ZW
24378 arelent * reloc;
24379 bfd_reloc_code_real_type code;
a737bd4d 24380
325801bd 24381 reloc = XNEW (arelent);
a737bd4d 24382
325801bd 24383 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24384 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24385 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24386
2fc8bdac 24387 if (fixp->fx_pcrel)
00a97672
RS
24388 {
24389 if (section->use_rela_p)
24390 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24391 else
24392 fixp->fx_offset = reloc->address;
24393 }
c19d1205 24394 reloc->addend = fixp->fx_offset;
a737bd4d 24395
c19d1205 24396 switch (fixp->fx_r_type)
a737bd4d 24397 {
c19d1205
ZW
24398 case BFD_RELOC_8:
24399 if (fixp->fx_pcrel)
24400 {
24401 code = BFD_RELOC_8_PCREL;
24402 break;
24403 }
1a0670f3 24404 /* Fall through. */
a737bd4d 24405
c19d1205
ZW
24406 case BFD_RELOC_16:
24407 if (fixp->fx_pcrel)
24408 {
24409 code = BFD_RELOC_16_PCREL;
24410 break;
24411 }
1a0670f3 24412 /* Fall through. */
6c43fab6 24413
c19d1205
ZW
24414 case BFD_RELOC_32:
24415 if (fixp->fx_pcrel)
24416 {
24417 code = BFD_RELOC_32_PCREL;
24418 break;
24419 }
1a0670f3 24420 /* Fall through. */
a737bd4d 24421
b6895b4f
PB
24422 case BFD_RELOC_ARM_MOVW:
24423 if (fixp->fx_pcrel)
24424 {
24425 code = BFD_RELOC_ARM_MOVW_PCREL;
24426 break;
24427 }
1a0670f3 24428 /* Fall through. */
b6895b4f
PB
24429
24430 case BFD_RELOC_ARM_MOVT:
24431 if (fixp->fx_pcrel)
24432 {
24433 code = BFD_RELOC_ARM_MOVT_PCREL;
24434 break;
24435 }
1a0670f3 24436 /* Fall through. */
b6895b4f
PB
24437
24438 case BFD_RELOC_ARM_THUMB_MOVW:
24439 if (fixp->fx_pcrel)
24440 {
24441 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24442 break;
24443 }
1a0670f3 24444 /* Fall through. */
b6895b4f
PB
24445
24446 case BFD_RELOC_ARM_THUMB_MOVT:
24447 if (fixp->fx_pcrel)
24448 {
24449 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24450 break;
24451 }
1a0670f3 24452 /* Fall through. */
b6895b4f 24453
c19d1205
ZW
24454 case BFD_RELOC_NONE:
24455 case BFD_RELOC_ARM_PCREL_BRANCH:
24456 case BFD_RELOC_ARM_PCREL_BLX:
24457 case BFD_RELOC_RVA:
24458 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24459 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24460 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24461 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24462 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24463 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24464 case BFD_RELOC_VTABLE_ENTRY:
24465 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24466#ifdef TE_PE
24467 case BFD_RELOC_32_SECREL:
24468#endif
c19d1205
ZW
24469 code = fixp->fx_r_type;
24470 break;
a737bd4d 24471
00adf2d4
JB
24472 case BFD_RELOC_THUMB_PCREL_BLX:
24473#ifdef OBJ_ELF
24474 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24475 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24476 else
24477#endif
24478 code = BFD_RELOC_THUMB_PCREL_BLX;
24479 break;
24480
c19d1205
ZW
24481 case BFD_RELOC_ARM_LITERAL:
24482 case BFD_RELOC_ARM_HWLITERAL:
24483 /* If this is called then the a literal has
24484 been referenced across a section boundary. */
24485 as_bad_where (fixp->fx_file, fixp->fx_line,
24486 _("literal referenced across section boundary"));
24487 return NULL;
a737bd4d 24488
c19d1205 24489#ifdef OBJ_ELF
0855e32b
NS
24490 case BFD_RELOC_ARM_TLS_CALL:
24491 case BFD_RELOC_ARM_THM_TLS_CALL:
24492 case BFD_RELOC_ARM_TLS_DESCSEQ:
24493 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24494 case BFD_RELOC_ARM_GOT32:
24495 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24496 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24497 case BFD_RELOC_ARM_PLT32:
24498 case BFD_RELOC_ARM_TARGET1:
24499 case BFD_RELOC_ARM_ROSEGREL32:
24500 case BFD_RELOC_ARM_SBREL32:
24501 case BFD_RELOC_ARM_PREL31:
24502 case BFD_RELOC_ARM_TARGET2:
c19d1205 24503 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24504 case BFD_RELOC_ARM_PCREL_CALL:
24505 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24506 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24507 case BFD_RELOC_ARM_ALU_PC_G0:
24508 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24509 case BFD_RELOC_ARM_ALU_PC_G1:
24510 case BFD_RELOC_ARM_ALU_PC_G2:
24511 case BFD_RELOC_ARM_LDR_PC_G0:
24512 case BFD_RELOC_ARM_LDR_PC_G1:
24513 case BFD_RELOC_ARM_LDR_PC_G2:
24514 case BFD_RELOC_ARM_LDRS_PC_G0:
24515 case BFD_RELOC_ARM_LDRS_PC_G1:
24516 case BFD_RELOC_ARM_LDRS_PC_G2:
24517 case BFD_RELOC_ARM_LDC_PC_G0:
24518 case BFD_RELOC_ARM_LDC_PC_G1:
24519 case BFD_RELOC_ARM_LDC_PC_G2:
24520 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24521 case BFD_RELOC_ARM_ALU_SB_G0:
24522 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24523 case BFD_RELOC_ARM_ALU_SB_G1:
24524 case BFD_RELOC_ARM_ALU_SB_G2:
24525 case BFD_RELOC_ARM_LDR_SB_G0:
24526 case BFD_RELOC_ARM_LDR_SB_G1:
24527 case BFD_RELOC_ARM_LDR_SB_G2:
24528 case BFD_RELOC_ARM_LDRS_SB_G0:
24529 case BFD_RELOC_ARM_LDRS_SB_G1:
24530 case BFD_RELOC_ARM_LDRS_SB_G2:
24531 case BFD_RELOC_ARM_LDC_SB_G0:
24532 case BFD_RELOC_ARM_LDC_SB_G1:
24533 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24534 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24535 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24536 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24537 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24538 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24539 code = fixp->fx_r_type;
24540 break;
a737bd4d 24541
0855e32b 24542 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24543 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24544 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24545 case BFD_RELOC_ARM_TLS_IE32:
24546 case BFD_RELOC_ARM_TLS_LDM32:
24547 /* BFD will include the symbol's address in the addend.
24548 But we don't want that, so subtract it out again here. */
24549 if (!S_IS_COMMON (fixp->fx_addsy))
24550 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24551 code = fixp->fx_r_type;
24552 break;
24553#endif
a737bd4d 24554
c19d1205
ZW
24555 case BFD_RELOC_ARM_IMMEDIATE:
24556 as_bad_where (fixp->fx_file, fixp->fx_line,
24557 _("internal relocation (type: IMMEDIATE) not fixed up"));
24558 return NULL;
a737bd4d 24559
c19d1205
ZW
24560 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24561 as_bad_where (fixp->fx_file, fixp->fx_line,
24562 _("ADRL used for a symbol not defined in the same file"));
24563 return NULL;
a737bd4d 24564
c19d1205 24565 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24566 if (section->use_rela_p)
24567 {
24568 code = fixp->fx_r_type;
24569 break;
24570 }
24571
c19d1205
ZW
24572 if (fixp->fx_addsy != NULL
24573 && !S_IS_DEFINED (fixp->fx_addsy)
24574 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24575 {
c19d1205
ZW
24576 as_bad_where (fixp->fx_file, fixp->fx_line,
24577 _("undefined local label `%s'"),
24578 S_GET_NAME (fixp->fx_addsy));
24579 return NULL;
a737bd4d
NC
24580 }
24581
c19d1205
ZW
24582 as_bad_where (fixp->fx_file, fixp->fx_line,
24583 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24584 return NULL;
a737bd4d 24585
c19d1205
ZW
24586 default:
24587 {
e0471c16 24588 const char * type;
6c43fab6 24589
c19d1205
ZW
24590 switch (fixp->fx_r_type)
24591 {
24592 case BFD_RELOC_NONE: type = "NONE"; break;
24593 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24594 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24595 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24596 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24597 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24598 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24599 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24600 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24601 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24602 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24603 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24604 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24605 default: type = _("<unknown>"); break;
24606 }
24607 as_bad_where (fixp->fx_file, fixp->fx_line,
24608 _("cannot represent %s relocation in this object file format"),
24609 type);
24610 return NULL;
24611 }
a737bd4d 24612 }
6c43fab6 24613
c19d1205
ZW
24614#ifdef OBJ_ELF
24615 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24616 && GOT_symbol
24617 && fixp->fx_addsy == GOT_symbol)
24618 {
24619 code = BFD_RELOC_ARM_GOTPC;
24620 reloc->addend = fixp->fx_offset = reloc->address;
24621 }
24622#endif
6c43fab6 24623
c19d1205 24624 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24625
c19d1205
ZW
24626 if (reloc->howto == NULL)
24627 {
24628 as_bad_where (fixp->fx_file, fixp->fx_line,
24629 _("cannot represent %s relocation in this object file format"),
24630 bfd_get_reloc_code_name (code));
24631 return NULL;
24632 }
6c43fab6 24633
c19d1205
ZW
24634 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24635 vtable entry to be used in the relocation's section offset. */
24636 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24637 reloc->address = fixp->fx_offset;
6c43fab6 24638
c19d1205 24639 return reloc;
6c43fab6
RE
24640}
24641
c19d1205 24642/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24643
c19d1205
ZW
24644void
24645cons_fix_new_arm (fragS * frag,
24646 int where,
24647 int size,
62ebcb5c
AM
24648 expressionS * exp,
24649 bfd_reloc_code_real_type reloc)
6c43fab6 24650{
c19d1205 24651 int pcrel = 0;
6c43fab6 24652
c19d1205
ZW
24653 /* Pick a reloc.
24654 FIXME: @@ Should look at CPU word size. */
24655 switch (size)
24656 {
24657 case 1:
62ebcb5c 24658 reloc = BFD_RELOC_8;
c19d1205
ZW
24659 break;
24660 case 2:
62ebcb5c 24661 reloc = BFD_RELOC_16;
c19d1205
ZW
24662 break;
24663 case 4:
24664 default:
62ebcb5c 24665 reloc = BFD_RELOC_32;
c19d1205
ZW
24666 break;
24667 case 8:
62ebcb5c 24668 reloc = BFD_RELOC_64;
c19d1205
ZW
24669 break;
24670 }
6c43fab6 24671
f0927246
NC
24672#ifdef TE_PE
24673 if (exp->X_op == O_secrel)
24674 {
24675 exp->X_op = O_symbol;
62ebcb5c 24676 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24677 }
24678#endif
24679
62ebcb5c 24680 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24681}
6c43fab6 24682
4343666d 24683#if defined (OBJ_COFF)
c19d1205
ZW
24684void
24685arm_validate_fix (fixS * fixP)
6c43fab6 24686{
c19d1205
ZW
24687 /* If the destination of the branch is a defined symbol which does not have
24688 the THUMB_FUNC attribute, then we must be calling a function which has
24689 the (interfacearm) attribute. We look for the Thumb entry point to that
24690 function and change the branch to refer to that function instead. */
24691 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24692 && fixP->fx_addsy != NULL
24693 && S_IS_DEFINED (fixP->fx_addsy)
24694 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24695 {
c19d1205 24696 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24697 }
c19d1205
ZW
24698}
24699#endif
6c43fab6 24700
267bf995 24701
c19d1205
ZW
24702int
24703arm_force_relocation (struct fix * fixp)
24704{
24705#if defined (OBJ_COFF) && defined (TE_PE)
24706 if (fixp->fx_r_type == BFD_RELOC_RVA)
24707 return 1;
24708#endif
6c43fab6 24709
267bf995
RR
24710 /* In case we have a call or a branch to a function in ARM ISA mode from
24711 a thumb function or vice-versa force the relocation. These relocations
24712 are cleared off for some cores that might have blx and simple transformations
24713 are possible. */
24714
24715#ifdef OBJ_ELF
24716 switch (fixp->fx_r_type)
24717 {
24718 case BFD_RELOC_ARM_PCREL_JUMP:
24719 case BFD_RELOC_ARM_PCREL_CALL:
24720 case BFD_RELOC_THUMB_PCREL_BLX:
24721 if (THUMB_IS_FUNC (fixp->fx_addsy))
24722 return 1;
24723 break;
24724
24725 case BFD_RELOC_ARM_PCREL_BLX:
24726 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24727 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24728 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24729 if (ARM_IS_FUNC (fixp->fx_addsy))
24730 return 1;
24731 break;
24732
24733 default:
24734 break;
24735 }
24736#endif
24737
b5884301
PB
24738 /* Resolve these relocations even if the symbol is extern or weak.
24739 Technically this is probably wrong due to symbol preemption.
24740 In practice these relocations do not have enough range to be useful
24741 at dynamic link time, and some code (e.g. in the Linux kernel)
24742 expects these references to be resolved. */
c19d1205
ZW
24743 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24744 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24745 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24746 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24747 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24748 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24749 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24750 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24751 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24752 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24753 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24754 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24755 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24756 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24757 return 0;
a737bd4d 24758
4962c51a
MS
24759 /* Always leave these relocations for the linker. */
24760 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24761 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24762 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24763 return 1;
24764
f0291e4c
PB
24765 /* Always generate relocations against function symbols. */
24766 if (fixp->fx_r_type == BFD_RELOC_32
24767 && fixp->fx_addsy
24768 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24769 return 1;
24770
c19d1205 24771 return generic_force_reloc (fixp);
404ff6b5
AH
24772}
24773
0ffdc86c 24774#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24775/* Relocations against function names must be left unadjusted,
24776 so that the linker can use this information to generate interworking
24777 stubs. The MIPS version of this function
c19d1205
ZW
24778 also prevents relocations that are mips-16 specific, but I do not
24779 know why it does this.
404ff6b5 24780
c19d1205
ZW
24781 FIXME:
24782 There is one other problem that ought to be addressed here, but
24783 which currently is not: Taking the address of a label (rather
24784 than a function) and then later jumping to that address. Such
24785 addresses also ought to have their bottom bit set (assuming that
24786 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24787
c19d1205
ZW
24788bfd_boolean
24789arm_fix_adjustable (fixS * fixP)
404ff6b5 24790{
c19d1205
ZW
24791 if (fixP->fx_addsy == NULL)
24792 return 1;
404ff6b5 24793
e28387c3
PB
24794 /* Preserve relocations against symbols with function type. */
24795 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24796 return FALSE;
e28387c3 24797
c19d1205
ZW
24798 if (THUMB_IS_FUNC (fixP->fx_addsy)
24799 && fixP->fx_subsy == NULL)
c921be7d 24800 return FALSE;
a737bd4d 24801
c19d1205
ZW
24802 /* We need the symbol name for the VTABLE entries. */
24803 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24804 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24805 return FALSE;
404ff6b5 24806
c19d1205
ZW
24807 /* Don't allow symbols to be discarded on GOT related relocs. */
24808 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24809 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24810 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24811 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24812 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24813 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24814 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24815 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24816 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24817 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24818 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24819 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24820 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24821 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24822 return FALSE;
a737bd4d 24823
4962c51a
MS
24824 /* Similarly for group relocations. */
24825 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24826 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24827 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24828 return FALSE;
4962c51a 24829
79947c54
CD
24830 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24831 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24832 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24833 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24834 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24835 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24836 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24837 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24838 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24839 return FALSE;
79947c54 24840
72d98d16
MG
24841 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24842 offsets, so keep these symbols. */
24843 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24844 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24845 return FALSE;
24846
c921be7d 24847 return TRUE;
a737bd4d 24848}
0ffdc86c
NC
24849#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24850
24851#ifdef OBJ_ELF
c19d1205
ZW
24852const char *
24853elf32_arm_target_format (void)
404ff6b5 24854{
c19d1205
ZW
24855#ifdef TE_SYMBIAN
24856 return (target_big_endian
24857 ? "elf32-bigarm-symbian"
24858 : "elf32-littlearm-symbian");
24859#elif defined (TE_VXWORKS)
24860 return (target_big_endian
24861 ? "elf32-bigarm-vxworks"
24862 : "elf32-littlearm-vxworks");
b38cadfb
NC
24863#elif defined (TE_NACL)
24864 return (target_big_endian
24865 ? "elf32-bigarm-nacl"
24866 : "elf32-littlearm-nacl");
c19d1205
ZW
24867#else
24868 if (target_big_endian)
24869 return "elf32-bigarm";
24870 else
24871 return "elf32-littlearm";
24872#endif
404ff6b5
AH
24873}
24874
c19d1205
ZW
24875void
24876armelf_frob_symbol (symbolS * symp,
24877 int * puntp)
404ff6b5 24878{
c19d1205
ZW
24879 elf_frob_symbol (symp, puntp);
24880}
24881#endif
404ff6b5 24882
c19d1205 24883/* MD interface: Finalization. */
a737bd4d 24884
c19d1205
ZW
24885void
24886arm_cleanup (void)
24887{
24888 literal_pool * pool;
a737bd4d 24889
e07e6e58
NC
24890 /* Ensure that all the IT blocks are properly closed. */
24891 check_it_blocks_finished ();
24892
c19d1205
ZW
24893 for (pool = list_of_pools; pool; pool = pool->next)
24894 {
5f4273c7 24895 /* Put it at the end of the relevant section. */
c19d1205
ZW
24896 subseg_set (pool->section, pool->sub_section);
24897#ifdef OBJ_ELF
24898 arm_elf_change_section ();
24899#endif
24900 s_ltorg (0);
24901 }
404ff6b5
AH
24902}
24903
cd000bff
DJ
24904#ifdef OBJ_ELF
24905/* Remove any excess mapping symbols generated for alignment frags in
24906 SEC. We may have created a mapping symbol before a zero byte
24907 alignment; remove it if there's a mapping symbol after the
24908 alignment. */
24909static void
24910check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24911 void *dummy ATTRIBUTE_UNUSED)
24912{
24913 segment_info_type *seginfo = seg_info (sec);
24914 fragS *fragp;
24915
24916 if (seginfo == NULL || seginfo->frchainP == NULL)
24917 return;
24918
24919 for (fragp = seginfo->frchainP->frch_root;
24920 fragp != NULL;
24921 fragp = fragp->fr_next)
24922 {
24923 symbolS *sym = fragp->tc_frag_data.last_map;
24924 fragS *next = fragp->fr_next;
24925
24926 /* Variable-sized frags have been converted to fixed size by
24927 this point. But if this was variable-sized to start with,
24928 there will be a fixed-size frag after it. So don't handle
24929 next == NULL. */
24930 if (sym == NULL || next == NULL)
24931 continue;
24932
24933 if (S_GET_VALUE (sym) < next->fr_address)
24934 /* Not at the end of this frag. */
24935 continue;
24936 know (S_GET_VALUE (sym) == next->fr_address);
24937
24938 do
24939 {
24940 if (next->tc_frag_data.first_map != NULL)
24941 {
24942 /* Next frag starts with a mapping symbol. Discard this
24943 one. */
24944 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24945 break;
24946 }
24947
24948 if (next->fr_next == NULL)
24949 {
24950 /* This mapping symbol is at the end of the section. Discard
24951 it. */
24952 know (next->fr_fix == 0 && next->fr_var == 0);
24953 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24954 break;
24955 }
24956
24957 /* As long as we have empty frags without any mapping symbols,
24958 keep looking. */
24959 /* If the next frag is non-empty and does not start with a
24960 mapping symbol, then this mapping symbol is required. */
24961 if (next->fr_address != next->fr_next->fr_address)
24962 break;
24963
24964 next = next->fr_next;
24965 }
24966 while (next != NULL);
24967 }
24968}
24969#endif
24970
c19d1205
ZW
24971/* Adjust the symbol table. This marks Thumb symbols as distinct from
24972 ARM ones. */
404ff6b5 24973
c19d1205
ZW
24974void
24975arm_adjust_symtab (void)
404ff6b5 24976{
c19d1205
ZW
24977#ifdef OBJ_COFF
24978 symbolS * sym;
404ff6b5 24979
c19d1205
ZW
24980 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24981 {
24982 if (ARM_IS_THUMB (sym))
24983 {
24984 if (THUMB_IS_FUNC (sym))
24985 {
24986 /* Mark the symbol as a Thumb function. */
24987 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24988 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24989 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24990
c19d1205
ZW
24991 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24992 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24993 else
24994 as_bad (_("%s: unexpected function type: %d"),
24995 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24996 }
24997 else switch (S_GET_STORAGE_CLASS (sym))
24998 {
24999 case C_EXT:
25000 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25001 break;
25002 case C_STAT:
25003 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25004 break;
25005 case C_LABEL:
25006 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25007 break;
25008 default:
25009 /* Do nothing. */
25010 break;
25011 }
25012 }
a737bd4d 25013
c19d1205
ZW
25014 if (ARM_IS_INTERWORK (sym))
25015 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25016 }
c19d1205
ZW
25017#endif
25018#ifdef OBJ_ELF
25019 symbolS * sym;
25020 char bind;
404ff6b5 25021
c19d1205 25022 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25023 {
c19d1205
ZW
25024 if (ARM_IS_THUMB (sym))
25025 {
25026 elf_symbol_type * elf_sym;
404ff6b5 25027
c19d1205
ZW
25028 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25029 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25030
b0796911
PB
25031 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25032 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25033 {
25034 /* If it's a .thumb_func, declare it as so,
25035 otherwise tag label as .code 16. */
25036 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25037 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25038 ST_BRANCH_TO_THUMB);
3ba67470 25039 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25040 elf_sym->internal_elf_sym.st_info =
25041 ELF_ST_INFO (bind, STT_ARM_16BIT);
25042 }
25043 }
25044 }
cd000bff
DJ
25045
25046 /* Remove any overlapping mapping symbols generated by alignment frags. */
25047 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25048 /* Now do generic ELF adjustments. */
25049 elf_adjust_symtab ();
c19d1205 25050#endif
404ff6b5
AH
25051}
25052
c19d1205 25053/* MD interface: Initialization. */
404ff6b5 25054
a737bd4d 25055static void
c19d1205 25056set_constant_flonums (void)
a737bd4d 25057{
c19d1205 25058 int i;
404ff6b5 25059
c19d1205
ZW
25060 for (i = 0; i < NUM_FLOAT_VALS; i++)
25061 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25062 abort ();
a737bd4d 25063}
404ff6b5 25064
3e9e4fcf
JB
25065/* Auto-select Thumb mode if it's the only available instruction set for the
25066 given architecture. */
25067
25068static void
25069autoselect_thumb_from_cpu_variant (void)
25070{
25071 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25072 opcode_select (16);
25073}
25074
c19d1205
ZW
25075void
25076md_begin (void)
a737bd4d 25077{
c19d1205
ZW
25078 unsigned mach;
25079 unsigned int i;
404ff6b5 25080
c19d1205
ZW
25081 if ( (arm_ops_hsh = hash_new ()) == NULL
25082 || (arm_cond_hsh = hash_new ()) == NULL
25083 || (arm_shift_hsh = hash_new ()) == NULL
25084 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25085 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25086 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25087 || (arm_reloc_hsh = hash_new ()) == NULL
25088 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25089 as_fatal (_("virtual memory exhausted"));
25090
25091 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25092 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25093 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25094 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25095 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25096 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25097 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25098 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25099 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25100 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25101 (void *) (v7m_psrs + i));
c19d1205 25102 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25103 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25104 for (i = 0;
25105 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25106 i++)
d3ce72d0 25107 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25108 (void *) (barrier_opt_names + i));
c19d1205 25109#ifdef OBJ_ELF
3da1d841
NC
25110 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25111 {
25112 struct reloc_entry * entry = reloc_names + i;
25113
25114 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25115 /* This makes encode_branch() use the EABI versions of this relocation. */
25116 entry->reloc = BFD_RELOC_UNUSED;
25117
25118 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25119 }
c19d1205
ZW
25120#endif
25121
25122 set_constant_flonums ();
404ff6b5 25123
c19d1205
ZW
25124 /* Set the cpu variant based on the command-line options. We prefer
25125 -mcpu= over -march= if both are set (as for GCC); and we prefer
25126 -mfpu= over any other way of setting the floating point unit.
25127 Use of legacy options with new options are faulted. */
e74cfd16 25128 if (legacy_cpu)
404ff6b5 25129 {
e74cfd16 25130 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25131 as_bad (_("use of old and new-style options to set CPU type"));
25132
25133 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25134 }
e74cfd16 25135 else if (!mcpu_cpu_opt)
c168ce07
TP
25136 {
25137 mcpu_cpu_opt = march_cpu_opt;
25138 dyn_mcpu_ext_opt = dyn_march_ext_opt;
25139 /* Avoid double free in arm_md_end. */
25140 dyn_march_ext_opt = NULL;
25141 }
404ff6b5 25142
e74cfd16 25143 if (legacy_fpu)
c19d1205 25144 {
e74cfd16 25145 if (mfpu_opt)
c19d1205 25146 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25147
25148 mfpu_opt = legacy_fpu;
25149 }
e74cfd16 25150 else if (!mfpu_opt)
03b1477f 25151 {
45eb4c1b
NS
25152#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25153 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25154 /* Some environments specify a default FPU. If they don't, infer it
25155 from the processor. */
e74cfd16 25156 if (mcpu_fpu_opt)
03b1477f
RE
25157 mfpu_opt = mcpu_fpu_opt;
25158 else
25159 mfpu_opt = march_fpu_opt;
39c2da32 25160#else
e74cfd16 25161 mfpu_opt = &fpu_default;
39c2da32 25162#endif
03b1477f
RE
25163 }
25164
e74cfd16 25165 if (!mfpu_opt)
03b1477f 25166 {
493cb6ef 25167 if (mcpu_cpu_opt != NULL)
e74cfd16 25168 mfpu_opt = &fpu_default;
493cb6ef 25169 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25170 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25171 else
e74cfd16 25172 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25173 }
25174
ee065d83 25175#ifdef CPU_DEFAULT
e74cfd16 25176 if (!mcpu_cpu_opt)
ee065d83 25177 {
e74cfd16
PB
25178 mcpu_cpu_opt = &cpu_default;
25179 selected_cpu = cpu_default;
ee065d83 25180 }
c168ce07
TP
25181 else if (dyn_mcpu_ext_opt)
25182 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
62785b09
TP
25183 else
25184 selected_cpu = *mcpu_cpu_opt;
e74cfd16 25185#else
c168ce07
TP
25186 if (mcpu_cpu_opt && dyn_mcpu_ext_opt)
25187 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
25188 else if (mcpu_cpu_opt)
e74cfd16 25189 selected_cpu = *mcpu_cpu_opt;
ee065d83 25190 else
e74cfd16 25191 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25192#endif
03b1477f 25193
e74cfd16 25194 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
25195 if (dyn_mcpu_ext_opt)
25196 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
03b1477f 25197
3e9e4fcf
JB
25198 autoselect_thumb_from_cpu_variant ();
25199
e74cfd16 25200 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25201
f17c130b 25202#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25203 {
7cc69913
NC
25204 unsigned int flags = 0;
25205
25206#if defined OBJ_ELF
25207 flags = meabi_flags;
d507cf36
PB
25208
25209 switch (meabi_flags)
33a392fb 25210 {
d507cf36 25211 case EF_ARM_EABI_UNKNOWN:
7cc69913 25212#endif
d507cf36
PB
25213 /* Set the flags in the private structure. */
25214 if (uses_apcs_26) flags |= F_APCS26;
25215 if (support_interwork) flags |= F_INTERWORK;
25216 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25217 if (pic_code) flags |= F_PIC;
e74cfd16 25218 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25219 flags |= F_SOFT_FLOAT;
25220
d507cf36
PB
25221 switch (mfloat_abi_opt)
25222 {
25223 case ARM_FLOAT_ABI_SOFT:
25224 case ARM_FLOAT_ABI_SOFTFP:
25225 flags |= F_SOFT_FLOAT;
25226 break;
33a392fb 25227
d507cf36
PB
25228 case ARM_FLOAT_ABI_HARD:
25229 if (flags & F_SOFT_FLOAT)
25230 as_bad (_("hard-float conflicts with specified fpu"));
25231 break;
25232 }
03b1477f 25233
e74cfd16
PB
25234 /* Using pure-endian doubles (even if soft-float). */
25235 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25236 flags |= F_VFP_FLOAT;
f17c130b 25237
fde78edd 25238#if defined OBJ_ELF
e74cfd16 25239 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25240 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25241 break;
25242
8cb51566 25243 case EF_ARM_EABI_VER4:
3a4a14e9 25244 case EF_ARM_EABI_VER5:
c19d1205 25245 /* No additional flags to set. */
d507cf36
PB
25246 break;
25247
25248 default:
25249 abort ();
25250 }
7cc69913 25251#endif
b99bd4ef
NC
25252 bfd_set_private_flags (stdoutput, flags);
25253
25254 /* We have run out flags in the COFF header to encode the
25255 status of ATPCS support, so instead we create a dummy,
c19d1205 25256 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25257 if (atpcs)
25258 {
25259 asection * sec;
25260
25261 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25262
25263 if (sec != NULL)
25264 {
25265 bfd_set_section_flags
25266 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25267 bfd_set_section_size (stdoutput, sec, 0);
25268 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25269 }
25270 }
7cc69913 25271 }
f17c130b 25272#endif
b99bd4ef
NC
25273
25274 /* Record the CPU type as well. */
2d447fca
JM
25275 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25276 mach = bfd_mach_arm_iWMMXt2;
25277 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25278 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25279 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25280 mach = bfd_mach_arm_XScale;
e74cfd16 25281 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25282 mach = bfd_mach_arm_ep9312;
e74cfd16 25283 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25284 mach = bfd_mach_arm_5TE;
e74cfd16 25285 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25286 {
e74cfd16 25287 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25288 mach = bfd_mach_arm_5T;
25289 else
25290 mach = bfd_mach_arm_5;
25291 }
e74cfd16 25292 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25293 {
e74cfd16 25294 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25295 mach = bfd_mach_arm_4T;
25296 else
25297 mach = bfd_mach_arm_4;
25298 }
e74cfd16 25299 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25300 mach = bfd_mach_arm_3M;
e74cfd16
PB
25301 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25302 mach = bfd_mach_arm_3;
25303 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25304 mach = bfd_mach_arm_2a;
25305 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25306 mach = bfd_mach_arm_2;
25307 else
25308 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25309
25310 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25311}
25312
c19d1205 25313/* Command line processing. */
b99bd4ef 25314
c19d1205
ZW
25315/* md_parse_option
25316 Invocation line includes a switch not recognized by the base assembler.
25317 See if it's a processor-specific option.
b99bd4ef 25318
c19d1205
ZW
25319 This routine is somewhat complicated by the need for backwards
25320 compatibility (since older releases of gcc can't be changed).
25321 The new options try to make the interface as compatible as
25322 possible with GCC.
b99bd4ef 25323
c19d1205 25324 New options (supported) are:
b99bd4ef 25325
c19d1205
ZW
25326 -mcpu=<cpu name> Assemble for selected processor
25327 -march=<architecture name> Assemble for selected architecture
25328 -mfpu=<fpu architecture> Assemble for selected FPU.
25329 -EB/-mbig-endian Big-endian
25330 -EL/-mlittle-endian Little-endian
25331 -k Generate PIC code
25332 -mthumb Start in Thumb mode
25333 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25334
278df34e 25335 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25336 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25337
c19d1205 25338 For now we will also provide support for:
b99bd4ef 25339
c19d1205
ZW
25340 -mapcs-32 32-bit Program counter
25341 -mapcs-26 26-bit Program counter
25342 -macps-float Floats passed in FP registers
25343 -mapcs-reentrant Reentrant code
25344 -matpcs
25345 (sometime these will probably be replaced with -mapcs=<list of options>
25346 and -matpcs=<list of options>)
b99bd4ef 25347
c19d1205
ZW
25348 The remaining options are only supported for back-wards compatibility.
25349 Cpu variants, the arm part is optional:
25350 -m[arm]1 Currently not supported.
25351 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25352 -m[arm]3 Arm 3 processor
25353 -m[arm]6[xx], Arm 6 processors
25354 -m[arm]7[xx][t][[d]m] Arm 7 processors
25355 -m[arm]8[10] Arm 8 processors
25356 -m[arm]9[20][tdmi] Arm 9 processors
25357 -mstrongarm[110[0]] StrongARM processors
25358 -mxscale XScale processors
25359 -m[arm]v[2345[t[e]]] Arm architectures
25360 -mall All (except the ARM1)
25361 FP variants:
25362 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25363 -mfpe-old (No float load/store multiples)
25364 -mvfpxd VFP Single precision
25365 -mvfp All VFP
25366 -mno-fpu Disable all floating point instructions
b99bd4ef 25367
c19d1205
ZW
25368 The following CPU names are recognized:
25369 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25370 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25371 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25372 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25373 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25374 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25375 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25376
c19d1205 25377 */
b99bd4ef 25378
c19d1205 25379const char * md_shortopts = "m:k";
b99bd4ef 25380
c19d1205
ZW
25381#ifdef ARM_BI_ENDIAN
25382#define OPTION_EB (OPTION_MD_BASE + 0)
25383#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25384#else
c19d1205
ZW
25385#if TARGET_BYTES_BIG_ENDIAN
25386#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25387#else
c19d1205
ZW
25388#define OPTION_EL (OPTION_MD_BASE + 1)
25389#endif
b99bd4ef 25390#endif
845b51d6 25391#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25392
c19d1205 25393struct option md_longopts[] =
b99bd4ef 25394{
c19d1205
ZW
25395#ifdef OPTION_EB
25396 {"EB", no_argument, NULL, OPTION_EB},
25397#endif
25398#ifdef OPTION_EL
25399 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25400#endif
845b51d6 25401 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25402 {NULL, no_argument, NULL, 0}
25403};
b99bd4ef 25404
8b2d793c 25405
c19d1205 25406size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25407
c19d1205 25408struct arm_option_table
b99bd4ef 25409{
e0471c16
TS
25410 const char *option; /* Option name to match. */
25411 const char *help; /* Help information. */
c19d1205
ZW
25412 int *var; /* Variable to change. */
25413 int value; /* What to change it to. */
e0471c16 25414 const char *deprecated; /* If non-null, print this message. */
c19d1205 25415};
b99bd4ef 25416
c19d1205
ZW
25417struct arm_option_table arm_opts[] =
25418{
25419 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25420 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25421 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25422 &support_interwork, 1, NULL},
25423 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25424 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25425 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25426 1, NULL},
25427 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25428 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25429 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25430 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25431 NULL},
b99bd4ef 25432
c19d1205
ZW
25433 /* These are recognized by the assembler, but have no affect on code. */
25434 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25435 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25436
25437 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25438 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25439 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25440 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25441 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25442 {NULL, NULL, NULL, 0, NULL}
25443};
25444
25445struct arm_legacy_option_table
25446{
e0471c16 25447 const char *option; /* Option name to match. */
e74cfd16
PB
25448 const arm_feature_set **var; /* Variable to change. */
25449 const arm_feature_set value; /* What to change it to. */
e0471c16 25450 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25451};
b99bd4ef 25452
e74cfd16
PB
25453const struct arm_legacy_option_table arm_legacy_opts[] =
25454{
c19d1205
ZW
25455 /* DON'T add any new processors to this list -- we want the whole list
25456 to go away... Add them to the processors table instead. */
e74cfd16
PB
25457 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25458 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25459 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25460 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25461 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25462 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25463 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25464 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25465 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25466 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25467 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25468 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25469 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25470 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25471 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25472 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25473 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25474 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25475 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25476 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25477 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25478 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25479 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25480 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25481 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25482 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25483 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25484 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25485 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25486 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25487 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25488 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25489 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25490 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25491 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25492 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25493 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25494 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25495 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25496 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25497 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25498 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25499 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25500 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25501 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25502 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25503 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25504 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25505 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25506 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25507 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25508 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25509 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25510 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25511 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25512 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25513 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25514 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25515 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25516 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25517 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25518 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25519 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25520 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25521 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25522 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25523 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25524 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25525 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25526 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25527 N_("use -mcpu=strongarm110")},
e74cfd16 25528 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25529 N_("use -mcpu=strongarm1100")},
e74cfd16 25530 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25531 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25532 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25533 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25534 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25535
c19d1205 25536 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25537 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25538 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25539 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25540 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25541 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25542 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25543 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25544 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25545 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25546 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25547 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25548 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25549 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25550 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25551 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25552 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25553 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25554 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25555
c19d1205 25556 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25557 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25558 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25559 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25560 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25561 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25562
e74cfd16 25563 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25564};
7ed4c4c5 25565
c19d1205 25566struct arm_cpu_option_table
7ed4c4c5 25567{
e0471c16 25568 const char *name;
f3bad469 25569 size_t name_len;
e74cfd16 25570 const arm_feature_set value;
996b5569 25571 const arm_feature_set ext;
c19d1205
ZW
25572 /* For some CPUs we assume an FPU unless the user explicitly sets
25573 -mfpu=... */
e74cfd16 25574 const arm_feature_set default_fpu;
ee065d83
PB
25575 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25576 case. */
25577 const char *canonical_name;
c19d1205 25578};
7ed4c4c5 25579
c19d1205
ZW
25580/* This list should, at a minimum, contain all the cpu names
25581 recognized by GCC. */
996b5569 25582#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
e74cfd16 25583static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25584{
996b5569
TP
25585 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25586 ARM_ARCH_NONE,
25587 FPU_ARCH_FPA),
25588 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25589 ARM_ARCH_NONE,
25590 FPU_ARCH_FPA),
25591 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25592 ARM_ARCH_NONE,
25593 FPU_ARCH_FPA),
25594 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25595 ARM_ARCH_NONE,
25596 FPU_ARCH_FPA),
25597 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25598 ARM_ARCH_NONE,
25599 FPU_ARCH_FPA),
25600 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25601 ARM_ARCH_NONE,
25602 FPU_ARCH_FPA),
25603 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25604 ARM_ARCH_NONE,
25605 FPU_ARCH_FPA),
25606 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25607 ARM_ARCH_NONE,
25608 FPU_ARCH_FPA),
25609 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25610 ARM_ARCH_NONE,
25611 FPU_ARCH_FPA),
25612 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25613 ARM_ARCH_NONE,
25614 FPU_ARCH_FPA),
25615 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25616 ARM_ARCH_NONE,
25617 FPU_ARCH_FPA),
25618 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25619 ARM_ARCH_NONE,
25620 FPU_ARCH_FPA),
25621 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25622 ARM_ARCH_NONE,
25623 FPU_ARCH_FPA),
25624 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25625 ARM_ARCH_NONE,
25626 FPU_ARCH_FPA),
25627 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25628 ARM_ARCH_NONE,
25629 FPU_ARCH_FPA),
25630 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25631 ARM_ARCH_NONE,
25632 FPU_ARCH_FPA),
25633 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25634 ARM_ARCH_NONE,
25635 FPU_ARCH_FPA),
25636 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25637 ARM_ARCH_NONE,
25638 FPU_ARCH_FPA),
25639 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25640 ARM_ARCH_NONE,
25641 FPU_ARCH_FPA),
25642 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25643 ARM_ARCH_NONE,
25644 FPU_ARCH_FPA),
25645 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25646 ARM_ARCH_NONE,
25647 FPU_ARCH_FPA),
25648 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25649 ARM_ARCH_NONE,
25650 FPU_ARCH_FPA),
25651 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25652 ARM_ARCH_NONE,
25653 FPU_ARCH_FPA),
25654 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25655 ARM_ARCH_NONE,
25656 FPU_ARCH_FPA),
25657 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25658 ARM_ARCH_NONE,
25659 FPU_ARCH_FPA),
25660 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25661 ARM_ARCH_NONE,
25662 FPU_ARCH_FPA),
25663 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25664 ARM_ARCH_NONE,
25665 FPU_ARCH_FPA),
25666 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25667 ARM_ARCH_NONE,
25668 FPU_ARCH_FPA),
25669 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25670 ARM_ARCH_NONE,
25671 FPU_ARCH_FPA),
25672 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25673 ARM_ARCH_NONE,
25674 FPU_ARCH_FPA),
25675 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25676 ARM_ARCH_NONE,
25677 FPU_ARCH_FPA),
25678 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25679 ARM_ARCH_NONE,
25680 FPU_ARCH_FPA),
25681 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25682 ARM_ARCH_NONE,
25683 FPU_ARCH_FPA),
25684 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25685 ARM_ARCH_NONE,
25686 FPU_ARCH_FPA),
25687 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25688 ARM_ARCH_NONE,
25689 FPU_ARCH_FPA),
25690 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25691 ARM_ARCH_NONE,
25692 FPU_ARCH_FPA),
25693 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25694 ARM_ARCH_NONE,
25695 FPU_ARCH_FPA),
25696 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25697 ARM_ARCH_NONE,
25698 FPU_ARCH_FPA),
25699 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25700 ARM_ARCH_NONE,
25701 FPU_ARCH_FPA),
25702 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25703 ARM_ARCH_NONE,
25704 FPU_ARCH_FPA),
25705 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25706 ARM_ARCH_NONE,
25707 FPU_ARCH_FPA),
25708 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25709 ARM_ARCH_NONE,
25710 FPU_ARCH_FPA),
25711 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25712 ARM_ARCH_NONE,
25713 FPU_ARCH_FPA),
25714 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25715 ARM_ARCH_NONE,
25716 FPU_ARCH_FPA),
25717 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25718 ARM_ARCH_NONE,
25719 FPU_ARCH_FPA),
25720 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25721 ARM_ARCH_NONE,
25722 FPU_ARCH_FPA),
25723
c19d1205
ZW
25724 /* For V5 or later processors we default to using VFP; but the user
25725 should really set the FPU type explicitly. */
996b5569
TP
25726 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25727 ARM_ARCH_NONE,
25728 FPU_ARCH_VFP_V2),
25729 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25730 ARM_ARCH_NONE,
25731 FPU_ARCH_VFP_V2),
25732 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25733 ARM_ARCH_NONE,
25734 FPU_ARCH_VFP_V2),
25735 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25736 ARM_ARCH_NONE,
25737 FPU_ARCH_VFP_V2),
25738 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25739 ARM_ARCH_NONE,
25740 FPU_ARCH_VFP_V2),
25741 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25742 ARM_ARCH_NONE,
25743 FPU_ARCH_VFP_V2),
25744 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25745 ARM_ARCH_NONE,
25746 FPU_ARCH_VFP_V2),
25747 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25748 ARM_ARCH_NONE,
25749 FPU_ARCH_VFP_V2),
25750 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25751 ARM_ARCH_NONE,
25752 FPU_ARCH_VFP_V2),
25753 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25754 ARM_ARCH_NONE,
25755 FPU_ARCH_VFP_V2),
25756 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
25757 ARM_ARCH_NONE,
25758 FPU_ARCH_VFP_V2),
25759 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
25760 ARM_ARCH_NONE,
25761 FPU_ARCH_VFP_V2),
25762 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
25763 ARM_ARCH_NONE,
25764 FPU_ARCH_VFP_V1),
25765 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
25766 ARM_ARCH_NONE,
25767 FPU_ARCH_VFP_V1),
25768 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
25769 ARM_ARCH_NONE,
25770 FPU_ARCH_VFP_V2),
25771 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
25772 ARM_ARCH_NONE,
25773 FPU_ARCH_VFP_V2),
25774 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
25775 ARM_ARCH_NONE,
25776 FPU_ARCH_VFP_V1),
25777 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
25778 ARM_ARCH_NONE,
25779 FPU_ARCH_VFP_V2),
25780 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
25781 ARM_ARCH_NONE,
25782 FPU_ARCH_VFP_V2),
25783 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
25784 ARM_ARCH_NONE,
25785 FPU_ARCH_VFP_V2),
25786 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
25787 ARM_ARCH_NONE,
25788 FPU_ARCH_VFP_V2),
25789 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
25790 ARM_ARCH_NONE,
25791 FPU_ARCH_VFP_V2),
25792 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
25793 ARM_ARCH_NONE,
25794 FPU_ARCH_VFP_V2),
25795 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
25796 ARM_ARCH_NONE,
25797 FPU_ARCH_VFP_V2),
25798 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
25799 ARM_ARCH_NONE,
25800 FPU_ARCH_VFP_V2),
25801 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
25802 ARM_ARCH_NONE,
25803 FPU_ARCH_VFP_V2),
25804 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
25805 ARM_ARCH_NONE,
25806 FPU_NONE),
25807 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
25808 ARM_ARCH_NONE,
25809 FPU_NONE),
25810 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
25811 ARM_ARCH_NONE,
25812 FPU_ARCH_VFP_V2),
25813 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
25814 ARM_ARCH_NONE,
25815 FPU_ARCH_VFP_V2),
25816 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
25817 ARM_ARCH_NONE,
25818 FPU_ARCH_VFP_V2),
25819 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
25820 ARM_ARCH_NONE,
25821 FPU_NONE),
25822 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
25823 ARM_ARCH_NONE,
25824 FPU_NONE),
25825 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
25826 ARM_ARCH_NONE,
25827 FPU_ARCH_VFP_V2),
25828 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
25829 ARM_ARCH_NONE,
25830 FPU_NONE),
25831 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
25832 ARM_ARCH_NONE,
25833 FPU_ARCH_VFP_V2),
25834 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
25835 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25836 FPU_NONE),
25837 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
25838 ARM_ARCH_NONE,
25839 FPU_ARCH_NEON_VFP_V4),
25840 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
25841 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25842 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25843 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
25844 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25845 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25846 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
25847 ARM_ARCH_NONE,
25848 FPU_ARCH_NEON_VFP_V4),
25849 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
25850 ARM_ARCH_NONE,
25851 FPU_ARCH_NEON_VFP_V4),
25852 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
25853 ARM_ARCH_NONE,
25854 FPU_ARCH_NEON_VFP_V4),
25855 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
25856 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25857 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25858 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
25859 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25860 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25861 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
25862 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25863 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
25864 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
25865 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25866 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
996b5569
TP
25867 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
25868 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25869 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25870 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
25871 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25872 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25873 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
25874 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25875 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
25876 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
25877 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25878 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
996b5569
TP
25879 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
25880 ARM_ARCH_NONE,
25881 FPU_NONE),
25882 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
25883 ARM_ARCH_NONE,
25884 FPU_ARCH_VFP_V3D16),
25885 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
25886 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25887 FPU_NONE),
25888 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
25889 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25890 FPU_ARCH_VFP_V3D16),
25891 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
25892 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25893 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
25894 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
25895 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25896 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
25897 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
25898 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25899 FPU_NONE),
25900 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
25901 ARM_ARCH_NONE,
25902 FPU_NONE),
25903 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
25904 ARM_ARCH_NONE,
25905 FPU_NONE),
25906 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
25907 ARM_ARCH_NONE,
25908 FPU_NONE),
25909 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
25910 ARM_ARCH_NONE,
25911 FPU_NONE),
25912 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
25913 ARM_ARCH_NONE,
25914 FPU_NONE),
25915 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
25916 ARM_ARCH_NONE,
25917 FPU_NONE),
25918 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
25919 ARM_ARCH_NONE,
25920 FPU_NONE),
25921 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
25922 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25923 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 25924
c19d1205 25925 /* ??? XSCALE is really an architecture. */
996b5569
TP
25926 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
25927 ARM_ARCH_NONE,
25928 FPU_ARCH_VFP_V2),
25929
c19d1205 25930 /* ??? iwmmxt is not a processor. */
996b5569
TP
25931 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
25932 ARM_ARCH_NONE,
25933 FPU_ARCH_VFP_V2),
25934 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
25935 ARM_ARCH_NONE,
25936 FPU_ARCH_VFP_V2),
25937 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
25938 ARM_ARCH_NONE,
25939 FPU_ARCH_VFP_V2),
25940
c19d1205 25941 /* Maverick */
996b5569
TP
25942 ARM_CPU_OPT ("ep9312", "ARM920T",
25943 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
25944 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
25945
da4339ed 25946 /* Marvell processors. */
996b5569
TP
25947 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
25948 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25949 FPU_ARCH_VFP_V3D16),
25950 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
25951 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25952 FPU_ARCH_NEON_VFP_V4),
da4339ed 25953
996b5569
TP
25954 /* APM X-Gene family. */
25955 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
25956 ARM_ARCH_NONE,
25957 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25958 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
25959 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25960 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25961
25962 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25963};
f3bad469 25964#undef ARM_CPU_OPT
7ed4c4c5 25965
c19d1205 25966struct arm_arch_option_table
7ed4c4c5 25967{
e0471c16 25968 const char *name;
f3bad469 25969 size_t name_len;
e74cfd16
PB
25970 const arm_feature_set value;
25971 const arm_feature_set default_fpu;
c19d1205 25972};
7ed4c4c5 25973
c19d1205
ZW
25974/* This list should, at a minimum, contain all the architecture names
25975 recognized by GCC. */
f3bad469 25976#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25977static const struct arm_arch_option_table arm_archs[] =
c19d1205 25978{
f3bad469
MGD
25979 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25980 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25981 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25982 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25983 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25984 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25985 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25986 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25987 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25988 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25989 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25990 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25991 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25992 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25993 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25994 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25995 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25996 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25997 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25998 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25999 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26000 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26001 kept to preserve existing behaviour. */
26002 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26003 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
26004 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26005 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26006 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26007 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26008 kept to preserve existing behaviour. */
26009 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26010 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
26011 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26012 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26013 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26014 /* The official spelling of the ARMv7 profile variants is the dashed form.
26015 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 26016 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 26017 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
26018 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26019 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26020 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26021 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26022 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26023 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 26024 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 26025 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 26026 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 26027 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 26028 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 26029 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
ced40572 26030 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
f3bad469
MGD
26031 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26032 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26033 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26034 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26035};
f3bad469 26036#undef ARM_ARCH_OPT
7ed4c4c5 26037
69133863
MGD
26038/* ISA extensions in the co-processor and main instruction set space. */
26039struct arm_option_extension_value_table
c19d1205 26040{
e0471c16 26041 const char *name;
f3bad469 26042 size_t name_len;
5a70a223
JB
26043 const arm_feature_set merge_value;
26044 const arm_feature_set clear_value;
d942732e
TP
26045 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26046 indicates that an extension is available for all architectures while
26047 ARM_ANY marks an empty entry. */
26048 const arm_feature_set allowed_archs[2];
c19d1205 26049};
7ed4c4c5 26050
69133863
MGD
26051/* The following table must be in alphabetical order with a NULL last entry.
26052 */
d942732e
TP
26053#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26054#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 26055static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26056{
823d2571
TG
26057 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26058 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26059 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26060 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26061 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26062 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26063 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26064 ARM_ARCH_V8_2A),
15afaa63
TP
26065 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26066 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26067 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26068 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26069 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26070 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26071 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26072 ARM_ARCH_V8_2A),
d942732e 26073 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26074 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26075 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26076 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26077 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26078 Thumb divide instruction. Due to this having the same name as the
26079 previous entry, this will be ignored when doing command-line parsing and
26080 only considered by build attribute selection code. */
26081 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26082 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26083 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26084 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26085 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26086 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26087 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26088 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26089 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26090 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26091 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26092 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26093 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26094 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26095 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26096 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26097 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26098 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26099 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
4d1464f2
MW
26100 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26101 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26102 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26103 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26104 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26105 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
d942732e 26106 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26107 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26108 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26109 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26110 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26111 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26112 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26113 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26114 | ARM_EXT_DIV),
26115 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26116 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26117 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26118 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26119 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26120};
f3bad469 26121#undef ARM_EXT_OPT
69133863
MGD
26122
26123/* ISA floating-point and Advanced SIMD extensions. */
26124struct arm_option_fpu_value_table
26125{
e0471c16 26126 const char *name;
69133863 26127 const arm_feature_set value;
c19d1205 26128};
7ed4c4c5 26129
c19d1205
ZW
26130/* This list should, at a minimum, contain all the fpu names
26131 recognized by GCC. */
69133863 26132static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26133{
26134 {"softfpa", FPU_NONE},
26135 {"fpe", FPU_ARCH_FPE},
26136 {"fpe2", FPU_ARCH_FPE},
26137 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26138 {"fpa", FPU_ARCH_FPA},
26139 {"fpa10", FPU_ARCH_FPA},
26140 {"fpa11", FPU_ARCH_FPA},
26141 {"arm7500fe", FPU_ARCH_FPA},
26142 {"softvfp", FPU_ARCH_VFP},
26143 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26144 {"vfp", FPU_ARCH_VFP_V2},
26145 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26146 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26147 {"vfp10", FPU_ARCH_VFP_V2},
26148 {"vfp10-r0", FPU_ARCH_VFP_V1},
26149 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26150 {"vfpv2", FPU_ARCH_VFP_V2},
26151 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26152 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26153 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26154 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26155 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26156 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26157 {"arm1020t", FPU_ARCH_VFP_V1},
26158 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26159 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26160 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26161 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26162 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26163 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26164 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26165 {"vfpv4", FPU_ARCH_VFP_V4},
26166 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26167 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26168 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26169 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26170 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26171 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26172 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26173 {"crypto-neon-fp-armv8",
26174 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26175 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26176 {"crypto-neon-fp-armv8.1",
26177 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26178 {NULL, ARM_ARCH_NONE}
26179};
26180
26181struct arm_option_value_table
26182{
e0471c16 26183 const char *name;
e74cfd16 26184 long value;
c19d1205 26185};
7ed4c4c5 26186
e74cfd16 26187static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26188{
26189 {"hard", ARM_FLOAT_ABI_HARD},
26190 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26191 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26192 {NULL, 0}
c19d1205 26193};
7ed4c4c5 26194
c19d1205 26195#ifdef OBJ_ELF
3a4a14e9 26196/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26197static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26198{
26199 {"gnu", EF_ARM_EABI_UNKNOWN},
26200 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26201 {"5", EF_ARM_EABI_VER5},
e74cfd16 26202 {NULL, 0}
c19d1205
ZW
26203};
26204#endif
7ed4c4c5 26205
c19d1205
ZW
26206struct arm_long_option_table
26207{
e0471c16
TS
26208 const char * option; /* Substring to match. */
26209 const char * help; /* Help information. */
17b9d67d 26210 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26211 const char * deprecated; /* If non-null, print this message. */
c19d1205 26212};
7ed4c4c5 26213
c921be7d 26214static bfd_boolean
c168ce07
TP
26215arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26216 arm_feature_set **ext_set_p)
7ed4c4c5 26217{
69133863 26218 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26219 extensions being added before being removed. We achieve this by having
26220 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26221 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26222 or removing it (0) and only allowing it to change in the order
69133863
MGD
26223 -1 -> 1 -> 0. */
26224 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26225 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26226 int adding_value = -1;
26227
c168ce07
TP
26228 if (!*ext_set_p)
26229 {
26230 *ext_set_p = XNEW (arm_feature_set);
26231 **ext_set_p = arm_arch_none;
26232 }
e74cfd16 26233
c19d1205 26234 while (str != NULL && *str != 0)
7ed4c4c5 26235 {
82b8a785 26236 const char *ext;
f3bad469 26237 size_t len;
7ed4c4c5 26238
c19d1205
ZW
26239 if (*str != '+')
26240 {
26241 as_bad (_("invalid architectural extension"));
c921be7d 26242 return FALSE;
c19d1205 26243 }
7ed4c4c5 26244
c19d1205
ZW
26245 str++;
26246 ext = strchr (str, '+');
7ed4c4c5 26247
c19d1205 26248 if (ext != NULL)
f3bad469 26249 len = ext - str;
c19d1205 26250 else
f3bad469 26251 len = strlen (str);
7ed4c4c5 26252
f3bad469 26253 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26254 {
26255 if (adding_value != 0)
26256 {
26257 adding_value = 0;
26258 opt = arm_extensions;
26259 }
26260
f3bad469 26261 len -= 2;
69133863
MGD
26262 str += 2;
26263 }
f3bad469 26264 else if (len > 0)
69133863
MGD
26265 {
26266 if (adding_value == -1)
26267 {
26268 adding_value = 1;
26269 opt = arm_extensions;
26270 }
26271 else if (adding_value != 1)
26272 {
26273 as_bad (_("must specify extensions to add before specifying "
26274 "those to remove"));
26275 return FALSE;
26276 }
26277 }
26278
f3bad469 26279 if (len == 0)
c19d1205
ZW
26280 {
26281 as_bad (_("missing architectural extension"));
c921be7d 26282 return FALSE;
c19d1205 26283 }
7ed4c4c5 26284
69133863
MGD
26285 gas_assert (adding_value != -1);
26286 gas_assert (opt != NULL);
26287
26288 /* Scan over the options table trying to find an exact match. */
26289 for (; opt->name != NULL; opt++)
f3bad469 26290 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26291 {
d942732e
TP
26292 int i, nb_allowed_archs =
26293 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26294 /* Check we can apply the extension to this architecture. */
d942732e
TP
26295 for (i = 0; i < nb_allowed_archs; i++)
26296 {
26297 /* Empty entry. */
26298 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26299 continue;
c168ce07 26300 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26301 break;
26302 }
26303 if (i == nb_allowed_archs)
69133863
MGD
26304 {
26305 as_bad (_("extension does not apply to the base architecture"));
26306 return FALSE;
26307 }
26308
26309 /* Add or remove the extension. */
26310 if (adding_value)
c168ce07
TP
26311 ARM_MERGE_FEATURE_SETS (**ext_set_p, **ext_set_p,
26312 opt->merge_value);
69133863 26313 else
c168ce07 26314 ARM_CLEAR_FEATURE (**ext_set_p, **ext_set_p, opt->clear_value);
69133863 26315
3d030cdb
TP
26316 /* Allowing Thumb division instructions for ARMv7 in autodetection
26317 rely on this break so that duplicate extensions (extensions
26318 with the same name as a previous extension in the list) are not
26319 considered for command-line parsing. */
c19d1205
ZW
26320 break;
26321 }
7ed4c4c5 26322
c19d1205
ZW
26323 if (opt->name == NULL)
26324 {
69133863
MGD
26325 /* Did we fail to find an extension because it wasn't specified in
26326 alphabetical order, or because it does not exist? */
26327
26328 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26329 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26330 break;
26331
26332 if (opt->name == NULL)
26333 as_bad (_("unknown architectural extension `%s'"), str);
26334 else
26335 as_bad (_("architectural extensions must be specified in "
26336 "alphabetical order"));
26337
c921be7d 26338 return FALSE;
c19d1205 26339 }
69133863
MGD
26340 else
26341 {
26342 /* We should skip the extension we've just matched the next time
26343 round. */
26344 opt++;
26345 }
7ed4c4c5 26346
c19d1205
ZW
26347 str = ext;
26348 };
7ed4c4c5 26349
c921be7d 26350 return TRUE;
c19d1205 26351}
7ed4c4c5 26352
c921be7d 26353static bfd_boolean
17b9d67d 26354arm_parse_cpu (const char *str)
7ed4c4c5 26355{
f3bad469 26356 const struct arm_cpu_option_table *opt;
82b8a785 26357 const char *ext = strchr (str, '+');
f3bad469 26358 size_t len;
7ed4c4c5 26359
c19d1205 26360 if (ext != NULL)
f3bad469 26361 len = ext - str;
7ed4c4c5 26362 else
f3bad469 26363 len = strlen (str);
7ed4c4c5 26364
f3bad469 26365 if (len == 0)
7ed4c4c5 26366 {
c19d1205 26367 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26368 return FALSE;
7ed4c4c5
NC
26369 }
26370
c19d1205 26371 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26372 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26373 {
c168ce07
TP
26374 mcpu_cpu_opt = &opt->value;
26375 if (!dyn_mcpu_ext_opt)
26376 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
26377 *dyn_mcpu_ext_opt = opt->ext;
e74cfd16 26378 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26379 if (opt->canonical_name)
ef8e6722
JW
26380 {
26381 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26382 strcpy (selected_cpu_name, opt->canonical_name);
26383 }
ee065d83
PB
26384 else
26385 {
f3bad469 26386 size_t i;
c921be7d 26387
ef8e6722
JW
26388 if (len >= sizeof selected_cpu_name)
26389 len = (sizeof selected_cpu_name) - 1;
26390
f3bad469 26391 for (i = 0; i < len; i++)
ee065d83
PB
26392 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26393 selected_cpu_name[i] = 0;
26394 }
7ed4c4c5 26395
c19d1205 26396 if (ext != NULL)
c168ce07 26397 return arm_parse_extension (ext, mcpu_cpu_opt, &dyn_mcpu_ext_opt);
7ed4c4c5 26398
c921be7d 26399 return TRUE;
c19d1205 26400 }
7ed4c4c5 26401
c19d1205 26402 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26403 return FALSE;
7ed4c4c5
NC
26404}
26405
c921be7d 26406static bfd_boolean
17b9d67d 26407arm_parse_arch (const char *str)
7ed4c4c5 26408{
e74cfd16 26409 const struct arm_arch_option_table *opt;
82b8a785 26410 const char *ext = strchr (str, '+');
f3bad469 26411 size_t len;
7ed4c4c5 26412
c19d1205 26413 if (ext != NULL)
f3bad469 26414 len = ext - str;
7ed4c4c5 26415 else
f3bad469 26416 len = strlen (str);
7ed4c4c5 26417
f3bad469 26418 if (len == 0)
7ed4c4c5 26419 {
c19d1205 26420 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26421 return FALSE;
7ed4c4c5
NC
26422 }
26423
c19d1205 26424 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26425 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26426 {
e74cfd16
PB
26427 march_cpu_opt = &opt->value;
26428 march_fpu_opt = &opt->default_fpu;
5f4273c7 26429 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26430
c19d1205 26431 if (ext != NULL)
c168ce07 26432 return arm_parse_extension (ext, march_cpu_opt, &dyn_march_ext_opt);
7ed4c4c5 26433
c921be7d 26434 return TRUE;
c19d1205
ZW
26435 }
26436
26437 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26438 return FALSE;
7ed4c4c5 26439}
eb043451 26440
c921be7d 26441static bfd_boolean
17b9d67d 26442arm_parse_fpu (const char * str)
c19d1205 26443{
69133863 26444 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26445
c19d1205
ZW
26446 for (opt = arm_fpus; opt->name != NULL; opt++)
26447 if (streq (opt->name, str))
26448 {
e74cfd16 26449 mfpu_opt = &opt->value;
c921be7d 26450 return TRUE;
c19d1205 26451 }
b99bd4ef 26452
c19d1205 26453 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26454 return FALSE;
c19d1205
ZW
26455}
26456
c921be7d 26457static bfd_boolean
17b9d67d 26458arm_parse_float_abi (const char * str)
b99bd4ef 26459{
e74cfd16 26460 const struct arm_option_value_table * opt;
b99bd4ef 26461
c19d1205
ZW
26462 for (opt = arm_float_abis; opt->name != NULL; opt++)
26463 if (streq (opt->name, str))
26464 {
26465 mfloat_abi_opt = opt->value;
c921be7d 26466 return TRUE;
c19d1205 26467 }
cc8a6dd0 26468
c19d1205 26469 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26470 return FALSE;
c19d1205 26471}
b99bd4ef 26472
c19d1205 26473#ifdef OBJ_ELF
c921be7d 26474static bfd_boolean
17b9d67d 26475arm_parse_eabi (const char * str)
c19d1205 26476{
e74cfd16 26477 const struct arm_option_value_table *opt;
cc8a6dd0 26478
c19d1205
ZW
26479 for (opt = arm_eabis; opt->name != NULL; opt++)
26480 if (streq (opt->name, str))
26481 {
26482 meabi_flags = opt->value;
c921be7d 26483 return TRUE;
c19d1205
ZW
26484 }
26485 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26486 return FALSE;
c19d1205
ZW
26487}
26488#endif
cc8a6dd0 26489
c921be7d 26490static bfd_boolean
17b9d67d 26491arm_parse_it_mode (const char * str)
e07e6e58 26492{
c921be7d 26493 bfd_boolean ret = TRUE;
e07e6e58
NC
26494
26495 if (streq ("arm", str))
26496 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26497 else if (streq ("thumb", str))
26498 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26499 else if (streq ("always", str))
26500 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26501 else if (streq ("never", str))
26502 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26503 else
26504 {
26505 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26506 "arm, thumb, always, or never."), str);
c921be7d 26507 ret = FALSE;
e07e6e58
NC
26508 }
26509
26510 return ret;
26511}
26512
2e6976a8 26513static bfd_boolean
17b9d67d 26514arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26515{
26516 codecomposer_syntax = TRUE;
26517 arm_comment_chars[0] = ';';
26518 arm_line_separator_chars[0] = 0;
26519 return TRUE;
26520}
26521
c19d1205
ZW
26522struct arm_long_option_table arm_long_opts[] =
26523{
26524 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26525 arm_parse_cpu, NULL},
26526 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26527 arm_parse_arch, NULL},
26528 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26529 arm_parse_fpu, NULL},
26530 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26531 arm_parse_float_abi, NULL},
26532#ifdef OBJ_ELF
7fac0536 26533 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26534 arm_parse_eabi, NULL},
26535#endif
e07e6e58
NC
26536 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26537 arm_parse_it_mode, NULL},
2e6976a8
DG
26538 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26539 arm_ccs_mode, NULL},
c19d1205
ZW
26540 {NULL, NULL, 0, NULL}
26541};
cc8a6dd0 26542
c19d1205 26543int
17b9d67d 26544md_parse_option (int c, const char * arg)
c19d1205
ZW
26545{
26546 struct arm_option_table *opt;
e74cfd16 26547 const struct arm_legacy_option_table *fopt;
c19d1205 26548 struct arm_long_option_table *lopt;
b99bd4ef 26549
c19d1205 26550 switch (c)
b99bd4ef 26551 {
c19d1205
ZW
26552#ifdef OPTION_EB
26553 case OPTION_EB:
26554 target_big_endian = 1;
26555 break;
26556#endif
cc8a6dd0 26557
c19d1205
ZW
26558#ifdef OPTION_EL
26559 case OPTION_EL:
26560 target_big_endian = 0;
26561 break;
26562#endif
b99bd4ef 26563
845b51d6
PB
26564 case OPTION_FIX_V4BX:
26565 fix_v4bx = TRUE;
26566 break;
26567
c19d1205
ZW
26568 case 'a':
26569 /* Listing option. Just ignore these, we don't support additional
26570 ones. */
26571 return 0;
b99bd4ef 26572
c19d1205
ZW
26573 default:
26574 for (opt = arm_opts; opt->option != NULL; opt++)
26575 {
26576 if (c == opt->option[0]
26577 && ((arg == NULL && opt->option[1] == 0)
26578 || streq (arg, opt->option + 1)))
26579 {
c19d1205 26580 /* If the option is deprecated, tell the user. */
278df34e 26581 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26582 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26583 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26584
c19d1205
ZW
26585 if (opt->var != NULL)
26586 *opt->var = opt->value;
cc8a6dd0 26587
c19d1205
ZW
26588 return 1;
26589 }
26590 }
b99bd4ef 26591
e74cfd16
PB
26592 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26593 {
26594 if (c == fopt->option[0]
26595 && ((arg == NULL && fopt->option[1] == 0)
26596 || streq (arg, fopt->option + 1)))
26597 {
e74cfd16 26598 /* If the option is deprecated, tell the user. */
278df34e 26599 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26600 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26601 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26602
26603 if (fopt->var != NULL)
26604 *fopt->var = &fopt->value;
26605
26606 return 1;
26607 }
26608 }
26609
c19d1205
ZW
26610 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26611 {
26612 /* These options are expected to have an argument. */
26613 if (c == lopt->option[0]
26614 && arg != NULL
26615 && strncmp (arg, lopt->option + 1,
26616 strlen (lopt->option + 1)) == 0)
26617 {
c19d1205 26618 /* If the option is deprecated, tell the user. */
278df34e 26619 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26620 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26621 _(lopt->deprecated));
b99bd4ef 26622
c19d1205
ZW
26623 /* Call the sup-option parser. */
26624 return lopt->func (arg + strlen (lopt->option) - 1);
26625 }
26626 }
a737bd4d 26627
c19d1205
ZW
26628 return 0;
26629 }
a394c00f 26630
c19d1205
ZW
26631 return 1;
26632}
a394c00f 26633
c19d1205
ZW
26634void
26635md_show_usage (FILE * fp)
a394c00f 26636{
c19d1205
ZW
26637 struct arm_option_table *opt;
26638 struct arm_long_option_table *lopt;
a394c00f 26639
c19d1205 26640 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26641
c19d1205
ZW
26642 for (opt = arm_opts; opt->option != NULL; opt++)
26643 if (opt->help != NULL)
26644 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26645
c19d1205
ZW
26646 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26647 if (lopt->help != NULL)
26648 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26649
c19d1205
ZW
26650#ifdef OPTION_EB
26651 fprintf (fp, _("\
26652 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26653#endif
26654
c19d1205
ZW
26655#ifdef OPTION_EL
26656 fprintf (fp, _("\
26657 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26658#endif
845b51d6
PB
26659
26660 fprintf (fp, _("\
26661 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26662}
ee065d83
PB
26663
26664
26665#ifdef OBJ_ELF
62b3e311
PB
26666typedef struct
26667{
26668 int val;
26669 arm_feature_set flags;
26670} cpu_arch_ver_table;
26671
2c6b98ea
TP
26672/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26673 chronologically for architectures, with an exception for ARMv6-M and
26674 ARMv6S-M due to legacy reasons. No new architecture should have a
26675 special case. This allows for build attribute selection results to be
26676 stable when new architectures are added. */
62b3e311
PB
26677static const cpu_arch_ver_table cpu_arch_ver[] =
26678{
2c6b98ea
TP
26679 {0, ARM_ARCH_V1},
26680 {0, ARM_ARCH_V2},
26681 {0, ARM_ARCH_V2S},
26682 {0, ARM_ARCH_V3},
26683 {0, ARM_ARCH_V3M},
26684 {1, ARM_ARCH_V4xM},
62b3e311 26685 {1, ARM_ARCH_V4},
2c6b98ea 26686 {2, ARM_ARCH_V4TxM},
62b3e311 26687 {2, ARM_ARCH_V4T},
2c6b98ea 26688 {3, ARM_ARCH_V5xM},
62b3e311 26689 {3, ARM_ARCH_V5},
2c6b98ea 26690 {3, ARM_ARCH_V5TxM},
ee3c0378 26691 {3, ARM_ARCH_V5T},
2c6b98ea 26692 {4, ARM_ARCH_V5TExP},
62b3e311
PB
26693 {4, ARM_ARCH_V5TE},
26694 {5, ARM_ARCH_V5TEJ},
26695 {6, ARM_ARCH_V6},
f4c65163 26696 {7, ARM_ARCH_V6Z},
2c6b98ea
TP
26697 {7, ARM_ARCH_V6KZ},
26698 {9, ARM_ARCH_V6K},
26699 {8, ARM_ARCH_V6T2},
26700 {8, ARM_ARCH_V6KT2},
26701 {8, ARM_ARCH_V6ZT2},
26702 {8, ARM_ARCH_V6KZT2},
26703
26704 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
26705 always selected build attributes to match those of ARMv6-M
26706 (resp. ARMv6S-M). However, due to these architectures being a strict
26707 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
26708 would be selected when fully respecting chronology of architectures.
26709 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
26710 move them before ARMv7 architectures. */
91e22acd 26711 {11, ARM_ARCH_V6M},
b2a5fbdc 26712 {12, ARM_ARCH_V6SM},
2c6b98ea
TP
26713
26714 {10, ARM_ARCH_V7},
26715 {10, ARM_ARCH_V7A},
62b3e311
PB
26716 {10, ARM_ARCH_V7R},
26717 {10, ARM_ARCH_V7M},
2c6b98ea
TP
26718 {10, ARM_ARCH_V7VE},
26719 {13, ARM_ARCH_V7EM},
bca38921 26720 {14, ARM_ARCH_V8A},
2c6b98ea
TP
26721 {14, ARM_ARCH_V8_1A},
26722 {14, ARM_ARCH_V8_2A},
26723 {14, ARM_ARCH_V8_3A},
ff8646ee 26724 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26725 {17, ARM_ARCH_V8M_MAIN},
ced40572 26726 {15, ARM_ARCH_V8R},
2c6b98ea 26727 {-1, ARM_ARCH_NONE}
62b3e311
PB
26728};
26729
ee3c0378
AS
26730/* Set an attribute if it has not already been set by the user. */
26731static void
26732aeabi_set_attribute_int (int tag, int value)
26733{
26734 if (tag < 1
26735 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26736 || !attributes_set_explicitly[tag])
26737 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26738}
26739
26740static void
26741aeabi_set_attribute_string (int tag, const char *value)
26742{
26743 if (tag < 1
26744 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26745 || !attributes_set_explicitly[tag])
26746 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26747}
26748
2c6b98ea
TP
26749/* Return whether features in the *NEEDED feature set are available via
26750 extensions for the architecture whose feature set is *ARCH_FSET. */
26751static bfd_boolean
26752have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
26753 const arm_feature_set *needed)
26754{
26755 int i, nb_allowed_archs;
26756 arm_feature_set ext_fset;
26757 const struct arm_option_extension_value_table *opt;
26758
26759 ext_fset = arm_arch_none;
26760 for (opt = arm_extensions; opt->name != NULL; opt++)
26761 {
26762 /* Extension does not provide any feature we need. */
26763 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
26764 continue;
26765
26766 nb_allowed_archs =
26767 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
26768 for (i = 0; i < nb_allowed_archs; i++)
26769 {
26770 /* Empty entry. */
26771 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
26772 break;
26773
26774 /* Extension is available, add it. */
26775 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
26776 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
26777 }
26778 }
26779
26780 /* Can we enable all features in *needed? */
26781 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
26782}
26783
26784/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
26785 a given architecture feature set *ARCH_EXT_FSET including extension feature
26786 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
26787 - if true, check for an exact match of the architecture modulo extensions;
26788 - otherwise, select build attribute value of the first superset
26789 architecture released so that results remains stable when new architectures
26790 are added.
26791 For -march/-mcpu=all the build attribute value of the most featureful
26792 architecture is returned. Tag_CPU_arch_profile result is returned in
26793 PROFILE. */
26794static int
26795get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
26796 const arm_feature_set *ext_fset,
26797 char *profile, int exact_match)
26798{
26799 arm_feature_set arch_fset;
26800 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
26801
26802 /* Select most featureful architecture with all its extensions if building
26803 for -march=all as the feature sets used to set build attributes. */
26804 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
26805 {
26806 /* Force revisiting of decision for each new architecture. */
26807 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
26808 *profile = 'A';
26809 return TAG_CPU_ARCH_V8;
26810 }
26811
26812 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
26813
26814 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
26815 {
26816 arm_feature_set known_arch_fset;
26817
26818 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
26819 if (exact_match)
26820 {
26821 /* Base architecture match user-specified architecture and
26822 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
26823 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
26824 {
26825 p_ver_ret = p_ver;
26826 goto found;
26827 }
26828 /* Base architecture match user-specified architecture only
26829 (eg. ARMv6-M in the same case as above). Record it in case we
26830 find a match with above condition. */
26831 else if (p_ver_ret == NULL
26832 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
26833 p_ver_ret = p_ver;
26834 }
26835 else
26836 {
26837
26838 /* Architecture has all features wanted. */
26839 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
26840 {
26841 arm_feature_set added_fset;
26842
26843 /* Compute features added by this architecture over the one
26844 recorded in p_ver_ret. */
26845 if (p_ver_ret != NULL)
26846 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
26847 p_ver_ret->flags);
26848 /* First architecture that match incl. with extensions, or the
26849 only difference in features over the recorded match is
26850 features that were optional and are now mandatory. */
26851 if (p_ver_ret == NULL
26852 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
26853 {
26854 p_ver_ret = p_ver;
26855 goto found;
26856 }
26857 }
26858 else if (p_ver_ret == NULL)
26859 {
26860 arm_feature_set needed_ext_fset;
26861
26862 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
26863
26864 /* Architecture has all features needed when using some
26865 extensions. Record it and continue searching in case there
26866 exist an architecture providing all needed features without
26867 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
26868 OS extension). */
26869 if (have_ext_for_needed_feat_p (&known_arch_fset,
26870 &needed_ext_fset))
26871 p_ver_ret = p_ver;
26872 }
26873 }
26874 }
26875
26876 if (p_ver_ret == NULL)
26877 return -1;
26878
26879found:
26880 /* Tag_CPU_arch_profile. */
26881 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
26882 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
26883 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
26884 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
26885 *profile = 'A';
26886 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
26887 *profile = 'R';
26888 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
26889 *profile = 'M';
26890 else
26891 *profile = '\0';
26892 return p_ver_ret->val;
26893}
26894
ee065d83 26895/* Set the public EABI object attributes. */
c168ce07 26896static void
ee065d83
PB
26897aeabi_set_public_attributes (void)
26898{
69239280 26899 char profile;
2c6b98ea 26900 int arch = -1;
90ec0d68 26901 int virt_sec = 0;
bca38921 26902 int fp16_optional = 0;
2c6b98ea
TP
26903 int skip_exact_match = 0;
26904 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 26905
54bab281
TP
26906 /* Autodetection mode, choose the architecture based the instructions
26907 actually used. */
26908 if (no_cpu_selected ())
26909 {
26910 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 26911
54bab281
TP
26912 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26913 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 26914
54bab281
TP
26915 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26916 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 26917
54bab281
TP
26918 /* Code run during relaxation relies on selected_cpu being set. */
26919 selected_cpu = flags;
26920 }
26921 /* Otherwise, choose the architecture based on the capabilities of the
26922 requested cpu. */
26923 else
26924 flags = selected_cpu;
26925 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
7f78eb34 26926
ddd7f988 26927 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26928 if (object_arch)
26929 {
2c6b98ea
TP
26930 ARM_CLEAR_FEATURE (flags_arch, *object_arch, fpu_any);
26931 flags_ext = arm_arch_none;
7a1d4c38 26932 }
2c6b98ea 26933 else
62b3e311 26934 {
2c6b98ea
TP
26935 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
26936 flags_ext = dyn_mcpu_ext_opt ? *dyn_mcpu_ext_opt : arm_arch_none;
26937 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
26938 }
26939
26940 /* When this function is run again after relaxation has happened there is no
26941 way to determine whether an architecture or CPU was specified by the user:
26942 - selected_cpu is set above for relaxation to work;
26943 - march_cpu_opt is not set if only -mcpu or .cpu is used;
26944 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
26945 Therefore, if not in -march=all case we first try an exact match and fall
26946 back to autodetection. */
26947 if (!skip_exact_match)
26948 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
26949 if (arch == -1)
26950 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
26951 if (arch == -1)
26952 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 26953
ee065d83
PB
26954 /* Tag_CPU_name. */
26955 if (selected_cpu_name[0])
26956 {
91d6fa6a 26957 char *q;
ee065d83 26958
91d6fa6a
NC
26959 q = selected_cpu_name;
26960 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26961 {
26962 int i;
5f4273c7 26963
91d6fa6a
NC
26964 q += 4;
26965 for (i = 0; q[i]; i++)
26966 q[i] = TOUPPER (q[i]);
ee065d83 26967 }
91d6fa6a 26968 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26969 }
62f3b8c8 26970
ee065d83 26971 /* Tag_CPU_arch. */
ee3c0378 26972 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26973
62b3e311 26974 /* Tag_CPU_arch_profile. */
69239280
MGD
26975 if (profile != '\0')
26976 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26977
15afaa63 26978 /* Tag_DSP_extension. */
6c290d53
TP
26979 if (dyn_mcpu_ext_opt && ARM_CPU_HAS_FEATURE (*dyn_mcpu_ext_opt, arm_ext_dsp))
26980 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 26981
2c6b98ea 26982 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 26983 /* Tag_ARM_ISA_use. */
ee3c0378 26984 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 26985 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 26986 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26987
ee065d83 26988 /* Tag_THUMB_ISA_use. */
ee3c0378 26989 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 26990 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
26991 {
26992 int thumb_isa_use;
26993
26994 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26995 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26996 thumb_isa_use = 3;
26997 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26998 thumb_isa_use = 2;
26999 else
27000 thumb_isa_use = 1;
27001 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27002 }
62f3b8c8 27003
ee065d83 27004 /* Tag_VFP_arch. */
a715796b
TG
27005 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27006 aeabi_set_attribute_int (Tag_VFP_arch,
27007 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27008 ? 7 : 8);
bca38921 27009 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27010 aeabi_set_attribute_int (Tag_VFP_arch,
27011 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27012 ? 5 : 6);
27013 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27014 {
27015 fp16_optional = 1;
27016 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27017 }
ada65aa3 27018 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27019 {
27020 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27021 fp16_optional = 1;
27022 }
ee3c0378
AS
27023 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27024 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27025 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27026 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27027 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27028
4547cb56
NC
27029 /* Tag_ABI_HardFP_use. */
27030 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27031 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27032 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27033
ee065d83 27034 /* Tag_WMMX_arch. */
ee3c0378
AS
27035 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27036 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27037 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27038 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27039
ee3c0378 27040 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27041 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27042 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27043 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27044 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27045 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27046 {
27047 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27048 {
27049 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27050 }
27051 else
27052 {
27053 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27054 fp16_optional = 1;
27055 }
27056 }
fa94de6b 27057
ee3c0378 27058 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27059 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27060 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27061
69239280
MGD
27062 /* Tag_DIV_use.
27063
27064 We set Tag_DIV_use to two when integer divide instructions have been used
27065 in ARM state, or when Thumb integer divide instructions have been used,
27066 but we have no architecture profile set, nor have we any ARM instructions.
27067
4ed7ed8d
TP
27068 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27069 by the base architecture.
bca38921 27070
69239280 27071 For new architectures we will have to check these tests. */
ced40572 27072 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27073 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27074 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27075 aeabi_set_attribute_int (Tag_DIV_use, 0);
27076 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27077 || (profile == '\0'
27078 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27079 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27080 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27081
27082 /* Tag_MP_extension_use. */
27083 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27084 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27085
27086 /* Tag Virtualization_use. */
27087 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27088 virt_sec |= 1;
27089 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27090 virt_sec |= 2;
27091 if (virt_sec != 0)
27092 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27093}
27094
c168ce07
TP
27095/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27096 finished and free extension feature bits which will not be used anymore. */
27097void
27098arm_md_post_relax (void)
27099{
27100 aeabi_set_public_attributes ();
27101 XDELETE (dyn_mcpu_ext_opt);
27102 dyn_mcpu_ext_opt = NULL;
27103 XDELETE (dyn_march_ext_opt);
27104 dyn_march_ext_opt = NULL;
27105}
27106
104d59d1 27107/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
27108void
27109arm_md_end (void)
27110{
ee065d83
PB
27111 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27112 return;
27113
27114 aeabi_set_public_attributes ();
ee065d83 27115}
8463be01 27116#endif /* OBJ_ELF */
ee065d83
PB
27117
27118
27119/* Parse a .cpu directive. */
27120
27121static void
27122s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27123{
e74cfd16 27124 const struct arm_cpu_option_table *opt;
ee065d83
PB
27125 char *name;
27126 char saved_char;
27127
27128 name = input_line_pointer;
5f4273c7 27129 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27130 input_line_pointer++;
27131 saved_char = *input_line_pointer;
27132 *input_line_pointer = 0;
27133
27134 /* Skip the first "all" entry. */
27135 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27136 if (streq (opt->name, name))
27137 {
c168ce07
TP
27138 mcpu_cpu_opt = &opt->value;
27139 if (!dyn_mcpu_ext_opt)
27140 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27141 *dyn_mcpu_ext_opt = opt->ext;
27142 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
ee065d83 27143 if (opt->canonical_name)
5f4273c7 27144 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27145 else
27146 {
27147 int i;
27148 for (i = 0; opt->name[i]; i++)
27149 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27150
ee065d83
PB
27151 selected_cpu_name[i] = 0;
27152 }
e74cfd16 27153 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27154 if (dyn_mcpu_ext_opt)
27155 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27156 *input_line_pointer = saved_char;
27157 demand_empty_rest_of_line ();
27158 return;
27159 }
27160 as_bad (_("unknown cpu `%s'"), name);
27161 *input_line_pointer = saved_char;
27162 ignore_rest_of_line ();
27163}
27164
27165
27166/* Parse a .arch directive. */
27167
27168static void
27169s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27170{
e74cfd16 27171 const struct arm_arch_option_table *opt;
ee065d83
PB
27172 char saved_char;
27173 char *name;
27174
27175 name = input_line_pointer;
5f4273c7 27176 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27177 input_line_pointer++;
27178 saved_char = *input_line_pointer;
27179 *input_line_pointer = 0;
27180
27181 /* Skip the first "all" entry. */
27182 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27183 if (streq (opt->name, name))
27184 {
e74cfd16 27185 mcpu_cpu_opt = &opt->value;
c168ce07
TP
27186 XDELETE (dyn_mcpu_ext_opt);
27187 dyn_mcpu_ext_opt = NULL;
27188 selected_cpu = *mcpu_cpu_opt;
5f4273c7 27189 strcpy (selected_cpu_name, opt->name);
c168ce07 27190 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
ee065d83
PB
27191 *input_line_pointer = saved_char;
27192 demand_empty_rest_of_line ();
27193 return;
27194 }
27195
27196 as_bad (_("unknown architecture `%s'\n"), name);
27197 *input_line_pointer = saved_char;
27198 ignore_rest_of_line ();
27199}
27200
27201
7a1d4c38
PB
27202/* Parse a .object_arch directive. */
27203
27204static void
27205s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27206{
27207 const struct arm_arch_option_table *opt;
27208 char saved_char;
27209 char *name;
27210
27211 name = input_line_pointer;
5f4273c7 27212 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27213 input_line_pointer++;
27214 saved_char = *input_line_pointer;
27215 *input_line_pointer = 0;
27216
27217 /* Skip the first "all" entry. */
27218 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27219 if (streq (opt->name, name))
27220 {
27221 object_arch = &opt->value;
27222 *input_line_pointer = saved_char;
27223 demand_empty_rest_of_line ();
27224 return;
27225 }
27226
27227 as_bad (_("unknown architecture `%s'\n"), name);
27228 *input_line_pointer = saved_char;
27229 ignore_rest_of_line ();
27230}
27231
69133863
MGD
27232/* Parse a .arch_extension directive. */
27233
27234static void
27235s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27236{
27237 const struct arm_option_extension_value_table *opt;
d942732e 27238 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
27239 char saved_char;
27240 char *name;
27241 int adding_value = 1;
27242
27243 name = input_line_pointer;
27244 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27245 input_line_pointer++;
27246 saved_char = *input_line_pointer;
27247 *input_line_pointer = 0;
27248
27249 if (strlen (name) >= 2
27250 && strncmp (name, "no", 2) == 0)
27251 {
27252 adding_value = 0;
27253 name += 2;
27254 }
27255
27256 for (opt = arm_extensions; opt->name != NULL; opt++)
27257 if (streq (opt->name, name))
27258 {
d942732e
TP
27259 int i, nb_allowed_archs =
27260 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27261 for (i = 0; i < nb_allowed_archs; i++)
27262 {
27263 /* Empty entry. */
27264 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27265 continue;
27266 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
27267 break;
27268 }
27269
27270 if (i == nb_allowed_archs)
69133863
MGD
27271 {
27272 as_bad (_("architectural extension `%s' is not allowed for the "
27273 "current base architecture"), name);
27274 break;
27275 }
27276
c168ce07
TP
27277 if (!dyn_mcpu_ext_opt)
27278 {
27279 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27280 *dyn_mcpu_ext_opt = arm_arch_none;
27281 }
69133863 27282 if (adding_value)
c168ce07 27283 ARM_MERGE_FEATURE_SETS (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
5a70a223 27284 opt->merge_value);
69133863 27285 else
c168ce07
TP
27286 ARM_CLEAR_FEATURE (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
27287 opt->clear_value);
69133863 27288
c168ce07
TP
27289 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
27290 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
69133863
MGD
27291 *input_line_pointer = saved_char;
27292 demand_empty_rest_of_line ();
3d030cdb
TP
27293 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27294 on this return so that duplicate extensions (extensions with the
27295 same name as a previous extension in the list) are not considered
27296 for command-line parsing. */
69133863
MGD
27297 return;
27298 }
27299
27300 if (opt->name == NULL)
e673710a 27301 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27302
27303 *input_line_pointer = saved_char;
27304 ignore_rest_of_line ();
27305}
27306
ee065d83
PB
27307/* Parse a .fpu directive. */
27308
27309static void
27310s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27311{
69133863 27312 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27313 char saved_char;
27314 char *name;
27315
27316 name = input_line_pointer;
5f4273c7 27317 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27318 input_line_pointer++;
27319 saved_char = *input_line_pointer;
27320 *input_line_pointer = 0;
5f4273c7 27321
ee065d83
PB
27322 for (opt = arm_fpus; opt->name != NULL; opt++)
27323 if (streq (opt->name, name))
27324 {
e74cfd16
PB
27325 mfpu_opt = &opt->value;
27326 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27327 if (dyn_mcpu_ext_opt)
27328 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27329 *input_line_pointer = saved_char;
27330 demand_empty_rest_of_line ();
27331 return;
27332 }
27333
27334 as_bad (_("unknown floating point format `%s'\n"), name);
27335 *input_line_pointer = saved_char;
27336 ignore_rest_of_line ();
27337}
ee065d83 27338
794ba86a 27339/* Copy symbol information. */
f31fef98 27340
794ba86a
DJ
27341void
27342arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27343{
27344 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27345}
e04befd0 27346
f31fef98 27347#ifdef OBJ_ELF
e04befd0
AS
27348/* Given a symbolic attribute NAME, return the proper integer value.
27349 Returns -1 if the attribute is not known. */
f31fef98 27350
e04befd0
AS
27351int
27352arm_convert_symbolic_attribute (const char *name)
27353{
f31fef98
NC
27354 static const struct
27355 {
27356 const char * name;
27357 const int tag;
27358 }
27359 attribute_table[] =
27360 {
27361 /* When you modify this table you should
27362 also modify the list in doc/c-arm.texi. */
e04befd0 27363#define T(tag) {#tag, tag}
f31fef98
NC
27364 T (Tag_CPU_raw_name),
27365 T (Tag_CPU_name),
27366 T (Tag_CPU_arch),
27367 T (Tag_CPU_arch_profile),
27368 T (Tag_ARM_ISA_use),
27369 T (Tag_THUMB_ISA_use),
75375b3e 27370 T (Tag_FP_arch),
f31fef98
NC
27371 T (Tag_VFP_arch),
27372 T (Tag_WMMX_arch),
27373 T (Tag_Advanced_SIMD_arch),
27374 T (Tag_PCS_config),
27375 T (Tag_ABI_PCS_R9_use),
27376 T (Tag_ABI_PCS_RW_data),
27377 T (Tag_ABI_PCS_RO_data),
27378 T (Tag_ABI_PCS_GOT_use),
27379 T (Tag_ABI_PCS_wchar_t),
27380 T (Tag_ABI_FP_rounding),
27381 T (Tag_ABI_FP_denormal),
27382 T (Tag_ABI_FP_exceptions),
27383 T (Tag_ABI_FP_user_exceptions),
27384 T (Tag_ABI_FP_number_model),
75375b3e 27385 T (Tag_ABI_align_needed),
f31fef98 27386 T (Tag_ABI_align8_needed),
75375b3e 27387 T (Tag_ABI_align_preserved),
f31fef98
NC
27388 T (Tag_ABI_align8_preserved),
27389 T (Tag_ABI_enum_size),
27390 T (Tag_ABI_HardFP_use),
27391 T (Tag_ABI_VFP_args),
27392 T (Tag_ABI_WMMX_args),
27393 T (Tag_ABI_optimization_goals),
27394 T (Tag_ABI_FP_optimization_goals),
27395 T (Tag_compatibility),
27396 T (Tag_CPU_unaligned_access),
75375b3e 27397 T (Tag_FP_HP_extension),
f31fef98
NC
27398 T (Tag_VFP_HP_extension),
27399 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27400 T (Tag_MPextension_use),
27401 T (Tag_DIV_use),
f31fef98
NC
27402 T (Tag_nodefaults),
27403 T (Tag_also_compatible_with),
27404 T (Tag_conformance),
27405 T (Tag_T2EE_use),
27406 T (Tag_Virtualization_use),
15afaa63 27407 T (Tag_DSP_extension),
cd21e546 27408 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27409#undef T
f31fef98 27410 };
e04befd0
AS
27411 unsigned int i;
27412
27413 if (name == NULL)
27414 return -1;
27415
f31fef98 27416 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27417 if (streq (name, attribute_table[i].name))
e04befd0
AS
27418 return attribute_table[i].tag;
27419
27420 return -1;
27421}
267bf995
RR
27422
27423
93ef582d
NC
27424/* Apply sym value for relocations only in the case that they are for
27425 local symbols in the same segment as the fixup and you have the
27426 respective architectural feature for blx and simple switches. */
267bf995 27427int
93ef582d 27428arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27429{
27430 if (fixP->fx_addsy
27431 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27432 /* PR 17444: If the local symbol is in a different section then a reloc
27433 will always be generated for it, so applying the symbol value now
27434 will result in a double offset being stored in the relocation. */
27435 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27436 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27437 {
27438 switch (fixP->fx_r_type)
27439 {
27440 case BFD_RELOC_ARM_PCREL_BLX:
27441 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27442 if (ARM_IS_FUNC (fixP->fx_addsy))
27443 return 1;
27444 break;
27445
27446 case BFD_RELOC_ARM_PCREL_CALL:
27447 case BFD_RELOC_THUMB_PCREL_BLX:
27448 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27449 return 1;
267bf995
RR
27450 break;
27451
27452 default:
27453 break;
27454 }
27455
27456 }
27457 return 0;
27458}
f31fef98 27459#endif /* OBJ_ELF */