]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
xtensa message pluralization
[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. */
0198d5e6
TC
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;
150static arm_feature_set * dyn_mcpu_ext_opt = NULL;
151static const arm_feature_set * mcpu_fpu_opt = NULL;
152static const arm_feature_set * march_cpu_opt = NULL;
153static arm_feature_set * dyn_march_ext_opt = NULL;
154static const arm_feature_set * march_fpu_opt = NULL;
155static const arm_feature_set * mfpu_opt = NULL;
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 175static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
4070243b 176static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
823d2571
TG
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{
0198d5e6 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
0198d5e6 980static bfd_boolean
c19d1205
ZW
981walk_no_bignums (symbolS * sp)
982{
983 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 984 return TRUE;
c19d1205
ZW
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
0198d5e6 993 return FALSE;
3d0c9500
NC
994}
995
0198d5e6 996static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
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;
0198d5e6
TC
1033 default:
1034 abort ();
c19d1205 1035 }
b99bd4ef 1036
c19d1205 1037 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1038
c19d1205
ZW
1039 save_in = input_line_pointer;
1040 input_line_pointer = *str;
0198d5e6 1041 in_my_get_expression = TRUE;
c19d1205 1042 seg = expression (ep);
0198d5e6 1043 in_my_get_expression = FALSE;
c19d1205 1044
f86adc07 1045 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1046 {
f86adc07 1047 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1048 *str = input_line_pointer;
1049 input_line_pointer = save_in;
1050 if (inst.error == NULL)
f86adc07
NS
1051 inst.error = (ep->X_op == O_absent
1052 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1053 return 1;
1054 }
b99bd4ef 1055
c19d1205
ZW
1056#ifdef OBJ_AOUT
1057 if (seg != absolute_section
1058 && seg != text_section
1059 && seg != data_section
1060 && seg != bss_section
1061 && seg != undefined_section)
1062 {
1063 inst.error = _("bad segment");
1064 *str = input_line_pointer;
1065 input_line_pointer = save_in;
1066 return 1;
b99bd4ef 1067 }
87975d2a
AM
1068#else
1069 (void) seg;
c19d1205 1070#endif
b99bd4ef 1071
c19d1205
ZW
1072 /* Get rid of any bignums now, so that we don't generate an error for which
1073 we can't establish a line number later on. Big numbers are never valid
1074 in instructions, which is where this routine is always called. */
5287ad62
JB
1075 if (prefix_mode != GE_OPT_PREFIX_BIG
1076 && (ep->X_op == O_big
477330fc 1077 || (ep->X_add_symbol
5287ad62 1078 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1079 || (ep->X_op_symbol
5287ad62 1080 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1081 {
1082 inst.error = _("invalid constant");
1083 *str = input_line_pointer;
1084 input_line_pointer = save_in;
1085 return 1;
1086 }
b99bd4ef 1087
c19d1205
ZW
1088 *str = input_line_pointer;
1089 input_line_pointer = save_in;
0198d5e6 1090 return SUCCESS;
b99bd4ef
NC
1091}
1092
c19d1205
ZW
1093/* Turn a string in input_line_pointer into a floating point constant
1094 of type TYPE, and store the appropriate bytes in *LITP. The number
1095 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1096 returned, or NULL on OK.
b99bd4ef 1097
c19d1205
ZW
1098 Note that fp constants aren't represent in the normal way on the ARM.
1099 In big endian mode, things are as expected. However, in little endian
1100 mode fp constants are big-endian word-wise, and little-endian byte-wise
1101 within the words. For example, (double) 1.1 in big endian mode is
1102 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1103 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1104
c19d1205 1105 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1106
6d4af3c2 1107const char *
c19d1205
ZW
1108md_atof (int type, char * litP, int * sizeP)
1109{
1110 int prec;
1111 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1112 char *t;
1113 int i;
b99bd4ef 1114
c19d1205
ZW
1115 switch (type)
1116 {
1117 case 'f':
1118 case 'F':
1119 case 's':
1120 case 'S':
1121 prec = 2;
1122 break;
b99bd4ef 1123
c19d1205
ZW
1124 case 'd':
1125 case 'D':
1126 case 'r':
1127 case 'R':
1128 prec = 4;
1129 break;
b99bd4ef 1130
c19d1205
ZW
1131 case 'x':
1132 case 'X':
499ac353 1133 prec = 5;
c19d1205 1134 break;
b99bd4ef 1135
c19d1205
ZW
1136 case 'p':
1137 case 'P':
499ac353 1138 prec = 5;
c19d1205 1139 break;
a737bd4d 1140
c19d1205
ZW
1141 default:
1142 *sizeP = 0;
499ac353 1143 return _("Unrecognized or unsupported floating point constant");
c19d1205 1144 }
b99bd4ef 1145
c19d1205
ZW
1146 t = atof_ieee (input_line_pointer, type, words);
1147 if (t)
1148 input_line_pointer = t;
499ac353 1149 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1150
c19d1205
ZW
1151 if (target_big_endian)
1152 {
1153 for (i = 0; i < prec; i++)
1154 {
499ac353
NC
1155 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1156 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1157 }
1158 }
1159 else
1160 {
e74cfd16 1161 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1162 for (i = prec - 1; i >= 0; i--)
1163 {
499ac353
NC
1164 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1165 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1166 }
1167 else
1168 /* For a 4 byte float the order of elements in `words' is 1 0.
1169 For an 8 byte float the order is 1 0 3 2. */
1170 for (i = 0; i < prec; i += 2)
1171 {
499ac353
NC
1172 md_number_to_chars (litP, (valueT) words[i + 1],
1173 sizeof (LITTLENUM_TYPE));
1174 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1175 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1176 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1177 }
1178 }
b99bd4ef 1179
499ac353 1180 return NULL;
c19d1205 1181}
b99bd4ef 1182
c19d1205
ZW
1183/* We handle all bad expressions here, so that we can report the faulty
1184 instruction in the error message. */
0198d5e6 1185
c19d1205 1186void
91d6fa6a 1187md_operand (expressionS * exp)
c19d1205
ZW
1188{
1189 if (in_my_get_expression)
91d6fa6a 1190 exp->X_op = O_illegal;
b99bd4ef
NC
1191}
1192
c19d1205 1193/* Immediate values. */
b99bd4ef 1194
0198d5e6 1195#ifdef OBJ_ELF
c19d1205
ZW
1196/* Generic immediate-value read function for use in directives.
1197 Accepts anything that 'expression' can fold to a constant.
1198 *val receives the number. */
0198d5e6 1199
c19d1205
ZW
1200static int
1201immediate_for_directive (int *val)
b99bd4ef 1202{
c19d1205
ZW
1203 expressionS exp;
1204 exp.X_op = O_illegal;
b99bd4ef 1205
c19d1205
ZW
1206 if (is_immediate_prefix (*input_line_pointer))
1207 {
1208 input_line_pointer++;
1209 expression (&exp);
1210 }
b99bd4ef 1211
c19d1205
ZW
1212 if (exp.X_op != O_constant)
1213 {
1214 as_bad (_("expected #constant"));
1215 ignore_rest_of_line ();
1216 return FAIL;
1217 }
1218 *val = exp.X_add_number;
1219 return SUCCESS;
b99bd4ef 1220}
c19d1205 1221#endif
b99bd4ef 1222
c19d1205 1223/* Register parsing. */
b99bd4ef 1224
c19d1205
ZW
1225/* Generic register parser. CCP points to what should be the
1226 beginning of a register name. If it is indeed a valid register
1227 name, advance CCP over it and return the reg_entry structure;
1228 otherwise return NULL. Does not issue diagnostics. */
1229
1230static struct reg_entry *
1231arm_reg_parse_multi (char **ccp)
b99bd4ef 1232{
c19d1205
ZW
1233 char *start = *ccp;
1234 char *p;
1235 struct reg_entry *reg;
b99bd4ef 1236
477330fc
RM
1237 skip_whitespace (start);
1238
c19d1205
ZW
1239#ifdef REGISTER_PREFIX
1240 if (*start != REGISTER_PREFIX)
01cfc07f 1241 return NULL;
c19d1205
ZW
1242 start++;
1243#endif
1244#ifdef OPTIONAL_REGISTER_PREFIX
1245 if (*start == OPTIONAL_REGISTER_PREFIX)
1246 start++;
1247#endif
b99bd4ef 1248
c19d1205
ZW
1249 p = start;
1250 if (!ISALPHA (*p) || !is_name_beginner (*p))
1251 return NULL;
b99bd4ef 1252
c19d1205
ZW
1253 do
1254 p++;
1255 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1256
1257 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1258
1259 if (!reg)
1260 return NULL;
1261
1262 *ccp = p;
1263 return reg;
b99bd4ef
NC
1264}
1265
1266static int
dcbf9037 1267arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1268 enum arm_reg_type type)
b99bd4ef 1269{
c19d1205
ZW
1270 /* Alternative syntaxes are accepted for a few register classes. */
1271 switch (type)
1272 {
1273 case REG_TYPE_MVF:
1274 case REG_TYPE_MVD:
1275 case REG_TYPE_MVFX:
1276 case REG_TYPE_MVDX:
1277 /* Generic coprocessor register names are allowed for these. */
79134647 1278 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1279 return reg->number;
1280 break;
69b97547 1281
c19d1205
ZW
1282 case REG_TYPE_CP:
1283 /* For backward compatibility, a bare number is valid here. */
1284 {
1285 unsigned long processor = strtoul (start, ccp, 10);
1286 if (*ccp != start && processor <= 15)
1287 return processor;
1288 }
1a0670f3 1289 /* Fall through. */
6057a28f 1290
c19d1205
ZW
1291 case REG_TYPE_MMXWC:
1292 /* WC includes WCG. ??? I'm not sure this is true for all
1293 instructions that take WC registers. */
79134647 1294 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1295 return reg->number;
6057a28f 1296 break;
c19d1205 1297
6057a28f 1298 default:
c19d1205 1299 break;
6057a28f
NC
1300 }
1301
dcbf9037
JB
1302 return FAIL;
1303}
1304
1305/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1306 return value is the register number or FAIL. */
1307
1308static int
1309arm_reg_parse (char **ccp, enum arm_reg_type type)
1310{
1311 char *start = *ccp;
1312 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1313 int ret;
1314
1315 /* Do not allow a scalar (reg+index) to parse as a register. */
1316 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1317 return FAIL;
1318
1319 if (reg && reg->type == type)
1320 return reg->number;
1321
1322 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1323 return ret;
1324
c19d1205
ZW
1325 *ccp = start;
1326 return FAIL;
1327}
69b97547 1328
dcbf9037
JB
1329/* Parse a Neon type specifier. *STR should point at the leading '.'
1330 character. Does no verification at this stage that the type fits the opcode
1331 properly. E.g.,
1332
1333 .i32.i32.s16
1334 .s32.f32
1335 .u16
1336
1337 Can all be legally parsed by this function.
1338
1339 Fills in neon_type struct pointer with parsed information, and updates STR
1340 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1341 type, FAIL if not. */
1342
1343static int
1344parse_neon_type (struct neon_type *type, char **str)
1345{
1346 char *ptr = *str;
1347
1348 if (type)
1349 type->elems = 0;
1350
1351 while (type->elems < NEON_MAX_TYPE_ELS)
1352 {
1353 enum neon_el_type thistype = NT_untyped;
1354 unsigned thissize = -1u;
1355
1356 if (*ptr != '.')
1357 break;
1358
1359 ptr++;
1360
1361 /* Just a size without an explicit type. */
1362 if (ISDIGIT (*ptr))
1363 goto parsesize;
1364
1365 switch (TOLOWER (*ptr))
1366 {
1367 case 'i': thistype = NT_integer; break;
1368 case 'f': thistype = NT_float; break;
1369 case 'p': thistype = NT_poly; break;
1370 case 's': thistype = NT_signed; break;
1371 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1372 case 'd':
1373 thistype = NT_float;
1374 thissize = 64;
1375 ptr++;
1376 goto done;
dcbf9037
JB
1377 default:
1378 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1379 return FAIL;
1380 }
1381
1382 ptr++;
1383
1384 /* .f is an abbreviation for .f32. */
1385 if (thistype == NT_float && !ISDIGIT (*ptr))
1386 thissize = 32;
1387 else
1388 {
1389 parsesize:
1390 thissize = strtoul (ptr, &ptr, 10);
1391
1392 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1393 && thissize != 64)
1394 {
1395 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1396 return FAIL;
1397 }
1398 }
1399
037e8744 1400 done:
dcbf9037 1401 if (type)
477330fc
RM
1402 {
1403 type->el[type->elems].type = thistype;
dcbf9037
JB
1404 type->el[type->elems].size = thissize;
1405 type->elems++;
1406 }
1407 }
1408
1409 /* Empty/missing type is not a successful parse. */
1410 if (type->elems == 0)
1411 return FAIL;
1412
1413 *str = ptr;
1414
1415 return SUCCESS;
1416}
1417
1418/* Errors may be set multiple times during parsing or bit encoding
1419 (particularly in the Neon bits), but usually the earliest error which is set
1420 will be the most meaningful. Avoid overwriting it with later (cascading)
1421 errors by calling this function. */
1422
1423static void
1424first_error (const char *err)
1425{
1426 if (!inst.error)
1427 inst.error = err;
1428}
1429
1430/* Parse a single type, e.g. ".s32", leading period included. */
1431static int
1432parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1433{
1434 char *str = *ccp;
1435 struct neon_type optype;
1436
1437 if (*str == '.')
1438 {
1439 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1440 {
1441 if (optype.elems == 1)
1442 *vectype = optype.el[0];
1443 else
1444 {
1445 first_error (_("only one type should be specified for operand"));
1446 return FAIL;
1447 }
1448 }
dcbf9037 1449 else
477330fc
RM
1450 {
1451 first_error (_("vector type expected"));
1452 return FAIL;
1453 }
dcbf9037
JB
1454 }
1455 else
1456 return FAIL;
5f4273c7 1457
dcbf9037 1458 *ccp = str;
5f4273c7 1459
dcbf9037
JB
1460 return SUCCESS;
1461}
1462
1463/* Special meanings for indices (which have a range of 0-7), which will fit into
1464 a 4-bit integer. */
1465
1466#define NEON_ALL_LANES 15
1467#define NEON_INTERLEAVE_LANES 14
1468
1469/* Parse either a register or a scalar, with an optional type. Return the
1470 register number, and optionally fill in the actual type of the register
1471 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1472 type/index information in *TYPEINFO. */
1473
1474static int
1475parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1476 enum arm_reg_type *rtype,
1477 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1478{
1479 char *str = *ccp;
1480 struct reg_entry *reg = arm_reg_parse_multi (&str);
1481 struct neon_typed_alias atype;
1482 struct neon_type_el parsetype;
1483
1484 atype.defined = 0;
1485 atype.index = -1;
1486 atype.eltype.type = NT_invtype;
1487 atype.eltype.size = -1;
1488
1489 /* Try alternate syntax for some types of register. Note these are mutually
1490 exclusive with the Neon syntax extensions. */
1491 if (reg == NULL)
1492 {
1493 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1494 if (altreg != FAIL)
477330fc 1495 *ccp = str;
dcbf9037 1496 if (typeinfo)
477330fc 1497 *typeinfo = atype;
dcbf9037
JB
1498 return altreg;
1499 }
1500
037e8744
JB
1501 /* Undo polymorphism when a set of register types may be accepted. */
1502 if ((type == REG_TYPE_NDQ
1503 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1504 || (type == REG_TYPE_VFSD
477330fc 1505 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1506 || (type == REG_TYPE_NSDQ
477330fc
RM
1507 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1508 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1509 || (type == REG_TYPE_MMXWC
1510 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1511 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1512
1513 if (type != reg->type)
1514 return FAIL;
1515
1516 if (reg->neon)
1517 atype = *reg->neon;
5f4273c7 1518
dcbf9037
JB
1519 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1520 {
1521 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1522 {
1523 first_error (_("can't redefine type for operand"));
1524 return FAIL;
1525 }
dcbf9037
JB
1526 atype.defined |= NTA_HASTYPE;
1527 atype.eltype = parsetype;
1528 }
5f4273c7 1529
dcbf9037
JB
1530 if (skip_past_char (&str, '[') == SUCCESS)
1531 {
1532 if (type != REG_TYPE_VFD)
477330fc
RM
1533 {
1534 first_error (_("only D registers may be indexed"));
1535 return FAIL;
1536 }
5f4273c7 1537
dcbf9037 1538 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1539 {
1540 first_error (_("can't change index for operand"));
1541 return FAIL;
1542 }
dcbf9037
JB
1543
1544 atype.defined |= NTA_HASINDEX;
1545
1546 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1547 atype.index = NEON_ALL_LANES;
dcbf9037 1548 else
477330fc
RM
1549 {
1550 expressionS exp;
dcbf9037 1551
477330fc 1552 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1553
477330fc
RM
1554 if (exp.X_op != O_constant)
1555 {
1556 first_error (_("constant expression required"));
1557 return FAIL;
1558 }
dcbf9037 1559
477330fc
RM
1560 if (skip_past_char (&str, ']') == FAIL)
1561 return FAIL;
dcbf9037 1562
477330fc
RM
1563 atype.index = exp.X_add_number;
1564 }
dcbf9037 1565 }
5f4273c7 1566
dcbf9037
JB
1567 if (typeinfo)
1568 *typeinfo = atype;
5f4273c7 1569
dcbf9037
JB
1570 if (rtype)
1571 *rtype = type;
5f4273c7 1572
dcbf9037 1573 *ccp = str;
5f4273c7 1574
dcbf9037
JB
1575 return reg->number;
1576}
1577
1578/* Like arm_reg_parse, but allow allow the following extra features:
1579 - If RTYPE is non-zero, return the (possibly restricted) type of the
1580 register (e.g. Neon double or quad reg when either has been requested).
1581 - If this is a Neon vector type with additional type information, fill
1582 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1583 This function will fault on encountering a scalar. */
dcbf9037
JB
1584
1585static int
1586arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1587 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1588{
1589 struct neon_typed_alias atype;
1590 char *str = *ccp;
1591 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1592
1593 if (reg == FAIL)
1594 return FAIL;
1595
0855e32b
NS
1596 /* Do not allow regname(... to parse as a register. */
1597 if (*str == '(')
1598 return FAIL;
1599
dcbf9037
JB
1600 /* Do not allow a scalar (reg+index) to parse as a register. */
1601 if ((atype.defined & NTA_HASINDEX) != 0)
1602 {
1603 first_error (_("register operand expected, but got scalar"));
1604 return FAIL;
1605 }
1606
1607 if (vectype)
1608 *vectype = atype.eltype;
1609
1610 *ccp = str;
1611
1612 return reg;
1613}
1614
1615#define NEON_SCALAR_REG(X) ((X) >> 4)
1616#define NEON_SCALAR_INDEX(X) ((X) & 15)
1617
5287ad62
JB
1618/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1619 have enough information to be able to do a good job bounds-checking. So, we
1620 just do easy checks here, and do further checks later. */
1621
1622static int
dcbf9037 1623parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1624{
dcbf9037 1625 int reg;
5287ad62 1626 char *str = *ccp;
dcbf9037 1627 struct neon_typed_alias atype;
5f4273c7 1628
dcbf9037 1629 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1630
dcbf9037 1631 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1632 return FAIL;
5f4273c7 1633
dcbf9037 1634 if (atype.index == NEON_ALL_LANES)
5287ad62 1635 {
dcbf9037 1636 first_error (_("scalar must have an index"));
5287ad62
JB
1637 return FAIL;
1638 }
dcbf9037 1639 else if (atype.index >= 64 / elsize)
5287ad62 1640 {
dcbf9037 1641 first_error (_("scalar index out of range"));
5287ad62
JB
1642 return FAIL;
1643 }
5f4273c7 1644
dcbf9037
JB
1645 if (type)
1646 *type = atype.eltype;
5f4273c7 1647
5287ad62 1648 *ccp = str;
5f4273c7 1649
dcbf9037 1650 return reg * 16 + atype.index;
5287ad62
JB
1651}
1652
c19d1205 1653/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1654
c19d1205
ZW
1655static long
1656parse_reg_list (char ** strp)
1657{
1658 char * str = * strp;
1659 long range = 0;
1660 int another_range;
a737bd4d 1661
c19d1205
ZW
1662 /* We come back here if we get ranges concatenated by '+' or '|'. */
1663 do
6057a28f 1664 {
477330fc
RM
1665 skip_whitespace (str);
1666
c19d1205 1667 another_range = 0;
a737bd4d 1668
c19d1205
ZW
1669 if (*str == '{')
1670 {
1671 int in_range = 0;
1672 int cur_reg = -1;
a737bd4d 1673
c19d1205
ZW
1674 str++;
1675 do
1676 {
1677 int reg;
6057a28f 1678
dcbf9037 1679 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1680 {
dcbf9037 1681 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1682 return FAIL;
1683 }
a737bd4d 1684
c19d1205
ZW
1685 if (in_range)
1686 {
1687 int i;
a737bd4d 1688
c19d1205
ZW
1689 if (reg <= cur_reg)
1690 {
dcbf9037 1691 first_error (_("bad range in register list"));
c19d1205
ZW
1692 return FAIL;
1693 }
40a18ebd 1694
c19d1205
ZW
1695 for (i = cur_reg + 1; i < reg; i++)
1696 {
1697 if (range & (1 << i))
1698 as_tsktsk
1699 (_("Warning: duplicated register (r%d) in register list"),
1700 i);
1701 else
1702 range |= 1 << i;
1703 }
1704 in_range = 0;
1705 }
a737bd4d 1706
c19d1205
ZW
1707 if (range & (1 << reg))
1708 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1709 reg);
1710 else if (reg <= cur_reg)
1711 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1712
c19d1205
ZW
1713 range |= 1 << reg;
1714 cur_reg = reg;
1715 }
1716 while (skip_past_comma (&str) != FAIL
1717 || (in_range = 1, *str++ == '-'));
1718 str--;
a737bd4d 1719
d996d970 1720 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1721 {
dcbf9037 1722 first_error (_("missing `}'"));
c19d1205
ZW
1723 return FAIL;
1724 }
1725 }
1726 else
1727 {
91d6fa6a 1728 expressionS exp;
40a18ebd 1729
91d6fa6a 1730 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1731 return FAIL;
40a18ebd 1732
91d6fa6a 1733 if (exp.X_op == O_constant)
c19d1205 1734 {
91d6fa6a
NC
1735 if (exp.X_add_number
1736 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1737 {
1738 inst.error = _("invalid register mask");
1739 return FAIL;
1740 }
a737bd4d 1741
91d6fa6a 1742 if ((range & exp.X_add_number) != 0)
c19d1205 1743 {
91d6fa6a 1744 int regno = range & exp.X_add_number;
a737bd4d 1745
c19d1205
ZW
1746 regno &= -regno;
1747 regno = (1 << regno) - 1;
1748 as_tsktsk
1749 (_("Warning: duplicated register (r%d) in register list"),
1750 regno);
1751 }
a737bd4d 1752
91d6fa6a 1753 range |= exp.X_add_number;
c19d1205
ZW
1754 }
1755 else
1756 {
1757 if (inst.reloc.type != 0)
1758 {
1759 inst.error = _("expression too complex");
1760 return FAIL;
1761 }
a737bd4d 1762
91d6fa6a 1763 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1764 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1765 inst.reloc.pc_rel = 0;
1766 }
1767 }
a737bd4d 1768
c19d1205
ZW
1769 if (*str == '|' || *str == '+')
1770 {
1771 str++;
1772 another_range = 1;
1773 }
a737bd4d 1774 }
c19d1205 1775 while (another_range);
a737bd4d 1776
c19d1205
ZW
1777 *strp = str;
1778 return range;
a737bd4d
NC
1779}
1780
5287ad62
JB
1781/* Types of registers in a list. */
1782
1783enum reg_list_els
1784{
1785 REGLIST_VFP_S,
1786 REGLIST_VFP_D,
1787 REGLIST_NEON_D
1788};
1789
c19d1205
ZW
1790/* Parse a VFP register list. If the string is invalid return FAIL.
1791 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1792 register. Parses registers of type ETYPE.
1793 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1794 - Q registers can be used to specify pairs of D registers
1795 - { } can be omitted from around a singleton register list
477330fc
RM
1796 FIXME: This is not implemented, as it would require backtracking in
1797 some cases, e.g.:
1798 vtbl.8 d3,d4,d5
1799 This could be done (the meaning isn't really ambiguous), but doesn't
1800 fit in well with the current parsing framework.
dcbf9037
JB
1801 - 32 D registers may be used (also true for VFPv3).
1802 FIXME: Types are ignored in these register lists, which is probably a
1803 bug. */
6057a28f 1804
c19d1205 1805static int
037e8744 1806parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1807{
037e8744 1808 char *str = *ccp;
c19d1205
ZW
1809 int base_reg;
1810 int new_base;
21d799b5 1811 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1812 int max_regs = 0;
c19d1205
ZW
1813 int count = 0;
1814 int warned = 0;
1815 unsigned long mask = 0;
a737bd4d 1816 int i;
6057a28f 1817
477330fc 1818 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1819 {
1820 inst.error = _("expecting {");
1821 return FAIL;
1822 }
6057a28f 1823
5287ad62 1824 switch (etype)
c19d1205 1825 {
5287ad62 1826 case REGLIST_VFP_S:
c19d1205
ZW
1827 regtype = REG_TYPE_VFS;
1828 max_regs = 32;
5287ad62 1829 break;
5f4273c7 1830
5287ad62
JB
1831 case REGLIST_VFP_D:
1832 regtype = REG_TYPE_VFD;
b7fc2769 1833 break;
5f4273c7 1834
b7fc2769
JB
1835 case REGLIST_NEON_D:
1836 regtype = REG_TYPE_NDQ;
1837 break;
1838 }
1839
1840 if (etype != REGLIST_VFP_S)
1841 {
b1cc4aeb
PB
1842 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1843 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1844 {
1845 max_regs = 32;
1846 if (thumb_mode)
1847 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1848 fpu_vfp_ext_d32);
1849 else
1850 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1851 fpu_vfp_ext_d32);
1852 }
5287ad62 1853 else
477330fc 1854 max_regs = 16;
c19d1205 1855 }
6057a28f 1856
c19d1205 1857 base_reg = max_regs;
a737bd4d 1858
c19d1205
ZW
1859 do
1860 {
5287ad62 1861 int setmask = 1, addregs = 1;
dcbf9037 1862
037e8744 1863 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1864
c19d1205 1865 if (new_base == FAIL)
a737bd4d 1866 {
dcbf9037 1867 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1868 return FAIL;
1869 }
5f4273c7 1870
b7fc2769 1871 if (new_base >= max_regs)
477330fc
RM
1872 {
1873 first_error (_("register out of range in list"));
1874 return FAIL;
1875 }
5f4273c7 1876
5287ad62
JB
1877 /* Note: a value of 2 * n is returned for the register Q<n>. */
1878 if (regtype == REG_TYPE_NQ)
477330fc
RM
1879 {
1880 setmask = 3;
1881 addregs = 2;
1882 }
5287ad62 1883
c19d1205
ZW
1884 if (new_base < base_reg)
1885 base_reg = new_base;
a737bd4d 1886
5287ad62 1887 if (mask & (setmask << new_base))
c19d1205 1888 {
dcbf9037 1889 first_error (_("invalid register list"));
c19d1205 1890 return FAIL;
a737bd4d 1891 }
a737bd4d 1892
c19d1205
ZW
1893 if ((mask >> new_base) != 0 && ! warned)
1894 {
1895 as_tsktsk (_("register list not in ascending order"));
1896 warned = 1;
1897 }
0bbf2aa4 1898
5287ad62
JB
1899 mask |= setmask << new_base;
1900 count += addregs;
0bbf2aa4 1901
037e8744 1902 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1903 {
1904 int high_range;
0bbf2aa4 1905
037e8744 1906 str++;
0bbf2aa4 1907
037e8744 1908 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1909 == FAIL)
c19d1205
ZW
1910 {
1911 inst.error = gettext (reg_expected_msgs[regtype]);
1912 return FAIL;
1913 }
0bbf2aa4 1914
477330fc
RM
1915 if (high_range >= max_regs)
1916 {
1917 first_error (_("register out of range in list"));
1918 return FAIL;
1919 }
b7fc2769 1920
477330fc
RM
1921 if (regtype == REG_TYPE_NQ)
1922 high_range = high_range + 1;
5287ad62 1923
c19d1205
ZW
1924 if (high_range <= new_base)
1925 {
1926 inst.error = _("register range not in ascending order");
1927 return FAIL;
1928 }
0bbf2aa4 1929
5287ad62 1930 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1931 {
5287ad62 1932 if (mask & (setmask << new_base))
0bbf2aa4 1933 {
c19d1205
ZW
1934 inst.error = _("invalid register list");
1935 return FAIL;
0bbf2aa4 1936 }
c19d1205 1937
5287ad62
JB
1938 mask |= setmask << new_base;
1939 count += addregs;
0bbf2aa4 1940 }
0bbf2aa4 1941 }
0bbf2aa4 1942 }
037e8744 1943 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1944
037e8744 1945 str++;
0bbf2aa4 1946
c19d1205
ZW
1947 /* Sanity check -- should have raised a parse error above. */
1948 if (count == 0 || count > max_regs)
1949 abort ();
1950
1951 *pbase = base_reg;
1952
1953 /* Final test -- the registers must be consecutive. */
1954 mask >>= base_reg;
1955 for (i = 0; i < count; i++)
1956 {
1957 if ((mask & (1u << i)) == 0)
1958 {
1959 inst.error = _("non-contiguous register range");
1960 return FAIL;
1961 }
1962 }
1963
037e8744
JB
1964 *ccp = str;
1965
c19d1205 1966 return count;
b99bd4ef
NC
1967}
1968
dcbf9037
JB
1969/* True if two alias types are the same. */
1970
c921be7d 1971static bfd_boolean
dcbf9037
JB
1972neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1973{
1974 if (!a && !b)
c921be7d 1975 return TRUE;
5f4273c7 1976
dcbf9037 1977 if (!a || !b)
c921be7d 1978 return FALSE;
dcbf9037
JB
1979
1980 if (a->defined != b->defined)
c921be7d 1981 return FALSE;
5f4273c7 1982
dcbf9037
JB
1983 if ((a->defined & NTA_HASTYPE) != 0
1984 && (a->eltype.type != b->eltype.type
477330fc 1985 || a->eltype.size != b->eltype.size))
c921be7d 1986 return FALSE;
dcbf9037
JB
1987
1988 if ((a->defined & NTA_HASINDEX) != 0
1989 && (a->index != b->index))
c921be7d 1990 return FALSE;
5f4273c7 1991
c921be7d 1992 return TRUE;
dcbf9037
JB
1993}
1994
5287ad62
JB
1995/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1996 The base register is put in *PBASE.
dcbf9037 1997 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1998 the return value.
1999 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2000 Bits [6:5] encode the list length (minus one).
2001 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2002
5287ad62 2003#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2004#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2005#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2006
2007static int
dcbf9037 2008parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2009 struct neon_type_el *eltype)
5287ad62
JB
2010{
2011 char *ptr = *str;
2012 int base_reg = -1;
2013 int reg_incr = -1;
2014 int count = 0;
2015 int lane = -1;
2016 int leading_brace = 0;
2017 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2018 const char *const incr_error = _("register stride must be 1 or 2");
2019 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2020 struct neon_typed_alias firsttype;
f85d59c3
KT
2021 firsttype.defined = 0;
2022 firsttype.eltype.type = NT_invtype;
2023 firsttype.eltype.size = -1;
2024 firsttype.index = -1;
5f4273c7 2025
5287ad62
JB
2026 if (skip_past_char (&ptr, '{') == SUCCESS)
2027 leading_brace = 1;
5f4273c7 2028
5287ad62
JB
2029 do
2030 {
dcbf9037
JB
2031 struct neon_typed_alias atype;
2032 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2033
5287ad62 2034 if (getreg == FAIL)
477330fc
RM
2035 {
2036 first_error (_(reg_expected_msgs[rtype]));
2037 return FAIL;
2038 }
5f4273c7 2039
5287ad62 2040 if (base_reg == -1)
477330fc
RM
2041 {
2042 base_reg = getreg;
2043 if (rtype == REG_TYPE_NQ)
2044 {
2045 reg_incr = 1;
2046 }
2047 firsttype = atype;
2048 }
5287ad62 2049 else if (reg_incr == -1)
477330fc
RM
2050 {
2051 reg_incr = getreg - base_reg;
2052 if (reg_incr < 1 || reg_incr > 2)
2053 {
2054 first_error (_(incr_error));
2055 return FAIL;
2056 }
2057 }
5287ad62 2058 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2059 {
2060 first_error (_(incr_error));
2061 return FAIL;
2062 }
dcbf9037 2063
c921be7d 2064 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2065 {
2066 first_error (_(type_error));
2067 return FAIL;
2068 }
5f4273c7 2069
5287ad62 2070 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2071 modes. */
5287ad62 2072 if (ptr[0] == '-')
477330fc
RM
2073 {
2074 struct neon_typed_alias htype;
2075 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2076 if (lane == -1)
2077 lane = NEON_INTERLEAVE_LANES;
2078 else if (lane != NEON_INTERLEAVE_LANES)
2079 {
2080 first_error (_(type_error));
2081 return FAIL;
2082 }
2083 if (reg_incr == -1)
2084 reg_incr = 1;
2085 else if (reg_incr != 1)
2086 {
2087 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2088 return FAIL;
2089 }
2090 ptr++;
2091 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2092 if (hireg == FAIL)
2093 {
2094 first_error (_(reg_expected_msgs[rtype]));
2095 return FAIL;
2096 }
2097 if (! neon_alias_types_same (&htype, &firsttype))
2098 {
2099 first_error (_(type_error));
2100 return FAIL;
2101 }
2102 count += hireg + dregs - getreg;
2103 continue;
2104 }
5f4273c7 2105
5287ad62
JB
2106 /* If we're using Q registers, we can't use [] or [n] syntax. */
2107 if (rtype == REG_TYPE_NQ)
477330fc
RM
2108 {
2109 count += 2;
2110 continue;
2111 }
5f4273c7 2112
dcbf9037 2113 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2114 {
2115 if (lane == -1)
2116 lane = atype.index;
2117 else if (lane != atype.index)
2118 {
2119 first_error (_(type_error));
2120 return FAIL;
2121 }
2122 }
5287ad62 2123 else if (lane == -1)
477330fc 2124 lane = NEON_INTERLEAVE_LANES;
5287ad62 2125 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2126 {
2127 first_error (_(type_error));
2128 return FAIL;
2129 }
5287ad62
JB
2130 count++;
2131 }
2132 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2133
5287ad62
JB
2134 /* No lane set by [x]. We must be interleaving structures. */
2135 if (lane == -1)
2136 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2137
5287ad62
JB
2138 /* Sanity check. */
2139 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2140 || (count > 1 && reg_incr == -1))
2141 {
dcbf9037 2142 first_error (_("error parsing element/structure list"));
5287ad62
JB
2143 return FAIL;
2144 }
2145
2146 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2147 {
dcbf9037 2148 first_error (_("expected }"));
5287ad62
JB
2149 return FAIL;
2150 }
5f4273c7 2151
5287ad62
JB
2152 if (reg_incr == -1)
2153 reg_incr = 1;
2154
dcbf9037
JB
2155 if (eltype)
2156 *eltype = firsttype.eltype;
2157
5287ad62
JB
2158 *pbase = base_reg;
2159 *str = ptr;
5f4273c7 2160
5287ad62
JB
2161 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2162}
2163
c19d1205
ZW
2164/* Parse an explicit relocation suffix on an expression. This is
2165 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2166 arm_reloc_hsh contains no entries, so this function can only
2167 succeed if there is no () after the word. Returns -1 on error,
2168 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2169
c19d1205
ZW
2170static int
2171parse_reloc (char **str)
b99bd4ef 2172{
c19d1205
ZW
2173 struct reloc_entry *r;
2174 char *p, *q;
b99bd4ef 2175
c19d1205
ZW
2176 if (**str != '(')
2177 return BFD_RELOC_UNUSED;
b99bd4ef 2178
c19d1205
ZW
2179 p = *str + 1;
2180 q = p;
2181
2182 while (*q && *q != ')' && *q != ',')
2183 q++;
2184 if (*q != ')')
2185 return -1;
2186
21d799b5
NC
2187 if ((r = (struct reloc_entry *)
2188 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2189 return -1;
2190
2191 *str = q + 1;
2192 return r->reloc;
b99bd4ef
NC
2193}
2194
c19d1205
ZW
2195/* Directives: register aliases. */
2196
dcbf9037 2197static struct reg_entry *
90ec0d68 2198insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2199{
d3ce72d0 2200 struct reg_entry *new_reg;
c19d1205 2201 const char *name;
b99bd4ef 2202
d3ce72d0 2203 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2204 {
d3ce72d0 2205 if (new_reg->builtin)
c19d1205 2206 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2207
c19d1205
ZW
2208 /* Only warn about a redefinition if it's not defined as the
2209 same register. */
d3ce72d0 2210 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2211 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2212
d929913e 2213 return NULL;
c19d1205 2214 }
b99bd4ef 2215
c19d1205 2216 name = xstrdup (str);
325801bd 2217 new_reg = XNEW (struct reg_entry);
b99bd4ef 2218
d3ce72d0
NC
2219 new_reg->name = name;
2220 new_reg->number = number;
2221 new_reg->type = type;
2222 new_reg->builtin = FALSE;
2223 new_reg->neon = NULL;
b99bd4ef 2224
d3ce72d0 2225 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2226 abort ();
5f4273c7 2227
d3ce72d0 2228 return new_reg;
dcbf9037
JB
2229}
2230
2231static void
2232insert_neon_reg_alias (char *str, int number, int type,
477330fc 2233 struct neon_typed_alias *atype)
dcbf9037
JB
2234{
2235 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2236
dcbf9037
JB
2237 if (!reg)
2238 {
2239 first_error (_("attempt to redefine typed alias"));
2240 return;
2241 }
5f4273c7 2242
dcbf9037
JB
2243 if (atype)
2244 {
325801bd 2245 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2246 *reg->neon = *atype;
2247 }
c19d1205 2248}
b99bd4ef 2249
c19d1205 2250/* Look for the .req directive. This is of the form:
b99bd4ef 2251
c19d1205 2252 new_register_name .req existing_register_name
b99bd4ef 2253
c19d1205 2254 If we find one, or if it looks sufficiently like one that we want to
d929913e 2255 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2256
d929913e 2257static bfd_boolean
c19d1205
ZW
2258create_register_alias (char * newname, char *p)
2259{
2260 struct reg_entry *old;
2261 char *oldname, *nbuf;
2262 size_t nlen;
b99bd4ef 2263
c19d1205
ZW
2264 /* The input scrubber ensures that whitespace after the mnemonic is
2265 collapsed to single spaces. */
2266 oldname = p;
2267 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2268 return FALSE;
b99bd4ef 2269
c19d1205
ZW
2270 oldname += 6;
2271 if (*oldname == '\0')
d929913e 2272 return FALSE;
b99bd4ef 2273
21d799b5 2274 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2275 if (!old)
b99bd4ef 2276 {
c19d1205 2277 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2278 return TRUE;
b99bd4ef
NC
2279 }
2280
c19d1205
ZW
2281 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2282 the desired alias name, and p points to its end. If not, then
2283 the desired alias name is in the global original_case_string. */
2284#ifdef TC_CASE_SENSITIVE
2285 nlen = p - newname;
2286#else
2287 newname = original_case_string;
2288 nlen = strlen (newname);
2289#endif
b99bd4ef 2290
29a2809e 2291 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2292
c19d1205
ZW
2293 /* Create aliases under the new name as stated; an all-lowercase
2294 version of the new name; and an all-uppercase version of the new
2295 name. */
d929913e
NC
2296 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2297 {
2298 for (p = nbuf; *p; p++)
2299 *p = TOUPPER (*p);
c19d1205 2300
d929913e
NC
2301 if (strncmp (nbuf, newname, nlen))
2302 {
2303 /* If this attempt to create an additional alias fails, do not bother
2304 trying to create the all-lower case alias. We will fail and issue
2305 a second, duplicate error message. This situation arises when the
2306 programmer does something like:
2307 foo .req r0
2308 Foo .req r1
2309 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2310 the artificial FOO alias because it has already been created by the
d929913e
NC
2311 first .req. */
2312 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2313 {
2314 free (nbuf);
2315 return TRUE;
2316 }
d929913e 2317 }
c19d1205 2318
d929913e
NC
2319 for (p = nbuf; *p; p++)
2320 *p = TOLOWER (*p);
c19d1205 2321
d929913e
NC
2322 if (strncmp (nbuf, newname, nlen))
2323 insert_reg_alias (nbuf, old->number, old->type);
2324 }
c19d1205 2325
e1fa0163 2326 free (nbuf);
d929913e 2327 return TRUE;
b99bd4ef
NC
2328}
2329
dcbf9037
JB
2330/* Create a Neon typed/indexed register alias using directives, e.g.:
2331 X .dn d5.s32[1]
2332 Y .qn 6.s16
2333 Z .dn d7
2334 T .dn Z[0]
2335 These typed registers can be used instead of the types specified after the
2336 Neon mnemonic, so long as all operands given have types. Types can also be
2337 specified directly, e.g.:
5f4273c7 2338 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2339
c921be7d 2340static bfd_boolean
dcbf9037
JB
2341create_neon_reg_alias (char *newname, char *p)
2342{
2343 enum arm_reg_type basetype;
2344 struct reg_entry *basereg;
2345 struct reg_entry mybasereg;
2346 struct neon_type ntype;
2347 struct neon_typed_alias typeinfo;
12d6b0b7 2348 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2349 int namelen;
5f4273c7 2350
dcbf9037
JB
2351 typeinfo.defined = 0;
2352 typeinfo.eltype.type = NT_invtype;
2353 typeinfo.eltype.size = -1;
2354 typeinfo.index = -1;
5f4273c7 2355
dcbf9037 2356 nameend = p;
5f4273c7 2357
dcbf9037
JB
2358 if (strncmp (p, " .dn ", 5) == 0)
2359 basetype = REG_TYPE_VFD;
2360 else if (strncmp (p, " .qn ", 5) == 0)
2361 basetype = REG_TYPE_NQ;
2362 else
c921be7d 2363 return FALSE;
5f4273c7 2364
dcbf9037 2365 p += 5;
5f4273c7 2366
dcbf9037 2367 if (*p == '\0')
c921be7d 2368 return FALSE;
5f4273c7 2369
dcbf9037
JB
2370 basereg = arm_reg_parse_multi (&p);
2371
2372 if (basereg && basereg->type != basetype)
2373 {
2374 as_bad (_("bad type for register"));
c921be7d 2375 return FALSE;
dcbf9037
JB
2376 }
2377
2378 if (basereg == NULL)
2379 {
2380 expressionS exp;
2381 /* Try parsing as an integer. */
2382 my_get_expression (&exp, &p, GE_NO_PREFIX);
2383 if (exp.X_op != O_constant)
477330fc
RM
2384 {
2385 as_bad (_("expression must be constant"));
2386 return FALSE;
2387 }
dcbf9037
JB
2388 basereg = &mybasereg;
2389 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2390 : exp.X_add_number;
dcbf9037
JB
2391 basereg->neon = 0;
2392 }
2393
2394 if (basereg->neon)
2395 typeinfo = *basereg->neon;
2396
2397 if (parse_neon_type (&ntype, &p) == SUCCESS)
2398 {
2399 /* We got a type. */
2400 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2401 {
2402 as_bad (_("can't redefine the type of a register alias"));
2403 return FALSE;
2404 }
5f4273c7 2405
dcbf9037
JB
2406 typeinfo.defined |= NTA_HASTYPE;
2407 if (ntype.elems != 1)
477330fc
RM
2408 {
2409 as_bad (_("you must specify a single type only"));
2410 return FALSE;
2411 }
dcbf9037
JB
2412 typeinfo.eltype = ntype.el[0];
2413 }
5f4273c7 2414
dcbf9037
JB
2415 if (skip_past_char (&p, '[') == SUCCESS)
2416 {
2417 expressionS exp;
2418 /* We got a scalar index. */
5f4273c7 2419
dcbf9037 2420 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2421 {
2422 as_bad (_("can't redefine the index of a scalar alias"));
2423 return FALSE;
2424 }
5f4273c7 2425
dcbf9037 2426 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2427
dcbf9037 2428 if (exp.X_op != O_constant)
477330fc
RM
2429 {
2430 as_bad (_("scalar index must be constant"));
2431 return FALSE;
2432 }
5f4273c7 2433
dcbf9037
JB
2434 typeinfo.defined |= NTA_HASINDEX;
2435 typeinfo.index = exp.X_add_number;
5f4273c7 2436
dcbf9037 2437 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2438 {
2439 as_bad (_("expecting ]"));
2440 return FALSE;
2441 }
dcbf9037
JB
2442 }
2443
15735687
NS
2444 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2445 the desired alias name, and p points to its end. If not, then
2446 the desired alias name is in the global original_case_string. */
2447#ifdef TC_CASE_SENSITIVE
dcbf9037 2448 namelen = nameend - newname;
15735687
NS
2449#else
2450 newname = original_case_string;
2451 namelen = strlen (newname);
2452#endif
2453
29a2809e 2454 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2455
dcbf9037 2456 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2457 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2458
dcbf9037
JB
2459 /* Insert name in all uppercase. */
2460 for (p = namebuf; *p; p++)
2461 *p = TOUPPER (*p);
5f4273c7 2462
dcbf9037
JB
2463 if (strncmp (namebuf, newname, namelen))
2464 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2465 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2466
dcbf9037
JB
2467 /* Insert name in all lowercase. */
2468 for (p = namebuf; *p; p++)
2469 *p = TOLOWER (*p);
5f4273c7 2470
dcbf9037
JB
2471 if (strncmp (namebuf, newname, namelen))
2472 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2473 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2474
e1fa0163 2475 free (namebuf);
c921be7d 2476 return TRUE;
dcbf9037
JB
2477}
2478
c19d1205
ZW
2479/* Should never be called, as .req goes between the alias and the
2480 register name, not at the beginning of the line. */
c921be7d 2481
b99bd4ef 2482static void
c19d1205 2483s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2484{
c19d1205
ZW
2485 as_bad (_("invalid syntax for .req directive"));
2486}
b99bd4ef 2487
dcbf9037
JB
2488static void
2489s_dn (int a ATTRIBUTE_UNUSED)
2490{
2491 as_bad (_("invalid syntax for .dn directive"));
2492}
2493
2494static void
2495s_qn (int a ATTRIBUTE_UNUSED)
2496{
2497 as_bad (_("invalid syntax for .qn directive"));
2498}
2499
c19d1205
ZW
2500/* The .unreq directive deletes an alias which was previously defined
2501 by .req. For example:
b99bd4ef 2502
c19d1205
ZW
2503 my_alias .req r11
2504 .unreq my_alias */
b99bd4ef
NC
2505
2506static void
c19d1205 2507s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2508{
c19d1205
ZW
2509 char * name;
2510 char saved_char;
b99bd4ef 2511
c19d1205
ZW
2512 name = input_line_pointer;
2513
2514 while (*input_line_pointer != 0
2515 && *input_line_pointer != ' '
2516 && *input_line_pointer != '\n')
2517 ++input_line_pointer;
2518
2519 saved_char = *input_line_pointer;
2520 *input_line_pointer = 0;
2521
2522 if (!*name)
2523 as_bad (_("invalid syntax for .unreq directive"));
2524 else
2525 {
21d799b5 2526 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2527 name);
c19d1205
ZW
2528
2529 if (!reg)
2530 as_bad (_("unknown register alias '%s'"), name);
2531 else if (reg->builtin)
a1727c1a 2532 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2533 name);
2534 else
2535 {
d929913e
NC
2536 char * p;
2537 char * nbuf;
2538
db0bc284 2539 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2540 free ((char *) reg->name);
477330fc
RM
2541 if (reg->neon)
2542 free (reg->neon);
c19d1205 2543 free (reg);
d929913e
NC
2544
2545 /* Also locate the all upper case and all lower case versions.
2546 Do not complain if we cannot find one or the other as it
2547 was probably deleted above. */
5f4273c7 2548
d929913e
NC
2549 nbuf = strdup (name);
2550 for (p = nbuf; *p; p++)
2551 *p = TOUPPER (*p);
21d799b5 2552 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2553 if (reg)
2554 {
db0bc284 2555 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2556 free ((char *) reg->name);
2557 if (reg->neon)
2558 free (reg->neon);
2559 free (reg);
2560 }
2561
2562 for (p = nbuf; *p; p++)
2563 *p = TOLOWER (*p);
21d799b5 2564 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2565 if (reg)
2566 {
db0bc284 2567 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2568 free ((char *) reg->name);
2569 if (reg->neon)
2570 free (reg->neon);
2571 free (reg);
2572 }
2573
2574 free (nbuf);
c19d1205
ZW
2575 }
2576 }
b99bd4ef 2577
c19d1205 2578 *input_line_pointer = saved_char;
b99bd4ef
NC
2579 demand_empty_rest_of_line ();
2580}
2581
c19d1205
ZW
2582/* Directives: Instruction set selection. */
2583
2584#ifdef OBJ_ELF
2585/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2586 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2587 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2588 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2589
cd000bff
DJ
2590/* Create a new mapping symbol for the transition to STATE. */
2591
2592static void
2593make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2594{
a737bd4d 2595 symbolS * symbolP;
c19d1205
ZW
2596 const char * symname;
2597 int type;
b99bd4ef 2598
c19d1205 2599 switch (state)
b99bd4ef 2600 {
c19d1205
ZW
2601 case MAP_DATA:
2602 symname = "$d";
2603 type = BSF_NO_FLAGS;
2604 break;
2605 case MAP_ARM:
2606 symname = "$a";
2607 type = BSF_NO_FLAGS;
2608 break;
2609 case MAP_THUMB:
2610 symname = "$t";
2611 type = BSF_NO_FLAGS;
2612 break;
c19d1205
ZW
2613 default:
2614 abort ();
2615 }
2616
cd000bff 2617 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2618 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2619
2620 switch (state)
2621 {
2622 case MAP_ARM:
2623 THUMB_SET_FUNC (symbolP, 0);
2624 ARM_SET_THUMB (symbolP, 0);
2625 ARM_SET_INTERWORK (symbolP, support_interwork);
2626 break;
2627
2628 case MAP_THUMB:
2629 THUMB_SET_FUNC (symbolP, 1);
2630 ARM_SET_THUMB (symbolP, 1);
2631 ARM_SET_INTERWORK (symbolP, support_interwork);
2632 break;
2633
2634 case MAP_DATA:
2635 default:
cd000bff
DJ
2636 break;
2637 }
2638
2639 /* Save the mapping symbols for future reference. Also check that
2640 we do not place two mapping symbols at the same offset within a
2641 frag. We'll handle overlap between frags in
2de7820f
JZ
2642 check_mapping_symbols.
2643
2644 If .fill or other data filling directive generates zero sized data,
2645 the mapping symbol for the following code will have the same value
2646 as the one generated for the data filling directive. In this case,
2647 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2648 if (value == 0)
2649 {
2de7820f
JZ
2650 if (frag->tc_frag_data.first_map != NULL)
2651 {
2652 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2653 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2654 }
cd000bff
DJ
2655 frag->tc_frag_data.first_map = symbolP;
2656 }
2657 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2658 {
2659 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2660 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2661 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2662 }
cd000bff
DJ
2663 frag->tc_frag_data.last_map = symbolP;
2664}
2665
2666/* We must sometimes convert a region marked as code to data during
2667 code alignment, if an odd number of bytes have to be padded. The
2668 code mapping symbol is pushed to an aligned address. */
2669
2670static void
2671insert_data_mapping_symbol (enum mstate state,
2672 valueT value, fragS *frag, offsetT bytes)
2673{
2674 /* If there was already a mapping symbol, remove it. */
2675 if (frag->tc_frag_data.last_map != NULL
2676 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2677 {
2678 symbolS *symp = frag->tc_frag_data.last_map;
2679
2680 if (value == 0)
2681 {
2682 know (frag->tc_frag_data.first_map == symp);
2683 frag->tc_frag_data.first_map = NULL;
2684 }
2685 frag->tc_frag_data.last_map = NULL;
2686 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2687 }
cd000bff
DJ
2688
2689 make_mapping_symbol (MAP_DATA, value, frag);
2690 make_mapping_symbol (state, value + bytes, frag);
2691}
2692
2693static void mapping_state_2 (enum mstate state, int max_chars);
2694
2695/* Set the mapping state to STATE. Only call this when about to
2696 emit some STATE bytes to the file. */
2697
4e9aaefb 2698#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2699void
2700mapping_state (enum mstate state)
2701{
940b5ce0
DJ
2702 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2703
cd000bff
DJ
2704 if (mapstate == state)
2705 /* The mapping symbol has already been emitted.
2706 There is nothing else to do. */
2707 return;
49c62a33
NC
2708
2709 if (state == MAP_ARM || state == MAP_THUMB)
2710 /* PR gas/12931
2711 All ARM instructions require 4-byte alignment.
2712 (Almost) all Thumb instructions require 2-byte alignment.
2713
2714 When emitting instructions into any section, mark the section
2715 appropriately.
2716
2717 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2718 but themselves require 2-byte alignment; this applies to some
33eaf5de 2719 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2720 literal pool generation or an explicit .align >=2, both of
2721 which will cause the section to me marked with sufficient
2722 alignment. Thus, we don't handle those cases here. */
2723 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2724
2725 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2726 /* This case will be evaluated later. */
cd000bff 2727 return;
cd000bff
DJ
2728
2729 mapping_state_2 (state, 0);
cd000bff
DJ
2730}
2731
2732/* Same as mapping_state, but MAX_CHARS bytes have already been
2733 allocated. Put the mapping symbol that far back. */
2734
2735static void
2736mapping_state_2 (enum mstate state, int max_chars)
2737{
940b5ce0
DJ
2738 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2739
2740 if (!SEG_NORMAL (now_seg))
2741 return;
2742
cd000bff
DJ
2743 if (mapstate == state)
2744 /* The mapping symbol has already been emitted.
2745 There is nothing else to do. */
2746 return;
2747
4e9aaefb
SA
2748 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2749 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2750 {
2751 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2752 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2753
2754 if (add_symbol)
2755 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2756 }
2757
cd000bff
DJ
2758 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2759 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2760}
4e9aaefb 2761#undef TRANSITION
c19d1205 2762#else
d3106081
NS
2763#define mapping_state(x) ((void)0)
2764#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2765#endif
2766
2767/* Find the real, Thumb encoded start of a Thumb function. */
2768
4343666d 2769#ifdef OBJ_COFF
c19d1205
ZW
2770static symbolS *
2771find_real_start (symbolS * symbolP)
2772{
2773 char * real_start;
2774 const char * name = S_GET_NAME (symbolP);
2775 symbolS * new_target;
2776
2777 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2778#define STUB_NAME ".real_start_of"
2779
2780 if (name == NULL)
2781 abort ();
2782
37f6032b
ZW
2783 /* The compiler may generate BL instructions to local labels because
2784 it needs to perform a branch to a far away location. These labels
2785 do not have a corresponding ".real_start_of" label. We check
2786 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2787 the ".real_start_of" convention for nonlocal branches. */
2788 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2789 return symbolP;
2790
e1fa0163 2791 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2792 new_target = symbol_find (real_start);
e1fa0163 2793 free (real_start);
c19d1205
ZW
2794
2795 if (new_target == NULL)
2796 {
bd3ba5d1 2797 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2798 new_target = symbolP;
2799 }
2800
c19d1205
ZW
2801 return new_target;
2802}
4343666d 2803#endif
c19d1205
ZW
2804
2805static void
2806opcode_select (int width)
2807{
2808 switch (width)
2809 {
2810 case 16:
2811 if (! thumb_mode)
2812 {
e74cfd16 2813 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2814 as_bad (_("selected processor does not support THUMB opcodes"));
2815
2816 thumb_mode = 1;
2817 /* No need to force the alignment, since we will have been
2818 coming from ARM mode, which is word-aligned. */
2819 record_alignment (now_seg, 1);
2820 }
c19d1205
ZW
2821 break;
2822
2823 case 32:
2824 if (thumb_mode)
2825 {
e74cfd16 2826 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2827 as_bad (_("selected processor does not support ARM opcodes"));
2828
2829 thumb_mode = 0;
2830
2831 if (!need_pass_2)
2832 frag_align (2, 0, 0);
2833
2834 record_alignment (now_seg, 1);
2835 }
c19d1205
ZW
2836 break;
2837
2838 default:
2839 as_bad (_("invalid instruction size selected (%d)"), width);
2840 }
2841}
2842
2843static void
2844s_arm (int ignore ATTRIBUTE_UNUSED)
2845{
2846 opcode_select (32);
2847 demand_empty_rest_of_line ();
2848}
2849
2850static void
2851s_thumb (int ignore ATTRIBUTE_UNUSED)
2852{
2853 opcode_select (16);
2854 demand_empty_rest_of_line ();
2855}
2856
2857static void
2858s_code (int unused ATTRIBUTE_UNUSED)
2859{
2860 int temp;
2861
2862 temp = get_absolute_expression ();
2863 switch (temp)
2864 {
2865 case 16:
2866 case 32:
2867 opcode_select (temp);
2868 break;
2869
2870 default:
2871 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2872 }
2873}
2874
2875static void
2876s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2877{
2878 /* If we are not already in thumb mode go into it, EVEN if
2879 the target processor does not support thumb instructions.
2880 This is used by gcc/config/arm/lib1funcs.asm for example
2881 to compile interworking support functions even if the
2882 target processor should not support interworking. */
2883 if (! thumb_mode)
2884 {
2885 thumb_mode = 2;
2886 record_alignment (now_seg, 1);
2887 }
2888
2889 demand_empty_rest_of_line ();
2890}
2891
2892static void
2893s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2894{
2895 s_thumb (0);
2896
2897 /* The following label is the name/address of the start of a Thumb function.
2898 We need to know this for the interworking support. */
2899 label_is_thumb_function_name = TRUE;
2900}
2901
2902/* Perform a .set directive, but also mark the alias as
2903 being a thumb function. */
2904
2905static void
2906s_thumb_set (int equiv)
2907{
2908 /* XXX the following is a duplicate of the code for s_set() in read.c
2909 We cannot just call that code as we need to get at the symbol that
2910 is created. */
2911 char * name;
2912 char delim;
2913 char * end_name;
2914 symbolS * symbolP;
2915
2916 /* Especial apologies for the random logic:
2917 This just grew, and could be parsed much more simply!
2918 Dean - in haste. */
d02603dc 2919 delim = get_symbol_name (& name);
c19d1205 2920 end_name = input_line_pointer;
d02603dc 2921 (void) restore_line_pointer (delim);
c19d1205
ZW
2922
2923 if (*input_line_pointer != ',')
2924 {
2925 *end_name = 0;
2926 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2927 *end_name = delim;
2928 ignore_rest_of_line ();
2929 return;
2930 }
2931
2932 input_line_pointer++;
2933 *end_name = 0;
2934
2935 if (name[0] == '.' && name[1] == '\0')
2936 {
2937 /* XXX - this should not happen to .thumb_set. */
2938 abort ();
2939 }
2940
2941 if ((symbolP = symbol_find (name)) == NULL
2942 && (symbolP = md_undefined_symbol (name)) == NULL)
2943 {
2944#ifndef NO_LISTING
2945 /* When doing symbol listings, play games with dummy fragments living
2946 outside the normal fragment chain to record the file and line info
c19d1205 2947 for this symbol. */
b99bd4ef
NC
2948 if (listing & LISTING_SYMBOLS)
2949 {
2950 extern struct list_info_struct * listing_tail;
21d799b5 2951 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2952
2953 memset (dummy_frag, 0, sizeof (fragS));
2954 dummy_frag->fr_type = rs_fill;
2955 dummy_frag->line = listing_tail;
2956 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2957 dummy_frag->fr_symbol = symbolP;
2958 }
2959 else
2960#endif
2961 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2962
2963#ifdef OBJ_COFF
2964 /* "set" symbols are local unless otherwise specified. */
2965 SF_SET_LOCAL (symbolP);
2966#endif /* OBJ_COFF */
2967 } /* Make a new symbol. */
2968
2969 symbol_table_insert (symbolP);
2970
2971 * end_name = delim;
2972
2973 if (equiv
2974 && S_IS_DEFINED (symbolP)
2975 && S_GET_SEGMENT (symbolP) != reg_section)
2976 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2977
2978 pseudo_set (symbolP);
2979
2980 demand_empty_rest_of_line ();
2981
c19d1205 2982 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2983
2984 THUMB_SET_FUNC (symbolP, 1);
2985 ARM_SET_THUMB (symbolP, 1);
2986#if defined OBJ_ELF || defined OBJ_COFF
2987 ARM_SET_INTERWORK (symbolP, support_interwork);
2988#endif
2989}
2990
c19d1205 2991/* Directives: Mode selection. */
b99bd4ef 2992
c19d1205
ZW
2993/* .syntax [unified|divided] - choose the new unified syntax
2994 (same for Arm and Thumb encoding, modulo slight differences in what
2995 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2996static void
c19d1205 2997s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2998{
c19d1205
ZW
2999 char *name, delim;
3000
d02603dc 3001 delim = get_symbol_name (& name);
c19d1205
ZW
3002
3003 if (!strcasecmp (name, "unified"))
3004 unified_syntax = TRUE;
3005 else if (!strcasecmp (name, "divided"))
3006 unified_syntax = FALSE;
3007 else
3008 {
3009 as_bad (_("unrecognized syntax mode \"%s\""), name);
3010 return;
3011 }
d02603dc 3012 (void) restore_line_pointer (delim);
b99bd4ef
NC
3013 demand_empty_rest_of_line ();
3014}
3015
c19d1205
ZW
3016/* Directives: sectioning and alignment. */
3017
c19d1205
ZW
3018static void
3019s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3020{
c19d1205
ZW
3021 /* We don't support putting frags in the BSS segment, we fake it by
3022 marking in_bss, then looking at s_skip for clues. */
3023 subseg_set (bss_section, 0);
3024 demand_empty_rest_of_line ();
cd000bff
DJ
3025
3026#ifdef md_elf_section_change_hook
3027 md_elf_section_change_hook ();
3028#endif
c19d1205 3029}
b99bd4ef 3030
c19d1205
ZW
3031static void
3032s_even (int ignore ATTRIBUTE_UNUSED)
3033{
3034 /* Never make frag if expect extra pass. */
3035 if (!need_pass_2)
3036 frag_align (1, 0, 0);
b99bd4ef 3037
c19d1205 3038 record_alignment (now_seg, 1);
b99bd4ef 3039
c19d1205 3040 demand_empty_rest_of_line ();
b99bd4ef
NC
3041}
3042
2e6976a8
DG
3043/* Directives: CodeComposer Studio. */
3044
3045/* .ref (for CodeComposer Studio syntax only). */
3046static void
3047s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3048{
3049 if (codecomposer_syntax)
3050 ignore_rest_of_line ();
3051 else
3052 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3053}
3054
3055/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3056 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3057static void
3058asmfunc_debug (const char * name)
3059{
3060 static const char * last_name = NULL;
3061
3062 if (name != NULL)
3063 {
3064 gas_assert (last_name == NULL);
3065 last_name = name;
3066
3067 if (debug_type == DEBUG_STABS)
3068 stabs_generate_asm_func (name, name);
3069 }
3070 else
3071 {
3072 gas_assert (last_name != NULL);
3073
3074 if (debug_type == DEBUG_STABS)
3075 stabs_generate_asm_endfunc (last_name, last_name);
3076
3077 last_name = NULL;
3078 }
3079}
3080
3081static void
3082s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3083{
3084 if (codecomposer_syntax)
3085 {
3086 switch (asmfunc_state)
3087 {
3088 case OUTSIDE_ASMFUNC:
3089 asmfunc_state = WAITING_ASMFUNC_NAME;
3090 break;
3091
3092 case WAITING_ASMFUNC_NAME:
3093 as_bad (_(".asmfunc repeated."));
3094 break;
3095
3096 case WAITING_ENDASMFUNC:
3097 as_bad (_(".asmfunc without function."));
3098 break;
3099 }
3100 demand_empty_rest_of_line ();
3101 }
3102 else
3103 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3104}
3105
3106static void
3107s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3108{
3109 if (codecomposer_syntax)
3110 {
3111 switch (asmfunc_state)
3112 {
3113 case OUTSIDE_ASMFUNC:
3114 as_bad (_(".endasmfunc without a .asmfunc."));
3115 break;
3116
3117 case WAITING_ASMFUNC_NAME:
3118 as_bad (_(".endasmfunc without function."));
3119 break;
3120
3121 case WAITING_ENDASMFUNC:
3122 asmfunc_state = OUTSIDE_ASMFUNC;
3123 asmfunc_debug (NULL);
3124 break;
3125 }
3126 demand_empty_rest_of_line ();
3127 }
3128 else
3129 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3130}
3131
3132static void
3133s_ccs_def (int name)
3134{
3135 if (codecomposer_syntax)
3136 s_globl (name);
3137 else
3138 as_bad (_(".def pseudo-op only available with -mccs flag."));
3139}
3140
c19d1205 3141/* Directives: Literal pools. */
a737bd4d 3142
c19d1205
ZW
3143static literal_pool *
3144find_literal_pool (void)
a737bd4d 3145{
c19d1205 3146 literal_pool * pool;
a737bd4d 3147
c19d1205 3148 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3149 {
c19d1205
ZW
3150 if (pool->section == now_seg
3151 && pool->sub_section == now_subseg)
3152 break;
a737bd4d
NC
3153 }
3154
c19d1205 3155 return pool;
a737bd4d
NC
3156}
3157
c19d1205
ZW
3158static literal_pool *
3159find_or_make_literal_pool (void)
a737bd4d 3160{
c19d1205
ZW
3161 /* Next literal pool ID number. */
3162 static unsigned int latest_pool_num = 1;
3163 literal_pool * pool;
a737bd4d 3164
c19d1205 3165 pool = find_literal_pool ();
a737bd4d 3166
c19d1205 3167 if (pool == NULL)
a737bd4d 3168 {
c19d1205 3169 /* Create a new pool. */
325801bd 3170 pool = XNEW (literal_pool);
c19d1205
ZW
3171 if (! pool)
3172 return NULL;
a737bd4d 3173
c19d1205
ZW
3174 pool->next_free_entry = 0;
3175 pool->section = now_seg;
3176 pool->sub_section = now_subseg;
3177 pool->next = list_of_pools;
3178 pool->symbol = NULL;
8335d6aa 3179 pool->alignment = 2;
c19d1205
ZW
3180
3181 /* Add it to the list. */
3182 list_of_pools = pool;
a737bd4d 3183 }
a737bd4d 3184
c19d1205
ZW
3185 /* New pools, and emptied pools, will have a NULL symbol. */
3186 if (pool->symbol == NULL)
a737bd4d 3187 {
c19d1205
ZW
3188 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3189 (valueT) 0, &zero_address_frag);
3190 pool->id = latest_pool_num ++;
a737bd4d
NC
3191 }
3192
c19d1205
ZW
3193 /* Done. */
3194 return pool;
a737bd4d
NC
3195}
3196
c19d1205 3197/* Add the literal in the global 'inst'
5f4273c7 3198 structure to the relevant literal pool. */
b99bd4ef
NC
3199
3200static int
8335d6aa 3201add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3202{
8335d6aa
JW
3203#define PADDING_SLOT 0x1
3204#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3205 literal_pool * pool;
8335d6aa
JW
3206 unsigned int entry, pool_size = 0;
3207 bfd_boolean padding_slot_p = FALSE;
e56c722b 3208 unsigned imm1 = 0;
8335d6aa
JW
3209 unsigned imm2 = 0;
3210
3211 if (nbytes == 8)
3212 {
3213 imm1 = inst.operands[1].imm;
3214 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3215 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3216 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3217 if (target_big_endian)
3218 {
3219 imm1 = imm2;
3220 imm2 = inst.operands[1].imm;
3221 }
3222 }
b99bd4ef 3223
c19d1205
ZW
3224 pool = find_or_make_literal_pool ();
3225
3226 /* Check if this literal value is already in the pool. */
3227 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3228 {
8335d6aa
JW
3229 if (nbytes == 4)
3230 {
3231 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3232 && (inst.reloc.exp.X_op == O_constant)
3233 && (pool->literals[entry].X_add_number
3234 == inst.reloc.exp.X_add_number)
3235 && (pool->literals[entry].X_md == nbytes)
3236 && (pool->literals[entry].X_unsigned
3237 == inst.reloc.exp.X_unsigned))
3238 break;
3239
3240 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3241 && (inst.reloc.exp.X_op == O_symbol)
3242 && (pool->literals[entry].X_add_number
3243 == inst.reloc.exp.X_add_number)
3244 && (pool->literals[entry].X_add_symbol
3245 == inst.reloc.exp.X_add_symbol)
3246 && (pool->literals[entry].X_op_symbol
3247 == inst.reloc.exp.X_op_symbol)
3248 && (pool->literals[entry].X_md == nbytes))
3249 break;
3250 }
3251 else if ((nbytes == 8)
3252 && !(pool_size & 0x7)
3253 && ((entry + 1) != pool->next_free_entry)
3254 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3255 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3256 && (pool->literals[entry].X_unsigned
3257 == inst.reloc.exp.X_unsigned)
3258 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3259 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3260 && (pool->literals[entry + 1].X_unsigned
3261 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3262 break;
3263
8335d6aa
JW
3264 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3265 if (padding_slot_p && (nbytes == 4))
c19d1205 3266 break;
8335d6aa
JW
3267
3268 pool_size += 4;
b99bd4ef
NC
3269 }
3270
c19d1205
ZW
3271 /* Do we need to create a new entry? */
3272 if (entry == pool->next_free_entry)
3273 {
3274 if (entry >= MAX_LITERAL_POOL_SIZE)
3275 {
3276 inst.error = _("literal pool overflow");
3277 return FAIL;
3278 }
3279
8335d6aa
JW
3280 if (nbytes == 8)
3281 {
3282 /* For 8-byte entries, we align to an 8-byte boundary,
3283 and split it into two 4-byte entries, because on 32-bit
3284 host, 8-byte constants are treated as big num, thus
3285 saved in "generic_bignum" which will be overwritten
3286 by later assignments.
3287
3288 We also need to make sure there is enough space for
3289 the split.
3290
3291 We also check to make sure the literal operand is a
3292 constant number. */
19f2f6a9
JW
3293 if (!(inst.reloc.exp.X_op == O_constant
3294 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3295 {
3296 inst.error = _("invalid type for literal pool");
3297 return FAIL;
3298 }
3299 else if (pool_size & 0x7)
3300 {
3301 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3302 {
3303 inst.error = _("literal pool overflow");
3304 return FAIL;
3305 }
3306
3307 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3308 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3309 pool->literals[entry].X_add_number = 0;
3310 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3311 pool->next_free_entry += 1;
3312 pool_size += 4;
3313 }
3314 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3315 {
3316 inst.error = _("literal pool overflow");
3317 return FAIL;
3318 }
3319
3320 pool->literals[entry] = inst.reloc.exp;
3321 pool->literals[entry].X_op = O_constant;
3322 pool->literals[entry].X_add_number = imm1;
3323 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3324 pool->literals[entry++].X_md = 4;
3325 pool->literals[entry] = inst.reloc.exp;
3326 pool->literals[entry].X_op = O_constant;
3327 pool->literals[entry].X_add_number = imm2;
3328 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3329 pool->literals[entry].X_md = 4;
3330 pool->alignment = 3;
3331 pool->next_free_entry += 1;
3332 }
3333 else
3334 {
3335 pool->literals[entry] = inst.reloc.exp;
3336 pool->literals[entry].X_md = 4;
3337 }
3338
a8040cf2
NC
3339#ifdef OBJ_ELF
3340 /* PR ld/12974: Record the location of the first source line to reference
3341 this entry in the literal pool. If it turns out during linking that the
3342 symbol does not exist we will be able to give an accurate line number for
3343 the (first use of the) missing reference. */
3344 if (debug_type == DEBUG_DWARF2)
3345 dwarf2_where (pool->locs + entry);
3346#endif
c19d1205
ZW
3347 pool->next_free_entry += 1;
3348 }
8335d6aa
JW
3349 else if (padding_slot_p)
3350 {
3351 pool->literals[entry] = inst.reloc.exp;
3352 pool->literals[entry].X_md = nbytes;
3353 }
b99bd4ef 3354
c19d1205 3355 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3356 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3357 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3358
c19d1205 3359 return SUCCESS;
b99bd4ef
NC
3360}
3361
2e6976a8 3362bfd_boolean
2e57ce7b 3363tc_start_label_without_colon (void)
2e6976a8
DG
3364{
3365 bfd_boolean ret = TRUE;
3366
3367 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3368 {
2e57ce7b 3369 const char *label = input_line_pointer;
2e6976a8
DG
3370
3371 while (!is_end_of_line[(int) label[-1]])
3372 --label;
3373
3374 if (*label == '.')
3375 {
3376 as_bad (_("Invalid label '%s'"), label);
3377 ret = FALSE;
3378 }
3379
3380 asmfunc_debug (label);
3381
3382 asmfunc_state = WAITING_ENDASMFUNC;
3383 }
3384
3385 return ret;
3386}
3387
c19d1205 3388/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3389 a later date assign it a value. That's what these functions do. */
e16bb312 3390
c19d1205
ZW
3391static void
3392symbol_locate (symbolS * symbolP,
3393 const char * name, /* It is copied, the caller can modify. */
3394 segT segment, /* Segment identifier (SEG_<something>). */
3395 valueT valu, /* Symbol value. */
3396 fragS * frag) /* Associated fragment. */
3397{
e57e6ddc 3398 size_t name_length;
c19d1205 3399 char * preserved_copy_of_name;
e16bb312 3400
c19d1205
ZW
3401 name_length = strlen (name) + 1; /* +1 for \0. */
3402 obstack_grow (&notes, name, name_length);
21d799b5 3403 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3404
c19d1205
ZW
3405#ifdef tc_canonicalize_symbol_name
3406 preserved_copy_of_name =
3407 tc_canonicalize_symbol_name (preserved_copy_of_name);
3408#endif
b99bd4ef 3409
c19d1205 3410 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3411
c19d1205
ZW
3412 S_SET_SEGMENT (symbolP, segment);
3413 S_SET_VALUE (symbolP, valu);
3414 symbol_clear_list_pointers (symbolP);
b99bd4ef 3415
c19d1205 3416 symbol_set_frag (symbolP, frag);
b99bd4ef 3417
c19d1205
ZW
3418 /* Link to end of symbol chain. */
3419 {
3420 extern int symbol_table_frozen;
b99bd4ef 3421
c19d1205
ZW
3422 if (symbol_table_frozen)
3423 abort ();
3424 }
b99bd4ef 3425
c19d1205 3426 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3427
c19d1205 3428 obj_symbol_new_hook (symbolP);
b99bd4ef 3429
c19d1205
ZW
3430#ifdef tc_symbol_new_hook
3431 tc_symbol_new_hook (symbolP);
3432#endif
3433
3434#ifdef DEBUG_SYMS
3435 verify_symbol_chain (symbol_rootP, symbol_lastP);
3436#endif /* DEBUG_SYMS */
b99bd4ef
NC
3437}
3438
c19d1205
ZW
3439static void
3440s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3441{
c19d1205
ZW
3442 unsigned int entry;
3443 literal_pool * pool;
3444 char sym_name[20];
b99bd4ef 3445
c19d1205
ZW
3446 pool = find_literal_pool ();
3447 if (pool == NULL
3448 || pool->symbol == NULL
3449 || pool->next_free_entry == 0)
3450 return;
b99bd4ef 3451
c19d1205
ZW
3452 /* Align pool as you have word accesses.
3453 Only make a frag if we have to. */
3454 if (!need_pass_2)
8335d6aa 3455 frag_align (pool->alignment, 0, 0);
b99bd4ef 3456
c19d1205 3457 record_alignment (now_seg, 2);
b99bd4ef 3458
aaca88ef 3459#ifdef OBJ_ELF
47fc6e36
WN
3460 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3461 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3462#endif
c19d1205 3463 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3464
c19d1205
ZW
3465 symbol_locate (pool->symbol, sym_name, now_seg,
3466 (valueT) frag_now_fix (), frag_now);
3467 symbol_table_insert (pool->symbol);
b99bd4ef 3468
c19d1205 3469 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3470
c19d1205
ZW
3471#if defined OBJ_COFF || defined OBJ_ELF
3472 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3473#endif
6c43fab6 3474
c19d1205 3475 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3476 {
3477#ifdef OBJ_ELF
3478 if (debug_type == DEBUG_DWARF2)
3479 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3480#endif
3481 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3482 emit_expr (&(pool->literals[entry]),
3483 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3484 }
b99bd4ef 3485
c19d1205
ZW
3486 /* Mark the pool as empty. */
3487 pool->next_free_entry = 0;
3488 pool->symbol = NULL;
b99bd4ef
NC
3489}
3490
c19d1205
ZW
3491#ifdef OBJ_ELF
3492/* Forward declarations for functions below, in the MD interface
3493 section. */
3494static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3495static valueT create_unwind_entry (int);
3496static void start_unwind_section (const segT, int);
3497static void add_unwind_opcode (valueT, int);
3498static void flush_pending_unwind (void);
b99bd4ef 3499
c19d1205 3500/* Directives: Data. */
b99bd4ef 3501
c19d1205
ZW
3502static void
3503s_arm_elf_cons (int nbytes)
3504{
3505 expressionS exp;
b99bd4ef 3506
c19d1205
ZW
3507#ifdef md_flush_pending_output
3508 md_flush_pending_output ();
3509#endif
b99bd4ef 3510
c19d1205 3511 if (is_it_end_of_statement ())
b99bd4ef 3512 {
c19d1205
ZW
3513 demand_empty_rest_of_line ();
3514 return;
b99bd4ef
NC
3515 }
3516
c19d1205
ZW
3517#ifdef md_cons_align
3518 md_cons_align (nbytes);
3519#endif
b99bd4ef 3520
c19d1205
ZW
3521 mapping_state (MAP_DATA);
3522 do
b99bd4ef 3523 {
c19d1205
ZW
3524 int reloc;
3525 char *base = input_line_pointer;
b99bd4ef 3526
c19d1205 3527 expression (& exp);
b99bd4ef 3528
c19d1205
ZW
3529 if (exp.X_op != O_symbol)
3530 emit_expr (&exp, (unsigned int) nbytes);
3531 else
3532 {
3533 char *before_reloc = input_line_pointer;
3534 reloc = parse_reloc (&input_line_pointer);
3535 if (reloc == -1)
3536 {
3537 as_bad (_("unrecognized relocation suffix"));
3538 ignore_rest_of_line ();
3539 return;
3540 }
3541 else if (reloc == BFD_RELOC_UNUSED)
3542 emit_expr (&exp, (unsigned int) nbytes);
3543 else
3544 {
21d799b5 3545 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3546 bfd_reloc_type_lookup (stdoutput,
3547 (bfd_reloc_code_real_type) reloc);
c19d1205 3548 int size = bfd_get_reloc_size (howto);
b99bd4ef 3549
2fc8bdac
ZW
3550 if (reloc == BFD_RELOC_ARM_PLT32)
3551 {
3552 as_bad (_("(plt) is only valid on branch targets"));
3553 reloc = BFD_RELOC_UNUSED;
3554 size = 0;
3555 }
3556
c19d1205 3557 if (size > nbytes)
992a06ee
AM
3558 as_bad (ngettext ("%s relocations do not fit in %d byte",
3559 "%s relocations do not fit in %d bytes",
3560 nbytes),
c19d1205
ZW
3561 howto->name, nbytes);
3562 else
3563 {
3564 /* We've parsed an expression stopping at O_symbol.
3565 But there may be more expression left now that we
3566 have parsed the relocation marker. Parse it again.
3567 XXX Surely there is a cleaner way to do this. */
3568 char *p = input_line_pointer;
3569 int offset;
325801bd 3570 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3571
c19d1205
ZW
3572 memcpy (save_buf, base, input_line_pointer - base);
3573 memmove (base + (input_line_pointer - before_reloc),
3574 base, before_reloc - base);
3575
3576 input_line_pointer = base + (input_line_pointer-before_reloc);
3577 expression (&exp);
3578 memcpy (base, save_buf, p - base);
3579
3580 offset = nbytes - size;
4b1a927e
AM
3581 p = frag_more (nbytes);
3582 memset (p, 0, nbytes);
c19d1205 3583 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3584 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3585 free (save_buf);
c19d1205
ZW
3586 }
3587 }
3588 }
b99bd4ef 3589 }
c19d1205 3590 while (*input_line_pointer++ == ',');
b99bd4ef 3591
c19d1205
ZW
3592 /* Put terminator back into stream. */
3593 input_line_pointer --;
3594 demand_empty_rest_of_line ();
b99bd4ef
NC
3595}
3596
c921be7d
NC
3597/* Emit an expression containing a 32-bit thumb instruction.
3598 Implementation based on put_thumb32_insn. */
3599
3600static void
3601emit_thumb32_expr (expressionS * exp)
3602{
3603 expressionS exp_high = *exp;
3604
3605 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3606 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3607 exp->X_add_number &= 0xffff;
3608 emit_expr (exp, (unsigned int) THUMB_SIZE);
3609}
3610
3611/* Guess the instruction size based on the opcode. */
3612
3613static int
3614thumb_insn_size (int opcode)
3615{
3616 if ((unsigned int) opcode < 0xe800u)
3617 return 2;
3618 else if ((unsigned int) opcode >= 0xe8000000u)
3619 return 4;
3620 else
3621 return 0;
3622}
3623
3624static bfd_boolean
3625emit_insn (expressionS *exp, int nbytes)
3626{
3627 int size = 0;
3628
3629 if (exp->X_op == O_constant)
3630 {
3631 size = nbytes;
3632
3633 if (size == 0)
3634 size = thumb_insn_size (exp->X_add_number);
3635
3636 if (size != 0)
3637 {
3638 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3639 {
3640 as_bad (_(".inst.n operand too big. "\
3641 "Use .inst.w instead"));
3642 size = 0;
3643 }
3644 else
3645 {
3646 if (now_it.state == AUTOMATIC_IT_BLOCK)
3647 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3648 else
3649 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3650
3651 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3652 emit_thumb32_expr (exp);
3653 else
3654 emit_expr (exp, (unsigned int) size);
3655
3656 it_fsm_post_encode ();
3657 }
3658 }
3659 else
3660 as_bad (_("cannot determine Thumb instruction size. " \
3661 "Use .inst.n/.inst.w instead"));
3662 }
3663 else
3664 as_bad (_("constant expression required"));
3665
3666 return (size != 0);
3667}
3668
3669/* Like s_arm_elf_cons but do not use md_cons_align and
3670 set the mapping state to MAP_ARM/MAP_THUMB. */
3671
3672static void
3673s_arm_elf_inst (int nbytes)
3674{
3675 if (is_it_end_of_statement ())
3676 {
3677 demand_empty_rest_of_line ();
3678 return;
3679 }
3680
3681 /* Calling mapping_state () here will not change ARM/THUMB,
3682 but will ensure not to be in DATA state. */
3683
3684 if (thumb_mode)
3685 mapping_state (MAP_THUMB);
3686 else
3687 {
3688 if (nbytes != 0)
3689 {
3690 as_bad (_("width suffixes are invalid in ARM mode"));
3691 ignore_rest_of_line ();
3692 return;
3693 }
3694
3695 nbytes = 4;
3696
3697 mapping_state (MAP_ARM);
3698 }
3699
3700 do
3701 {
3702 expressionS exp;
3703
3704 expression (& exp);
3705
3706 if (! emit_insn (& exp, nbytes))
3707 {
3708 ignore_rest_of_line ();
3709 return;
3710 }
3711 }
3712 while (*input_line_pointer++ == ',');
3713
3714 /* Put terminator back into stream. */
3715 input_line_pointer --;
3716 demand_empty_rest_of_line ();
3717}
b99bd4ef 3718
c19d1205 3719/* Parse a .rel31 directive. */
b99bd4ef 3720
c19d1205
ZW
3721static void
3722s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3723{
3724 expressionS exp;
3725 char *p;
3726 valueT highbit;
b99bd4ef 3727
c19d1205
ZW
3728 highbit = 0;
3729 if (*input_line_pointer == '1')
3730 highbit = 0x80000000;
3731 else if (*input_line_pointer != '0')
3732 as_bad (_("expected 0 or 1"));
b99bd4ef 3733
c19d1205
ZW
3734 input_line_pointer++;
3735 if (*input_line_pointer != ',')
3736 as_bad (_("missing comma"));
3737 input_line_pointer++;
b99bd4ef 3738
c19d1205
ZW
3739#ifdef md_flush_pending_output
3740 md_flush_pending_output ();
3741#endif
b99bd4ef 3742
c19d1205
ZW
3743#ifdef md_cons_align
3744 md_cons_align (4);
3745#endif
b99bd4ef 3746
c19d1205 3747 mapping_state (MAP_DATA);
b99bd4ef 3748
c19d1205 3749 expression (&exp);
b99bd4ef 3750
c19d1205
ZW
3751 p = frag_more (4);
3752 md_number_to_chars (p, highbit, 4);
3753 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3754 BFD_RELOC_ARM_PREL31);
b99bd4ef 3755
c19d1205 3756 demand_empty_rest_of_line ();
b99bd4ef
NC
3757}
3758
c19d1205 3759/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3760
c19d1205 3761/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3762
c19d1205
ZW
3763static void
3764s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3765{
3766 demand_empty_rest_of_line ();
921e5f0a
PB
3767 if (unwind.proc_start)
3768 {
c921be7d 3769 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3770 return;
3771 }
3772
c19d1205
ZW
3773 /* Mark the start of the function. */
3774 unwind.proc_start = expr_build_dot ();
b99bd4ef 3775
c19d1205
ZW
3776 /* Reset the rest of the unwind info. */
3777 unwind.opcode_count = 0;
3778 unwind.table_entry = NULL;
3779 unwind.personality_routine = NULL;
3780 unwind.personality_index = -1;
3781 unwind.frame_size = 0;
3782 unwind.fp_offset = 0;
fdfde340 3783 unwind.fp_reg = REG_SP;
c19d1205
ZW
3784 unwind.fp_used = 0;
3785 unwind.sp_restored = 0;
3786}
b99bd4ef 3787
b99bd4ef 3788
c19d1205
ZW
3789/* Parse a handlerdata directive. Creates the exception handling table entry
3790 for the function. */
b99bd4ef 3791
c19d1205
ZW
3792static void
3793s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3794{
3795 demand_empty_rest_of_line ();
921e5f0a 3796 if (!unwind.proc_start)
c921be7d 3797 as_bad (MISSING_FNSTART);
921e5f0a 3798
c19d1205 3799 if (unwind.table_entry)
6decc662 3800 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3801
c19d1205
ZW
3802 create_unwind_entry (1);
3803}
a737bd4d 3804
c19d1205 3805/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3806
c19d1205
ZW
3807static void
3808s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3809{
3810 long where;
3811 char *ptr;
3812 valueT val;
940b5ce0 3813 unsigned int marked_pr_dependency;
f02232aa 3814
c19d1205 3815 demand_empty_rest_of_line ();
f02232aa 3816
921e5f0a
PB
3817 if (!unwind.proc_start)
3818 {
c921be7d 3819 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3820 return;
3821 }
3822
c19d1205
ZW
3823 /* Add eh table entry. */
3824 if (unwind.table_entry == NULL)
3825 val = create_unwind_entry (0);
3826 else
3827 val = 0;
f02232aa 3828
c19d1205
ZW
3829 /* Add index table entry. This is two words. */
3830 start_unwind_section (unwind.saved_seg, 1);
3831 frag_align (2, 0, 0);
3832 record_alignment (now_seg, 2);
b99bd4ef 3833
c19d1205 3834 ptr = frag_more (8);
5011093d 3835 memset (ptr, 0, 8);
c19d1205 3836 where = frag_now_fix () - 8;
f02232aa 3837
c19d1205
ZW
3838 /* Self relative offset of the function start. */
3839 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3840 BFD_RELOC_ARM_PREL31);
f02232aa 3841
c19d1205
ZW
3842 /* Indicate dependency on EHABI-defined personality routines to the
3843 linker, if it hasn't been done already. */
940b5ce0
DJ
3844 marked_pr_dependency
3845 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3846 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3847 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3848 {
5f4273c7
NC
3849 static const char *const name[] =
3850 {
3851 "__aeabi_unwind_cpp_pr0",
3852 "__aeabi_unwind_cpp_pr1",
3853 "__aeabi_unwind_cpp_pr2"
3854 };
c19d1205
ZW
3855 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3856 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3857 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3858 |= 1 << unwind.personality_index;
c19d1205 3859 }
f02232aa 3860
c19d1205
ZW
3861 if (val)
3862 /* Inline exception table entry. */
3863 md_number_to_chars (ptr + 4, val, 4);
3864 else
3865 /* Self relative offset of the table entry. */
3866 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3867 BFD_RELOC_ARM_PREL31);
f02232aa 3868
c19d1205
ZW
3869 /* Restore the original section. */
3870 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3871
3872 unwind.proc_start = NULL;
c19d1205 3873}
f02232aa 3874
f02232aa 3875
c19d1205 3876/* Parse an unwind_cantunwind directive. */
b99bd4ef 3877
c19d1205
ZW
3878static void
3879s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3880{
3881 demand_empty_rest_of_line ();
921e5f0a 3882 if (!unwind.proc_start)
c921be7d 3883 as_bad (MISSING_FNSTART);
921e5f0a 3884
c19d1205
ZW
3885 if (unwind.personality_routine || unwind.personality_index != -1)
3886 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3887
c19d1205
ZW
3888 unwind.personality_index = -2;
3889}
b99bd4ef 3890
b99bd4ef 3891
c19d1205 3892/* Parse a personalityindex directive. */
b99bd4ef 3893
c19d1205
ZW
3894static void
3895s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3896{
3897 expressionS exp;
b99bd4ef 3898
921e5f0a 3899 if (!unwind.proc_start)
c921be7d 3900 as_bad (MISSING_FNSTART);
921e5f0a 3901
c19d1205
ZW
3902 if (unwind.personality_routine || unwind.personality_index != -1)
3903 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3904
c19d1205 3905 expression (&exp);
b99bd4ef 3906
c19d1205
ZW
3907 if (exp.X_op != O_constant
3908 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3909 {
c19d1205
ZW
3910 as_bad (_("bad personality routine number"));
3911 ignore_rest_of_line ();
3912 return;
b99bd4ef
NC
3913 }
3914
c19d1205 3915 unwind.personality_index = exp.X_add_number;
b99bd4ef 3916
c19d1205
ZW
3917 demand_empty_rest_of_line ();
3918}
e16bb312 3919
e16bb312 3920
c19d1205 3921/* Parse a personality directive. */
e16bb312 3922
c19d1205
ZW
3923static void
3924s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3925{
3926 char *name, *p, c;
a737bd4d 3927
921e5f0a 3928 if (!unwind.proc_start)
c921be7d 3929 as_bad (MISSING_FNSTART);
921e5f0a 3930
c19d1205
ZW
3931 if (unwind.personality_routine || unwind.personality_index != -1)
3932 as_bad (_("duplicate .personality directive"));
a737bd4d 3933
d02603dc 3934 c = get_symbol_name (& name);
c19d1205 3935 p = input_line_pointer;
d02603dc
NC
3936 if (c == '"')
3937 ++ input_line_pointer;
c19d1205
ZW
3938 unwind.personality_routine = symbol_find_or_make (name);
3939 *p = c;
3940 demand_empty_rest_of_line ();
3941}
e16bb312 3942
e16bb312 3943
c19d1205 3944/* Parse a directive saving core registers. */
e16bb312 3945
c19d1205
ZW
3946static void
3947s_arm_unwind_save_core (void)
e16bb312 3948{
c19d1205
ZW
3949 valueT op;
3950 long range;
3951 int n;
e16bb312 3952
c19d1205
ZW
3953 range = parse_reg_list (&input_line_pointer);
3954 if (range == FAIL)
e16bb312 3955 {
c19d1205
ZW
3956 as_bad (_("expected register list"));
3957 ignore_rest_of_line ();
3958 return;
3959 }
e16bb312 3960
c19d1205 3961 demand_empty_rest_of_line ();
e16bb312 3962
c19d1205
ZW
3963 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3964 into .unwind_save {..., sp...}. We aren't bothered about the value of
3965 ip because it is clobbered by calls. */
3966 if (unwind.sp_restored && unwind.fp_reg == 12
3967 && (range & 0x3000) == 0x1000)
3968 {
3969 unwind.opcode_count--;
3970 unwind.sp_restored = 0;
3971 range = (range | 0x2000) & ~0x1000;
3972 unwind.pending_offset = 0;
3973 }
e16bb312 3974
01ae4198
DJ
3975 /* Pop r4-r15. */
3976 if (range & 0xfff0)
c19d1205 3977 {
01ae4198
DJ
3978 /* See if we can use the short opcodes. These pop a block of up to 8
3979 registers starting with r4, plus maybe r14. */
3980 for (n = 0; n < 8; n++)
3981 {
3982 /* Break at the first non-saved register. */
3983 if ((range & (1 << (n + 4))) == 0)
3984 break;
3985 }
3986 /* See if there are any other bits set. */
3987 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3988 {
3989 /* Use the long form. */
3990 op = 0x8000 | ((range >> 4) & 0xfff);
3991 add_unwind_opcode (op, 2);
3992 }
0dd132b6 3993 else
01ae4198
DJ
3994 {
3995 /* Use the short form. */
3996 if (range & 0x4000)
3997 op = 0xa8; /* Pop r14. */
3998 else
3999 op = 0xa0; /* Do not pop r14. */
4000 op |= (n - 1);
4001 add_unwind_opcode (op, 1);
4002 }
c19d1205 4003 }
0dd132b6 4004
c19d1205
ZW
4005 /* Pop r0-r3. */
4006 if (range & 0xf)
4007 {
4008 op = 0xb100 | (range & 0xf);
4009 add_unwind_opcode (op, 2);
0dd132b6
NC
4010 }
4011
c19d1205
ZW
4012 /* Record the number of bytes pushed. */
4013 for (n = 0; n < 16; n++)
4014 {
4015 if (range & (1 << n))
4016 unwind.frame_size += 4;
4017 }
0dd132b6
NC
4018}
4019
c19d1205
ZW
4020
4021/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4022
4023static void
c19d1205 4024s_arm_unwind_save_fpa (int reg)
b99bd4ef 4025{
c19d1205
ZW
4026 expressionS exp;
4027 int num_regs;
4028 valueT op;
b99bd4ef 4029
c19d1205
ZW
4030 /* Get Number of registers to transfer. */
4031 if (skip_past_comma (&input_line_pointer) != FAIL)
4032 expression (&exp);
4033 else
4034 exp.X_op = O_illegal;
b99bd4ef 4035
c19d1205 4036 if (exp.X_op != O_constant)
b99bd4ef 4037 {
c19d1205
ZW
4038 as_bad (_("expected , <constant>"));
4039 ignore_rest_of_line ();
b99bd4ef
NC
4040 return;
4041 }
4042
c19d1205
ZW
4043 num_regs = exp.X_add_number;
4044
4045 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4046 {
c19d1205
ZW
4047 as_bad (_("number of registers must be in the range [1:4]"));
4048 ignore_rest_of_line ();
b99bd4ef
NC
4049 return;
4050 }
4051
c19d1205 4052 demand_empty_rest_of_line ();
b99bd4ef 4053
c19d1205
ZW
4054 if (reg == 4)
4055 {
4056 /* Short form. */
4057 op = 0xb4 | (num_regs - 1);
4058 add_unwind_opcode (op, 1);
4059 }
b99bd4ef
NC
4060 else
4061 {
c19d1205
ZW
4062 /* Long form. */
4063 op = 0xc800 | (reg << 4) | (num_regs - 1);
4064 add_unwind_opcode (op, 2);
b99bd4ef 4065 }
c19d1205 4066 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4067}
4068
c19d1205 4069
fa073d69
MS
4070/* Parse a directive saving VFP registers for ARMv6 and above. */
4071
4072static void
4073s_arm_unwind_save_vfp_armv6 (void)
4074{
4075 int count;
4076 unsigned int start;
4077 valueT op;
4078 int num_vfpv3_regs = 0;
4079 int num_regs_below_16;
4080
4081 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4082 if (count == FAIL)
4083 {
4084 as_bad (_("expected register list"));
4085 ignore_rest_of_line ();
4086 return;
4087 }
4088
4089 demand_empty_rest_of_line ();
4090
4091 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4092 than FSTMX/FLDMX-style ones). */
4093
4094 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4095 if (start >= 16)
4096 num_vfpv3_regs = count;
4097 else if (start + count > 16)
4098 num_vfpv3_regs = start + count - 16;
4099
4100 if (num_vfpv3_regs > 0)
4101 {
4102 int start_offset = start > 16 ? start - 16 : 0;
4103 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4104 add_unwind_opcode (op, 2);
4105 }
4106
4107 /* Generate opcode for registers numbered in the range 0 .. 15. */
4108 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4109 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4110 if (num_regs_below_16 > 0)
4111 {
4112 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4113 add_unwind_opcode (op, 2);
4114 }
4115
4116 unwind.frame_size += count * 8;
4117}
4118
4119
4120/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4121
4122static void
c19d1205 4123s_arm_unwind_save_vfp (void)
b99bd4ef 4124{
c19d1205 4125 int count;
ca3f61f7 4126 unsigned int reg;
c19d1205 4127 valueT op;
b99bd4ef 4128
5287ad62 4129 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4130 if (count == FAIL)
b99bd4ef 4131 {
c19d1205
ZW
4132 as_bad (_("expected register list"));
4133 ignore_rest_of_line ();
b99bd4ef
NC
4134 return;
4135 }
4136
c19d1205 4137 demand_empty_rest_of_line ();
b99bd4ef 4138
c19d1205 4139 if (reg == 8)
b99bd4ef 4140 {
c19d1205
ZW
4141 /* Short form. */
4142 op = 0xb8 | (count - 1);
4143 add_unwind_opcode (op, 1);
b99bd4ef 4144 }
c19d1205 4145 else
b99bd4ef 4146 {
c19d1205
ZW
4147 /* Long form. */
4148 op = 0xb300 | (reg << 4) | (count - 1);
4149 add_unwind_opcode (op, 2);
b99bd4ef 4150 }
c19d1205
ZW
4151 unwind.frame_size += count * 8 + 4;
4152}
b99bd4ef 4153
b99bd4ef 4154
c19d1205
ZW
4155/* Parse a directive saving iWMMXt data registers. */
4156
4157static void
4158s_arm_unwind_save_mmxwr (void)
4159{
4160 int reg;
4161 int hi_reg;
4162 int i;
4163 unsigned mask = 0;
4164 valueT op;
b99bd4ef 4165
c19d1205
ZW
4166 if (*input_line_pointer == '{')
4167 input_line_pointer++;
b99bd4ef 4168
c19d1205 4169 do
b99bd4ef 4170 {
dcbf9037 4171 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4172
c19d1205 4173 if (reg == FAIL)
b99bd4ef 4174 {
9b7132d3 4175 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4176 goto error;
b99bd4ef
NC
4177 }
4178
c19d1205
ZW
4179 if (mask >> reg)
4180 as_tsktsk (_("register list not in ascending order"));
4181 mask |= 1 << reg;
b99bd4ef 4182
c19d1205
ZW
4183 if (*input_line_pointer == '-')
4184 {
4185 input_line_pointer++;
dcbf9037 4186 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4187 if (hi_reg == FAIL)
4188 {
9b7132d3 4189 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4190 goto error;
4191 }
4192 else if (reg >= hi_reg)
4193 {
4194 as_bad (_("bad register range"));
4195 goto error;
4196 }
4197 for (; reg < hi_reg; reg++)
4198 mask |= 1 << reg;
4199 }
4200 }
4201 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4202
d996d970 4203 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4204
c19d1205 4205 demand_empty_rest_of_line ();
b99bd4ef 4206
708587a4 4207 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4208 the list. */
4209 flush_pending_unwind ();
b99bd4ef 4210
c19d1205 4211 for (i = 0; i < 16; i++)
b99bd4ef 4212 {
c19d1205
ZW
4213 if (mask & (1 << i))
4214 unwind.frame_size += 8;
b99bd4ef
NC
4215 }
4216
c19d1205
ZW
4217 /* Attempt to combine with a previous opcode. We do this because gcc
4218 likes to output separate unwind directives for a single block of
4219 registers. */
4220 if (unwind.opcode_count > 0)
b99bd4ef 4221 {
c19d1205
ZW
4222 i = unwind.opcodes[unwind.opcode_count - 1];
4223 if ((i & 0xf8) == 0xc0)
4224 {
4225 i &= 7;
4226 /* Only merge if the blocks are contiguous. */
4227 if (i < 6)
4228 {
4229 if ((mask & 0xfe00) == (1 << 9))
4230 {
4231 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4232 unwind.opcode_count--;
4233 }
4234 }
4235 else if (i == 6 && unwind.opcode_count >= 2)
4236 {
4237 i = unwind.opcodes[unwind.opcode_count - 2];
4238 reg = i >> 4;
4239 i &= 0xf;
b99bd4ef 4240
c19d1205
ZW
4241 op = 0xffff << (reg - 1);
4242 if (reg > 0
87a1fd79 4243 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4244 {
4245 op = (1 << (reg + i + 1)) - 1;
4246 op &= ~((1 << reg) - 1);
4247 mask |= op;
4248 unwind.opcode_count -= 2;
4249 }
4250 }
4251 }
b99bd4ef
NC
4252 }
4253
c19d1205
ZW
4254 hi_reg = 15;
4255 /* We want to generate opcodes in the order the registers have been
4256 saved, ie. descending order. */
4257 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4258 {
c19d1205
ZW
4259 /* Save registers in blocks. */
4260 if (reg < 0
4261 || !(mask & (1 << reg)))
4262 {
4263 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4264 preceding block. */
c19d1205
ZW
4265 if (reg != hi_reg)
4266 {
4267 if (reg == 9)
4268 {
4269 /* Short form. */
4270 op = 0xc0 | (hi_reg - 10);
4271 add_unwind_opcode (op, 1);
4272 }
4273 else
4274 {
4275 /* Long form. */
4276 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4277 add_unwind_opcode (op, 2);
4278 }
4279 }
4280 hi_reg = reg - 1;
4281 }
b99bd4ef
NC
4282 }
4283
c19d1205
ZW
4284 return;
4285error:
4286 ignore_rest_of_line ();
b99bd4ef
NC
4287}
4288
4289static void
c19d1205 4290s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4291{
c19d1205
ZW
4292 int reg;
4293 int hi_reg;
4294 unsigned mask = 0;
4295 valueT op;
b99bd4ef 4296
c19d1205
ZW
4297 if (*input_line_pointer == '{')
4298 input_line_pointer++;
b99bd4ef 4299
477330fc
RM
4300 skip_whitespace (input_line_pointer);
4301
c19d1205 4302 do
b99bd4ef 4303 {
dcbf9037 4304 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4305
c19d1205
ZW
4306 if (reg == FAIL)
4307 {
9b7132d3 4308 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4309 goto error;
4310 }
b99bd4ef 4311
c19d1205
ZW
4312 reg -= 8;
4313 if (mask >> reg)
4314 as_tsktsk (_("register list not in ascending order"));
4315 mask |= 1 << reg;
b99bd4ef 4316
c19d1205
ZW
4317 if (*input_line_pointer == '-')
4318 {
4319 input_line_pointer++;
dcbf9037 4320 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4321 if (hi_reg == FAIL)
4322 {
9b7132d3 4323 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4324 goto error;
4325 }
4326 else if (reg >= hi_reg)
4327 {
4328 as_bad (_("bad register range"));
4329 goto error;
4330 }
4331 for (; reg < hi_reg; reg++)
4332 mask |= 1 << reg;
4333 }
b99bd4ef 4334 }
c19d1205 4335 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4336
d996d970 4337 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4338
c19d1205
ZW
4339 demand_empty_rest_of_line ();
4340
708587a4 4341 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4342 the list. */
4343 flush_pending_unwind ();
b99bd4ef 4344
c19d1205 4345 for (reg = 0; reg < 16; reg++)
b99bd4ef 4346 {
c19d1205
ZW
4347 if (mask & (1 << reg))
4348 unwind.frame_size += 4;
b99bd4ef 4349 }
c19d1205
ZW
4350 op = 0xc700 | mask;
4351 add_unwind_opcode (op, 2);
4352 return;
4353error:
4354 ignore_rest_of_line ();
b99bd4ef
NC
4355}
4356
c19d1205 4357
fa073d69
MS
4358/* Parse an unwind_save directive.
4359 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4360
b99bd4ef 4361static void
fa073d69 4362s_arm_unwind_save (int arch_v6)
b99bd4ef 4363{
c19d1205
ZW
4364 char *peek;
4365 struct reg_entry *reg;
4366 bfd_boolean had_brace = FALSE;
b99bd4ef 4367
921e5f0a 4368 if (!unwind.proc_start)
c921be7d 4369 as_bad (MISSING_FNSTART);
921e5f0a 4370
c19d1205
ZW
4371 /* Figure out what sort of save we have. */
4372 peek = input_line_pointer;
b99bd4ef 4373
c19d1205 4374 if (*peek == '{')
b99bd4ef 4375 {
c19d1205
ZW
4376 had_brace = TRUE;
4377 peek++;
b99bd4ef
NC
4378 }
4379
c19d1205 4380 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4381
c19d1205 4382 if (!reg)
b99bd4ef 4383 {
c19d1205
ZW
4384 as_bad (_("register expected"));
4385 ignore_rest_of_line ();
b99bd4ef
NC
4386 return;
4387 }
4388
c19d1205 4389 switch (reg->type)
b99bd4ef 4390 {
c19d1205
ZW
4391 case REG_TYPE_FN:
4392 if (had_brace)
4393 {
4394 as_bad (_("FPA .unwind_save does not take a register list"));
4395 ignore_rest_of_line ();
4396 return;
4397 }
93ac2687 4398 input_line_pointer = peek;
c19d1205 4399 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4400 return;
c19d1205 4401
1f5afe1c
NC
4402 case REG_TYPE_RN:
4403 s_arm_unwind_save_core ();
4404 return;
4405
fa073d69
MS
4406 case REG_TYPE_VFD:
4407 if (arch_v6)
477330fc 4408 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4409 else
477330fc 4410 s_arm_unwind_save_vfp ();
fa073d69 4411 return;
1f5afe1c
NC
4412
4413 case REG_TYPE_MMXWR:
4414 s_arm_unwind_save_mmxwr ();
4415 return;
4416
4417 case REG_TYPE_MMXWCG:
4418 s_arm_unwind_save_mmxwcg ();
4419 return;
c19d1205
ZW
4420
4421 default:
4422 as_bad (_(".unwind_save does not support this kind of register"));
4423 ignore_rest_of_line ();
b99bd4ef 4424 }
c19d1205 4425}
b99bd4ef 4426
b99bd4ef 4427
c19d1205
ZW
4428/* Parse an unwind_movsp directive. */
4429
4430static void
4431s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4432{
4433 int reg;
4434 valueT op;
4fa3602b 4435 int offset;
c19d1205 4436
921e5f0a 4437 if (!unwind.proc_start)
c921be7d 4438 as_bad (MISSING_FNSTART);
921e5f0a 4439
dcbf9037 4440 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4441 if (reg == FAIL)
b99bd4ef 4442 {
9b7132d3 4443 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4444 ignore_rest_of_line ();
b99bd4ef
NC
4445 return;
4446 }
4fa3602b
PB
4447
4448 /* Optional constant. */
4449 if (skip_past_comma (&input_line_pointer) != FAIL)
4450 {
4451 if (immediate_for_directive (&offset) == FAIL)
4452 return;
4453 }
4454 else
4455 offset = 0;
4456
c19d1205 4457 demand_empty_rest_of_line ();
b99bd4ef 4458
c19d1205 4459 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4460 {
c19d1205 4461 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4462 return;
4463 }
4464
c19d1205
ZW
4465 if (unwind.fp_reg != REG_SP)
4466 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4467
c19d1205
ZW
4468 /* Generate opcode to restore the value. */
4469 op = 0x90 | reg;
4470 add_unwind_opcode (op, 1);
4471
4472 /* Record the information for later. */
4473 unwind.fp_reg = reg;
4fa3602b 4474 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4475 unwind.sp_restored = 1;
b05fe5cf
ZW
4476}
4477
c19d1205
ZW
4478/* Parse an unwind_pad directive. */
4479
b05fe5cf 4480static void
c19d1205 4481s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4482{
c19d1205 4483 int offset;
b05fe5cf 4484
921e5f0a 4485 if (!unwind.proc_start)
c921be7d 4486 as_bad (MISSING_FNSTART);
921e5f0a 4487
c19d1205
ZW
4488 if (immediate_for_directive (&offset) == FAIL)
4489 return;
b99bd4ef 4490
c19d1205
ZW
4491 if (offset & 3)
4492 {
4493 as_bad (_("stack increment must be multiple of 4"));
4494 ignore_rest_of_line ();
4495 return;
4496 }
b99bd4ef 4497
c19d1205
ZW
4498 /* Don't generate any opcodes, just record the details for later. */
4499 unwind.frame_size += offset;
4500 unwind.pending_offset += offset;
4501
4502 demand_empty_rest_of_line ();
4503}
4504
4505/* Parse an unwind_setfp directive. */
4506
4507static void
4508s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4509{
c19d1205
ZW
4510 int sp_reg;
4511 int fp_reg;
4512 int offset;
4513
921e5f0a 4514 if (!unwind.proc_start)
c921be7d 4515 as_bad (MISSING_FNSTART);
921e5f0a 4516
dcbf9037 4517 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4518 if (skip_past_comma (&input_line_pointer) == FAIL)
4519 sp_reg = FAIL;
4520 else
dcbf9037 4521 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4522
c19d1205
ZW
4523 if (fp_reg == FAIL || sp_reg == FAIL)
4524 {
4525 as_bad (_("expected <reg>, <reg>"));
4526 ignore_rest_of_line ();
4527 return;
4528 }
b99bd4ef 4529
c19d1205
ZW
4530 /* Optional constant. */
4531 if (skip_past_comma (&input_line_pointer) != FAIL)
4532 {
4533 if (immediate_for_directive (&offset) == FAIL)
4534 return;
4535 }
4536 else
4537 offset = 0;
a737bd4d 4538
c19d1205 4539 demand_empty_rest_of_line ();
a737bd4d 4540
fdfde340 4541 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4542 {
c19d1205
ZW
4543 as_bad (_("register must be either sp or set by a previous"
4544 "unwind_movsp directive"));
4545 return;
a737bd4d
NC
4546 }
4547
c19d1205
ZW
4548 /* Don't generate any opcodes, just record the information for later. */
4549 unwind.fp_reg = fp_reg;
4550 unwind.fp_used = 1;
fdfde340 4551 if (sp_reg == REG_SP)
c19d1205
ZW
4552 unwind.fp_offset = unwind.frame_size - offset;
4553 else
4554 unwind.fp_offset -= offset;
a737bd4d
NC
4555}
4556
c19d1205
ZW
4557/* Parse an unwind_raw directive. */
4558
4559static void
4560s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4561{
c19d1205 4562 expressionS exp;
708587a4 4563 /* This is an arbitrary limit. */
c19d1205
ZW
4564 unsigned char op[16];
4565 int count;
a737bd4d 4566
921e5f0a 4567 if (!unwind.proc_start)
c921be7d 4568 as_bad (MISSING_FNSTART);
921e5f0a 4569
c19d1205
ZW
4570 expression (&exp);
4571 if (exp.X_op == O_constant
4572 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4573 {
c19d1205
ZW
4574 unwind.frame_size += exp.X_add_number;
4575 expression (&exp);
4576 }
4577 else
4578 exp.X_op = O_illegal;
a737bd4d 4579
c19d1205
ZW
4580 if (exp.X_op != O_constant)
4581 {
4582 as_bad (_("expected <offset>, <opcode>"));
4583 ignore_rest_of_line ();
4584 return;
4585 }
a737bd4d 4586
c19d1205 4587 count = 0;
a737bd4d 4588
c19d1205
ZW
4589 /* Parse the opcode. */
4590 for (;;)
4591 {
4592 if (count >= 16)
4593 {
4594 as_bad (_("unwind opcode too long"));
4595 ignore_rest_of_line ();
a737bd4d 4596 }
c19d1205 4597 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4598 {
c19d1205
ZW
4599 as_bad (_("invalid unwind opcode"));
4600 ignore_rest_of_line ();
4601 return;
a737bd4d 4602 }
c19d1205 4603 op[count++] = exp.X_add_number;
a737bd4d 4604
c19d1205
ZW
4605 /* Parse the next byte. */
4606 if (skip_past_comma (&input_line_pointer) == FAIL)
4607 break;
a737bd4d 4608
c19d1205
ZW
4609 expression (&exp);
4610 }
b99bd4ef 4611
c19d1205
ZW
4612 /* Add the opcode bytes in reverse order. */
4613 while (count--)
4614 add_unwind_opcode (op[count], 1);
b99bd4ef 4615
c19d1205 4616 demand_empty_rest_of_line ();
b99bd4ef 4617}
ee065d83
PB
4618
4619
4620/* Parse a .eabi_attribute directive. */
4621
4622static void
4623s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4624{
0420f52b 4625 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4626
4627 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4628 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4629}
4630
0855e32b
NS
4631/* Emit a tls fix for the symbol. */
4632
4633static void
4634s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4635{
4636 char *p;
4637 expressionS exp;
4638#ifdef md_flush_pending_output
4639 md_flush_pending_output ();
4640#endif
4641
4642#ifdef md_cons_align
4643 md_cons_align (4);
4644#endif
4645
4646 /* Since we're just labelling the code, there's no need to define a
4647 mapping symbol. */
4648 expression (&exp);
4649 p = obstack_next_free (&frchain_now->frch_obstack);
4650 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4651 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4652 : BFD_RELOC_ARM_TLS_DESCSEQ);
4653}
cdf9ccec 4654#endif /* OBJ_ELF */
0855e32b 4655
ee065d83 4656static void s_arm_arch (int);
7a1d4c38 4657static void s_arm_object_arch (int);
ee065d83
PB
4658static void s_arm_cpu (int);
4659static void s_arm_fpu (int);
69133863 4660static void s_arm_arch_extension (int);
b99bd4ef 4661
f0927246
NC
4662#ifdef TE_PE
4663
4664static void
5f4273c7 4665pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4666{
4667 expressionS exp;
4668
4669 do
4670 {
4671 expression (&exp);
4672 if (exp.X_op == O_symbol)
4673 exp.X_op = O_secrel;
4674
4675 emit_expr (&exp, 4);
4676 }
4677 while (*input_line_pointer++ == ',');
4678
4679 input_line_pointer--;
4680 demand_empty_rest_of_line ();
4681}
4682#endif /* TE_PE */
4683
c19d1205
ZW
4684/* This table describes all the machine specific pseudo-ops the assembler
4685 has to support. The fields are:
4686 pseudo-op name without dot
4687 function to call to execute this pseudo-op
4688 Integer arg to pass to the function. */
b99bd4ef 4689
c19d1205 4690const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4691{
c19d1205
ZW
4692 /* Never called because '.req' does not start a line. */
4693 { "req", s_req, 0 },
dcbf9037
JB
4694 /* Following two are likewise never called. */
4695 { "dn", s_dn, 0 },
4696 { "qn", s_qn, 0 },
c19d1205
ZW
4697 { "unreq", s_unreq, 0 },
4698 { "bss", s_bss, 0 },
db2ed2e0 4699 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4700 { "arm", s_arm, 0 },
4701 { "thumb", s_thumb, 0 },
4702 { "code", s_code, 0 },
4703 { "force_thumb", s_force_thumb, 0 },
4704 { "thumb_func", s_thumb_func, 0 },
4705 { "thumb_set", s_thumb_set, 0 },
4706 { "even", s_even, 0 },
4707 { "ltorg", s_ltorg, 0 },
4708 { "pool", s_ltorg, 0 },
4709 { "syntax", s_syntax, 0 },
8463be01
PB
4710 { "cpu", s_arm_cpu, 0 },
4711 { "arch", s_arm_arch, 0 },
7a1d4c38 4712 { "object_arch", s_arm_object_arch, 0 },
8463be01 4713 { "fpu", s_arm_fpu, 0 },
69133863 4714 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4715#ifdef OBJ_ELF
c921be7d
NC
4716 { "word", s_arm_elf_cons, 4 },
4717 { "long", s_arm_elf_cons, 4 },
4718 { "inst.n", s_arm_elf_inst, 2 },
4719 { "inst.w", s_arm_elf_inst, 4 },
4720 { "inst", s_arm_elf_inst, 0 },
4721 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4722 { "fnstart", s_arm_unwind_fnstart, 0 },
4723 { "fnend", s_arm_unwind_fnend, 0 },
4724 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4725 { "personality", s_arm_unwind_personality, 0 },
4726 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4727 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4728 { "save", s_arm_unwind_save, 0 },
fa073d69 4729 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4730 { "movsp", s_arm_unwind_movsp, 0 },
4731 { "pad", s_arm_unwind_pad, 0 },
4732 { "setfp", s_arm_unwind_setfp, 0 },
4733 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4734 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4735 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4736#else
4737 { "word", cons, 4},
f0927246
NC
4738
4739 /* These are used for dwarf. */
4740 {"2byte", cons, 2},
4741 {"4byte", cons, 4},
4742 {"8byte", cons, 8},
4743 /* These are used for dwarf2. */
4744 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4745 { "loc", dwarf2_directive_loc, 0 },
4746 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4747#endif
4748 { "extend", float_cons, 'x' },
4749 { "ldouble", float_cons, 'x' },
4750 { "packed", float_cons, 'p' },
f0927246
NC
4751#ifdef TE_PE
4752 {"secrel32", pe_directive_secrel, 0},
4753#endif
2e6976a8
DG
4754
4755 /* These are for compatibility with CodeComposer Studio. */
4756 {"ref", s_ccs_ref, 0},
4757 {"def", s_ccs_def, 0},
4758 {"asmfunc", s_ccs_asmfunc, 0},
4759 {"endasmfunc", s_ccs_endasmfunc, 0},
4760
c19d1205
ZW
4761 { 0, 0, 0 }
4762};
4763\f
4764/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4765
c19d1205
ZW
4766/* Generic immediate-value read function for use in insn parsing.
4767 STR points to the beginning of the immediate (the leading #);
4768 VAL receives the value; if the value is outside [MIN, MAX]
4769 issue an error. PREFIX_OPT is true if the immediate prefix is
4770 optional. */
b99bd4ef 4771
c19d1205
ZW
4772static int
4773parse_immediate (char **str, int *val, int min, int max,
4774 bfd_boolean prefix_opt)
4775{
4776 expressionS exp;
0198d5e6 4777
c19d1205
ZW
4778 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4779 if (exp.X_op != O_constant)
b99bd4ef 4780 {
c19d1205
ZW
4781 inst.error = _("constant expression required");
4782 return FAIL;
4783 }
b99bd4ef 4784
c19d1205
ZW
4785 if (exp.X_add_number < min || exp.X_add_number > max)
4786 {
4787 inst.error = _("immediate value out of range");
4788 return FAIL;
4789 }
b99bd4ef 4790
c19d1205
ZW
4791 *val = exp.X_add_number;
4792 return SUCCESS;
4793}
b99bd4ef 4794
5287ad62 4795/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4796 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4797 instructions. Puts the result directly in inst.operands[i]. */
4798
4799static int
8335d6aa
JW
4800parse_big_immediate (char **str, int i, expressionS *in_exp,
4801 bfd_boolean allow_symbol_p)
5287ad62
JB
4802{
4803 expressionS exp;
8335d6aa 4804 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4805 char *ptr = *str;
4806
8335d6aa 4807 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4808
8335d6aa 4809 if (exp_p->X_op == O_constant)
036dc3f7 4810 {
8335d6aa 4811 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4812 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4813 O_constant. We have to be careful not to break compilation for
4814 32-bit X_add_number, though. */
8335d6aa 4815 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4816 {
8335d6aa
JW
4817 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4818 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4819 & 0xffffffff);
036dc3f7
PB
4820 inst.operands[i].regisimm = 1;
4821 }
4822 }
8335d6aa
JW
4823 else if (exp_p->X_op == O_big
4824 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4825 {
4826 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4827
5287ad62 4828 /* Bignums have their least significant bits in
477330fc
RM
4829 generic_bignum[0]. Make sure we put 32 bits in imm and
4830 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4831 gas_assert (parts != 0);
95b75c01
NC
4832
4833 /* Make sure that the number is not too big.
4834 PR 11972: Bignums can now be sign-extended to the
4835 size of a .octa so check that the out of range bits
4836 are all zero or all one. */
8335d6aa 4837 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4838 {
4839 LITTLENUM_TYPE m = -1;
4840
4841 if (generic_bignum[parts * 2] != 0
4842 && generic_bignum[parts * 2] != m)
4843 return FAIL;
4844
8335d6aa 4845 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4846 if (generic_bignum[j] != generic_bignum[j-1])
4847 return FAIL;
4848 }
4849
5287ad62
JB
4850 inst.operands[i].imm = 0;
4851 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4852 inst.operands[i].imm |= generic_bignum[idx]
4853 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4854 inst.operands[i].reg = 0;
4855 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4856 inst.operands[i].reg |= generic_bignum[idx]
4857 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4858 inst.operands[i].regisimm = 1;
4859 }
8335d6aa 4860 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4861 return FAIL;
5f4273c7 4862
5287ad62
JB
4863 *str = ptr;
4864
4865 return SUCCESS;
4866}
4867
c19d1205
ZW
4868/* Returns the pseudo-register number of an FPA immediate constant,
4869 or FAIL if there isn't a valid constant here. */
b99bd4ef 4870
c19d1205
ZW
4871static int
4872parse_fpa_immediate (char ** str)
4873{
4874 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4875 char * save_in;
4876 expressionS exp;
4877 int i;
4878 int j;
b99bd4ef 4879
c19d1205
ZW
4880 /* First try and match exact strings, this is to guarantee
4881 that some formats will work even for cross assembly. */
b99bd4ef 4882
c19d1205
ZW
4883 for (i = 0; fp_const[i]; i++)
4884 {
4885 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4886 {
c19d1205 4887 char *start = *str;
b99bd4ef 4888
c19d1205
ZW
4889 *str += strlen (fp_const[i]);
4890 if (is_end_of_line[(unsigned char) **str])
4891 return i + 8;
4892 *str = start;
4893 }
4894 }
b99bd4ef 4895
c19d1205
ZW
4896 /* Just because we didn't get a match doesn't mean that the constant
4897 isn't valid, just that it is in a format that we don't
4898 automatically recognize. Try parsing it with the standard
4899 expression routines. */
b99bd4ef 4900
c19d1205 4901 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4902
c19d1205
ZW
4903 /* Look for a raw floating point number. */
4904 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4905 && is_end_of_line[(unsigned char) *save_in])
4906 {
4907 for (i = 0; i < NUM_FLOAT_VALS; i++)
4908 {
4909 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4910 {
c19d1205
ZW
4911 if (words[j] != fp_values[i][j])
4912 break;
b99bd4ef
NC
4913 }
4914
c19d1205 4915 if (j == MAX_LITTLENUMS)
b99bd4ef 4916 {
c19d1205
ZW
4917 *str = save_in;
4918 return i + 8;
b99bd4ef
NC
4919 }
4920 }
4921 }
b99bd4ef 4922
c19d1205
ZW
4923 /* Try and parse a more complex expression, this will probably fail
4924 unless the code uses a floating point prefix (eg "0f"). */
4925 save_in = input_line_pointer;
4926 input_line_pointer = *str;
4927 if (expression (&exp) == absolute_section
4928 && exp.X_op == O_big
4929 && exp.X_add_number < 0)
4930 {
4931 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4932 Ditto for 15. */
ba592044
AM
4933#define X_PRECISION 5
4934#define E_PRECISION 15L
4935 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4936 {
4937 for (i = 0; i < NUM_FLOAT_VALS; i++)
4938 {
4939 for (j = 0; j < MAX_LITTLENUMS; j++)
4940 {
4941 if (words[j] != fp_values[i][j])
4942 break;
4943 }
b99bd4ef 4944
c19d1205
ZW
4945 if (j == MAX_LITTLENUMS)
4946 {
4947 *str = input_line_pointer;
4948 input_line_pointer = save_in;
4949 return i + 8;
4950 }
4951 }
4952 }
b99bd4ef
NC
4953 }
4954
c19d1205
ZW
4955 *str = input_line_pointer;
4956 input_line_pointer = save_in;
4957 inst.error = _("invalid FPA immediate expression");
4958 return FAIL;
b99bd4ef
NC
4959}
4960
136da414
JB
4961/* Returns 1 if a number has "quarter-precision" float format
4962 0baBbbbbbc defgh000 00000000 00000000. */
4963
4964static int
4965is_quarter_float (unsigned imm)
4966{
4967 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4968 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4969}
4970
aacf0b33
KT
4971
4972/* Detect the presence of a floating point or integer zero constant,
4973 i.e. #0.0 or #0. */
4974
4975static bfd_boolean
4976parse_ifimm_zero (char **in)
4977{
4978 int error_code;
4979
4980 if (!is_immediate_prefix (**in))
3c6452ae
TP
4981 {
4982 /* In unified syntax, all prefixes are optional. */
4983 if (!unified_syntax)
4984 return FALSE;
4985 }
4986 else
4987 ++*in;
0900a05b
JW
4988
4989 /* Accept #0x0 as a synonym for #0. */
4990 if (strncmp (*in, "0x", 2) == 0)
4991 {
4992 int val;
4993 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4994 return FALSE;
4995 return TRUE;
4996 }
4997
aacf0b33
KT
4998 error_code = atof_generic (in, ".", EXP_CHARS,
4999 &generic_floating_point_number);
5000
5001 if (!error_code
5002 && generic_floating_point_number.sign == '+'
5003 && (generic_floating_point_number.low
5004 > generic_floating_point_number.leader))
5005 return TRUE;
5006
5007 return FALSE;
5008}
5009
136da414
JB
5010/* Parse an 8-bit "quarter-precision" floating point number of the form:
5011 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5012 The zero and minus-zero cases need special handling, since they can't be
5013 encoded in the "quarter-precision" float format, but can nonetheless be
5014 loaded as integer constants. */
136da414
JB
5015
5016static unsigned
5017parse_qfloat_immediate (char **ccp, int *immed)
5018{
5019 char *str = *ccp;
c96612cc 5020 char *fpnum;
136da414 5021 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5022 int found_fpchar = 0;
5f4273c7 5023
136da414 5024 skip_past_char (&str, '#');
5f4273c7 5025
c96612cc
JB
5026 /* We must not accidentally parse an integer as a floating-point number. Make
5027 sure that the value we parse is not an integer by checking for special
5028 characters '.' or 'e'.
5029 FIXME: This is a horrible hack, but doing better is tricky because type
5030 information isn't in a very usable state at parse time. */
5031 fpnum = str;
5032 skip_whitespace (fpnum);
5033
5034 if (strncmp (fpnum, "0x", 2) == 0)
5035 return FAIL;
5036 else
5037 {
5038 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5039 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5040 {
5041 found_fpchar = 1;
5042 break;
5043 }
c96612cc
JB
5044
5045 if (!found_fpchar)
477330fc 5046 return FAIL;
c96612cc 5047 }
5f4273c7 5048
136da414
JB
5049 if ((str = atof_ieee (str, 's', words)) != NULL)
5050 {
5051 unsigned fpword = 0;
5052 int i;
5f4273c7 5053
136da414
JB
5054 /* Our FP word must be 32 bits (single-precision FP). */
5055 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5056 {
5057 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5058 fpword |= words[i];
5059 }
5f4273c7 5060
c96612cc 5061 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5062 *immed = fpword;
136da414 5063 else
477330fc 5064 return FAIL;
136da414
JB
5065
5066 *ccp = str;
5f4273c7 5067
136da414
JB
5068 return SUCCESS;
5069 }
5f4273c7 5070
136da414
JB
5071 return FAIL;
5072}
5073
c19d1205
ZW
5074/* Shift operands. */
5075enum shift_kind
b99bd4ef 5076{
c19d1205
ZW
5077 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5078};
b99bd4ef 5079
c19d1205
ZW
5080struct asm_shift_name
5081{
5082 const char *name;
5083 enum shift_kind kind;
5084};
b99bd4ef 5085
c19d1205
ZW
5086/* Third argument to parse_shift. */
5087enum parse_shift_mode
5088{
5089 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5090 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5091 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5092 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5093 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5094};
b99bd4ef 5095
c19d1205
ZW
5096/* Parse a <shift> specifier on an ARM data processing instruction.
5097 This has three forms:
b99bd4ef 5098
c19d1205
ZW
5099 (LSL|LSR|ASL|ASR|ROR) Rs
5100 (LSL|LSR|ASL|ASR|ROR) #imm
5101 RRX
b99bd4ef 5102
c19d1205
ZW
5103 Note that ASL is assimilated to LSL in the instruction encoding, and
5104 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5105
c19d1205
ZW
5106static int
5107parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5108{
c19d1205
ZW
5109 const struct asm_shift_name *shift_name;
5110 enum shift_kind shift;
5111 char *s = *str;
5112 char *p = s;
5113 int reg;
b99bd4ef 5114
c19d1205
ZW
5115 for (p = *str; ISALPHA (*p); p++)
5116 ;
b99bd4ef 5117
c19d1205 5118 if (p == *str)
b99bd4ef 5119 {
c19d1205
ZW
5120 inst.error = _("shift expression expected");
5121 return FAIL;
b99bd4ef
NC
5122 }
5123
21d799b5 5124 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5125 p - *str);
c19d1205
ZW
5126
5127 if (shift_name == NULL)
b99bd4ef 5128 {
c19d1205
ZW
5129 inst.error = _("shift expression expected");
5130 return FAIL;
b99bd4ef
NC
5131 }
5132
c19d1205 5133 shift = shift_name->kind;
b99bd4ef 5134
c19d1205
ZW
5135 switch (mode)
5136 {
5137 case NO_SHIFT_RESTRICT:
5138 case SHIFT_IMMEDIATE: break;
b99bd4ef 5139
c19d1205
ZW
5140 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5141 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5142 {
5143 inst.error = _("'LSL' or 'ASR' required");
5144 return FAIL;
5145 }
5146 break;
b99bd4ef 5147
c19d1205
ZW
5148 case SHIFT_LSL_IMMEDIATE:
5149 if (shift != SHIFT_LSL)
5150 {
5151 inst.error = _("'LSL' required");
5152 return FAIL;
5153 }
5154 break;
b99bd4ef 5155
c19d1205
ZW
5156 case SHIFT_ASR_IMMEDIATE:
5157 if (shift != SHIFT_ASR)
5158 {
5159 inst.error = _("'ASR' required");
5160 return FAIL;
5161 }
5162 break;
b99bd4ef 5163
c19d1205
ZW
5164 default: abort ();
5165 }
b99bd4ef 5166
c19d1205
ZW
5167 if (shift != SHIFT_RRX)
5168 {
5169 /* Whitespace can appear here if the next thing is a bare digit. */
5170 skip_whitespace (p);
b99bd4ef 5171
c19d1205 5172 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5173 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5174 {
5175 inst.operands[i].imm = reg;
5176 inst.operands[i].immisreg = 1;
5177 }
5178 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5179 return FAIL;
5180 }
5181 inst.operands[i].shift_kind = shift;
5182 inst.operands[i].shifted = 1;
5183 *str = p;
5184 return SUCCESS;
b99bd4ef
NC
5185}
5186
c19d1205 5187/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5188
c19d1205
ZW
5189 #<immediate>
5190 #<immediate>, <rotate>
5191 <Rm>
5192 <Rm>, <shift>
b99bd4ef 5193
c19d1205
ZW
5194 where <shift> is defined by parse_shift above, and <rotate> is a
5195 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5196 is deferred to md_apply_fix. */
b99bd4ef 5197
c19d1205
ZW
5198static int
5199parse_shifter_operand (char **str, int i)
5200{
5201 int value;
91d6fa6a 5202 expressionS exp;
b99bd4ef 5203
dcbf9037 5204 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5205 {
5206 inst.operands[i].reg = value;
5207 inst.operands[i].isreg = 1;
b99bd4ef 5208
c19d1205
ZW
5209 /* parse_shift will override this if appropriate */
5210 inst.reloc.exp.X_op = O_constant;
5211 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5212
c19d1205
ZW
5213 if (skip_past_comma (str) == FAIL)
5214 return SUCCESS;
b99bd4ef 5215
c19d1205
ZW
5216 /* Shift operation on register. */
5217 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5218 }
5219
c19d1205
ZW
5220 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5221 return FAIL;
b99bd4ef 5222
c19d1205 5223 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5224 {
c19d1205 5225 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5226 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5227 return FAIL;
b99bd4ef 5228
91d6fa6a 5229 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5230 {
5231 inst.error = _("constant expression expected");
5232 return FAIL;
5233 }
b99bd4ef 5234
91d6fa6a 5235 value = exp.X_add_number;
c19d1205
ZW
5236 if (value < 0 || value > 30 || value % 2 != 0)
5237 {
5238 inst.error = _("invalid rotation");
5239 return FAIL;
5240 }
5241 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5242 {
5243 inst.error = _("invalid constant");
5244 return FAIL;
5245 }
09d92015 5246
a415b1cd
JB
5247 /* Encode as specified. */
5248 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5249 return SUCCESS;
09d92015
MM
5250 }
5251
c19d1205
ZW
5252 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5253 inst.reloc.pc_rel = 0;
5254 return SUCCESS;
09d92015
MM
5255}
5256
4962c51a
MS
5257/* Group relocation information. Each entry in the table contains the
5258 textual name of the relocation as may appear in assembler source
5259 and must end with a colon.
5260 Along with this textual name are the relocation codes to be used if
5261 the corresponding instruction is an ALU instruction (ADD or SUB only),
5262 an LDR, an LDRS, or an LDC. */
5263
5264struct group_reloc_table_entry
5265{
5266 const char *name;
5267 int alu_code;
5268 int ldr_code;
5269 int ldrs_code;
5270 int ldc_code;
5271};
5272
5273typedef enum
5274{
5275 /* Varieties of non-ALU group relocation. */
5276
5277 GROUP_LDR,
5278 GROUP_LDRS,
5279 GROUP_LDC
5280} group_reloc_type;
5281
5282static struct group_reloc_table_entry group_reloc_table[] =
5283 { /* Program counter relative: */
5284 { "pc_g0_nc",
5285 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5286 0, /* LDR */
5287 0, /* LDRS */
5288 0 }, /* LDC */
5289 { "pc_g0",
5290 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5291 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5292 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5293 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5294 { "pc_g1_nc",
5295 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5296 0, /* LDR */
5297 0, /* LDRS */
5298 0 }, /* LDC */
5299 { "pc_g1",
5300 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5301 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5302 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5303 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5304 { "pc_g2",
5305 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5306 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5307 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5308 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5309 /* Section base relative */
5310 { "sb_g0_nc",
5311 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5312 0, /* LDR */
5313 0, /* LDRS */
5314 0 }, /* LDC */
5315 { "sb_g0",
5316 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5317 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5318 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5319 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5320 { "sb_g1_nc",
5321 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5322 0, /* LDR */
5323 0, /* LDRS */
5324 0 }, /* LDC */
5325 { "sb_g1",
5326 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5327 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5328 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5329 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5330 { "sb_g2",
5331 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5332 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5333 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5334 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5335 /* Absolute thumb alu relocations. */
5336 { "lower0_7",
5337 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5338 0, /* LDR. */
5339 0, /* LDRS. */
5340 0 }, /* LDC. */
5341 { "lower8_15",
5342 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5343 0, /* LDR. */
5344 0, /* LDRS. */
5345 0 }, /* LDC. */
5346 { "upper0_7",
5347 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5348 0, /* LDR. */
5349 0, /* LDRS. */
5350 0 }, /* LDC. */
5351 { "upper8_15",
5352 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5353 0, /* LDR. */
5354 0, /* LDRS. */
5355 0 } }; /* LDC. */
4962c51a
MS
5356
5357/* Given the address of a pointer pointing to the textual name of a group
5358 relocation as may appear in assembler source, attempt to find its details
5359 in group_reloc_table. The pointer will be updated to the character after
5360 the trailing colon. On failure, FAIL will be returned; SUCCESS
5361 otherwise. On success, *entry will be updated to point at the relevant
5362 group_reloc_table entry. */
5363
5364static int
5365find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5366{
5367 unsigned int i;
5368 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5369 {
5370 int length = strlen (group_reloc_table[i].name);
5371
5f4273c7
NC
5372 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5373 && (*str)[length] == ':')
477330fc
RM
5374 {
5375 *out = &group_reloc_table[i];
5376 *str += (length + 1);
5377 return SUCCESS;
5378 }
4962c51a
MS
5379 }
5380
5381 return FAIL;
5382}
5383
5384/* Parse a <shifter_operand> for an ARM data processing instruction
5385 (as for parse_shifter_operand) where group relocations are allowed:
5386
5387 #<immediate>
5388 #<immediate>, <rotate>
5389 #:<group_reloc>:<expression>
5390 <Rm>
5391 <Rm>, <shift>
5392
5393 where <group_reloc> is one of the strings defined in group_reloc_table.
5394 The hashes are optional.
5395
5396 Everything else is as for parse_shifter_operand. */
5397
5398static parse_operand_result
5399parse_shifter_operand_group_reloc (char **str, int i)
5400{
5401 /* Determine if we have the sequence of characters #: or just :
5402 coming next. If we do, then we check for a group relocation.
5403 If we don't, punt the whole lot to parse_shifter_operand. */
5404
5405 if (((*str)[0] == '#' && (*str)[1] == ':')
5406 || (*str)[0] == ':')
5407 {
5408 struct group_reloc_table_entry *entry;
5409
5410 if ((*str)[0] == '#')
477330fc 5411 (*str) += 2;
4962c51a 5412 else
477330fc 5413 (*str)++;
4962c51a
MS
5414
5415 /* Try to parse a group relocation. Anything else is an error. */
5416 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5417 {
5418 inst.error = _("unknown group relocation");
5419 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5420 }
4962c51a
MS
5421
5422 /* We now have the group relocation table entry corresponding to
477330fc 5423 the name in the assembler source. Next, we parse the expression. */
4962c51a 5424 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5425 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5426
5427 /* Record the relocation type (always the ALU variant here). */
21d799b5 5428 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5429 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5430
5431 return PARSE_OPERAND_SUCCESS;
5432 }
5433 else
5434 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5435 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5436
5437 /* Never reached. */
5438}
5439
8e560766
MGD
5440/* Parse a Neon alignment expression. Information is written to
5441 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5442
8e560766
MGD
5443 align .imm = align << 8, .immisalign=1, .preind=0 */
5444static parse_operand_result
5445parse_neon_alignment (char **str, int i)
5446{
5447 char *p = *str;
5448 expressionS exp;
5449
5450 my_get_expression (&exp, &p, GE_NO_PREFIX);
5451
5452 if (exp.X_op != O_constant)
5453 {
5454 inst.error = _("alignment must be constant");
5455 return PARSE_OPERAND_FAIL;
5456 }
5457
5458 inst.operands[i].imm = exp.X_add_number << 8;
5459 inst.operands[i].immisalign = 1;
5460 /* Alignments are not pre-indexes. */
5461 inst.operands[i].preind = 0;
5462
5463 *str = p;
5464 return PARSE_OPERAND_SUCCESS;
5465}
5466
c19d1205
ZW
5467/* Parse all forms of an ARM address expression. Information is written
5468 to inst.operands[i] and/or inst.reloc.
09d92015 5469
c19d1205 5470 Preindexed addressing (.preind=1):
09d92015 5471
c19d1205
ZW
5472 [Rn, #offset] .reg=Rn .reloc.exp=offset
5473 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5474 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5475 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5476
c19d1205 5477 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5478
c19d1205 5479 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5480
c19d1205
ZW
5481 [Rn], #offset .reg=Rn .reloc.exp=offset
5482 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5483 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5484 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5485
c19d1205 5486 Unindexed addressing (.preind=0, .postind=0):
09d92015 5487
c19d1205 5488 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5489
c19d1205 5490 Other:
09d92015 5491
c19d1205
ZW
5492 [Rn]{!} shorthand for [Rn,#0]{!}
5493 =immediate .isreg=0 .reloc.exp=immediate
5494 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5495
c19d1205
ZW
5496 It is the caller's responsibility to check for addressing modes not
5497 supported by the instruction, and to set inst.reloc.type. */
5498
4962c51a
MS
5499static parse_operand_result
5500parse_address_main (char **str, int i, int group_relocations,
477330fc 5501 group_reloc_type group_type)
09d92015 5502{
c19d1205
ZW
5503 char *p = *str;
5504 int reg;
09d92015 5505
c19d1205 5506 if (skip_past_char (&p, '[') == FAIL)
09d92015 5507 {
c19d1205
ZW
5508 if (skip_past_char (&p, '=') == FAIL)
5509 {
974da60d 5510 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5511 inst.reloc.pc_rel = 1;
5512 inst.operands[i].reg = REG_PC;
5513 inst.operands[i].isreg = 1;
5514 inst.operands[i].preind = 1;
09d92015 5515
8335d6aa
JW
5516 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5517 return PARSE_OPERAND_FAIL;
5518 }
5519 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5520 /*allow_symbol_p=*/TRUE))
4962c51a 5521 return PARSE_OPERAND_FAIL;
09d92015 5522
c19d1205 5523 *str = p;
4962c51a 5524 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5525 }
5526
8ab8155f
NC
5527 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5528 skip_whitespace (p);
5529
dcbf9037 5530 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5531 {
c19d1205 5532 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5533 return PARSE_OPERAND_FAIL;
09d92015 5534 }
c19d1205
ZW
5535 inst.operands[i].reg = reg;
5536 inst.operands[i].isreg = 1;
09d92015 5537
c19d1205 5538 if (skip_past_comma (&p) == SUCCESS)
09d92015 5539 {
c19d1205 5540 inst.operands[i].preind = 1;
09d92015 5541
c19d1205
ZW
5542 if (*p == '+') p++;
5543 else if (*p == '-') p++, inst.operands[i].negative = 1;
5544
dcbf9037 5545 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5546 {
c19d1205
ZW
5547 inst.operands[i].imm = reg;
5548 inst.operands[i].immisreg = 1;
5549
5550 if (skip_past_comma (&p) == SUCCESS)
5551 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5552 return PARSE_OPERAND_FAIL;
c19d1205 5553 }
5287ad62 5554 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5555 {
5556 /* FIXME: '@' should be used here, but it's filtered out by generic
5557 code before we get to see it here. This may be subject to
5558 change. */
5559 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5560
8e560766
MGD
5561 if (result != PARSE_OPERAND_SUCCESS)
5562 return result;
5563 }
c19d1205
ZW
5564 else
5565 {
5566 if (inst.operands[i].negative)
5567 {
5568 inst.operands[i].negative = 0;
5569 p--;
5570 }
4962c51a 5571
5f4273c7
NC
5572 if (group_relocations
5573 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5574 {
5575 struct group_reloc_table_entry *entry;
5576
477330fc
RM
5577 /* Skip over the #: or : sequence. */
5578 if (*p == '#')
5579 p += 2;
5580 else
5581 p++;
4962c51a
MS
5582
5583 /* Try to parse a group relocation. Anything else is an
477330fc 5584 error. */
4962c51a
MS
5585 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5586 {
5587 inst.error = _("unknown group relocation");
5588 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5589 }
5590
5591 /* We now have the group relocation table entry corresponding to
5592 the name in the assembler source. Next, we parse the
477330fc 5593 expression. */
4962c51a
MS
5594 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5595 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5596
5597 /* Record the relocation type. */
477330fc
RM
5598 switch (group_type)
5599 {
5600 case GROUP_LDR:
5601 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5602 break;
4962c51a 5603
477330fc
RM
5604 case GROUP_LDRS:
5605 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5606 break;
4962c51a 5607
477330fc
RM
5608 case GROUP_LDC:
5609 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5610 break;
4962c51a 5611
477330fc
RM
5612 default:
5613 gas_assert (0);
5614 }
4962c51a 5615
477330fc 5616 if (inst.reloc.type == 0)
4962c51a
MS
5617 {
5618 inst.error = _("this group relocation is not allowed on this instruction");
5619 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5620 }
477330fc
RM
5621 }
5622 else
26d97720
NS
5623 {
5624 char *q = p;
0198d5e6 5625
26d97720
NS
5626 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5627 return PARSE_OPERAND_FAIL;
5628 /* If the offset is 0, find out if it's a +0 or -0. */
5629 if (inst.reloc.exp.X_op == O_constant
5630 && inst.reloc.exp.X_add_number == 0)
5631 {
5632 skip_whitespace (q);
5633 if (*q == '#')
5634 {
5635 q++;
5636 skip_whitespace (q);
5637 }
5638 if (*q == '-')
5639 inst.operands[i].negative = 1;
5640 }
5641 }
09d92015
MM
5642 }
5643 }
8e560766
MGD
5644 else if (skip_past_char (&p, ':') == SUCCESS)
5645 {
5646 /* FIXME: '@' should be used here, but it's filtered out by generic code
5647 before we get to see it here. This may be subject to change. */
5648 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5649
8e560766
MGD
5650 if (result != PARSE_OPERAND_SUCCESS)
5651 return result;
5652 }
09d92015 5653
c19d1205 5654 if (skip_past_char (&p, ']') == FAIL)
09d92015 5655 {
c19d1205 5656 inst.error = _("']' expected");
4962c51a 5657 return PARSE_OPERAND_FAIL;
09d92015
MM
5658 }
5659
c19d1205
ZW
5660 if (skip_past_char (&p, '!') == SUCCESS)
5661 inst.operands[i].writeback = 1;
09d92015 5662
c19d1205 5663 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5664 {
c19d1205
ZW
5665 if (skip_past_char (&p, '{') == SUCCESS)
5666 {
5667 /* [Rn], {expr} - unindexed, with option */
5668 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5669 0, 255, TRUE) == FAIL)
4962c51a 5670 return PARSE_OPERAND_FAIL;
09d92015 5671
c19d1205
ZW
5672 if (skip_past_char (&p, '}') == FAIL)
5673 {
5674 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5675 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5676 }
5677 if (inst.operands[i].preind)
5678 {
5679 inst.error = _("cannot combine index with option");
4962c51a 5680 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5681 }
5682 *str = p;
4962c51a 5683 return PARSE_OPERAND_SUCCESS;
09d92015 5684 }
c19d1205
ZW
5685 else
5686 {
5687 inst.operands[i].postind = 1;
5688 inst.operands[i].writeback = 1;
09d92015 5689
c19d1205
ZW
5690 if (inst.operands[i].preind)
5691 {
5692 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5693 return PARSE_OPERAND_FAIL;
c19d1205 5694 }
09d92015 5695
c19d1205
ZW
5696 if (*p == '+') p++;
5697 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5698
dcbf9037 5699 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5700 {
477330fc
RM
5701 /* We might be using the immediate for alignment already. If we
5702 are, OR the register number into the low-order bits. */
5703 if (inst.operands[i].immisalign)
5704 inst.operands[i].imm |= reg;
5705 else
5706 inst.operands[i].imm = reg;
c19d1205 5707 inst.operands[i].immisreg = 1;
a737bd4d 5708
c19d1205
ZW
5709 if (skip_past_comma (&p) == SUCCESS)
5710 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5711 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5712 }
5713 else
5714 {
26d97720 5715 char *q = p;
0198d5e6 5716
c19d1205
ZW
5717 if (inst.operands[i].negative)
5718 {
5719 inst.operands[i].negative = 0;
5720 p--;
5721 }
5722 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5723 return PARSE_OPERAND_FAIL;
26d97720
NS
5724 /* If the offset is 0, find out if it's a +0 or -0. */
5725 if (inst.reloc.exp.X_op == O_constant
5726 && inst.reloc.exp.X_add_number == 0)
5727 {
5728 skip_whitespace (q);
5729 if (*q == '#')
5730 {
5731 q++;
5732 skip_whitespace (q);
5733 }
5734 if (*q == '-')
5735 inst.operands[i].negative = 1;
5736 }
c19d1205
ZW
5737 }
5738 }
a737bd4d
NC
5739 }
5740
c19d1205
ZW
5741 /* If at this point neither .preind nor .postind is set, we have a
5742 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5743 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5744 {
5745 inst.operands[i].preind = 1;
5746 inst.reloc.exp.X_op = O_constant;
5747 inst.reloc.exp.X_add_number = 0;
5748 }
5749 *str = p;
4962c51a
MS
5750 return PARSE_OPERAND_SUCCESS;
5751}
5752
5753static int
5754parse_address (char **str, int i)
5755{
21d799b5 5756 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5757 ? SUCCESS : FAIL;
4962c51a
MS
5758}
5759
5760static parse_operand_result
5761parse_address_group_reloc (char **str, int i, group_reloc_type type)
5762{
5763 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5764}
5765
b6895b4f
PB
5766/* Parse an operand for a MOVW or MOVT instruction. */
5767static int
5768parse_half (char **str)
5769{
5770 char * p;
5f4273c7 5771
b6895b4f
PB
5772 p = *str;
5773 skip_past_char (&p, '#');
5f4273c7 5774 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5775 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5776 else if (strncasecmp (p, ":upper16:", 9) == 0)
5777 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5778
5779 if (inst.reloc.type != BFD_RELOC_UNUSED)
5780 {
5781 p += 9;
5f4273c7 5782 skip_whitespace (p);
b6895b4f
PB
5783 }
5784
5785 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5786 return FAIL;
5787
5788 if (inst.reloc.type == BFD_RELOC_UNUSED)
5789 {
5790 if (inst.reloc.exp.X_op != O_constant)
5791 {
5792 inst.error = _("constant expression expected");
5793 return FAIL;
5794 }
5795 if (inst.reloc.exp.X_add_number < 0
5796 || inst.reloc.exp.X_add_number > 0xffff)
5797 {
5798 inst.error = _("immediate value out of range");
5799 return FAIL;
5800 }
5801 }
5802 *str = p;
5803 return SUCCESS;
5804}
5805
c19d1205 5806/* Miscellaneous. */
a737bd4d 5807
c19d1205
ZW
5808/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5809 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5810static int
d2cd1205 5811parse_psr (char **str, bfd_boolean lhs)
09d92015 5812{
c19d1205
ZW
5813 char *p;
5814 unsigned long psr_field;
62b3e311
PB
5815 const struct asm_psr *psr;
5816 char *start;
d2cd1205 5817 bfd_boolean is_apsr = FALSE;
ac7f631b 5818 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5819
a4482bb6
NC
5820 /* PR gas/12698: If the user has specified -march=all then m_profile will
5821 be TRUE, but we want to ignore it in this case as we are building for any
5822 CPU type, including non-m variants. */
823d2571 5823 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5824 m_profile = FALSE;
5825
c19d1205
ZW
5826 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5827 feature for ease of use and backwards compatibility. */
5828 p = *str;
62b3e311 5829 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5830 {
5831 if (m_profile)
5832 goto unsupported_psr;
fa94de6b 5833
d2cd1205
JB
5834 psr_field = SPSR_BIT;
5835 }
5836 else if (strncasecmp (p, "CPSR", 4) == 0)
5837 {
5838 if (m_profile)
5839 goto unsupported_psr;
5840
5841 psr_field = 0;
5842 }
5843 else if (strncasecmp (p, "APSR", 4) == 0)
5844 {
5845 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5846 and ARMv7-R architecture CPUs. */
5847 is_apsr = TRUE;
5848 psr_field = 0;
5849 }
5850 else if (m_profile)
62b3e311
PB
5851 {
5852 start = p;
5853 do
5854 p++;
5855 while (ISALNUM (*p) || *p == '_');
5856
d2cd1205
JB
5857 if (strncasecmp (start, "iapsr", 5) == 0
5858 || strncasecmp (start, "eapsr", 5) == 0
5859 || strncasecmp (start, "xpsr", 4) == 0
5860 || strncasecmp (start, "psr", 3) == 0)
5861 p = start + strcspn (start, "rR") + 1;
5862
21d799b5 5863 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5864 p - start);
d2cd1205 5865
62b3e311
PB
5866 if (!psr)
5867 return FAIL;
09d92015 5868
d2cd1205
JB
5869 /* If APSR is being written, a bitfield may be specified. Note that
5870 APSR itself is handled above. */
5871 if (psr->field <= 3)
5872 {
5873 psr_field = psr->field;
5874 is_apsr = TRUE;
5875 goto check_suffix;
5876 }
5877
62b3e311 5878 *str = p;
d2cd1205
JB
5879 /* M-profile MSR instructions have the mask field set to "10", except
5880 *PSR variants which modify APSR, which may use a different mask (and
5881 have been handled already). Do that by setting the PSR_f field
5882 here. */
5883 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5884 }
d2cd1205
JB
5885 else
5886 goto unsupported_psr;
09d92015 5887
62b3e311 5888 p += 4;
d2cd1205 5889check_suffix:
c19d1205
ZW
5890 if (*p == '_')
5891 {
5892 /* A suffix follows. */
c19d1205
ZW
5893 p++;
5894 start = p;
a737bd4d 5895
c19d1205
ZW
5896 do
5897 p++;
5898 while (ISALNUM (*p) || *p == '_');
a737bd4d 5899
d2cd1205
JB
5900 if (is_apsr)
5901 {
5902 /* APSR uses a notation for bits, rather than fields. */
5903 unsigned int nzcvq_bits = 0;
5904 unsigned int g_bit = 0;
5905 char *bit;
fa94de6b 5906
d2cd1205
JB
5907 for (bit = start; bit != p; bit++)
5908 {
5909 switch (TOLOWER (*bit))
477330fc 5910 {
d2cd1205
JB
5911 case 'n':
5912 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5913 break;
5914
5915 case 'z':
5916 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5917 break;
5918
5919 case 'c':
5920 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5921 break;
5922
5923 case 'v':
5924 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5925 break;
fa94de6b 5926
d2cd1205
JB
5927 case 'q':
5928 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5929 break;
fa94de6b 5930
d2cd1205
JB
5931 case 'g':
5932 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5933 break;
fa94de6b 5934
d2cd1205
JB
5935 default:
5936 inst.error = _("unexpected bit specified after APSR");
5937 return FAIL;
5938 }
5939 }
fa94de6b 5940
d2cd1205
JB
5941 if (nzcvq_bits == 0x1f)
5942 psr_field |= PSR_f;
fa94de6b 5943
d2cd1205
JB
5944 if (g_bit == 0x1)
5945 {
5946 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5947 {
d2cd1205
JB
5948 inst.error = _("selected processor does not "
5949 "support DSP extension");
5950 return FAIL;
5951 }
5952
5953 psr_field |= PSR_s;
5954 }
fa94de6b 5955
d2cd1205
JB
5956 if ((nzcvq_bits & 0x20) != 0
5957 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5958 || (g_bit & 0x2) != 0)
5959 {
5960 inst.error = _("bad bitmask specified after APSR");
5961 return FAIL;
5962 }
5963 }
5964 else
477330fc 5965 {
d2cd1205 5966 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5967 p - start);
d2cd1205 5968 if (!psr)
477330fc 5969 goto error;
a737bd4d 5970
d2cd1205
JB
5971 psr_field |= psr->field;
5972 }
a737bd4d 5973 }
c19d1205 5974 else
a737bd4d 5975 {
c19d1205
ZW
5976 if (ISALNUM (*p))
5977 goto error; /* Garbage after "[CS]PSR". */
5978
d2cd1205 5979 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5980 is deprecated, but allow it anyway. */
d2cd1205
JB
5981 if (is_apsr && lhs)
5982 {
5983 psr_field |= PSR_f;
5984 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5985 "deprecated"));
5986 }
5987 else if (!m_profile)
5988 /* These bits are never right for M-profile devices: don't set them
5989 (only code paths which read/write APSR reach here). */
5990 psr_field |= (PSR_c | PSR_f);
a737bd4d 5991 }
c19d1205
ZW
5992 *str = p;
5993 return psr_field;
a737bd4d 5994
d2cd1205
JB
5995 unsupported_psr:
5996 inst.error = _("selected processor does not support requested special "
5997 "purpose register");
5998 return FAIL;
5999
c19d1205
ZW
6000 error:
6001 inst.error = _("flag for {c}psr instruction expected");
6002 return FAIL;
a737bd4d
NC
6003}
6004
c19d1205
ZW
6005/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6006 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6007
c19d1205
ZW
6008static int
6009parse_cps_flags (char **str)
a737bd4d 6010{
c19d1205
ZW
6011 int val = 0;
6012 int saw_a_flag = 0;
6013 char *s = *str;
a737bd4d 6014
c19d1205
ZW
6015 for (;;)
6016 switch (*s++)
6017 {
6018 case '\0': case ',':
6019 goto done;
a737bd4d 6020
c19d1205
ZW
6021 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6022 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6023 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6024
c19d1205
ZW
6025 default:
6026 inst.error = _("unrecognized CPS flag");
6027 return FAIL;
6028 }
a737bd4d 6029
c19d1205
ZW
6030 done:
6031 if (saw_a_flag == 0)
a737bd4d 6032 {
c19d1205
ZW
6033 inst.error = _("missing CPS flags");
6034 return FAIL;
a737bd4d 6035 }
a737bd4d 6036
c19d1205
ZW
6037 *str = s - 1;
6038 return val;
a737bd4d
NC
6039}
6040
c19d1205
ZW
6041/* Parse an endian specifier ("BE" or "LE", case insensitive);
6042 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6043
6044static int
c19d1205 6045parse_endian_specifier (char **str)
a737bd4d 6046{
c19d1205
ZW
6047 int little_endian;
6048 char *s = *str;
a737bd4d 6049
c19d1205
ZW
6050 if (strncasecmp (s, "BE", 2))
6051 little_endian = 0;
6052 else if (strncasecmp (s, "LE", 2))
6053 little_endian = 1;
6054 else
a737bd4d 6055 {
c19d1205 6056 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6057 return FAIL;
6058 }
6059
c19d1205 6060 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6061 {
c19d1205 6062 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6063 return FAIL;
6064 }
6065
c19d1205
ZW
6066 *str = s + 2;
6067 return little_endian;
6068}
a737bd4d 6069
c19d1205
ZW
6070/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6071 value suitable for poking into the rotate field of an sxt or sxta
6072 instruction, or FAIL on error. */
6073
6074static int
6075parse_ror (char **str)
6076{
6077 int rot;
6078 char *s = *str;
6079
6080 if (strncasecmp (s, "ROR", 3) == 0)
6081 s += 3;
6082 else
a737bd4d 6083 {
c19d1205 6084 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6085 return FAIL;
6086 }
c19d1205
ZW
6087
6088 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6089 return FAIL;
6090
6091 switch (rot)
a737bd4d 6092 {
c19d1205
ZW
6093 case 0: *str = s; return 0x0;
6094 case 8: *str = s; return 0x1;
6095 case 16: *str = s; return 0x2;
6096 case 24: *str = s; return 0x3;
6097
6098 default:
6099 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6100 return FAIL;
6101 }
c19d1205 6102}
a737bd4d 6103
c19d1205
ZW
6104/* Parse a conditional code (from conds[] below). The value returned is in the
6105 range 0 .. 14, or FAIL. */
6106static int
6107parse_cond (char **str)
6108{
c462b453 6109 char *q;
c19d1205 6110 const struct asm_cond *c;
c462b453
PB
6111 int n;
6112 /* Condition codes are always 2 characters, so matching up to
6113 3 characters is sufficient. */
6114 char cond[3];
a737bd4d 6115
c462b453
PB
6116 q = *str;
6117 n = 0;
6118 while (ISALPHA (*q) && n < 3)
6119 {
e07e6e58 6120 cond[n] = TOLOWER (*q);
c462b453
PB
6121 q++;
6122 n++;
6123 }
a737bd4d 6124
21d799b5 6125 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6126 if (!c)
a737bd4d 6127 {
c19d1205 6128 inst.error = _("condition required");
a737bd4d
NC
6129 return FAIL;
6130 }
6131
c19d1205
ZW
6132 *str = q;
6133 return c->value;
6134}
6135
643afb90
MW
6136/* Record a use of the given feature. */
6137static void
6138record_feature_use (const arm_feature_set *feature)
6139{
6140 if (thumb_mode)
6141 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6142 else
6143 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6144}
6145
e797f7e0
MGD
6146/* If the given feature available in the selected CPU, mark it as used.
6147 Returns TRUE iff feature is available. */
6148static bfd_boolean
6149mark_feature_used (const arm_feature_set *feature)
6150{
6151 /* Ensure the option is valid on the current architecture. */
6152 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6153 return FALSE;
6154
6155 /* Add the appropriate architecture feature for the barrier option used.
6156 */
643afb90 6157 record_feature_use (feature);
e797f7e0
MGD
6158
6159 return TRUE;
6160}
6161
62b3e311
PB
6162/* Parse an option for a barrier instruction. Returns the encoding for the
6163 option, or FAIL. */
6164static int
6165parse_barrier (char **str)
6166{
6167 char *p, *q;
6168 const struct asm_barrier_opt *o;
6169
6170 p = q = *str;
6171 while (ISALPHA (*q))
6172 q++;
6173
21d799b5 6174 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6175 q - p);
62b3e311
PB
6176 if (!o)
6177 return FAIL;
6178
e797f7e0
MGD
6179 if (!mark_feature_used (&o->arch))
6180 return FAIL;
6181
62b3e311
PB
6182 *str = q;
6183 return o->value;
6184}
6185
92e90b6e
PB
6186/* Parse the operands of a table branch instruction. Similar to a memory
6187 operand. */
6188static int
6189parse_tb (char **str)
6190{
6191 char * p = *str;
6192 int reg;
6193
6194 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6195 {
6196 inst.error = _("'[' expected");
6197 return FAIL;
6198 }
92e90b6e 6199
dcbf9037 6200 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6201 {
6202 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6203 return FAIL;
6204 }
6205 inst.operands[0].reg = reg;
6206
6207 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6208 {
6209 inst.error = _("',' expected");
6210 return FAIL;
6211 }
5f4273c7 6212
dcbf9037 6213 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6214 {
6215 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6216 return FAIL;
6217 }
6218 inst.operands[0].imm = reg;
6219
6220 if (skip_past_comma (&p) == SUCCESS)
6221 {
6222 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6223 return FAIL;
6224 if (inst.reloc.exp.X_add_number != 1)
6225 {
6226 inst.error = _("invalid shift");
6227 return FAIL;
6228 }
6229 inst.operands[0].shifted = 1;
6230 }
6231
6232 if (skip_past_char (&p, ']') == FAIL)
6233 {
6234 inst.error = _("']' expected");
6235 return FAIL;
6236 }
6237 *str = p;
6238 return SUCCESS;
6239}
6240
5287ad62
JB
6241/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6242 information on the types the operands can take and how they are encoded.
037e8744
JB
6243 Up to four operands may be read; this function handles setting the
6244 ".present" field for each read operand itself.
5287ad62
JB
6245 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6246 else returns FAIL. */
6247
6248static int
6249parse_neon_mov (char **str, int *which_operand)
6250{
6251 int i = *which_operand, val;
6252 enum arm_reg_type rtype;
6253 char *ptr = *str;
dcbf9037 6254 struct neon_type_el optype;
5f4273c7 6255
dcbf9037 6256 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6257 {
6258 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6259 inst.operands[i].reg = val;
6260 inst.operands[i].isscalar = 1;
dcbf9037 6261 inst.operands[i].vectype = optype;
5287ad62
JB
6262 inst.operands[i++].present = 1;
6263
6264 if (skip_past_comma (&ptr) == FAIL)
477330fc 6265 goto wanted_comma;
5f4273c7 6266
dcbf9037 6267 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6268 goto wanted_arm;
5f4273c7 6269
5287ad62
JB
6270 inst.operands[i].reg = val;
6271 inst.operands[i].isreg = 1;
6272 inst.operands[i].present = 1;
6273 }
037e8744 6274 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6275 != FAIL)
5287ad62
JB
6276 {
6277 /* Cases 0, 1, 2, 3, 5 (D only). */
6278 if (skip_past_comma (&ptr) == FAIL)
477330fc 6279 goto wanted_comma;
5f4273c7 6280
5287ad62
JB
6281 inst.operands[i].reg = val;
6282 inst.operands[i].isreg = 1;
6283 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6284 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6285 inst.operands[i].isvec = 1;
dcbf9037 6286 inst.operands[i].vectype = optype;
5287ad62
JB
6287 inst.operands[i++].present = 1;
6288
dcbf9037 6289 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6290 {
6291 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6292 Case 13: VMOV <Sd>, <Rm> */
6293 inst.operands[i].reg = val;
6294 inst.operands[i].isreg = 1;
6295 inst.operands[i].present = 1;
6296
6297 if (rtype == REG_TYPE_NQ)
6298 {
6299 first_error (_("can't use Neon quad register here"));
6300 return FAIL;
6301 }
6302 else if (rtype != REG_TYPE_VFS)
6303 {
6304 i++;
6305 if (skip_past_comma (&ptr) == FAIL)
6306 goto wanted_comma;
6307 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6308 goto wanted_arm;
6309 inst.operands[i].reg = val;
6310 inst.operands[i].isreg = 1;
6311 inst.operands[i].present = 1;
6312 }
6313 }
037e8744 6314 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6315 &optype)) != FAIL)
6316 {
6317 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6318 Case 1: VMOV<c><q> <Dd>, <Dm>
6319 Case 8: VMOV.F32 <Sd>, <Sm>
6320 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6321
6322 inst.operands[i].reg = val;
6323 inst.operands[i].isreg = 1;
6324 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6325 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6326 inst.operands[i].isvec = 1;
6327 inst.operands[i].vectype = optype;
6328 inst.operands[i].present = 1;
6329
6330 if (skip_past_comma (&ptr) == SUCCESS)
6331 {
6332 /* Case 15. */
6333 i++;
6334
6335 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6336 goto wanted_arm;
6337
6338 inst.operands[i].reg = val;
6339 inst.operands[i].isreg = 1;
6340 inst.operands[i++].present = 1;
6341
6342 if (skip_past_comma (&ptr) == FAIL)
6343 goto wanted_comma;
6344
6345 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6346 goto wanted_arm;
6347
6348 inst.operands[i].reg = val;
6349 inst.operands[i].isreg = 1;
6350 inst.operands[i].present = 1;
6351 }
6352 }
4641781c 6353 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6354 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6355 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6356 Case 10: VMOV.F32 <Sd>, #<imm>
6357 Case 11: VMOV.F64 <Dd>, #<imm> */
6358 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6359 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6360 == SUCCESS)
477330fc
RM
6361 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6362 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6363 ;
5287ad62 6364 else
477330fc
RM
6365 {
6366 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6367 return FAIL;
6368 }
5287ad62 6369 }
dcbf9037 6370 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6371 {
6372 /* Cases 6, 7. */
6373 inst.operands[i].reg = val;
6374 inst.operands[i].isreg = 1;
6375 inst.operands[i++].present = 1;
5f4273c7 6376
5287ad62 6377 if (skip_past_comma (&ptr) == FAIL)
477330fc 6378 goto wanted_comma;
5f4273c7 6379
dcbf9037 6380 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6381 {
6382 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6383 inst.operands[i].reg = val;
6384 inst.operands[i].isscalar = 1;
6385 inst.operands[i].present = 1;
6386 inst.operands[i].vectype = optype;
6387 }
dcbf9037 6388 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6389 {
6390 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6391 inst.operands[i].reg = val;
6392 inst.operands[i].isreg = 1;
6393 inst.operands[i++].present = 1;
6394
6395 if (skip_past_comma (&ptr) == FAIL)
6396 goto wanted_comma;
6397
6398 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6399 == FAIL)
6400 {
6401 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6402 return FAIL;
6403 }
6404
6405 inst.operands[i].reg = val;
6406 inst.operands[i].isreg = 1;
6407 inst.operands[i].isvec = 1;
6408 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6409 inst.operands[i].vectype = optype;
6410 inst.operands[i].present = 1;
6411
6412 if (rtype == REG_TYPE_VFS)
6413 {
6414 /* Case 14. */
6415 i++;
6416 if (skip_past_comma (&ptr) == FAIL)
6417 goto wanted_comma;
6418 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6419 &optype)) == FAIL)
6420 {
6421 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6422 return FAIL;
6423 }
6424 inst.operands[i].reg = val;
6425 inst.operands[i].isreg = 1;
6426 inst.operands[i].isvec = 1;
6427 inst.operands[i].issingle = 1;
6428 inst.operands[i].vectype = optype;
6429 inst.operands[i].present = 1;
6430 }
6431 }
037e8744 6432 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6433 != FAIL)
6434 {
6435 /* Case 13. */
6436 inst.operands[i].reg = val;
6437 inst.operands[i].isreg = 1;
6438 inst.operands[i].isvec = 1;
6439 inst.operands[i].issingle = 1;
6440 inst.operands[i].vectype = optype;
6441 inst.operands[i].present = 1;
6442 }
5287ad62
JB
6443 }
6444 else
6445 {
dcbf9037 6446 first_error (_("parse error"));
5287ad62
JB
6447 return FAIL;
6448 }
6449
6450 /* Successfully parsed the operands. Update args. */
6451 *which_operand = i;
6452 *str = ptr;
6453 return SUCCESS;
6454
5f4273c7 6455 wanted_comma:
dcbf9037 6456 first_error (_("expected comma"));
5287ad62 6457 return FAIL;
5f4273c7
NC
6458
6459 wanted_arm:
dcbf9037 6460 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6461 return FAIL;
5287ad62
JB
6462}
6463
5be8be5d
DG
6464/* Use this macro when the operand constraints are different
6465 for ARM and THUMB (e.g. ldrd). */
6466#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6467 ((arm_operand) | ((thumb_operand) << 16))
6468
c19d1205
ZW
6469/* Matcher codes for parse_operands. */
6470enum operand_parse_code
6471{
6472 OP_stop, /* end of line */
6473
6474 OP_RR, /* ARM register */
6475 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6476 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6477 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6478 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6479 optional trailing ! */
c19d1205
ZW
6480 OP_RRw, /* ARM register, not r15, optional trailing ! */
6481 OP_RCP, /* Coprocessor number */
6482 OP_RCN, /* Coprocessor register */
6483 OP_RF, /* FPA register */
6484 OP_RVS, /* VFP single precision register */
5287ad62
JB
6485 OP_RVD, /* VFP double precision register (0..15) */
6486 OP_RND, /* Neon double precision register (0..31) */
6487 OP_RNQ, /* Neon quad precision register */
037e8744 6488 OP_RVSD, /* VFP single or double precision register */
5287ad62 6489 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6490 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6491 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6492 OP_RVC, /* VFP control register */
6493 OP_RMF, /* Maverick F register */
6494 OP_RMD, /* Maverick D register */
6495 OP_RMFX, /* Maverick FX register */
6496 OP_RMDX, /* Maverick DX register */
6497 OP_RMAX, /* Maverick AX register */
6498 OP_RMDS, /* Maverick DSPSC register */
6499 OP_RIWR, /* iWMMXt wR register */
6500 OP_RIWC, /* iWMMXt wC register */
6501 OP_RIWG, /* iWMMXt wCG register */
6502 OP_RXA, /* XScale accumulator register */
6503
6504 OP_REGLST, /* ARM register list */
6505 OP_VRSLST, /* VFP single-precision register list */
6506 OP_VRDLST, /* VFP double-precision register list */
037e8744 6507 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6508 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6509 OP_NSTRLST, /* Neon element/structure list */
6510
5287ad62 6511 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6512 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6513 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6514 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6515 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6516 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6517 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6518 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6519 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6520 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6521 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6522
6523 OP_I0, /* immediate zero */
c19d1205
ZW
6524 OP_I7, /* immediate value 0 .. 7 */
6525 OP_I15, /* 0 .. 15 */
6526 OP_I16, /* 1 .. 16 */
5287ad62 6527 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6528 OP_I31, /* 0 .. 31 */
6529 OP_I31w, /* 0 .. 31, optional trailing ! */
6530 OP_I32, /* 1 .. 32 */
5287ad62
JB
6531 OP_I32z, /* 0 .. 32 */
6532 OP_I63, /* 0 .. 63 */
c19d1205 6533 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6534 OP_I64, /* 1 .. 64 */
6535 OP_I64z, /* 0 .. 64 */
c19d1205 6536 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6537
6538 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6539 OP_I7b, /* 0 .. 7 */
6540 OP_I15b, /* 0 .. 15 */
6541 OP_I31b, /* 0 .. 31 */
6542
6543 OP_SH, /* shifter operand */
4962c51a 6544 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6545 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6546 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6547 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6548 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6549 OP_EXP, /* arbitrary expression */
6550 OP_EXPi, /* same, with optional immediate prefix */
6551 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6552 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6553 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6554 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6555
6556 OP_CPSF, /* CPS flags */
6557 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6558 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6559 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6560 OP_COND, /* conditional code */
92e90b6e 6561 OP_TB, /* Table branch. */
c19d1205 6562
037e8744
JB
6563 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6564
c19d1205 6565 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6566 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6567 OP_RR_EXi, /* ARM register or expression with imm prefix */
6568 OP_RF_IF, /* FPA register or immediate */
6569 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6570 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6571
6572 /* Optional operands. */
6573 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6574 OP_oI31b, /* 0 .. 31 */
5287ad62 6575 OP_oI32b, /* 1 .. 32 */
5f1af56b 6576 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6577 OP_oIffffb, /* 0 .. 65535 */
6578 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6579
6580 OP_oRR, /* ARM register */
6581 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6582 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6583 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6584 OP_oRND, /* Optional Neon double precision register */
6585 OP_oRNQ, /* Optional Neon quad precision register */
6586 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6587 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6588 OP_oSHll, /* LSL immediate */
6589 OP_oSHar, /* ASR immediate */
6590 OP_oSHllar, /* LSL or ASR immediate */
6591 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6592 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6593
5be8be5d
DG
6594 /* Some pre-defined mixed (ARM/THUMB) operands. */
6595 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6596 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6597 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6598
c19d1205
ZW
6599 OP_FIRST_OPTIONAL = OP_oI7b
6600};
a737bd4d 6601
c19d1205
ZW
6602/* Generic instruction operand parser. This does no encoding and no
6603 semantic validation; it merely squirrels values away in the inst
6604 structure. Returns SUCCESS or FAIL depending on whether the
6605 specified grammar matched. */
6606static int
5be8be5d 6607parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6608{
5be8be5d 6609 unsigned const int *upat = pattern;
c19d1205
ZW
6610 char *backtrack_pos = 0;
6611 const char *backtrack_error = 0;
99aad254 6612 int i, val = 0, backtrack_index = 0;
5287ad62 6613 enum arm_reg_type rtype;
4962c51a 6614 parse_operand_result result;
5be8be5d 6615 unsigned int op_parse_code;
c19d1205 6616
e07e6e58
NC
6617#define po_char_or_fail(chr) \
6618 do \
6619 { \
6620 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6621 goto bad_args; \
e07e6e58
NC
6622 } \
6623 while (0)
c19d1205 6624
e07e6e58
NC
6625#define po_reg_or_fail(regtype) \
6626 do \
dcbf9037 6627 { \
e07e6e58 6628 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6629 & inst.operands[i].vectype); \
e07e6e58 6630 if (val == FAIL) \
477330fc
RM
6631 { \
6632 first_error (_(reg_expected_msgs[regtype])); \
6633 goto failure; \
6634 } \
e07e6e58
NC
6635 inst.operands[i].reg = val; \
6636 inst.operands[i].isreg = 1; \
6637 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6638 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6639 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6640 || rtype == REG_TYPE_VFD \
6641 || rtype == REG_TYPE_NQ); \
dcbf9037 6642 } \
e07e6e58
NC
6643 while (0)
6644
6645#define po_reg_or_goto(regtype, label) \
6646 do \
6647 { \
6648 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6649 & inst.operands[i].vectype); \
6650 if (val == FAIL) \
6651 goto label; \
dcbf9037 6652 \
e07e6e58
NC
6653 inst.operands[i].reg = val; \
6654 inst.operands[i].isreg = 1; \
6655 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6656 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6657 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6658 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6659 || rtype == REG_TYPE_NQ); \
6660 } \
6661 while (0)
6662
6663#define po_imm_or_fail(min, max, popt) \
6664 do \
6665 { \
6666 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6667 goto failure; \
6668 inst.operands[i].imm = val; \
6669 } \
6670 while (0)
6671
6672#define po_scalar_or_goto(elsz, label) \
6673 do \
6674 { \
6675 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6676 if (val == FAIL) \
6677 goto label; \
6678 inst.operands[i].reg = val; \
6679 inst.operands[i].isscalar = 1; \
6680 } \
6681 while (0)
6682
6683#define po_misc_or_fail(expr) \
6684 do \
6685 { \
6686 if (expr) \
6687 goto failure; \
6688 } \
6689 while (0)
6690
6691#define po_misc_or_fail_no_backtrack(expr) \
6692 do \
6693 { \
6694 result = expr; \
6695 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6696 backtrack_pos = 0; \
6697 if (result != PARSE_OPERAND_SUCCESS) \
6698 goto failure; \
6699 } \
6700 while (0)
4962c51a 6701
52e7f43d
RE
6702#define po_barrier_or_imm(str) \
6703 do \
6704 { \
6705 val = parse_barrier (&str); \
ccb84d65
JB
6706 if (val == FAIL && ! ISALPHA (*str)) \
6707 goto immediate; \
6708 if (val == FAIL \
6709 /* ISB can only take SY as an option. */ \
6710 || ((inst.instruction & 0xf0) == 0x60 \
6711 && val != 0xf)) \
52e7f43d 6712 { \
ccb84d65
JB
6713 inst.error = _("invalid barrier type"); \
6714 backtrack_pos = 0; \
6715 goto failure; \
52e7f43d
RE
6716 } \
6717 } \
6718 while (0)
6719
c19d1205
ZW
6720 skip_whitespace (str);
6721
6722 for (i = 0; upat[i] != OP_stop; i++)
6723 {
5be8be5d
DG
6724 op_parse_code = upat[i];
6725 if (op_parse_code >= 1<<16)
6726 op_parse_code = thumb ? (op_parse_code >> 16)
6727 : (op_parse_code & ((1<<16)-1));
6728
6729 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6730 {
6731 /* Remember where we are in case we need to backtrack. */
9c2799c2 6732 gas_assert (!backtrack_pos);
c19d1205
ZW
6733 backtrack_pos = str;
6734 backtrack_error = inst.error;
6735 backtrack_index = i;
6736 }
6737
b6702015 6738 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6739 po_char_or_fail (',');
6740
5be8be5d 6741 switch (op_parse_code)
c19d1205
ZW
6742 {
6743 /* Registers */
6744 case OP_oRRnpc:
5be8be5d 6745 case OP_oRRnpcsp:
c19d1205 6746 case OP_RRnpc:
5be8be5d 6747 case OP_RRnpcsp:
c19d1205
ZW
6748 case OP_oRR:
6749 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6750 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6751 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6752 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6753 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6754 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6755 case OP_oRND:
5287ad62 6756 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6757 case OP_RVC:
6758 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6759 break;
6760 /* Also accept generic coprocessor regs for unknown registers. */
6761 coproc_reg:
6762 po_reg_or_fail (REG_TYPE_CN);
6763 break;
c19d1205
ZW
6764 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6765 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6766 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6767 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6768 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6769 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6770 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6771 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6772 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6773 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6774 case OP_oRNQ:
5287ad62 6775 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6776 case OP_oRNDQ:
5287ad62 6777 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6778 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6779 case OP_oRNSDQ:
6780 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6781
6782 /* Neon scalar. Using an element size of 8 means that some invalid
6783 scalars are accepted here, so deal with those in later code. */
6784 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6785
6786 case OP_RNDQ_I0:
6787 {
6788 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6789 break;
6790 try_imm0:
6791 po_imm_or_fail (0, 0, TRUE);
6792 }
6793 break;
6794
6795 case OP_RVSD_I0:
6796 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6797 break;
6798
aacf0b33
KT
6799 case OP_RSVD_FI0:
6800 {
6801 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6802 break;
6803 try_ifimm0:
6804 if (parse_ifimm_zero (&str))
6805 inst.operands[i].imm = 0;
6806 else
6807 {
6808 inst.error
6809 = _("only floating point zero is allowed as immediate value");
6810 goto failure;
6811 }
6812 }
6813 break;
6814
477330fc
RM
6815 case OP_RR_RNSC:
6816 {
6817 po_scalar_or_goto (8, try_rr);
6818 break;
6819 try_rr:
6820 po_reg_or_fail (REG_TYPE_RN);
6821 }
6822 break;
6823
6824 case OP_RNSDQ_RNSC:
6825 {
6826 po_scalar_or_goto (8, try_nsdq);
6827 break;
6828 try_nsdq:
6829 po_reg_or_fail (REG_TYPE_NSDQ);
6830 }
6831 break;
6832
6833 case OP_RNDQ_RNSC:
6834 {
6835 po_scalar_or_goto (8, try_ndq);
6836 break;
6837 try_ndq:
6838 po_reg_or_fail (REG_TYPE_NDQ);
6839 }
6840 break;
6841
6842 case OP_RND_RNSC:
6843 {
6844 po_scalar_or_goto (8, try_vfd);
6845 break;
6846 try_vfd:
6847 po_reg_or_fail (REG_TYPE_VFD);
6848 }
6849 break;
6850
6851 case OP_VMOV:
6852 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6853 not careful then bad things might happen. */
6854 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6855 break;
6856
6857 case OP_RNDQ_Ibig:
6858 {
6859 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6860 break;
6861 try_immbig:
6862 /* There's a possibility of getting a 64-bit immediate here, so
6863 we need special handling. */
8335d6aa
JW
6864 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6865 == FAIL)
477330fc
RM
6866 {
6867 inst.error = _("immediate value is out of range");
6868 goto failure;
6869 }
6870 }
6871 break;
6872
6873 case OP_RNDQ_I63b:
6874 {
6875 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6876 break;
6877 try_shimm:
6878 po_imm_or_fail (0, 63, TRUE);
6879 }
6880 break;
c19d1205
ZW
6881
6882 case OP_RRnpcb:
6883 po_char_or_fail ('[');
6884 po_reg_or_fail (REG_TYPE_RN);
6885 po_char_or_fail (']');
6886 break;
a737bd4d 6887
55881a11 6888 case OP_RRnpctw:
c19d1205 6889 case OP_RRw:
b6702015 6890 case OP_oRRw:
c19d1205
ZW
6891 po_reg_or_fail (REG_TYPE_RN);
6892 if (skip_past_char (&str, '!') == SUCCESS)
6893 inst.operands[i].writeback = 1;
6894 break;
6895
6896 /* Immediates */
6897 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6898 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6899 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6900 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6901 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6902 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6903 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6904 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6905 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6906 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6907 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6908 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6909
6910 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6911 case OP_oI7b:
6912 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6913 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6914 case OP_oI31b:
6915 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6916 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6917 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6918 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6919
6920 /* Immediate variants */
6921 case OP_oI255c:
6922 po_char_or_fail ('{');
6923 po_imm_or_fail (0, 255, TRUE);
6924 po_char_or_fail ('}');
6925 break;
6926
6927 case OP_I31w:
6928 /* The expression parser chokes on a trailing !, so we have
6929 to find it first and zap it. */
6930 {
6931 char *s = str;
6932 while (*s && *s != ',')
6933 s++;
6934 if (s[-1] == '!')
6935 {
6936 s[-1] = '\0';
6937 inst.operands[i].writeback = 1;
6938 }
6939 po_imm_or_fail (0, 31, TRUE);
6940 if (str == s - 1)
6941 str = s;
6942 }
6943 break;
6944
6945 /* Expressions */
6946 case OP_EXPi: EXPi:
6947 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6948 GE_OPT_PREFIX));
6949 break;
6950
6951 case OP_EXP:
6952 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6953 GE_NO_PREFIX));
6954 break;
6955
6956 case OP_EXPr: EXPr:
6957 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6958 GE_NO_PREFIX));
6959 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6960 {
c19d1205
ZW
6961 val = parse_reloc (&str);
6962 if (val == -1)
6963 {
6964 inst.error = _("unrecognized relocation suffix");
6965 goto failure;
6966 }
6967 else if (val != BFD_RELOC_UNUSED)
6968 {
6969 inst.operands[i].imm = val;
6970 inst.operands[i].hasreloc = 1;
6971 }
a737bd4d 6972 }
c19d1205 6973 break;
a737bd4d 6974
b6895b4f
PB
6975 /* Operand for MOVW or MOVT. */
6976 case OP_HALF:
6977 po_misc_or_fail (parse_half (&str));
6978 break;
6979
e07e6e58 6980 /* Register or expression. */
c19d1205
ZW
6981 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6982 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6983
e07e6e58 6984 /* Register or immediate. */
c19d1205
ZW
6985 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6986 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6987
c19d1205
ZW
6988 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6989 IF:
6990 if (!is_immediate_prefix (*str))
6991 goto bad_args;
6992 str++;
6993 val = parse_fpa_immediate (&str);
6994 if (val == FAIL)
6995 goto failure;
6996 /* FPA immediates are encoded as registers 8-15.
6997 parse_fpa_immediate has already applied the offset. */
6998 inst.operands[i].reg = val;
6999 inst.operands[i].isreg = 1;
7000 break;
09d92015 7001
2d447fca
JM
7002 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7003 I32z: po_imm_or_fail (0, 32, FALSE); break;
7004
e07e6e58 7005 /* Two kinds of register. */
c19d1205
ZW
7006 case OP_RIWR_RIWC:
7007 {
7008 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7009 if (!rege
7010 || (rege->type != REG_TYPE_MMXWR
7011 && rege->type != REG_TYPE_MMXWC
7012 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7013 {
7014 inst.error = _("iWMMXt data or control register expected");
7015 goto failure;
7016 }
7017 inst.operands[i].reg = rege->number;
7018 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7019 }
7020 break;
09d92015 7021
41adaa5c
JM
7022 case OP_RIWC_RIWG:
7023 {
7024 struct reg_entry *rege = arm_reg_parse_multi (&str);
7025 if (!rege
7026 || (rege->type != REG_TYPE_MMXWC
7027 && rege->type != REG_TYPE_MMXWCG))
7028 {
7029 inst.error = _("iWMMXt control register expected");
7030 goto failure;
7031 }
7032 inst.operands[i].reg = rege->number;
7033 inst.operands[i].isreg = 1;
7034 }
7035 break;
7036
c19d1205
ZW
7037 /* Misc */
7038 case OP_CPSF: val = parse_cps_flags (&str); break;
7039 case OP_ENDI: val = parse_endian_specifier (&str); break;
7040 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7041 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7042 case OP_oBARRIER_I15:
7043 po_barrier_or_imm (str); break;
7044 immediate:
7045 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7046 goto failure;
52e7f43d 7047 break;
c19d1205 7048
fa94de6b 7049 case OP_wPSR:
d2cd1205 7050 case OP_rPSR:
90ec0d68
MGD
7051 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7052 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7053 {
7054 inst.error = _("Banked registers are not available with this "
7055 "architecture.");
7056 goto failure;
7057 }
7058 break;
d2cd1205
JB
7059 try_psr:
7060 val = parse_psr (&str, op_parse_code == OP_wPSR);
7061 break;
037e8744 7062
477330fc
RM
7063 case OP_APSR_RR:
7064 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7065 break;
7066 try_apsr:
7067 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7068 instruction). */
7069 if (strncasecmp (str, "APSR_", 5) == 0)
7070 {
7071 unsigned found = 0;
7072 str += 5;
7073 while (found < 15)
7074 switch (*str++)
7075 {
7076 case 'c': found = (found & 1) ? 16 : found | 1; break;
7077 case 'n': found = (found & 2) ? 16 : found | 2; break;
7078 case 'z': found = (found & 4) ? 16 : found | 4; break;
7079 case 'v': found = (found & 8) ? 16 : found | 8; break;
7080 default: found = 16;
7081 }
7082 if (found != 15)
7083 goto failure;
7084 inst.operands[i].isvec = 1;
f7c21dc7
NC
7085 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7086 inst.operands[i].reg = REG_PC;
477330fc
RM
7087 }
7088 else
7089 goto failure;
7090 break;
037e8744 7091
92e90b6e
PB
7092 case OP_TB:
7093 po_misc_or_fail (parse_tb (&str));
7094 break;
7095
e07e6e58 7096 /* Register lists. */
c19d1205
ZW
7097 case OP_REGLST:
7098 val = parse_reg_list (&str);
7099 if (*str == '^')
7100 {
5e0d7f77 7101 inst.operands[i].writeback = 1;
c19d1205
ZW
7102 str++;
7103 }
7104 break;
09d92015 7105
c19d1205 7106 case OP_VRSLST:
5287ad62 7107 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7108 break;
09d92015 7109
c19d1205 7110 case OP_VRDLST:
5287ad62 7111 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7112 break;
a737bd4d 7113
477330fc
RM
7114 case OP_VRSDLST:
7115 /* Allow Q registers too. */
7116 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7117 REGLIST_NEON_D);
7118 if (val == FAIL)
7119 {
7120 inst.error = NULL;
7121 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7122 REGLIST_VFP_S);
7123 inst.operands[i].issingle = 1;
7124 }
7125 break;
7126
7127 case OP_NRDLST:
7128 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7129 REGLIST_NEON_D);
7130 break;
5287ad62
JB
7131
7132 case OP_NSTRLST:
477330fc
RM
7133 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7134 &inst.operands[i].vectype);
7135 break;
5287ad62 7136
c19d1205
ZW
7137 /* Addressing modes */
7138 case OP_ADDR:
7139 po_misc_or_fail (parse_address (&str, i));
7140 break;
09d92015 7141
4962c51a
MS
7142 case OP_ADDRGLDR:
7143 po_misc_or_fail_no_backtrack (
477330fc 7144 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7145 break;
7146
7147 case OP_ADDRGLDRS:
7148 po_misc_or_fail_no_backtrack (
477330fc 7149 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7150 break;
7151
7152 case OP_ADDRGLDC:
7153 po_misc_or_fail_no_backtrack (
477330fc 7154 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7155 break;
7156
c19d1205
ZW
7157 case OP_SH:
7158 po_misc_or_fail (parse_shifter_operand (&str, i));
7159 break;
09d92015 7160
4962c51a
MS
7161 case OP_SHG:
7162 po_misc_or_fail_no_backtrack (
477330fc 7163 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7164 break;
7165
c19d1205
ZW
7166 case OP_oSHll:
7167 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7168 break;
09d92015 7169
c19d1205
ZW
7170 case OP_oSHar:
7171 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7172 break;
09d92015 7173
c19d1205
ZW
7174 case OP_oSHllar:
7175 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7176 break;
09d92015 7177
c19d1205 7178 default:
5be8be5d 7179 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7180 }
09d92015 7181
c19d1205
ZW
7182 /* Various value-based sanity checks and shared operations. We
7183 do not signal immediate failures for the register constraints;
7184 this allows a syntax error to take precedence. */
5be8be5d 7185 switch (op_parse_code)
c19d1205
ZW
7186 {
7187 case OP_oRRnpc:
7188 case OP_RRnpc:
7189 case OP_RRnpcb:
7190 case OP_RRw:
b6702015 7191 case OP_oRRw:
c19d1205
ZW
7192 case OP_RRnpc_I0:
7193 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7194 inst.error = BAD_PC;
7195 break;
09d92015 7196
5be8be5d
DG
7197 case OP_oRRnpcsp:
7198 case OP_RRnpcsp:
7199 if (inst.operands[i].isreg)
7200 {
7201 if (inst.operands[i].reg == REG_PC)
7202 inst.error = BAD_PC;
5c8ed6a4
JW
7203 else if (inst.operands[i].reg == REG_SP
7204 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7205 relaxed since ARMv8-A. */
7206 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7207 {
7208 gas_assert (thumb);
7209 inst.error = BAD_SP;
7210 }
5be8be5d
DG
7211 }
7212 break;
7213
55881a11 7214 case OP_RRnpctw:
fa94de6b
RM
7215 if (inst.operands[i].isreg
7216 && inst.operands[i].reg == REG_PC
55881a11
MGD
7217 && (inst.operands[i].writeback || thumb))
7218 inst.error = BAD_PC;
7219 break;
7220
c19d1205
ZW
7221 case OP_CPSF:
7222 case OP_ENDI:
7223 case OP_oROR:
d2cd1205
JB
7224 case OP_wPSR:
7225 case OP_rPSR:
c19d1205 7226 case OP_COND:
52e7f43d 7227 case OP_oBARRIER_I15:
c19d1205
ZW
7228 case OP_REGLST:
7229 case OP_VRSLST:
7230 case OP_VRDLST:
477330fc
RM
7231 case OP_VRSDLST:
7232 case OP_NRDLST:
7233 case OP_NSTRLST:
c19d1205
ZW
7234 if (val == FAIL)
7235 goto failure;
7236 inst.operands[i].imm = val;
7237 break;
a737bd4d 7238
c19d1205
ZW
7239 default:
7240 break;
7241 }
09d92015 7242
c19d1205
ZW
7243 /* If we get here, this operand was successfully parsed. */
7244 inst.operands[i].present = 1;
7245 continue;
09d92015 7246
c19d1205 7247 bad_args:
09d92015 7248 inst.error = BAD_ARGS;
c19d1205
ZW
7249
7250 failure:
7251 if (!backtrack_pos)
d252fdde
PB
7252 {
7253 /* The parse routine should already have set inst.error, but set a
5f4273c7 7254 default here just in case. */
d252fdde
PB
7255 if (!inst.error)
7256 inst.error = _("syntax error");
7257 return FAIL;
7258 }
c19d1205
ZW
7259
7260 /* Do not backtrack over a trailing optional argument that
7261 absorbed some text. We will only fail again, with the
7262 'garbage following instruction' error message, which is
7263 probably less helpful than the current one. */
7264 if (backtrack_index == i && backtrack_pos != str
7265 && upat[i+1] == OP_stop)
d252fdde
PB
7266 {
7267 if (!inst.error)
7268 inst.error = _("syntax error");
7269 return FAIL;
7270 }
c19d1205
ZW
7271
7272 /* Try again, skipping the optional argument at backtrack_pos. */
7273 str = backtrack_pos;
7274 inst.error = backtrack_error;
7275 inst.operands[backtrack_index].present = 0;
7276 i = backtrack_index;
7277 backtrack_pos = 0;
09d92015 7278 }
09d92015 7279
c19d1205
ZW
7280 /* Check that we have parsed all the arguments. */
7281 if (*str != '\0' && !inst.error)
7282 inst.error = _("garbage following instruction");
09d92015 7283
c19d1205 7284 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7285}
7286
c19d1205
ZW
7287#undef po_char_or_fail
7288#undef po_reg_or_fail
7289#undef po_reg_or_goto
7290#undef po_imm_or_fail
5287ad62 7291#undef po_scalar_or_fail
52e7f43d 7292#undef po_barrier_or_imm
e07e6e58 7293
c19d1205 7294/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7295#define constraint(expr, err) \
7296 do \
c19d1205 7297 { \
e07e6e58
NC
7298 if (expr) \
7299 { \
7300 inst.error = err; \
7301 return; \
7302 } \
c19d1205 7303 } \
e07e6e58 7304 while (0)
c19d1205 7305
fdfde340
JM
7306/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7307 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7308 is the BadReg predicate in ARM's Thumb-2 documentation.
7309
7310 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7311 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7312#define reject_bad_reg(reg) \
7313 do \
7314 if (reg == REG_PC) \
7315 { \
7316 inst.error = BAD_PC; \
7317 return; \
7318 } \
7319 else if (reg == REG_SP \
7320 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7321 { \
7322 inst.error = BAD_SP; \
7323 return; \
7324 } \
fdfde340
JM
7325 while (0)
7326
94206790
MM
7327/* If REG is R13 (the stack pointer), warn that its use is
7328 deprecated. */
7329#define warn_deprecated_sp(reg) \
7330 do \
7331 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7332 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7333 while (0)
7334
c19d1205
ZW
7335/* Functions for operand encoding. ARM, then Thumb. */
7336
d840c081 7337#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7338
9db2f6b4
RL
7339/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7340
7341 The only binary encoding difference is the Coprocessor number. Coprocessor
7342 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7343 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7344 exists for Single-Precision operation. */
7345
7346static void
7347do_scalar_fp16_v82_encode (void)
7348{
7349 if (inst.cond != COND_ALWAYS)
7350 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7351 " the behaviour is UNPREDICTABLE"));
7352 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7353 _(BAD_FP16));
7354
7355 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7356 mark_feature_used (&arm_ext_fp16);
7357}
7358
c19d1205
ZW
7359/* If VAL can be encoded in the immediate field of an ARM instruction,
7360 return the encoded form. Otherwise, return FAIL. */
7361
7362static unsigned int
7363encode_arm_immediate (unsigned int val)
09d92015 7364{
c19d1205
ZW
7365 unsigned int a, i;
7366
4f1d6205
L
7367 if (val <= 0xff)
7368 return val;
7369
7370 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7371 if ((a = rotate_left (val, i)) <= 0xff)
7372 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7373
7374 return FAIL;
09d92015
MM
7375}
7376
c19d1205
ZW
7377/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7378 return the encoded form. Otherwise, return FAIL. */
7379static unsigned int
7380encode_thumb32_immediate (unsigned int val)
09d92015 7381{
c19d1205 7382 unsigned int a, i;
09d92015 7383
9c3c69f2 7384 if (val <= 0xff)
c19d1205 7385 return val;
a737bd4d 7386
9c3c69f2 7387 for (i = 1; i <= 24; i++)
09d92015 7388 {
9c3c69f2
PB
7389 a = val >> i;
7390 if ((val & ~(0xff << i)) == 0)
7391 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7392 }
a737bd4d 7393
c19d1205
ZW
7394 a = val & 0xff;
7395 if (val == ((a << 16) | a))
7396 return 0x100 | a;
7397 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7398 return 0x300 | a;
09d92015 7399
c19d1205
ZW
7400 a = val & 0xff00;
7401 if (val == ((a << 16) | a))
7402 return 0x200 | (a >> 8);
a737bd4d 7403
c19d1205 7404 return FAIL;
09d92015 7405}
5287ad62 7406/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7407
7408static void
5287ad62
JB
7409encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7410{
7411 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7412 && reg > 15)
7413 {
b1cc4aeb 7414 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7415 {
7416 if (thumb_mode)
7417 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7418 fpu_vfp_ext_d32);
7419 else
7420 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7421 fpu_vfp_ext_d32);
7422 }
5287ad62 7423 else
477330fc
RM
7424 {
7425 first_error (_("D register out of range for selected VFP version"));
7426 return;
7427 }
5287ad62
JB
7428 }
7429
c19d1205 7430 switch (pos)
09d92015 7431 {
c19d1205
ZW
7432 case VFP_REG_Sd:
7433 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7434 break;
7435
7436 case VFP_REG_Sn:
7437 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7438 break;
7439
7440 case VFP_REG_Sm:
7441 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7442 break;
7443
5287ad62
JB
7444 case VFP_REG_Dd:
7445 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7446 break;
5f4273c7 7447
5287ad62
JB
7448 case VFP_REG_Dn:
7449 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7450 break;
5f4273c7 7451
5287ad62
JB
7452 case VFP_REG_Dm:
7453 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7454 break;
7455
c19d1205
ZW
7456 default:
7457 abort ();
09d92015 7458 }
09d92015
MM
7459}
7460
c19d1205 7461/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7462 if any, is handled by md_apply_fix. */
09d92015 7463static void
c19d1205 7464encode_arm_shift (int i)
09d92015 7465{
008a97ef
RL
7466 /* register-shifted register. */
7467 if (inst.operands[i].immisreg)
7468 {
bf355b69
MR
7469 int op_index;
7470 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7471 {
5689c942
RL
7472 /* Check the operand only when it's presented. In pre-UAL syntax,
7473 if the destination register is the same as the first operand, two
7474 register form of the instruction can be used. */
bf355b69
MR
7475 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7476 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7477 as_warn (UNPRED_REG ("r15"));
7478 }
7479
7480 if (inst.operands[i].imm == REG_PC)
7481 as_warn (UNPRED_REG ("r15"));
7482 }
7483
c19d1205
ZW
7484 if (inst.operands[i].shift_kind == SHIFT_RRX)
7485 inst.instruction |= SHIFT_ROR << 5;
7486 else
09d92015 7487 {
c19d1205
ZW
7488 inst.instruction |= inst.operands[i].shift_kind << 5;
7489 if (inst.operands[i].immisreg)
7490 {
7491 inst.instruction |= SHIFT_BY_REG;
7492 inst.instruction |= inst.operands[i].imm << 8;
7493 }
7494 else
7495 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7496 }
c19d1205 7497}
09d92015 7498
c19d1205
ZW
7499static void
7500encode_arm_shifter_operand (int i)
7501{
7502 if (inst.operands[i].isreg)
09d92015 7503 {
c19d1205
ZW
7504 inst.instruction |= inst.operands[i].reg;
7505 encode_arm_shift (i);
09d92015 7506 }
c19d1205 7507 else
a415b1cd
JB
7508 {
7509 inst.instruction |= INST_IMMEDIATE;
7510 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7511 inst.instruction |= inst.operands[i].imm;
7512 }
09d92015
MM
7513}
7514
c19d1205 7515/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7516static void
c19d1205 7517encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7518{
2b2f5df9
NC
7519 /* PR 14260:
7520 Generate an error if the operand is not a register. */
7521 constraint (!inst.operands[i].isreg,
7522 _("Instruction does not support =N addresses"));
7523
c19d1205 7524 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7525
c19d1205 7526 if (inst.operands[i].preind)
09d92015 7527 {
c19d1205
ZW
7528 if (is_t)
7529 {
7530 inst.error = _("instruction does not accept preindexed addressing");
7531 return;
7532 }
7533 inst.instruction |= PRE_INDEX;
7534 if (inst.operands[i].writeback)
7535 inst.instruction |= WRITE_BACK;
09d92015 7536
c19d1205
ZW
7537 }
7538 else if (inst.operands[i].postind)
7539 {
9c2799c2 7540 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7541 if (is_t)
7542 inst.instruction |= WRITE_BACK;
7543 }
7544 else /* unindexed - only for coprocessor */
09d92015 7545 {
c19d1205 7546 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7547 return;
7548 }
7549
c19d1205
ZW
7550 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7551 && (((inst.instruction & 0x000f0000) >> 16)
7552 == ((inst.instruction & 0x0000f000) >> 12)))
7553 as_warn ((inst.instruction & LOAD_BIT)
7554 ? _("destination register same as write-back base")
7555 : _("source register same as write-back base"));
09d92015
MM
7556}
7557
c19d1205
ZW
7558/* inst.operands[i] was set up by parse_address. Encode it into an
7559 ARM-format mode 2 load or store instruction. If is_t is true,
7560 reject forms that cannot be used with a T instruction (i.e. not
7561 post-indexed). */
a737bd4d 7562static void
c19d1205 7563encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7564{
5be8be5d
DG
7565 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7566
c19d1205 7567 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7568
c19d1205 7569 if (inst.operands[i].immisreg)
09d92015 7570 {
5be8be5d
DG
7571 constraint ((inst.operands[i].imm == REG_PC
7572 || (is_pc && inst.operands[i].writeback)),
7573 BAD_PC_ADDRESSING);
c19d1205
ZW
7574 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7575 inst.instruction |= inst.operands[i].imm;
7576 if (!inst.operands[i].negative)
7577 inst.instruction |= INDEX_UP;
7578 if (inst.operands[i].shifted)
7579 {
7580 if (inst.operands[i].shift_kind == SHIFT_RRX)
7581 inst.instruction |= SHIFT_ROR << 5;
7582 else
7583 {
7584 inst.instruction |= inst.operands[i].shift_kind << 5;
7585 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7586 }
7587 }
09d92015 7588 }
c19d1205 7589 else /* immediate offset in inst.reloc */
09d92015 7590 {
5be8be5d
DG
7591 if (is_pc && !inst.reloc.pc_rel)
7592 {
7593 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7594
7595 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7596 cannot use PC in addressing.
7597 PC cannot be used in writeback addressing, either. */
7598 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7599 BAD_PC_ADDRESSING);
23a10334 7600
dc5ec521 7601 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7602 if (warn_on_deprecated
7603 && !is_load
7604 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7605 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7606 }
7607
c19d1205 7608 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7609 {
7610 /* Prefer + for zero encoded value. */
7611 if (!inst.operands[i].negative)
7612 inst.instruction |= INDEX_UP;
7613 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7614 }
09d92015 7615 }
09d92015
MM
7616}
7617
c19d1205
ZW
7618/* inst.operands[i] was set up by parse_address. Encode it into an
7619 ARM-format mode 3 load or store instruction. Reject forms that
7620 cannot be used with such instructions. If is_t is true, reject
7621 forms that cannot be used with a T instruction (i.e. not
7622 post-indexed). */
7623static void
7624encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7625{
c19d1205 7626 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7627 {
c19d1205
ZW
7628 inst.error = _("instruction does not accept scaled register index");
7629 return;
09d92015 7630 }
a737bd4d 7631
c19d1205 7632 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7633
c19d1205
ZW
7634 if (inst.operands[i].immisreg)
7635 {
5be8be5d 7636 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7637 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7638 BAD_PC_ADDRESSING);
eb9f3f00
JB
7639 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7640 BAD_PC_WRITEBACK);
c19d1205
ZW
7641 inst.instruction |= inst.operands[i].imm;
7642 if (!inst.operands[i].negative)
7643 inst.instruction |= INDEX_UP;
7644 }
7645 else /* immediate offset in inst.reloc */
7646 {
5be8be5d
DG
7647 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7648 && inst.operands[i].writeback),
7649 BAD_PC_WRITEBACK);
c19d1205
ZW
7650 inst.instruction |= HWOFFSET_IMM;
7651 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7652 {
7653 /* Prefer + for zero encoded value. */
7654 if (!inst.operands[i].negative)
7655 inst.instruction |= INDEX_UP;
7656
7657 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7658 }
c19d1205 7659 }
a737bd4d
NC
7660}
7661
8335d6aa
JW
7662/* Write immediate bits [7:0] to the following locations:
7663
7664 |28/24|23 19|18 16|15 4|3 0|
7665 | 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|
7666
7667 This function is used by VMOV/VMVN/VORR/VBIC. */
7668
7669static void
7670neon_write_immbits (unsigned immbits)
7671{
7672 inst.instruction |= immbits & 0xf;
7673 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7674 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7675}
7676
7677/* Invert low-order SIZE bits of XHI:XLO. */
7678
7679static void
7680neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7681{
7682 unsigned immlo = xlo ? *xlo : 0;
7683 unsigned immhi = xhi ? *xhi : 0;
7684
7685 switch (size)
7686 {
7687 case 8:
7688 immlo = (~immlo) & 0xff;
7689 break;
7690
7691 case 16:
7692 immlo = (~immlo) & 0xffff;
7693 break;
7694
7695 case 64:
7696 immhi = (~immhi) & 0xffffffff;
7697 /* fall through. */
7698
7699 case 32:
7700 immlo = (~immlo) & 0xffffffff;
7701 break;
7702
7703 default:
7704 abort ();
7705 }
7706
7707 if (xlo)
7708 *xlo = immlo;
7709
7710 if (xhi)
7711 *xhi = immhi;
7712}
7713
7714/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7715 A, B, C, D. */
09d92015 7716
c19d1205 7717static int
8335d6aa 7718neon_bits_same_in_bytes (unsigned imm)
09d92015 7719{
8335d6aa
JW
7720 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7721 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7722 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7723 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7724}
a737bd4d 7725
8335d6aa 7726/* For immediate of above form, return 0bABCD. */
09d92015 7727
8335d6aa
JW
7728static unsigned
7729neon_squash_bits (unsigned imm)
7730{
7731 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7732 | ((imm & 0x01000000) >> 21);
7733}
7734
7735/* Compress quarter-float representation to 0b...000 abcdefgh. */
7736
7737static unsigned
7738neon_qfloat_bits (unsigned imm)
7739{
7740 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7741}
7742
7743/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7744 the instruction. *OP is passed as the initial value of the op field, and
7745 may be set to a different value depending on the constant (i.e.
7746 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7747 MVN). If the immediate looks like a repeated pattern then also
7748 try smaller element sizes. */
7749
7750static int
7751neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7752 unsigned *immbits, int *op, int size,
7753 enum neon_el_type type)
7754{
7755 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7756 float. */
7757 if (type == NT_float && !float_p)
7758 return FAIL;
7759
7760 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7761 {
8335d6aa
JW
7762 if (size != 32 || *op == 1)
7763 return FAIL;
7764 *immbits = neon_qfloat_bits (immlo);
7765 return 0xf;
7766 }
7767
7768 if (size == 64)
7769 {
7770 if (neon_bits_same_in_bytes (immhi)
7771 && neon_bits_same_in_bytes (immlo))
c19d1205 7772 {
8335d6aa
JW
7773 if (*op == 1)
7774 return FAIL;
7775 *immbits = (neon_squash_bits (immhi) << 4)
7776 | neon_squash_bits (immlo);
7777 *op = 1;
7778 return 0xe;
c19d1205 7779 }
a737bd4d 7780
8335d6aa
JW
7781 if (immhi != immlo)
7782 return FAIL;
7783 }
a737bd4d 7784
8335d6aa 7785 if (size >= 32)
09d92015 7786 {
8335d6aa 7787 if (immlo == (immlo & 0x000000ff))
c19d1205 7788 {
8335d6aa
JW
7789 *immbits = immlo;
7790 return 0x0;
c19d1205 7791 }
8335d6aa 7792 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7793 {
8335d6aa
JW
7794 *immbits = immlo >> 8;
7795 return 0x2;
c19d1205 7796 }
8335d6aa
JW
7797 else if (immlo == (immlo & 0x00ff0000))
7798 {
7799 *immbits = immlo >> 16;
7800 return 0x4;
7801 }
7802 else if (immlo == (immlo & 0xff000000))
7803 {
7804 *immbits = immlo >> 24;
7805 return 0x6;
7806 }
7807 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7808 {
7809 *immbits = (immlo >> 8) & 0xff;
7810 return 0xc;
7811 }
7812 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7813 {
7814 *immbits = (immlo >> 16) & 0xff;
7815 return 0xd;
7816 }
7817
7818 if ((immlo & 0xffff) != (immlo >> 16))
7819 return FAIL;
7820 immlo &= 0xffff;
09d92015 7821 }
a737bd4d 7822
8335d6aa 7823 if (size >= 16)
4962c51a 7824 {
8335d6aa
JW
7825 if (immlo == (immlo & 0x000000ff))
7826 {
7827 *immbits = immlo;
7828 return 0x8;
7829 }
7830 else if (immlo == (immlo & 0x0000ff00))
7831 {
7832 *immbits = immlo >> 8;
7833 return 0xa;
7834 }
7835
7836 if ((immlo & 0xff) != (immlo >> 8))
7837 return FAIL;
7838 immlo &= 0xff;
4962c51a
MS
7839 }
7840
8335d6aa
JW
7841 if (immlo == (immlo & 0x000000ff))
7842 {
7843 /* Don't allow MVN with 8-bit immediate. */
7844 if (*op == 1)
7845 return FAIL;
7846 *immbits = immlo;
7847 return 0xe;
7848 }
26d97720 7849
8335d6aa 7850 return FAIL;
c19d1205 7851}
a737bd4d 7852
5fc177c8 7853#if defined BFD_HOST_64_BIT
ba592044
AM
7854/* Returns TRUE if double precision value V may be cast
7855 to single precision without loss of accuracy. */
7856
7857static bfd_boolean
5fc177c8 7858is_double_a_single (bfd_int64_t v)
ba592044 7859{
5fc177c8 7860 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7861 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7862
7863 return (exp == 0 || exp == 0x7FF
7864 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7865 && (mantissa & 0x1FFFFFFFl) == 0;
7866}
7867
3739860c 7868/* Returns a double precision value casted to single precision
ba592044
AM
7869 (ignoring the least significant bits in exponent and mantissa). */
7870
7871static int
5fc177c8 7872double_to_single (bfd_int64_t v)
ba592044
AM
7873{
7874 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7875 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7876 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7877
7878 if (exp == 0x7FF)
7879 exp = 0xFF;
7880 else
7881 {
7882 exp = exp - 1023 + 127;
7883 if (exp >= 0xFF)
7884 {
7885 /* Infinity. */
7886 exp = 0x7F;
7887 mantissa = 0;
7888 }
7889 else if (exp < 0)
7890 {
7891 /* No denormalized numbers. */
7892 exp = 0;
7893 mantissa = 0;
7894 }
7895 }
7896 mantissa >>= 29;
7897 return (sign << 31) | (exp << 23) | mantissa;
7898}
5fc177c8 7899#endif /* BFD_HOST_64_BIT */
ba592044 7900
8335d6aa
JW
7901enum lit_type
7902{
7903 CONST_THUMB,
7904 CONST_ARM,
7905 CONST_VEC
7906};
7907
ba592044
AM
7908static void do_vfp_nsyn_opcode (const char *);
7909
c19d1205
ZW
7910/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7911 Determine whether it can be performed with a move instruction; if
7912 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7913 return TRUE; if it can't, convert inst.instruction to a literal-pool
7914 load and return FALSE. If this is not a valid thing to do in the
7915 current context, set inst.error and return TRUE.
a737bd4d 7916
c19d1205
ZW
7917 inst.operands[i] describes the destination register. */
7918
c921be7d 7919static bfd_boolean
8335d6aa 7920move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7921{
53365c0d 7922 unsigned long tbit;
8335d6aa
JW
7923 bfd_boolean thumb_p = (t == CONST_THUMB);
7924 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7925
7926 if (thumb_p)
7927 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7928 else
7929 tbit = LOAD_BIT;
7930
7931 if ((inst.instruction & tbit) == 0)
09d92015 7932 {
c19d1205 7933 inst.error = _("invalid pseudo operation");
c921be7d 7934 return TRUE;
09d92015 7935 }
ba592044 7936
8335d6aa
JW
7937 if (inst.reloc.exp.X_op != O_constant
7938 && inst.reloc.exp.X_op != O_symbol
7939 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7940 {
7941 inst.error = _("constant expression expected");
c921be7d 7942 return TRUE;
09d92015 7943 }
ba592044
AM
7944
7945 if (inst.reloc.exp.X_op == O_constant
7946 || inst.reloc.exp.X_op == O_big)
8335d6aa 7947 {
5fc177c8
NC
7948#if defined BFD_HOST_64_BIT
7949 bfd_int64_t v;
7950#else
ba592044 7951 offsetT v;
5fc177c8 7952#endif
ba592044 7953 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7954 {
ba592044
AM
7955 LITTLENUM_TYPE w[X_PRECISION];
7956 LITTLENUM_TYPE * l;
7957
7958 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7959 {
ba592044
AM
7960 gen_to_words (w, X_PRECISION, E_PRECISION);
7961 l = w;
7962 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7963 }
ba592044
AM
7964 else
7965 l = generic_bignum;
3739860c 7966
5fc177c8
NC
7967#if defined BFD_HOST_64_BIT
7968 v =
7969 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7970 << LITTLENUM_NUMBER_OF_BITS)
7971 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7972 << LITTLENUM_NUMBER_OF_BITS)
7973 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7974 << LITTLENUM_NUMBER_OF_BITS)
7975 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7976#else
ba592044
AM
7977 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7978 | (l[0] & LITTLENUM_MASK);
5fc177c8 7979#endif
8335d6aa 7980 }
ba592044
AM
7981 else
7982 v = inst.reloc.exp.X_add_number;
7983
7984 if (!inst.operands[i].issingle)
8335d6aa 7985 {
12569877 7986 if (thumb_p)
8335d6aa 7987 {
53445554
TP
7988 /* LDR should not use lead in a flag-setting instruction being
7989 chosen so we do not check whether movs can be used. */
12569877 7990
53445554 7991 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 7992 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
7993 && inst.operands[i].reg != 13
7994 && inst.operands[i].reg != 15)
12569877 7995 {
fc289b0a
TP
7996 /* Check if on thumb2 it can be done with a mov.w, mvn or
7997 movw instruction. */
12569877
AM
7998 unsigned int newimm;
7999 bfd_boolean isNegated;
8000
8001 newimm = encode_thumb32_immediate (v);
8002 if (newimm != (unsigned int) FAIL)
8003 isNegated = FALSE;
8004 else
8005 {
582cfe03 8006 newimm = encode_thumb32_immediate (~v);
12569877
AM
8007 if (newimm != (unsigned int) FAIL)
8008 isNegated = TRUE;
8009 }
8010
fc289b0a
TP
8011 /* The number can be loaded with a mov.w or mvn
8012 instruction. */
ff8646ee
TP
8013 if (newimm != (unsigned int) FAIL
8014 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8015 {
fc289b0a 8016 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8017 | (inst.operands[i].reg << 8));
fc289b0a 8018 /* Change to MOVN. */
582cfe03 8019 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8020 inst.instruction |= (newimm & 0x800) << 15;
8021 inst.instruction |= (newimm & 0x700) << 4;
8022 inst.instruction |= (newimm & 0x0ff);
8023 return TRUE;
8024 }
fc289b0a 8025 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8026 else if ((v & ~0xFFFF) == 0
8027 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8028 {
582cfe03 8029 int imm = v & 0xFFFF;
12569877 8030
582cfe03 8031 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8032 inst.instruction |= (inst.operands[i].reg << 8);
8033 inst.instruction |= (imm & 0xf000) << 4;
8034 inst.instruction |= (imm & 0x0800) << 15;
8035 inst.instruction |= (imm & 0x0700) << 4;
8036 inst.instruction |= (imm & 0x00ff);
8037 return TRUE;
8038 }
8039 }
8335d6aa 8040 }
12569877 8041 else if (arm_p)
ba592044
AM
8042 {
8043 int value = encode_arm_immediate (v);
12569877 8044
ba592044
AM
8045 if (value != FAIL)
8046 {
8047 /* This can be done with a mov instruction. */
8048 inst.instruction &= LITERAL_MASK;
8049 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8050 inst.instruction |= value & 0xfff;
8051 return TRUE;
8052 }
8335d6aa 8053
ba592044
AM
8054 value = encode_arm_immediate (~ v);
8055 if (value != FAIL)
8056 {
8057 /* This can be done with a mvn instruction. */
8058 inst.instruction &= LITERAL_MASK;
8059 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8060 inst.instruction |= value & 0xfff;
8061 return TRUE;
8062 }
8063 }
934c2632 8064 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8065 {
ba592044
AM
8066 int op = 0;
8067 unsigned immbits = 0;
8068 unsigned immlo = inst.operands[1].imm;
8069 unsigned immhi = inst.operands[1].regisimm
8070 ? inst.operands[1].reg
8071 : inst.reloc.exp.X_unsigned
8072 ? 0
8073 : ((bfd_int64_t)((int) immlo)) >> 32;
8074 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8075 &op, 64, NT_invtype);
8076
8077 if (cmode == FAIL)
8078 {
8079 neon_invert_size (&immlo, &immhi, 64);
8080 op = !op;
8081 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8082 &op, 64, NT_invtype);
8083 }
8084
8085 if (cmode != FAIL)
8086 {
8087 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8088 | (1 << 23)
8089 | (cmode << 8)
8090 | (op << 5)
8091 | (1 << 4);
8092
8093 /* Fill other bits in vmov encoding for both thumb and arm. */
8094 if (thumb_mode)
eff0bc54 8095 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8096 else
eff0bc54 8097 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8098 neon_write_immbits (immbits);
8099 return TRUE;
8100 }
8335d6aa
JW
8101 }
8102 }
8335d6aa 8103
ba592044
AM
8104 if (t == CONST_VEC)
8105 {
8106 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8107 if (inst.operands[i].issingle
8108 && is_quarter_float (inst.operands[1].imm)
8109 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8110 {
ba592044
AM
8111 inst.operands[1].imm =
8112 neon_qfloat_bits (v);
8113 do_vfp_nsyn_opcode ("fconsts");
8114 return TRUE;
8335d6aa 8115 }
5fc177c8
NC
8116
8117 /* If our host does not support a 64-bit type then we cannot perform
8118 the following optimization. This mean that there will be a
8119 discrepancy between the output produced by an assembler built for
8120 a 32-bit-only host and the output produced from a 64-bit host, but
8121 this cannot be helped. */
8122#if defined BFD_HOST_64_BIT
ba592044
AM
8123 else if (!inst.operands[1].issingle
8124 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8125 {
ba592044
AM
8126 if (is_double_a_single (v)
8127 && is_quarter_float (double_to_single (v)))
8128 {
8129 inst.operands[1].imm =
8130 neon_qfloat_bits (double_to_single (v));
8131 do_vfp_nsyn_opcode ("fconstd");
8132 return TRUE;
8133 }
8335d6aa 8134 }
5fc177c8 8135#endif
8335d6aa
JW
8136 }
8137 }
8138
8139 if (add_to_lit_pool ((!inst.operands[i].isvec
8140 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8141 return TRUE;
8142
8143 inst.operands[1].reg = REG_PC;
8144 inst.operands[1].isreg = 1;
8145 inst.operands[1].preind = 1;
8146 inst.reloc.pc_rel = 1;
8147 inst.reloc.type = (thumb_p
8148 ? BFD_RELOC_ARM_THUMB_OFFSET
8149 : (mode_3
8150 ? BFD_RELOC_ARM_HWLITERAL
8151 : BFD_RELOC_ARM_LITERAL));
8152 return FALSE;
8153}
8154
8155/* inst.operands[i] was set up by parse_address. Encode it into an
8156 ARM-format instruction. Reject all forms which cannot be encoded
8157 into a coprocessor load/store instruction. If wb_ok is false,
8158 reject use of writeback; if unind_ok is false, reject use of
8159 unindexed addressing. If reloc_override is not 0, use it instead
8160 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8161 (in which case it is preserved). */
8162
8163static int
8164encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8165{
8166 if (!inst.operands[i].isreg)
8167 {
99b2a2dd
NC
8168 /* PR 18256 */
8169 if (! inst.operands[0].isvec)
8170 {
8171 inst.error = _("invalid co-processor operand");
8172 return FAIL;
8173 }
8335d6aa
JW
8174 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8175 return SUCCESS;
8176 }
8177
8178 inst.instruction |= inst.operands[i].reg << 16;
8179
8180 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8181
8182 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8183 {
8184 gas_assert (!inst.operands[i].writeback);
8185 if (!unind_ok)
8186 {
8187 inst.error = _("instruction does not support unindexed addressing");
8188 return FAIL;
8189 }
8190 inst.instruction |= inst.operands[i].imm;
8191 inst.instruction |= INDEX_UP;
8192 return SUCCESS;
8193 }
8194
8195 if (inst.operands[i].preind)
8196 inst.instruction |= PRE_INDEX;
8197
8198 if (inst.operands[i].writeback)
09d92015 8199 {
8335d6aa 8200 if (inst.operands[i].reg == REG_PC)
c19d1205 8201 {
8335d6aa
JW
8202 inst.error = _("pc may not be used with write-back");
8203 return FAIL;
c19d1205 8204 }
8335d6aa 8205 if (!wb_ok)
c19d1205 8206 {
8335d6aa
JW
8207 inst.error = _("instruction does not support writeback");
8208 return FAIL;
c19d1205 8209 }
8335d6aa 8210 inst.instruction |= WRITE_BACK;
09d92015
MM
8211 }
8212
8335d6aa
JW
8213 if (reloc_override)
8214 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8215 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8216 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8217 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8218 {
8335d6aa
JW
8219 if (thumb_mode)
8220 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8221 else
8222 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8223 }
8335d6aa
JW
8224
8225 /* Prefer + for zero encoded value. */
8226 if (!inst.operands[i].negative)
8227 inst.instruction |= INDEX_UP;
8228
8229 return SUCCESS;
09d92015
MM
8230}
8231
5f4273c7 8232/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8233 First some generics; their names are taken from the conventional
8234 bit positions for register arguments in ARM format instructions. */
09d92015 8235
a737bd4d 8236static void
c19d1205 8237do_noargs (void)
09d92015 8238{
c19d1205 8239}
a737bd4d 8240
c19d1205
ZW
8241static void
8242do_rd (void)
8243{
8244 inst.instruction |= inst.operands[0].reg << 12;
8245}
a737bd4d 8246
16a1fa25
TP
8247static void
8248do_rn (void)
8249{
8250 inst.instruction |= inst.operands[0].reg << 16;
8251}
8252
c19d1205
ZW
8253static void
8254do_rd_rm (void)
8255{
8256 inst.instruction |= inst.operands[0].reg << 12;
8257 inst.instruction |= inst.operands[1].reg;
8258}
09d92015 8259
9eb6c0f1
MGD
8260static void
8261do_rm_rn (void)
8262{
8263 inst.instruction |= inst.operands[0].reg;
8264 inst.instruction |= inst.operands[1].reg << 16;
8265}
8266
c19d1205
ZW
8267static void
8268do_rd_rn (void)
8269{
8270 inst.instruction |= inst.operands[0].reg << 12;
8271 inst.instruction |= inst.operands[1].reg << 16;
8272}
a737bd4d 8273
c19d1205
ZW
8274static void
8275do_rn_rd (void)
8276{
8277 inst.instruction |= inst.operands[0].reg << 16;
8278 inst.instruction |= inst.operands[1].reg << 12;
8279}
09d92015 8280
4ed7ed8d
TP
8281static void
8282do_tt (void)
8283{
8284 inst.instruction |= inst.operands[0].reg << 8;
8285 inst.instruction |= inst.operands[1].reg << 16;
8286}
8287
59d09be6
MGD
8288static bfd_boolean
8289check_obsolete (const arm_feature_set *feature, const char *msg)
8290{
8291 if (ARM_CPU_IS_ANY (cpu_variant))
8292 {
5c3696f8 8293 as_tsktsk ("%s", msg);
59d09be6
MGD
8294 return TRUE;
8295 }
8296 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8297 {
8298 as_bad ("%s", msg);
8299 return TRUE;
8300 }
8301
8302 return FALSE;
8303}
8304
c19d1205
ZW
8305static void
8306do_rd_rm_rn (void)
8307{
9a64e435 8308 unsigned Rn = inst.operands[2].reg;
708587a4 8309 /* Enforce restrictions on SWP instruction. */
9a64e435 8310 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8311 {
8312 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8313 _("Rn must not overlap other operands"));
8314
59d09be6
MGD
8315 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8316 */
8317 if (!check_obsolete (&arm_ext_v8,
8318 _("swp{b} use is obsoleted for ARMv8 and later"))
8319 && warn_on_deprecated
8320 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8321 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8322 }
59d09be6 8323
c19d1205
ZW
8324 inst.instruction |= inst.operands[0].reg << 12;
8325 inst.instruction |= inst.operands[1].reg;
9a64e435 8326 inst.instruction |= Rn << 16;
c19d1205 8327}
09d92015 8328
c19d1205
ZW
8329static void
8330do_rd_rn_rm (void)
8331{
8332 inst.instruction |= inst.operands[0].reg << 12;
8333 inst.instruction |= inst.operands[1].reg << 16;
8334 inst.instruction |= inst.operands[2].reg;
8335}
a737bd4d 8336
c19d1205
ZW
8337static void
8338do_rm_rd_rn (void)
8339{
5be8be5d
DG
8340 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8341 constraint (((inst.reloc.exp.X_op != O_constant
8342 && inst.reloc.exp.X_op != O_illegal)
8343 || inst.reloc.exp.X_add_number != 0),
8344 BAD_ADDR_MODE);
c19d1205
ZW
8345 inst.instruction |= inst.operands[0].reg;
8346 inst.instruction |= inst.operands[1].reg << 12;
8347 inst.instruction |= inst.operands[2].reg << 16;
8348}
09d92015 8349
c19d1205
ZW
8350static void
8351do_imm0 (void)
8352{
8353 inst.instruction |= inst.operands[0].imm;
8354}
09d92015 8355
c19d1205
ZW
8356static void
8357do_rd_cpaddr (void)
8358{
8359 inst.instruction |= inst.operands[0].reg << 12;
8360 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8361}
a737bd4d 8362
c19d1205
ZW
8363/* ARM instructions, in alphabetical order by function name (except
8364 that wrapper functions appear immediately after the function they
8365 wrap). */
09d92015 8366
c19d1205
ZW
8367/* This is a pseudo-op of the form "adr rd, label" to be converted
8368 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8369
8370static void
c19d1205 8371do_adr (void)
09d92015 8372{
c19d1205 8373 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8374
c19d1205
ZW
8375 /* Frag hacking will turn this into a sub instruction if the offset turns
8376 out to be negative. */
8377 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8378 inst.reloc.pc_rel = 1;
2fc8bdac 8379 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8380
8381 if (inst.reloc.exp.X_op == O_symbol
8382 && inst.reloc.exp.X_add_symbol != NULL
8383 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8384 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8385 inst.reloc.exp.X_add_number += 1;
c19d1205 8386}
b99bd4ef 8387
c19d1205
ZW
8388/* This is a pseudo-op of the form "adrl rd, label" to be converted
8389 into a relative address of the form:
8390 add rd, pc, #low(label-.-8)"
8391 add rd, rd, #high(label-.-8)" */
b99bd4ef 8392
c19d1205
ZW
8393static void
8394do_adrl (void)
8395{
8396 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8397
c19d1205
ZW
8398 /* Frag hacking will turn this into a sub instruction if the offset turns
8399 out to be negative. */
8400 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8401 inst.reloc.pc_rel = 1;
8402 inst.size = INSN_SIZE * 2;
2fc8bdac 8403 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8404
8405 if (inst.reloc.exp.X_op == O_symbol
8406 && inst.reloc.exp.X_add_symbol != NULL
8407 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8408 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8409 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8410}
8411
b99bd4ef 8412static void
c19d1205 8413do_arit (void)
b99bd4ef 8414{
a9f02af8
MG
8415 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8416 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8417 THUMB1_RELOC_ONLY);
c19d1205
ZW
8418 if (!inst.operands[1].present)
8419 inst.operands[1].reg = inst.operands[0].reg;
8420 inst.instruction |= inst.operands[0].reg << 12;
8421 inst.instruction |= inst.operands[1].reg << 16;
8422 encode_arm_shifter_operand (2);
8423}
b99bd4ef 8424
62b3e311
PB
8425static void
8426do_barrier (void)
8427{
8428 if (inst.operands[0].present)
ccb84d65 8429 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8430 else
8431 inst.instruction |= 0xf;
8432}
8433
c19d1205
ZW
8434static void
8435do_bfc (void)
8436{
8437 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8438 constraint (msb > 32, _("bit-field extends past end of register"));
8439 /* The instruction encoding stores the LSB and MSB,
8440 not the LSB and width. */
8441 inst.instruction |= inst.operands[0].reg << 12;
8442 inst.instruction |= inst.operands[1].imm << 7;
8443 inst.instruction |= (msb - 1) << 16;
8444}
b99bd4ef 8445
c19d1205
ZW
8446static void
8447do_bfi (void)
8448{
8449 unsigned int msb;
b99bd4ef 8450
c19d1205
ZW
8451 /* #0 in second position is alternative syntax for bfc, which is
8452 the same instruction but with REG_PC in the Rm field. */
8453 if (!inst.operands[1].isreg)
8454 inst.operands[1].reg = REG_PC;
b99bd4ef 8455
c19d1205
ZW
8456 msb = inst.operands[2].imm + inst.operands[3].imm;
8457 constraint (msb > 32, _("bit-field extends past end of register"));
8458 /* The instruction encoding stores the LSB and MSB,
8459 not the LSB and width. */
8460 inst.instruction |= inst.operands[0].reg << 12;
8461 inst.instruction |= inst.operands[1].reg;
8462 inst.instruction |= inst.operands[2].imm << 7;
8463 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8464}
8465
b99bd4ef 8466static void
c19d1205 8467do_bfx (void)
b99bd4ef 8468{
c19d1205
ZW
8469 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8470 _("bit-field extends past end of register"));
8471 inst.instruction |= inst.operands[0].reg << 12;
8472 inst.instruction |= inst.operands[1].reg;
8473 inst.instruction |= inst.operands[2].imm << 7;
8474 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8475}
09d92015 8476
c19d1205
ZW
8477/* ARM V5 breakpoint instruction (argument parse)
8478 BKPT <16 bit unsigned immediate>
8479 Instruction is not conditional.
8480 The bit pattern given in insns[] has the COND_ALWAYS condition,
8481 and it is an error if the caller tried to override that. */
b99bd4ef 8482
c19d1205
ZW
8483static void
8484do_bkpt (void)
8485{
8486 /* Top 12 of 16 bits to bits 19:8. */
8487 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8488
c19d1205
ZW
8489 /* Bottom 4 of 16 bits to bits 3:0. */
8490 inst.instruction |= inst.operands[0].imm & 0xf;
8491}
09d92015 8492
c19d1205
ZW
8493static void
8494encode_branch (int default_reloc)
8495{
8496 if (inst.operands[0].hasreloc)
8497 {
0855e32b
NS
8498 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8499 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8500 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8501 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8502 ? BFD_RELOC_ARM_PLT32
8503 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8504 }
b99bd4ef 8505 else
9ae92b05 8506 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8507 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8508}
8509
b99bd4ef 8510static void
c19d1205 8511do_branch (void)
b99bd4ef 8512{
39b41c9c
PB
8513#ifdef OBJ_ELF
8514 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8515 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8516 else
8517#endif
8518 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8519}
8520
8521static void
8522do_bl (void)
8523{
8524#ifdef OBJ_ELF
8525 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8526 {
8527 if (inst.cond == COND_ALWAYS)
8528 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8529 else
8530 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8531 }
8532 else
8533#endif
8534 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8535}
b99bd4ef 8536
c19d1205
ZW
8537/* ARM V5 branch-link-exchange instruction (argument parse)
8538 BLX <target_addr> ie BLX(1)
8539 BLX{<condition>} <Rm> ie BLX(2)
8540 Unfortunately, there are two different opcodes for this mnemonic.
8541 So, the insns[].value is not used, and the code here zaps values
8542 into inst.instruction.
8543 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8544
c19d1205
ZW
8545static void
8546do_blx (void)
8547{
8548 if (inst.operands[0].isreg)
b99bd4ef 8549 {
c19d1205
ZW
8550 /* Arg is a register; the opcode provided by insns[] is correct.
8551 It is not illegal to do "blx pc", just useless. */
8552 if (inst.operands[0].reg == REG_PC)
8553 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8554
c19d1205
ZW
8555 inst.instruction |= inst.operands[0].reg;
8556 }
8557 else
b99bd4ef 8558 {
c19d1205 8559 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8560 conditionally, and the opcode must be adjusted.
8561 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8562 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8563 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8564 inst.instruction = 0xfa000000;
267bf995 8565 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8566 }
c19d1205
ZW
8567}
8568
8569static void
8570do_bx (void)
8571{
845b51d6
PB
8572 bfd_boolean want_reloc;
8573
c19d1205
ZW
8574 if (inst.operands[0].reg == REG_PC)
8575 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8576
c19d1205 8577 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8578 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8579 it is for ARMv4t or earlier. */
8580 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8581 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8582 want_reloc = TRUE;
8583
5ad34203 8584#ifdef OBJ_ELF
845b51d6 8585 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8586#endif
584206db 8587 want_reloc = FALSE;
845b51d6
PB
8588
8589 if (want_reloc)
8590 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8591}
8592
c19d1205
ZW
8593
8594/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8595
8596static void
c19d1205 8597do_bxj (void)
a737bd4d 8598{
c19d1205
ZW
8599 if (inst.operands[0].reg == REG_PC)
8600 as_tsktsk (_("use of r15 in bxj is not really useful"));
8601
8602 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8603}
8604
c19d1205
ZW
8605/* Co-processor data operation:
8606 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8607 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8608static void
8609do_cdp (void)
8610{
8611 inst.instruction |= inst.operands[0].reg << 8;
8612 inst.instruction |= inst.operands[1].imm << 20;
8613 inst.instruction |= inst.operands[2].reg << 12;
8614 inst.instruction |= inst.operands[3].reg << 16;
8615 inst.instruction |= inst.operands[4].reg;
8616 inst.instruction |= inst.operands[5].imm << 5;
8617}
a737bd4d
NC
8618
8619static void
c19d1205 8620do_cmp (void)
a737bd4d 8621{
c19d1205
ZW
8622 inst.instruction |= inst.operands[0].reg << 16;
8623 encode_arm_shifter_operand (1);
a737bd4d
NC
8624}
8625
c19d1205
ZW
8626/* Transfer between coprocessor and ARM registers.
8627 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8628 MRC2
8629 MCR{cond}
8630 MCR2
8631
8632 No special properties. */
09d92015 8633
dcbd0d71
MGD
8634struct deprecated_coproc_regs_s
8635{
8636 unsigned cp;
8637 int opc1;
8638 unsigned crn;
8639 unsigned crm;
8640 int opc2;
8641 arm_feature_set deprecated;
8642 arm_feature_set obsoleted;
8643 const char *dep_msg;
8644 const char *obs_msg;
8645};
8646
8647#define DEPR_ACCESS_V8 \
8648 N_("This coprocessor register access is deprecated in ARMv8")
8649
8650/* Table of all deprecated coprocessor registers. */
8651static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8652{
8653 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8654 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8655 DEPR_ACCESS_V8, NULL},
8656 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8657 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8658 DEPR_ACCESS_V8, NULL},
8659 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8660 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8661 DEPR_ACCESS_V8, NULL},
8662 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8663 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8664 DEPR_ACCESS_V8, NULL},
8665 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8666 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8667 DEPR_ACCESS_V8, NULL},
8668};
8669
8670#undef DEPR_ACCESS_V8
8671
8672static const size_t deprecated_coproc_reg_count =
8673 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8674
09d92015 8675static void
c19d1205 8676do_co_reg (void)
09d92015 8677{
fdfde340 8678 unsigned Rd;
dcbd0d71 8679 size_t i;
fdfde340
JM
8680
8681 Rd = inst.operands[2].reg;
8682 if (thumb_mode)
8683 {
8684 if (inst.instruction == 0xee000010
8685 || inst.instruction == 0xfe000010)
8686 /* MCR, MCR2 */
8687 reject_bad_reg (Rd);
5c8ed6a4 8688 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8689 /* MRC, MRC2 */
8690 constraint (Rd == REG_SP, BAD_SP);
8691 }
8692 else
8693 {
8694 /* MCR */
8695 if (inst.instruction == 0xe000010)
8696 constraint (Rd == REG_PC, BAD_PC);
8697 }
8698
dcbd0d71
MGD
8699 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8700 {
8701 const struct deprecated_coproc_regs_s *r =
8702 deprecated_coproc_regs + i;
8703
8704 if (inst.operands[0].reg == r->cp
8705 && inst.operands[1].imm == r->opc1
8706 && inst.operands[3].reg == r->crn
8707 && inst.operands[4].reg == r->crm
8708 && inst.operands[5].imm == r->opc2)
8709 {
b10bf8c5 8710 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8711 && warn_on_deprecated
dcbd0d71 8712 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8713 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8714 }
8715 }
fdfde340 8716
c19d1205
ZW
8717 inst.instruction |= inst.operands[0].reg << 8;
8718 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8719 inst.instruction |= Rd << 12;
c19d1205
ZW
8720 inst.instruction |= inst.operands[3].reg << 16;
8721 inst.instruction |= inst.operands[4].reg;
8722 inst.instruction |= inst.operands[5].imm << 5;
8723}
09d92015 8724
c19d1205
ZW
8725/* Transfer between coprocessor register and pair of ARM registers.
8726 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8727 MCRR2
8728 MRRC{cond}
8729 MRRC2
b99bd4ef 8730
c19d1205 8731 Two XScale instructions are special cases of these:
09d92015 8732
c19d1205
ZW
8733 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8734 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8735
5f4273c7 8736 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8737
c19d1205
ZW
8738static void
8739do_co_reg2c (void)
8740{
fdfde340
JM
8741 unsigned Rd, Rn;
8742
8743 Rd = inst.operands[2].reg;
8744 Rn = inst.operands[3].reg;
8745
8746 if (thumb_mode)
8747 {
8748 reject_bad_reg (Rd);
8749 reject_bad_reg (Rn);
8750 }
8751 else
8752 {
8753 constraint (Rd == REG_PC, BAD_PC);
8754 constraint (Rn == REG_PC, BAD_PC);
8755 }
8756
873f10f0
TC
8757 /* Only check the MRRC{2} variants. */
8758 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8759 {
8760 /* If Rd == Rn, error that the operation is
8761 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8762 constraint (Rd == Rn, BAD_OVERLAP);
8763 }
8764
c19d1205
ZW
8765 inst.instruction |= inst.operands[0].reg << 8;
8766 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8767 inst.instruction |= Rd << 12;
8768 inst.instruction |= Rn << 16;
c19d1205 8769 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8770}
8771
c19d1205
ZW
8772static void
8773do_cpsi (void)
8774{
8775 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8776 if (inst.operands[1].present)
8777 {
8778 inst.instruction |= CPSI_MMOD;
8779 inst.instruction |= inst.operands[1].imm;
8780 }
c19d1205 8781}
b99bd4ef 8782
62b3e311
PB
8783static void
8784do_dbg (void)
8785{
8786 inst.instruction |= inst.operands[0].imm;
8787}
8788
eea54501
MGD
8789static void
8790do_div (void)
8791{
8792 unsigned Rd, Rn, Rm;
8793
8794 Rd = inst.operands[0].reg;
8795 Rn = (inst.operands[1].present
8796 ? inst.operands[1].reg : Rd);
8797 Rm = inst.operands[2].reg;
8798
8799 constraint ((Rd == REG_PC), BAD_PC);
8800 constraint ((Rn == REG_PC), BAD_PC);
8801 constraint ((Rm == REG_PC), BAD_PC);
8802
8803 inst.instruction |= Rd << 16;
8804 inst.instruction |= Rn << 0;
8805 inst.instruction |= Rm << 8;
8806}
8807
b99bd4ef 8808static void
c19d1205 8809do_it (void)
b99bd4ef 8810{
c19d1205 8811 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8812 process it to do the validation as if in
8813 thumb mode, just in case the code gets
8814 assembled for thumb using the unified syntax. */
8815
c19d1205 8816 inst.size = 0;
e07e6e58
NC
8817 if (unified_syntax)
8818 {
8819 set_it_insn_type (IT_INSN);
8820 now_it.mask = (inst.instruction & 0xf) | 0x10;
8821 now_it.cc = inst.operands[0].imm;
8822 }
09d92015 8823}
b99bd4ef 8824
6530b175
NC
8825/* If there is only one register in the register list,
8826 then return its register number. Otherwise return -1. */
8827static int
8828only_one_reg_in_list (int range)
8829{
8830 int i = ffs (range) - 1;
8831 return (i > 15 || range != (1 << i)) ? -1 : i;
8832}
8833
09d92015 8834static void
6530b175 8835encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8836{
c19d1205
ZW
8837 int base_reg = inst.operands[0].reg;
8838 int range = inst.operands[1].imm;
6530b175 8839 int one_reg;
ea6ef066 8840
c19d1205
ZW
8841 inst.instruction |= base_reg << 16;
8842 inst.instruction |= range;
ea6ef066 8843
c19d1205
ZW
8844 if (inst.operands[1].writeback)
8845 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8846
c19d1205 8847 if (inst.operands[0].writeback)
ea6ef066 8848 {
c19d1205
ZW
8849 inst.instruction |= WRITE_BACK;
8850 /* Check for unpredictable uses of writeback. */
8851 if (inst.instruction & LOAD_BIT)
09d92015 8852 {
c19d1205
ZW
8853 /* Not allowed in LDM type 2. */
8854 if ((inst.instruction & LDM_TYPE_2_OR_3)
8855 && ((range & (1 << REG_PC)) == 0))
8856 as_warn (_("writeback of base register is UNPREDICTABLE"));
8857 /* Only allowed if base reg not in list for other types. */
8858 else if (range & (1 << base_reg))
8859 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8860 }
8861 else /* STM. */
8862 {
8863 /* Not allowed for type 2. */
8864 if (inst.instruction & LDM_TYPE_2_OR_3)
8865 as_warn (_("writeback of base register is UNPREDICTABLE"));
8866 /* Only allowed if base reg not in list, or first in list. */
8867 else if ((range & (1 << base_reg))
8868 && (range & ((1 << base_reg) - 1)))
8869 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8870 }
ea6ef066 8871 }
6530b175
NC
8872
8873 /* If PUSH/POP has only one register, then use the A2 encoding. */
8874 one_reg = only_one_reg_in_list (range);
8875 if (from_push_pop_mnem && one_reg >= 0)
8876 {
8877 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8878
8879 inst.instruction &= A_COND_MASK;
8880 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8881 inst.instruction |= one_reg << 12;
8882 }
8883}
8884
8885static void
8886do_ldmstm (void)
8887{
8888 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8889}
8890
c19d1205
ZW
8891/* ARMv5TE load-consecutive (argument parse)
8892 Mode is like LDRH.
8893
8894 LDRccD R, mode
8895 STRccD R, mode. */
8896
a737bd4d 8897static void
c19d1205 8898do_ldrd (void)
a737bd4d 8899{
c19d1205 8900 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8901 _("first transfer register must be even"));
c19d1205
ZW
8902 constraint (inst.operands[1].present
8903 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8904 _("can only transfer two consecutive registers"));
c19d1205
ZW
8905 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8906 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8907
c19d1205
ZW
8908 if (!inst.operands[1].present)
8909 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8910
c56791bb
RE
8911 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8912 register and the first register written; we have to diagnose
8913 overlap between the base and the second register written here. */
ea6ef066 8914
c56791bb
RE
8915 if (inst.operands[2].reg == inst.operands[1].reg
8916 && (inst.operands[2].writeback || inst.operands[2].postind))
8917 as_warn (_("base register written back, and overlaps "
8918 "second transfer register"));
b05fe5cf 8919
c56791bb
RE
8920 if (!(inst.instruction & V4_STR_BIT))
8921 {
c19d1205 8922 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8923 destination (even if not write-back). */
8924 if (inst.operands[2].immisreg
8925 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8926 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8927 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8928 }
c19d1205
ZW
8929 inst.instruction |= inst.operands[0].reg << 12;
8930 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8931}
8932
8933static void
c19d1205 8934do_ldrex (void)
b05fe5cf 8935{
c19d1205
ZW
8936 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8937 || inst.operands[1].postind || inst.operands[1].writeback
8938 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8939 || inst.operands[1].negative
8940 /* This can arise if the programmer has written
8941 strex rN, rM, foo
8942 or if they have mistakenly used a register name as the last
8943 operand, eg:
8944 strex rN, rM, rX
8945 It is very difficult to distinguish between these two cases
8946 because "rX" might actually be a label. ie the register
8947 name has been occluded by a symbol of the same name. So we
8948 just generate a general 'bad addressing mode' type error
8949 message and leave it up to the programmer to discover the
8950 true cause and fix their mistake. */
8951 || (inst.operands[1].reg == REG_PC),
8952 BAD_ADDR_MODE);
b05fe5cf 8953
c19d1205
ZW
8954 constraint (inst.reloc.exp.X_op != O_constant
8955 || inst.reloc.exp.X_add_number != 0,
8956 _("offset must be zero in ARM encoding"));
b05fe5cf 8957
5be8be5d
DG
8958 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8959
c19d1205
ZW
8960 inst.instruction |= inst.operands[0].reg << 12;
8961 inst.instruction |= inst.operands[1].reg << 16;
8962 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8963}
8964
8965static void
c19d1205 8966do_ldrexd (void)
b05fe5cf 8967{
c19d1205
ZW
8968 constraint (inst.operands[0].reg % 2 != 0,
8969 _("even register required"));
8970 constraint (inst.operands[1].present
8971 && inst.operands[1].reg != inst.operands[0].reg + 1,
8972 _("can only load two consecutive registers"));
8973 /* If op 1 were present and equal to PC, this function wouldn't
8974 have been called in the first place. */
8975 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8976
c19d1205
ZW
8977 inst.instruction |= inst.operands[0].reg << 12;
8978 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8979}
8980
1be5fd2e
NC
8981/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8982 which is not a multiple of four is UNPREDICTABLE. */
8983static void
8984check_ldr_r15_aligned (void)
8985{
8986 constraint (!(inst.operands[1].immisreg)
8987 && (inst.operands[0].reg == REG_PC
8988 && inst.operands[1].reg == REG_PC
8989 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 8990 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
8991}
8992
b05fe5cf 8993static void
c19d1205 8994do_ldst (void)
b05fe5cf 8995{
c19d1205
ZW
8996 inst.instruction |= inst.operands[0].reg << 12;
8997 if (!inst.operands[1].isreg)
8335d6aa 8998 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8999 return;
c19d1205 9000 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9001 check_ldr_r15_aligned ();
b05fe5cf
ZW
9002}
9003
9004static void
c19d1205 9005do_ldstt (void)
b05fe5cf 9006{
c19d1205
ZW
9007 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9008 reject [Rn,...]. */
9009 if (inst.operands[1].preind)
b05fe5cf 9010 {
bd3ba5d1
NC
9011 constraint (inst.reloc.exp.X_op != O_constant
9012 || inst.reloc.exp.X_add_number != 0,
c19d1205 9013 _("this instruction requires a post-indexed address"));
b05fe5cf 9014
c19d1205
ZW
9015 inst.operands[1].preind = 0;
9016 inst.operands[1].postind = 1;
9017 inst.operands[1].writeback = 1;
b05fe5cf 9018 }
c19d1205
ZW
9019 inst.instruction |= inst.operands[0].reg << 12;
9020 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9021}
b05fe5cf 9022
c19d1205 9023/* Halfword and signed-byte load/store operations. */
b05fe5cf 9024
c19d1205
ZW
9025static void
9026do_ldstv4 (void)
9027{
ff4a8d2b 9028 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9029 inst.instruction |= inst.operands[0].reg << 12;
9030 if (!inst.operands[1].isreg)
8335d6aa 9031 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9032 return;
c19d1205 9033 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9034}
9035
9036static void
c19d1205 9037do_ldsttv4 (void)
b05fe5cf 9038{
c19d1205
ZW
9039 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9040 reject [Rn,...]. */
9041 if (inst.operands[1].preind)
b05fe5cf 9042 {
bd3ba5d1
NC
9043 constraint (inst.reloc.exp.X_op != O_constant
9044 || inst.reloc.exp.X_add_number != 0,
c19d1205 9045 _("this instruction requires a post-indexed address"));
b05fe5cf 9046
c19d1205
ZW
9047 inst.operands[1].preind = 0;
9048 inst.operands[1].postind = 1;
9049 inst.operands[1].writeback = 1;
b05fe5cf 9050 }
c19d1205
ZW
9051 inst.instruction |= inst.operands[0].reg << 12;
9052 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9053}
b05fe5cf 9054
c19d1205
ZW
9055/* Co-processor register load/store.
9056 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9057static void
9058do_lstc (void)
9059{
9060 inst.instruction |= inst.operands[0].reg << 8;
9061 inst.instruction |= inst.operands[1].reg << 12;
9062 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9063}
9064
b05fe5cf 9065static void
c19d1205 9066do_mlas (void)
b05fe5cf 9067{
8fb9d7b9 9068 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9069 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9070 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9071 && !(inst.instruction & 0x00400000))
8fb9d7b9 9072 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9073
c19d1205
ZW
9074 inst.instruction |= inst.operands[0].reg << 16;
9075 inst.instruction |= inst.operands[1].reg;
9076 inst.instruction |= inst.operands[2].reg << 8;
9077 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9078}
b05fe5cf 9079
c19d1205
ZW
9080static void
9081do_mov (void)
9082{
a9f02af8
MG
9083 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9084 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9085 THUMB1_RELOC_ONLY);
c19d1205
ZW
9086 inst.instruction |= inst.operands[0].reg << 12;
9087 encode_arm_shifter_operand (1);
9088}
b05fe5cf 9089
c19d1205
ZW
9090/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9091static void
9092do_mov16 (void)
9093{
b6895b4f
PB
9094 bfd_vma imm;
9095 bfd_boolean top;
9096
9097 top = (inst.instruction & 0x00400000) != 0;
9098 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9099 _(":lower16: not allowed in this instruction"));
b6895b4f 9100 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9101 _(":upper16: not allowed in this instruction"));
c19d1205 9102 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9103 if (inst.reloc.type == BFD_RELOC_UNUSED)
9104 {
9105 imm = inst.reloc.exp.X_add_number;
9106 /* The value is in two pieces: 0:11, 16:19. */
9107 inst.instruction |= (imm & 0x00000fff);
9108 inst.instruction |= (imm & 0x0000f000) << 4;
9109 }
b05fe5cf 9110}
b99bd4ef 9111
037e8744
JB
9112static int
9113do_vfp_nsyn_mrs (void)
9114{
9115 if (inst.operands[0].isvec)
9116 {
9117 if (inst.operands[1].reg != 1)
477330fc 9118 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9119 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9120 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9121 do_vfp_nsyn_opcode ("fmstat");
9122 }
9123 else if (inst.operands[1].isvec)
9124 do_vfp_nsyn_opcode ("fmrx");
9125 else
9126 return FAIL;
5f4273c7 9127
037e8744
JB
9128 return SUCCESS;
9129}
9130
9131static int
9132do_vfp_nsyn_msr (void)
9133{
9134 if (inst.operands[0].isvec)
9135 do_vfp_nsyn_opcode ("fmxr");
9136 else
9137 return FAIL;
9138
9139 return SUCCESS;
9140}
9141
f7c21dc7
NC
9142static void
9143do_vmrs (void)
9144{
9145 unsigned Rt = inst.operands[0].reg;
fa94de6b 9146
16d02dc9 9147 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9148 {
9149 inst.error = BAD_SP;
9150 return;
9151 }
9152
40c7d507
RR
9153 /* MVFR2 is only valid at ARMv8-A. */
9154 if (inst.operands[1].reg == 5)
9155 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9156 _(BAD_FPU));
9157
f7c21dc7 9158 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9159 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9160 {
9161 inst.error = BAD_PC;
9162 return;
9163 }
9164
16d02dc9
JB
9165 /* If we get through parsing the register name, we just insert the number
9166 generated into the instruction without further validation. */
9167 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9168 inst.instruction |= (Rt << 12);
9169}
9170
9171static void
9172do_vmsr (void)
9173{
9174 unsigned Rt = inst.operands[1].reg;
fa94de6b 9175
f7c21dc7
NC
9176 if (thumb_mode)
9177 reject_bad_reg (Rt);
9178 else if (Rt == REG_PC)
9179 {
9180 inst.error = BAD_PC;
9181 return;
9182 }
9183
40c7d507
RR
9184 /* MVFR2 is only valid for ARMv8-A. */
9185 if (inst.operands[0].reg == 5)
9186 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9187 _(BAD_FPU));
9188
16d02dc9
JB
9189 /* If we get through parsing the register name, we just insert the number
9190 generated into the instruction without further validation. */
9191 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9192 inst.instruction |= (Rt << 12);
9193}
9194
b99bd4ef 9195static void
c19d1205 9196do_mrs (void)
b99bd4ef 9197{
90ec0d68
MGD
9198 unsigned br;
9199
037e8744
JB
9200 if (do_vfp_nsyn_mrs () == SUCCESS)
9201 return;
9202
ff4a8d2b 9203 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9204 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9205
9206 if (inst.operands[1].isreg)
9207 {
9208 br = inst.operands[1].reg;
9209 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9210 as_bad (_("bad register for mrs"));
9211 }
9212 else
9213 {
9214 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9215 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9216 != (PSR_c|PSR_f),
d2cd1205 9217 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9218 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9219 }
9220
9221 inst.instruction |= br;
c19d1205 9222}
b99bd4ef 9223
c19d1205
ZW
9224/* Two possible forms:
9225 "{C|S}PSR_<field>, Rm",
9226 "{C|S}PSR_f, #expression". */
b99bd4ef 9227
c19d1205
ZW
9228static void
9229do_msr (void)
9230{
037e8744
JB
9231 if (do_vfp_nsyn_msr () == SUCCESS)
9232 return;
9233
c19d1205
ZW
9234 inst.instruction |= inst.operands[0].imm;
9235 if (inst.operands[1].isreg)
9236 inst.instruction |= inst.operands[1].reg;
9237 else
b99bd4ef 9238 {
c19d1205
ZW
9239 inst.instruction |= INST_IMMEDIATE;
9240 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9241 inst.reloc.pc_rel = 0;
b99bd4ef 9242 }
b99bd4ef
NC
9243}
9244
c19d1205
ZW
9245static void
9246do_mul (void)
a737bd4d 9247{
ff4a8d2b
NC
9248 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9249
c19d1205
ZW
9250 if (!inst.operands[2].present)
9251 inst.operands[2].reg = inst.operands[0].reg;
9252 inst.instruction |= inst.operands[0].reg << 16;
9253 inst.instruction |= inst.operands[1].reg;
9254 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9255
8fb9d7b9
MS
9256 if (inst.operands[0].reg == inst.operands[1].reg
9257 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9258 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9259}
9260
c19d1205
ZW
9261/* Long Multiply Parser
9262 UMULL RdLo, RdHi, Rm, Rs
9263 SMULL RdLo, RdHi, Rm, Rs
9264 UMLAL RdLo, RdHi, Rm, Rs
9265 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9266
9267static void
c19d1205 9268do_mull (void)
b99bd4ef 9269{
c19d1205
ZW
9270 inst.instruction |= inst.operands[0].reg << 12;
9271 inst.instruction |= inst.operands[1].reg << 16;
9272 inst.instruction |= inst.operands[2].reg;
9273 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9274
682b27ad
PB
9275 /* rdhi and rdlo must be different. */
9276 if (inst.operands[0].reg == inst.operands[1].reg)
9277 as_tsktsk (_("rdhi and rdlo must be different"));
9278
9279 /* rdhi, rdlo and rm must all be different before armv6. */
9280 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9281 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9282 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9283 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9284}
b99bd4ef 9285
c19d1205
ZW
9286static void
9287do_nop (void)
9288{
e7495e45
NS
9289 if (inst.operands[0].present
9290 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9291 {
9292 /* Architectural NOP hints are CPSR sets with no bits selected. */
9293 inst.instruction &= 0xf0000000;
e7495e45
NS
9294 inst.instruction |= 0x0320f000;
9295 if (inst.operands[0].present)
9296 inst.instruction |= inst.operands[0].imm;
c19d1205 9297 }
b99bd4ef
NC
9298}
9299
c19d1205
ZW
9300/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9301 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9302 Condition defaults to COND_ALWAYS.
9303 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9304
9305static void
c19d1205 9306do_pkhbt (void)
b99bd4ef 9307{
c19d1205
ZW
9308 inst.instruction |= inst.operands[0].reg << 12;
9309 inst.instruction |= inst.operands[1].reg << 16;
9310 inst.instruction |= inst.operands[2].reg;
9311 if (inst.operands[3].present)
9312 encode_arm_shift (3);
9313}
b99bd4ef 9314
c19d1205 9315/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9316
c19d1205
ZW
9317static void
9318do_pkhtb (void)
9319{
9320 if (!inst.operands[3].present)
b99bd4ef 9321 {
c19d1205
ZW
9322 /* If the shift specifier is omitted, turn the instruction
9323 into pkhbt rd, rm, rn. */
9324 inst.instruction &= 0xfff00010;
9325 inst.instruction |= inst.operands[0].reg << 12;
9326 inst.instruction |= inst.operands[1].reg;
9327 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9328 }
9329 else
9330 {
c19d1205
ZW
9331 inst.instruction |= inst.operands[0].reg << 12;
9332 inst.instruction |= inst.operands[1].reg << 16;
9333 inst.instruction |= inst.operands[2].reg;
9334 encode_arm_shift (3);
b99bd4ef
NC
9335 }
9336}
9337
c19d1205 9338/* ARMv5TE: Preload-Cache
60e5ef9f 9339 MP Extensions: Preload for write
c19d1205 9340
60e5ef9f 9341 PLD(W) <addr_mode>
c19d1205
ZW
9342
9343 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9344
9345static void
c19d1205 9346do_pld (void)
b99bd4ef 9347{
c19d1205
ZW
9348 constraint (!inst.operands[0].isreg,
9349 _("'[' expected after PLD mnemonic"));
9350 constraint (inst.operands[0].postind,
9351 _("post-indexed expression used in preload instruction"));
9352 constraint (inst.operands[0].writeback,
9353 _("writeback used in preload instruction"));
9354 constraint (!inst.operands[0].preind,
9355 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9356 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9357}
b99bd4ef 9358
62b3e311
PB
9359/* ARMv7: PLI <addr_mode> */
9360static void
9361do_pli (void)
9362{
9363 constraint (!inst.operands[0].isreg,
9364 _("'[' expected after PLI mnemonic"));
9365 constraint (inst.operands[0].postind,
9366 _("post-indexed expression used in preload instruction"));
9367 constraint (inst.operands[0].writeback,
9368 _("writeback used in preload instruction"));
9369 constraint (!inst.operands[0].preind,
9370 _("unindexed addressing used in preload instruction"));
9371 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9372 inst.instruction &= ~PRE_INDEX;
9373}
9374
c19d1205
ZW
9375static void
9376do_push_pop (void)
9377{
5e0d7f77
MP
9378 constraint (inst.operands[0].writeback,
9379 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9380 inst.operands[1] = inst.operands[0];
9381 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9382 inst.operands[0].isreg = 1;
9383 inst.operands[0].writeback = 1;
9384 inst.operands[0].reg = REG_SP;
6530b175 9385 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9386}
b99bd4ef 9387
c19d1205
ZW
9388/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9389 word at the specified address and the following word
9390 respectively.
9391 Unconditionally executed.
9392 Error if Rn is R15. */
b99bd4ef 9393
c19d1205
ZW
9394static void
9395do_rfe (void)
9396{
9397 inst.instruction |= inst.operands[0].reg << 16;
9398 if (inst.operands[0].writeback)
9399 inst.instruction |= WRITE_BACK;
9400}
b99bd4ef 9401
c19d1205 9402/* ARM V6 ssat (argument parse). */
b99bd4ef 9403
c19d1205
ZW
9404static void
9405do_ssat (void)
9406{
9407 inst.instruction |= inst.operands[0].reg << 12;
9408 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9409 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9410
c19d1205
ZW
9411 if (inst.operands[3].present)
9412 encode_arm_shift (3);
b99bd4ef
NC
9413}
9414
c19d1205 9415/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9416
9417static void
c19d1205 9418do_usat (void)
b99bd4ef 9419{
c19d1205
ZW
9420 inst.instruction |= inst.operands[0].reg << 12;
9421 inst.instruction |= inst.operands[1].imm << 16;
9422 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9423
c19d1205
ZW
9424 if (inst.operands[3].present)
9425 encode_arm_shift (3);
b99bd4ef
NC
9426}
9427
c19d1205 9428/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9429
9430static void
c19d1205 9431do_ssat16 (void)
09d92015 9432{
c19d1205
ZW
9433 inst.instruction |= inst.operands[0].reg << 12;
9434 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9435 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9436}
9437
c19d1205
ZW
9438static void
9439do_usat16 (void)
a737bd4d 9440{
c19d1205
ZW
9441 inst.instruction |= inst.operands[0].reg << 12;
9442 inst.instruction |= inst.operands[1].imm << 16;
9443 inst.instruction |= inst.operands[2].reg;
9444}
a737bd4d 9445
c19d1205
ZW
9446/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9447 preserving the other bits.
a737bd4d 9448
c19d1205
ZW
9449 setend <endian_specifier>, where <endian_specifier> is either
9450 BE or LE. */
a737bd4d 9451
c19d1205
ZW
9452static void
9453do_setend (void)
9454{
12e37cbc
MGD
9455 if (warn_on_deprecated
9456 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9457 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9458
c19d1205
ZW
9459 if (inst.operands[0].imm)
9460 inst.instruction |= 0x200;
a737bd4d
NC
9461}
9462
9463static void
c19d1205 9464do_shift (void)
a737bd4d 9465{
c19d1205
ZW
9466 unsigned int Rm = (inst.operands[1].present
9467 ? inst.operands[1].reg
9468 : inst.operands[0].reg);
a737bd4d 9469
c19d1205
ZW
9470 inst.instruction |= inst.operands[0].reg << 12;
9471 inst.instruction |= Rm;
9472 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9473 {
c19d1205
ZW
9474 inst.instruction |= inst.operands[2].reg << 8;
9475 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9476 /* PR 12854: Error on extraneous shifts. */
9477 constraint (inst.operands[2].shifted,
9478 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9479 }
9480 else
c19d1205 9481 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9482}
9483
09d92015 9484static void
3eb17e6b 9485do_smc (void)
09d92015 9486{
3eb17e6b 9487 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9488 inst.reloc.pc_rel = 0;
09d92015
MM
9489}
9490
90ec0d68
MGD
9491static void
9492do_hvc (void)
9493{
9494 inst.reloc.type = BFD_RELOC_ARM_HVC;
9495 inst.reloc.pc_rel = 0;
9496}
9497
09d92015 9498static void
c19d1205 9499do_swi (void)
09d92015 9500{
c19d1205
ZW
9501 inst.reloc.type = BFD_RELOC_ARM_SWI;
9502 inst.reloc.pc_rel = 0;
09d92015
MM
9503}
9504
ddfded2f
MW
9505static void
9506do_setpan (void)
9507{
9508 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9509 _("selected processor does not support SETPAN instruction"));
9510
9511 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9512}
9513
9514static void
9515do_t_setpan (void)
9516{
9517 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9518 _("selected processor does not support SETPAN instruction"));
9519
9520 inst.instruction |= (inst.operands[0].imm << 3);
9521}
9522
c19d1205
ZW
9523/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9524 SMLAxy{cond} Rd,Rm,Rs,Rn
9525 SMLAWy{cond} Rd,Rm,Rs,Rn
9526 Error if any register is R15. */
e16bb312 9527
c19d1205
ZW
9528static void
9529do_smla (void)
e16bb312 9530{
c19d1205
ZW
9531 inst.instruction |= inst.operands[0].reg << 16;
9532 inst.instruction |= inst.operands[1].reg;
9533 inst.instruction |= inst.operands[2].reg << 8;
9534 inst.instruction |= inst.operands[3].reg << 12;
9535}
a737bd4d 9536
c19d1205
ZW
9537/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9538 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9539 Error if any register is R15.
9540 Warning if Rdlo == Rdhi. */
a737bd4d 9541
c19d1205
ZW
9542static void
9543do_smlal (void)
9544{
9545 inst.instruction |= inst.operands[0].reg << 12;
9546 inst.instruction |= inst.operands[1].reg << 16;
9547 inst.instruction |= inst.operands[2].reg;
9548 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9549
c19d1205
ZW
9550 if (inst.operands[0].reg == inst.operands[1].reg)
9551 as_tsktsk (_("rdhi and rdlo must be different"));
9552}
a737bd4d 9553
c19d1205
ZW
9554/* ARM V5E (El Segundo) signed-multiply (argument parse)
9555 SMULxy{cond} Rd,Rm,Rs
9556 Error if any register is R15. */
a737bd4d 9557
c19d1205
ZW
9558static void
9559do_smul (void)
9560{
9561 inst.instruction |= inst.operands[0].reg << 16;
9562 inst.instruction |= inst.operands[1].reg;
9563 inst.instruction |= inst.operands[2].reg << 8;
9564}
a737bd4d 9565
b6702015
PB
9566/* ARM V6 srs (argument parse). The variable fields in the encoding are
9567 the same for both ARM and Thumb-2. */
a737bd4d 9568
c19d1205
ZW
9569static void
9570do_srs (void)
9571{
b6702015
PB
9572 int reg;
9573
9574 if (inst.operands[0].present)
9575 {
9576 reg = inst.operands[0].reg;
fdfde340 9577 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9578 }
9579 else
fdfde340 9580 reg = REG_SP;
b6702015
PB
9581
9582 inst.instruction |= reg << 16;
9583 inst.instruction |= inst.operands[1].imm;
9584 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9585 inst.instruction |= WRITE_BACK;
9586}
a737bd4d 9587
c19d1205 9588/* ARM V6 strex (argument parse). */
a737bd4d 9589
c19d1205
ZW
9590static void
9591do_strex (void)
9592{
9593 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9594 || inst.operands[2].postind || inst.operands[2].writeback
9595 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9596 || inst.operands[2].negative
9597 /* See comment in do_ldrex(). */
9598 || (inst.operands[2].reg == REG_PC),
9599 BAD_ADDR_MODE);
a737bd4d 9600
c19d1205
ZW
9601 constraint (inst.operands[0].reg == inst.operands[1].reg
9602 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9603
c19d1205
ZW
9604 constraint (inst.reloc.exp.X_op != O_constant
9605 || inst.reloc.exp.X_add_number != 0,
9606 _("offset must be zero in ARM encoding"));
a737bd4d 9607
c19d1205
ZW
9608 inst.instruction |= inst.operands[0].reg << 12;
9609 inst.instruction |= inst.operands[1].reg;
9610 inst.instruction |= inst.operands[2].reg << 16;
9611 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9612}
9613
877807f8
NC
9614static void
9615do_t_strexbh (void)
9616{
9617 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9618 || inst.operands[2].postind || inst.operands[2].writeback
9619 || inst.operands[2].immisreg || inst.operands[2].shifted
9620 || inst.operands[2].negative,
9621 BAD_ADDR_MODE);
9622
9623 constraint (inst.operands[0].reg == inst.operands[1].reg
9624 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9625
9626 do_rm_rd_rn ();
9627}
9628
e16bb312 9629static void
c19d1205 9630do_strexd (void)
e16bb312 9631{
c19d1205
ZW
9632 constraint (inst.operands[1].reg % 2 != 0,
9633 _("even register required"));
9634 constraint (inst.operands[2].present
9635 && inst.operands[2].reg != inst.operands[1].reg + 1,
9636 _("can only store two consecutive registers"));
9637 /* If op 2 were present and equal to PC, this function wouldn't
9638 have been called in the first place. */
9639 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9640
c19d1205
ZW
9641 constraint (inst.operands[0].reg == inst.operands[1].reg
9642 || inst.operands[0].reg == inst.operands[1].reg + 1
9643 || inst.operands[0].reg == inst.operands[3].reg,
9644 BAD_OVERLAP);
e16bb312 9645
c19d1205
ZW
9646 inst.instruction |= inst.operands[0].reg << 12;
9647 inst.instruction |= inst.operands[1].reg;
9648 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9649}
9650
9eb6c0f1
MGD
9651/* ARM V8 STRL. */
9652static void
4b8c8c02 9653do_stlex (void)
9eb6c0f1
MGD
9654{
9655 constraint (inst.operands[0].reg == inst.operands[1].reg
9656 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9657
9658 do_rd_rm_rn ();
9659}
9660
9661static void
4b8c8c02 9662do_t_stlex (void)
9eb6c0f1
MGD
9663{
9664 constraint (inst.operands[0].reg == inst.operands[1].reg
9665 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9666
9667 do_rm_rd_rn ();
9668}
9669
c19d1205
ZW
9670/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9671 extends it to 32-bits, and adds the result to a value in another
9672 register. You can specify a rotation by 0, 8, 16, or 24 bits
9673 before extracting the 16-bit value.
9674 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9675 Condition defaults to COND_ALWAYS.
9676 Error if any register uses R15. */
9677
e16bb312 9678static void
c19d1205 9679do_sxtah (void)
e16bb312 9680{
c19d1205
ZW
9681 inst.instruction |= inst.operands[0].reg << 12;
9682 inst.instruction |= inst.operands[1].reg << 16;
9683 inst.instruction |= inst.operands[2].reg;
9684 inst.instruction |= inst.operands[3].imm << 10;
9685}
e16bb312 9686
c19d1205 9687/* ARM V6 SXTH.
e16bb312 9688
c19d1205
ZW
9689 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9690 Condition defaults to COND_ALWAYS.
9691 Error if any register uses R15. */
e16bb312
NC
9692
9693static void
c19d1205 9694do_sxth (void)
e16bb312 9695{
c19d1205
ZW
9696 inst.instruction |= inst.operands[0].reg << 12;
9697 inst.instruction |= inst.operands[1].reg;
9698 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9699}
c19d1205
ZW
9700\f
9701/* VFP instructions. In a logical order: SP variant first, monad
9702 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9703
9704static void
c19d1205 9705do_vfp_sp_monadic (void)
e16bb312 9706{
5287ad62
JB
9707 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9708 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9709}
9710
9711static void
c19d1205 9712do_vfp_sp_dyadic (void)
e16bb312 9713{
5287ad62
JB
9714 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9715 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9716 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9717}
9718
9719static void
c19d1205 9720do_vfp_sp_compare_z (void)
e16bb312 9721{
5287ad62 9722 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9723}
9724
9725static void
c19d1205 9726do_vfp_dp_sp_cvt (void)
e16bb312 9727{
5287ad62
JB
9728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9729 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9730}
9731
9732static void
c19d1205 9733do_vfp_sp_dp_cvt (void)
e16bb312 9734{
5287ad62
JB
9735 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9736 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9737}
9738
9739static void
c19d1205 9740do_vfp_reg_from_sp (void)
e16bb312 9741{
c19d1205 9742 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9743 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9744}
9745
9746static void
c19d1205 9747do_vfp_reg2_from_sp2 (void)
e16bb312 9748{
c19d1205
ZW
9749 constraint (inst.operands[2].imm != 2,
9750 _("only two consecutive VFP SP registers allowed here"));
9751 inst.instruction |= inst.operands[0].reg << 12;
9752 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9753 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9754}
9755
9756static void
c19d1205 9757do_vfp_sp_from_reg (void)
e16bb312 9758{
5287ad62 9759 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9760 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9761}
9762
9763static void
c19d1205 9764do_vfp_sp2_from_reg2 (void)
e16bb312 9765{
c19d1205
ZW
9766 constraint (inst.operands[0].imm != 2,
9767 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9769 inst.instruction |= inst.operands[1].reg << 12;
9770 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9771}
9772
9773static void
c19d1205 9774do_vfp_sp_ldst (void)
e16bb312 9775{
5287ad62 9776 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9777 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9778}
9779
9780static void
c19d1205 9781do_vfp_dp_ldst (void)
e16bb312 9782{
5287ad62 9783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9784 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9785}
9786
c19d1205 9787
e16bb312 9788static void
c19d1205 9789vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9790{
c19d1205
ZW
9791 if (inst.operands[0].writeback)
9792 inst.instruction |= WRITE_BACK;
9793 else
9794 constraint (ldstm_type != VFP_LDSTMIA,
9795 _("this addressing mode requires base-register writeback"));
9796 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9797 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9798 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9799}
9800
9801static void
c19d1205 9802vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9803{
c19d1205 9804 int count;
e16bb312 9805
c19d1205
ZW
9806 if (inst.operands[0].writeback)
9807 inst.instruction |= WRITE_BACK;
9808 else
9809 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9810 _("this addressing mode requires base-register writeback"));
e16bb312 9811
c19d1205 9812 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9813 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9814
c19d1205
ZW
9815 count = inst.operands[1].imm << 1;
9816 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9817 count += 1;
e16bb312 9818
c19d1205 9819 inst.instruction |= count;
e16bb312
NC
9820}
9821
9822static void
c19d1205 9823do_vfp_sp_ldstmia (void)
e16bb312 9824{
c19d1205 9825 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9826}
9827
9828static void
c19d1205 9829do_vfp_sp_ldstmdb (void)
e16bb312 9830{
c19d1205 9831 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9832}
9833
9834static void
c19d1205 9835do_vfp_dp_ldstmia (void)
e16bb312 9836{
c19d1205 9837 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9838}
9839
9840static void
c19d1205 9841do_vfp_dp_ldstmdb (void)
e16bb312 9842{
c19d1205 9843 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9844}
9845
9846static void
c19d1205 9847do_vfp_xp_ldstmia (void)
e16bb312 9848{
c19d1205
ZW
9849 vfp_dp_ldstm (VFP_LDSTMIAX);
9850}
e16bb312 9851
c19d1205
ZW
9852static void
9853do_vfp_xp_ldstmdb (void)
9854{
9855 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9856}
5287ad62
JB
9857
9858static void
9859do_vfp_dp_rd_rm (void)
9860{
9861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9863}
9864
9865static void
9866do_vfp_dp_rn_rd (void)
9867{
9868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9869 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9870}
9871
9872static void
9873do_vfp_dp_rd_rn (void)
9874{
9875 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9876 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9877}
9878
9879static void
9880do_vfp_dp_rd_rn_rm (void)
9881{
9882 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9883 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9884 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9885}
9886
9887static void
9888do_vfp_dp_rd (void)
9889{
9890 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9891}
9892
9893static void
9894do_vfp_dp_rm_rd_rn (void)
9895{
9896 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9897 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9898 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9899}
9900
9901/* VFPv3 instructions. */
9902static void
9903do_vfp_sp_const (void)
9904{
9905 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
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
9911do_vfp_dp_const (void)
9912{
9913 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9914 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9915 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9916}
9917
9918static void
9919vfp_conv (int srcsize)
9920{
5f1af56b
MGD
9921 int immbits = srcsize - inst.operands[1].imm;
9922
fa94de6b
RM
9923 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9924 {
5f1af56b 9925 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9926 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9927 inst.error = _("immediate value out of range, expected range [0, 16]");
9928 return;
9929 }
fa94de6b 9930 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9931 {
9932 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9933 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9934 inst.error = _("immediate value out of range, expected range [1, 32]");
9935 return;
9936 }
9937
5287ad62
JB
9938 inst.instruction |= (immbits & 1) << 5;
9939 inst.instruction |= (immbits >> 1);
9940}
9941
9942static void
9943do_vfp_sp_conv_16 (void)
9944{
9945 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9946 vfp_conv (16);
9947}
9948
9949static void
9950do_vfp_dp_conv_16 (void)
9951{
9952 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9953 vfp_conv (16);
9954}
9955
9956static void
9957do_vfp_sp_conv_32 (void)
9958{
9959 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9960 vfp_conv (32);
9961}
9962
9963static void
9964do_vfp_dp_conv_32 (void)
9965{
9966 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9967 vfp_conv (32);
9968}
c19d1205
ZW
9969\f
9970/* FPA instructions. Also in a logical order. */
e16bb312 9971
c19d1205
ZW
9972static void
9973do_fpa_cmp (void)
9974{
9975 inst.instruction |= inst.operands[0].reg << 16;
9976 inst.instruction |= inst.operands[1].reg;
9977}
b99bd4ef
NC
9978
9979static void
c19d1205 9980do_fpa_ldmstm (void)
b99bd4ef 9981{
c19d1205
ZW
9982 inst.instruction |= inst.operands[0].reg << 12;
9983 switch (inst.operands[1].imm)
9984 {
9985 case 1: inst.instruction |= CP_T_X; break;
9986 case 2: inst.instruction |= CP_T_Y; break;
9987 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9988 case 4: break;
9989 default: abort ();
9990 }
b99bd4ef 9991
c19d1205
ZW
9992 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9993 {
9994 /* The instruction specified "ea" or "fd", so we can only accept
9995 [Rn]{!}. The instruction does not really support stacking or
9996 unstacking, so we have to emulate these by setting appropriate
9997 bits and offsets. */
9998 constraint (inst.reloc.exp.X_op != O_constant
9999 || inst.reloc.exp.X_add_number != 0,
10000 _("this instruction does not support indexing"));
b99bd4ef 10001
c19d1205
ZW
10002 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10003 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10004
c19d1205
ZW
10005 if (!(inst.instruction & INDEX_UP))
10006 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 10007
c19d1205
ZW
10008 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10009 {
10010 inst.operands[2].preind = 0;
10011 inst.operands[2].postind = 1;
10012 }
10013 }
b99bd4ef 10014
c19d1205 10015 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10016}
c19d1205
ZW
10017\f
10018/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10019
c19d1205
ZW
10020static void
10021do_iwmmxt_tandorc (void)
10022{
10023 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10024}
b99bd4ef 10025
c19d1205
ZW
10026static void
10027do_iwmmxt_textrc (void)
10028{
10029 inst.instruction |= inst.operands[0].reg << 12;
10030 inst.instruction |= inst.operands[1].imm;
10031}
b99bd4ef
NC
10032
10033static void
c19d1205 10034do_iwmmxt_textrm (void)
b99bd4ef 10035{
c19d1205
ZW
10036 inst.instruction |= inst.operands[0].reg << 12;
10037 inst.instruction |= inst.operands[1].reg << 16;
10038 inst.instruction |= inst.operands[2].imm;
10039}
b99bd4ef 10040
c19d1205
ZW
10041static void
10042do_iwmmxt_tinsr (void)
10043{
10044 inst.instruction |= inst.operands[0].reg << 16;
10045 inst.instruction |= inst.operands[1].reg << 12;
10046 inst.instruction |= inst.operands[2].imm;
10047}
b99bd4ef 10048
c19d1205
ZW
10049static void
10050do_iwmmxt_tmia (void)
10051{
10052 inst.instruction |= inst.operands[0].reg << 5;
10053 inst.instruction |= inst.operands[1].reg;
10054 inst.instruction |= inst.operands[2].reg << 12;
10055}
b99bd4ef 10056
c19d1205
ZW
10057static void
10058do_iwmmxt_waligni (void)
10059{
10060 inst.instruction |= inst.operands[0].reg << 12;
10061 inst.instruction |= inst.operands[1].reg << 16;
10062 inst.instruction |= inst.operands[2].reg;
10063 inst.instruction |= inst.operands[3].imm << 20;
10064}
b99bd4ef 10065
2d447fca
JM
10066static void
10067do_iwmmxt_wmerge (void)
10068{
10069 inst.instruction |= inst.operands[0].reg << 12;
10070 inst.instruction |= inst.operands[1].reg << 16;
10071 inst.instruction |= inst.operands[2].reg;
10072 inst.instruction |= inst.operands[3].imm << 21;
10073}
10074
c19d1205
ZW
10075static void
10076do_iwmmxt_wmov (void)
10077{
10078 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10079 inst.instruction |= inst.operands[0].reg << 12;
10080 inst.instruction |= inst.operands[1].reg << 16;
10081 inst.instruction |= inst.operands[1].reg;
10082}
b99bd4ef 10083
c19d1205
ZW
10084static void
10085do_iwmmxt_wldstbh (void)
10086{
8f06b2d8 10087 int reloc;
c19d1205 10088 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10089 if (thumb_mode)
10090 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10091 else
10092 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10093 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10094}
10095
c19d1205
ZW
10096static void
10097do_iwmmxt_wldstw (void)
10098{
10099 /* RIWR_RIWC clears .isreg for a control register. */
10100 if (!inst.operands[0].isreg)
10101 {
10102 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10103 inst.instruction |= 0xf0000000;
10104 }
b99bd4ef 10105
c19d1205
ZW
10106 inst.instruction |= inst.operands[0].reg << 12;
10107 encode_arm_cp_address (1, TRUE, TRUE, 0);
10108}
b99bd4ef
NC
10109
10110static void
c19d1205 10111do_iwmmxt_wldstd (void)
b99bd4ef 10112{
c19d1205 10113 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10114 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10115 && inst.operands[1].immisreg)
10116 {
10117 inst.instruction &= ~0x1a000ff;
eff0bc54 10118 inst.instruction |= (0xfU << 28);
2d447fca
JM
10119 if (inst.operands[1].preind)
10120 inst.instruction |= PRE_INDEX;
10121 if (!inst.operands[1].negative)
10122 inst.instruction |= INDEX_UP;
10123 if (inst.operands[1].writeback)
10124 inst.instruction |= WRITE_BACK;
10125 inst.instruction |= inst.operands[1].reg << 16;
10126 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10127 inst.instruction |= inst.operands[1].imm;
10128 }
10129 else
10130 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10131}
b99bd4ef 10132
c19d1205
ZW
10133static void
10134do_iwmmxt_wshufh (void)
10135{
10136 inst.instruction |= inst.operands[0].reg << 12;
10137 inst.instruction |= inst.operands[1].reg << 16;
10138 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10139 inst.instruction |= (inst.operands[2].imm & 0x0f);
10140}
b99bd4ef 10141
c19d1205
ZW
10142static void
10143do_iwmmxt_wzero (void)
10144{
10145 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10146 inst.instruction |= inst.operands[0].reg;
10147 inst.instruction |= inst.operands[0].reg << 12;
10148 inst.instruction |= inst.operands[0].reg << 16;
10149}
2d447fca
JM
10150
10151static void
10152do_iwmmxt_wrwrwr_or_imm5 (void)
10153{
10154 if (inst.operands[2].isreg)
10155 do_rd_rn_rm ();
10156 else {
10157 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10158 _("immediate operand requires iWMMXt2"));
10159 do_rd_rn ();
10160 if (inst.operands[2].imm == 0)
10161 {
10162 switch ((inst.instruction >> 20) & 0xf)
10163 {
10164 case 4:
10165 case 5:
10166 case 6:
5f4273c7 10167 case 7:
2d447fca
JM
10168 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10169 inst.operands[2].imm = 16;
10170 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10171 break;
10172 case 8:
10173 case 9:
10174 case 10:
10175 case 11:
10176 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10177 inst.operands[2].imm = 32;
10178 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10179 break;
10180 case 12:
10181 case 13:
10182 case 14:
10183 case 15:
10184 {
10185 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10186 unsigned long wrn;
10187 wrn = (inst.instruction >> 16) & 0xf;
10188 inst.instruction &= 0xff0fff0f;
10189 inst.instruction |= wrn;
10190 /* Bail out here; the instruction is now assembled. */
10191 return;
10192 }
10193 }
10194 }
10195 /* Map 32 -> 0, etc. */
10196 inst.operands[2].imm &= 0x1f;
eff0bc54 10197 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10198 }
10199}
c19d1205
ZW
10200\f
10201/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10202 operations first, then control, shift, and load/store. */
b99bd4ef 10203
c19d1205 10204/* Insns like "foo X,Y,Z". */
b99bd4ef 10205
c19d1205
ZW
10206static void
10207do_mav_triple (void)
10208{
10209 inst.instruction |= inst.operands[0].reg << 16;
10210 inst.instruction |= inst.operands[1].reg;
10211 inst.instruction |= inst.operands[2].reg << 12;
10212}
b99bd4ef 10213
c19d1205
ZW
10214/* Insns like "foo W,X,Y,Z".
10215 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10216
c19d1205
ZW
10217static void
10218do_mav_quad (void)
10219{
10220 inst.instruction |= inst.operands[0].reg << 5;
10221 inst.instruction |= inst.operands[1].reg << 12;
10222 inst.instruction |= inst.operands[2].reg << 16;
10223 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10224}
10225
c19d1205
ZW
10226/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10227static void
10228do_mav_dspsc (void)
a737bd4d 10229{
c19d1205
ZW
10230 inst.instruction |= inst.operands[1].reg << 12;
10231}
a737bd4d 10232
c19d1205
ZW
10233/* Maverick shift immediate instructions.
10234 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10235 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10236
c19d1205
ZW
10237static void
10238do_mav_shift (void)
10239{
10240 int imm = inst.operands[2].imm;
a737bd4d 10241
c19d1205
ZW
10242 inst.instruction |= inst.operands[0].reg << 12;
10243 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10244
c19d1205
ZW
10245 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10246 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10247 Bit 4 should be 0. */
10248 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10249
c19d1205
ZW
10250 inst.instruction |= imm;
10251}
10252\f
10253/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10254
c19d1205
ZW
10255/* Xscale multiply-accumulate (argument parse)
10256 MIAcc acc0,Rm,Rs
10257 MIAPHcc acc0,Rm,Rs
10258 MIAxycc acc0,Rm,Rs. */
a737bd4d 10259
c19d1205
ZW
10260static void
10261do_xsc_mia (void)
10262{
10263 inst.instruction |= inst.operands[1].reg;
10264 inst.instruction |= inst.operands[2].reg << 12;
10265}
a737bd4d 10266
c19d1205 10267/* Xscale move-accumulator-register (argument parse)
a737bd4d 10268
c19d1205 10269 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10270
c19d1205
ZW
10271static void
10272do_xsc_mar (void)
10273{
10274 inst.instruction |= inst.operands[1].reg << 12;
10275 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10276}
10277
c19d1205 10278/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10279
c19d1205 10280 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10281
10282static void
c19d1205 10283do_xsc_mra (void)
b99bd4ef 10284{
c19d1205
ZW
10285 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10286 inst.instruction |= inst.operands[0].reg << 12;
10287 inst.instruction |= inst.operands[1].reg << 16;
10288}
10289\f
10290/* Encoding functions relevant only to Thumb. */
b99bd4ef 10291
c19d1205
ZW
10292/* inst.operands[i] is a shifted-register operand; encode
10293 it into inst.instruction in the format used by Thumb32. */
10294
10295static void
10296encode_thumb32_shifted_operand (int i)
10297{
10298 unsigned int value = inst.reloc.exp.X_add_number;
10299 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10300
9c3c69f2
PB
10301 constraint (inst.operands[i].immisreg,
10302 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10303 inst.instruction |= inst.operands[i].reg;
10304 if (shift == SHIFT_RRX)
10305 inst.instruction |= SHIFT_ROR << 4;
10306 else
b99bd4ef 10307 {
c19d1205
ZW
10308 constraint (inst.reloc.exp.X_op != O_constant,
10309 _("expression too complex"));
10310
10311 constraint (value > 32
10312 || (value == 32 && (shift == SHIFT_LSL
10313 || shift == SHIFT_ROR)),
10314 _("shift expression is too large"));
10315
10316 if (value == 0)
10317 shift = SHIFT_LSL;
10318 else if (value == 32)
10319 value = 0;
10320
10321 inst.instruction |= shift << 4;
10322 inst.instruction |= (value & 0x1c) << 10;
10323 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10324 }
c19d1205 10325}
b99bd4ef 10326
b99bd4ef 10327
c19d1205
ZW
10328/* inst.operands[i] was set up by parse_address. Encode it into a
10329 Thumb32 format load or store instruction. Reject forms that cannot
10330 be used with such instructions. If is_t is true, reject forms that
10331 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10332 that cannot be used with a D instruction. If it is a store insn,
10333 reject PC in Rn. */
b99bd4ef 10334
c19d1205
ZW
10335static void
10336encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10337{
5be8be5d 10338 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10339
10340 constraint (!inst.operands[i].isreg,
53365c0d 10341 _("Instruction does not support =N addresses"));
b99bd4ef 10342
c19d1205
ZW
10343 inst.instruction |= inst.operands[i].reg << 16;
10344 if (inst.operands[i].immisreg)
b99bd4ef 10345 {
5be8be5d 10346 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10347 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10348 constraint (inst.operands[i].negative,
10349 _("Thumb does not support negative register indexing"));
10350 constraint (inst.operands[i].postind,
10351 _("Thumb does not support register post-indexing"));
10352 constraint (inst.operands[i].writeback,
10353 _("Thumb does not support register indexing with writeback"));
10354 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10355 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10356
f40d1643 10357 inst.instruction |= inst.operands[i].imm;
c19d1205 10358 if (inst.operands[i].shifted)
b99bd4ef 10359 {
c19d1205
ZW
10360 constraint (inst.reloc.exp.X_op != O_constant,
10361 _("expression too complex"));
9c3c69f2
PB
10362 constraint (inst.reloc.exp.X_add_number < 0
10363 || inst.reloc.exp.X_add_number > 3,
c19d1205 10364 _("shift out of range"));
9c3c69f2 10365 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10366 }
10367 inst.reloc.type = BFD_RELOC_UNUSED;
10368 }
10369 else if (inst.operands[i].preind)
10370 {
5be8be5d 10371 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10372 constraint (is_t && inst.operands[i].writeback,
c19d1205 10373 _("cannot use writeback with this instruction"));
4755303e
WN
10374 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10375 BAD_PC_ADDRESSING);
c19d1205
ZW
10376
10377 if (is_d)
10378 {
10379 inst.instruction |= 0x01000000;
10380 if (inst.operands[i].writeback)
10381 inst.instruction |= 0x00200000;
b99bd4ef 10382 }
c19d1205 10383 else
b99bd4ef 10384 {
c19d1205
ZW
10385 inst.instruction |= 0x00000c00;
10386 if (inst.operands[i].writeback)
10387 inst.instruction |= 0x00000100;
b99bd4ef 10388 }
c19d1205 10389 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10390 }
c19d1205 10391 else if (inst.operands[i].postind)
b99bd4ef 10392 {
9c2799c2 10393 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10394 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10395 constraint (is_t, _("cannot use post-indexing with this instruction"));
10396
10397 if (is_d)
10398 inst.instruction |= 0x00200000;
10399 else
10400 inst.instruction |= 0x00000900;
10401 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10402 }
10403 else /* unindexed - only for coprocessor */
10404 inst.error = _("instruction does not accept unindexed addressing");
10405}
10406
10407/* Table of Thumb instructions which exist in both 16- and 32-bit
10408 encodings (the latter only in post-V6T2 cores). The index is the
10409 value used in the insns table below. When there is more than one
10410 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10411 holds variant (1).
10412 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10413#define T16_32_TAB \
21d799b5
NC
10414 X(_adc, 4140, eb400000), \
10415 X(_adcs, 4140, eb500000), \
10416 X(_add, 1c00, eb000000), \
10417 X(_adds, 1c00, eb100000), \
10418 X(_addi, 0000, f1000000), \
10419 X(_addis, 0000, f1100000), \
10420 X(_add_pc,000f, f20f0000), \
10421 X(_add_sp,000d, f10d0000), \
10422 X(_adr, 000f, f20f0000), \
10423 X(_and, 4000, ea000000), \
10424 X(_ands, 4000, ea100000), \
10425 X(_asr, 1000, fa40f000), \
10426 X(_asrs, 1000, fa50f000), \
10427 X(_b, e000, f000b000), \
10428 X(_bcond, d000, f0008000), \
10429 X(_bic, 4380, ea200000), \
10430 X(_bics, 4380, ea300000), \
10431 X(_cmn, 42c0, eb100f00), \
10432 X(_cmp, 2800, ebb00f00), \
10433 X(_cpsie, b660, f3af8400), \
10434 X(_cpsid, b670, f3af8600), \
10435 X(_cpy, 4600, ea4f0000), \
10436 X(_dec_sp,80dd, f1ad0d00), \
10437 X(_eor, 4040, ea800000), \
10438 X(_eors, 4040, ea900000), \
10439 X(_inc_sp,00dd, f10d0d00), \
10440 X(_ldmia, c800, e8900000), \
10441 X(_ldr, 6800, f8500000), \
10442 X(_ldrb, 7800, f8100000), \
10443 X(_ldrh, 8800, f8300000), \
10444 X(_ldrsb, 5600, f9100000), \
10445 X(_ldrsh, 5e00, f9300000), \
10446 X(_ldr_pc,4800, f85f0000), \
10447 X(_ldr_pc2,4800, f85f0000), \
10448 X(_ldr_sp,9800, f85d0000), \
10449 X(_lsl, 0000, fa00f000), \
10450 X(_lsls, 0000, fa10f000), \
10451 X(_lsr, 0800, fa20f000), \
10452 X(_lsrs, 0800, fa30f000), \
10453 X(_mov, 2000, ea4f0000), \
10454 X(_movs, 2000, ea5f0000), \
10455 X(_mul, 4340, fb00f000), \
10456 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10457 X(_mvn, 43c0, ea6f0000), \
10458 X(_mvns, 43c0, ea7f0000), \
10459 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10460 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10461 X(_orr, 4300, ea400000), \
10462 X(_orrs, 4300, ea500000), \
10463 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10464 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10465 X(_rev, ba00, fa90f080), \
10466 X(_rev16, ba40, fa90f090), \
10467 X(_revsh, bac0, fa90f0b0), \
10468 X(_ror, 41c0, fa60f000), \
10469 X(_rors, 41c0, fa70f000), \
10470 X(_sbc, 4180, eb600000), \
10471 X(_sbcs, 4180, eb700000), \
10472 X(_stmia, c000, e8800000), \
10473 X(_str, 6000, f8400000), \
10474 X(_strb, 7000, f8000000), \
10475 X(_strh, 8000, f8200000), \
10476 X(_str_sp,9000, f84d0000), \
10477 X(_sub, 1e00, eba00000), \
10478 X(_subs, 1e00, ebb00000), \
10479 X(_subi, 8000, f1a00000), \
10480 X(_subis, 8000, f1b00000), \
10481 X(_sxtb, b240, fa4ff080), \
10482 X(_sxth, b200, fa0ff080), \
10483 X(_tst, 4200, ea100f00), \
10484 X(_uxtb, b2c0, fa5ff080), \
10485 X(_uxth, b280, fa1ff080), \
10486 X(_nop, bf00, f3af8000), \
10487 X(_yield, bf10, f3af8001), \
10488 X(_wfe, bf20, f3af8002), \
10489 X(_wfi, bf30, f3af8003), \
53c4b28b 10490 X(_sev, bf40, f3af8004), \
74db7efb
NC
10491 X(_sevl, bf50, f3af8005), \
10492 X(_udf, de00, f7f0a000)
c19d1205
ZW
10493
10494/* To catch errors in encoding functions, the codes are all offset by
10495 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10496 as 16-bit instructions. */
21d799b5 10497#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10498enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10499#undef X
10500
10501#define X(a,b,c) 0x##b
10502static const unsigned short thumb_op16[] = { T16_32_TAB };
10503#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10504#undef X
10505
10506#define X(a,b,c) 0x##c
10507static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10508#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10509#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10510#undef X
10511#undef T16_32_TAB
10512
10513/* Thumb instruction encoders, in alphabetical order. */
10514
92e90b6e 10515/* ADDW or SUBW. */
c921be7d 10516
92e90b6e
PB
10517static void
10518do_t_add_sub_w (void)
10519{
10520 int Rd, Rn;
10521
10522 Rd = inst.operands[0].reg;
10523 Rn = inst.operands[1].reg;
10524
539d4391
NC
10525 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10526 is the SP-{plus,minus}-immediate form of the instruction. */
10527 if (Rn == REG_SP)
10528 constraint (Rd == REG_PC, BAD_PC);
10529 else
10530 reject_bad_reg (Rd);
fdfde340 10531
92e90b6e
PB
10532 inst.instruction |= (Rn << 16) | (Rd << 8);
10533 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10534}
10535
c19d1205 10536/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10537 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10538
10539static void
10540do_t_add_sub (void)
10541{
10542 int Rd, Rs, Rn;
10543
10544 Rd = inst.operands[0].reg;
10545 Rs = (inst.operands[1].present
10546 ? inst.operands[1].reg /* Rd, Rs, foo */
10547 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10548
e07e6e58
NC
10549 if (Rd == REG_PC)
10550 set_it_insn_type_last ();
10551
c19d1205
ZW
10552 if (unified_syntax)
10553 {
0110f2b8
PB
10554 bfd_boolean flags;
10555 bfd_boolean narrow;
10556 int opcode;
10557
10558 flags = (inst.instruction == T_MNEM_adds
10559 || inst.instruction == T_MNEM_subs);
10560 if (flags)
e07e6e58 10561 narrow = !in_it_block ();
0110f2b8 10562 else
e07e6e58 10563 narrow = in_it_block ();
c19d1205 10564 if (!inst.operands[2].isreg)
b99bd4ef 10565 {
16805f35
PB
10566 int add;
10567
5c8ed6a4
JW
10568 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10569 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10570
16805f35
PB
10571 add = (inst.instruction == T_MNEM_add
10572 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10573 opcode = 0;
10574 if (inst.size_req != 4)
10575 {
0110f2b8 10576 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10577 appropriate. */
0110f2b8
PB
10578 if (Rd == REG_SP && Rs == REG_SP && !flags)
10579 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10580 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10581 opcode = T_MNEM_add_sp;
10582 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10583 opcode = T_MNEM_add_pc;
10584 else if (Rd <= 7 && Rs <= 7 && narrow)
10585 {
10586 if (flags)
10587 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10588 else
10589 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10590 }
10591 if (opcode)
10592 {
10593 inst.instruction = THUMB_OP16(opcode);
10594 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10595 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10596 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10597 {
10598 if (inst.size_req == 2)
10599 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10600 else
10601 inst.relax = opcode;
10602 }
0110f2b8
PB
10603 }
10604 else
10605 constraint (inst.size_req == 2, BAD_HIREG);
10606 }
10607 if (inst.size_req == 4
10608 || (inst.size_req != 2 && !opcode))
10609 {
a9f02af8
MG
10610 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10611 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10612 THUMB1_RELOC_ONLY);
efd81785
PB
10613 if (Rd == REG_PC)
10614 {
fdfde340 10615 constraint (add, BAD_PC);
efd81785
PB
10616 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10617 _("only SUBS PC, LR, #const allowed"));
10618 constraint (inst.reloc.exp.X_op != O_constant,
10619 _("expression too complex"));
10620 constraint (inst.reloc.exp.X_add_number < 0
10621 || inst.reloc.exp.X_add_number > 0xff,
10622 _("immediate value out of range"));
10623 inst.instruction = T2_SUBS_PC_LR
10624 | inst.reloc.exp.X_add_number;
10625 inst.reloc.type = BFD_RELOC_UNUSED;
10626 return;
10627 }
10628 else if (Rs == REG_PC)
16805f35
PB
10629 {
10630 /* Always use addw/subw. */
10631 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10632 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10633 }
10634 else
10635 {
10636 inst.instruction = THUMB_OP32 (inst.instruction);
10637 inst.instruction = (inst.instruction & 0xe1ffffff)
10638 | 0x10000000;
10639 if (flags)
10640 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10641 else
10642 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10643 }
dc4503c6
PB
10644 inst.instruction |= Rd << 8;
10645 inst.instruction |= Rs << 16;
0110f2b8 10646 }
b99bd4ef 10647 }
c19d1205
ZW
10648 else
10649 {
5f4cb198
NC
10650 unsigned int value = inst.reloc.exp.X_add_number;
10651 unsigned int shift = inst.operands[2].shift_kind;
10652
c19d1205
ZW
10653 Rn = inst.operands[2].reg;
10654 /* See if we can do this with a 16-bit instruction. */
10655 if (!inst.operands[2].shifted && inst.size_req != 4)
10656 {
e27ec89e
PB
10657 if (Rd > 7 || Rs > 7 || Rn > 7)
10658 narrow = FALSE;
10659
10660 if (narrow)
c19d1205 10661 {
e27ec89e
PB
10662 inst.instruction = ((inst.instruction == T_MNEM_adds
10663 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10664 ? T_OPCODE_ADD_R3
10665 : T_OPCODE_SUB_R3);
10666 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10667 return;
10668 }
b99bd4ef 10669
7e806470 10670 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10671 {
7e806470
PB
10672 /* Thumb-1 cores (except v6-M) require at least one high
10673 register in a narrow non flag setting add. */
10674 if (Rd > 7 || Rn > 7
10675 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10676 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10677 {
7e806470
PB
10678 if (Rd == Rn)
10679 {
10680 Rn = Rs;
10681 Rs = Rd;
10682 }
c19d1205
ZW
10683 inst.instruction = T_OPCODE_ADD_HI;
10684 inst.instruction |= (Rd & 8) << 4;
10685 inst.instruction |= (Rd & 7);
10686 inst.instruction |= Rn << 3;
10687 return;
10688 }
c19d1205
ZW
10689 }
10690 }
c921be7d 10691
fdfde340 10692 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10693 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10694 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10695 constraint (Rs == REG_PC, BAD_PC);
10696 reject_bad_reg (Rn);
10697
c19d1205
ZW
10698 /* If we get here, it can't be done in 16 bits. */
10699 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10700 _("shift must be constant"));
10701 inst.instruction = THUMB_OP32 (inst.instruction);
10702 inst.instruction |= Rd << 8;
10703 inst.instruction |= Rs << 16;
5f4cb198
NC
10704 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10705 _("shift value over 3 not allowed in thumb mode"));
10706 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10707 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10708 encode_thumb32_shifted_operand (2);
10709 }
10710 }
10711 else
10712 {
10713 constraint (inst.instruction == T_MNEM_adds
10714 || inst.instruction == T_MNEM_subs,
10715 BAD_THUMB32);
b99bd4ef 10716
c19d1205 10717 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10718 {
c19d1205
ZW
10719 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10720 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10721 BAD_HIREG);
10722
10723 inst.instruction = (inst.instruction == T_MNEM_add
10724 ? 0x0000 : 0x8000);
10725 inst.instruction |= (Rd << 4) | Rs;
10726 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10727 return;
10728 }
10729
c19d1205
ZW
10730 Rn = inst.operands[2].reg;
10731 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10732
c19d1205
ZW
10733 /* We now have Rd, Rs, and Rn set to registers. */
10734 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10735 {
c19d1205
ZW
10736 /* Can't do this for SUB. */
10737 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10738 inst.instruction = T_OPCODE_ADD_HI;
10739 inst.instruction |= (Rd & 8) << 4;
10740 inst.instruction |= (Rd & 7);
10741 if (Rs == Rd)
10742 inst.instruction |= Rn << 3;
10743 else if (Rn == Rd)
10744 inst.instruction |= Rs << 3;
10745 else
10746 constraint (1, _("dest must overlap one source register"));
10747 }
10748 else
10749 {
10750 inst.instruction = (inst.instruction == T_MNEM_add
10751 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10752 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10753 }
b99bd4ef 10754 }
b99bd4ef
NC
10755}
10756
c19d1205
ZW
10757static void
10758do_t_adr (void)
10759{
fdfde340
JM
10760 unsigned Rd;
10761
10762 Rd = inst.operands[0].reg;
10763 reject_bad_reg (Rd);
10764
10765 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10766 {
10767 /* Defer to section relaxation. */
10768 inst.relax = inst.instruction;
10769 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10770 inst.instruction |= Rd << 4;
0110f2b8
PB
10771 }
10772 else if (unified_syntax && inst.size_req != 2)
e9f89963 10773 {
0110f2b8 10774 /* Generate a 32-bit opcode. */
e9f89963 10775 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10776 inst.instruction |= Rd << 8;
e9f89963
PB
10777 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10778 inst.reloc.pc_rel = 1;
10779 }
10780 else
10781 {
0110f2b8 10782 /* Generate a 16-bit opcode. */
e9f89963
PB
10783 inst.instruction = THUMB_OP16 (inst.instruction);
10784 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10785 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10786 inst.reloc.pc_rel = 1;
fdfde340 10787 inst.instruction |= Rd << 4;
e9f89963 10788 }
52a86f84
NC
10789
10790 if (inst.reloc.exp.X_op == O_symbol
10791 && inst.reloc.exp.X_add_symbol != NULL
10792 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10793 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10794 inst.reloc.exp.X_add_number += 1;
c19d1205 10795}
b99bd4ef 10796
c19d1205
ZW
10797/* Arithmetic instructions for which there is just one 16-bit
10798 instruction encoding, and it allows only two low registers.
10799 For maximal compatibility with ARM syntax, we allow three register
10800 operands even when Thumb-32 instructions are not available, as long
10801 as the first two are identical. For instance, both "sbc r0,r1" and
10802 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10803static void
c19d1205 10804do_t_arit3 (void)
b99bd4ef 10805{
c19d1205 10806 int Rd, Rs, Rn;
b99bd4ef 10807
c19d1205
ZW
10808 Rd = inst.operands[0].reg;
10809 Rs = (inst.operands[1].present
10810 ? inst.operands[1].reg /* Rd, Rs, foo */
10811 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10812 Rn = inst.operands[2].reg;
b99bd4ef 10813
fdfde340
JM
10814 reject_bad_reg (Rd);
10815 reject_bad_reg (Rs);
10816 if (inst.operands[2].isreg)
10817 reject_bad_reg (Rn);
10818
c19d1205 10819 if (unified_syntax)
b99bd4ef 10820 {
c19d1205
ZW
10821 if (!inst.operands[2].isreg)
10822 {
10823 /* For an immediate, we always generate a 32-bit opcode;
10824 section relaxation will shrink it later if possible. */
10825 inst.instruction = THUMB_OP32 (inst.instruction);
10826 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10827 inst.instruction |= Rd << 8;
10828 inst.instruction |= Rs << 16;
10829 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10830 }
10831 else
10832 {
e27ec89e
PB
10833 bfd_boolean narrow;
10834
c19d1205 10835 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10836 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10837 narrow = !in_it_block ();
e27ec89e 10838 else
e07e6e58 10839 narrow = in_it_block ();
e27ec89e
PB
10840
10841 if (Rd > 7 || Rn > 7 || Rs > 7)
10842 narrow = FALSE;
10843 if (inst.operands[2].shifted)
10844 narrow = FALSE;
10845 if (inst.size_req == 4)
10846 narrow = FALSE;
10847
10848 if (narrow
c19d1205
ZW
10849 && Rd == Rs)
10850 {
10851 inst.instruction = THUMB_OP16 (inst.instruction);
10852 inst.instruction |= Rd;
10853 inst.instruction |= Rn << 3;
10854 return;
10855 }
b99bd4ef 10856
c19d1205
ZW
10857 /* If we get here, it can't be done in 16 bits. */
10858 constraint (inst.operands[2].shifted
10859 && inst.operands[2].immisreg,
10860 _("shift must be constant"));
10861 inst.instruction = THUMB_OP32 (inst.instruction);
10862 inst.instruction |= Rd << 8;
10863 inst.instruction |= Rs << 16;
10864 encode_thumb32_shifted_operand (2);
10865 }
a737bd4d 10866 }
c19d1205 10867 else
b99bd4ef 10868 {
c19d1205
ZW
10869 /* On its face this is a lie - the instruction does set the
10870 flags. However, the only supported mnemonic in this mode
10871 says it doesn't. */
10872 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10873
c19d1205
ZW
10874 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10875 _("unshifted register required"));
10876 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10877 constraint (Rd != Rs,
10878 _("dest and source1 must be the same register"));
a737bd4d 10879
c19d1205
ZW
10880 inst.instruction = THUMB_OP16 (inst.instruction);
10881 inst.instruction |= Rd;
10882 inst.instruction |= Rn << 3;
b99bd4ef 10883 }
a737bd4d 10884}
b99bd4ef 10885
c19d1205
ZW
10886/* Similarly, but for instructions where the arithmetic operation is
10887 commutative, so we can allow either of them to be different from
10888 the destination operand in a 16-bit instruction. For instance, all
10889 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10890 accepted. */
10891static void
10892do_t_arit3c (void)
a737bd4d 10893{
c19d1205 10894 int Rd, Rs, Rn;
b99bd4ef 10895
c19d1205
ZW
10896 Rd = inst.operands[0].reg;
10897 Rs = (inst.operands[1].present
10898 ? inst.operands[1].reg /* Rd, Rs, foo */
10899 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10900 Rn = inst.operands[2].reg;
c921be7d 10901
fdfde340
JM
10902 reject_bad_reg (Rd);
10903 reject_bad_reg (Rs);
10904 if (inst.operands[2].isreg)
10905 reject_bad_reg (Rn);
a737bd4d 10906
c19d1205 10907 if (unified_syntax)
a737bd4d 10908 {
c19d1205 10909 if (!inst.operands[2].isreg)
b99bd4ef 10910 {
c19d1205
ZW
10911 /* For an immediate, we always generate a 32-bit opcode;
10912 section relaxation will shrink it later if possible. */
10913 inst.instruction = THUMB_OP32 (inst.instruction);
10914 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10915 inst.instruction |= Rd << 8;
10916 inst.instruction |= Rs << 16;
10917 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10918 }
c19d1205 10919 else
a737bd4d 10920 {
e27ec89e
PB
10921 bfd_boolean narrow;
10922
c19d1205 10923 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10924 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10925 narrow = !in_it_block ();
e27ec89e 10926 else
e07e6e58 10927 narrow = in_it_block ();
e27ec89e
PB
10928
10929 if (Rd > 7 || Rn > 7 || Rs > 7)
10930 narrow = FALSE;
10931 if (inst.operands[2].shifted)
10932 narrow = FALSE;
10933 if (inst.size_req == 4)
10934 narrow = FALSE;
10935
10936 if (narrow)
a737bd4d 10937 {
c19d1205 10938 if (Rd == Rs)
a737bd4d 10939 {
c19d1205
ZW
10940 inst.instruction = THUMB_OP16 (inst.instruction);
10941 inst.instruction |= Rd;
10942 inst.instruction |= Rn << 3;
10943 return;
a737bd4d 10944 }
c19d1205 10945 if (Rd == Rn)
a737bd4d 10946 {
c19d1205
ZW
10947 inst.instruction = THUMB_OP16 (inst.instruction);
10948 inst.instruction |= Rd;
10949 inst.instruction |= Rs << 3;
10950 return;
a737bd4d
NC
10951 }
10952 }
c19d1205
ZW
10953
10954 /* If we get here, it can't be done in 16 bits. */
10955 constraint (inst.operands[2].shifted
10956 && inst.operands[2].immisreg,
10957 _("shift must be constant"));
10958 inst.instruction = THUMB_OP32 (inst.instruction);
10959 inst.instruction |= Rd << 8;
10960 inst.instruction |= Rs << 16;
10961 encode_thumb32_shifted_operand (2);
a737bd4d 10962 }
b99bd4ef 10963 }
c19d1205
ZW
10964 else
10965 {
10966 /* On its face this is a lie - the instruction does set the
10967 flags. However, the only supported mnemonic in this mode
10968 says it doesn't. */
10969 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10970
c19d1205
ZW
10971 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10972 _("unshifted register required"));
10973 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10974
10975 inst.instruction = THUMB_OP16 (inst.instruction);
10976 inst.instruction |= Rd;
10977
10978 if (Rd == Rs)
10979 inst.instruction |= Rn << 3;
10980 else if (Rd == Rn)
10981 inst.instruction |= Rs << 3;
10982 else
10983 constraint (1, _("dest must overlap one source register"));
10984 }
a737bd4d
NC
10985}
10986
c19d1205
ZW
10987static void
10988do_t_bfc (void)
a737bd4d 10989{
fdfde340 10990 unsigned Rd;
c19d1205
ZW
10991 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10992 constraint (msb > 32, _("bit-field extends past end of register"));
10993 /* The instruction encoding stores the LSB and MSB,
10994 not the LSB and width. */
fdfde340
JM
10995 Rd = inst.operands[0].reg;
10996 reject_bad_reg (Rd);
10997 inst.instruction |= Rd << 8;
c19d1205
ZW
10998 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10999 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11000 inst.instruction |= msb - 1;
b99bd4ef
NC
11001}
11002
c19d1205
ZW
11003static void
11004do_t_bfi (void)
b99bd4ef 11005{
fdfde340 11006 int Rd, Rn;
c19d1205 11007 unsigned int msb;
b99bd4ef 11008
fdfde340
JM
11009 Rd = inst.operands[0].reg;
11010 reject_bad_reg (Rd);
11011
c19d1205
ZW
11012 /* #0 in second position is alternative syntax for bfc, which is
11013 the same instruction but with REG_PC in the Rm field. */
11014 if (!inst.operands[1].isreg)
fdfde340
JM
11015 Rn = REG_PC;
11016 else
11017 {
11018 Rn = inst.operands[1].reg;
11019 reject_bad_reg (Rn);
11020 }
b99bd4ef 11021
c19d1205
ZW
11022 msb = inst.operands[2].imm + inst.operands[3].imm;
11023 constraint (msb > 32, _("bit-field extends past end of register"));
11024 /* The instruction encoding stores the LSB and MSB,
11025 not the LSB and width. */
fdfde340
JM
11026 inst.instruction |= Rd << 8;
11027 inst.instruction |= Rn << 16;
c19d1205
ZW
11028 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11029 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11030 inst.instruction |= msb - 1;
b99bd4ef
NC
11031}
11032
c19d1205
ZW
11033static void
11034do_t_bfx (void)
b99bd4ef 11035{
fdfde340
JM
11036 unsigned Rd, Rn;
11037
11038 Rd = inst.operands[0].reg;
11039 Rn = inst.operands[1].reg;
11040
11041 reject_bad_reg (Rd);
11042 reject_bad_reg (Rn);
11043
c19d1205
ZW
11044 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11045 _("bit-field extends past end of register"));
fdfde340
JM
11046 inst.instruction |= Rd << 8;
11047 inst.instruction |= Rn << 16;
c19d1205
ZW
11048 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11049 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11050 inst.instruction |= inst.operands[3].imm - 1;
11051}
b99bd4ef 11052
c19d1205
ZW
11053/* ARM V5 Thumb BLX (argument parse)
11054 BLX <target_addr> which is BLX(1)
11055 BLX <Rm> which is BLX(2)
11056 Unfortunately, there are two different opcodes for this mnemonic.
11057 So, the insns[].value is not used, and the code here zaps values
11058 into inst.instruction.
b99bd4ef 11059
c19d1205
ZW
11060 ??? How to take advantage of the additional two bits of displacement
11061 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11062
c19d1205
ZW
11063static void
11064do_t_blx (void)
11065{
e07e6e58
NC
11066 set_it_insn_type_last ();
11067
c19d1205 11068 if (inst.operands[0].isreg)
fdfde340
JM
11069 {
11070 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11071 /* We have a register, so this is BLX(2). */
11072 inst.instruction |= inst.operands[0].reg << 3;
11073 }
b99bd4ef
NC
11074 else
11075 {
c19d1205 11076 /* No register. This must be BLX(1). */
2fc8bdac 11077 inst.instruction = 0xf000e800;
0855e32b 11078 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11079 }
11080}
11081
c19d1205
ZW
11082static void
11083do_t_branch (void)
b99bd4ef 11084{
0110f2b8 11085 int opcode;
dfa9f0d5 11086 int cond;
2fe88214 11087 bfd_reloc_code_real_type reloc;
dfa9f0d5 11088
e07e6e58
NC
11089 cond = inst.cond;
11090 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11091
11092 if (in_it_block ())
dfa9f0d5
PB
11093 {
11094 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11095 branches. */
dfa9f0d5 11096 cond = COND_ALWAYS;
dfa9f0d5
PB
11097 }
11098 else
11099 cond = inst.cond;
11100
11101 if (cond != COND_ALWAYS)
0110f2b8
PB
11102 opcode = T_MNEM_bcond;
11103 else
11104 opcode = inst.instruction;
11105
12d6b0b7
RS
11106 if (unified_syntax
11107 && (inst.size_req == 4
10960bfb
PB
11108 || (inst.size_req != 2
11109 && (inst.operands[0].hasreloc
11110 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11111 {
0110f2b8 11112 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11113 if (cond == COND_ALWAYS)
9ae92b05 11114 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11115 else
11116 {
ff8646ee
TP
11117 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11118 _("selected architecture does not support "
11119 "wide conditional branch instruction"));
11120
9c2799c2 11121 gas_assert (cond != 0xF);
dfa9f0d5 11122 inst.instruction |= cond << 22;
9ae92b05 11123 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11124 }
11125 }
b99bd4ef
NC
11126 else
11127 {
0110f2b8 11128 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11129 if (cond == COND_ALWAYS)
9ae92b05 11130 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11131 else
b99bd4ef 11132 {
dfa9f0d5 11133 inst.instruction |= cond << 8;
9ae92b05 11134 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11135 }
0110f2b8
PB
11136 /* Allow section relaxation. */
11137 if (unified_syntax && inst.size_req != 2)
11138 inst.relax = opcode;
b99bd4ef 11139 }
9ae92b05 11140 inst.reloc.type = reloc;
c19d1205 11141 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11142}
11143
8884b720 11144/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11145 between the two is the maximum immediate allowed - which is passed in
8884b720 11146 RANGE. */
b99bd4ef 11147static void
8884b720 11148do_t_bkpt_hlt1 (int range)
b99bd4ef 11149{
dfa9f0d5
PB
11150 constraint (inst.cond != COND_ALWAYS,
11151 _("instruction is always unconditional"));
c19d1205 11152 if (inst.operands[0].present)
b99bd4ef 11153 {
8884b720 11154 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11155 _("immediate value out of range"));
11156 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11157 }
8884b720
MGD
11158
11159 set_it_insn_type (NEUTRAL_IT_INSN);
11160}
11161
11162static void
11163do_t_hlt (void)
11164{
11165 do_t_bkpt_hlt1 (63);
11166}
11167
11168static void
11169do_t_bkpt (void)
11170{
11171 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11172}
11173
11174static void
c19d1205 11175do_t_branch23 (void)
b99bd4ef 11176{
e07e6e58 11177 set_it_insn_type_last ();
0855e32b 11178 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11179
0855e32b
NS
11180 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11181 this file. We used to simply ignore the PLT reloc type here --
11182 the branch encoding is now needed to deal with TLSCALL relocs.
11183 So if we see a PLT reloc now, put it back to how it used to be to
11184 keep the preexisting behaviour. */
11185 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11186 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11187
4343666d 11188#if defined(OBJ_COFF)
c19d1205
ZW
11189 /* If the destination of the branch is a defined symbol which does not have
11190 the THUMB_FUNC attribute, then we must be calling a function which has
11191 the (interfacearm) attribute. We look for the Thumb entry point to that
11192 function and change the branch to refer to that function instead. */
11193 if ( inst.reloc.exp.X_op == O_symbol
11194 && inst.reloc.exp.X_add_symbol != NULL
11195 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11196 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11197 inst.reloc.exp.X_add_symbol =
11198 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11199#endif
90e4755a
RE
11200}
11201
11202static void
c19d1205 11203do_t_bx (void)
90e4755a 11204{
e07e6e58 11205 set_it_insn_type_last ();
c19d1205
ZW
11206 inst.instruction |= inst.operands[0].reg << 3;
11207 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11208 should cause the alignment to be checked once it is known. This is
11209 because BX PC only works if the instruction is word aligned. */
11210}
90e4755a 11211
c19d1205
ZW
11212static void
11213do_t_bxj (void)
11214{
fdfde340 11215 int Rm;
90e4755a 11216
e07e6e58 11217 set_it_insn_type_last ();
fdfde340
JM
11218 Rm = inst.operands[0].reg;
11219 reject_bad_reg (Rm);
11220 inst.instruction |= Rm << 16;
90e4755a
RE
11221}
11222
11223static void
c19d1205 11224do_t_clz (void)
90e4755a 11225{
fdfde340
JM
11226 unsigned Rd;
11227 unsigned Rm;
11228
11229 Rd = inst.operands[0].reg;
11230 Rm = inst.operands[1].reg;
11231
11232 reject_bad_reg (Rd);
11233 reject_bad_reg (Rm);
11234
11235 inst.instruction |= Rd << 8;
11236 inst.instruction |= Rm << 16;
11237 inst.instruction |= Rm;
c19d1205 11238}
90e4755a 11239
dfa9f0d5
PB
11240static void
11241do_t_cps (void)
11242{
e07e6e58 11243 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11244 inst.instruction |= inst.operands[0].imm;
11245}
11246
c19d1205
ZW
11247static void
11248do_t_cpsi (void)
11249{
e07e6e58 11250 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11251 if (unified_syntax
62b3e311
PB
11252 && (inst.operands[1].present || inst.size_req == 4)
11253 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11254 {
c19d1205
ZW
11255 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11256 inst.instruction = 0xf3af8000;
11257 inst.instruction |= imod << 9;
11258 inst.instruction |= inst.operands[0].imm << 5;
11259 if (inst.operands[1].present)
11260 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11261 }
c19d1205 11262 else
90e4755a 11263 {
62b3e311
PB
11264 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11265 && (inst.operands[0].imm & 4),
11266 _("selected processor does not support 'A' form "
11267 "of this instruction"));
11268 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11269 _("Thumb does not support the 2-argument "
11270 "form of this instruction"));
11271 inst.instruction |= inst.operands[0].imm;
90e4755a 11272 }
90e4755a
RE
11273}
11274
c19d1205
ZW
11275/* THUMB CPY instruction (argument parse). */
11276
90e4755a 11277static void
c19d1205 11278do_t_cpy (void)
90e4755a 11279{
c19d1205 11280 if (inst.size_req == 4)
90e4755a 11281 {
c19d1205
ZW
11282 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11283 inst.instruction |= inst.operands[0].reg << 8;
11284 inst.instruction |= inst.operands[1].reg;
90e4755a 11285 }
c19d1205 11286 else
90e4755a 11287 {
c19d1205
ZW
11288 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11289 inst.instruction |= (inst.operands[0].reg & 0x7);
11290 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11291 }
90e4755a
RE
11292}
11293
90e4755a 11294static void
25fe350b 11295do_t_cbz (void)
90e4755a 11296{
e07e6e58 11297 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11298 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11299 inst.instruction |= inst.operands[0].reg;
11300 inst.reloc.pc_rel = 1;
11301 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11302}
90e4755a 11303
62b3e311
PB
11304static void
11305do_t_dbg (void)
11306{
11307 inst.instruction |= inst.operands[0].imm;
11308}
11309
11310static void
11311do_t_div (void)
11312{
fdfde340
JM
11313 unsigned Rd, Rn, Rm;
11314
11315 Rd = inst.operands[0].reg;
11316 Rn = (inst.operands[1].present
11317 ? inst.operands[1].reg : Rd);
11318 Rm = inst.operands[2].reg;
11319
11320 reject_bad_reg (Rd);
11321 reject_bad_reg (Rn);
11322 reject_bad_reg (Rm);
11323
11324 inst.instruction |= Rd << 8;
11325 inst.instruction |= Rn << 16;
11326 inst.instruction |= Rm;
62b3e311
PB
11327}
11328
c19d1205
ZW
11329static void
11330do_t_hint (void)
11331{
11332 if (unified_syntax && inst.size_req == 4)
11333 inst.instruction = THUMB_OP32 (inst.instruction);
11334 else
11335 inst.instruction = THUMB_OP16 (inst.instruction);
11336}
90e4755a 11337
c19d1205
ZW
11338static void
11339do_t_it (void)
11340{
11341 unsigned int cond = inst.operands[0].imm;
e27ec89e 11342
e07e6e58
NC
11343 set_it_insn_type (IT_INSN);
11344 now_it.mask = (inst.instruction & 0xf) | 0x10;
11345 now_it.cc = cond;
5a01bb1d 11346 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11347
11348 /* If the condition is a negative condition, invert the mask. */
c19d1205 11349 if ((cond & 0x1) == 0x0)
90e4755a 11350 {
c19d1205 11351 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11352
c19d1205 11353 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11354 {
11355 /* No conversion needed. */
11356 now_it.block_length = 1;
11357 }
c19d1205 11358 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11359 {
11360 mask ^= 0x8;
11361 now_it.block_length = 2;
11362 }
e27ec89e 11363 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11364 {
11365 mask ^= 0xC;
11366 now_it.block_length = 3;
11367 }
c19d1205 11368 else
5a01bb1d
MGD
11369 {
11370 mask ^= 0xE;
11371 now_it.block_length = 4;
11372 }
90e4755a 11373
e27ec89e
PB
11374 inst.instruction &= 0xfff0;
11375 inst.instruction |= mask;
c19d1205 11376 }
90e4755a 11377
c19d1205
ZW
11378 inst.instruction |= cond << 4;
11379}
90e4755a 11380
3c707909
PB
11381/* Helper function used for both push/pop and ldm/stm. */
11382static void
11383encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11384{
11385 bfd_boolean load;
11386
11387 load = (inst.instruction & (1 << 20)) != 0;
11388
11389 if (mask & (1 << 13))
11390 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11391
11392 if ((mask & (1 << base)) != 0
11393 && writeback)
11394 inst.error = _("having the base register in the register list when "
11395 "using write back is UNPREDICTABLE");
11396
3c707909
PB
11397 if (load)
11398 {
e07e6e58 11399 if (mask & (1 << 15))
477330fc
RM
11400 {
11401 if (mask & (1 << 14))
11402 inst.error = _("LR and PC should not both be in register list");
11403 else
11404 set_it_insn_type_last ();
11405 }
3c707909
PB
11406 }
11407 else
11408 {
11409 if (mask & (1 << 15))
11410 inst.error = _("PC not allowed in register list");
3c707909
PB
11411 }
11412
11413 if ((mask & (mask - 1)) == 0)
11414 {
11415 /* Single register transfers implemented as str/ldr. */
11416 if (writeback)
11417 {
11418 if (inst.instruction & (1 << 23))
11419 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11420 else
11421 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11422 }
11423 else
11424 {
11425 if (inst.instruction & (1 << 23))
11426 inst.instruction = 0x00800000; /* ia -> [base] */
11427 else
11428 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11429 }
11430
11431 inst.instruction |= 0xf8400000;
11432 if (load)
11433 inst.instruction |= 0x00100000;
11434
5f4273c7 11435 mask = ffs (mask) - 1;
3c707909
PB
11436 mask <<= 12;
11437 }
11438 else if (writeback)
11439 inst.instruction |= WRITE_BACK;
11440
11441 inst.instruction |= mask;
11442 inst.instruction |= base << 16;
11443}
11444
c19d1205
ZW
11445static void
11446do_t_ldmstm (void)
11447{
11448 /* This really doesn't seem worth it. */
11449 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11450 _("expression too complex"));
11451 constraint (inst.operands[1].writeback,
11452 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11453
c19d1205
ZW
11454 if (unified_syntax)
11455 {
3c707909
PB
11456 bfd_boolean narrow;
11457 unsigned mask;
11458
11459 narrow = FALSE;
c19d1205
ZW
11460 /* See if we can use a 16-bit instruction. */
11461 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11462 && inst.size_req != 4
3c707909 11463 && !(inst.operands[1].imm & ~0xff))
90e4755a 11464 {
3c707909 11465 mask = 1 << inst.operands[0].reg;
90e4755a 11466
eab4f823 11467 if (inst.operands[0].reg <= 7)
90e4755a 11468 {
3c707909 11469 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11470 ? inst.operands[0].writeback
11471 : (inst.operands[0].writeback
11472 == !(inst.operands[1].imm & mask)))
477330fc 11473 {
eab4f823
MGD
11474 if (inst.instruction == T_MNEM_stmia
11475 && (inst.operands[1].imm & mask)
11476 && (inst.operands[1].imm & (mask - 1)))
11477 as_warn (_("value stored for r%d is UNKNOWN"),
11478 inst.operands[0].reg);
3c707909 11479
eab4f823
MGD
11480 inst.instruction = THUMB_OP16 (inst.instruction);
11481 inst.instruction |= inst.operands[0].reg << 8;
11482 inst.instruction |= inst.operands[1].imm;
11483 narrow = TRUE;
11484 }
11485 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11486 {
11487 /* This means 1 register in reg list one of 3 situations:
11488 1. Instruction is stmia, but without writeback.
11489 2. lmdia without writeback, but with Rn not in
477330fc 11490 reglist.
eab4f823
MGD
11491 3. ldmia with writeback, but with Rn in reglist.
11492 Case 3 is UNPREDICTABLE behaviour, so we handle
11493 case 1 and 2 which can be converted into a 16-bit
11494 str or ldr. The SP cases are handled below. */
11495 unsigned long opcode;
11496 /* First, record an error for Case 3. */
11497 if (inst.operands[1].imm & mask
11498 && inst.operands[0].writeback)
fa94de6b 11499 inst.error =
eab4f823
MGD
11500 _("having the base register in the register list when "
11501 "using write back is UNPREDICTABLE");
fa94de6b
RM
11502
11503 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11504 : T_MNEM_ldr);
11505 inst.instruction = THUMB_OP16 (opcode);
11506 inst.instruction |= inst.operands[0].reg << 3;
11507 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11508 narrow = TRUE;
11509 }
90e4755a 11510 }
eab4f823 11511 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11512 {
eab4f823
MGD
11513 if (inst.operands[0].writeback)
11514 {
fa94de6b 11515 inst.instruction =
eab4f823 11516 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11517 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11518 inst.instruction |= inst.operands[1].imm;
477330fc 11519 narrow = TRUE;
eab4f823
MGD
11520 }
11521 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11522 {
fa94de6b 11523 inst.instruction =
eab4f823 11524 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11525 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11526 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11527 narrow = TRUE;
eab4f823 11528 }
90e4755a 11529 }
3c707909
PB
11530 }
11531
11532 if (!narrow)
11533 {
c19d1205
ZW
11534 if (inst.instruction < 0xffff)
11535 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11536
5f4273c7
NC
11537 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11538 inst.operands[0].writeback);
90e4755a
RE
11539 }
11540 }
c19d1205 11541 else
90e4755a 11542 {
c19d1205
ZW
11543 constraint (inst.operands[0].reg > 7
11544 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11545 constraint (inst.instruction != T_MNEM_ldmia
11546 && inst.instruction != T_MNEM_stmia,
11547 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11548 if (inst.instruction == T_MNEM_stmia)
f03698e6 11549 {
c19d1205
ZW
11550 if (!inst.operands[0].writeback)
11551 as_warn (_("this instruction will write back the base register"));
11552 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11553 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11554 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11555 inst.operands[0].reg);
f03698e6 11556 }
c19d1205 11557 else
90e4755a 11558 {
c19d1205
ZW
11559 if (!inst.operands[0].writeback
11560 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11561 as_warn (_("this instruction will write back the base register"));
11562 else if (inst.operands[0].writeback
11563 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11564 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11565 }
11566
c19d1205
ZW
11567 inst.instruction = THUMB_OP16 (inst.instruction);
11568 inst.instruction |= inst.operands[0].reg << 8;
11569 inst.instruction |= inst.operands[1].imm;
11570 }
11571}
e28cd48c 11572
c19d1205
ZW
11573static void
11574do_t_ldrex (void)
11575{
11576 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11577 || inst.operands[1].postind || inst.operands[1].writeback
11578 || inst.operands[1].immisreg || inst.operands[1].shifted
11579 || inst.operands[1].negative,
01cfc07f 11580 BAD_ADDR_MODE);
e28cd48c 11581
5be8be5d
DG
11582 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11583
c19d1205
ZW
11584 inst.instruction |= inst.operands[0].reg << 12;
11585 inst.instruction |= inst.operands[1].reg << 16;
11586 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11587}
e28cd48c 11588
c19d1205
ZW
11589static void
11590do_t_ldrexd (void)
11591{
11592 if (!inst.operands[1].present)
1cac9012 11593 {
c19d1205
ZW
11594 constraint (inst.operands[0].reg == REG_LR,
11595 _("r14 not allowed as first register "
11596 "when second register is omitted"));
11597 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11598 }
c19d1205
ZW
11599 constraint (inst.operands[0].reg == inst.operands[1].reg,
11600 BAD_OVERLAP);
b99bd4ef 11601
c19d1205
ZW
11602 inst.instruction |= inst.operands[0].reg << 12;
11603 inst.instruction |= inst.operands[1].reg << 8;
11604 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11605}
11606
11607static void
c19d1205 11608do_t_ldst (void)
b99bd4ef 11609{
0110f2b8
PB
11610 unsigned long opcode;
11611 int Rn;
11612
e07e6e58
NC
11613 if (inst.operands[0].isreg
11614 && !inst.operands[0].preind
11615 && inst.operands[0].reg == REG_PC)
11616 set_it_insn_type_last ();
11617
0110f2b8 11618 opcode = inst.instruction;
c19d1205 11619 if (unified_syntax)
b99bd4ef 11620 {
53365c0d
PB
11621 if (!inst.operands[1].isreg)
11622 {
11623 if (opcode <= 0xffff)
11624 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11625 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11626 return;
11627 }
0110f2b8
PB
11628 if (inst.operands[1].isreg
11629 && !inst.operands[1].writeback
c19d1205
ZW
11630 && !inst.operands[1].shifted && !inst.operands[1].postind
11631 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11632 && opcode <= 0xffff
11633 && inst.size_req != 4)
c19d1205 11634 {
0110f2b8
PB
11635 /* Insn may have a 16-bit form. */
11636 Rn = inst.operands[1].reg;
11637 if (inst.operands[1].immisreg)
11638 {
11639 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11640 /* [Rn, Rik] */
0110f2b8
PB
11641 if (Rn <= 7 && inst.operands[1].imm <= 7)
11642 goto op16;
5be8be5d
DG
11643 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11644 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11645 }
11646 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11647 && opcode != T_MNEM_ldrsb)
11648 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11649 || (Rn == REG_SP && opcode == T_MNEM_str))
11650 {
11651 /* [Rn, #const] */
11652 if (Rn > 7)
11653 {
11654 if (Rn == REG_PC)
11655 {
11656 if (inst.reloc.pc_rel)
11657 opcode = T_MNEM_ldr_pc2;
11658 else
11659 opcode = T_MNEM_ldr_pc;
11660 }
11661 else
11662 {
11663 if (opcode == T_MNEM_ldr)
11664 opcode = T_MNEM_ldr_sp;
11665 else
11666 opcode = T_MNEM_str_sp;
11667 }
11668 inst.instruction = inst.operands[0].reg << 8;
11669 }
11670 else
11671 {
11672 inst.instruction = inst.operands[0].reg;
11673 inst.instruction |= inst.operands[1].reg << 3;
11674 }
11675 inst.instruction |= THUMB_OP16 (opcode);
11676 if (inst.size_req == 2)
11677 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11678 else
11679 inst.relax = opcode;
11680 return;
11681 }
c19d1205 11682 }
0110f2b8 11683 /* Definitely a 32-bit variant. */
5be8be5d 11684
8d67f500
NC
11685 /* Warning for Erratum 752419. */
11686 if (opcode == T_MNEM_ldr
11687 && inst.operands[0].reg == REG_SP
11688 && inst.operands[1].writeback == 1
11689 && !inst.operands[1].immisreg)
11690 {
11691 if (no_cpu_selected ()
11692 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11693 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11694 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11695 as_warn (_("This instruction may be unpredictable "
11696 "if executed on M-profile cores "
11697 "with interrupts enabled."));
11698 }
11699
5be8be5d 11700 /* Do some validations regarding addressing modes. */
1be5fd2e 11701 if (inst.operands[1].immisreg)
5be8be5d
DG
11702 reject_bad_reg (inst.operands[1].imm);
11703
1be5fd2e
NC
11704 constraint (inst.operands[1].writeback == 1
11705 && inst.operands[0].reg == inst.operands[1].reg,
11706 BAD_OVERLAP);
11707
0110f2b8 11708 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11709 inst.instruction |= inst.operands[0].reg << 12;
11710 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11711 check_ldr_r15_aligned ();
b99bd4ef
NC
11712 return;
11713 }
11714
c19d1205
ZW
11715 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11716
11717 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11718 {
c19d1205
ZW
11719 /* Only [Rn,Rm] is acceptable. */
11720 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11721 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11722 || inst.operands[1].postind || inst.operands[1].shifted
11723 || inst.operands[1].negative,
11724 _("Thumb does not support this addressing mode"));
11725 inst.instruction = THUMB_OP16 (inst.instruction);
11726 goto op16;
b99bd4ef 11727 }
5f4273c7 11728
c19d1205
ZW
11729 inst.instruction = THUMB_OP16 (inst.instruction);
11730 if (!inst.operands[1].isreg)
8335d6aa 11731 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11732 return;
b99bd4ef 11733
c19d1205
ZW
11734 constraint (!inst.operands[1].preind
11735 || inst.operands[1].shifted
11736 || inst.operands[1].writeback,
11737 _("Thumb does not support this addressing mode"));
11738 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11739 {
c19d1205
ZW
11740 constraint (inst.instruction & 0x0600,
11741 _("byte or halfword not valid for base register"));
11742 constraint (inst.operands[1].reg == REG_PC
11743 && !(inst.instruction & THUMB_LOAD_BIT),
11744 _("r15 based store not allowed"));
11745 constraint (inst.operands[1].immisreg,
11746 _("invalid base register for register offset"));
b99bd4ef 11747
c19d1205
ZW
11748 if (inst.operands[1].reg == REG_PC)
11749 inst.instruction = T_OPCODE_LDR_PC;
11750 else if (inst.instruction & THUMB_LOAD_BIT)
11751 inst.instruction = T_OPCODE_LDR_SP;
11752 else
11753 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11754
c19d1205
ZW
11755 inst.instruction |= inst.operands[0].reg << 8;
11756 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11757 return;
11758 }
90e4755a 11759
c19d1205
ZW
11760 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11761 if (!inst.operands[1].immisreg)
11762 {
11763 /* Immediate offset. */
11764 inst.instruction |= inst.operands[0].reg;
11765 inst.instruction |= inst.operands[1].reg << 3;
11766 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11767 return;
11768 }
90e4755a 11769
c19d1205
ZW
11770 /* Register offset. */
11771 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11772 constraint (inst.operands[1].negative,
11773 _("Thumb does not support this addressing mode"));
90e4755a 11774
c19d1205
ZW
11775 op16:
11776 switch (inst.instruction)
11777 {
11778 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11779 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11780 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11781 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11782 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11783 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11784 case 0x5600 /* ldrsb */:
11785 case 0x5e00 /* ldrsh */: break;
11786 default: abort ();
11787 }
90e4755a 11788
c19d1205
ZW
11789 inst.instruction |= inst.operands[0].reg;
11790 inst.instruction |= inst.operands[1].reg << 3;
11791 inst.instruction |= inst.operands[1].imm << 6;
11792}
90e4755a 11793
c19d1205
ZW
11794static void
11795do_t_ldstd (void)
11796{
11797 if (!inst.operands[1].present)
b99bd4ef 11798 {
c19d1205
ZW
11799 inst.operands[1].reg = inst.operands[0].reg + 1;
11800 constraint (inst.operands[0].reg == REG_LR,
11801 _("r14 not allowed here"));
bd340a04 11802 constraint (inst.operands[0].reg == REG_R12,
477330fc 11803 _("r12 not allowed here"));
b99bd4ef 11804 }
bd340a04
MGD
11805
11806 if (inst.operands[2].writeback
11807 && (inst.operands[0].reg == inst.operands[2].reg
11808 || inst.operands[1].reg == inst.operands[2].reg))
11809 as_warn (_("base register written back, and overlaps "
477330fc 11810 "one of transfer registers"));
bd340a04 11811
c19d1205
ZW
11812 inst.instruction |= inst.operands[0].reg << 12;
11813 inst.instruction |= inst.operands[1].reg << 8;
11814 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11815}
11816
c19d1205
ZW
11817static void
11818do_t_ldstt (void)
11819{
11820 inst.instruction |= inst.operands[0].reg << 12;
11821 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11822}
a737bd4d 11823
b99bd4ef 11824static void
c19d1205 11825do_t_mla (void)
b99bd4ef 11826{
fdfde340 11827 unsigned Rd, Rn, Rm, Ra;
c921be7d 11828
fdfde340
JM
11829 Rd = inst.operands[0].reg;
11830 Rn = inst.operands[1].reg;
11831 Rm = inst.operands[2].reg;
11832 Ra = inst.operands[3].reg;
11833
11834 reject_bad_reg (Rd);
11835 reject_bad_reg (Rn);
11836 reject_bad_reg (Rm);
11837 reject_bad_reg (Ra);
11838
11839 inst.instruction |= Rd << 8;
11840 inst.instruction |= Rn << 16;
11841 inst.instruction |= Rm;
11842 inst.instruction |= Ra << 12;
c19d1205 11843}
b99bd4ef 11844
c19d1205
ZW
11845static void
11846do_t_mlal (void)
11847{
fdfde340
JM
11848 unsigned RdLo, RdHi, Rn, Rm;
11849
11850 RdLo = inst.operands[0].reg;
11851 RdHi = inst.operands[1].reg;
11852 Rn = inst.operands[2].reg;
11853 Rm = inst.operands[3].reg;
11854
11855 reject_bad_reg (RdLo);
11856 reject_bad_reg (RdHi);
11857 reject_bad_reg (Rn);
11858 reject_bad_reg (Rm);
11859
11860 inst.instruction |= RdLo << 12;
11861 inst.instruction |= RdHi << 8;
11862 inst.instruction |= Rn << 16;
11863 inst.instruction |= Rm;
c19d1205 11864}
b99bd4ef 11865
c19d1205
ZW
11866static void
11867do_t_mov_cmp (void)
11868{
fdfde340
JM
11869 unsigned Rn, Rm;
11870
11871 Rn = inst.operands[0].reg;
11872 Rm = inst.operands[1].reg;
11873
e07e6e58
NC
11874 if (Rn == REG_PC)
11875 set_it_insn_type_last ();
11876
c19d1205 11877 if (unified_syntax)
b99bd4ef 11878 {
c19d1205
ZW
11879 int r0off = (inst.instruction == T_MNEM_mov
11880 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11881 unsigned long opcode;
3d388997
PB
11882 bfd_boolean narrow;
11883 bfd_boolean low_regs;
11884
fdfde340 11885 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11886 opcode = inst.instruction;
e07e6e58 11887 if (in_it_block ())
0110f2b8 11888 narrow = opcode != T_MNEM_movs;
3d388997 11889 else
0110f2b8 11890 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11891 if (inst.size_req == 4
11892 || inst.operands[1].shifted)
11893 narrow = FALSE;
11894
efd81785
PB
11895 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11896 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11897 && !inst.operands[1].shifted
fdfde340
JM
11898 && Rn == REG_PC
11899 && Rm == REG_LR)
efd81785
PB
11900 {
11901 inst.instruction = T2_SUBS_PC_LR;
11902 return;
11903 }
11904
fdfde340
JM
11905 if (opcode == T_MNEM_cmp)
11906 {
11907 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11908 if (narrow)
11909 {
11910 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11911 but valid. */
11912 warn_deprecated_sp (Rm);
11913 /* R15 was documented as a valid choice for Rm in ARMv6,
11914 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11915 tools reject R15, so we do too. */
11916 constraint (Rm == REG_PC, BAD_PC);
11917 }
11918 else
11919 reject_bad_reg (Rm);
fdfde340
JM
11920 }
11921 else if (opcode == T_MNEM_mov
11922 || opcode == T_MNEM_movs)
11923 {
11924 if (inst.operands[1].isreg)
11925 {
11926 if (opcode == T_MNEM_movs)
11927 {
11928 reject_bad_reg (Rn);
11929 reject_bad_reg (Rm);
11930 }
76fa04a4
MGD
11931 else if (narrow)
11932 {
11933 /* This is mov.n. */
11934 if ((Rn == REG_SP || Rn == REG_PC)
11935 && (Rm == REG_SP || Rm == REG_PC))
11936 {
5c3696f8 11937 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11938 "deprecated when r%u is the destination "
11939 "register."), Rm, Rn);
11940 }
11941 }
11942 else
11943 {
11944 /* This is mov.w. */
11945 constraint (Rn == REG_PC, BAD_PC);
11946 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
11947 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11948 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 11949 }
fdfde340
JM
11950 }
11951 else
11952 reject_bad_reg (Rn);
11953 }
11954
c19d1205
ZW
11955 if (!inst.operands[1].isreg)
11956 {
0110f2b8 11957 /* Immediate operand. */
e07e6e58 11958 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11959 narrow = 0;
11960 if (low_regs && narrow)
11961 {
11962 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11963 inst.instruction |= Rn << 8;
a9f02af8
MG
11964 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11965 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11966 {
a9f02af8 11967 if (inst.size_req == 2)
72d98d16 11968 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11969 else
11970 inst.relax = opcode;
72d98d16 11971 }
0110f2b8
PB
11972 }
11973 else
11974 {
a9f02af8
MG
11975 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11976 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11977 THUMB1_RELOC_ONLY);
11978
0110f2b8
PB
11979 inst.instruction = THUMB_OP32 (inst.instruction);
11980 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11981 inst.instruction |= Rn << r0off;
0110f2b8
PB
11982 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11983 }
c19d1205 11984 }
728ca7c9
PB
11985 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11986 && (inst.instruction == T_MNEM_mov
11987 || inst.instruction == T_MNEM_movs))
11988 {
11989 /* Register shifts are encoded as separate shift instructions. */
11990 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11991
e07e6e58 11992 if (in_it_block ())
728ca7c9
PB
11993 narrow = !flags;
11994 else
11995 narrow = flags;
11996
11997 if (inst.size_req == 4)
11998 narrow = FALSE;
11999
12000 if (!low_regs || inst.operands[1].imm > 7)
12001 narrow = FALSE;
12002
fdfde340 12003 if (Rn != Rm)
728ca7c9
PB
12004 narrow = FALSE;
12005
12006 switch (inst.operands[1].shift_kind)
12007 {
12008 case SHIFT_LSL:
12009 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12010 break;
12011 case SHIFT_ASR:
12012 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12013 break;
12014 case SHIFT_LSR:
12015 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12016 break;
12017 case SHIFT_ROR:
12018 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12019 break;
12020 default:
5f4273c7 12021 abort ();
728ca7c9
PB
12022 }
12023
12024 inst.instruction = opcode;
12025 if (narrow)
12026 {
fdfde340 12027 inst.instruction |= Rn;
728ca7c9
PB
12028 inst.instruction |= inst.operands[1].imm << 3;
12029 }
12030 else
12031 {
12032 if (flags)
12033 inst.instruction |= CONDS_BIT;
12034
fdfde340
JM
12035 inst.instruction |= Rn << 8;
12036 inst.instruction |= Rm << 16;
728ca7c9
PB
12037 inst.instruction |= inst.operands[1].imm;
12038 }
12039 }
3d388997 12040 else if (!narrow)
c19d1205 12041 {
728ca7c9
PB
12042 /* Some mov with immediate shift have narrow variants.
12043 Register shifts are handled above. */
12044 if (low_regs && inst.operands[1].shifted
12045 && (inst.instruction == T_MNEM_mov
12046 || inst.instruction == T_MNEM_movs))
12047 {
e07e6e58 12048 if (in_it_block ())
728ca7c9
PB
12049 narrow = (inst.instruction == T_MNEM_mov);
12050 else
12051 narrow = (inst.instruction == T_MNEM_movs);
12052 }
12053
12054 if (narrow)
12055 {
12056 switch (inst.operands[1].shift_kind)
12057 {
12058 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12059 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12060 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12061 default: narrow = FALSE; break;
12062 }
12063 }
12064
12065 if (narrow)
12066 {
fdfde340
JM
12067 inst.instruction |= Rn;
12068 inst.instruction |= Rm << 3;
728ca7c9
PB
12069 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12070 }
12071 else
12072 {
12073 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12074 inst.instruction |= Rn << r0off;
728ca7c9
PB
12075 encode_thumb32_shifted_operand (1);
12076 }
c19d1205
ZW
12077 }
12078 else
12079 switch (inst.instruction)
12080 {
12081 case T_MNEM_mov:
837b3435 12082 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12083 results. Don't allow this. */
12084 if (low_regs)
12085 {
12086 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12087 "MOV Rd, Rs with two low registers is not "
12088 "permitted on this architecture");
fa94de6b 12089 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12090 arm_ext_v6);
12091 }
12092
c19d1205 12093 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12094 inst.instruction |= (Rn & 0x8) << 4;
12095 inst.instruction |= (Rn & 0x7);
12096 inst.instruction |= Rm << 3;
c19d1205 12097 break;
b99bd4ef 12098
c19d1205
ZW
12099 case T_MNEM_movs:
12100 /* We know we have low registers at this point.
941a8a52
MGD
12101 Generate LSLS Rd, Rs, #0. */
12102 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12103 inst.instruction |= Rn;
12104 inst.instruction |= Rm << 3;
c19d1205
ZW
12105 break;
12106
12107 case T_MNEM_cmp:
3d388997 12108 if (low_regs)
c19d1205
ZW
12109 {
12110 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12111 inst.instruction |= Rn;
12112 inst.instruction |= Rm << 3;
c19d1205
ZW
12113 }
12114 else
12115 {
12116 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12117 inst.instruction |= (Rn & 0x8) << 4;
12118 inst.instruction |= (Rn & 0x7);
12119 inst.instruction |= Rm << 3;
c19d1205
ZW
12120 }
12121 break;
12122 }
b99bd4ef
NC
12123 return;
12124 }
12125
c19d1205 12126 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12127
12128 /* PR 10443: Do not silently ignore shifted operands. */
12129 constraint (inst.operands[1].shifted,
12130 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12131
c19d1205 12132 if (inst.operands[1].isreg)
b99bd4ef 12133 {
fdfde340 12134 if (Rn < 8 && Rm < 8)
b99bd4ef 12135 {
c19d1205
ZW
12136 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12137 since a MOV instruction produces unpredictable results. */
12138 if (inst.instruction == T_OPCODE_MOV_I8)
12139 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12140 else
c19d1205 12141 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12142
fdfde340
JM
12143 inst.instruction |= Rn;
12144 inst.instruction |= Rm << 3;
b99bd4ef
NC
12145 }
12146 else
12147 {
c19d1205
ZW
12148 if (inst.instruction == T_OPCODE_MOV_I8)
12149 inst.instruction = T_OPCODE_MOV_HR;
12150 else
12151 inst.instruction = T_OPCODE_CMP_HR;
12152 do_t_cpy ();
b99bd4ef
NC
12153 }
12154 }
c19d1205 12155 else
b99bd4ef 12156 {
fdfde340 12157 constraint (Rn > 7,
c19d1205 12158 _("only lo regs allowed with immediate"));
fdfde340 12159 inst.instruction |= Rn << 8;
c19d1205
ZW
12160 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12161 }
12162}
b99bd4ef 12163
c19d1205
ZW
12164static void
12165do_t_mov16 (void)
12166{
fdfde340 12167 unsigned Rd;
b6895b4f
PB
12168 bfd_vma imm;
12169 bfd_boolean top;
12170
12171 top = (inst.instruction & 0x00800000) != 0;
12172 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12173 {
33eaf5de 12174 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12175 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12176 }
12177 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12178 {
33eaf5de 12179 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12180 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12181 }
12182
fdfde340
JM
12183 Rd = inst.operands[0].reg;
12184 reject_bad_reg (Rd);
12185
12186 inst.instruction |= Rd << 8;
b6895b4f
PB
12187 if (inst.reloc.type == BFD_RELOC_UNUSED)
12188 {
12189 imm = inst.reloc.exp.X_add_number;
12190 inst.instruction |= (imm & 0xf000) << 4;
12191 inst.instruction |= (imm & 0x0800) << 15;
12192 inst.instruction |= (imm & 0x0700) << 4;
12193 inst.instruction |= (imm & 0x00ff);
12194 }
c19d1205 12195}
b99bd4ef 12196
c19d1205
ZW
12197static void
12198do_t_mvn_tst (void)
12199{
fdfde340 12200 unsigned Rn, Rm;
c921be7d 12201
fdfde340
JM
12202 Rn = inst.operands[0].reg;
12203 Rm = inst.operands[1].reg;
12204
12205 if (inst.instruction == T_MNEM_cmp
12206 || inst.instruction == T_MNEM_cmn)
12207 constraint (Rn == REG_PC, BAD_PC);
12208 else
12209 reject_bad_reg (Rn);
12210 reject_bad_reg (Rm);
12211
c19d1205
ZW
12212 if (unified_syntax)
12213 {
12214 int r0off = (inst.instruction == T_MNEM_mvn
12215 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12216 bfd_boolean narrow;
12217
12218 if (inst.size_req == 4
12219 || inst.instruction > 0xffff
12220 || inst.operands[1].shifted
fdfde340 12221 || Rn > 7 || Rm > 7)
3d388997 12222 narrow = FALSE;
fe8b4cc3
KT
12223 else if (inst.instruction == T_MNEM_cmn
12224 || inst.instruction == T_MNEM_tst)
3d388997
PB
12225 narrow = TRUE;
12226 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12227 narrow = !in_it_block ();
3d388997 12228 else
e07e6e58 12229 narrow = in_it_block ();
3d388997 12230
c19d1205 12231 if (!inst.operands[1].isreg)
b99bd4ef 12232 {
c19d1205
ZW
12233 /* For an immediate, we always generate a 32-bit opcode;
12234 section relaxation will shrink it later if possible. */
12235 if (inst.instruction < 0xffff)
12236 inst.instruction = THUMB_OP32 (inst.instruction);
12237 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12238 inst.instruction |= Rn << r0off;
c19d1205 12239 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12240 }
c19d1205 12241 else
b99bd4ef 12242 {
c19d1205 12243 /* See if we can do this with a 16-bit instruction. */
3d388997 12244 if (narrow)
b99bd4ef 12245 {
c19d1205 12246 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12247 inst.instruction |= Rn;
12248 inst.instruction |= Rm << 3;
b99bd4ef 12249 }
c19d1205 12250 else
b99bd4ef 12251 {
c19d1205
ZW
12252 constraint (inst.operands[1].shifted
12253 && inst.operands[1].immisreg,
12254 _("shift must be constant"));
12255 if (inst.instruction < 0xffff)
12256 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12257 inst.instruction |= Rn << r0off;
c19d1205 12258 encode_thumb32_shifted_operand (1);
b99bd4ef 12259 }
b99bd4ef
NC
12260 }
12261 }
12262 else
12263 {
c19d1205
ZW
12264 constraint (inst.instruction > 0xffff
12265 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12266 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12267 _("unshifted register required"));
fdfde340 12268 constraint (Rn > 7 || Rm > 7,
c19d1205 12269 BAD_HIREG);
b99bd4ef 12270
c19d1205 12271 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12272 inst.instruction |= Rn;
12273 inst.instruction |= Rm << 3;
b99bd4ef 12274 }
b99bd4ef
NC
12275}
12276
b05fe5cf 12277static void
c19d1205 12278do_t_mrs (void)
b05fe5cf 12279{
fdfde340 12280 unsigned Rd;
037e8744
JB
12281
12282 if (do_vfp_nsyn_mrs () == SUCCESS)
12283 return;
12284
90ec0d68
MGD
12285 Rd = inst.operands[0].reg;
12286 reject_bad_reg (Rd);
12287 inst.instruction |= Rd << 8;
12288
12289 if (inst.operands[1].isreg)
62b3e311 12290 {
90ec0d68
MGD
12291 unsigned br = inst.operands[1].reg;
12292 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12293 as_bad (_("bad register for mrs"));
12294
12295 inst.instruction |= br & (0xf << 16);
12296 inst.instruction |= (br & 0x300) >> 4;
12297 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12298 }
12299 else
12300 {
90ec0d68 12301 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12302
d2cd1205 12303 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12304 {
12305 /* PR gas/12698: The constraint is only applied for m_profile.
12306 If the user has specified -march=all, we want to ignore it as
12307 we are building for any CPU type, including non-m variants. */
823d2571
TG
12308 bfd_boolean m_profile =
12309 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12310 constraint ((flags != 0) && m_profile, _("selected processor does "
12311 "not support requested special purpose register"));
12312 }
90ec0d68 12313 else
d2cd1205
JB
12314 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12315 devices). */
12316 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12317 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12318
90ec0d68
MGD
12319 inst.instruction |= (flags & SPSR_BIT) >> 2;
12320 inst.instruction |= inst.operands[1].imm & 0xff;
12321 inst.instruction |= 0xf0000;
12322 }
c19d1205 12323}
b05fe5cf 12324
c19d1205
ZW
12325static void
12326do_t_msr (void)
12327{
62b3e311 12328 int flags;
fdfde340 12329 unsigned Rn;
62b3e311 12330
037e8744
JB
12331 if (do_vfp_nsyn_msr () == SUCCESS)
12332 return;
12333
c19d1205
ZW
12334 constraint (!inst.operands[1].isreg,
12335 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12336
12337 if (inst.operands[0].isreg)
12338 flags = (int)(inst.operands[0].reg);
12339 else
12340 flags = inst.operands[0].imm;
12341
d2cd1205 12342 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12343 {
d2cd1205
JB
12344 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12345
1a43faaf 12346 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12347 If the user has specified -march=all, we want to ignore it as
12348 we are building for any CPU type, including non-m variants. */
823d2571
TG
12349 bfd_boolean m_profile =
12350 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12351 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12352 && (bits & ~(PSR_s | PSR_f)) != 0)
12353 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12354 && bits != PSR_f)) && m_profile,
12355 _("selected processor does not support requested special "
12356 "purpose register"));
62b3e311
PB
12357 }
12358 else
d2cd1205
JB
12359 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12360 "requested special purpose register"));
c921be7d 12361
fdfde340
JM
12362 Rn = inst.operands[1].reg;
12363 reject_bad_reg (Rn);
12364
62b3e311 12365 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12366 inst.instruction |= (flags & 0xf0000) >> 8;
12367 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12368 inst.instruction |= (flags & 0xff);
fdfde340 12369 inst.instruction |= Rn << 16;
c19d1205 12370}
b05fe5cf 12371
c19d1205
ZW
12372static void
12373do_t_mul (void)
12374{
17828f45 12375 bfd_boolean narrow;
fdfde340 12376 unsigned Rd, Rn, Rm;
17828f45 12377
c19d1205
ZW
12378 if (!inst.operands[2].present)
12379 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12380
fdfde340
JM
12381 Rd = inst.operands[0].reg;
12382 Rn = inst.operands[1].reg;
12383 Rm = inst.operands[2].reg;
12384
17828f45 12385 if (unified_syntax)
b05fe5cf 12386 {
17828f45 12387 if (inst.size_req == 4
fdfde340
JM
12388 || (Rd != Rn
12389 && Rd != Rm)
12390 || Rn > 7
12391 || Rm > 7)
17828f45
JM
12392 narrow = FALSE;
12393 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12394 narrow = !in_it_block ();
17828f45 12395 else
e07e6e58 12396 narrow = in_it_block ();
b05fe5cf 12397 }
c19d1205 12398 else
b05fe5cf 12399 {
17828f45 12400 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12401 constraint (Rn > 7 || Rm > 7,
c19d1205 12402 BAD_HIREG);
17828f45
JM
12403 narrow = TRUE;
12404 }
b05fe5cf 12405
17828f45
JM
12406 if (narrow)
12407 {
12408 /* 16-bit MULS/Conditional MUL. */
c19d1205 12409 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12410 inst.instruction |= Rd;
b05fe5cf 12411
fdfde340
JM
12412 if (Rd == Rn)
12413 inst.instruction |= Rm << 3;
12414 else if (Rd == Rm)
12415 inst.instruction |= Rn << 3;
c19d1205
ZW
12416 else
12417 constraint (1, _("dest must overlap one source register"));
12418 }
17828f45
JM
12419 else
12420 {
e07e6e58
NC
12421 constraint (inst.instruction != T_MNEM_mul,
12422 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12423 /* 32-bit MUL. */
12424 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12425 inst.instruction |= Rd << 8;
12426 inst.instruction |= Rn << 16;
12427 inst.instruction |= Rm << 0;
12428
12429 reject_bad_reg (Rd);
12430 reject_bad_reg (Rn);
12431 reject_bad_reg (Rm);
17828f45 12432 }
c19d1205 12433}
b05fe5cf 12434
c19d1205
ZW
12435static void
12436do_t_mull (void)
12437{
fdfde340 12438 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12439
fdfde340
JM
12440 RdLo = inst.operands[0].reg;
12441 RdHi = inst.operands[1].reg;
12442 Rn = inst.operands[2].reg;
12443 Rm = inst.operands[3].reg;
12444
12445 reject_bad_reg (RdLo);
12446 reject_bad_reg (RdHi);
12447 reject_bad_reg (Rn);
12448 reject_bad_reg (Rm);
12449
12450 inst.instruction |= RdLo << 12;
12451 inst.instruction |= RdHi << 8;
12452 inst.instruction |= Rn << 16;
12453 inst.instruction |= Rm;
12454
12455 if (RdLo == RdHi)
c19d1205
ZW
12456 as_tsktsk (_("rdhi and rdlo must be different"));
12457}
b05fe5cf 12458
c19d1205
ZW
12459static void
12460do_t_nop (void)
12461{
e07e6e58
NC
12462 set_it_insn_type (NEUTRAL_IT_INSN);
12463
c19d1205
ZW
12464 if (unified_syntax)
12465 {
12466 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12467 {
c19d1205
ZW
12468 inst.instruction = THUMB_OP32 (inst.instruction);
12469 inst.instruction |= inst.operands[0].imm;
12470 }
12471 else
12472 {
bc2d1808
NC
12473 /* PR9722: Check for Thumb2 availability before
12474 generating a thumb2 nop instruction. */
afa62d5e 12475 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12476 {
12477 inst.instruction = THUMB_OP16 (inst.instruction);
12478 inst.instruction |= inst.operands[0].imm << 4;
12479 }
12480 else
12481 inst.instruction = 0x46c0;
c19d1205
ZW
12482 }
12483 }
12484 else
12485 {
12486 constraint (inst.operands[0].present,
12487 _("Thumb does not support NOP with hints"));
12488 inst.instruction = 0x46c0;
12489 }
12490}
b05fe5cf 12491
c19d1205
ZW
12492static void
12493do_t_neg (void)
12494{
12495 if (unified_syntax)
12496 {
3d388997
PB
12497 bfd_boolean narrow;
12498
12499 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12500 narrow = !in_it_block ();
3d388997 12501 else
e07e6e58 12502 narrow = in_it_block ();
3d388997
PB
12503 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12504 narrow = FALSE;
12505 if (inst.size_req == 4)
12506 narrow = FALSE;
12507
12508 if (!narrow)
c19d1205
ZW
12509 {
12510 inst.instruction = THUMB_OP32 (inst.instruction);
12511 inst.instruction |= inst.operands[0].reg << 8;
12512 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12513 }
12514 else
12515 {
c19d1205
ZW
12516 inst.instruction = THUMB_OP16 (inst.instruction);
12517 inst.instruction |= inst.operands[0].reg;
12518 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12519 }
12520 }
12521 else
12522 {
c19d1205
ZW
12523 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12524 BAD_HIREG);
12525 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12526
12527 inst.instruction = THUMB_OP16 (inst.instruction);
12528 inst.instruction |= inst.operands[0].reg;
12529 inst.instruction |= inst.operands[1].reg << 3;
12530 }
12531}
12532
1c444d06
JM
12533static void
12534do_t_orn (void)
12535{
12536 unsigned Rd, Rn;
12537
12538 Rd = inst.operands[0].reg;
12539 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12540
fdfde340
JM
12541 reject_bad_reg (Rd);
12542 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12543 reject_bad_reg (Rn);
12544
1c444d06
JM
12545 inst.instruction |= Rd << 8;
12546 inst.instruction |= Rn << 16;
12547
12548 if (!inst.operands[2].isreg)
12549 {
12550 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12551 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12552 }
12553 else
12554 {
12555 unsigned Rm;
12556
12557 Rm = inst.operands[2].reg;
fdfde340 12558 reject_bad_reg (Rm);
1c444d06
JM
12559
12560 constraint (inst.operands[2].shifted
12561 && inst.operands[2].immisreg,
12562 _("shift must be constant"));
12563 encode_thumb32_shifted_operand (2);
12564 }
12565}
12566
c19d1205
ZW
12567static void
12568do_t_pkhbt (void)
12569{
fdfde340
JM
12570 unsigned Rd, Rn, Rm;
12571
12572 Rd = inst.operands[0].reg;
12573 Rn = inst.operands[1].reg;
12574 Rm = inst.operands[2].reg;
12575
12576 reject_bad_reg (Rd);
12577 reject_bad_reg (Rn);
12578 reject_bad_reg (Rm);
12579
12580 inst.instruction |= Rd << 8;
12581 inst.instruction |= Rn << 16;
12582 inst.instruction |= Rm;
c19d1205
ZW
12583 if (inst.operands[3].present)
12584 {
12585 unsigned int val = inst.reloc.exp.X_add_number;
12586 constraint (inst.reloc.exp.X_op != O_constant,
12587 _("expression too complex"));
12588 inst.instruction |= (val & 0x1c) << 10;
12589 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12590 }
c19d1205 12591}
b05fe5cf 12592
c19d1205
ZW
12593static void
12594do_t_pkhtb (void)
12595{
12596 if (!inst.operands[3].present)
1ef52f49
NC
12597 {
12598 unsigned Rtmp;
12599
12600 inst.instruction &= ~0x00000020;
12601
12602 /* PR 10168. Swap the Rm and Rn registers. */
12603 Rtmp = inst.operands[1].reg;
12604 inst.operands[1].reg = inst.operands[2].reg;
12605 inst.operands[2].reg = Rtmp;
12606 }
c19d1205 12607 do_t_pkhbt ();
b05fe5cf
ZW
12608}
12609
c19d1205
ZW
12610static void
12611do_t_pld (void)
12612{
fdfde340
JM
12613 if (inst.operands[0].immisreg)
12614 reject_bad_reg (inst.operands[0].imm);
12615
c19d1205
ZW
12616 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12617}
b05fe5cf 12618
c19d1205
ZW
12619static void
12620do_t_push_pop (void)
b99bd4ef 12621{
e9f89963 12622 unsigned mask;
5f4273c7 12623
c19d1205
ZW
12624 constraint (inst.operands[0].writeback,
12625 _("push/pop do not support {reglist}^"));
12626 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12627 _("expression too complex"));
b99bd4ef 12628
e9f89963 12629 mask = inst.operands[0].imm;
d3bfe16e 12630 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12631 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12632 else if (inst.size_req != 4
c6025a80 12633 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12634 ? REG_LR : REG_PC)))
b99bd4ef 12635 {
c19d1205
ZW
12636 inst.instruction = THUMB_OP16 (inst.instruction);
12637 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12638 inst.instruction |= mask & 0xff;
c19d1205
ZW
12639 }
12640 else if (unified_syntax)
12641 {
3c707909 12642 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12643 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12644 }
12645 else
12646 {
12647 inst.error = _("invalid register list to push/pop instruction");
12648 return;
12649 }
c19d1205 12650}
b99bd4ef 12651
c19d1205
ZW
12652static void
12653do_t_rbit (void)
12654{
fdfde340
JM
12655 unsigned Rd, Rm;
12656
12657 Rd = inst.operands[0].reg;
12658 Rm = inst.operands[1].reg;
12659
12660 reject_bad_reg (Rd);
12661 reject_bad_reg (Rm);
12662
12663 inst.instruction |= Rd << 8;
12664 inst.instruction |= Rm << 16;
12665 inst.instruction |= Rm;
c19d1205 12666}
b99bd4ef 12667
c19d1205
ZW
12668static void
12669do_t_rev (void)
12670{
fdfde340
JM
12671 unsigned Rd, Rm;
12672
12673 Rd = inst.operands[0].reg;
12674 Rm = inst.operands[1].reg;
12675
12676 reject_bad_reg (Rd);
12677 reject_bad_reg (Rm);
12678
12679 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12680 && inst.size_req != 4)
12681 {
12682 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12683 inst.instruction |= Rd;
12684 inst.instruction |= Rm << 3;
c19d1205
ZW
12685 }
12686 else if (unified_syntax)
12687 {
12688 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12689 inst.instruction |= Rd << 8;
12690 inst.instruction |= Rm << 16;
12691 inst.instruction |= Rm;
c19d1205
ZW
12692 }
12693 else
12694 inst.error = BAD_HIREG;
12695}
b99bd4ef 12696
1c444d06
JM
12697static void
12698do_t_rrx (void)
12699{
12700 unsigned Rd, Rm;
12701
12702 Rd = inst.operands[0].reg;
12703 Rm = inst.operands[1].reg;
12704
fdfde340
JM
12705 reject_bad_reg (Rd);
12706 reject_bad_reg (Rm);
c921be7d 12707
1c444d06
JM
12708 inst.instruction |= Rd << 8;
12709 inst.instruction |= Rm;
12710}
12711
c19d1205
ZW
12712static void
12713do_t_rsb (void)
12714{
fdfde340 12715 unsigned Rd, Rs;
b99bd4ef 12716
c19d1205
ZW
12717 Rd = inst.operands[0].reg;
12718 Rs = (inst.operands[1].present
12719 ? inst.operands[1].reg /* Rd, Rs, foo */
12720 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12721
fdfde340
JM
12722 reject_bad_reg (Rd);
12723 reject_bad_reg (Rs);
12724 if (inst.operands[2].isreg)
12725 reject_bad_reg (inst.operands[2].reg);
12726
c19d1205
ZW
12727 inst.instruction |= Rd << 8;
12728 inst.instruction |= Rs << 16;
12729 if (!inst.operands[2].isreg)
12730 {
026d3abb
PB
12731 bfd_boolean narrow;
12732
12733 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12734 narrow = !in_it_block ();
026d3abb 12735 else
e07e6e58 12736 narrow = in_it_block ();
026d3abb
PB
12737
12738 if (Rd > 7 || Rs > 7)
12739 narrow = FALSE;
12740
12741 if (inst.size_req == 4 || !unified_syntax)
12742 narrow = FALSE;
12743
12744 if (inst.reloc.exp.X_op != O_constant
12745 || inst.reloc.exp.X_add_number != 0)
12746 narrow = FALSE;
12747
12748 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12749 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12750 if (narrow)
12751 {
12752 inst.reloc.type = BFD_RELOC_UNUSED;
12753 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12754 inst.instruction |= Rs << 3;
12755 inst.instruction |= Rd;
12756 }
12757 else
12758 {
12759 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12760 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12761 }
c19d1205
ZW
12762 }
12763 else
12764 encode_thumb32_shifted_operand (2);
12765}
b99bd4ef 12766
c19d1205
ZW
12767static void
12768do_t_setend (void)
12769{
12e37cbc
MGD
12770 if (warn_on_deprecated
12771 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12772 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12773
e07e6e58 12774 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12775 if (inst.operands[0].imm)
12776 inst.instruction |= 0x8;
12777}
b99bd4ef 12778
c19d1205
ZW
12779static void
12780do_t_shift (void)
12781{
12782 if (!inst.operands[1].present)
12783 inst.operands[1].reg = inst.operands[0].reg;
12784
12785 if (unified_syntax)
12786 {
3d388997
PB
12787 bfd_boolean narrow;
12788 int shift_kind;
12789
12790 switch (inst.instruction)
12791 {
12792 case T_MNEM_asr:
12793 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12794 case T_MNEM_lsl:
12795 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12796 case T_MNEM_lsr:
12797 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12798 case T_MNEM_ror:
12799 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12800 default: abort ();
12801 }
12802
12803 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12804 narrow = !in_it_block ();
3d388997 12805 else
e07e6e58 12806 narrow = in_it_block ();
3d388997
PB
12807 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12808 narrow = FALSE;
12809 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12810 narrow = FALSE;
12811 if (inst.operands[2].isreg
12812 && (inst.operands[1].reg != inst.operands[0].reg
12813 || inst.operands[2].reg > 7))
12814 narrow = FALSE;
12815 if (inst.size_req == 4)
12816 narrow = FALSE;
12817
fdfde340
JM
12818 reject_bad_reg (inst.operands[0].reg);
12819 reject_bad_reg (inst.operands[1].reg);
c921be7d 12820
3d388997 12821 if (!narrow)
c19d1205
ZW
12822 {
12823 if (inst.operands[2].isreg)
b99bd4ef 12824 {
fdfde340 12825 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12826 inst.instruction = THUMB_OP32 (inst.instruction);
12827 inst.instruction |= inst.operands[0].reg << 8;
12828 inst.instruction |= inst.operands[1].reg << 16;
12829 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12830
12831 /* PR 12854: Error on extraneous shifts. */
12832 constraint (inst.operands[2].shifted,
12833 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12834 }
12835 else
12836 {
12837 inst.operands[1].shifted = 1;
3d388997 12838 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12839 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12840 ? T_MNEM_movs : T_MNEM_mov);
12841 inst.instruction |= inst.operands[0].reg << 8;
12842 encode_thumb32_shifted_operand (1);
12843 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12844 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12845 }
12846 }
12847 else
12848 {
c19d1205 12849 if (inst.operands[2].isreg)
b99bd4ef 12850 {
3d388997 12851 switch (shift_kind)
b99bd4ef 12852 {
3d388997
PB
12853 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12854 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12855 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12856 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12857 default: abort ();
b99bd4ef 12858 }
5f4273c7 12859
c19d1205
ZW
12860 inst.instruction |= inst.operands[0].reg;
12861 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12862
12863 /* PR 12854: Error on extraneous shifts. */
12864 constraint (inst.operands[2].shifted,
12865 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12866 }
12867 else
12868 {
3d388997 12869 switch (shift_kind)
b99bd4ef 12870 {
3d388997
PB
12871 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12872 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12873 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12874 default: abort ();
b99bd4ef 12875 }
c19d1205
ZW
12876 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12877 inst.instruction |= inst.operands[0].reg;
12878 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12879 }
12880 }
c19d1205
ZW
12881 }
12882 else
12883 {
12884 constraint (inst.operands[0].reg > 7
12885 || inst.operands[1].reg > 7, BAD_HIREG);
12886 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12887
c19d1205
ZW
12888 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12889 {
12890 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12891 constraint (inst.operands[0].reg != inst.operands[1].reg,
12892 _("source1 and dest must be same register"));
b99bd4ef 12893
c19d1205
ZW
12894 switch (inst.instruction)
12895 {
12896 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12897 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12898 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12899 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12900 default: abort ();
12901 }
5f4273c7 12902
c19d1205
ZW
12903 inst.instruction |= inst.operands[0].reg;
12904 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12905
12906 /* PR 12854: Error on extraneous shifts. */
12907 constraint (inst.operands[2].shifted,
12908 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12909 }
12910 else
b99bd4ef 12911 {
c19d1205
ZW
12912 switch (inst.instruction)
12913 {
12914 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12915 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12916 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12917 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12918 default: abort ();
12919 }
12920 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12921 inst.instruction |= inst.operands[0].reg;
12922 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12923 }
12924 }
b99bd4ef
NC
12925}
12926
12927static void
c19d1205 12928do_t_simd (void)
b99bd4ef 12929{
fdfde340
JM
12930 unsigned Rd, Rn, Rm;
12931
12932 Rd = inst.operands[0].reg;
12933 Rn = inst.operands[1].reg;
12934 Rm = inst.operands[2].reg;
12935
12936 reject_bad_reg (Rd);
12937 reject_bad_reg (Rn);
12938 reject_bad_reg (Rm);
12939
12940 inst.instruction |= Rd << 8;
12941 inst.instruction |= Rn << 16;
12942 inst.instruction |= Rm;
c19d1205 12943}
b99bd4ef 12944
03ee1b7f
NC
12945static void
12946do_t_simd2 (void)
12947{
12948 unsigned Rd, Rn, Rm;
12949
12950 Rd = inst.operands[0].reg;
12951 Rm = inst.operands[1].reg;
12952 Rn = inst.operands[2].reg;
12953
12954 reject_bad_reg (Rd);
12955 reject_bad_reg (Rn);
12956 reject_bad_reg (Rm);
12957
12958 inst.instruction |= Rd << 8;
12959 inst.instruction |= Rn << 16;
12960 inst.instruction |= Rm;
12961}
12962
c19d1205 12963static void
3eb17e6b 12964do_t_smc (void)
c19d1205
ZW
12965{
12966 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12967 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12968 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12969 constraint (inst.reloc.exp.X_op != O_constant,
12970 _("expression too complex"));
12971 inst.reloc.type = BFD_RELOC_UNUSED;
12972 inst.instruction |= (value & 0xf000) >> 12;
12973 inst.instruction |= (value & 0x0ff0);
12974 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12975 /* PR gas/15623: SMC instructions must be last in an IT block. */
12976 set_it_insn_type_last ();
c19d1205 12977}
b99bd4ef 12978
90ec0d68
MGD
12979static void
12980do_t_hvc (void)
12981{
12982 unsigned int value = inst.reloc.exp.X_add_number;
12983
12984 inst.reloc.type = BFD_RELOC_UNUSED;
12985 inst.instruction |= (value & 0x0fff);
12986 inst.instruction |= (value & 0xf000) << 4;
12987}
12988
c19d1205 12989static void
3a21c15a 12990do_t_ssat_usat (int bias)
c19d1205 12991{
fdfde340
JM
12992 unsigned Rd, Rn;
12993
12994 Rd = inst.operands[0].reg;
12995 Rn = inst.operands[2].reg;
12996
12997 reject_bad_reg (Rd);
12998 reject_bad_reg (Rn);
12999
13000 inst.instruction |= Rd << 8;
3a21c15a 13001 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13002 inst.instruction |= Rn << 16;
b99bd4ef 13003
c19d1205 13004 if (inst.operands[3].present)
b99bd4ef 13005 {
3a21c15a
NC
13006 offsetT shift_amount = inst.reloc.exp.X_add_number;
13007
13008 inst.reloc.type = BFD_RELOC_UNUSED;
13009
c19d1205
ZW
13010 constraint (inst.reloc.exp.X_op != O_constant,
13011 _("expression too complex"));
b99bd4ef 13012
3a21c15a 13013 if (shift_amount != 0)
6189168b 13014 {
3a21c15a
NC
13015 constraint (shift_amount > 31,
13016 _("shift expression is too large"));
13017
c19d1205 13018 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13019 inst.instruction |= 0x00200000; /* sh bit. */
13020
13021 inst.instruction |= (shift_amount & 0x1c) << 10;
13022 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13023 }
13024 }
b99bd4ef 13025}
c921be7d 13026
3a21c15a
NC
13027static void
13028do_t_ssat (void)
13029{
13030 do_t_ssat_usat (1);
13031}
b99bd4ef 13032
0dd132b6 13033static void
c19d1205 13034do_t_ssat16 (void)
0dd132b6 13035{
fdfde340
JM
13036 unsigned Rd, Rn;
13037
13038 Rd = inst.operands[0].reg;
13039 Rn = inst.operands[2].reg;
13040
13041 reject_bad_reg (Rd);
13042 reject_bad_reg (Rn);
13043
13044 inst.instruction |= Rd << 8;
c19d1205 13045 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13046 inst.instruction |= Rn << 16;
c19d1205 13047}
0dd132b6 13048
c19d1205
ZW
13049static void
13050do_t_strex (void)
13051{
13052 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13053 || inst.operands[2].postind || inst.operands[2].writeback
13054 || inst.operands[2].immisreg || inst.operands[2].shifted
13055 || inst.operands[2].negative,
01cfc07f 13056 BAD_ADDR_MODE);
0dd132b6 13057
5be8be5d
DG
13058 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13059
c19d1205
ZW
13060 inst.instruction |= inst.operands[0].reg << 8;
13061 inst.instruction |= inst.operands[1].reg << 12;
13062 inst.instruction |= inst.operands[2].reg << 16;
13063 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13064}
13065
b99bd4ef 13066static void
c19d1205 13067do_t_strexd (void)
b99bd4ef 13068{
c19d1205
ZW
13069 if (!inst.operands[2].present)
13070 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13071
c19d1205
ZW
13072 constraint (inst.operands[0].reg == inst.operands[1].reg
13073 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13074 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13075 BAD_OVERLAP);
b99bd4ef 13076
c19d1205
ZW
13077 inst.instruction |= inst.operands[0].reg;
13078 inst.instruction |= inst.operands[1].reg << 12;
13079 inst.instruction |= inst.operands[2].reg << 8;
13080 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13081}
13082
13083static void
c19d1205 13084do_t_sxtah (void)
b99bd4ef 13085{
fdfde340
JM
13086 unsigned Rd, Rn, Rm;
13087
13088 Rd = inst.operands[0].reg;
13089 Rn = inst.operands[1].reg;
13090 Rm = inst.operands[2].reg;
13091
13092 reject_bad_reg (Rd);
13093 reject_bad_reg (Rn);
13094 reject_bad_reg (Rm);
13095
13096 inst.instruction |= Rd << 8;
13097 inst.instruction |= Rn << 16;
13098 inst.instruction |= Rm;
c19d1205
ZW
13099 inst.instruction |= inst.operands[3].imm << 4;
13100}
b99bd4ef 13101
c19d1205
ZW
13102static void
13103do_t_sxth (void)
13104{
fdfde340
JM
13105 unsigned Rd, Rm;
13106
13107 Rd = inst.operands[0].reg;
13108 Rm = inst.operands[1].reg;
13109
13110 reject_bad_reg (Rd);
13111 reject_bad_reg (Rm);
c921be7d
NC
13112
13113 if (inst.instruction <= 0xffff
13114 && inst.size_req != 4
fdfde340 13115 && Rd <= 7 && Rm <= 7
c19d1205 13116 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13117 {
c19d1205 13118 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13119 inst.instruction |= Rd;
13120 inst.instruction |= Rm << 3;
b99bd4ef 13121 }
c19d1205 13122 else if (unified_syntax)
b99bd4ef 13123 {
c19d1205
ZW
13124 if (inst.instruction <= 0xffff)
13125 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13126 inst.instruction |= Rd << 8;
13127 inst.instruction |= Rm;
c19d1205 13128 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13129 }
c19d1205 13130 else
b99bd4ef 13131 {
c19d1205
ZW
13132 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13133 _("Thumb encoding does not support rotation"));
13134 constraint (1, BAD_HIREG);
b99bd4ef 13135 }
c19d1205 13136}
b99bd4ef 13137
c19d1205
ZW
13138static void
13139do_t_swi (void)
13140{
13141 inst.reloc.type = BFD_RELOC_ARM_SWI;
13142}
b99bd4ef 13143
92e90b6e
PB
13144static void
13145do_t_tb (void)
13146{
fdfde340 13147 unsigned Rn, Rm;
92e90b6e
PB
13148 int half;
13149
13150 half = (inst.instruction & 0x10) != 0;
e07e6e58 13151 set_it_insn_type_last ();
dfa9f0d5
PB
13152 constraint (inst.operands[0].immisreg,
13153 _("instruction requires register index"));
fdfde340
JM
13154
13155 Rn = inst.operands[0].reg;
13156 Rm = inst.operands[0].imm;
c921be7d 13157
5c8ed6a4
JW
13158 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13159 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13160 reject_bad_reg (Rm);
13161
92e90b6e
PB
13162 constraint (!half && inst.operands[0].shifted,
13163 _("instruction does not allow shifted index"));
fdfde340 13164 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13165}
13166
74db7efb
NC
13167static void
13168do_t_udf (void)
13169{
13170 if (!inst.operands[0].present)
13171 inst.operands[0].imm = 0;
13172
13173 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13174 {
13175 constraint (inst.size_req == 2,
13176 _("immediate value out of range"));
13177 inst.instruction = THUMB_OP32 (inst.instruction);
13178 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13179 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13180 }
13181 else
13182 {
13183 inst.instruction = THUMB_OP16 (inst.instruction);
13184 inst.instruction |= inst.operands[0].imm;
13185 }
13186
13187 set_it_insn_type (NEUTRAL_IT_INSN);
13188}
13189
13190
c19d1205
ZW
13191static void
13192do_t_usat (void)
13193{
3a21c15a 13194 do_t_ssat_usat (0);
b99bd4ef
NC
13195}
13196
13197static void
c19d1205 13198do_t_usat16 (void)
b99bd4ef 13199{
fdfde340
JM
13200 unsigned Rd, Rn;
13201
13202 Rd = inst.operands[0].reg;
13203 Rn = inst.operands[2].reg;
13204
13205 reject_bad_reg (Rd);
13206 reject_bad_reg (Rn);
13207
13208 inst.instruction |= Rd << 8;
c19d1205 13209 inst.instruction |= inst.operands[1].imm;
fdfde340 13210 inst.instruction |= Rn << 16;
b99bd4ef 13211}
c19d1205 13212
5287ad62 13213/* Neon instruction encoder helpers. */
5f4273c7 13214
5287ad62 13215/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13216
5287ad62
JB
13217/* An "invalid" code for the following tables. */
13218#define N_INV -1u
13219
13220struct neon_tab_entry
b99bd4ef 13221{
5287ad62
JB
13222 unsigned integer;
13223 unsigned float_or_poly;
13224 unsigned scalar_or_imm;
13225};
5f4273c7 13226
5287ad62
JB
13227/* Map overloaded Neon opcodes to their respective encodings. */
13228#define NEON_ENC_TAB \
13229 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13230 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13231 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13232 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13233 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13234 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13235 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13236 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13237 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13238 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13239 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13240 /* Register variants of the following two instructions are encoded as
e07e6e58 13241 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13242 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13243 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13244 X(vfma, N_INV, 0x0000c10, N_INV), \
13245 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13246 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13247 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13248 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13249 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13250 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13251 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13252 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13253 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13254 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13255 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13256 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13257 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13258 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13259 X(vshl, 0x0000400, N_INV, 0x0800510), \
13260 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13261 X(vand, 0x0000110, N_INV, 0x0800030), \
13262 X(vbic, 0x0100110, N_INV, 0x0800030), \
13263 X(veor, 0x1000110, N_INV, N_INV), \
13264 X(vorn, 0x0300110, N_INV, 0x0800010), \
13265 X(vorr, 0x0200110, N_INV, 0x0800010), \
13266 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13267 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13268 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13269 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13270 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13271 X(vst1, 0x0000000, 0x0800000, N_INV), \
13272 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13273 X(vst2, 0x0000100, 0x0800100, N_INV), \
13274 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13275 X(vst3, 0x0000200, 0x0800200, N_INV), \
13276 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13277 X(vst4, 0x0000300, 0x0800300, N_INV), \
13278 X(vmovn, 0x1b20200, N_INV, N_INV), \
13279 X(vtrn, 0x1b20080, N_INV, N_INV), \
13280 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13281 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13282 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13283 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13284 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13285 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13286 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13287 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13288 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13289 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13290 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13291 X(vseleq, 0xe000a00, N_INV, N_INV), \
13292 X(vselvs, 0xe100a00, N_INV, N_INV), \
13293 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13294 X(vselgt, 0xe300a00, N_INV, N_INV), \
13295 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13296 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13297 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13298 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13299 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13300 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13301 X(sha3op, 0x2000c00, N_INV, N_INV), \
13302 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13303 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13304
13305enum neon_opc
13306{
13307#define X(OPC,I,F,S) N_MNEM_##OPC
13308NEON_ENC_TAB
13309#undef X
13310};
b99bd4ef 13311
5287ad62
JB
13312static const struct neon_tab_entry neon_enc_tab[] =
13313{
13314#define X(OPC,I,F,S) { (I), (F), (S) }
13315NEON_ENC_TAB
13316#undef X
13317};
b99bd4ef 13318
88714cb8
DG
13319/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13320#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13321#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13322#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13323#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13324#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13325#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13326#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13327#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13328#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13329#define NEON_ENC_SINGLE_(X) \
037e8744 13330 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13331#define NEON_ENC_DOUBLE_(X) \
037e8744 13332 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13333#define NEON_ENC_FPV8_(X) \
13334 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13335
88714cb8
DG
13336#define NEON_ENCODE(type, inst) \
13337 do \
13338 { \
13339 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13340 inst.is_neon = 1; \
13341 } \
13342 while (0)
13343
13344#define check_neon_suffixes \
13345 do \
13346 { \
13347 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13348 { \
13349 as_bad (_("invalid neon suffix for non neon instruction")); \
13350 return; \
13351 } \
13352 } \
13353 while (0)
13354
037e8744
JB
13355/* Define shapes for instruction operands. The following mnemonic characters
13356 are used in this table:
5287ad62 13357
037e8744 13358 F - VFP S<n> register
5287ad62
JB
13359 D - Neon D<n> register
13360 Q - Neon Q<n> register
13361 I - Immediate
13362 S - Scalar
13363 R - ARM register
13364 L - D<n> register list
5f4273c7 13365
037e8744
JB
13366 This table is used to generate various data:
13367 - enumerations of the form NS_DDR to be used as arguments to
13368 neon_select_shape.
13369 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13370 - a table used to drive neon_select_shape. */
b99bd4ef 13371
037e8744
JB
13372#define NEON_SHAPE_DEF \
13373 X(3, (D, D, D), DOUBLE), \
13374 X(3, (Q, Q, Q), QUAD), \
13375 X(3, (D, D, I), DOUBLE), \
13376 X(3, (Q, Q, I), QUAD), \
13377 X(3, (D, D, S), DOUBLE), \
13378 X(3, (Q, Q, S), QUAD), \
13379 X(2, (D, D), DOUBLE), \
13380 X(2, (Q, Q), QUAD), \
13381 X(2, (D, S), DOUBLE), \
13382 X(2, (Q, S), QUAD), \
13383 X(2, (D, R), DOUBLE), \
13384 X(2, (Q, R), QUAD), \
13385 X(2, (D, I), DOUBLE), \
13386 X(2, (Q, I), QUAD), \
13387 X(3, (D, L, D), DOUBLE), \
13388 X(2, (D, Q), MIXED), \
13389 X(2, (Q, D), MIXED), \
13390 X(3, (D, Q, I), MIXED), \
13391 X(3, (Q, D, I), MIXED), \
13392 X(3, (Q, D, D), MIXED), \
13393 X(3, (D, Q, Q), MIXED), \
13394 X(3, (Q, Q, D), MIXED), \
13395 X(3, (Q, D, S), MIXED), \
13396 X(3, (D, Q, S), MIXED), \
13397 X(4, (D, D, D, I), DOUBLE), \
13398 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13399 X(4, (D, D, S, I), DOUBLE), \
13400 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13401 X(2, (F, F), SINGLE), \
13402 X(3, (F, F, F), SINGLE), \
13403 X(2, (F, I), SINGLE), \
13404 X(2, (F, D), MIXED), \
13405 X(2, (D, F), MIXED), \
13406 X(3, (F, F, I), MIXED), \
13407 X(4, (R, R, F, F), SINGLE), \
13408 X(4, (F, F, R, R), SINGLE), \
13409 X(3, (D, R, R), DOUBLE), \
13410 X(3, (R, R, D), DOUBLE), \
13411 X(2, (S, R), SINGLE), \
13412 X(2, (R, S), SINGLE), \
13413 X(2, (F, R), SINGLE), \
d54af2d0
RL
13414 X(2, (R, F), SINGLE), \
13415/* Half float shape supported so far. */\
13416 X (2, (H, D), MIXED), \
13417 X (2, (D, H), MIXED), \
13418 X (2, (H, F), MIXED), \
13419 X (2, (F, H), MIXED), \
13420 X (2, (H, H), HALF), \
13421 X (2, (H, R), HALF), \
13422 X (2, (R, H), HALF), \
13423 X (2, (H, I), HALF), \
13424 X (3, (H, H, H), HALF), \
13425 X (3, (H, F, I), MIXED), \
13426 X (3, (F, H, I), MIXED)
037e8744
JB
13427
13428#define S2(A,B) NS_##A##B
13429#define S3(A,B,C) NS_##A##B##C
13430#define S4(A,B,C,D) NS_##A##B##C##D
13431
13432#define X(N, L, C) S##N L
13433
5287ad62
JB
13434enum neon_shape
13435{
037e8744
JB
13436 NEON_SHAPE_DEF,
13437 NS_NULL
5287ad62 13438};
b99bd4ef 13439
037e8744
JB
13440#undef X
13441#undef S2
13442#undef S3
13443#undef S4
13444
13445enum neon_shape_class
13446{
d54af2d0 13447 SC_HALF,
037e8744
JB
13448 SC_SINGLE,
13449 SC_DOUBLE,
13450 SC_QUAD,
13451 SC_MIXED
13452};
13453
13454#define X(N, L, C) SC_##C
13455
13456static enum neon_shape_class neon_shape_class[] =
13457{
13458 NEON_SHAPE_DEF
13459};
13460
13461#undef X
13462
13463enum neon_shape_el
13464{
d54af2d0 13465 SE_H,
037e8744
JB
13466 SE_F,
13467 SE_D,
13468 SE_Q,
13469 SE_I,
13470 SE_S,
13471 SE_R,
13472 SE_L
13473};
13474
13475/* Register widths of above. */
13476static unsigned neon_shape_el_size[] =
13477{
d54af2d0 13478 16,
037e8744
JB
13479 32,
13480 64,
13481 128,
13482 0,
13483 32,
13484 32,
13485 0
13486};
13487
13488struct neon_shape_info
13489{
13490 unsigned els;
13491 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13492};
13493
13494#define S2(A,B) { SE_##A, SE_##B }
13495#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13496#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13497
13498#define X(N, L, C) { N, S##N L }
13499
13500static struct neon_shape_info neon_shape_tab[] =
13501{
13502 NEON_SHAPE_DEF
13503};
13504
13505#undef X
13506#undef S2
13507#undef S3
13508#undef S4
13509
5287ad62
JB
13510/* Bit masks used in type checking given instructions.
13511 'N_EQK' means the type must be the same as (or based on in some way) the key
13512 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13513 set, various other bits can be set as well in order to modify the meaning of
13514 the type constraint. */
13515
13516enum neon_type_mask
13517{
8e79c3df
CM
13518 N_S8 = 0x0000001,
13519 N_S16 = 0x0000002,
13520 N_S32 = 0x0000004,
13521 N_S64 = 0x0000008,
13522 N_U8 = 0x0000010,
13523 N_U16 = 0x0000020,
13524 N_U32 = 0x0000040,
13525 N_U64 = 0x0000080,
13526 N_I8 = 0x0000100,
13527 N_I16 = 0x0000200,
13528 N_I32 = 0x0000400,
13529 N_I64 = 0x0000800,
13530 N_8 = 0x0001000,
13531 N_16 = 0x0002000,
13532 N_32 = 0x0004000,
13533 N_64 = 0x0008000,
13534 N_P8 = 0x0010000,
13535 N_P16 = 0x0020000,
13536 N_F16 = 0x0040000,
13537 N_F32 = 0x0080000,
13538 N_F64 = 0x0100000,
4f51b4bd 13539 N_P64 = 0x0200000,
c921be7d
NC
13540 N_KEY = 0x1000000, /* Key element (main type specifier). */
13541 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13542 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13543 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13544 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13545 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13546 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13547 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13548 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13549 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13550 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13551 N_UTYP = 0,
4f51b4bd 13552 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13553};
13554
dcbf9037
JB
13555#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13556
5287ad62
JB
13557#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13558#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13559#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13560#define N_S_32 (N_S8 | N_S16 | N_S32)
13561#define N_F_16_32 (N_F16 | N_F32)
13562#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13563#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13564#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13565#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13566
13567/* Pass this as the first type argument to neon_check_type to ignore types
13568 altogether. */
13569#define N_IGNORE_TYPE (N_KEY | N_EQK)
13570
037e8744
JB
13571/* Select a "shape" for the current instruction (describing register types or
13572 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13573 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13574 function of operand parsing, so this function doesn't need to be called.
13575 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13576
13577static enum neon_shape
037e8744 13578neon_select_shape (enum neon_shape shape, ...)
5287ad62 13579{
037e8744
JB
13580 va_list ap;
13581 enum neon_shape first_shape = shape;
5287ad62
JB
13582
13583 /* Fix missing optional operands. FIXME: we don't know at this point how
13584 many arguments we should have, so this makes the assumption that we have
13585 > 1. This is true of all current Neon opcodes, I think, but may not be
13586 true in the future. */
13587 if (!inst.operands[1].present)
13588 inst.operands[1] = inst.operands[0];
13589
037e8744 13590 va_start (ap, shape);
5f4273c7 13591
21d799b5 13592 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13593 {
13594 unsigned j;
13595 int matches = 1;
13596
13597 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13598 {
13599 if (!inst.operands[j].present)
13600 {
13601 matches = 0;
13602 break;
13603 }
13604
13605 switch (neon_shape_tab[shape].el[j])
13606 {
d54af2d0
RL
13607 /* If a .f16, .16, .u16, .s16 type specifier is given over
13608 a VFP single precision register operand, it's essentially
13609 means only half of the register is used.
13610
13611 If the type specifier is given after the mnemonics, the
13612 information is stored in inst.vectype. If the type specifier
13613 is given after register operand, the information is stored
13614 in inst.operands[].vectype.
13615
13616 When there is only one type specifier, and all the register
13617 operands are the same type of hardware register, the type
13618 specifier applies to all register operands.
13619
13620 If no type specifier is given, the shape is inferred from
13621 operand information.
13622
13623 for example:
13624 vadd.f16 s0, s1, s2: NS_HHH
13625 vabs.f16 s0, s1: NS_HH
13626 vmov.f16 s0, r1: NS_HR
13627 vmov.f16 r0, s1: NS_RH
13628 vcvt.f16 r0, s1: NS_RH
13629 vcvt.f16.s32 s2, s2, #29: NS_HFI
13630 vcvt.f16.s32 s2, s2: NS_HF
13631 */
13632 case SE_H:
13633 if (!(inst.operands[j].isreg
13634 && inst.operands[j].isvec
13635 && inst.operands[j].issingle
13636 && !inst.operands[j].isquad
13637 && ((inst.vectype.elems == 1
13638 && inst.vectype.el[0].size == 16)
13639 || (inst.vectype.elems > 1
13640 && inst.vectype.el[j].size == 16)
13641 || (inst.vectype.elems == 0
13642 && inst.operands[j].vectype.type != NT_invtype
13643 && inst.operands[j].vectype.size == 16))))
13644 matches = 0;
13645 break;
13646
477330fc
RM
13647 case SE_F:
13648 if (!(inst.operands[j].isreg
13649 && inst.operands[j].isvec
13650 && inst.operands[j].issingle
d54af2d0
RL
13651 && !inst.operands[j].isquad
13652 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13653 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13654 || (inst.vectype.elems == 0
13655 && (inst.operands[j].vectype.size == 32
13656 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13657 matches = 0;
13658 break;
13659
13660 case SE_D:
13661 if (!(inst.operands[j].isreg
13662 && inst.operands[j].isvec
13663 && !inst.operands[j].isquad
13664 && !inst.operands[j].issingle))
13665 matches = 0;
13666 break;
13667
13668 case SE_R:
13669 if (!(inst.operands[j].isreg
13670 && !inst.operands[j].isvec))
13671 matches = 0;
13672 break;
13673
13674 case SE_Q:
13675 if (!(inst.operands[j].isreg
13676 && inst.operands[j].isvec
13677 && inst.operands[j].isquad
13678 && !inst.operands[j].issingle))
13679 matches = 0;
13680 break;
13681
13682 case SE_I:
13683 if (!(!inst.operands[j].isreg
13684 && !inst.operands[j].isscalar))
13685 matches = 0;
13686 break;
13687
13688 case SE_S:
13689 if (!(!inst.operands[j].isreg
13690 && inst.operands[j].isscalar))
13691 matches = 0;
13692 break;
13693
13694 case SE_L:
13695 break;
13696 }
3fde54a2
JZ
13697 if (!matches)
13698 break;
477330fc 13699 }
ad6cec43
MGD
13700 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13701 /* We've matched all the entries in the shape table, and we don't
13702 have any left over operands which have not been matched. */
477330fc 13703 break;
037e8744 13704 }
5f4273c7 13705
037e8744 13706 va_end (ap);
5287ad62 13707
037e8744
JB
13708 if (shape == NS_NULL && first_shape != NS_NULL)
13709 first_error (_("invalid instruction shape"));
5287ad62 13710
037e8744
JB
13711 return shape;
13712}
5287ad62 13713
037e8744
JB
13714/* True if SHAPE is predominantly a quadword operation (most of the time, this
13715 means the Q bit should be set). */
13716
13717static int
13718neon_quad (enum neon_shape shape)
13719{
13720 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13721}
037e8744 13722
5287ad62
JB
13723static void
13724neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13725 unsigned *g_size)
5287ad62
JB
13726{
13727 /* Allow modification to be made to types which are constrained to be
13728 based on the key element, based on bits set alongside N_EQK. */
13729 if ((typebits & N_EQK) != 0)
13730 {
13731 if ((typebits & N_HLF) != 0)
13732 *g_size /= 2;
13733 else if ((typebits & N_DBL) != 0)
13734 *g_size *= 2;
13735 if ((typebits & N_SGN) != 0)
13736 *g_type = NT_signed;
13737 else if ((typebits & N_UNS) != 0)
477330fc 13738 *g_type = NT_unsigned;
5287ad62 13739 else if ((typebits & N_INT) != 0)
477330fc 13740 *g_type = NT_integer;
5287ad62 13741 else if ((typebits & N_FLT) != 0)
477330fc 13742 *g_type = NT_float;
dcbf9037 13743 else if ((typebits & N_SIZ) != 0)
477330fc 13744 *g_type = NT_untyped;
5287ad62
JB
13745 }
13746}
5f4273c7 13747
5287ad62
JB
13748/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13749 operand type, i.e. the single type specified in a Neon instruction when it
13750 is the only one given. */
13751
13752static struct neon_type_el
13753neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13754{
13755 struct neon_type_el dest = *key;
5f4273c7 13756
9c2799c2 13757 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13758
5287ad62
JB
13759 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13760
13761 return dest;
13762}
13763
13764/* Convert Neon type and size into compact bitmask representation. */
13765
13766static enum neon_type_mask
13767type_chk_of_el_type (enum neon_el_type type, unsigned size)
13768{
13769 switch (type)
13770 {
13771 case NT_untyped:
13772 switch (size)
477330fc
RM
13773 {
13774 case 8: return N_8;
13775 case 16: return N_16;
13776 case 32: return N_32;
13777 case 64: return N_64;
13778 default: ;
13779 }
5287ad62
JB
13780 break;
13781
13782 case NT_integer:
13783 switch (size)
477330fc
RM
13784 {
13785 case 8: return N_I8;
13786 case 16: return N_I16;
13787 case 32: return N_I32;
13788 case 64: return N_I64;
13789 default: ;
13790 }
5287ad62
JB
13791 break;
13792
13793 case NT_float:
037e8744 13794 switch (size)
477330fc 13795 {
8e79c3df 13796 case 16: return N_F16;
477330fc
RM
13797 case 32: return N_F32;
13798 case 64: return N_F64;
13799 default: ;
13800 }
5287ad62
JB
13801 break;
13802
13803 case NT_poly:
13804 switch (size)
477330fc
RM
13805 {
13806 case 8: return N_P8;
13807 case 16: return N_P16;
4f51b4bd 13808 case 64: return N_P64;
477330fc
RM
13809 default: ;
13810 }
5287ad62
JB
13811 break;
13812
13813 case NT_signed:
13814 switch (size)
477330fc
RM
13815 {
13816 case 8: return N_S8;
13817 case 16: return N_S16;
13818 case 32: return N_S32;
13819 case 64: return N_S64;
13820 default: ;
13821 }
5287ad62
JB
13822 break;
13823
13824 case NT_unsigned:
13825 switch (size)
477330fc
RM
13826 {
13827 case 8: return N_U8;
13828 case 16: return N_U16;
13829 case 32: return N_U32;
13830 case 64: return N_U64;
13831 default: ;
13832 }
5287ad62
JB
13833 break;
13834
13835 default: ;
13836 }
5f4273c7 13837
5287ad62
JB
13838 return N_UTYP;
13839}
13840
13841/* Convert compact Neon bitmask type representation to a type and size. Only
13842 handles the case where a single bit is set in the mask. */
13843
dcbf9037 13844static int
5287ad62 13845el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13846 enum neon_type_mask mask)
5287ad62 13847{
dcbf9037
JB
13848 if ((mask & N_EQK) != 0)
13849 return FAIL;
13850
5287ad62
JB
13851 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13852 *size = 8;
c70a8987 13853 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13854 *size = 16;
dcbf9037 13855 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13856 *size = 32;
4f51b4bd 13857 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13858 *size = 64;
dcbf9037
JB
13859 else
13860 return FAIL;
13861
5287ad62
JB
13862 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13863 *type = NT_signed;
dcbf9037 13864 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13865 *type = NT_unsigned;
dcbf9037 13866 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13867 *type = NT_integer;
dcbf9037 13868 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13869 *type = NT_untyped;
4f51b4bd 13870 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13871 *type = NT_poly;
d54af2d0 13872 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13873 *type = NT_float;
dcbf9037
JB
13874 else
13875 return FAIL;
5f4273c7 13876
dcbf9037 13877 return SUCCESS;
5287ad62
JB
13878}
13879
13880/* Modify a bitmask of allowed types. This is only needed for type
13881 relaxation. */
13882
13883static unsigned
13884modify_types_allowed (unsigned allowed, unsigned mods)
13885{
13886 unsigned size;
13887 enum neon_el_type type;
13888 unsigned destmask;
13889 int i;
5f4273c7 13890
5287ad62 13891 destmask = 0;
5f4273c7 13892
5287ad62
JB
13893 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13894 {
21d799b5 13895 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13896 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13897 {
13898 neon_modify_type_size (mods, &type, &size);
13899 destmask |= type_chk_of_el_type (type, size);
13900 }
5287ad62 13901 }
5f4273c7 13902
5287ad62
JB
13903 return destmask;
13904}
13905
13906/* Check type and return type classification.
13907 The manual states (paraphrase): If one datatype is given, it indicates the
13908 type given in:
13909 - the second operand, if there is one
13910 - the operand, if there is no second operand
13911 - the result, if there are no operands.
13912 This isn't quite good enough though, so we use a concept of a "key" datatype
13913 which is set on a per-instruction basis, which is the one which matters when
13914 only one data type is written.
13915 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13916 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13917
13918static struct neon_type_el
13919neon_check_type (unsigned els, enum neon_shape ns, ...)
13920{
13921 va_list ap;
13922 unsigned i, pass, key_el = 0;
13923 unsigned types[NEON_MAX_TYPE_ELS];
13924 enum neon_el_type k_type = NT_invtype;
13925 unsigned k_size = -1u;
13926 struct neon_type_el badtype = {NT_invtype, -1};
13927 unsigned key_allowed = 0;
13928
13929 /* Optional registers in Neon instructions are always (not) in operand 1.
13930 Fill in the missing operand here, if it was omitted. */
13931 if (els > 1 && !inst.operands[1].present)
13932 inst.operands[1] = inst.operands[0];
13933
13934 /* Suck up all the varargs. */
13935 va_start (ap, ns);
13936 for (i = 0; i < els; i++)
13937 {
13938 unsigned thisarg = va_arg (ap, unsigned);
13939 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13940 {
13941 va_end (ap);
13942 return badtype;
13943 }
5287ad62
JB
13944 types[i] = thisarg;
13945 if ((thisarg & N_KEY) != 0)
477330fc 13946 key_el = i;
5287ad62
JB
13947 }
13948 va_end (ap);
13949
dcbf9037
JB
13950 if (inst.vectype.elems > 0)
13951 for (i = 0; i < els; i++)
13952 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13953 {
13954 first_error (_("types specified in both the mnemonic and operands"));
13955 return badtype;
13956 }
dcbf9037 13957
5287ad62
JB
13958 /* Duplicate inst.vectype elements here as necessary.
13959 FIXME: No idea if this is exactly the same as the ARM assembler,
13960 particularly when an insn takes one register and one non-register
13961 operand. */
13962 if (inst.vectype.elems == 1 && els > 1)
13963 {
13964 unsigned j;
13965 inst.vectype.elems = els;
13966 inst.vectype.el[key_el] = inst.vectype.el[0];
13967 for (j = 0; j < els; j++)
477330fc
RM
13968 if (j != key_el)
13969 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13970 types[j]);
dcbf9037
JB
13971 }
13972 else if (inst.vectype.elems == 0 && els > 0)
13973 {
13974 unsigned j;
13975 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13976 after each operand. We allow some flexibility here; as long as the
13977 "key" operand has a type, we can infer the others. */
dcbf9037 13978 for (j = 0; j < els; j++)
477330fc
RM
13979 if (inst.operands[j].vectype.type != NT_invtype)
13980 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13981
13982 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13983 {
13984 for (j = 0; j < els; j++)
13985 if (inst.operands[j].vectype.type == NT_invtype)
13986 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13987 types[j]);
13988 }
dcbf9037 13989 else
477330fc
RM
13990 {
13991 first_error (_("operand types can't be inferred"));
13992 return badtype;
13993 }
5287ad62
JB
13994 }
13995 else if (inst.vectype.elems != els)
13996 {
dcbf9037 13997 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13998 return badtype;
13999 }
14000
14001 for (pass = 0; pass < 2; pass++)
14002 {
14003 for (i = 0; i < els; i++)
477330fc
RM
14004 {
14005 unsigned thisarg = types[i];
14006 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14007 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14008 enum neon_el_type g_type = inst.vectype.el[i].type;
14009 unsigned g_size = inst.vectype.el[i].size;
14010
14011 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14012 integer types if sign-specific variants are unavailable. */
477330fc 14013 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14014 && (types_allowed & N_SU_ALL) == 0)
14015 g_type = NT_integer;
14016
477330fc 14017 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14018 them. Some instructions only care about signs for some element
14019 sizes, so handle that properly. */
477330fc 14020 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14021 && ((g_size == 8 && (types_allowed & N_8) != 0)
14022 || (g_size == 16 && (types_allowed & N_16) != 0)
14023 || (g_size == 32 && (types_allowed & N_32) != 0)
14024 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14025 g_type = NT_untyped;
14026
477330fc
RM
14027 if (pass == 0)
14028 {
14029 if ((thisarg & N_KEY) != 0)
14030 {
14031 k_type = g_type;
14032 k_size = g_size;
14033 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14034
14035 /* Check architecture constraint on FP16 extension. */
14036 if (k_size == 16
14037 && k_type == NT_float
14038 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14039 {
14040 inst.error = _(BAD_FP16);
14041 return badtype;
14042 }
477330fc
RM
14043 }
14044 }
14045 else
14046 {
14047 if ((thisarg & N_VFP) != 0)
14048 {
14049 enum neon_shape_el regshape;
14050 unsigned regwidth, match;
99b253c5
NC
14051
14052 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14053 if (ns == NS_NULL)
14054 {
14055 first_error (_("invalid instruction shape"));
14056 return badtype;
14057 }
477330fc
RM
14058 regshape = neon_shape_tab[ns].el[i];
14059 regwidth = neon_shape_el_size[regshape];
14060
14061 /* In VFP mode, operands must match register widths. If we
14062 have a key operand, use its width, else use the width of
14063 the current operand. */
14064 if (k_size != -1u)
14065 match = k_size;
14066 else
14067 match = g_size;
14068
9db2f6b4
RL
14069 /* FP16 will use a single precision register. */
14070 if (regwidth == 32 && match == 16)
14071 {
14072 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14073 match = regwidth;
14074 else
14075 {
14076 inst.error = _(BAD_FP16);
14077 return badtype;
14078 }
14079 }
14080
477330fc
RM
14081 if (regwidth != match)
14082 {
14083 first_error (_("operand size must match register width"));
14084 return badtype;
14085 }
14086 }
14087
14088 if ((thisarg & N_EQK) == 0)
14089 {
14090 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14091
14092 if ((given_type & types_allowed) == 0)
14093 {
14094 first_error (_("bad type in Neon instruction"));
14095 return badtype;
14096 }
14097 }
14098 else
14099 {
14100 enum neon_el_type mod_k_type = k_type;
14101 unsigned mod_k_size = k_size;
14102 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14103 if (g_type != mod_k_type || g_size != mod_k_size)
14104 {
14105 first_error (_("inconsistent types in Neon instruction"));
14106 return badtype;
14107 }
14108 }
14109 }
14110 }
5287ad62
JB
14111 }
14112
14113 return inst.vectype.el[key_el];
14114}
14115
037e8744 14116/* Neon-style VFP instruction forwarding. */
5287ad62 14117
037e8744
JB
14118/* Thumb VFP instructions have 0xE in the condition field. */
14119
14120static void
14121do_vfp_cond_or_thumb (void)
5287ad62 14122{
88714cb8
DG
14123 inst.is_neon = 1;
14124
5287ad62 14125 if (thumb_mode)
037e8744 14126 inst.instruction |= 0xe0000000;
5287ad62 14127 else
037e8744 14128 inst.instruction |= inst.cond << 28;
5287ad62
JB
14129}
14130
037e8744
JB
14131/* Look up and encode a simple mnemonic, for use as a helper function for the
14132 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14133 etc. It is assumed that operand parsing has already been done, and that the
14134 operands are in the form expected by the given opcode (this isn't necessarily
14135 the same as the form in which they were parsed, hence some massaging must
14136 take place before this function is called).
14137 Checks current arch version against that in the looked-up opcode. */
5287ad62 14138
037e8744
JB
14139static void
14140do_vfp_nsyn_opcode (const char *opname)
5287ad62 14141{
037e8744 14142 const struct asm_opcode *opcode;
5f4273c7 14143
21d799b5 14144 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14145
037e8744
JB
14146 if (!opcode)
14147 abort ();
5287ad62 14148
037e8744 14149 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14150 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14151 _(BAD_FPU));
5287ad62 14152
88714cb8
DG
14153 inst.is_neon = 1;
14154
037e8744
JB
14155 if (thumb_mode)
14156 {
14157 inst.instruction = opcode->tvalue;
14158 opcode->tencode ();
14159 }
14160 else
14161 {
14162 inst.instruction = (inst.cond << 28) | opcode->avalue;
14163 opcode->aencode ();
14164 }
14165}
5287ad62
JB
14166
14167static void
037e8744 14168do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14169{
037e8744
JB
14170 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14171
9db2f6b4 14172 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14173 {
14174 if (is_add)
477330fc 14175 do_vfp_nsyn_opcode ("fadds");
037e8744 14176 else
477330fc 14177 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14178
14179 /* ARMv8.2 fp16 instruction. */
14180 if (rs == NS_HHH)
14181 do_scalar_fp16_v82_encode ();
037e8744
JB
14182 }
14183 else
14184 {
14185 if (is_add)
477330fc 14186 do_vfp_nsyn_opcode ("faddd");
037e8744 14187 else
477330fc 14188 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14189 }
14190}
14191
14192/* Check operand types to see if this is a VFP instruction, and if so call
14193 PFN (). */
14194
14195static int
14196try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14197{
14198 enum neon_shape rs;
14199 struct neon_type_el et;
14200
14201 switch (args)
14202 {
14203 case 2:
9db2f6b4
RL
14204 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14205 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14206 break;
5f4273c7 14207
037e8744 14208 case 3:
9db2f6b4
RL
14209 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14210 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14211 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14212 break;
14213
14214 default:
14215 abort ();
14216 }
14217
14218 if (et.type != NT_invtype)
14219 {
14220 pfn (rs);
14221 return SUCCESS;
14222 }
037e8744 14223
99b253c5 14224 inst.error = NULL;
037e8744
JB
14225 return FAIL;
14226}
14227
14228static void
14229do_vfp_nsyn_mla_mls (enum neon_shape rs)
14230{
14231 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14232
9db2f6b4 14233 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14234 {
14235 if (is_mla)
477330fc 14236 do_vfp_nsyn_opcode ("fmacs");
037e8744 14237 else
477330fc 14238 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14239
14240 /* ARMv8.2 fp16 instruction. */
14241 if (rs == NS_HHH)
14242 do_scalar_fp16_v82_encode ();
037e8744
JB
14243 }
14244 else
14245 {
14246 if (is_mla)
477330fc 14247 do_vfp_nsyn_opcode ("fmacd");
037e8744 14248 else
477330fc 14249 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14250 }
14251}
14252
62f3b8c8
PB
14253static void
14254do_vfp_nsyn_fma_fms (enum neon_shape rs)
14255{
14256 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14257
9db2f6b4 14258 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14259 {
14260 if (is_fma)
477330fc 14261 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14262 else
477330fc 14263 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14264
14265 /* ARMv8.2 fp16 instruction. */
14266 if (rs == NS_HHH)
14267 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14268 }
14269 else
14270 {
14271 if (is_fma)
477330fc 14272 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14273 else
477330fc 14274 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14275 }
14276}
14277
037e8744
JB
14278static void
14279do_vfp_nsyn_mul (enum neon_shape rs)
14280{
9db2f6b4
RL
14281 if (rs == NS_FFF || rs == NS_HHH)
14282 {
14283 do_vfp_nsyn_opcode ("fmuls");
14284
14285 /* ARMv8.2 fp16 instruction. */
14286 if (rs == NS_HHH)
14287 do_scalar_fp16_v82_encode ();
14288 }
037e8744
JB
14289 else
14290 do_vfp_nsyn_opcode ("fmuld");
14291}
14292
14293static void
14294do_vfp_nsyn_abs_neg (enum neon_shape rs)
14295{
14296 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14297 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14298
9db2f6b4 14299 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14300 {
14301 if (is_neg)
477330fc 14302 do_vfp_nsyn_opcode ("fnegs");
037e8744 14303 else
477330fc 14304 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14305
14306 /* ARMv8.2 fp16 instruction. */
14307 if (rs == NS_HH)
14308 do_scalar_fp16_v82_encode ();
037e8744
JB
14309 }
14310 else
14311 {
14312 if (is_neg)
477330fc 14313 do_vfp_nsyn_opcode ("fnegd");
037e8744 14314 else
477330fc 14315 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14316 }
14317}
14318
14319/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14320 insns belong to Neon, and are handled elsewhere. */
14321
14322static void
14323do_vfp_nsyn_ldm_stm (int is_dbmode)
14324{
14325 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14326 if (is_ldm)
14327 {
14328 if (is_dbmode)
477330fc 14329 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14330 else
477330fc 14331 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14332 }
14333 else
14334 {
14335 if (is_dbmode)
477330fc 14336 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14337 else
477330fc 14338 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14339 }
14340}
14341
037e8744
JB
14342static void
14343do_vfp_nsyn_sqrt (void)
14344{
9db2f6b4
RL
14345 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14346 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14347
9db2f6b4
RL
14348 if (rs == NS_FF || rs == NS_HH)
14349 {
14350 do_vfp_nsyn_opcode ("fsqrts");
14351
14352 /* ARMv8.2 fp16 instruction. */
14353 if (rs == NS_HH)
14354 do_scalar_fp16_v82_encode ();
14355 }
037e8744
JB
14356 else
14357 do_vfp_nsyn_opcode ("fsqrtd");
14358}
14359
14360static void
14361do_vfp_nsyn_div (void)
14362{
9db2f6b4 14363 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14364 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14365 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14366
9db2f6b4
RL
14367 if (rs == NS_FFF || rs == NS_HHH)
14368 {
14369 do_vfp_nsyn_opcode ("fdivs");
14370
14371 /* ARMv8.2 fp16 instruction. */
14372 if (rs == NS_HHH)
14373 do_scalar_fp16_v82_encode ();
14374 }
037e8744
JB
14375 else
14376 do_vfp_nsyn_opcode ("fdivd");
14377}
14378
14379static void
14380do_vfp_nsyn_nmul (void)
14381{
9db2f6b4 14382 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14383 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14384 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14385
9db2f6b4 14386 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14387 {
88714cb8 14388 NEON_ENCODE (SINGLE, inst);
037e8744 14389 do_vfp_sp_dyadic ();
9db2f6b4
RL
14390
14391 /* ARMv8.2 fp16 instruction. */
14392 if (rs == NS_HHH)
14393 do_scalar_fp16_v82_encode ();
037e8744
JB
14394 }
14395 else
14396 {
88714cb8 14397 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14398 do_vfp_dp_rd_rn_rm ();
14399 }
14400 do_vfp_cond_or_thumb ();
9db2f6b4 14401
037e8744
JB
14402}
14403
14404static void
14405do_vfp_nsyn_cmp (void)
14406{
9db2f6b4 14407 enum neon_shape rs;
037e8744
JB
14408 if (inst.operands[1].isreg)
14409 {
9db2f6b4
RL
14410 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14411 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14412
9db2f6b4 14413 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14414 {
14415 NEON_ENCODE (SINGLE, inst);
14416 do_vfp_sp_monadic ();
14417 }
037e8744 14418 else
477330fc
RM
14419 {
14420 NEON_ENCODE (DOUBLE, inst);
14421 do_vfp_dp_rd_rm ();
14422 }
037e8744
JB
14423 }
14424 else
14425 {
9db2f6b4
RL
14426 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14427 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14428
14429 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14430 {
14431 case N_MNEM_vcmp:
14432 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14433 break;
14434 case N_MNEM_vcmpe:
14435 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14436 break;
14437 default:
14438 abort ();
14439 }
5f4273c7 14440
9db2f6b4 14441 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14442 {
14443 NEON_ENCODE (SINGLE, inst);
14444 do_vfp_sp_compare_z ();
14445 }
037e8744 14446 else
477330fc
RM
14447 {
14448 NEON_ENCODE (DOUBLE, inst);
14449 do_vfp_dp_rd ();
14450 }
037e8744
JB
14451 }
14452 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14453
14454 /* ARMv8.2 fp16 instruction. */
14455 if (rs == NS_HI || rs == NS_HH)
14456 do_scalar_fp16_v82_encode ();
037e8744
JB
14457}
14458
14459static void
14460nsyn_insert_sp (void)
14461{
14462 inst.operands[1] = inst.operands[0];
14463 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14464 inst.operands[0].reg = REG_SP;
037e8744
JB
14465 inst.operands[0].isreg = 1;
14466 inst.operands[0].writeback = 1;
14467 inst.operands[0].present = 1;
14468}
14469
14470static void
14471do_vfp_nsyn_push (void)
14472{
14473 nsyn_insert_sp ();
b126985e
NC
14474
14475 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14476 _("register list must contain at least 1 and at most 16 "
14477 "registers"));
14478
037e8744
JB
14479 if (inst.operands[1].issingle)
14480 do_vfp_nsyn_opcode ("fstmdbs");
14481 else
14482 do_vfp_nsyn_opcode ("fstmdbd");
14483}
14484
14485static void
14486do_vfp_nsyn_pop (void)
14487{
14488 nsyn_insert_sp ();
b126985e
NC
14489
14490 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14491 _("register list must contain at least 1 and at most 16 "
14492 "registers"));
14493
037e8744 14494 if (inst.operands[1].issingle)
22b5b651 14495 do_vfp_nsyn_opcode ("fldmias");
037e8744 14496 else
22b5b651 14497 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14498}
14499
14500/* Fix up Neon data-processing instructions, ORing in the correct bits for
14501 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14502
88714cb8
DG
14503static void
14504neon_dp_fixup (struct arm_it* insn)
037e8744 14505{
88714cb8
DG
14506 unsigned int i = insn->instruction;
14507 insn->is_neon = 1;
14508
037e8744
JB
14509 if (thumb_mode)
14510 {
14511 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14512 if (i & (1 << 24))
477330fc 14513 i |= 1 << 28;
5f4273c7 14514
037e8744 14515 i &= ~(1 << 24);
5f4273c7 14516
037e8744
JB
14517 i |= 0xef000000;
14518 }
14519 else
14520 i |= 0xf2000000;
5f4273c7 14521
88714cb8 14522 insn->instruction = i;
037e8744
JB
14523}
14524
14525/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14526 (0, 1, 2, 3). */
14527
14528static unsigned
14529neon_logbits (unsigned x)
14530{
14531 return ffs (x) - 4;
14532}
14533
14534#define LOW4(R) ((R) & 0xf)
14535#define HI1(R) (((R) >> 4) & 1)
14536
14537/* Encode insns with bit pattern:
14538
14539 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14540 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14541
037e8744
JB
14542 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14543 different meaning for some instruction. */
14544
14545static void
14546neon_three_same (int isquad, int ubit, int size)
14547{
14548 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14549 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14550 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14551 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14552 inst.instruction |= LOW4 (inst.operands[2].reg);
14553 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14554 inst.instruction |= (isquad != 0) << 6;
14555 inst.instruction |= (ubit != 0) << 24;
14556 if (size != -1)
14557 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14558
88714cb8 14559 neon_dp_fixup (&inst);
037e8744
JB
14560}
14561
14562/* Encode instructions of the form:
14563
14564 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14565 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14566
14567 Don't write size if SIZE == -1. */
14568
14569static void
14570neon_two_same (int qbit, int ubit, int size)
14571{
14572 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14573 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14574 inst.instruction |= LOW4 (inst.operands[1].reg);
14575 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14576 inst.instruction |= (qbit != 0) << 6;
14577 inst.instruction |= (ubit != 0) << 24;
14578
14579 if (size != -1)
14580 inst.instruction |= neon_logbits (size) << 18;
14581
88714cb8 14582 neon_dp_fixup (&inst);
5287ad62
JB
14583}
14584
14585/* Neon instruction encoders, in approximate order of appearance. */
14586
14587static void
14588do_neon_dyadic_i_su (void)
14589{
037e8744 14590 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14591 struct neon_type_el et = neon_check_type (3, rs,
14592 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14593 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14594}
14595
14596static void
14597do_neon_dyadic_i64_su (void)
14598{
037e8744 14599 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14600 struct neon_type_el et = neon_check_type (3, rs,
14601 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14602 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14603}
14604
14605static void
14606neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14607 unsigned immbits)
5287ad62
JB
14608{
14609 unsigned size = et.size >> 3;
14610 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14611 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14612 inst.instruction |= LOW4 (inst.operands[1].reg);
14613 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14614 inst.instruction |= (isquad != 0) << 6;
14615 inst.instruction |= immbits << 16;
14616 inst.instruction |= (size >> 3) << 7;
14617 inst.instruction |= (size & 0x7) << 19;
14618 if (write_ubit)
14619 inst.instruction |= (uval != 0) << 24;
14620
88714cb8 14621 neon_dp_fixup (&inst);
5287ad62
JB
14622}
14623
14624static void
14625do_neon_shl_imm (void)
14626{
14627 if (!inst.operands[2].isreg)
14628 {
037e8744 14629 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14630 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14631 int imm = inst.operands[2].imm;
14632
14633 constraint (imm < 0 || (unsigned)imm >= et.size,
14634 _("immediate out of range for shift"));
88714cb8 14635 NEON_ENCODE (IMMED, inst);
cb3b1e65 14636 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14637 }
14638 else
14639 {
037e8744 14640 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14641 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14642 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14643 unsigned int tmp;
14644
14645 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14646 vshl.xx Dd, Dm, Dn
14647 whereas other 3-register operations encoded by neon_three_same have
14648 syntax like:
14649 vadd.xx Dd, Dn, Dm
14650 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14651 here. */
627907b7
JB
14652 tmp = inst.operands[2].reg;
14653 inst.operands[2].reg = inst.operands[1].reg;
14654 inst.operands[1].reg = tmp;
88714cb8 14655 NEON_ENCODE (INTEGER, inst);
037e8744 14656 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14657 }
14658}
14659
14660static void
14661do_neon_qshl_imm (void)
14662{
14663 if (!inst.operands[2].isreg)
14664 {
037e8744 14665 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14666 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14667 int imm = inst.operands[2].imm;
627907b7 14668
cb3b1e65
JB
14669 constraint (imm < 0 || (unsigned)imm >= et.size,
14670 _("immediate out of range for shift"));
88714cb8 14671 NEON_ENCODE (IMMED, inst);
cb3b1e65 14672 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14673 }
14674 else
14675 {
037e8744 14676 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14677 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14678 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14679 unsigned int tmp;
14680
14681 /* See note in do_neon_shl_imm. */
14682 tmp = inst.operands[2].reg;
14683 inst.operands[2].reg = inst.operands[1].reg;
14684 inst.operands[1].reg = tmp;
88714cb8 14685 NEON_ENCODE (INTEGER, inst);
037e8744 14686 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14687 }
14688}
14689
627907b7
JB
14690static void
14691do_neon_rshl (void)
14692{
14693 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14694 struct neon_type_el et = neon_check_type (3, rs,
14695 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14696 unsigned int tmp;
14697
14698 tmp = inst.operands[2].reg;
14699 inst.operands[2].reg = inst.operands[1].reg;
14700 inst.operands[1].reg = tmp;
14701 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14702}
14703
5287ad62
JB
14704static int
14705neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14706{
036dc3f7
PB
14707 /* Handle .I8 pseudo-instructions. */
14708 if (size == 8)
5287ad62 14709 {
5287ad62 14710 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14711 FIXME is this the intended semantics? There doesn't seem much point in
14712 accepting .I8 if so. */
5287ad62
JB
14713 immediate |= immediate << 8;
14714 size = 16;
036dc3f7
PB
14715 }
14716
14717 if (size >= 32)
14718 {
14719 if (immediate == (immediate & 0x000000ff))
14720 {
14721 *immbits = immediate;
14722 return 0x1;
14723 }
14724 else if (immediate == (immediate & 0x0000ff00))
14725 {
14726 *immbits = immediate >> 8;
14727 return 0x3;
14728 }
14729 else if (immediate == (immediate & 0x00ff0000))
14730 {
14731 *immbits = immediate >> 16;
14732 return 0x5;
14733 }
14734 else if (immediate == (immediate & 0xff000000))
14735 {
14736 *immbits = immediate >> 24;
14737 return 0x7;
14738 }
14739 if ((immediate & 0xffff) != (immediate >> 16))
14740 goto bad_immediate;
14741 immediate &= 0xffff;
5287ad62
JB
14742 }
14743
14744 if (immediate == (immediate & 0x000000ff))
14745 {
14746 *immbits = immediate;
036dc3f7 14747 return 0x9;
5287ad62
JB
14748 }
14749 else if (immediate == (immediate & 0x0000ff00))
14750 {
14751 *immbits = immediate >> 8;
036dc3f7 14752 return 0xb;
5287ad62
JB
14753 }
14754
14755 bad_immediate:
dcbf9037 14756 first_error (_("immediate value out of range"));
5287ad62
JB
14757 return FAIL;
14758}
14759
5287ad62
JB
14760static void
14761do_neon_logic (void)
14762{
14763 if (inst.operands[2].present && inst.operands[2].isreg)
14764 {
037e8744 14765 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14766 neon_check_type (3, rs, N_IGNORE_TYPE);
14767 /* U bit and size field were set as part of the bitmask. */
88714cb8 14768 NEON_ENCODE (INTEGER, inst);
037e8744 14769 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14770 }
14771 else
14772 {
4316f0d2
DG
14773 const int three_ops_form = (inst.operands[2].present
14774 && !inst.operands[2].isreg);
14775 const int immoperand = (three_ops_form ? 2 : 1);
14776 enum neon_shape rs = (three_ops_form
14777 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14778 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14779 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14780 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14781 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14782 unsigned immbits;
14783 int cmode;
5f4273c7 14784
5287ad62 14785 if (et.type == NT_invtype)
477330fc 14786 return;
5f4273c7 14787
4316f0d2
DG
14788 if (three_ops_form)
14789 constraint (inst.operands[0].reg != inst.operands[1].reg,
14790 _("first and second operands shall be the same register"));
14791
88714cb8 14792 NEON_ENCODE (IMMED, inst);
5287ad62 14793
4316f0d2 14794 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14795 if (et.size == 64)
14796 {
14797 /* .i64 is a pseudo-op, so the immediate must be a repeating
14798 pattern. */
4316f0d2
DG
14799 if (immbits != (inst.operands[immoperand].regisimm ?
14800 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14801 {
14802 /* Set immbits to an invalid constant. */
14803 immbits = 0xdeadbeef;
14804 }
14805 }
14806
5287ad62 14807 switch (opcode)
477330fc
RM
14808 {
14809 case N_MNEM_vbic:
14810 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14811 break;
14812
14813 case N_MNEM_vorr:
14814 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14815 break;
14816
14817 case N_MNEM_vand:
14818 /* Pseudo-instruction for VBIC. */
14819 neon_invert_size (&immbits, 0, et.size);
14820 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14821 break;
14822
14823 case N_MNEM_vorn:
14824 /* Pseudo-instruction for VORR. */
14825 neon_invert_size (&immbits, 0, et.size);
14826 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14827 break;
14828
14829 default:
14830 abort ();
14831 }
5287ad62
JB
14832
14833 if (cmode == FAIL)
477330fc 14834 return;
5287ad62 14835
037e8744 14836 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14837 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14838 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14839 inst.instruction |= cmode << 8;
14840 neon_write_immbits (immbits);
5f4273c7 14841
88714cb8 14842 neon_dp_fixup (&inst);
5287ad62
JB
14843 }
14844}
14845
14846static void
14847do_neon_bitfield (void)
14848{
037e8744 14849 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14850 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14851 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14852}
14853
14854static void
dcbf9037 14855neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14856 unsigned destbits)
5287ad62 14857{
037e8744 14858 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14859 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14860 types | N_KEY);
5287ad62
JB
14861 if (et.type == NT_float)
14862 {
88714cb8 14863 NEON_ENCODE (FLOAT, inst);
cc933301 14864 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14865 }
14866 else
14867 {
88714cb8 14868 NEON_ENCODE (INTEGER, inst);
037e8744 14869 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14870 }
14871}
14872
14873static void
14874do_neon_dyadic_if_su (void)
14875{
dcbf9037 14876 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14877}
14878
14879static void
14880do_neon_dyadic_if_su_d (void)
14881{
14882 /* This version only allow D registers, but that constraint is enforced during
14883 operand parsing so we don't need to do anything extra here. */
dcbf9037 14884 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14885}
14886
5287ad62
JB
14887static void
14888do_neon_dyadic_if_i_d (void)
14889{
428e3f1f
PB
14890 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14891 affected if we specify unsigned args. */
14892 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14893}
14894
037e8744
JB
14895enum vfp_or_neon_is_neon_bits
14896{
14897 NEON_CHECK_CC = 1,
73924fbc
MGD
14898 NEON_CHECK_ARCH = 2,
14899 NEON_CHECK_ARCH8 = 4
037e8744
JB
14900};
14901
14902/* Call this function if an instruction which may have belonged to the VFP or
14903 Neon instruction sets, but turned out to be a Neon instruction (due to the
14904 operand types involved, etc.). We have to check and/or fix-up a couple of
14905 things:
14906
14907 - Make sure the user hasn't attempted to make a Neon instruction
14908 conditional.
14909 - Alter the value in the condition code field if necessary.
14910 - Make sure that the arch supports Neon instructions.
14911
14912 Which of these operations take place depends on bits from enum
14913 vfp_or_neon_is_neon_bits.
14914
14915 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14916 current instruction's condition is COND_ALWAYS, the condition field is
14917 changed to inst.uncond_value. This is necessary because instructions shared
14918 between VFP and Neon may be conditional for the VFP variants only, and the
14919 unconditional Neon version must have, e.g., 0xF in the condition field. */
14920
14921static int
14922vfp_or_neon_is_neon (unsigned check)
14923{
14924 /* Conditions are always legal in Thumb mode (IT blocks). */
14925 if (!thumb_mode && (check & NEON_CHECK_CC))
14926 {
14927 if (inst.cond != COND_ALWAYS)
477330fc
RM
14928 {
14929 first_error (_(BAD_COND));
14930 return FAIL;
14931 }
037e8744 14932 if (inst.uncond_value != -1)
477330fc 14933 inst.instruction |= inst.uncond_value << 28;
037e8744 14934 }
5f4273c7 14935
037e8744 14936 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14937 && !mark_feature_used (&fpu_neon_ext_v1))
14938 {
14939 first_error (_(BAD_FPU));
14940 return FAIL;
14941 }
14942
14943 if ((check & NEON_CHECK_ARCH8)
14944 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14945 {
14946 first_error (_(BAD_FPU));
14947 return FAIL;
14948 }
5f4273c7 14949
037e8744
JB
14950 return SUCCESS;
14951}
14952
5287ad62
JB
14953static void
14954do_neon_addsub_if_i (void)
14955{
037e8744
JB
14956 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14957 return;
14958
14959 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14960 return;
14961
5287ad62
JB
14962 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14963 affected if we specify unsigned args. */
dcbf9037 14964 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14965}
14966
14967/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14968 result to be:
14969 V<op> A,B (A is operand 0, B is operand 2)
14970 to mean:
14971 V<op> A,B,A
14972 not:
14973 V<op> A,B,B
14974 so handle that case specially. */
14975
14976static void
14977neon_exchange_operands (void)
14978{
5287ad62
JB
14979 if (inst.operands[1].present)
14980 {
e1fa0163
NC
14981 void *scratch = xmalloc (sizeof (inst.operands[0]));
14982
5287ad62
JB
14983 /* Swap operands[1] and operands[2]. */
14984 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14985 inst.operands[1] = inst.operands[2];
14986 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14987 free (scratch);
5287ad62
JB
14988 }
14989 else
14990 {
14991 inst.operands[1] = inst.operands[2];
14992 inst.operands[2] = inst.operands[0];
14993 }
14994}
14995
14996static void
14997neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14998{
14999 if (inst.operands[2].isreg)
15000 {
15001 if (invert)
477330fc 15002 neon_exchange_operands ();
dcbf9037 15003 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15004 }
15005 else
15006 {
037e8744 15007 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15008 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15009 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15010
88714cb8 15011 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15012 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15013 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15014 inst.instruction |= LOW4 (inst.operands[1].reg);
15015 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15016 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15017 inst.instruction |= (et.type == NT_float) << 10;
15018 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15019
88714cb8 15020 neon_dp_fixup (&inst);
5287ad62
JB
15021 }
15022}
15023
15024static void
15025do_neon_cmp (void)
15026{
cc933301 15027 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15028}
15029
15030static void
15031do_neon_cmp_inv (void)
15032{
cc933301 15033 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15034}
15035
15036static void
15037do_neon_ceq (void)
15038{
15039 neon_compare (N_IF_32, N_IF_32, FALSE);
15040}
15041
15042/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15043 scalars, which are encoded in 5 bits, M : Rm.
15044 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15045 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15046 index in M.
15047
15048 Dot Product instructions are similar to multiply instructions except elsize
15049 should always be 32.
15050
15051 This function translates SCALAR, which is GAS's internal encoding of indexed
15052 scalar register, to raw encoding. There is also register and index range
15053 check based on ELSIZE. */
5287ad62
JB
15054
15055static unsigned
15056neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15057{
dcbf9037
JB
15058 unsigned regno = NEON_SCALAR_REG (scalar);
15059 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15060
15061 switch (elsize)
15062 {
15063 case 16:
15064 if (regno > 7 || elno > 3)
477330fc 15065 goto bad_scalar;
5287ad62 15066 return regno | (elno << 3);
5f4273c7 15067
5287ad62
JB
15068 case 32:
15069 if (regno > 15 || elno > 1)
477330fc 15070 goto bad_scalar;
5287ad62
JB
15071 return regno | (elno << 4);
15072
15073 default:
15074 bad_scalar:
dcbf9037 15075 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15076 }
15077
15078 return 0;
15079}
15080
15081/* Encode multiply / multiply-accumulate scalar instructions. */
15082
15083static void
15084neon_mul_mac (struct neon_type_el et, int ubit)
15085{
dcbf9037
JB
15086 unsigned scalar;
15087
15088 /* Give a more helpful error message if we have an invalid type. */
15089 if (et.type == NT_invtype)
15090 return;
5f4273c7 15091
dcbf9037 15092 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15093 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15094 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15095 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15096 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15097 inst.instruction |= LOW4 (scalar);
15098 inst.instruction |= HI1 (scalar) << 5;
15099 inst.instruction |= (et.type == NT_float) << 8;
15100 inst.instruction |= neon_logbits (et.size) << 20;
15101 inst.instruction |= (ubit != 0) << 24;
15102
88714cb8 15103 neon_dp_fixup (&inst);
5287ad62
JB
15104}
15105
15106static void
15107do_neon_mac_maybe_scalar (void)
15108{
037e8744
JB
15109 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15110 return;
15111
15112 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15113 return;
15114
5287ad62
JB
15115 if (inst.operands[2].isscalar)
15116 {
037e8744 15117 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15118 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15119 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15120 NEON_ENCODE (SCALAR, inst);
037e8744 15121 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15122 }
15123 else
428e3f1f
PB
15124 {
15125 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15126 affected if we specify unsigned args. */
15127 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15128 }
5287ad62
JB
15129}
15130
62f3b8c8
PB
15131static void
15132do_neon_fmac (void)
15133{
15134 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15135 return;
15136
15137 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15138 return;
15139
15140 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15141}
15142
5287ad62
JB
15143static void
15144do_neon_tst (void)
15145{
037e8744 15146 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15147 struct neon_type_el et = neon_check_type (3, rs,
15148 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15149 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15150}
15151
15152/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15153 same types as the MAC equivalents. The polynomial type for this instruction
15154 is encoded the same as the integer type. */
15155
15156static void
15157do_neon_mul (void)
15158{
037e8744
JB
15159 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15160 return;
15161
15162 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15163 return;
15164
5287ad62
JB
15165 if (inst.operands[2].isscalar)
15166 do_neon_mac_maybe_scalar ();
15167 else
cc933301 15168 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15169}
15170
15171static void
15172do_neon_qdmulh (void)
15173{
15174 if (inst.operands[2].isscalar)
15175 {
037e8744 15176 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, 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 (SCALAR, inst);
037e8744 15180 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15181 }
15182 else
15183 {
037e8744 15184 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15185 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15186 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15187 NEON_ENCODE (INTEGER, inst);
5287ad62 15188 /* The U bit (rounding) comes from bit mask. */
037e8744 15189 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15190 }
15191}
15192
643afb90
MW
15193static void
15194do_neon_qrdmlah (void)
15195{
15196 /* Check we're on the correct architecture. */
15197 if (!mark_feature_used (&fpu_neon_ext_armv8))
15198 inst.error =
15199 _("instruction form not available on this architecture.");
15200 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15201 {
15202 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15203 record_feature_use (&fpu_neon_ext_v8_1);
15204 }
15205
15206 if (inst.operands[2].isscalar)
15207 {
15208 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, 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 (SCALAR, inst);
15212 neon_mul_mac (et, neon_quad (rs));
15213 }
15214 else
15215 {
15216 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15217 struct neon_type_el et = neon_check_type (3, rs,
15218 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15219 NEON_ENCODE (INTEGER, inst);
15220 /* The U bit (rounding) comes from bit mask. */
15221 neon_three_same (neon_quad (rs), 0, et.size);
15222 }
15223}
15224
5287ad62
JB
15225static void
15226do_neon_fcmp_absolute (void)
15227{
037e8744 15228 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15229 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15230 N_F_16_32 | N_KEY);
5287ad62 15231 /* Size field comes from bit mask. */
cc933301 15232 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15233}
15234
15235static void
15236do_neon_fcmp_absolute_inv (void)
15237{
15238 neon_exchange_operands ();
15239 do_neon_fcmp_absolute ();
15240}
15241
15242static void
15243do_neon_step (void)
15244{
037e8744 15245 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15246 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15247 N_F_16_32 | N_KEY);
15248 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15249}
15250
15251static void
15252do_neon_abs_neg (void)
15253{
037e8744
JB
15254 enum neon_shape rs;
15255 struct neon_type_el et;
5f4273c7 15256
037e8744
JB
15257 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15258 return;
15259
15260 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15261 return;
15262
15263 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15264 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15265
5287ad62
JB
15266 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15267 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15268 inst.instruction |= LOW4 (inst.operands[1].reg);
15269 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15270 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15271 inst.instruction |= (et.type == NT_float) << 10;
15272 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15273
88714cb8 15274 neon_dp_fixup (&inst);
5287ad62
JB
15275}
15276
15277static void
15278do_neon_sli (void)
15279{
037e8744 15280 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15281 struct neon_type_el et = neon_check_type (2, rs,
15282 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15283 int imm = inst.operands[2].imm;
15284 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15285 _("immediate out of range for insert"));
037e8744 15286 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15287}
15288
15289static void
15290do_neon_sri (void)
15291{
037e8744 15292 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15293 struct neon_type_el et = neon_check_type (2, rs,
15294 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15295 int imm = inst.operands[2].imm;
15296 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15297 _("immediate out of range for insert"));
037e8744 15298 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15299}
15300
15301static void
15302do_neon_qshlu_imm (void)
15303{
037e8744 15304 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15305 struct neon_type_el et = neon_check_type (2, rs,
15306 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15307 int imm = inst.operands[2].imm;
15308 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15309 _("immediate out of range for shift"));
5287ad62
JB
15310 /* Only encodes the 'U present' variant of the instruction.
15311 In this case, signed types have OP (bit 8) set to 0.
15312 Unsigned types have OP set to 1. */
15313 inst.instruction |= (et.type == NT_unsigned) << 8;
15314 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15315 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15316}
15317
15318static void
15319do_neon_qmovn (void)
15320{
15321 struct neon_type_el et = neon_check_type (2, NS_DQ,
15322 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15323 /* Saturating move where operands can be signed or unsigned, and the
15324 destination has the same signedness. */
88714cb8 15325 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15326 if (et.type == NT_unsigned)
15327 inst.instruction |= 0xc0;
15328 else
15329 inst.instruction |= 0x80;
15330 neon_two_same (0, 1, et.size / 2);
15331}
15332
15333static void
15334do_neon_qmovun (void)
15335{
15336 struct neon_type_el et = neon_check_type (2, NS_DQ,
15337 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15338 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15339 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15340 neon_two_same (0, 1, et.size / 2);
15341}
15342
15343static void
15344do_neon_rshift_sat_narrow (void)
15345{
15346 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15347 or unsigned. If operands are unsigned, results must also be unsigned. */
15348 struct neon_type_el et = neon_check_type (2, NS_DQI,
15349 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15350 int imm = inst.operands[2].imm;
15351 /* This gets the bounds check, size encoding and immediate bits calculation
15352 right. */
15353 et.size /= 2;
5f4273c7 15354
5287ad62
JB
15355 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15356 VQMOVN.I<size> <Dd>, <Qm>. */
15357 if (imm == 0)
15358 {
15359 inst.operands[2].present = 0;
15360 inst.instruction = N_MNEM_vqmovn;
15361 do_neon_qmovn ();
15362 return;
15363 }
5f4273c7 15364
5287ad62 15365 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15366 _("immediate out of range"));
5287ad62
JB
15367 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15368}
15369
15370static void
15371do_neon_rshift_sat_narrow_u (void)
15372{
15373 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15374 or unsigned. If operands are unsigned, results must also be unsigned. */
15375 struct neon_type_el et = neon_check_type (2, NS_DQI,
15376 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15377 int imm = inst.operands[2].imm;
15378 /* This gets the bounds check, size encoding and immediate bits calculation
15379 right. */
15380 et.size /= 2;
15381
15382 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15383 VQMOVUN.I<size> <Dd>, <Qm>. */
15384 if (imm == 0)
15385 {
15386 inst.operands[2].present = 0;
15387 inst.instruction = N_MNEM_vqmovun;
15388 do_neon_qmovun ();
15389 return;
15390 }
15391
15392 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15393 _("immediate out of range"));
5287ad62
JB
15394 /* FIXME: The manual is kind of unclear about what value U should have in
15395 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15396 must be 1. */
15397 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15398}
15399
15400static void
15401do_neon_movn (void)
15402{
15403 struct neon_type_el et = neon_check_type (2, NS_DQ,
15404 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15405 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15406 neon_two_same (0, 1, et.size / 2);
15407}
15408
15409static void
15410do_neon_rshift_narrow (void)
15411{
15412 struct neon_type_el et = neon_check_type (2, NS_DQI,
15413 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15414 int imm = inst.operands[2].imm;
15415 /* This gets the bounds check, size encoding and immediate bits calculation
15416 right. */
15417 et.size /= 2;
5f4273c7 15418
5287ad62
JB
15419 /* If immediate is zero then we are a pseudo-instruction for
15420 VMOVN.I<size> <Dd>, <Qm> */
15421 if (imm == 0)
15422 {
15423 inst.operands[2].present = 0;
15424 inst.instruction = N_MNEM_vmovn;
15425 do_neon_movn ();
15426 return;
15427 }
5f4273c7 15428
5287ad62 15429 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15430 _("immediate out of range for narrowing operation"));
5287ad62
JB
15431 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15432}
15433
15434static void
15435do_neon_shll (void)
15436{
15437 /* FIXME: Type checking when lengthening. */
15438 struct neon_type_el et = neon_check_type (2, NS_QDI,
15439 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15440 unsigned imm = inst.operands[2].imm;
15441
15442 if (imm == et.size)
15443 {
15444 /* Maximum shift variant. */
88714cb8 15445 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15446 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15447 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15448 inst.instruction |= LOW4 (inst.operands[1].reg);
15449 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15450 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15451
88714cb8 15452 neon_dp_fixup (&inst);
5287ad62
JB
15453 }
15454 else
15455 {
15456 /* A more-specific type check for non-max versions. */
15457 et = neon_check_type (2, NS_QDI,
477330fc 15458 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15459 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15460 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15461 }
15462}
15463
037e8744 15464/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15465 the current instruction is. */
15466
6b9a8b67
MGD
15467#define CVT_FLAVOUR_VAR \
15468 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15469 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15470 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15471 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15472 /* Half-precision conversions. */ \
cc933301
JW
15473 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15474 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15475 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15476 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15477 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15478 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15479 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15480 Compared with single/double precision variants, only the co-processor \
15481 field is different, so the encoding flow is reused here. */ \
15482 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15483 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15484 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15485 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15486 /* VFP instructions. */ \
15487 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15488 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15489 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15490 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15491 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15492 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15493 /* VFP instructions with bitshift. */ \
15494 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15495 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15496 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15497 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15498 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15499 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15500 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15501 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15502
15503#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15504 neon_cvt_flavour_##C,
15505
15506/* The different types of conversions we can do. */
15507enum neon_cvt_flavour
15508{
15509 CVT_FLAVOUR_VAR
15510 neon_cvt_flavour_invalid,
15511 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15512};
15513
15514#undef CVT_VAR
15515
15516static enum neon_cvt_flavour
15517get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15518{
6b9a8b67
MGD
15519#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15520 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15521 if (et.type != NT_invtype) \
15522 { \
15523 inst.error = NULL; \
15524 return (neon_cvt_flavour_##C); \
5287ad62 15525 }
6b9a8b67 15526
5287ad62 15527 struct neon_type_el et;
037e8744 15528 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15529 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15530 /* The instruction versions which take an immediate take one register
15531 argument, which is extended to the width of the full register. Thus the
15532 "source" and "destination" registers must have the same width. Hack that
15533 here by making the size equal to the key (wider, in this case) operand. */
15534 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15535
6b9a8b67
MGD
15536 CVT_FLAVOUR_VAR;
15537
15538 return neon_cvt_flavour_invalid;
5287ad62
JB
15539#undef CVT_VAR
15540}
15541
7e8e6784
MGD
15542enum neon_cvt_mode
15543{
15544 neon_cvt_mode_a,
15545 neon_cvt_mode_n,
15546 neon_cvt_mode_p,
15547 neon_cvt_mode_m,
15548 neon_cvt_mode_z,
30bdf752
MGD
15549 neon_cvt_mode_x,
15550 neon_cvt_mode_r
7e8e6784
MGD
15551};
15552
037e8744
JB
15553/* Neon-syntax VFP conversions. */
15554
5287ad62 15555static void
6b9a8b67 15556do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15557{
037e8744 15558 const char *opname = 0;
5f4273c7 15559
d54af2d0
RL
15560 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15561 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15562 {
037e8744
JB
15563 /* Conversions with immediate bitshift. */
15564 const char *enc[] =
477330fc 15565 {
6b9a8b67
MGD
15566#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15567 CVT_FLAVOUR_VAR
15568 NULL
15569#undef CVT_VAR
477330fc 15570 };
037e8744 15571
6b9a8b67 15572 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15573 {
15574 opname = enc[flavour];
15575 constraint (inst.operands[0].reg != inst.operands[1].reg,
15576 _("operands 0 and 1 must be the same register"));
15577 inst.operands[1] = inst.operands[2];
15578 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15579 }
5287ad62
JB
15580 }
15581 else
15582 {
037e8744
JB
15583 /* Conversions without bitshift. */
15584 const char *enc[] =
477330fc 15585 {
6b9a8b67
MGD
15586#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15587 CVT_FLAVOUR_VAR
15588 NULL
15589#undef CVT_VAR
477330fc 15590 };
037e8744 15591
6b9a8b67 15592 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15593 opname = enc[flavour];
037e8744
JB
15594 }
15595
15596 if (opname)
15597 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15598
15599 /* ARMv8.2 fp16 VCVT instruction. */
15600 if (flavour == neon_cvt_flavour_s32_f16
15601 || flavour == neon_cvt_flavour_u32_f16
15602 || flavour == neon_cvt_flavour_f16_u32
15603 || flavour == neon_cvt_flavour_f16_s32)
15604 do_scalar_fp16_v82_encode ();
037e8744
JB
15605}
15606
15607static void
15608do_vfp_nsyn_cvtz (void)
15609{
d54af2d0 15610 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15611 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15612 const char *enc[] =
15613 {
6b9a8b67
MGD
15614#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15615 CVT_FLAVOUR_VAR
15616 NULL
15617#undef CVT_VAR
037e8744
JB
15618 };
15619
6b9a8b67 15620 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15621 do_vfp_nsyn_opcode (enc[flavour]);
15622}
f31fef98 15623
037e8744 15624static void
bacebabc 15625do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15626 enum neon_cvt_mode mode)
15627{
15628 int sz, op;
15629 int rm;
15630
a715796b
TG
15631 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15632 D register operands. */
15633 if (flavour == neon_cvt_flavour_s32_f64
15634 || flavour == neon_cvt_flavour_u32_f64)
15635 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15636 _(BAD_FPU));
15637
9db2f6b4
RL
15638 if (flavour == neon_cvt_flavour_s32_f16
15639 || flavour == neon_cvt_flavour_u32_f16)
15640 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15641 _(BAD_FP16));
15642
7e8e6784
MGD
15643 set_it_insn_type (OUTSIDE_IT_INSN);
15644
15645 switch (flavour)
15646 {
15647 case neon_cvt_flavour_s32_f64:
15648 sz = 1;
827f64ff 15649 op = 1;
7e8e6784
MGD
15650 break;
15651 case neon_cvt_flavour_s32_f32:
15652 sz = 0;
15653 op = 1;
15654 break;
9db2f6b4
RL
15655 case neon_cvt_flavour_s32_f16:
15656 sz = 0;
15657 op = 1;
15658 break;
7e8e6784
MGD
15659 case neon_cvt_flavour_u32_f64:
15660 sz = 1;
15661 op = 0;
15662 break;
15663 case neon_cvt_flavour_u32_f32:
15664 sz = 0;
15665 op = 0;
15666 break;
9db2f6b4
RL
15667 case neon_cvt_flavour_u32_f16:
15668 sz = 0;
15669 op = 0;
15670 break;
7e8e6784
MGD
15671 default:
15672 first_error (_("invalid instruction shape"));
15673 return;
15674 }
15675
15676 switch (mode)
15677 {
15678 case neon_cvt_mode_a: rm = 0; break;
15679 case neon_cvt_mode_n: rm = 1; break;
15680 case neon_cvt_mode_p: rm = 2; break;
15681 case neon_cvt_mode_m: rm = 3; break;
15682 default: first_error (_("invalid rounding mode")); return;
15683 }
15684
15685 NEON_ENCODE (FPV8, inst);
15686 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15687 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15688 inst.instruction |= sz << 8;
9db2f6b4
RL
15689
15690 /* ARMv8.2 fp16 VCVT instruction. */
15691 if (flavour == neon_cvt_flavour_s32_f16
15692 ||flavour == neon_cvt_flavour_u32_f16)
15693 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15694 inst.instruction |= op << 7;
15695 inst.instruction |= rm << 16;
15696 inst.instruction |= 0xf0000000;
15697 inst.is_neon = TRUE;
15698}
15699
15700static void
15701do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15702{
15703 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15704 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15705 NS_FH, NS_HF, NS_FHI, NS_HFI,
15706 NS_NULL);
6b9a8b67 15707 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15708
cc933301
JW
15709 if (flavour == neon_cvt_flavour_invalid)
15710 return;
15711
e3e535bc 15712 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15713 if (mode == neon_cvt_mode_z
e3e535bc 15714 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15715 && (flavour == neon_cvt_flavour_s16_f16
15716 || flavour == neon_cvt_flavour_u16_f16
15717 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15718 || flavour == neon_cvt_flavour_u32_f32
15719 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15720 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15721 && (rs == NS_FD || rs == NS_FF))
15722 {
15723 do_vfp_nsyn_cvtz ();
15724 return;
15725 }
15726
9db2f6b4
RL
15727 /* ARMv8.2 fp16 VCVT conversions. */
15728 if (mode == neon_cvt_mode_z
15729 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15730 && (flavour == neon_cvt_flavour_s32_f16
15731 || flavour == neon_cvt_flavour_u32_f16)
15732 && (rs == NS_FH))
15733 {
15734 do_vfp_nsyn_cvtz ();
15735 do_scalar_fp16_v82_encode ();
15736 return;
15737 }
15738
037e8744 15739 /* VFP rather than Neon conversions. */
6b9a8b67 15740 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15741 {
7e8e6784
MGD
15742 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15743 do_vfp_nsyn_cvt (rs, flavour);
15744 else
15745 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15746
037e8744
JB
15747 return;
15748 }
15749
15750 switch (rs)
15751 {
15752 case NS_DDI:
15753 case NS_QQI:
15754 {
477330fc 15755 unsigned immbits;
cc933301
JW
15756 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15757 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15758
477330fc
RM
15759 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15760 return;
037e8744 15761
477330fc
RM
15762 /* Fixed-point conversion with #0 immediate is encoded as an
15763 integer conversion. */
15764 if (inst.operands[2].present && inst.operands[2].imm == 0)
15765 goto int_encode;
477330fc
RM
15766 NEON_ENCODE (IMMED, inst);
15767 if (flavour != neon_cvt_flavour_invalid)
15768 inst.instruction |= enctab[flavour];
15769 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15770 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15771 inst.instruction |= LOW4 (inst.operands[1].reg);
15772 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15773 inst.instruction |= neon_quad (rs) << 6;
15774 inst.instruction |= 1 << 21;
cc933301
JW
15775 if (flavour < neon_cvt_flavour_s16_f16)
15776 {
15777 inst.instruction |= 1 << 21;
15778 immbits = 32 - inst.operands[2].imm;
15779 inst.instruction |= immbits << 16;
15780 }
15781 else
15782 {
15783 inst.instruction |= 3 << 20;
15784 immbits = 16 - inst.operands[2].imm;
15785 inst.instruction |= immbits << 16;
15786 inst.instruction &= ~(1 << 9);
15787 }
477330fc
RM
15788
15789 neon_dp_fixup (&inst);
037e8744
JB
15790 }
15791 break;
15792
15793 case NS_DD:
15794 case NS_QQ:
7e8e6784
MGD
15795 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15796 {
15797 NEON_ENCODE (FLOAT, inst);
15798 set_it_insn_type (OUTSIDE_IT_INSN);
15799
15800 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15801 return;
15802
15803 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15804 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15805 inst.instruction |= LOW4 (inst.operands[1].reg);
15806 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15807 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15808 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15809 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15810 inst.instruction |= mode << 8;
cc933301
JW
15811 if (flavour == neon_cvt_flavour_u16_f16
15812 || flavour == neon_cvt_flavour_s16_f16)
15813 /* Mask off the original size bits and reencode them. */
15814 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15815
7e8e6784
MGD
15816 if (thumb_mode)
15817 inst.instruction |= 0xfc000000;
15818 else
15819 inst.instruction |= 0xf0000000;
15820 }
15821 else
15822 {
037e8744 15823 int_encode:
7e8e6784 15824 {
cc933301
JW
15825 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15826 0x100, 0x180, 0x0, 0x080};
037e8744 15827
7e8e6784 15828 NEON_ENCODE (INTEGER, inst);
037e8744 15829
7e8e6784
MGD
15830 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15831 return;
037e8744 15832
7e8e6784
MGD
15833 if (flavour != neon_cvt_flavour_invalid)
15834 inst.instruction |= enctab[flavour];
037e8744 15835
7e8e6784
MGD
15836 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15837 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15838 inst.instruction |= LOW4 (inst.operands[1].reg);
15839 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15840 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15841 if (flavour >= neon_cvt_flavour_s16_f16
15842 && flavour <= neon_cvt_flavour_f16_u16)
15843 /* Half precision. */
15844 inst.instruction |= 1 << 18;
15845 else
15846 inst.instruction |= 2 << 18;
037e8744 15847
7e8e6784
MGD
15848 neon_dp_fixup (&inst);
15849 }
15850 }
15851 break;
037e8744 15852
8e79c3df
CM
15853 /* Half-precision conversions for Advanced SIMD -- neon. */
15854 case NS_QD:
15855 case NS_DQ:
15856
15857 if ((rs == NS_DQ)
15858 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15859 {
15860 as_bad (_("operand size must match register width"));
15861 break;
15862 }
15863
15864 if ((rs == NS_QD)
15865 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15866 {
15867 as_bad (_("operand size must match register width"));
15868 break;
15869 }
15870
15871 if (rs == NS_DQ)
477330fc 15872 inst.instruction = 0x3b60600;
8e79c3df
CM
15873 else
15874 inst.instruction = 0x3b60700;
15875
15876 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15877 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15878 inst.instruction |= LOW4 (inst.operands[1].reg);
15879 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15880 neon_dp_fixup (&inst);
8e79c3df
CM
15881 break;
15882
037e8744
JB
15883 default:
15884 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15885 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15886 do_vfp_nsyn_cvt (rs, flavour);
15887 else
15888 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15889 }
5287ad62
JB
15890}
15891
e3e535bc
NC
15892static void
15893do_neon_cvtr (void)
15894{
7e8e6784 15895 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15896}
15897
15898static void
15899do_neon_cvt (void)
15900{
7e8e6784
MGD
15901 do_neon_cvt_1 (neon_cvt_mode_z);
15902}
15903
15904static void
15905do_neon_cvta (void)
15906{
15907 do_neon_cvt_1 (neon_cvt_mode_a);
15908}
15909
15910static void
15911do_neon_cvtn (void)
15912{
15913 do_neon_cvt_1 (neon_cvt_mode_n);
15914}
15915
15916static void
15917do_neon_cvtp (void)
15918{
15919 do_neon_cvt_1 (neon_cvt_mode_p);
15920}
15921
15922static void
15923do_neon_cvtm (void)
15924{
15925 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15926}
15927
8e79c3df 15928static void
c70a8987 15929do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15930{
c70a8987
MGD
15931 if (is_double)
15932 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15933
c70a8987
MGD
15934 encode_arm_vfp_reg (inst.operands[0].reg,
15935 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15936 encode_arm_vfp_reg (inst.operands[1].reg,
15937 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15938 inst.instruction |= to ? 0x10000 : 0;
15939 inst.instruction |= t ? 0x80 : 0;
15940 inst.instruction |= is_double ? 0x100 : 0;
15941 do_vfp_cond_or_thumb ();
15942}
8e79c3df 15943
c70a8987
MGD
15944static void
15945do_neon_cvttb_1 (bfd_boolean t)
15946{
d54af2d0
RL
15947 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15948 NS_DF, NS_DH, NS_NULL);
8e79c3df 15949
c70a8987
MGD
15950 if (rs == NS_NULL)
15951 return;
15952 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15953 {
15954 inst.error = NULL;
15955 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15956 }
15957 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15958 {
15959 inst.error = NULL;
15960 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15961 }
15962 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15963 {
a715796b
TG
15964 /* The VCVTB and VCVTT instructions with D-register operands
15965 don't work for SP only targets. */
15966 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15967 _(BAD_FPU));
15968
c70a8987
MGD
15969 inst.error = NULL;
15970 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15971 }
15972 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15973 {
a715796b
TG
15974 /* The VCVTB and VCVTT instructions with D-register operands
15975 don't work for SP only targets. */
15976 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15977 _(BAD_FPU));
15978
c70a8987
MGD
15979 inst.error = NULL;
15980 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15981 }
15982 else
15983 return;
15984}
15985
15986static void
15987do_neon_cvtb (void)
15988{
15989 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15990}
15991
15992
15993static void
15994do_neon_cvtt (void)
15995{
c70a8987 15996 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15997}
15998
5287ad62
JB
15999static void
16000neon_move_immediate (void)
16001{
037e8744
JB
16002 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16003 struct neon_type_el et = neon_check_type (2, rs,
16004 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16005 unsigned immlo, immhi = 0, immbits;
c96612cc 16006 int op, cmode, float_p;
5287ad62 16007
037e8744 16008 constraint (et.type == NT_invtype,
477330fc 16009 _("operand size must be specified for immediate VMOV"));
037e8744 16010
5287ad62
JB
16011 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16012 op = (inst.instruction & (1 << 5)) != 0;
16013
16014 immlo = inst.operands[1].imm;
16015 if (inst.operands[1].regisimm)
16016 immhi = inst.operands[1].reg;
16017
16018 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16019 _("immediate has bits set outside the operand size"));
5287ad62 16020
c96612cc
JB
16021 float_p = inst.operands[1].immisfloat;
16022
16023 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16024 et.size, et.type)) == FAIL)
5287ad62
JB
16025 {
16026 /* Invert relevant bits only. */
16027 neon_invert_size (&immlo, &immhi, et.size);
16028 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16029 with one or the other; those cases are caught by
16030 neon_cmode_for_move_imm. */
5287ad62 16031 op = !op;
c96612cc
JB
16032 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16033 &op, et.size, et.type)) == FAIL)
477330fc
RM
16034 {
16035 first_error (_("immediate out of range"));
16036 return;
16037 }
5287ad62
JB
16038 }
16039
16040 inst.instruction &= ~(1 << 5);
16041 inst.instruction |= op << 5;
16042
16043 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16044 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16045 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16046 inst.instruction |= cmode << 8;
16047
16048 neon_write_immbits (immbits);
16049}
16050
16051static void
16052do_neon_mvn (void)
16053{
16054 if (inst.operands[1].isreg)
16055 {
037e8744 16056 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16057
88714cb8 16058 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16059 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16060 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16061 inst.instruction |= LOW4 (inst.operands[1].reg);
16062 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16063 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16064 }
16065 else
16066 {
88714cb8 16067 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16068 neon_move_immediate ();
16069 }
16070
88714cb8 16071 neon_dp_fixup (&inst);
5287ad62
JB
16072}
16073
16074/* Encode instructions of form:
16075
16076 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16077 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16078
16079static void
16080neon_mixed_length (struct neon_type_el et, unsigned size)
16081{
16082 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16083 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16084 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16085 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16086 inst.instruction |= LOW4 (inst.operands[2].reg);
16087 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16088 inst.instruction |= (et.type == NT_unsigned) << 24;
16089 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16090
88714cb8 16091 neon_dp_fixup (&inst);
5287ad62
JB
16092}
16093
16094static void
16095do_neon_dyadic_long (void)
16096{
16097 /* FIXME: Type checking for lengthening op. */
16098 struct neon_type_el et = neon_check_type (3, NS_QDD,
16099 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16100 neon_mixed_length (et, et.size);
16101}
16102
16103static void
16104do_neon_abal (void)
16105{
16106 struct neon_type_el et = neon_check_type (3, NS_QDD,
16107 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16108 neon_mixed_length (et, et.size);
16109}
16110
16111static void
16112neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16113{
16114 if (inst.operands[2].isscalar)
16115 {
dcbf9037 16116 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16117 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16118 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16119 neon_mul_mac (et, et.type == NT_unsigned);
16120 }
16121 else
16122 {
16123 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16124 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16125 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16126 neon_mixed_length (et, et.size);
16127 }
16128}
16129
16130static void
16131do_neon_mac_maybe_scalar_long (void)
16132{
16133 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16134}
16135
16136static void
16137do_neon_dyadic_wide (void)
16138{
16139 struct neon_type_el et = neon_check_type (3, NS_QQD,
16140 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16141 neon_mixed_length (et, et.size);
16142}
16143
16144static void
16145do_neon_dyadic_narrow (void)
16146{
16147 struct neon_type_el et = neon_check_type (3, NS_QDD,
16148 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16149 /* Operand sign is unimportant, and the U bit is part of the opcode,
16150 so force the operand type to integer. */
16151 et.type = NT_integer;
5287ad62
JB
16152 neon_mixed_length (et, et.size / 2);
16153}
16154
16155static void
16156do_neon_mul_sat_scalar_long (void)
16157{
16158 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16159}
16160
16161static void
16162do_neon_vmull (void)
16163{
16164 if (inst.operands[2].isscalar)
16165 do_neon_mac_maybe_scalar_long ();
16166 else
16167 {
16168 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16169 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16170
5287ad62 16171 if (et.type == NT_poly)
477330fc 16172 NEON_ENCODE (POLY, inst);
5287ad62 16173 else
477330fc 16174 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16175
16176 /* For polynomial encoding the U bit must be zero, and the size must
16177 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16178 obviously, as 0b10). */
16179 if (et.size == 64)
16180 {
16181 /* Check we're on the correct architecture. */
16182 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16183 inst.error =
16184 _("Instruction form not available on this architecture.");
16185
16186 et.size = 32;
16187 }
16188
5287ad62
JB
16189 neon_mixed_length (et, et.size);
16190 }
16191}
16192
16193static void
16194do_neon_ext (void)
16195{
037e8744 16196 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16197 struct neon_type_el et = neon_check_type (3, rs,
16198 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16199 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16200
16201 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16202 _("shift out of range"));
5287ad62
JB
16203 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16204 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16205 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16206 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16207 inst.instruction |= LOW4 (inst.operands[2].reg);
16208 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16209 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16210 inst.instruction |= imm << 8;
5f4273c7 16211
88714cb8 16212 neon_dp_fixup (&inst);
5287ad62
JB
16213}
16214
16215static void
16216do_neon_rev (void)
16217{
037e8744 16218 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16219 struct neon_type_el et = neon_check_type (2, rs,
16220 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16221 unsigned op = (inst.instruction >> 7) & 3;
16222 /* N (width of reversed regions) is encoded as part of the bitmask. We
16223 extract it here to check the elements to be reversed are smaller.
16224 Otherwise we'd get a reserved instruction. */
16225 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16226 gas_assert (elsize != 0);
5287ad62 16227 constraint (et.size >= elsize,
477330fc 16228 _("elements must be smaller than reversal region"));
037e8744 16229 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16230}
16231
16232static void
16233do_neon_dup (void)
16234{
16235 if (inst.operands[1].isscalar)
16236 {
037e8744 16237 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16238 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16239 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16240 unsigned sizebits = et.size >> 3;
dcbf9037 16241 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16242 int logsize = neon_logbits (et.size);
dcbf9037 16243 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16244
16245 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16246 return;
037e8744 16247
88714cb8 16248 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16249 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16250 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16251 inst.instruction |= LOW4 (dm);
16252 inst.instruction |= HI1 (dm) << 5;
037e8744 16253 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16254 inst.instruction |= x << 17;
16255 inst.instruction |= sizebits << 16;
5f4273c7 16256
88714cb8 16257 neon_dp_fixup (&inst);
5287ad62
JB
16258 }
16259 else
16260 {
037e8744
JB
16261 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16262 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16263 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16264 /* Duplicate ARM register to lanes of vector. */
88714cb8 16265 NEON_ENCODE (ARMREG, inst);
5287ad62 16266 switch (et.size)
477330fc
RM
16267 {
16268 case 8: inst.instruction |= 0x400000; break;
16269 case 16: inst.instruction |= 0x000020; break;
16270 case 32: inst.instruction |= 0x000000; break;
16271 default: break;
16272 }
5287ad62
JB
16273 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16274 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16275 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16276 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16277 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16278 variants, except for the condition field. */
037e8744 16279 do_vfp_cond_or_thumb ();
5287ad62
JB
16280 }
16281}
16282
16283/* VMOV has particularly many variations. It can be one of:
16284 0. VMOV<c><q> <Qd>, <Qm>
16285 1. VMOV<c><q> <Dd>, <Dm>
16286 (Register operations, which are VORR with Rm = Rn.)
16287 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16288 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16289 (Immediate loads.)
16290 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16291 (ARM register to scalar.)
16292 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16293 (Two ARM registers to vector.)
16294 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16295 (Scalar to ARM register.)
16296 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16297 (Vector to two ARM registers.)
037e8744
JB
16298 8. VMOV.F32 <Sd>, <Sm>
16299 9. VMOV.F64 <Dd>, <Dm>
16300 (VFP register moves.)
16301 10. VMOV.F32 <Sd>, #imm
16302 11. VMOV.F64 <Dd>, #imm
16303 (VFP float immediate load.)
16304 12. VMOV <Rd>, <Sm>
16305 (VFP single to ARM reg.)
16306 13. VMOV <Sd>, <Rm>
16307 (ARM reg to VFP single.)
16308 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16309 (Two ARM regs to two VFP singles.)
16310 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16311 (Two VFP singles to two ARM regs.)
5f4273c7 16312
037e8744
JB
16313 These cases can be disambiguated using neon_select_shape, except cases 1/9
16314 and 3/11 which depend on the operand type too.
5f4273c7 16315
5287ad62 16316 All the encoded bits are hardcoded by this function.
5f4273c7 16317
b7fc2769
JB
16318 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16319 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16320
5287ad62 16321 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16322 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16323
16324static void
16325do_neon_mov (void)
16326{
037e8744 16327 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16328 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16329 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16330 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16331 struct neon_type_el et;
16332 const char *ldconst = 0;
5287ad62 16333
037e8744 16334 switch (rs)
5287ad62 16335 {
037e8744
JB
16336 case NS_DD: /* case 1/9. */
16337 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16338 /* It is not an error here if no type is given. */
16339 inst.error = NULL;
16340 if (et.type == NT_float && et.size == 64)
477330fc
RM
16341 {
16342 do_vfp_nsyn_opcode ("fcpyd");
16343 break;
16344 }
037e8744 16345 /* fall through. */
5287ad62 16346
037e8744
JB
16347 case NS_QQ: /* case 0/1. */
16348 {
477330fc
RM
16349 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16350 return;
16351 /* The architecture manual I have doesn't explicitly state which
16352 value the U bit should have for register->register moves, but
16353 the equivalent VORR instruction has U = 0, so do that. */
16354 inst.instruction = 0x0200110;
16355 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16356 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16357 inst.instruction |= LOW4 (inst.operands[1].reg);
16358 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16359 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16360 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16361 inst.instruction |= neon_quad (rs) << 6;
16362
16363 neon_dp_fixup (&inst);
037e8744
JB
16364 }
16365 break;
5f4273c7 16366
037e8744
JB
16367 case NS_DI: /* case 3/11. */
16368 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16369 inst.error = NULL;
16370 if (et.type == NT_float && et.size == 64)
477330fc
RM
16371 {
16372 /* case 11 (fconstd). */
16373 ldconst = "fconstd";
16374 goto encode_fconstd;
16375 }
037e8744
JB
16376 /* fall through. */
16377
16378 case NS_QI: /* case 2/3. */
16379 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16380 return;
037e8744
JB
16381 inst.instruction = 0x0800010;
16382 neon_move_immediate ();
88714cb8 16383 neon_dp_fixup (&inst);
5287ad62 16384 break;
5f4273c7 16385
037e8744
JB
16386 case NS_SR: /* case 4. */
16387 {
477330fc
RM
16388 unsigned bcdebits = 0;
16389 int logsize;
16390 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16391 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16392
05ac0ffb
JB
16393 /* .<size> is optional here, defaulting to .32. */
16394 if (inst.vectype.elems == 0
16395 && inst.operands[0].vectype.type == NT_invtype
16396 && inst.operands[1].vectype.type == NT_invtype)
16397 {
16398 inst.vectype.el[0].type = NT_untyped;
16399 inst.vectype.el[0].size = 32;
16400 inst.vectype.elems = 1;
16401 }
16402
477330fc
RM
16403 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16404 logsize = neon_logbits (et.size);
16405
16406 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16407 _(BAD_FPU));
16408 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16409 && et.size != 32, _(BAD_FPU));
16410 constraint (et.type == NT_invtype, _("bad type for scalar"));
16411 constraint (x >= 64 / et.size, _("scalar index out of range"));
16412
16413 switch (et.size)
16414 {
16415 case 8: bcdebits = 0x8; break;
16416 case 16: bcdebits = 0x1; break;
16417 case 32: bcdebits = 0x0; break;
16418 default: ;
16419 }
16420
16421 bcdebits |= x << logsize;
16422
16423 inst.instruction = 0xe000b10;
16424 do_vfp_cond_or_thumb ();
16425 inst.instruction |= LOW4 (dn) << 16;
16426 inst.instruction |= HI1 (dn) << 7;
16427 inst.instruction |= inst.operands[1].reg << 12;
16428 inst.instruction |= (bcdebits & 3) << 5;
16429 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16430 }
16431 break;
5f4273c7 16432
037e8744 16433 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16434 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16435 _(BAD_FPU));
b7fc2769 16436
037e8744
JB
16437 inst.instruction = 0xc400b10;
16438 do_vfp_cond_or_thumb ();
16439 inst.instruction |= LOW4 (inst.operands[0].reg);
16440 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16441 inst.instruction |= inst.operands[1].reg << 12;
16442 inst.instruction |= inst.operands[2].reg << 16;
16443 break;
5f4273c7 16444
037e8744
JB
16445 case NS_RS: /* case 6. */
16446 {
477330fc
RM
16447 unsigned logsize;
16448 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16449 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16450 unsigned abcdebits = 0;
037e8744 16451
05ac0ffb
JB
16452 /* .<dt> is optional here, defaulting to .32. */
16453 if (inst.vectype.elems == 0
16454 && inst.operands[0].vectype.type == NT_invtype
16455 && inst.operands[1].vectype.type == NT_invtype)
16456 {
16457 inst.vectype.el[0].type = NT_untyped;
16458 inst.vectype.el[0].size = 32;
16459 inst.vectype.elems = 1;
16460 }
16461
91d6fa6a
NC
16462 et = neon_check_type (2, NS_NULL,
16463 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16464 logsize = neon_logbits (et.size);
16465
16466 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16467 _(BAD_FPU));
16468 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16469 && et.size != 32, _(BAD_FPU));
16470 constraint (et.type == NT_invtype, _("bad type for scalar"));
16471 constraint (x >= 64 / et.size, _("scalar index out of range"));
16472
16473 switch (et.size)
16474 {
16475 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16476 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16477 case 32: abcdebits = 0x00; break;
16478 default: ;
16479 }
16480
16481 abcdebits |= x << logsize;
16482 inst.instruction = 0xe100b10;
16483 do_vfp_cond_or_thumb ();
16484 inst.instruction |= LOW4 (dn) << 16;
16485 inst.instruction |= HI1 (dn) << 7;
16486 inst.instruction |= inst.operands[0].reg << 12;
16487 inst.instruction |= (abcdebits & 3) << 5;
16488 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16489 }
16490 break;
5f4273c7 16491
037e8744
JB
16492 case NS_RRD: /* case 7 (fmrrd). */
16493 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16494 _(BAD_FPU));
037e8744
JB
16495
16496 inst.instruction = 0xc500b10;
16497 do_vfp_cond_or_thumb ();
16498 inst.instruction |= inst.operands[0].reg << 12;
16499 inst.instruction |= inst.operands[1].reg << 16;
16500 inst.instruction |= LOW4 (inst.operands[2].reg);
16501 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16502 break;
5f4273c7 16503
037e8744
JB
16504 case NS_FF: /* case 8 (fcpys). */
16505 do_vfp_nsyn_opcode ("fcpys");
16506 break;
5f4273c7 16507
9db2f6b4 16508 case NS_HI:
037e8744
JB
16509 case NS_FI: /* case 10 (fconsts). */
16510 ldconst = "fconsts";
16511 encode_fconstd:
16512 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16513 {
16514 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16515 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16516
16517 /* ARMv8.2 fp16 vmov.f16 instruction. */
16518 if (rs == NS_HI)
16519 do_scalar_fp16_v82_encode ();
477330fc 16520 }
5287ad62 16521 else
477330fc 16522 first_error (_("immediate out of range"));
037e8744 16523 break;
5f4273c7 16524
9db2f6b4 16525 case NS_RH:
037e8744
JB
16526 case NS_RF: /* case 12 (fmrs). */
16527 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16528 /* ARMv8.2 fp16 vmov.f16 instruction. */
16529 if (rs == NS_RH)
16530 do_scalar_fp16_v82_encode ();
037e8744 16531 break;
5f4273c7 16532
9db2f6b4 16533 case NS_HR:
037e8744
JB
16534 case NS_FR: /* case 13 (fmsr). */
16535 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16536 /* ARMv8.2 fp16 vmov.f16 instruction. */
16537 if (rs == NS_HR)
16538 do_scalar_fp16_v82_encode ();
037e8744 16539 break;
5f4273c7 16540
037e8744
JB
16541 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16542 (one of which is a list), but we have parsed four. Do some fiddling to
16543 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16544 expect. */
16545 case NS_RRFF: /* case 14 (fmrrs). */
16546 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16547 _("VFP registers must be adjacent"));
037e8744
JB
16548 inst.operands[2].imm = 2;
16549 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16550 do_vfp_nsyn_opcode ("fmrrs");
16551 break;
5f4273c7 16552
037e8744
JB
16553 case NS_FFRR: /* case 15 (fmsrr). */
16554 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16555 _("VFP registers must be adjacent"));
037e8744
JB
16556 inst.operands[1] = inst.operands[2];
16557 inst.operands[2] = inst.operands[3];
16558 inst.operands[0].imm = 2;
16559 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16560 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16561 break;
5f4273c7 16562
4c261dff
NC
16563 case NS_NULL:
16564 /* neon_select_shape has determined that the instruction
16565 shape is wrong and has already set the error message. */
16566 break;
16567
5287ad62
JB
16568 default:
16569 abort ();
16570 }
16571}
16572
16573static void
16574do_neon_rshift_round_imm (void)
16575{
037e8744 16576 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16577 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16578 int imm = inst.operands[2].imm;
16579
16580 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16581 if (imm == 0)
16582 {
16583 inst.operands[2].present = 0;
16584 do_neon_mov ();
16585 return;
16586 }
16587
16588 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16589 _("immediate out of range for shift"));
037e8744 16590 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16591 et.size - imm);
5287ad62
JB
16592}
16593
9db2f6b4
RL
16594static void
16595do_neon_movhf (void)
16596{
16597 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16598 constraint (rs != NS_HH, _("invalid suffix"));
16599
16600 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16601 _(BAD_FPU));
16602
16603 do_vfp_sp_monadic ();
16604
16605 inst.is_neon = 1;
16606 inst.instruction |= 0xf0000000;
16607}
16608
5287ad62
JB
16609static void
16610do_neon_movl (void)
16611{
16612 struct neon_type_el et = neon_check_type (2, NS_QD,
16613 N_EQK | N_DBL, N_SU_32 | N_KEY);
16614 unsigned sizebits = et.size >> 3;
16615 inst.instruction |= sizebits << 19;
16616 neon_two_same (0, et.type == NT_unsigned, -1);
16617}
16618
16619static void
16620do_neon_trn (void)
16621{
037e8744 16622 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16623 struct neon_type_el et = neon_check_type (2, rs,
16624 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16625 NEON_ENCODE (INTEGER, inst);
037e8744 16626 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16627}
16628
16629static void
16630do_neon_zip_uzp (void)
16631{
037e8744 16632 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16633 struct neon_type_el et = neon_check_type (2, rs,
16634 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16635 if (rs == NS_DD && et.size == 32)
16636 {
16637 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16638 inst.instruction = N_MNEM_vtrn;
16639 do_neon_trn ();
16640 return;
16641 }
037e8744 16642 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16643}
16644
16645static void
16646do_neon_sat_abs_neg (void)
16647{
037e8744 16648 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16649 struct neon_type_el et = neon_check_type (2, rs,
16650 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16651 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16652}
16653
16654static void
16655do_neon_pair_long (void)
16656{
037e8744 16657 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16658 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16659 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16660 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16661 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16662}
16663
16664static void
16665do_neon_recip_est (void)
16666{
037e8744 16667 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16668 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16669 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16670 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16671 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16672}
16673
16674static void
16675do_neon_cls (void)
16676{
037e8744 16677 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16678 struct neon_type_el et = neon_check_type (2, rs,
16679 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16680 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16681}
16682
16683static void
16684do_neon_clz (void)
16685{
037e8744 16686 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16687 struct neon_type_el et = neon_check_type (2, rs,
16688 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16689 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16690}
16691
16692static void
16693do_neon_cnt (void)
16694{
037e8744 16695 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16696 struct neon_type_el et = neon_check_type (2, rs,
16697 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16698 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16699}
16700
16701static void
16702do_neon_swp (void)
16703{
037e8744
JB
16704 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16705 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16706}
16707
16708static void
16709do_neon_tbl_tbx (void)
16710{
16711 unsigned listlenbits;
dcbf9037 16712 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16713
5287ad62
JB
16714 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16715 {
dcbf9037 16716 first_error (_("bad list length for table lookup"));
5287ad62
JB
16717 return;
16718 }
5f4273c7 16719
5287ad62
JB
16720 listlenbits = inst.operands[1].imm - 1;
16721 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16722 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16723 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16724 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16725 inst.instruction |= LOW4 (inst.operands[2].reg);
16726 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16727 inst.instruction |= listlenbits << 8;
5f4273c7 16728
88714cb8 16729 neon_dp_fixup (&inst);
5287ad62
JB
16730}
16731
16732static void
16733do_neon_ldm_stm (void)
16734{
16735 /* P, U and L bits are part of bitmask. */
16736 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16737 unsigned offsetbits = inst.operands[1].imm * 2;
16738
037e8744
JB
16739 if (inst.operands[1].issingle)
16740 {
16741 do_vfp_nsyn_ldm_stm (is_dbmode);
16742 return;
16743 }
16744
5287ad62 16745 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16746 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16747
16748 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16749 _("register list must contain at least 1 and at most 16 "
16750 "registers"));
5287ad62
JB
16751
16752 inst.instruction |= inst.operands[0].reg << 16;
16753 inst.instruction |= inst.operands[0].writeback << 21;
16754 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16755 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16756
16757 inst.instruction |= offsetbits;
5f4273c7 16758
037e8744 16759 do_vfp_cond_or_thumb ();
5287ad62
JB
16760}
16761
16762static void
16763do_neon_ldr_str (void)
16764{
5287ad62 16765 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16766
6844b2c2
MGD
16767 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16768 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16769 if (!is_ldr
6844b2c2 16770 && inst.operands[1].reg == REG_PC
ba86b375 16771 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16772 {
94dcf8bf 16773 if (thumb_mode)
6844b2c2 16774 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16775 else if (warn_on_deprecated)
5c3696f8 16776 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16777 }
16778
037e8744
JB
16779 if (inst.operands[0].issingle)
16780 {
cd2f129f 16781 if (is_ldr)
477330fc 16782 do_vfp_nsyn_opcode ("flds");
cd2f129f 16783 else
477330fc 16784 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16785
16786 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16787 if (inst.vectype.el[0].size == 16)
16788 do_scalar_fp16_v82_encode ();
5287ad62
JB
16789 }
16790 else
5287ad62 16791 {
cd2f129f 16792 if (is_ldr)
477330fc 16793 do_vfp_nsyn_opcode ("fldd");
5287ad62 16794 else
477330fc 16795 do_vfp_nsyn_opcode ("fstd");
5287ad62 16796 }
5287ad62
JB
16797}
16798
16799/* "interleave" version also handles non-interleaving register VLD1/VST1
16800 instructions. */
16801
16802static void
16803do_neon_ld_st_interleave (void)
16804{
037e8744 16805 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16806 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16807 unsigned alignbits = 0;
16808 unsigned idx;
16809 /* The bits in this table go:
16810 0: register stride of one (0) or two (1)
16811 1,2: register list length, minus one (1, 2, 3, 4).
16812 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16813 We use -1 for invalid entries. */
16814 const int typetable[] =
16815 {
16816 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16817 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16818 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16819 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16820 };
16821 int typebits;
16822
dcbf9037
JB
16823 if (et.type == NT_invtype)
16824 return;
16825
5287ad62
JB
16826 if (inst.operands[1].immisalign)
16827 switch (inst.operands[1].imm >> 8)
16828 {
16829 case 64: alignbits = 1; break;
16830 case 128:
477330fc 16831 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16832 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16833 goto bad_alignment;
16834 alignbits = 2;
16835 break;
5287ad62 16836 case 256:
477330fc
RM
16837 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16838 goto bad_alignment;
16839 alignbits = 3;
16840 break;
5287ad62
JB
16841 default:
16842 bad_alignment:
477330fc
RM
16843 first_error (_("bad alignment"));
16844 return;
5287ad62
JB
16845 }
16846
16847 inst.instruction |= alignbits << 4;
16848 inst.instruction |= neon_logbits (et.size) << 6;
16849
16850 /* Bits [4:6] of the immediate in a list specifier encode register stride
16851 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16852 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16853 up the right value for "type" in a table based on this value and the given
16854 list style, then stick it back. */
16855 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16856 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16857
16858 typebits = typetable[idx];
5f4273c7 16859
5287ad62 16860 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16861 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16862 _("bad element type for instruction"));
5287ad62
JB
16863
16864 inst.instruction &= ~0xf00;
16865 inst.instruction |= typebits << 8;
16866}
16867
16868/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16869 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16870 otherwise. The variable arguments are a list of pairs of legal (size, align)
16871 values, terminated with -1. */
16872
16873static int
aa8a0863 16874neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16875{
16876 va_list ap;
16877 int result = FAIL, thissize, thisalign;
5f4273c7 16878
5287ad62
JB
16879 if (!inst.operands[1].immisalign)
16880 {
aa8a0863 16881 *do_alignment = 0;
5287ad62
JB
16882 return SUCCESS;
16883 }
5f4273c7 16884
aa8a0863 16885 va_start (ap, do_alignment);
5287ad62
JB
16886
16887 do
16888 {
16889 thissize = va_arg (ap, int);
16890 if (thissize == -1)
477330fc 16891 break;
5287ad62
JB
16892 thisalign = va_arg (ap, int);
16893
16894 if (size == thissize && align == thisalign)
477330fc 16895 result = SUCCESS;
5287ad62
JB
16896 }
16897 while (result != SUCCESS);
16898
16899 va_end (ap);
16900
16901 if (result == SUCCESS)
aa8a0863 16902 *do_alignment = 1;
5287ad62 16903 else
dcbf9037 16904 first_error (_("unsupported alignment for instruction"));
5f4273c7 16905
5287ad62
JB
16906 return result;
16907}
16908
16909static void
16910do_neon_ld_st_lane (void)
16911{
037e8744 16912 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16913 int align_good, do_alignment = 0;
5287ad62
JB
16914 int logsize = neon_logbits (et.size);
16915 int align = inst.operands[1].imm >> 8;
16916 int n = (inst.instruction >> 8) & 3;
16917 int max_el = 64 / et.size;
5f4273c7 16918
dcbf9037
JB
16919 if (et.type == NT_invtype)
16920 return;
5f4273c7 16921
5287ad62 16922 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16923 _("bad list length"));
5287ad62 16924 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16925 _("scalar index out of range"));
5287ad62 16926 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16927 && et.size == 8,
16928 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16929
5287ad62
JB
16930 switch (n)
16931 {
16932 case 0: /* VLD1 / VST1. */
aa8a0863 16933 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16934 32, 32, -1);
5287ad62 16935 if (align_good == FAIL)
477330fc 16936 return;
aa8a0863 16937 if (do_alignment)
477330fc
RM
16938 {
16939 unsigned alignbits = 0;
16940 switch (et.size)
16941 {
16942 case 16: alignbits = 0x1; break;
16943 case 32: alignbits = 0x3; break;
16944 default: ;
16945 }
16946 inst.instruction |= alignbits << 4;
16947 }
5287ad62
JB
16948 break;
16949
16950 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16951 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16952 16, 32, 32, 64, -1);
5287ad62 16953 if (align_good == FAIL)
477330fc 16954 return;
aa8a0863 16955 if (do_alignment)
477330fc 16956 inst.instruction |= 1 << 4;
5287ad62
JB
16957 break;
16958
16959 case 2: /* VLD3 / VST3. */
16960 constraint (inst.operands[1].immisalign,
477330fc 16961 _("can't use alignment with this instruction"));
5287ad62
JB
16962 break;
16963
16964 case 3: /* VLD4 / VST4. */
aa8a0863 16965 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16966 16, 64, 32, 64, 32, 128, -1);
5287ad62 16967 if (align_good == FAIL)
477330fc 16968 return;
aa8a0863 16969 if (do_alignment)
477330fc
RM
16970 {
16971 unsigned alignbits = 0;
16972 switch (et.size)
16973 {
16974 case 8: alignbits = 0x1; break;
16975 case 16: alignbits = 0x1; break;
16976 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16977 default: ;
16978 }
16979 inst.instruction |= alignbits << 4;
16980 }
5287ad62
JB
16981 break;
16982
16983 default: ;
16984 }
16985
16986 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16987 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16988 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16989
5287ad62
JB
16990 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16991 inst.instruction |= logsize << 10;
16992}
16993
16994/* Encode single n-element structure to all lanes VLD<n> instructions. */
16995
16996static void
16997do_neon_ld_dup (void)
16998{
037e8744 16999 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17000 int align_good, do_alignment = 0;
5287ad62 17001
dcbf9037
JB
17002 if (et.type == NT_invtype)
17003 return;
17004
5287ad62
JB
17005 switch ((inst.instruction >> 8) & 3)
17006 {
17007 case 0: /* VLD1. */
9c2799c2 17008 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17009 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17010 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17011 if (align_good == FAIL)
477330fc 17012 return;
5287ad62 17013 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17014 {
17015 case 1: break;
17016 case 2: inst.instruction |= 1 << 5; break;
17017 default: first_error (_("bad list length")); return;
17018 }
5287ad62
JB
17019 inst.instruction |= neon_logbits (et.size) << 6;
17020 break;
17021
17022 case 1: /* VLD2. */
17023 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17024 &do_alignment, 8, 16, 16, 32, 32, 64,
17025 -1);
5287ad62 17026 if (align_good == FAIL)
477330fc 17027 return;
5287ad62 17028 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17029 _("bad list length"));
5287ad62 17030 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17031 inst.instruction |= 1 << 5;
5287ad62
JB
17032 inst.instruction |= neon_logbits (et.size) << 6;
17033 break;
17034
17035 case 2: /* VLD3. */
17036 constraint (inst.operands[1].immisalign,
477330fc 17037 _("can't use alignment with this instruction"));
5287ad62 17038 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17039 _("bad list length"));
5287ad62 17040 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17041 inst.instruction |= 1 << 5;
5287ad62
JB
17042 inst.instruction |= neon_logbits (et.size) << 6;
17043 break;
17044
17045 case 3: /* VLD4. */
17046 {
477330fc 17047 int align = inst.operands[1].imm >> 8;
aa8a0863 17048 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17049 16, 64, 32, 64, 32, 128, -1);
17050 if (align_good == FAIL)
17051 return;
17052 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17053 _("bad list length"));
17054 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17055 inst.instruction |= 1 << 5;
17056 if (et.size == 32 && align == 128)
17057 inst.instruction |= 0x3 << 6;
17058 else
17059 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17060 }
17061 break;
17062
17063 default: ;
17064 }
17065
aa8a0863 17066 inst.instruction |= do_alignment << 4;
5287ad62
JB
17067}
17068
17069/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17070 apart from bits [11:4]. */
17071
17072static void
17073do_neon_ldx_stx (void)
17074{
b1a769ed
DG
17075 if (inst.operands[1].isreg)
17076 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17077
5287ad62
JB
17078 switch (NEON_LANE (inst.operands[0].imm))
17079 {
17080 case NEON_INTERLEAVE_LANES:
88714cb8 17081 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17082 do_neon_ld_st_interleave ();
17083 break;
5f4273c7 17084
5287ad62 17085 case NEON_ALL_LANES:
88714cb8 17086 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17087 if (inst.instruction == N_INV)
17088 {
17089 first_error ("only loads support such operands");
17090 break;
17091 }
5287ad62
JB
17092 do_neon_ld_dup ();
17093 break;
5f4273c7 17094
5287ad62 17095 default:
88714cb8 17096 NEON_ENCODE (LANE, inst);
5287ad62
JB
17097 do_neon_ld_st_lane ();
17098 }
17099
17100 /* L bit comes from bit mask. */
17101 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17102 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17103 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17104
5287ad62
JB
17105 if (inst.operands[1].postind)
17106 {
17107 int postreg = inst.operands[1].imm & 0xf;
17108 constraint (!inst.operands[1].immisreg,
477330fc 17109 _("post-index must be a register"));
5287ad62 17110 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17111 _("bad register for post-index"));
5287ad62
JB
17112 inst.instruction |= postreg;
17113 }
4f2374c7 17114 else
5287ad62 17115 {
4f2374c7
WN
17116 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17117 constraint (inst.reloc.exp.X_op != O_constant
17118 || inst.reloc.exp.X_add_number != 0,
17119 BAD_ADDR_MODE);
17120
17121 if (inst.operands[1].writeback)
17122 {
17123 inst.instruction |= 0xd;
17124 }
17125 else
17126 inst.instruction |= 0xf;
5287ad62 17127 }
5f4273c7 17128
5287ad62
JB
17129 if (thumb_mode)
17130 inst.instruction |= 0xf9000000;
17131 else
17132 inst.instruction |= 0xf4000000;
17133}
33399f07
MGD
17134
17135/* FP v8. */
17136static void
17137do_vfp_nsyn_fpv8 (enum neon_shape rs)
17138{
a715796b
TG
17139 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17140 D register operands. */
17141 if (neon_shape_class[rs] == SC_DOUBLE)
17142 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17143 _(BAD_FPU));
17144
33399f07
MGD
17145 NEON_ENCODE (FPV8, inst);
17146
9db2f6b4
RL
17147 if (rs == NS_FFF || rs == NS_HHH)
17148 {
17149 do_vfp_sp_dyadic ();
17150
17151 /* ARMv8.2 fp16 instruction. */
17152 if (rs == NS_HHH)
17153 do_scalar_fp16_v82_encode ();
17154 }
33399f07
MGD
17155 else
17156 do_vfp_dp_rd_rn_rm ();
17157
17158 if (rs == NS_DDD)
17159 inst.instruction |= 0x100;
17160
17161 inst.instruction |= 0xf0000000;
17162}
17163
17164static void
17165do_vsel (void)
17166{
17167 set_it_insn_type (OUTSIDE_IT_INSN);
17168
17169 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17170 first_error (_("invalid instruction shape"));
17171}
17172
73924fbc
MGD
17173static void
17174do_vmaxnm (void)
17175{
17176 set_it_insn_type (OUTSIDE_IT_INSN);
17177
17178 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17179 return;
17180
17181 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17182 return;
17183
cc933301 17184 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17185}
17186
30bdf752
MGD
17187static void
17188do_vrint_1 (enum neon_cvt_mode mode)
17189{
9db2f6b4 17190 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17191 struct neon_type_el et;
17192
17193 if (rs == NS_NULL)
17194 return;
17195
a715796b
TG
17196 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17197 D register operands. */
17198 if (neon_shape_class[rs] == SC_DOUBLE)
17199 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17200 _(BAD_FPU));
17201
9db2f6b4
RL
17202 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17203 | N_VFP);
30bdf752
MGD
17204 if (et.type != NT_invtype)
17205 {
17206 /* VFP encodings. */
17207 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17208 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17209 set_it_insn_type (OUTSIDE_IT_INSN);
17210
17211 NEON_ENCODE (FPV8, inst);
9db2f6b4 17212 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17213 do_vfp_sp_monadic ();
17214 else
17215 do_vfp_dp_rd_rm ();
17216
17217 switch (mode)
17218 {
17219 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17220 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17221 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17222 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17223 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17224 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17225 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17226 default: abort ();
17227 }
17228
17229 inst.instruction |= (rs == NS_DD) << 8;
17230 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17231
17232 /* ARMv8.2 fp16 vrint instruction. */
17233 if (rs == NS_HH)
17234 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17235 }
17236 else
17237 {
17238 /* Neon encodings (or something broken...). */
17239 inst.error = NULL;
cc933301 17240 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17241
17242 if (et.type == NT_invtype)
17243 return;
17244
17245 set_it_insn_type (OUTSIDE_IT_INSN);
17246 NEON_ENCODE (FLOAT, inst);
17247
17248 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17249 return;
17250
17251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17253 inst.instruction |= LOW4 (inst.operands[1].reg);
17254 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17255 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17256 /* Mask off the original size bits and reencode them. */
17257 inst.instruction = ((inst.instruction & 0xfff3ffff)
17258 | neon_logbits (et.size) << 18);
17259
30bdf752
MGD
17260 switch (mode)
17261 {
17262 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17263 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17264 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17265 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17266 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17267 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17268 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17269 default: abort ();
17270 }
17271
17272 if (thumb_mode)
17273 inst.instruction |= 0xfc000000;
17274 else
17275 inst.instruction |= 0xf0000000;
17276 }
17277}
17278
17279static void
17280do_vrintx (void)
17281{
17282 do_vrint_1 (neon_cvt_mode_x);
17283}
17284
17285static void
17286do_vrintz (void)
17287{
17288 do_vrint_1 (neon_cvt_mode_z);
17289}
17290
17291static void
17292do_vrintr (void)
17293{
17294 do_vrint_1 (neon_cvt_mode_r);
17295}
17296
17297static void
17298do_vrinta (void)
17299{
17300 do_vrint_1 (neon_cvt_mode_a);
17301}
17302
17303static void
17304do_vrintn (void)
17305{
17306 do_vrint_1 (neon_cvt_mode_n);
17307}
17308
17309static void
17310do_vrintp (void)
17311{
17312 do_vrint_1 (neon_cvt_mode_p);
17313}
17314
17315static void
17316do_vrintm (void)
17317{
17318 do_vrint_1 (neon_cvt_mode_m);
17319}
17320
c28eeff2
SN
17321static unsigned
17322neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17323{
17324 unsigned regno = NEON_SCALAR_REG (opnd);
17325 unsigned elno = NEON_SCALAR_INDEX (opnd);
17326
17327 if (elsize == 16 && elno < 2 && regno < 16)
17328 return regno | (elno << 4);
17329 else if (elsize == 32 && elno == 0)
17330 return regno;
17331
17332 first_error (_("scalar out of range"));
17333 return 0;
17334}
17335
17336static void
17337do_vcmla (void)
17338{
17339 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17340 _(BAD_FPU));
17341 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17342 unsigned rot = inst.reloc.exp.X_add_number;
17343 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17344 _("immediate out of range"));
17345 rot /= 90;
17346 if (inst.operands[2].isscalar)
17347 {
17348 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17349 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17350 N_KEY | N_F16 | N_F32).size;
17351 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17352 inst.is_neon = 1;
17353 inst.instruction = 0xfe000800;
17354 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17355 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17356 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17357 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17358 inst.instruction |= LOW4 (m);
17359 inst.instruction |= HI1 (m) << 5;
17360 inst.instruction |= neon_quad (rs) << 6;
17361 inst.instruction |= rot << 20;
17362 inst.instruction |= (size == 32) << 23;
17363 }
17364 else
17365 {
17366 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17367 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17368 N_KEY | N_F16 | N_F32).size;
17369 neon_three_same (neon_quad (rs), 0, -1);
17370 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17371 inst.instruction |= 0xfc200800;
17372 inst.instruction |= rot << 23;
17373 inst.instruction |= (size == 32) << 20;
17374 }
17375}
17376
17377static void
17378do_vcadd (void)
17379{
17380 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17381 _(BAD_FPU));
17382 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17383 unsigned rot = inst.reloc.exp.X_add_number;
17384 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17385 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17386 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17387 N_KEY | N_F16 | N_F32).size;
17388 neon_three_same (neon_quad (rs), 0, -1);
17389 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17390 inst.instruction |= 0xfc800800;
17391 inst.instruction |= (rot == 270) << 24;
17392 inst.instruction |= (size == 32) << 20;
17393}
17394
c604a79a
JW
17395/* Dot Product instructions encoding support. */
17396
17397static void
17398do_neon_dotproduct (int unsigned_p)
17399{
17400 enum neon_shape rs;
17401 unsigned scalar_oprd2 = 0;
17402 int high8;
17403
17404 if (inst.cond != COND_ALWAYS)
17405 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17406 "is UNPREDICTABLE"));
17407
17408 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17409 _(BAD_FPU));
17410
17411 /* Dot Product instructions are in three-same D/Q register format or the third
17412 operand can be a scalar index register. */
17413 if (inst.operands[2].isscalar)
17414 {
17415 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17416 high8 = 0xfe000000;
17417 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17418 }
17419 else
17420 {
17421 high8 = 0xfc000000;
17422 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17423 }
17424
17425 if (unsigned_p)
17426 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17427 else
17428 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17429
17430 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17431 Product instruction, so we pass 0 as the "ubit" parameter. And the
17432 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17433 neon_three_same (neon_quad (rs), 0, 32);
17434
17435 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17436 different NEON three-same encoding. */
17437 inst.instruction &= 0x00ffffff;
17438 inst.instruction |= high8;
17439 /* Encode 'U' bit which indicates signedness. */
17440 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17441 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17442 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17443 the instruction encoding. */
17444 if (inst.operands[2].isscalar)
17445 {
17446 inst.instruction &= 0xffffffd0;
17447 inst.instruction |= LOW4 (scalar_oprd2);
17448 inst.instruction |= HI1 (scalar_oprd2) << 5;
17449 }
17450}
17451
17452/* Dot Product instructions for signed integer. */
17453
17454static void
17455do_neon_dotproduct_s (void)
17456{
17457 return do_neon_dotproduct (0);
17458}
17459
17460/* Dot Product instructions for unsigned integer. */
17461
17462static void
17463do_neon_dotproduct_u (void)
17464{
17465 return do_neon_dotproduct (1);
17466}
17467
91ff7894
MGD
17468/* Crypto v1 instructions. */
17469static void
17470do_crypto_2op_1 (unsigned elttype, int op)
17471{
17472 set_it_insn_type (OUTSIDE_IT_INSN);
17473
17474 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17475 == NT_invtype)
17476 return;
17477
17478 inst.error = NULL;
17479
17480 NEON_ENCODE (INTEGER, inst);
17481 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17482 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17483 inst.instruction |= LOW4 (inst.operands[1].reg);
17484 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17485 if (op != -1)
17486 inst.instruction |= op << 6;
17487
17488 if (thumb_mode)
17489 inst.instruction |= 0xfc000000;
17490 else
17491 inst.instruction |= 0xf0000000;
17492}
17493
48adcd8e
MGD
17494static void
17495do_crypto_3op_1 (int u, int op)
17496{
17497 set_it_insn_type (OUTSIDE_IT_INSN);
17498
17499 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17500 N_32 | N_UNT | N_KEY).type == NT_invtype)
17501 return;
17502
17503 inst.error = NULL;
17504
17505 NEON_ENCODE (INTEGER, inst);
17506 neon_three_same (1, u, 8 << op);
17507}
17508
91ff7894
MGD
17509static void
17510do_aese (void)
17511{
17512 do_crypto_2op_1 (N_8, 0);
17513}
17514
17515static void
17516do_aesd (void)
17517{
17518 do_crypto_2op_1 (N_8, 1);
17519}
17520
17521static void
17522do_aesmc (void)
17523{
17524 do_crypto_2op_1 (N_8, 2);
17525}
17526
17527static void
17528do_aesimc (void)
17529{
17530 do_crypto_2op_1 (N_8, 3);
17531}
17532
48adcd8e
MGD
17533static void
17534do_sha1c (void)
17535{
17536 do_crypto_3op_1 (0, 0);
17537}
17538
17539static void
17540do_sha1p (void)
17541{
17542 do_crypto_3op_1 (0, 1);
17543}
17544
17545static void
17546do_sha1m (void)
17547{
17548 do_crypto_3op_1 (0, 2);
17549}
17550
17551static void
17552do_sha1su0 (void)
17553{
17554 do_crypto_3op_1 (0, 3);
17555}
91ff7894 17556
48adcd8e
MGD
17557static void
17558do_sha256h (void)
17559{
17560 do_crypto_3op_1 (1, 0);
17561}
17562
17563static void
17564do_sha256h2 (void)
17565{
17566 do_crypto_3op_1 (1, 1);
17567}
17568
17569static void
17570do_sha256su1 (void)
17571{
17572 do_crypto_3op_1 (1, 2);
17573}
3c9017d2
MGD
17574
17575static void
17576do_sha1h (void)
17577{
17578 do_crypto_2op_1 (N_32, -1);
17579}
17580
17581static void
17582do_sha1su1 (void)
17583{
17584 do_crypto_2op_1 (N_32, 0);
17585}
17586
17587static void
17588do_sha256su0 (void)
17589{
17590 do_crypto_2op_1 (N_32, 1);
17591}
dd5181d5
KT
17592
17593static void
17594do_crc32_1 (unsigned int poly, unsigned int sz)
17595{
17596 unsigned int Rd = inst.operands[0].reg;
17597 unsigned int Rn = inst.operands[1].reg;
17598 unsigned int Rm = inst.operands[2].reg;
17599
17600 set_it_insn_type (OUTSIDE_IT_INSN);
17601 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17602 inst.instruction |= LOW4 (Rn) << 16;
17603 inst.instruction |= LOW4 (Rm);
17604 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17605 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17606
17607 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17608 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17609}
17610
17611static void
17612do_crc32b (void)
17613{
17614 do_crc32_1 (0, 0);
17615}
17616
17617static void
17618do_crc32h (void)
17619{
17620 do_crc32_1 (0, 1);
17621}
17622
17623static void
17624do_crc32w (void)
17625{
17626 do_crc32_1 (0, 2);
17627}
17628
17629static void
17630do_crc32cb (void)
17631{
17632 do_crc32_1 (1, 0);
17633}
17634
17635static void
17636do_crc32ch (void)
17637{
17638 do_crc32_1 (1, 1);
17639}
17640
17641static void
17642do_crc32cw (void)
17643{
17644 do_crc32_1 (1, 2);
17645}
17646
49e8a725
SN
17647static void
17648do_vjcvt (void)
17649{
17650 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17651 _(BAD_FPU));
17652 neon_check_type (2, NS_FD, N_S32, N_F64);
17653 do_vfp_sp_dp_cvt ();
17654 do_vfp_cond_or_thumb ();
17655}
17656
5287ad62
JB
17657\f
17658/* Overall per-instruction processing. */
17659
17660/* We need to be able to fix up arbitrary expressions in some statements.
17661 This is so that we can handle symbols that are an arbitrary distance from
17662 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17663 which returns part of an address in a form which will be valid for
17664 a data instruction. We do this by pushing the expression into a symbol
17665 in the expr_section, and creating a fix for that. */
17666
17667static void
17668fix_new_arm (fragS * frag,
17669 int where,
17670 short int size,
17671 expressionS * exp,
17672 int pc_rel,
17673 int reloc)
17674{
17675 fixS * new_fix;
17676
17677 switch (exp->X_op)
17678 {
17679 case O_constant:
6e7ce2cd
PB
17680 if (pc_rel)
17681 {
17682 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17683 refer to in the object file. Unfortunately for us, gas's
17684 generic expression parsing will already have folded out
17685 any use of .set foo/.type foo %function that may have
17686 been used to set type information of the target location,
17687 that's being specified symbolically. We have to presume
17688 the user knows what they are doing. */
6e7ce2cd
PB
17689 char name[16 + 8];
17690 symbolS *symbol;
17691
17692 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17693
17694 symbol = symbol_find_or_make (name);
17695 S_SET_SEGMENT (symbol, absolute_section);
17696 symbol_set_frag (symbol, &zero_address_frag);
17697 S_SET_VALUE (symbol, exp->X_add_number);
17698 exp->X_op = O_symbol;
17699 exp->X_add_symbol = symbol;
17700 exp->X_add_number = 0;
17701 }
17702 /* FALLTHROUGH */
5287ad62
JB
17703 case O_symbol:
17704 case O_add:
17705 case O_subtract:
21d799b5 17706 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17707 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17708 break;
17709
17710 default:
21d799b5 17711 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17712 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17713 break;
17714 }
17715
17716 /* Mark whether the fix is to a THUMB instruction, or an ARM
17717 instruction. */
17718 new_fix->tc_fix_data = thumb_mode;
17719}
17720
17721/* Create a frg for an instruction requiring relaxation. */
17722static void
17723output_relax_insn (void)
17724{
17725 char * to;
17726 symbolS *sym;
0110f2b8
PB
17727 int offset;
17728
6e1cb1a6
PB
17729 /* The size of the instruction is unknown, so tie the debug info to the
17730 start of the instruction. */
17731 dwarf2_emit_insn (0);
6e1cb1a6 17732
0110f2b8
PB
17733 switch (inst.reloc.exp.X_op)
17734 {
17735 case O_symbol:
17736 sym = inst.reloc.exp.X_add_symbol;
17737 offset = inst.reloc.exp.X_add_number;
17738 break;
17739 case O_constant:
17740 sym = NULL;
17741 offset = inst.reloc.exp.X_add_number;
17742 break;
17743 default:
17744 sym = make_expr_symbol (&inst.reloc.exp);
17745 offset = 0;
17746 break;
17747 }
17748 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17749 inst.relax, sym, offset, NULL/*offset, opcode*/);
17750 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17751}
17752
17753/* Write a 32-bit thumb instruction to buf. */
17754static void
17755put_thumb32_insn (char * buf, unsigned long insn)
17756{
17757 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17758 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17759}
17760
b99bd4ef 17761static void
c19d1205 17762output_inst (const char * str)
b99bd4ef 17763{
c19d1205 17764 char * to = NULL;
b99bd4ef 17765
c19d1205 17766 if (inst.error)
b99bd4ef 17767 {
c19d1205 17768 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17769 return;
17770 }
5f4273c7
NC
17771 if (inst.relax)
17772 {
17773 output_relax_insn ();
0110f2b8 17774 return;
5f4273c7 17775 }
c19d1205
ZW
17776 if (inst.size == 0)
17777 return;
b99bd4ef 17778
c19d1205 17779 to = frag_more (inst.size);
8dc2430f
NC
17780 /* PR 9814: Record the thumb mode into the current frag so that we know
17781 what type of NOP padding to use, if necessary. We override any previous
17782 setting so that if the mode has changed then the NOPS that we use will
17783 match the encoding of the last instruction in the frag. */
cd000bff 17784 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17785
17786 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17787 {
9c2799c2 17788 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17789 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17790 }
c19d1205 17791 else if (inst.size > INSN_SIZE)
b99bd4ef 17792 {
9c2799c2 17793 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17794 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17795 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17796 }
c19d1205
ZW
17797 else
17798 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17799
c19d1205
ZW
17800 if (inst.reloc.type != BFD_RELOC_UNUSED)
17801 fix_new_arm (frag_now, to - frag_now->fr_literal,
17802 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17803 inst.reloc.type);
b99bd4ef 17804
c19d1205 17805 dwarf2_emit_insn (inst.size);
c19d1205 17806}
b99bd4ef 17807
e07e6e58
NC
17808static char *
17809output_it_inst (int cond, int mask, char * to)
17810{
17811 unsigned long instruction = 0xbf00;
17812
17813 mask &= 0xf;
17814 instruction |= mask;
17815 instruction |= cond << 4;
17816
17817 if (to == NULL)
17818 {
17819 to = frag_more (2);
17820#ifdef OBJ_ELF
17821 dwarf2_emit_insn (2);
17822#endif
17823 }
17824
17825 md_number_to_chars (to, instruction, 2);
17826
17827 return to;
17828}
17829
c19d1205
ZW
17830/* Tag values used in struct asm_opcode's tag field. */
17831enum opcode_tag
17832{
17833 OT_unconditional, /* Instruction cannot be conditionalized.
17834 The ARM condition field is still 0xE. */
17835 OT_unconditionalF, /* Instruction cannot be conditionalized
17836 and carries 0xF in its ARM condition field. */
17837 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17838 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17839 suffix, others place 0xF where the condition field
17840 would be. */
c19d1205
ZW
17841 OT_cinfix3, /* Instruction takes a conditional infix,
17842 beginning at character index 3. (In
17843 unified mode, it becomes a suffix.) */
088fa78e
KH
17844 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17845 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17846 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17847 character index 3, even in unified mode. Used for
17848 legacy instructions where suffix and infix forms
17849 may be ambiguous. */
c19d1205 17850 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17851 suffix or an infix at character index 3. */
c19d1205
ZW
17852 OT_odd_infix_unc, /* This is the unconditional variant of an
17853 instruction that takes a conditional infix
17854 at an unusual position. In unified mode,
17855 this variant will accept a suffix. */
17856 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17857 are the conditional variants of instructions that
17858 take conditional infixes in unusual positions.
17859 The infix appears at character index
17860 (tag - OT_odd_infix_0). These are not accepted
17861 in unified mode. */
17862};
b99bd4ef 17863
c19d1205
ZW
17864/* Subroutine of md_assemble, responsible for looking up the primary
17865 opcode from the mnemonic the user wrote. STR points to the
17866 beginning of the mnemonic.
17867
17868 This is not simply a hash table lookup, because of conditional
17869 variants. Most instructions have conditional variants, which are
17870 expressed with a _conditional affix_ to the mnemonic. If we were
17871 to encode each conditional variant as a literal string in the opcode
17872 table, it would have approximately 20,000 entries.
17873
17874 Most mnemonics take this affix as a suffix, and in unified syntax,
17875 'most' is upgraded to 'all'. However, in the divided syntax, some
17876 instructions take the affix as an infix, notably the s-variants of
17877 the arithmetic instructions. Of those instructions, all but six
17878 have the infix appear after the third character of the mnemonic.
17879
17880 Accordingly, the algorithm for looking up primary opcodes given
17881 an identifier is:
17882
17883 1. Look up the identifier in the opcode table.
17884 If we find a match, go to step U.
17885
17886 2. Look up the last two characters of the identifier in the
17887 conditions table. If we find a match, look up the first N-2
17888 characters of the identifier in the opcode table. If we
17889 find a match, go to step CE.
17890
17891 3. Look up the fourth and fifth characters of the identifier in
17892 the conditions table. If we find a match, extract those
17893 characters from the identifier, and look up the remaining
17894 characters in the opcode table. If we find a match, go
17895 to step CM.
17896
17897 4. Fail.
17898
17899 U. Examine the tag field of the opcode structure, in case this is
17900 one of the six instructions with its conditional infix in an
17901 unusual place. If it is, the tag tells us where to find the
17902 infix; look it up in the conditions table and set inst.cond
17903 accordingly. Otherwise, this is an unconditional instruction.
17904 Again set inst.cond accordingly. Return the opcode structure.
17905
17906 CE. Examine the tag field to make sure this is an instruction that
17907 should receive a conditional suffix. If it is not, fail.
17908 Otherwise, set inst.cond from the suffix we already looked up,
17909 and return the opcode structure.
17910
17911 CM. Examine the tag field to make sure this is an instruction that
17912 should receive a conditional infix after the third character.
17913 If it is not, fail. Otherwise, undo the edits to the current
17914 line of input and proceed as for case CE. */
17915
17916static const struct asm_opcode *
17917opcode_lookup (char **str)
17918{
17919 char *end, *base;
17920 char *affix;
17921 const struct asm_opcode *opcode;
17922 const struct asm_cond *cond;
e3cb604e 17923 char save[2];
c19d1205
ZW
17924
17925 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17926 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17927 for (base = end = *str; *end != '\0'; end++)
721a8186 17928 if (*end == ' ' || *end == '.')
c19d1205 17929 break;
b99bd4ef 17930
c19d1205 17931 if (end == base)
c921be7d 17932 return NULL;
b99bd4ef 17933
5287ad62 17934 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17935 if (end[0] == '.')
b99bd4ef 17936 {
5287ad62 17937 int offset = 2;
5f4273c7 17938
267d2029 17939 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17940 use. */
267d2029 17941 if (unified_syntax && end[1] == 'w')
c19d1205 17942 inst.size_req = 4;
267d2029 17943 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17944 inst.size_req = 2;
17945 else
477330fc 17946 offset = 0;
5287ad62
JB
17947
17948 inst.vectype.elems = 0;
17949
17950 *str = end + offset;
b99bd4ef 17951
5f4273c7 17952 if (end[offset] == '.')
5287ad62 17953 {
267d2029 17954 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17955 non-unified ARM syntax mode). */
17956 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17957 return NULL;
477330fc 17958 }
5287ad62 17959 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17960 return NULL;
b99bd4ef 17961 }
c19d1205
ZW
17962 else
17963 *str = end;
b99bd4ef 17964
c19d1205 17965 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17966 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17967 end - base);
c19d1205 17968 if (opcode)
b99bd4ef 17969 {
c19d1205
ZW
17970 /* step U */
17971 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17972 {
c19d1205
ZW
17973 inst.cond = COND_ALWAYS;
17974 return opcode;
b99bd4ef 17975 }
b99bd4ef 17976
278df34e 17977 if (warn_on_deprecated && unified_syntax)
5c3696f8 17978 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17979 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17980 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17981 gas_assert (cond);
b99bd4ef 17982
c19d1205
ZW
17983 inst.cond = cond->value;
17984 return opcode;
17985 }
b99bd4ef 17986
c19d1205
ZW
17987 /* Cannot have a conditional suffix on a mnemonic of less than two
17988 characters. */
17989 if (end - base < 3)
c921be7d 17990 return NULL;
b99bd4ef 17991
c19d1205
ZW
17992 /* Look for suffixed mnemonic. */
17993 affix = end - 2;
21d799b5
NC
17994 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17995 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17996 affix - base);
c19d1205
ZW
17997 if (opcode && cond)
17998 {
17999 /* step CE */
18000 switch (opcode->tag)
18001 {
e3cb604e
PB
18002 case OT_cinfix3_legacy:
18003 /* Ignore conditional suffixes matched on infix only mnemonics. */
18004 break;
18005
c19d1205 18006 case OT_cinfix3:
088fa78e 18007 case OT_cinfix3_deprecated:
c19d1205
ZW
18008 case OT_odd_infix_unc:
18009 if (!unified_syntax)
0198d5e6 18010 return NULL;
1a0670f3 18011 /* Fall through. */
c19d1205
ZW
18012
18013 case OT_csuffix:
477330fc 18014 case OT_csuffixF:
c19d1205
ZW
18015 case OT_csuf_or_in3:
18016 inst.cond = cond->value;
18017 return opcode;
18018
18019 case OT_unconditional:
18020 case OT_unconditionalF:
dfa9f0d5 18021 if (thumb_mode)
c921be7d 18022 inst.cond = cond->value;
dfa9f0d5
PB
18023 else
18024 {
c921be7d 18025 /* Delayed diagnostic. */
dfa9f0d5
PB
18026 inst.error = BAD_COND;
18027 inst.cond = COND_ALWAYS;
18028 }
c19d1205 18029 return opcode;
b99bd4ef 18030
c19d1205 18031 default:
c921be7d 18032 return NULL;
c19d1205
ZW
18033 }
18034 }
b99bd4ef 18035
c19d1205
ZW
18036 /* Cannot have a usual-position infix on a mnemonic of less than
18037 six characters (five would be a suffix). */
18038 if (end - base < 6)
c921be7d 18039 return NULL;
b99bd4ef 18040
c19d1205
ZW
18041 /* Look for infixed mnemonic in the usual position. */
18042 affix = base + 3;
21d799b5 18043 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18044 if (!cond)
c921be7d 18045 return NULL;
e3cb604e
PB
18046
18047 memcpy (save, affix, 2);
18048 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18049 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18050 (end - base) - 2);
e3cb604e
PB
18051 memmove (affix + 2, affix, (end - affix) - 2);
18052 memcpy (affix, save, 2);
18053
088fa78e
KH
18054 if (opcode
18055 && (opcode->tag == OT_cinfix3
18056 || opcode->tag == OT_cinfix3_deprecated
18057 || opcode->tag == OT_csuf_or_in3
18058 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18059 {
c921be7d 18060 /* Step CM. */
278df34e 18061 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18062 && (opcode->tag == OT_cinfix3
18063 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18064 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18065
18066 inst.cond = cond->value;
18067 return opcode;
b99bd4ef
NC
18068 }
18069
c921be7d 18070 return NULL;
b99bd4ef
NC
18071}
18072
e07e6e58
NC
18073/* This function generates an initial IT instruction, leaving its block
18074 virtually open for the new instructions. Eventually,
18075 the mask will be updated by now_it_add_mask () each time
18076 a new instruction needs to be included in the IT block.
18077 Finally, the block is closed with close_automatic_it_block ().
18078 The block closure can be requested either from md_assemble (),
18079 a tencode (), or due to a label hook. */
18080
18081static void
18082new_automatic_it_block (int cond)
18083{
18084 now_it.state = AUTOMATIC_IT_BLOCK;
18085 now_it.mask = 0x18;
18086 now_it.cc = cond;
18087 now_it.block_length = 1;
cd000bff 18088 mapping_state (MAP_THUMB);
e07e6e58 18089 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18090 now_it.warn_deprecated = FALSE;
18091 now_it.insn_cond = TRUE;
e07e6e58
NC
18092}
18093
18094/* Close an automatic IT block.
18095 See comments in new_automatic_it_block (). */
18096
18097static void
18098close_automatic_it_block (void)
18099{
18100 now_it.mask = 0x10;
18101 now_it.block_length = 0;
18102}
18103
18104/* Update the mask of the current automatically-generated IT
18105 instruction. See comments in new_automatic_it_block (). */
18106
18107static void
18108now_it_add_mask (int cond)
18109{
18110#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18111#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18112 | ((bitvalue) << (nbit)))
e07e6e58 18113 const int resulting_bit = (cond & 1);
c921be7d 18114
e07e6e58
NC
18115 now_it.mask &= 0xf;
18116 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18117 resulting_bit,
18118 (5 - now_it.block_length));
e07e6e58 18119 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18120 1,
18121 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18122 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18123
18124#undef CLEAR_BIT
18125#undef SET_BIT_VALUE
e07e6e58
NC
18126}
18127
18128/* The IT blocks handling machinery is accessed through the these functions:
18129 it_fsm_pre_encode () from md_assemble ()
18130 set_it_insn_type () optional, from the tencode functions
18131 set_it_insn_type_last () ditto
18132 in_it_block () ditto
18133 it_fsm_post_encode () from md_assemble ()
33eaf5de 18134 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18135
18136 Rationale:
18137 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18138 initializing the IT insn type with a generic initial value depending
18139 on the inst.condition.
e07e6e58 18140 2) During the tencode function, two things may happen:
477330fc
RM
18141 a) The tencode function overrides the IT insn type by
18142 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18143 b) The tencode function queries the IT block state by
18144 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18145
18146 Both set_it_insn_type and in_it_block run the internal FSM state
18147 handling function (handle_it_state), because: a) setting the IT insn
18148 type may incur in an invalid state (exiting the function),
18149 and b) querying the state requires the FSM to be updated.
18150 Specifically we want to avoid creating an IT block for conditional
18151 branches, so it_fsm_pre_encode is actually a guess and we can't
18152 determine whether an IT block is required until the tencode () routine
18153 has decided what type of instruction this actually it.
18154 Because of this, if set_it_insn_type and in_it_block have to be used,
18155 set_it_insn_type has to be called first.
18156
18157 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18158 determines the insn IT type depending on the inst.cond code.
18159 When a tencode () routine encodes an instruction that can be
18160 either outside an IT block, or, in the case of being inside, has to be
18161 the last one, set_it_insn_type_last () will determine the proper
18162 IT instruction type based on the inst.cond code. Otherwise,
18163 set_it_insn_type can be called for overriding that logic or
18164 for covering other cases.
18165
18166 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18167 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18168 still queried. Instead, if the FSM determines that the state should
18169 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18170 after the tencode () function: that's what it_fsm_post_encode () does.
18171
18172 Since in_it_block () calls the state handling function to get an
18173 updated state, an error may occur (due to invalid insns combination).
18174 In that case, inst.error is set.
18175 Therefore, inst.error has to be checked after the execution of
18176 the tencode () routine.
e07e6e58
NC
18177
18178 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18179 any pending state change (if any) that didn't take place in
18180 handle_it_state () as explained above. */
e07e6e58
NC
18181
18182static void
18183it_fsm_pre_encode (void)
18184{
18185 if (inst.cond != COND_ALWAYS)
18186 inst.it_insn_type = INSIDE_IT_INSN;
18187 else
18188 inst.it_insn_type = OUTSIDE_IT_INSN;
18189
18190 now_it.state_handled = 0;
18191}
18192
18193/* IT state FSM handling function. */
18194
18195static int
18196handle_it_state (void)
18197{
18198 now_it.state_handled = 1;
5a01bb1d 18199 now_it.insn_cond = FALSE;
e07e6e58
NC
18200
18201 switch (now_it.state)
18202 {
18203 case OUTSIDE_IT_BLOCK:
18204 switch (inst.it_insn_type)
18205 {
18206 case OUTSIDE_IT_INSN:
18207 break;
18208
18209 case INSIDE_IT_INSN:
18210 case INSIDE_IT_LAST_INSN:
18211 if (thumb_mode == 0)
18212 {
c921be7d 18213 if (unified_syntax
e07e6e58
NC
18214 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18215 as_tsktsk (_("Warning: conditional outside an IT block"\
18216 " for Thumb."));
18217 }
18218 else
18219 {
18220 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18221 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18222 {
18223 /* Automatically generate the IT instruction. */
18224 new_automatic_it_block (inst.cond);
18225 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18226 close_automatic_it_block ();
18227 }
18228 else
18229 {
18230 inst.error = BAD_OUT_IT;
18231 return FAIL;
18232 }
18233 }
18234 break;
18235
18236 case IF_INSIDE_IT_LAST_INSN:
18237 case NEUTRAL_IT_INSN:
18238 break;
18239
18240 case IT_INSN:
18241 now_it.state = MANUAL_IT_BLOCK;
18242 now_it.block_length = 0;
18243 break;
18244 }
18245 break;
18246
18247 case AUTOMATIC_IT_BLOCK:
18248 /* Three things may happen now:
18249 a) We should increment current it block size;
18250 b) We should close current it block (closing insn or 4 insns);
18251 c) We should close current it block and start a new one (due
18252 to incompatible conditions or
18253 4 insns-length block reached). */
18254
18255 switch (inst.it_insn_type)
18256 {
18257 case OUTSIDE_IT_INSN:
2b0f3761 18258 /* The closure of the block shall happen immediately,
e07e6e58
NC
18259 so any in_it_block () call reports the block as closed. */
18260 force_automatic_it_block_close ();
18261 break;
18262
18263 case INSIDE_IT_INSN:
18264 case INSIDE_IT_LAST_INSN:
18265 case IF_INSIDE_IT_LAST_INSN:
18266 now_it.block_length++;
18267
18268 if (now_it.block_length > 4
18269 || !now_it_compatible (inst.cond))
18270 {
18271 force_automatic_it_block_close ();
18272 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18273 new_automatic_it_block (inst.cond);
18274 }
18275 else
18276 {
5a01bb1d 18277 now_it.insn_cond = TRUE;
e07e6e58
NC
18278 now_it_add_mask (inst.cond);
18279 }
18280
18281 if (now_it.state == AUTOMATIC_IT_BLOCK
18282 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18283 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18284 close_automatic_it_block ();
18285 break;
18286
18287 case NEUTRAL_IT_INSN:
18288 now_it.block_length++;
5a01bb1d 18289 now_it.insn_cond = TRUE;
e07e6e58
NC
18290
18291 if (now_it.block_length > 4)
18292 force_automatic_it_block_close ();
18293 else
18294 now_it_add_mask (now_it.cc & 1);
18295 break;
18296
18297 case IT_INSN:
18298 close_automatic_it_block ();
18299 now_it.state = MANUAL_IT_BLOCK;
18300 break;
18301 }
18302 break;
18303
18304 case MANUAL_IT_BLOCK:
18305 {
18306 /* Check conditional suffixes. */
18307 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18308 int is_last;
18309 now_it.mask <<= 1;
18310 now_it.mask &= 0x1f;
18311 is_last = (now_it.mask == 0x10);
5a01bb1d 18312 now_it.insn_cond = TRUE;
e07e6e58
NC
18313
18314 switch (inst.it_insn_type)
18315 {
18316 case OUTSIDE_IT_INSN:
18317 inst.error = BAD_NOT_IT;
18318 return FAIL;
18319
18320 case INSIDE_IT_INSN:
18321 if (cond != inst.cond)
18322 {
18323 inst.error = BAD_IT_COND;
18324 return FAIL;
18325 }
18326 break;
18327
18328 case INSIDE_IT_LAST_INSN:
18329 case IF_INSIDE_IT_LAST_INSN:
18330 if (cond != inst.cond)
18331 {
18332 inst.error = BAD_IT_COND;
18333 return FAIL;
18334 }
18335 if (!is_last)
18336 {
18337 inst.error = BAD_BRANCH;
18338 return FAIL;
18339 }
18340 break;
18341
18342 case NEUTRAL_IT_INSN:
18343 /* The BKPT instruction is unconditional even in an IT block. */
18344 break;
18345
18346 case IT_INSN:
18347 inst.error = BAD_IT_IT;
18348 return FAIL;
18349 }
18350 }
18351 break;
18352 }
18353
18354 return SUCCESS;
18355}
18356
5a01bb1d
MGD
18357struct depr_insn_mask
18358{
18359 unsigned long pattern;
18360 unsigned long mask;
18361 const char* description;
18362};
18363
18364/* List of 16-bit instruction patterns deprecated in an IT block in
18365 ARMv8. */
18366static const struct depr_insn_mask depr_it_insns[] = {
18367 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18368 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18369 { 0xa000, 0xb800, N_("ADR") },
18370 { 0x4800, 0xf800, N_("Literal loads") },
18371 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18372 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18373 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18374 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18375 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18376 { 0, 0, NULL }
18377};
18378
e07e6e58
NC
18379static void
18380it_fsm_post_encode (void)
18381{
18382 int is_last;
18383
18384 if (!now_it.state_handled)
18385 handle_it_state ();
18386
5a01bb1d
MGD
18387 if (now_it.insn_cond
18388 && !now_it.warn_deprecated
18389 && warn_on_deprecated
18390 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18391 {
18392 if (inst.instruction >= 0x10000)
18393 {
5c3696f8 18394 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18395 "deprecated in ARMv8"));
18396 now_it.warn_deprecated = TRUE;
18397 }
18398 else
18399 {
18400 const struct depr_insn_mask *p = depr_it_insns;
18401
18402 while (p->mask != 0)
18403 {
18404 if ((inst.instruction & p->mask) == p->pattern)
18405 {
5c3696f8 18406 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18407 "of the following class are deprecated in ARMv8: "
18408 "%s"), p->description);
18409 now_it.warn_deprecated = TRUE;
18410 break;
18411 }
18412
18413 ++p;
18414 }
18415 }
18416
18417 if (now_it.block_length > 1)
18418 {
5c3696f8 18419 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18420 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18421 now_it.warn_deprecated = TRUE;
18422 }
18423 }
18424
e07e6e58
NC
18425 is_last = (now_it.mask == 0x10);
18426 if (is_last)
18427 {
18428 now_it.state = OUTSIDE_IT_BLOCK;
18429 now_it.mask = 0;
18430 }
18431}
18432
18433static void
18434force_automatic_it_block_close (void)
18435{
18436 if (now_it.state == AUTOMATIC_IT_BLOCK)
18437 {
18438 close_automatic_it_block ();
18439 now_it.state = OUTSIDE_IT_BLOCK;
18440 now_it.mask = 0;
18441 }
18442}
18443
18444static int
18445in_it_block (void)
18446{
18447 if (!now_it.state_handled)
18448 handle_it_state ();
18449
18450 return now_it.state != OUTSIDE_IT_BLOCK;
18451}
18452
ff8646ee
TP
18453/* Whether OPCODE only has T32 encoding. Since this function is only used by
18454 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18455 here, hence the "known" in the function name. */
fc289b0a
TP
18456
18457static bfd_boolean
ff8646ee 18458known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18459{
18460 /* Original Thumb-1 wide instruction. */
18461 if (opcode->tencode == do_t_blx
18462 || opcode->tencode == do_t_branch23
18463 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18464 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18465 return TRUE;
18466
16a1fa25
TP
18467 /* Wide-only instruction added to ARMv8-M Baseline. */
18468 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18469 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18470 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18471 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18472 return TRUE;
18473
18474 return FALSE;
18475}
18476
18477/* Whether wide instruction variant can be used if available for a valid OPCODE
18478 in ARCH. */
18479
18480static bfd_boolean
18481t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18482{
18483 if (known_t32_only_insn (opcode))
18484 return TRUE;
18485
18486 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18487 of variant T3 of B.W is checked in do_t_branch. */
18488 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18489 && opcode->tencode == do_t_branch)
18490 return TRUE;
18491
bada4342
JW
18492 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18493 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18494 && opcode->tencode == do_t_mov_cmp
18495 /* Make sure CMP instruction is not affected. */
18496 && opcode->aencode == do_mov)
18497 return TRUE;
18498
ff8646ee
TP
18499 /* Wide instruction variants of all instructions with narrow *and* wide
18500 variants become available with ARMv6t2. Other opcodes are either
18501 narrow-only or wide-only and are thus available if OPCODE is valid. */
18502 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18503 return TRUE;
18504
18505 /* OPCODE with narrow only instruction variant or wide variant not
18506 available. */
fc289b0a
TP
18507 return FALSE;
18508}
18509
c19d1205
ZW
18510void
18511md_assemble (char *str)
b99bd4ef 18512{
c19d1205
ZW
18513 char *p = str;
18514 const struct asm_opcode * opcode;
b99bd4ef 18515
c19d1205
ZW
18516 /* Align the previous label if needed. */
18517 if (last_label_seen != NULL)
b99bd4ef 18518 {
c19d1205
ZW
18519 symbol_set_frag (last_label_seen, frag_now);
18520 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18521 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18522 }
18523
c19d1205
ZW
18524 memset (&inst, '\0', sizeof (inst));
18525 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18526
c19d1205
ZW
18527 opcode = opcode_lookup (&p);
18528 if (!opcode)
b99bd4ef 18529 {
c19d1205 18530 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18531 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18532 if (! create_register_alias (str, p)
477330fc 18533 && ! create_neon_reg_alias (str, p))
c19d1205 18534 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18535
b99bd4ef
NC
18536 return;
18537 }
18538
278df34e 18539 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18540 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18541
037e8744
JB
18542 /* The value which unconditional instructions should have in place of the
18543 condition field. */
18544 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18545
c19d1205 18546 if (thumb_mode)
b99bd4ef 18547 {
e74cfd16 18548 arm_feature_set variant;
8f06b2d8
PB
18549
18550 variant = cpu_variant;
18551 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18552 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18553 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18554 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18555 if (!opcode->tvariant
18556 || (thumb_mode == 1
18557 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18558 {
173205ca
TP
18559 if (opcode->tencode == do_t_swi)
18560 as_bad (_("SVC is not permitted on this architecture"));
18561 else
18562 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18563 return;
18564 }
c19d1205
ZW
18565 if (inst.cond != COND_ALWAYS && !unified_syntax
18566 && opcode->tencode != do_t_branch)
b99bd4ef 18567 {
c19d1205 18568 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18569 return;
18570 }
18571
fc289b0a
TP
18572 /* Two things are addressed here:
18573 1) Implicit require narrow instructions on Thumb-1.
18574 This avoids relaxation accidentally introducing Thumb-2
18575 instructions.
18576 2) Reject wide instructions in non Thumb-2 cores.
18577
18578 Only instructions with narrow and wide variants need to be handled
18579 but selecting all non wide-only instructions is easier. */
18580 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18581 && !t32_insn_ok (variant, opcode))
076d447c 18582 {
fc289b0a
TP
18583 if (inst.size_req == 0)
18584 inst.size_req = 2;
18585 else if (inst.size_req == 4)
752d5da4 18586 {
ff8646ee
TP
18587 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18588 as_bad (_("selected processor does not support 32bit wide "
18589 "variant of instruction `%s'"), str);
18590 else
18591 as_bad (_("selected processor does not support `%s' in "
18592 "Thumb-2 mode"), str);
fc289b0a 18593 return;
752d5da4 18594 }
076d447c
PB
18595 }
18596
c19d1205
ZW
18597 inst.instruction = opcode->tvalue;
18598
5be8be5d 18599 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18600 {
18601 /* Prepare the it_insn_type for those encodings that don't set
18602 it. */
18603 it_fsm_pre_encode ();
c19d1205 18604
477330fc 18605 opcode->tencode ();
e07e6e58 18606
477330fc
RM
18607 it_fsm_post_encode ();
18608 }
e27ec89e 18609
0110f2b8 18610 if (!(inst.error || inst.relax))
b99bd4ef 18611 {
9c2799c2 18612 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18613 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18614 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18615 {
c19d1205 18616 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18617 return;
18618 }
18619 }
076d447c
PB
18620
18621 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18622 instruction. */
9c2799c2 18623 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18624
e74cfd16
PB
18625 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18626 *opcode->tvariant);
ee065d83 18627 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18628 set those bits when Thumb-2 32-bit instructions are seen. The impact
18629 of relaxable instructions will be considered later after we finish all
18630 relaxation. */
ff8646ee
TP
18631 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18632 variant = arm_arch_none;
18633 else
18634 variant = cpu_variant;
18635 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18636 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18637 arm_ext_v6t2);
cd000bff 18638
88714cb8
DG
18639 check_neon_suffixes;
18640
cd000bff 18641 if (!inst.error)
c877a2f2
NC
18642 {
18643 mapping_state (MAP_THUMB);
18644 }
c19d1205 18645 }
3e9e4fcf 18646 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18647 {
845b51d6
PB
18648 bfd_boolean is_bx;
18649
18650 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18651 is_bx = (opcode->aencode == do_bx);
18652
c19d1205 18653 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18654 if (!(is_bx && fix_v4bx)
18655 && !(opcode->avariant &&
18656 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18657 {
84b52b66 18658 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18659 return;
b99bd4ef 18660 }
c19d1205 18661 if (inst.size_req)
b99bd4ef 18662 {
c19d1205
ZW
18663 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18664 return;
b99bd4ef
NC
18665 }
18666
c19d1205
ZW
18667 inst.instruction = opcode->avalue;
18668 if (opcode->tag == OT_unconditionalF)
eff0bc54 18669 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18670 else
18671 inst.instruction |= inst.cond << 28;
18672 inst.size = INSN_SIZE;
5be8be5d 18673 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18674 {
18675 it_fsm_pre_encode ();
18676 opcode->aencode ();
18677 it_fsm_post_encode ();
18678 }
ee065d83 18679 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18680 on a hypothetical non-thumb v5 core. */
845b51d6 18681 if (is_bx)
e74cfd16 18682 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18683 else
e74cfd16
PB
18684 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18685 *opcode->avariant);
88714cb8
DG
18686
18687 check_neon_suffixes;
18688
cd000bff 18689 if (!inst.error)
c877a2f2
NC
18690 {
18691 mapping_state (MAP_ARM);
18692 }
b99bd4ef 18693 }
3e9e4fcf
JB
18694 else
18695 {
18696 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18697 "-- `%s'"), str);
18698 return;
18699 }
c19d1205
ZW
18700 output_inst (str);
18701}
b99bd4ef 18702
e07e6e58
NC
18703static void
18704check_it_blocks_finished (void)
18705{
18706#ifdef OBJ_ELF
18707 asection *sect;
18708
18709 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18710 if (seg_info (sect)->tc_segment_info_data.current_it.state
18711 == MANUAL_IT_BLOCK)
18712 {
18713 as_warn (_("section '%s' finished with an open IT block."),
18714 sect->name);
18715 }
18716#else
18717 if (now_it.state == MANUAL_IT_BLOCK)
18718 as_warn (_("file finished with an open IT block."));
18719#endif
18720}
18721
c19d1205
ZW
18722/* Various frobbings of labels and their addresses. */
18723
18724void
18725arm_start_line_hook (void)
18726{
18727 last_label_seen = NULL;
b99bd4ef
NC
18728}
18729
c19d1205
ZW
18730void
18731arm_frob_label (symbolS * sym)
b99bd4ef 18732{
c19d1205 18733 last_label_seen = sym;
b99bd4ef 18734
c19d1205 18735 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18736
c19d1205
ZW
18737#if defined OBJ_COFF || defined OBJ_ELF
18738 ARM_SET_INTERWORK (sym, support_interwork);
18739#endif
b99bd4ef 18740
e07e6e58
NC
18741 force_automatic_it_block_close ();
18742
5f4273c7 18743 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18744 as Thumb functions. This is because these labels, whilst
18745 they exist inside Thumb code, are not the entry points for
18746 possible ARM->Thumb calls. Also, these labels can be used
18747 as part of a computed goto or switch statement. eg gcc
18748 can generate code that looks like this:
b99bd4ef 18749
c19d1205
ZW
18750 ldr r2, [pc, .Laaa]
18751 lsl r3, r3, #2
18752 ldr r2, [r3, r2]
18753 mov pc, r2
b99bd4ef 18754
c19d1205
ZW
18755 .Lbbb: .word .Lxxx
18756 .Lccc: .word .Lyyy
18757 ..etc...
18758 .Laaa: .word Lbbb
b99bd4ef 18759
c19d1205
ZW
18760 The first instruction loads the address of the jump table.
18761 The second instruction converts a table index into a byte offset.
18762 The third instruction gets the jump address out of the table.
18763 The fourth instruction performs the jump.
b99bd4ef 18764
c19d1205
ZW
18765 If the address stored at .Laaa is that of a symbol which has the
18766 Thumb_Func bit set, then the linker will arrange for this address
18767 to have the bottom bit set, which in turn would mean that the
18768 address computation performed by the third instruction would end
18769 up with the bottom bit set. Since the ARM is capable of unaligned
18770 word loads, the instruction would then load the incorrect address
18771 out of the jump table, and chaos would ensue. */
18772 if (label_is_thumb_function_name
18773 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18774 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18775 {
c19d1205
ZW
18776 /* When the address of a Thumb function is taken the bottom
18777 bit of that address should be set. This will allow
18778 interworking between Arm and Thumb functions to work
18779 correctly. */
b99bd4ef 18780
c19d1205 18781 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18782
c19d1205 18783 label_is_thumb_function_name = FALSE;
b99bd4ef 18784 }
07a53e5c 18785
07a53e5c 18786 dwarf2_emit_label (sym);
b99bd4ef
NC
18787}
18788
c921be7d 18789bfd_boolean
c19d1205 18790arm_data_in_code (void)
b99bd4ef 18791{
c19d1205 18792 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18793 {
c19d1205
ZW
18794 *input_line_pointer = '/';
18795 input_line_pointer += 5;
18796 *input_line_pointer = 0;
c921be7d 18797 return TRUE;
b99bd4ef
NC
18798 }
18799
c921be7d 18800 return FALSE;
b99bd4ef
NC
18801}
18802
c19d1205
ZW
18803char *
18804arm_canonicalize_symbol_name (char * name)
b99bd4ef 18805{
c19d1205 18806 int len;
b99bd4ef 18807
c19d1205
ZW
18808 if (thumb_mode && (len = strlen (name)) > 5
18809 && streq (name + len - 5, "/data"))
18810 *(name + len - 5) = 0;
b99bd4ef 18811
c19d1205 18812 return name;
b99bd4ef 18813}
c19d1205
ZW
18814\f
18815/* Table of all register names defined by default. The user can
18816 define additional names with .req. Note that all register names
18817 should appear in both upper and lowercase variants. Some registers
18818 also have mixed-case names. */
b99bd4ef 18819
dcbf9037 18820#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18821#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18822#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18823#define REGSET(p,t) \
18824 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18825 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18826 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18827 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18828#define REGSETH(p,t) \
18829 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18830 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18831 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18832 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18833#define REGSET2(p,t) \
18834 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18835 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18836 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18837 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18838#define SPLRBANK(base,bank,t) \
18839 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18840 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18841 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18842 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18843 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18844 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18845
c19d1205 18846static const struct reg_entry reg_names[] =
7ed4c4c5 18847{
c19d1205
ZW
18848 /* ARM integer registers. */
18849 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18850
c19d1205
ZW
18851 /* ATPCS synonyms. */
18852 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18853 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18854 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18855
c19d1205
ZW
18856 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18857 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18858 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18859
c19d1205
ZW
18860 /* Well-known aliases. */
18861 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18862 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18863
18864 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18865 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18866
18867 /* Coprocessor numbers. */
18868 REGSET(p, CP), REGSET(P, CP),
18869
18870 /* Coprocessor register numbers. The "cr" variants are for backward
18871 compatibility. */
18872 REGSET(c, CN), REGSET(C, CN),
18873 REGSET(cr, CN), REGSET(CR, CN),
18874
90ec0d68
MGD
18875 /* ARM banked registers. */
18876 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18877 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18878 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18879 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18880 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18881 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18882 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18883
18884 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18885 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18886 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18887 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18888 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18889 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18890 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18891 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18892
18893 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18894 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18895 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18896 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18897 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18898 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18899 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18900 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18901 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18902
c19d1205
ZW
18903 /* FPA registers. */
18904 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18905 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18906
18907 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18908 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18909
18910 /* VFP SP registers. */
5287ad62
JB
18911 REGSET(s,VFS), REGSET(S,VFS),
18912 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18913
18914 /* VFP DP Registers. */
5287ad62
JB
18915 REGSET(d,VFD), REGSET(D,VFD),
18916 /* Extra Neon DP registers. */
18917 REGSETH(d,VFD), REGSETH(D,VFD),
18918
18919 /* Neon QP registers. */
18920 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18921
18922 /* VFP control registers. */
18923 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18924 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18925 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18926 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18927 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18928 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 18929 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
18930
18931 /* Maverick DSP coprocessor registers. */
18932 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18933 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18934
18935 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18936 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18937 REGDEF(dspsc,0,DSPSC),
18938
18939 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18940 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18941 REGDEF(DSPSC,0,DSPSC),
18942
18943 /* iWMMXt data registers - p0, c0-15. */
18944 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18945
18946 /* iWMMXt control registers - p1, c0-3. */
18947 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18948 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18949 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18950 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18951
18952 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18953 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18954 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18955 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18956 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18957
18958 /* XScale accumulator registers. */
18959 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18960};
18961#undef REGDEF
18962#undef REGNUM
18963#undef REGSET
7ed4c4c5 18964
c19d1205
ZW
18965/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18966 within psr_required_here. */
18967static const struct asm_psr psrs[] =
18968{
18969 /* Backward compatibility notation. Note that "all" is no longer
18970 truly all possible PSR bits. */
18971 {"all", PSR_c | PSR_f},
18972 {"flg", PSR_f},
18973 {"ctl", PSR_c},
18974
18975 /* Individual flags. */
18976 {"f", PSR_f},
18977 {"c", PSR_c},
18978 {"x", PSR_x},
18979 {"s", PSR_s},
59b42a0d 18980
c19d1205
ZW
18981 /* Combinations of flags. */
18982 {"fs", PSR_f | PSR_s},
18983 {"fx", PSR_f | PSR_x},
18984 {"fc", PSR_f | PSR_c},
18985 {"sf", PSR_s | PSR_f},
18986 {"sx", PSR_s | PSR_x},
18987 {"sc", PSR_s | PSR_c},
18988 {"xf", PSR_x | PSR_f},
18989 {"xs", PSR_x | PSR_s},
18990 {"xc", PSR_x | PSR_c},
18991 {"cf", PSR_c | PSR_f},
18992 {"cs", PSR_c | PSR_s},
18993 {"cx", PSR_c | PSR_x},
18994 {"fsx", PSR_f | PSR_s | PSR_x},
18995 {"fsc", PSR_f | PSR_s | PSR_c},
18996 {"fxs", PSR_f | PSR_x | PSR_s},
18997 {"fxc", PSR_f | PSR_x | PSR_c},
18998 {"fcs", PSR_f | PSR_c | PSR_s},
18999 {"fcx", PSR_f | PSR_c | PSR_x},
19000 {"sfx", PSR_s | PSR_f | PSR_x},
19001 {"sfc", PSR_s | PSR_f | PSR_c},
19002 {"sxf", PSR_s | PSR_x | PSR_f},
19003 {"sxc", PSR_s | PSR_x | PSR_c},
19004 {"scf", PSR_s | PSR_c | PSR_f},
19005 {"scx", PSR_s | PSR_c | PSR_x},
19006 {"xfs", PSR_x | PSR_f | PSR_s},
19007 {"xfc", PSR_x | PSR_f | PSR_c},
19008 {"xsf", PSR_x | PSR_s | PSR_f},
19009 {"xsc", PSR_x | PSR_s | PSR_c},
19010 {"xcf", PSR_x | PSR_c | PSR_f},
19011 {"xcs", PSR_x | PSR_c | PSR_s},
19012 {"cfs", PSR_c | PSR_f | PSR_s},
19013 {"cfx", PSR_c | PSR_f | PSR_x},
19014 {"csf", PSR_c | PSR_s | PSR_f},
19015 {"csx", PSR_c | PSR_s | PSR_x},
19016 {"cxf", PSR_c | PSR_x | PSR_f},
19017 {"cxs", PSR_c | PSR_x | PSR_s},
19018 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19019 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19020 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19021 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19022 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19023 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19024 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19025 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19026 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19027 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19028 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19029 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19030 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19031 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19032 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19033 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19034 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19035 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19036 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19037 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19038 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19039 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19040 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19041 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19042};
19043
62b3e311
PB
19044/* Table of V7M psr names. */
19045static const struct asm_psr v7m_psrs[] =
19046{
1a336194
TP
19047 {"apsr", 0x0 }, {"APSR", 0x0 },
19048 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19049 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19050 {"psr", 0x3 }, {"PSR", 0x3 },
19051 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19052 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19053 {"epsr", 0x6 }, {"EPSR", 0x6 },
19054 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19055 {"msp", 0x8 }, {"MSP", 0x8 },
19056 {"psp", 0x9 }, {"PSP", 0x9 },
19057 {"msplim", 0xa }, {"MSPLIM", 0xa },
19058 {"psplim", 0xb }, {"PSPLIM", 0xb },
19059 {"primask", 0x10}, {"PRIMASK", 0x10},
19060 {"basepri", 0x11}, {"BASEPRI", 0x11},
19061 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19062 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19063 {"control", 0x14}, {"CONTROL", 0x14},
19064 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19065 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19066 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19067 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19068 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19069 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19070 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19071 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19072 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19073};
19074
c19d1205
ZW
19075/* Table of all shift-in-operand names. */
19076static const struct asm_shift_name shift_names [] =
b99bd4ef 19077{
c19d1205
ZW
19078 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19079 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19080 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19081 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19082 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19083 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19084};
b99bd4ef 19085
c19d1205
ZW
19086/* Table of all explicit relocation names. */
19087#ifdef OBJ_ELF
19088static struct reloc_entry reloc_names[] =
19089{
19090 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19091 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19092 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19093 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19094 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19095 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19096 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19097 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19098 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19099 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19100 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19101 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19102 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19103 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19104 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19105 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19106 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19107 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19108};
19109#endif
b99bd4ef 19110
c19d1205
ZW
19111/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19112static const struct asm_cond conds[] =
19113{
19114 {"eq", 0x0},
19115 {"ne", 0x1},
19116 {"cs", 0x2}, {"hs", 0x2},
19117 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19118 {"mi", 0x4},
19119 {"pl", 0x5},
19120 {"vs", 0x6},
19121 {"vc", 0x7},
19122 {"hi", 0x8},
19123 {"ls", 0x9},
19124 {"ge", 0xa},
19125 {"lt", 0xb},
19126 {"gt", 0xc},
19127 {"le", 0xd},
19128 {"al", 0xe}
19129};
bfae80f2 19130
e797f7e0 19131#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19132 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19133 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19134
62b3e311
PB
19135static struct asm_barrier_opt barrier_opt_names[] =
19136{
e797f7e0
MGD
19137 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19138 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19139 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19140 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19141 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19142 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19143 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19144 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19145 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19146 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19147 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19148 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19149 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19150 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19151 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19152 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19153};
19154
e797f7e0
MGD
19155#undef UL_BARRIER
19156
c19d1205
ZW
19157/* Table of ARM-format instructions. */
19158
19159/* Macros for gluing together operand strings. N.B. In all cases
19160 other than OPS0, the trailing OP_stop comes from default
19161 zero-initialization of the unspecified elements of the array. */
19162#define OPS0() { OP_stop, }
19163#define OPS1(a) { OP_##a, }
19164#define OPS2(a,b) { OP_##a,OP_##b, }
19165#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19166#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19167#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19168#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19169
5be8be5d
DG
19170/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19171 This is useful when mixing operands for ARM and THUMB, i.e. using the
19172 MIX_ARM_THUMB_OPERANDS macro.
19173 In order to use these macros, prefix the number of operands with _
19174 e.g. _3. */
19175#define OPS_1(a) { a, }
19176#define OPS_2(a,b) { a,b, }
19177#define OPS_3(a,b,c) { a,b,c, }
19178#define OPS_4(a,b,c,d) { a,b,c,d, }
19179#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19180#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19181
c19d1205
ZW
19182/* These macros abstract out the exact format of the mnemonic table and
19183 save some repeated characters. */
19184
19185/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19186#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19187 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19188 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19189
19190/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19191 a T_MNEM_xyz enumerator. */
19192#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19193 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19194#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19195 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19196
19197/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19198 infix after the third character. */
19199#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19200 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19201 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19202#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19203 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19204 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19205#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19206 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19207#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19208 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19209#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19210 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19211#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19212 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19213
c19d1205 19214/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19215 field is still 0xE. Many of the Thumb variants can be executed
19216 conditionally, so this is checked separately. */
c19d1205 19217#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19218 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19219 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19220
dd5181d5
KT
19221/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19222 Used by mnemonics that have very minimal differences in the encoding for
19223 ARM and Thumb variants and can be handled in a common function. */
19224#define TUEc(mnem, op, top, nops, ops, en) \
19225 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19226 THUMB_VARIANT, do_##en, do_##en }
19227
c19d1205
ZW
19228/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19229 condition code field. */
19230#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19231 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19232 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19233
19234/* ARM-only variants of all the above. */
6a86118a 19235#define CE(mnem, op, nops, ops, ae) \
21d799b5 19236 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19237
19238#define C3(mnem, op, nops, ops, ae) \
19239 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19240
e3cb604e
PB
19241/* Legacy mnemonics that always have conditional infix after the third
19242 character. */
19243#define CL(mnem, op, nops, ops, ae) \
21d799b5 19244 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19245 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19246
8f06b2d8
PB
19247/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19248#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19249 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19250
e3cb604e
PB
19251/* Legacy coprocessor instructions where conditional infix and conditional
19252 suffix are ambiguous. For consistency this includes all FPA instructions,
19253 not just the potentially ambiguous ones. */
19254#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19255 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19256 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19257
19258/* Coprocessor, takes either a suffix or a position-3 infix
19259 (for an FPA corner case). */
19260#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19261 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19262 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19263
6a86118a 19264#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19265 { m1 #m2 m3, OPS##nops ops, \
19266 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19267 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19268
19269#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19270 xCM_ (m1, , m2, op, nops, ops, ae), \
19271 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19272 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19273 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19274 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19275 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19276 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19277 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19278 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19279 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19280 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19281 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19282 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19283 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19284 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19285 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19286 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19287 xCM_ (m1, le, m2, op, nops, ops, ae), \
19288 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19289
19290#define UE(mnem, op, nops, ops, ae) \
19291 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19292
19293#define UF(mnem, op, nops, ops, ae) \
19294 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19295
5287ad62
JB
19296/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19297 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19298 use the same encoding function for each. */
19299#define NUF(mnem, op, nops, ops, enc) \
19300 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19301 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19302
19303/* Neon data processing, version which indirects through neon_enc_tab for
19304 the various overloaded versions of opcodes. */
19305#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19306 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19307 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19308
19309/* Neon insn with conditional suffix for the ARM version, non-overloaded
19310 version. */
037e8744
JB
19311#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19312 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19313 THUMB_VARIANT, do_##enc, do_##enc }
19314
037e8744 19315#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19316 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19317
19318#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19319 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19320
5287ad62 19321/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19322#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19323 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19324 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19325
037e8744 19326#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19327 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19328
19329#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19330 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19331
c19d1205
ZW
19332#define do_0 0
19333
c19d1205 19334static const struct asm_opcode insns[] =
bfae80f2 19335{
74db7efb
NC
19336#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19337#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19338 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19339 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19340 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19341 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19342 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19343 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19344 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19345 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19346 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19347 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19348 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19349 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19350 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19351 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19352 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19353 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19354
19355 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19356 for setting PSR flag bits. They are obsolete in V6 and do not
19357 have Thumb equivalents. */
21d799b5
NC
19358 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19359 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19360 CL("tstp", 110f000, 2, (RR, SH), cmp),
19361 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19362 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19363 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19364 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19365 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19366 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19367
19368 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19369 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19370 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19371 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19372
19373 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19374 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19375 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19376 OP_RRnpc),
19377 OP_ADDRGLDR),ldst, t_ldst),
19378 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19379
19380 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19381 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19382 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19383 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19384 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19385 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19386
21d799b5
NC
19387 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19388 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19389
c19d1205 19390 /* Pseudo ops. */
21d799b5 19391 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19392 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19393 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19394 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19395
19396 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19397 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19398 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19399 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19400 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19401 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19402 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19403 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19404 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19405 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19406 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19407 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19408 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19409
16a4cf17 19410 /* These may simplify to neg. */
21d799b5
NC
19411 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19412 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19413
173205ca
TP
19414#undef THUMB_VARIANT
19415#define THUMB_VARIANT & arm_ext_os
19416
19417 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19418 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19419
c921be7d
NC
19420#undef THUMB_VARIANT
19421#define THUMB_VARIANT & arm_ext_v6
19422
21d799b5 19423 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19424
19425 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19426#undef THUMB_VARIANT
19427#define THUMB_VARIANT & arm_ext_v6t2
19428
21d799b5
NC
19429 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19430 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19431 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19432
5be8be5d
DG
19433 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19434 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19435 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19436 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19437
21d799b5
NC
19438 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19439 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19440
21d799b5
NC
19441 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19442 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19443
19444 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19445 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19446 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19447
19448 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19449 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19450 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19451 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19452 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19453 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19454 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19455 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19456
c921be7d
NC
19457#undef ARM_VARIANT
19458#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19459#undef THUMB_VARIANT
19460#define THUMB_VARIANT & arm_ext_v4t
19461
21d799b5
NC
19462 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19463 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19464
c921be7d
NC
19465#undef THUMB_VARIANT
19466#define THUMB_VARIANT & arm_ext_v6t2
19467
21d799b5 19468 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19469 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19470
19471 /* Generic coprocessor instructions. */
21d799b5
NC
19472 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19473 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19474 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19475 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19476 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19477 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19478 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19479
c921be7d
NC
19480#undef ARM_VARIANT
19481#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19482
21d799b5 19483 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19484 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19485
c921be7d
NC
19486#undef ARM_VARIANT
19487#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19488#undef THUMB_VARIANT
19489#define THUMB_VARIANT & arm_ext_msr
19490
d2cd1205
JB
19491 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19492 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19493
c921be7d
NC
19494#undef ARM_VARIANT
19495#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19496#undef THUMB_VARIANT
19497#define THUMB_VARIANT & arm_ext_v6t2
19498
21d799b5
NC
19499 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19500 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19501 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19502 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19503 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19504 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19505 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19506 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19507
c921be7d
NC
19508#undef ARM_VARIANT
19509#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19510#undef THUMB_VARIANT
19511#define THUMB_VARIANT & arm_ext_v4t
19512
5be8be5d
DG
19513 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19514 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19515 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19516 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19517 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19518 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19519
c921be7d
NC
19520#undef ARM_VARIANT
19521#define ARM_VARIANT & arm_ext_v4t_5
19522
c19d1205
ZW
19523 /* ARM Architecture 4T. */
19524 /* Note: bx (and blx) are required on V5, even if the processor does
19525 not support Thumb. */
21d799b5 19526 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19527
c921be7d
NC
19528#undef ARM_VARIANT
19529#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19530#undef THUMB_VARIANT
19531#define THUMB_VARIANT & arm_ext_v5t
19532
c19d1205
ZW
19533 /* Note: blx has 2 variants; the .value coded here is for
19534 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19535 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19536 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19537
c921be7d
NC
19538#undef THUMB_VARIANT
19539#define THUMB_VARIANT & arm_ext_v6t2
19540
21d799b5
NC
19541 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19542 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19543 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19544 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19545 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19546 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19547 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19548 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19549
c921be7d 19550#undef ARM_VARIANT
74db7efb
NC
19551#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19552#undef THUMB_VARIANT
19553#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19554
21d799b5
NC
19555 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19556 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19557 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19558 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19559
21d799b5
NC
19560 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19561 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19562
21d799b5
NC
19563 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19564 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19565 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19566 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19567
21d799b5
NC
19568 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19569 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19570 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19571 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19572
21d799b5
NC
19573 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19574 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19575
03ee1b7f
NC
19576 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19577 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19578 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19579 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19580
c921be7d 19581#undef ARM_VARIANT
74db7efb
NC
19582#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19583#undef THUMB_VARIANT
19584#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19585
21d799b5 19586 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19587 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19588 ldrd, t_ldstd),
19589 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19590 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19591
21d799b5
NC
19592 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19593 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19594
c921be7d
NC
19595#undef ARM_VARIANT
19596#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19597
21d799b5 19598 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19599
c921be7d
NC
19600#undef ARM_VARIANT
19601#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19602#undef THUMB_VARIANT
19603#define THUMB_VARIANT & arm_ext_v6
19604
21d799b5
NC
19605 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19606 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19607 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19608 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19609 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19610 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19611 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19612 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19613 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19614 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19615
c921be7d 19616#undef THUMB_VARIANT
ff8646ee 19617#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19618
5be8be5d
DG
19619 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19620 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19621 strex, t_strex),
ff8646ee
TP
19622#undef THUMB_VARIANT
19623#define THUMB_VARIANT & arm_ext_v6t2
19624
21d799b5
NC
19625 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19626 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19627
21d799b5
NC
19628 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19629 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19630
9e3c6df6 19631/* ARM V6 not included in V7M. */
c921be7d
NC
19632#undef THUMB_VARIANT
19633#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19634 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19635 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19636 UF(rfeib, 9900a00, 1, (RRw), rfe),
19637 UF(rfeda, 8100a00, 1, (RRw), rfe),
19638 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19639 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19640 UF(rfefa, 8100a00, 1, (RRw), rfe),
19641 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19642 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19643 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19644 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19645 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19646 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19647 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19648 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19649 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19650 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19651 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19652 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19653
9e3c6df6
PB
19654/* ARM V6 not included in V7M (eg. integer SIMD). */
19655#undef THUMB_VARIANT
19656#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19657 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19658 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19659 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19660 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19661 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19662 /* Old name for QASX. */
74db7efb 19663 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19664 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19665 /* Old name for QSAX. */
74db7efb 19666 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19667 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19668 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19669 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19670 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19671 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19672 /* Old name for SASX. */
74db7efb 19673 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19674 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19675 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19676 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19677 /* Old name for SHASX. */
21d799b5 19678 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19679 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19680 /* Old name for SHSAX. */
21d799b5
NC
19681 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19682 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19683 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19684 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19685 /* Old name for SSAX. */
74db7efb 19686 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19687 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19688 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19689 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19690 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19691 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19692 /* Old name for UASX. */
74db7efb 19693 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19694 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19695 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19696 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19697 /* Old name for UHASX. */
21d799b5
NC
19698 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19699 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19700 /* Old name for UHSAX. */
21d799b5
NC
19701 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19702 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19703 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19704 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19705 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19706 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19707 /* Old name for UQASX. */
21d799b5
NC
19708 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19709 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19710 /* Old name for UQSAX. */
21d799b5
NC
19711 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19712 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19713 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19714 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19715 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19716 /* Old name for USAX. */
74db7efb 19717 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19718 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19719 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19720 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19721 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19722 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19723 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19724 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19725 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19726 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19727 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19728 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19729 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19730 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19731 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19732 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19733 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19734 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19735 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19736 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19737 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19738 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19739 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19740 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19741 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19742 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19743 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19744 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19745 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19746 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19747 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19748 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19749 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19750 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19751
c921be7d
NC
19752#undef ARM_VARIANT
19753#define ARM_VARIANT & arm_ext_v6k
19754#undef THUMB_VARIANT
19755#define THUMB_VARIANT & arm_ext_v6k
19756
21d799b5
NC
19757 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19758 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19759 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19760 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19761
c921be7d
NC
19762#undef THUMB_VARIANT
19763#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19764 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19765 ldrexd, t_ldrexd),
19766 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19767 RRnpcb), strexd, t_strexd),
ebdca51a 19768
c921be7d 19769#undef THUMB_VARIANT
ff8646ee 19770#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19771 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19772 rd_rn, rd_rn),
19773 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19774 rd_rn, rd_rn),
19775 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19776 strex, t_strexbh),
5be8be5d 19777 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19778 strex, t_strexbh),
21d799b5 19779 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19780
c921be7d 19781#undef ARM_VARIANT
f4c65163 19782#define ARM_VARIANT & arm_ext_sec
74db7efb 19783#undef THUMB_VARIANT
f4c65163 19784#define THUMB_VARIANT & arm_ext_sec
c921be7d 19785
21d799b5 19786 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19787
90ec0d68
MGD
19788#undef ARM_VARIANT
19789#define ARM_VARIANT & arm_ext_virt
19790#undef THUMB_VARIANT
19791#define THUMB_VARIANT & arm_ext_virt
19792
19793 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19794 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19795
ddfded2f
MW
19796#undef ARM_VARIANT
19797#define ARM_VARIANT & arm_ext_pan
19798#undef THUMB_VARIANT
19799#define THUMB_VARIANT & arm_ext_pan
19800
19801 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19802
c921be7d 19803#undef ARM_VARIANT
74db7efb 19804#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19805#undef THUMB_VARIANT
19806#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19807
21d799b5
NC
19808 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19809 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19810 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19811 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19812
21d799b5 19813 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19814 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19815
5be8be5d
DG
19816 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19817 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19818 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19819 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19820
ff8646ee
TP
19821#undef THUMB_VARIANT
19822#define THUMB_VARIANT & arm_ext_v6t2_v8m
19823 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19824 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19825
bf3eeda7 19826 /* Thumb-only instructions. */
74db7efb 19827#undef ARM_VARIANT
bf3eeda7
NS
19828#define ARM_VARIANT NULL
19829 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19830 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19831
19832 /* ARM does not really have an IT instruction, so always allow it.
19833 The opcode is copied from Thumb in order to allow warnings in
19834 -mimplicit-it=[never | arm] modes. */
19835#undef ARM_VARIANT
19836#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19837#undef THUMB_VARIANT
19838#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19839
21d799b5
NC
19840 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19841 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19842 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19843 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19844 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19845 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19846 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19847 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19848 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19849 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19850 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19851 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19852 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19853 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19854 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19855 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19856 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19857 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19858
92e90b6e 19859 /* Thumb2 only instructions. */
c921be7d
NC
19860#undef ARM_VARIANT
19861#define ARM_VARIANT NULL
92e90b6e 19862
21d799b5
NC
19863 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19864 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19865 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19866 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19867 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19868 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19869
eea54501
MGD
19870 /* Hardware division instructions. */
19871#undef ARM_VARIANT
19872#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19873#undef THUMB_VARIANT
19874#define THUMB_VARIANT & arm_ext_div
19875
eea54501
MGD
19876 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19877 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19878
7e806470 19879 /* ARM V6M/V7 instructions. */
c921be7d
NC
19880#undef ARM_VARIANT
19881#define ARM_VARIANT & arm_ext_barrier
19882#undef THUMB_VARIANT
19883#define THUMB_VARIANT & arm_ext_barrier
19884
ccb84d65
JB
19885 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19886 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19887 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19888
62b3e311 19889 /* ARM V7 instructions. */
c921be7d
NC
19890#undef ARM_VARIANT
19891#define ARM_VARIANT & arm_ext_v7
19892#undef THUMB_VARIANT
19893#define THUMB_VARIANT & arm_ext_v7
19894
21d799b5
NC
19895 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19896 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19897
74db7efb 19898#undef ARM_VARIANT
60e5ef9f 19899#define ARM_VARIANT & arm_ext_mp
74db7efb 19900#undef THUMB_VARIANT
60e5ef9f
MGD
19901#define THUMB_VARIANT & arm_ext_mp
19902
19903 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19904
53c4b28b
MGD
19905 /* AArchv8 instructions. */
19906#undef ARM_VARIANT
19907#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19908
19909/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19910#undef THUMB_VARIANT
4ed7ed8d 19911#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19912
4ed7ed8d
TP
19913 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19914 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19915 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19916 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19917 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19918 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19919 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19920 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19921 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19922 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19923 stlex, t_stlex),
4b8c8c02
RE
19924 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19925 stlex, t_stlex),
19926 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19927 stlex, t_stlex),
4ed7ed8d
TP
19928#undef THUMB_VARIANT
19929#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19930
4ed7ed8d
TP
19931 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19932 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19933 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19934 ldrexd, t_ldrexd),
19935 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19936 strexd, t_strexd),
8884b720 19937 /* ARMv8 T32 only. */
74db7efb 19938#undef ARM_VARIANT
b79f7053
MGD
19939#define ARM_VARIANT NULL
19940 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19941 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19942 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19943
33399f07
MGD
19944 /* FP for ARMv8. */
19945#undef ARM_VARIANT
a715796b 19946#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19947#undef THUMB_VARIANT
a715796b 19948#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19949
19950 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19951 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19952 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19953 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19954 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19955 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19956 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19957 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19958 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19959 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19960 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19961 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19962 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19963 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19964 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19965 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19966 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19967
91ff7894
MGD
19968 /* Crypto v1 extensions. */
19969#undef ARM_VARIANT
19970#define ARM_VARIANT & fpu_crypto_ext_armv8
19971#undef THUMB_VARIANT
19972#define THUMB_VARIANT & fpu_crypto_ext_armv8
19973
19974 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19975 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19976 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19977 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19978 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19979 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19980 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19981 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19982 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19983 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19984 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19985 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19986 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19987 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19988
dd5181d5 19989#undef ARM_VARIANT
74db7efb 19990#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19991#undef THUMB_VARIANT
19992#define THUMB_VARIANT & crc_ext_armv8
19993 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19994 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19995 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19996 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19997 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19998 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19999
105bde57
MW
20000 /* ARMv8.2 RAS extension. */
20001#undef ARM_VARIANT
4d1464f2 20002#define ARM_VARIANT & arm_ext_ras
105bde57 20003#undef THUMB_VARIANT
4d1464f2 20004#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20005 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20006
49e8a725
SN
20007#undef ARM_VARIANT
20008#define ARM_VARIANT & arm_ext_v8_3
20009#undef THUMB_VARIANT
20010#define THUMB_VARIANT & arm_ext_v8_3
20011 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20012 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20013 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20014
c604a79a
JW
20015#undef ARM_VARIANT
20016#define ARM_VARIANT & fpu_neon_ext_dotprod
20017#undef THUMB_VARIANT
20018#define THUMB_VARIANT & fpu_neon_ext_dotprod
20019 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20020 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20021
c921be7d
NC
20022#undef ARM_VARIANT
20023#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20024#undef THUMB_VARIANT
20025#define THUMB_VARIANT NULL
c921be7d 20026
21d799b5
NC
20027 cCE("wfs", e200110, 1, (RR), rd),
20028 cCE("rfs", e300110, 1, (RR), rd),
20029 cCE("wfc", e400110, 1, (RR), rd),
20030 cCE("rfc", e500110, 1, (RR), rd),
20031
20032 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20033 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20034 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20035 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20036
20037 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20038 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20039 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20040 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20041
20042 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20043 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20044 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20045 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20046 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20047 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20048 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20049 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20050 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20051 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20052 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20053 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20054
20055 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20056 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20057 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20058 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20059 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20060 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20061 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20062 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20063 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20064 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20065 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20066 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20067
20068 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20069 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20070 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20071 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20072 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20073 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20074 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20075 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20076 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20077 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20078 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20079 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20080
20081 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20082 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20083 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20084 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20085 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20086 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20087 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20088 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20089 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20090 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20091 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20092 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20093
20094 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20095 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20096 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20097 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20098 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20099 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20100 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20101 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20102 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20103 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20104 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20105 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20106
20107 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20108 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20109 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20110 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20111 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20112 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20113 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20114 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20115 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20116 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20117 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20118 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20119
20120 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20121 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20122 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20123 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20124 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20125 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20126 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20127 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20128 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20129 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20130 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20131 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20132
20133 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20134 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20135 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20136 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20137 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20138 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20139 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20140 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20141 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20142 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20143 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20144 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20145
20146 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20147 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20148 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20149 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20150 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20151 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20152 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20153 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20154 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20155 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20156 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20157 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20158
20159 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20160 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20161 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20162 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20163 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20164 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20165 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20166 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20167 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20168 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20169 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20170 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20171
20172 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20173 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20174 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20175 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20176 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20177 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20178 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20179 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20180 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20181 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20182 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20183 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20184
20185 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20186 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20187 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20188 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20189 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20190 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20191 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20192 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20193 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20194 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20195 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20196 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20197
20198 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20199 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20200 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20201 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20202 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20203 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20204 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20205 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20206 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20207 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20208 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20209 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20210
20211 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20212 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20213 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20214 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20215 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20216 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20217 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20218 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20219 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20220 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20221 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20222 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20223
20224 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20225 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20226 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20227 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20228 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20229 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20230 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20231 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20232 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20233 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20234 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20235 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20236
20237 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20238 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20239 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20240 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20241 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20242 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20243 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20244 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20245 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20246 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20247 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20248 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20249
20250 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20251 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20252 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20253 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20254 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20255 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20256 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20257 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20258 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20259 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20260 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20261 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20262
20263 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20264 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20265 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20266 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20267 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20268 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20269 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20270 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20271 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20272 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20273 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20274 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20275
20276 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20277 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20278 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20279 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20280 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20281 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20282 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20283 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20284 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20285 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20286 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20287 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20288
20289 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20290 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20291 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20292 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20293 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20294 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20295 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20296 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20297 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20298 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20299 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20300 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20301
20302 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20303 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20304 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20305 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20306 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20307 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20308 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20309 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20310 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20311 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20312 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20313 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20314
20315 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20316 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20317 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20318 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20319 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20320 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20321 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20322 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20323 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20324 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20325 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20326 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20327
20328 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20329 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20330 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20331 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20332 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20333 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20334 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20335 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20336 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20337 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20338 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20339 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20340
20341 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20342 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20343 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20344 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20345 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20346 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20347 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20348 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20349 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20350 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20351 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20352 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20353
20354 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20355 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20356 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20357 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20358 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20359 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20360 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20361 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20362 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20363 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20364 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20365 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20366
20367 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20368 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20369 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20370 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20371 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20372 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20373 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20374 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20375 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20376 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20377 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20378 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20379
20380 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20381 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20382 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20383 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20384 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20385 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20386 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20387 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20388 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20389 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20390 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20391 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20392
20393 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20394 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20395 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20396 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20397 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20398 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20399 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20400 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20401 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20402 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20403 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20404 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20405
20406 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20407 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20408 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20409 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20410 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20411 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20412 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20413 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20414 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20415 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20416 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20417 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20418
20419 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20420 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20421 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20422 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20423
20424 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20425 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20426 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20427 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20428 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20429 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20430 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20431 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20432 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20433 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20434 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20435 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20436
c19d1205
ZW
20437 /* The implementation of the FIX instruction is broken on some
20438 assemblers, in that it accepts a precision specifier as well as a
20439 rounding specifier, despite the fact that this is meaningless.
20440 To be more compatible, we accept it as well, though of course it
20441 does not set any bits. */
21d799b5
NC
20442 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20443 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20444 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20445 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20446 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20447 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20448 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20449 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20450 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20451 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20452 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20453 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20454 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20455
c19d1205 20456 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20457#undef ARM_VARIANT
20458#define ARM_VARIANT & fpu_fpa_ext_v2
20459
21d799b5
NC
20460 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20461 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20462 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20463 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20464 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20465 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20466
c921be7d
NC
20467#undef ARM_VARIANT
20468#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20469
c19d1205 20470 /* Moves and type conversions. */
21d799b5
NC
20471 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20472 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20473 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20474 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20475 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20476 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20477 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20478 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20479 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20480 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20481 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20482 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20483 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20484 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20485
20486 /* Memory operations. */
21d799b5
NC
20487 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20488 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20489 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20490 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20491 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20492 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20493 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20494 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20495 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20496 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20497 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20498 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20499 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20500 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20501 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20502 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20503 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20504 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20505
c19d1205 20506 /* Monadic operations. */
21d799b5
NC
20507 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20508 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20509 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20510
20511 /* Dyadic operations. */
21d799b5
NC
20512 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20513 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20514 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20515 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20516 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20517 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20518 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20519 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20520 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20521
c19d1205 20522 /* Comparisons. */
21d799b5
NC
20523 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20524 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20525 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20526 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20527
62f3b8c8
PB
20528 /* Double precision load/store are still present on single precision
20529 implementations. */
20530 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20531 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20532 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20533 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20534 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20535 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20536 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20537 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20538 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20539 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20540
c921be7d
NC
20541#undef ARM_VARIANT
20542#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20543
c19d1205 20544 /* Moves and type conversions. */
21d799b5
NC
20545 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20546 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20547 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20548 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20549 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20550 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20551 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20552 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20553 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20554 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20555 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20556 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20557 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20558
c19d1205 20559 /* Monadic operations. */
21d799b5
NC
20560 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20561 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20562 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20563
20564 /* Dyadic operations. */
21d799b5
NC
20565 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20566 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20567 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20568 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20569 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20570 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20571 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20572 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20573 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20574
c19d1205 20575 /* Comparisons. */
21d799b5
NC
20576 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20577 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20578 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20579 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20580
c921be7d
NC
20581#undef ARM_VARIANT
20582#define ARM_VARIANT & fpu_vfp_ext_v2
20583
21d799b5
NC
20584 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20585 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20586 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20587 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20588
037e8744
JB
20589/* Instructions which may belong to either the Neon or VFP instruction sets.
20590 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20591#undef ARM_VARIANT
20592#define ARM_VARIANT & fpu_vfp_ext_v1xd
20593#undef THUMB_VARIANT
20594#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20595
037e8744
JB
20596 /* These mnemonics are unique to VFP. */
20597 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20598 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20599 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20600 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20601 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20602 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20603 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20604 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20605 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20606 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20607
20608 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20609 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20610 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20611 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20612
21d799b5
NC
20613 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20614 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20615
20616 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20617 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20618
55881a11
MGD
20619 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20620 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20621 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20622 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20623 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20624 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20625 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20626 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20627
5f1af56b 20628 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20629 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20630 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20631 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20632
037e8744
JB
20633
20634 /* NOTE: All VMOV encoding is special-cased! */
20635 NCE(vmov, 0, 1, (VMOV), neon_mov),
20636 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20637
9db2f6b4
RL
20638#undef ARM_VARIANT
20639#define ARM_VARIANT & arm_ext_fp16
20640#undef THUMB_VARIANT
20641#define THUMB_VARIANT & arm_ext_fp16
20642 /* New instructions added from v8.2, allowing the extraction and insertion of
20643 the upper 16 bits of a 32-bit vector register. */
20644 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20645 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20646
c921be7d
NC
20647#undef THUMB_VARIANT
20648#define THUMB_VARIANT & fpu_neon_ext_v1
20649#undef ARM_VARIANT
20650#define ARM_VARIANT & fpu_neon_ext_v1
20651
5287ad62
JB
20652 /* Data processing with three registers of the same length. */
20653 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20654 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20655 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20656 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20657 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20658 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20659 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20660 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20661 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20662 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20663 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20664 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20665 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20666 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20667 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20668 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20669 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20670 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20671 /* If not immediate, fall back to neon_dyadic_i64_su.
20672 shl_imm should accept I8 I16 I32 I64,
20673 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20674 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20675 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20676 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20677 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20678 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20679 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20680 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20681 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20682 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20683 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20684 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20685 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20686 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20687 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20688 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20689 /* Bitfield ops, untyped. */
20690 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20691 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20692 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20693 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20694 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20695 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20696 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20697 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20698 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20699 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20700 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20701 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20702 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20703 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20704 back to neon_dyadic_if_su. */
21d799b5
NC
20705 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20706 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20707 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20708 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20709 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20710 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20711 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20712 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20713 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20714 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20715 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20716 /* As above, D registers only. */
21d799b5
NC
20717 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20718 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20719 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20720 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20721 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20722 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20723 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20724 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20725 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20726 /* vtst takes sizes 8, 16, 32. */
20727 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20728 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20729 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20730 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20731 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20732 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20733 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20734 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20735 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20736 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20737 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20738 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20739 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20740 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20741 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20742 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20743 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20744 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20745 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20746 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20747 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20748 /* ARM v8.1 extension. */
643afb90
MW
20749 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20750 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20751 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20752 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20753
20754 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20755 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20756 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20757
20758 /* Data processing with two registers and a shift amount. */
20759 /* Right shifts, and variants with rounding.
20760 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20761 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20762 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20763 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20764 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20765 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20766 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20767 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20768 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20769 /* Shift and insert. Sizes accepted 8 16 32 64. */
20770 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20771 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20772 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20773 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20774 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20775 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20776 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20777 /* Right shift immediate, saturating & narrowing, with rounding variants.
20778 Types accepted S16 S32 S64 U16 U32 U64. */
20779 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20780 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20781 /* As above, unsigned. Types accepted S16 S32 S64. */
20782 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20783 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20784 /* Right shift narrowing. Types accepted I16 I32 I64. */
20785 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20786 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20787 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20788 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20789 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20790 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20791
4316f0d2
DG
20792 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20793 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20794
20795 /* Data processing, three registers of different lengths. */
20796 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20797 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20798 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20799 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20800 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20801 /* If not scalar, fall back to neon_dyadic_long.
20802 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20803 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20804 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20805 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20806 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20807 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20808 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20809 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20810 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20811 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20812 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20813 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20814 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20815 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20816 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20817 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20818 S16 S32 U16 U32. */
21d799b5 20819 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20820
20821 /* Extract. Size 8. */
3b8d421e
PB
20822 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20823 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20824
20825 /* Two registers, miscellaneous. */
20826 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20827 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20828 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20829 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20830 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20831 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20832 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20833 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20834 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20835 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20836 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20837 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20838 /* VMOVN. Types I16 I32 I64. */
21d799b5 20839 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20840 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20841 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20842 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20843 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20844 /* VZIP / VUZP. Sizes 8 16 32. */
20845 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20846 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20847 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20848 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20849 /* VQABS / VQNEG. Types S8 S16 S32. */
20850 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20851 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20852 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20853 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20854 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20855 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20856 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20857 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20858 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20859 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20860 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20861 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20862 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20863 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20864 /* VCLS. Types S8 S16 S32. */
20865 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20866 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20867 /* VCLZ. Types I8 I16 I32. */
20868 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20869 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20870 /* VCNT. Size 8. */
20871 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20872 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20873 /* Two address, untyped. */
20874 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20875 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20876 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20877 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20878 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20879
20880 /* Table lookup. Size 8. */
20881 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20882 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20883
c921be7d
NC
20884#undef THUMB_VARIANT
20885#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20886#undef ARM_VARIANT
20887#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20888
5287ad62 20889 /* Neon element/structure load/store. */
21d799b5
NC
20890 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20891 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20892 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20893 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20894 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20895 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20896 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20897 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20898
c921be7d 20899#undef THUMB_VARIANT
74db7efb
NC
20900#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20901#undef ARM_VARIANT
20902#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20903 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20904 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20905 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20906 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20907 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20908 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20909 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20910 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20911 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20912
74db7efb 20913#undef THUMB_VARIANT
c921be7d
NC
20914#define THUMB_VARIANT & fpu_vfp_ext_v3
20915#undef ARM_VARIANT
20916#define ARM_VARIANT & fpu_vfp_ext_v3
20917
21d799b5 20918 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20919 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20920 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20921 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20922 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20923 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20924 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20925 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20926 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20927
74db7efb
NC
20928#undef ARM_VARIANT
20929#define ARM_VARIANT & fpu_vfp_ext_fma
20930#undef THUMB_VARIANT
20931#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20932 /* Mnemonics shared by Neon and VFP. These are included in the
20933 VFP FMA variant; NEON and VFP FMA always includes the NEON
20934 FMA instructions. */
20935 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20936 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20937 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20938 the v form should always be used. */
20939 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20940 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20941 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20942 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20943 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20944 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20945
5287ad62 20946#undef THUMB_VARIANT
c921be7d
NC
20947#undef ARM_VARIANT
20948#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20949
21d799b5
NC
20950 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20951 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20952 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20953 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20954 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20955 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20956 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20957 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20958
c921be7d
NC
20959#undef ARM_VARIANT
20960#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20961
21d799b5
NC
20962 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20963 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20964 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20965 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20966 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20967 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20968 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20969 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20970 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20971 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20972 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20973 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20974 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20975 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20976 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20977 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20978 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20979 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20980 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20981 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20982 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20983 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20984 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20985 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20986 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20987 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20988 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20989 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20990 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20991 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20992 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20993 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20994 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20995 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20996 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20997 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20998 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20999 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21000 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21001 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21002 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21003 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21004 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21005 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21006 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21007 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21008 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21009 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21010 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21011 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21012 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21013 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21014 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21015 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21016 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21017 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21018 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21019 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21020 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21021 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21022 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21023 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21024 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21025 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21026 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21027 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21028 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21029 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21030 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21031 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21032 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21033 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21034 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21035 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21036 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21037 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21038 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21039 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21040 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21041 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21042 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21043 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21044 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21045 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21046 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21047 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21048 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21049 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21050 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21051 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21052 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21053 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21054 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21055 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21056 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21057 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21058 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21059 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21060 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21061 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21062 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21063 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21064 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21065 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21066 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21067 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21068 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21069 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21070 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21071 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21072 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21073 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21074 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21075 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21076 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21077 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21078 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21079 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21080 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21081 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21082 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21083 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21084 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21085 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21086 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21087 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21088 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21089 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21090 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21091 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21092 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21093 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21094 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21095 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21096 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21097 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21098 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21099 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21100 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21101 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21102 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21103 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21104 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21105 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21106 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21107 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21108 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21109 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21110 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21111 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21112 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21113 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21114 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21115 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21116 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21117 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21118 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21119 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21120 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21121 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21122 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21123 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21124
c921be7d
NC
21125#undef ARM_VARIANT
21126#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21127
21d799b5
NC
21128 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21129 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21130 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21131 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21132 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21133 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21134 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21135 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21136 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21137 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21138 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21139 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21140 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21141 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21142 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21143 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21144 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21145 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21146 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21147 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21148 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21149 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21150 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21151 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21152 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21153 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21154 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21155 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21156 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21157 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21158 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21159 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21160 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21161 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21162 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21163 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21164 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21165 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21166 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21167 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21168 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21169 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21170 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21171 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21172 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21173 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21174 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21175 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21176 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21177 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21178 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21179 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21180 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21181 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21182 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21183 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21184 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21185
c921be7d
NC
21186#undef ARM_VARIANT
21187#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21188
21d799b5
NC
21189 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21190 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21191 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21192 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21193 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21194 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21195 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21196 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21197 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21198 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21199 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21200 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21201 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21202 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21203 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21204 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21205 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21206 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21207 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21208 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21209 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21210 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21211 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21212 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21213 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21214 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21215 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21216 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21217 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21218 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21219 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21220 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21221 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21222 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21223 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21224 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21225 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21226 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21227 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21228 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21229 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21230 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21231 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21232 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21233 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21234 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21235 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21236 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21237 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21238 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21239 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21240 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21241 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21242 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21243 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21244 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21245 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21246 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21247 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21248 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21249 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21250 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21251 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21252 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21253 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21254 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21255 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21256 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21257 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21258 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21259 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21260 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21261 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21262 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21263 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21264 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21265
16a1fa25 21266 /* ARMv8-M instructions. */
4ed7ed8d
TP
21267#undef ARM_VARIANT
21268#define ARM_VARIANT NULL
21269#undef THUMB_VARIANT
21270#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21271 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21272 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21273 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21274 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21275 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21276 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21277 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21278
21279 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21280 instructions behave as nop if no VFP is present. */
21281#undef THUMB_VARIANT
21282#define THUMB_VARIANT & arm_ext_v8m_main
21283 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21284 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21285};
21286#undef ARM_VARIANT
21287#undef THUMB_VARIANT
21288#undef TCE
c19d1205
ZW
21289#undef TUE
21290#undef TUF
21291#undef TCC
8f06b2d8 21292#undef cCE
e3cb604e
PB
21293#undef cCL
21294#undef C3E
c19d1205
ZW
21295#undef CE
21296#undef CM
21297#undef UE
21298#undef UF
21299#undef UT
5287ad62
JB
21300#undef NUF
21301#undef nUF
21302#undef NCE
21303#undef nCE
c19d1205
ZW
21304#undef OPS0
21305#undef OPS1
21306#undef OPS2
21307#undef OPS3
21308#undef OPS4
21309#undef OPS5
21310#undef OPS6
21311#undef do_0
21312\f
21313/* MD interface: bits in the object file. */
bfae80f2 21314
c19d1205
ZW
21315/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21316 for use in the a.out file, and stores them in the array pointed to by buf.
21317 This knows about the endian-ness of the target machine and does
21318 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21319 2 (short) and 4 (long) Floating numbers are put out as a series of
21320 LITTLENUMS (shorts, here at least). */
b99bd4ef 21321
c19d1205
ZW
21322void
21323md_number_to_chars (char * buf, valueT val, int n)
21324{
21325 if (target_big_endian)
21326 number_to_chars_bigendian (buf, val, n);
21327 else
21328 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21329}
21330
c19d1205
ZW
21331static valueT
21332md_chars_to_number (char * buf, int n)
bfae80f2 21333{
c19d1205
ZW
21334 valueT result = 0;
21335 unsigned char * where = (unsigned char *) buf;
bfae80f2 21336
c19d1205 21337 if (target_big_endian)
b99bd4ef 21338 {
c19d1205
ZW
21339 while (n--)
21340 {
21341 result <<= 8;
21342 result |= (*where++ & 255);
21343 }
b99bd4ef 21344 }
c19d1205 21345 else
b99bd4ef 21346 {
c19d1205
ZW
21347 while (n--)
21348 {
21349 result <<= 8;
21350 result |= (where[n] & 255);
21351 }
bfae80f2 21352 }
b99bd4ef 21353
c19d1205 21354 return result;
bfae80f2 21355}
b99bd4ef 21356
c19d1205 21357/* MD interface: Sections. */
b99bd4ef 21358
fa94de6b
RM
21359/* Calculate the maximum variable size (i.e., excluding fr_fix)
21360 that an rs_machine_dependent frag may reach. */
21361
21362unsigned int
21363arm_frag_max_var (fragS *fragp)
21364{
21365 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21366 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21367
21368 Note that we generate relaxable instructions even for cases that don't
21369 really need it, like an immediate that's a trivial constant. So we're
21370 overestimating the instruction size for some of those cases. Rather
21371 than putting more intelligence here, it would probably be better to
21372 avoid generating a relaxation frag in the first place when it can be
21373 determined up front that a short instruction will suffice. */
21374
21375 gas_assert (fragp->fr_type == rs_machine_dependent);
21376 return INSN_SIZE;
21377}
21378
0110f2b8
PB
21379/* Estimate the size of a frag before relaxing. Assume everything fits in
21380 2 bytes. */
21381
c19d1205 21382int
0110f2b8 21383md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21384 segT segtype ATTRIBUTE_UNUSED)
21385{
0110f2b8
PB
21386 fragp->fr_var = 2;
21387 return 2;
21388}
21389
21390/* Convert a machine dependent frag. */
21391
21392void
21393md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21394{
21395 unsigned long insn;
21396 unsigned long old_op;
21397 char *buf;
21398 expressionS exp;
21399 fixS *fixp;
21400 int reloc_type;
21401 int pc_rel;
21402 int opcode;
21403
21404 buf = fragp->fr_literal + fragp->fr_fix;
21405
21406 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21407 if (fragp->fr_symbol)
21408 {
0110f2b8
PB
21409 exp.X_op = O_symbol;
21410 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21411 }
21412 else
21413 {
0110f2b8 21414 exp.X_op = O_constant;
5f4273c7 21415 }
0110f2b8
PB
21416 exp.X_add_number = fragp->fr_offset;
21417 opcode = fragp->fr_subtype;
21418 switch (opcode)
21419 {
21420 case T_MNEM_ldr_pc:
21421 case T_MNEM_ldr_pc2:
21422 case T_MNEM_ldr_sp:
21423 case T_MNEM_str_sp:
21424 case T_MNEM_ldr:
21425 case T_MNEM_ldrb:
21426 case T_MNEM_ldrh:
21427 case T_MNEM_str:
21428 case T_MNEM_strb:
21429 case T_MNEM_strh:
21430 if (fragp->fr_var == 4)
21431 {
5f4273c7 21432 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21433 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21434 {
21435 insn |= (old_op & 0x700) << 4;
21436 }
21437 else
21438 {
21439 insn |= (old_op & 7) << 12;
21440 insn |= (old_op & 0x38) << 13;
21441 }
21442 insn |= 0x00000c00;
21443 put_thumb32_insn (buf, insn);
21444 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21445 }
21446 else
21447 {
21448 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21449 }
21450 pc_rel = (opcode == T_MNEM_ldr_pc2);
21451 break;
21452 case T_MNEM_adr:
21453 if (fragp->fr_var == 4)
21454 {
21455 insn = THUMB_OP32 (opcode);
21456 insn |= (old_op & 0xf0) << 4;
21457 put_thumb32_insn (buf, insn);
21458 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21459 }
21460 else
21461 {
21462 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21463 exp.X_add_number -= 4;
21464 }
21465 pc_rel = 1;
21466 break;
21467 case T_MNEM_mov:
21468 case T_MNEM_movs:
21469 case T_MNEM_cmp:
21470 case T_MNEM_cmn:
21471 if (fragp->fr_var == 4)
21472 {
21473 int r0off = (opcode == T_MNEM_mov
21474 || opcode == T_MNEM_movs) ? 0 : 8;
21475 insn = THUMB_OP32 (opcode);
21476 insn = (insn & 0xe1ffffff) | 0x10000000;
21477 insn |= (old_op & 0x700) << r0off;
21478 put_thumb32_insn (buf, insn);
21479 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21480 }
21481 else
21482 {
21483 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21484 }
21485 pc_rel = 0;
21486 break;
21487 case T_MNEM_b:
21488 if (fragp->fr_var == 4)
21489 {
21490 insn = THUMB_OP32(opcode);
21491 put_thumb32_insn (buf, insn);
21492 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21493 }
21494 else
21495 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21496 pc_rel = 1;
21497 break;
21498 case T_MNEM_bcond:
21499 if (fragp->fr_var == 4)
21500 {
21501 insn = THUMB_OP32(opcode);
21502 insn |= (old_op & 0xf00) << 14;
21503 put_thumb32_insn (buf, insn);
21504 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21505 }
21506 else
21507 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21508 pc_rel = 1;
21509 break;
21510 case T_MNEM_add_sp:
21511 case T_MNEM_add_pc:
21512 case T_MNEM_inc_sp:
21513 case T_MNEM_dec_sp:
21514 if (fragp->fr_var == 4)
21515 {
21516 /* ??? Choose between add and addw. */
21517 insn = THUMB_OP32 (opcode);
21518 insn |= (old_op & 0xf0) << 4;
21519 put_thumb32_insn (buf, insn);
16805f35
PB
21520 if (opcode == T_MNEM_add_pc)
21521 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21522 else
21523 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21524 }
21525 else
21526 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21527 pc_rel = 0;
21528 break;
21529
21530 case T_MNEM_addi:
21531 case T_MNEM_addis:
21532 case T_MNEM_subi:
21533 case T_MNEM_subis:
21534 if (fragp->fr_var == 4)
21535 {
21536 insn = THUMB_OP32 (opcode);
21537 insn |= (old_op & 0xf0) << 4;
21538 insn |= (old_op & 0xf) << 16;
21539 put_thumb32_insn (buf, insn);
16805f35
PB
21540 if (insn & (1 << 20))
21541 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21542 else
21543 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21544 }
21545 else
21546 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21547 pc_rel = 0;
21548 break;
21549 default:
5f4273c7 21550 abort ();
0110f2b8
PB
21551 }
21552 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21553 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21554 fixp->fx_file = fragp->fr_file;
21555 fixp->fx_line = fragp->fr_line;
21556 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21557
21558 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21559 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21560 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21561 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21562}
21563
21564/* Return the size of a relaxable immediate operand instruction.
21565 SHIFT and SIZE specify the form of the allowable immediate. */
21566static int
21567relax_immediate (fragS *fragp, int size, int shift)
21568{
21569 offsetT offset;
21570 offsetT mask;
21571 offsetT low;
21572
21573 /* ??? Should be able to do better than this. */
21574 if (fragp->fr_symbol)
21575 return 4;
21576
21577 low = (1 << shift) - 1;
21578 mask = (1 << (shift + size)) - (1 << shift);
21579 offset = fragp->fr_offset;
21580 /* Force misaligned offsets to 32-bit variant. */
21581 if (offset & low)
5e77afaa 21582 return 4;
0110f2b8
PB
21583 if (offset & ~mask)
21584 return 4;
21585 return 2;
21586}
21587
5e77afaa
PB
21588/* Get the address of a symbol during relaxation. */
21589static addressT
5f4273c7 21590relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21591{
21592 fragS *sym_frag;
21593 addressT addr;
21594 symbolS *sym;
21595
21596 sym = fragp->fr_symbol;
21597 sym_frag = symbol_get_frag (sym);
21598 know (S_GET_SEGMENT (sym) != absolute_section
21599 || sym_frag == &zero_address_frag);
21600 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21601
21602 /* If frag has yet to be reached on this pass, assume it will
21603 move by STRETCH just as we did. If this is not so, it will
21604 be because some frag between grows, and that will force
21605 another pass. */
21606
21607 if (stretch != 0
21608 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21609 {
21610 fragS *f;
21611
21612 /* Adjust stretch for any alignment frag. Note that if have
21613 been expanding the earlier code, the symbol may be
21614 defined in what appears to be an earlier frag. FIXME:
21615 This doesn't handle the fr_subtype field, which specifies
21616 a maximum number of bytes to skip when doing an
21617 alignment. */
21618 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21619 {
21620 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21621 {
21622 if (stretch < 0)
21623 stretch = - ((- stretch)
21624 & ~ ((1 << (int) f->fr_offset) - 1));
21625 else
21626 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21627 if (stretch == 0)
21628 break;
21629 }
21630 }
21631 if (f != NULL)
21632 addr += stretch;
21633 }
5e77afaa
PB
21634
21635 return addr;
21636}
21637
0110f2b8
PB
21638/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21639 load. */
21640static int
5e77afaa 21641relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21642{
21643 addressT addr;
21644 offsetT val;
21645
21646 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21647 if (fragp->fr_symbol == NULL
21648 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21649 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21650 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21651 return 4;
21652
5f4273c7 21653 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21654 addr = fragp->fr_address + fragp->fr_fix;
21655 addr = (addr + 4) & ~3;
5e77afaa 21656 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21657 if (val & 3)
5e77afaa 21658 return 4;
0110f2b8
PB
21659 val -= addr;
21660 if (val < 0 || val > 1020)
21661 return 4;
21662 return 2;
21663}
21664
21665/* Return the size of a relaxable add/sub immediate instruction. */
21666static int
21667relax_addsub (fragS *fragp, asection *sec)
21668{
21669 char *buf;
21670 int op;
21671
21672 buf = fragp->fr_literal + fragp->fr_fix;
21673 op = bfd_get_16(sec->owner, buf);
21674 if ((op & 0xf) == ((op >> 4) & 0xf))
21675 return relax_immediate (fragp, 8, 0);
21676 else
21677 return relax_immediate (fragp, 3, 0);
21678}
21679
e83a675f
RE
21680/* Return TRUE iff the definition of symbol S could be pre-empted
21681 (overridden) at link or load time. */
21682static bfd_boolean
21683symbol_preemptible (symbolS *s)
21684{
21685 /* Weak symbols can always be pre-empted. */
21686 if (S_IS_WEAK (s))
21687 return TRUE;
21688
21689 /* Non-global symbols cannot be pre-empted. */
21690 if (! S_IS_EXTERNAL (s))
21691 return FALSE;
21692
21693#ifdef OBJ_ELF
21694 /* In ELF, a global symbol can be marked protected, or private. In that
21695 case it can't be pre-empted (other definitions in the same link unit
21696 would violate the ODR). */
21697 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21698 return FALSE;
21699#endif
21700
21701 /* Other global symbols might be pre-empted. */
21702 return TRUE;
21703}
0110f2b8
PB
21704
21705/* Return the size of a relaxable branch instruction. BITS is the
21706 size of the offset field in the narrow instruction. */
21707
21708static int
5e77afaa 21709relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21710{
21711 addressT addr;
21712 offsetT val;
21713 offsetT limit;
21714
21715 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21716 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21717 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21718 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21719 return 4;
21720
267bf995 21721#ifdef OBJ_ELF
e83a675f 21722 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21723 if (S_IS_DEFINED (fragp->fr_symbol)
21724 && ARM_IS_FUNC (fragp->fr_symbol))
21725 return 4;
e83a675f 21726#endif
0d9b4b55 21727
e83a675f 21728 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21729 return 4;
267bf995 21730
5f4273c7 21731 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21732 addr = fragp->fr_address + fragp->fr_fix + 4;
21733 val -= addr;
21734
21735 /* Offset is a signed value *2 */
21736 limit = 1 << bits;
21737 if (val >= limit || val < -limit)
21738 return 4;
21739 return 2;
21740}
21741
21742
21743/* Relax a machine dependent frag. This returns the amount by which
21744 the current size of the frag should change. */
21745
21746int
5e77afaa 21747arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21748{
21749 int oldsize;
21750 int newsize;
21751
21752 oldsize = fragp->fr_var;
21753 switch (fragp->fr_subtype)
21754 {
21755 case T_MNEM_ldr_pc2:
5f4273c7 21756 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21757 break;
21758 case T_MNEM_ldr_pc:
21759 case T_MNEM_ldr_sp:
21760 case T_MNEM_str_sp:
5f4273c7 21761 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21762 break;
21763 case T_MNEM_ldr:
21764 case T_MNEM_str:
5f4273c7 21765 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21766 break;
21767 case T_MNEM_ldrh:
21768 case T_MNEM_strh:
5f4273c7 21769 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21770 break;
21771 case T_MNEM_ldrb:
21772 case T_MNEM_strb:
5f4273c7 21773 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21774 break;
21775 case T_MNEM_adr:
5f4273c7 21776 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21777 break;
21778 case T_MNEM_mov:
21779 case T_MNEM_movs:
21780 case T_MNEM_cmp:
21781 case T_MNEM_cmn:
5f4273c7 21782 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21783 break;
21784 case T_MNEM_b:
5f4273c7 21785 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21786 break;
21787 case T_MNEM_bcond:
5f4273c7 21788 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21789 break;
21790 case T_MNEM_add_sp:
21791 case T_MNEM_add_pc:
21792 newsize = relax_immediate (fragp, 8, 2);
21793 break;
21794 case T_MNEM_inc_sp:
21795 case T_MNEM_dec_sp:
21796 newsize = relax_immediate (fragp, 7, 2);
21797 break;
21798 case T_MNEM_addi:
21799 case T_MNEM_addis:
21800 case T_MNEM_subi:
21801 case T_MNEM_subis:
21802 newsize = relax_addsub (fragp, sec);
21803 break;
21804 default:
5f4273c7 21805 abort ();
0110f2b8 21806 }
5e77afaa
PB
21807
21808 fragp->fr_var = newsize;
21809 /* Freeze wide instructions that are at or before the same location as
21810 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21811 Don't freeze them unconditionally because targets may be artificially
21812 misaligned by the expansion of preceding frags. */
5e77afaa 21813 if (stretch <= 0 && newsize > 2)
0110f2b8 21814 {
0110f2b8 21815 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21816 frag_wane (fragp);
0110f2b8 21817 }
5e77afaa 21818
0110f2b8 21819 return newsize - oldsize;
c19d1205 21820}
b99bd4ef 21821
c19d1205 21822/* Round up a section size to the appropriate boundary. */
b99bd4ef 21823
c19d1205
ZW
21824valueT
21825md_section_align (segT segment ATTRIBUTE_UNUSED,
21826 valueT size)
21827{
f0927246
NC
21828#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21829 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21830 {
21831 /* For a.out, force the section size to be aligned. If we don't do
21832 this, BFD will align it for us, but it will not write out the
21833 final bytes of the section. This may be a bug in BFD, but it is
21834 easier to fix it here since that is how the other a.out targets
21835 work. */
21836 int align;
21837
21838 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21839 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21840 }
c19d1205 21841#endif
f0927246 21842
6844c0cc 21843 return size;
bfae80f2 21844}
b99bd4ef 21845
c19d1205
ZW
21846/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21847 of an rs_align_code fragment. */
21848
21849void
21850arm_handle_align (fragS * fragP)
bfae80f2 21851{
d9235011 21852 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21853 {
21854 { /* ARMv1 */
21855 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21856 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21857 },
21858 { /* ARMv6k */
21859 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21860 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21861 },
21862 };
d9235011 21863 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21864 {
21865 { /* Thumb-1 */
21866 {0xc0, 0x46}, /* LE */
21867 {0x46, 0xc0}, /* BE */
21868 },
21869 { /* Thumb-2 */
21870 {0x00, 0xbf}, /* LE */
21871 {0xbf, 0x00} /* BE */
21872 }
21873 };
d9235011 21874 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21875 { /* Wide Thumb-2 */
21876 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21877 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21878 };
c921be7d 21879
e7495e45 21880 unsigned bytes, fix, noop_size;
c19d1205 21881 char * p;
d9235011
TS
21882 const unsigned char * noop;
21883 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21884#ifdef OBJ_ELF
21885 enum mstate state;
21886#endif
bfae80f2 21887
c19d1205 21888 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21889 return;
21890
c19d1205
ZW
21891 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21892 p = fragP->fr_literal + fragP->fr_fix;
21893 fix = 0;
bfae80f2 21894
c19d1205
ZW
21895 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21896 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21897
cd000bff 21898 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21899
cd000bff 21900 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21901 {
7f78eb34
JW
21902 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21903 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21904 {
21905 narrow_noop = thumb_noop[1][target_big_endian];
21906 noop = wide_thumb_noop[target_big_endian];
21907 }
c19d1205 21908 else
e7495e45
NS
21909 noop = thumb_noop[0][target_big_endian];
21910 noop_size = 2;
cd000bff
DJ
21911#ifdef OBJ_ELF
21912 state = MAP_THUMB;
21913#endif
7ed4c4c5
NC
21914 }
21915 else
21916 {
7f78eb34
JW
21917 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21918 ? selected_cpu : arm_arch_none,
21919 arm_ext_v6k) != 0]
e7495e45
NS
21920 [target_big_endian];
21921 noop_size = 4;
cd000bff
DJ
21922#ifdef OBJ_ELF
21923 state = MAP_ARM;
21924#endif
7ed4c4c5 21925 }
c921be7d 21926
e7495e45 21927 fragP->fr_var = noop_size;
c921be7d 21928
c19d1205 21929 if (bytes & (noop_size - 1))
7ed4c4c5 21930 {
c19d1205 21931 fix = bytes & (noop_size - 1);
cd000bff
DJ
21932#ifdef OBJ_ELF
21933 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21934#endif
c19d1205
ZW
21935 memset (p, 0, fix);
21936 p += fix;
21937 bytes -= fix;
a737bd4d 21938 }
a737bd4d 21939
e7495e45
NS
21940 if (narrow_noop)
21941 {
21942 if (bytes & noop_size)
21943 {
21944 /* Insert a narrow noop. */
21945 memcpy (p, narrow_noop, noop_size);
21946 p += noop_size;
21947 bytes -= noop_size;
21948 fix += noop_size;
21949 }
21950
21951 /* Use wide noops for the remainder */
21952 noop_size = 4;
21953 }
21954
c19d1205 21955 while (bytes >= noop_size)
a737bd4d 21956 {
c19d1205
ZW
21957 memcpy (p, noop, noop_size);
21958 p += noop_size;
21959 bytes -= noop_size;
21960 fix += noop_size;
a737bd4d
NC
21961 }
21962
c19d1205 21963 fragP->fr_fix += fix;
a737bd4d
NC
21964}
21965
c19d1205
ZW
21966/* Called from md_do_align. Used to create an alignment
21967 frag in a code section. */
21968
21969void
21970arm_frag_align_code (int n, int max)
bfae80f2 21971{
c19d1205 21972 char * p;
7ed4c4c5 21973
c19d1205 21974 /* We assume that there will never be a requirement
6ec8e702 21975 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21976 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21977 {
21978 char err_msg[128];
21979
fa94de6b 21980 sprintf (err_msg,
477330fc
RM
21981 _("alignments greater than %d bytes not supported in .text sections."),
21982 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21983 as_fatal ("%s", err_msg);
6ec8e702 21984 }
bfae80f2 21985
c19d1205
ZW
21986 p = frag_var (rs_align_code,
21987 MAX_MEM_FOR_RS_ALIGN_CODE,
21988 1,
21989 (relax_substateT) max,
21990 (symbolS *) NULL,
21991 (offsetT) n,
21992 (char *) NULL);
21993 *p = 0;
21994}
bfae80f2 21995
8dc2430f
NC
21996/* Perform target specific initialisation of a frag.
21997 Note - despite the name this initialisation is not done when the frag
21998 is created, but only when its type is assigned. A frag can be created
21999 and used a long time before its type is set, so beware of assuming that
33eaf5de 22000 this initialisation is performed first. */
bfae80f2 22001
cd000bff
DJ
22002#ifndef OBJ_ELF
22003void
22004arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22005{
22006 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22007 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22008}
22009
22010#else /* OBJ_ELF is defined. */
c19d1205 22011void
cd000bff 22012arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22013{
e8d84ca1 22014 bfd_boolean frag_thumb_mode;
b968d18a 22015
8dc2430f
NC
22016 /* If the current ARM vs THUMB mode has not already
22017 been recorded into this frag then do so now. */
cd000bff 22018 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22019 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22020
e8d84ca1
NC
22021 /* PR 21809: Do not set a mapping state for debug sections
22022 - it just confuses other tools. */
22023 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22024 return;
22025
b968d18a 22026 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22027
f9c1b181
RL
22028 /* Record a mapping symbol for alignment frags. We will delete this
22029 later if the alignment ends up empty. */
22030 switch (fragP->fr_type)
22031 {
22032 case rs_align:
22033 case rs_align_test:
22034 case rs_fill:
22035 mapping_state_2 (MAP_DATA, max_chars);
22036 break;
22037 case rs_align_code:
b968d18a 22038 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22039 break;
22040 default:
22041 break;
cd000bff 22042 }
bfae80f2
RE
22043}
22044
c19d1205
ZW
22045/* When we change sections we need to issue a new mapping symbol. */
22046
22047void
22048arm_elf_change_section (void)
bfae80f2 22049{
c19d1205
ZW
22050 /* Link an unlinked unwind index table section to the .text section. */
22051 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22052 && elf_linked_to_section (now_seg) == NULL)
22053 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22054}
22055
c19d1205
ZW
22056int
22057arm_elf_section_type (const char * str, size_t len)
e45d0630 22058{
c19d1205
ZW
22059 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22060 return SHT_ARM_EXIDX;
e45d0630 22061
c19d1205
ZW
22062 return -1;
22063}
22064\f
22065/* Code to deal with unwinding tables. */
e45d0630 22066
c19d1205 22067static void add_unwind_adjustsp (offsetT);
e45d0630 22068
5f4273c7 22069/* Generate any deferred unwind frame offset. */
e45d0630 22070
bfae80f2 22071static void
c19d1205 22072flush_pending_unwind (void)
bfae80f2 22073{
c19d1205 22074 offsetT offset;
bfae80f2 22075
c19d1205
ZW
22076 offset = unwind.pending_offset;
22077 unwind.pending_offset = 0;
22078 if (offset != 0)
22079 add_unwind_adjustsp (offset);
bfae80f2
RE
22080}
22081
c19d1205
ZW
22082/* Add an opcode to this list for this function. Two-byte opcodes should
22083 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22084 order. */
22085
bfae80f2 22086static void
c19d1205 22087add_unwind_opcode (valueT op, int length)
bfae80f2 22088{
c19d1205
ZW
22089 /* Add any deferred stack adjustment. */
22090 if (unwind.pending_offset)
22091 flush_pending_unwind ();
bfae80f2 22092
c19d1205 22093 unwind.sp_restored = 0;
bfae80f2 22094
c19d1205 22095 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22096 {
c19d1205
ZW
22097 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22098 if (unwind.opcodes)
325801bd
TS
22099 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22100 unwind.opcode_alloc);
c19d1205 22101 else
325801bd 22102 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22103 }
c19d1205 22104 while (length > 0)
bfae80f2 22105 {
c19d1205
ZW
22106 length--;
22107 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22108 op >>= 8;
22109 unwind.opcode_count++;
bfae80f2 22110 }
bfae80f2
RE
22111}
22112
c19d1205
ZW
22113/* Add unwind opcodes to adjust the stack pointer. */
22114
bfae80f2 22115static void
c19d1205 22116add_unwind_adjustsp (offsetT offset)
bfae80f2 22117{
c19d1205 22118 valueT op;
bfae80f2 22119
c19d1205 22120 if (offset > 0x200)
bfae80f2 22121 {
c19d1205
ZW
22122 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22123 char bytes[5];
22124 int n;
22125 valueT o;
bfae80f2 22126
c19d1205
ZW
22127 /* Long form: 0xb2, uleb128. */
22128 /* This might not fit in a word so add the individual bytes,
22129 remembering the list is built in reverse order. */
22130 o = (valueT) ((offset - 0x204) >> 2);
22131 if (o == 0)
22132 add_unwind_opcode (0, 1);
bfae80f2 22133
c19d1205
ZW
22134 /* Calculate the uleb128 encoding of the offset. */
22135 n = 0;
22136 while (o)
22137 {
22138 bytes[n] = o & 0x7f;
22139 o >>= 7;
22140 if (o)
22141 bytes[n] |= 0x80;
22142 n++;
22143 }
22144 /* Add the insn. */
22145 for (; n; n--)
22146 add_unwind_opcode (bytes[n - 1], 1);
22147 add_unwind_opcode (0xb2, 1);
22148 }
22149 else if (offset > 0x100)
bfae80f2 22150 {
c19d1205
ZW
22151 /* Two short opcodes. */
22152 add_unwind_opcode (0x3f, 1);
22153 op = (offset - 0x104) >> 2;
22154 add_unwind_opcode (op, 1);
bfae80f2 22155 }
c19d1205
ZW
22156 else if (offset > 0)
22157 {
22158 /* Short opcode. */
22159 op = (offset - 4) >> 2;
22160 add_unwind_opcode (op, 1);
22161 }
22162 else if (offset < 0)
bfae80f2 22163 {
c19d1205
ZW
22164 offset = -offset;
22165 while (offset > 0x100)
bfae80f2 22166 {
c19d1205
ZW
22167 add_unwind_opcode (0x7f, 1);
22168 offset -= 0x100;
bfae80f2 22169 }
c19d1205
ZW
22170 op = ((offset - 4) >> 2) | 0x40;
22171 add_unwind_opcode (op, 1);
bfae80f2 22172 }
bfae80f2
RE
22173}
22174
c19d1205 22175/* Finish the list of unwind opcodes for this function. */
0198d5e6 22176
c19d1205
ZW
22177static void
22178finish_unwind_opcodes (void)
bfae80f2 22179{
c19d1205 22180 valueT op;
bfae80f2 22181
c19d1205 22182 if (unwind.fp_used)
bfae80f2 22183 {
708587a4 22184 /* Adjust sp as necessary. */
c19d1205
ZW
22185 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22186 flush_pending_unwind ();
bfae80f2 22187
c19d1205
ZW
22188 /* After restoring sp from the frame pointer. */
22189 op = 0x90 | unwind.fp_reg;
22190 add_unwind_opcode (op, 1);
22191 }
22192 else
22193 flush_pending_unwind ();
bfae80f2
RE
22194}
22195
bfae80f2 22196
c19d1205
ZW
22197/* Start an exception table entry. If idx is nonzero this is an index table
22198 entry. */
bfae80f2
RE
22199
22200static void
c19d1205 22201start_unwind_section (const segT text_seg, int idx)
bfae80f2 22202{
c19d1205
ZW
22203 const char * text_name;
22204 const char * prefix;
22205 const char * prefix_once;
22206 const char * group_name;
c19d1205 22207 char * sec_name;
c19d1205
ZW
22208 int type;
22209 int flags;
22210 int linkonce;
bfae80f2 22211
c19d1205 22212 if (idx)
bfae80f2 22213 {
c19d1205
ZW
22214 prefix = ELF_STRING_ARM_unwind;
22215 prefix_once = ELF_STRING_ARM_unwind_once;
22216 type = SHT_ARM_EXIDX;
bfae80f2 22217 }
c19d1205 22218 else
bfae80f2 22219 {
c19d1205
ZW
22220 prefix = ELF_STRING_ARM_unwind_info;
22221 prefix_once = ELF_STRING_ARM_unwind_info_once;
22222 type = SHT_PROGBITS;
bfae80f2
RE
22223 }
22224
c19d1205
ZW
22225 text_name = segment_name (text_seg);
22226 if (streq (text_name, ".text"))
22227 text_name = "";
22228
22229 if (strncmp (text_name, ".gnu.linkonce.t.",
22230 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22231 {
c19d1205
ZW
22232 prefix = prefix_once;
22233 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22234 }
22235
29a2809e 22236 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22237
c19d1205
ZW
22238 flags = SHF_ALLOC;
22239 linkonce = 0;
22240 group_name = 0;
bfae80f2 22241
c19d1205
ZW
22242 /* Handle COMDAT group. */
22243 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22244 {
c19d1205
ZW
22245 group_name = elf_group_name (text_seg);
22246 if (group_name == NULL)
22247 {
bd3ba5d1 22248 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22249 segment_name (text_seg));
22250 ignore_rest_of_line ();
22251 return;
22252 }
22253 flags |= SHF_GROUP;
22254 linkonce = 1;
bfae80f2
RE
22255 }
22256
a91e1603
L
22257 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22258 linkonce, 0);
bfae80f2 22259
5f4273c7 22260 /* Set the section link for index tables. */
c19d1205
ZW
22261 if (idx)
22262 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22263}
22264
bfae80f2 22265
c19d1205
ZW
22266/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22267 personality routine data. Returns zero, or the index table value for
cad0da33 22268 an inline entry. */
c19d1205
ZW
22269
22270static valueT
22271create_unwind_entry (int have_data)
bfae80f2 22272{
c19d1205
ZW
22273 int size;
22274 addressT where;
22275 char *ptr;
22276 /* The current word of data. */
22277 valueT data;
22278 /* The number of bytes left in this word. */
22279 int n;
bfae80f2 22280
c19d1205 22281 finish_unwind_opcodes ();
bfae80f2 22282
c19d1205
ZW
22283 /* Remember the current text section. */
22284 unwind.saved_seg = now_seg;
22285 unwind.saved_subseg = now_subseg;
bfae80f2 22286
c19d1205 22287 start_unwind_section (now_seg, 0);
bfae80f2 22288
c19d1205 22289 if (unwind.personality_routine == NULL)
bfae80f2 22290 {
c19d1205
ZW
22291 if (unwind.personality_index == -2)
22292 {
22293 if (have_data)
5f4273c7 22294 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22295 return 1; /* EXIDX_CANTUNWIND. */
22296 }
bfae80f2 22297
c19d1205
ZW
22298 /* Use a default personality routine if none is specified. */
22299 if (unwind.personality_index == -1)
22300 {
22301 if (unwind.opcode_count > 3)
22302 unwind.personality_index = 1;
22303 else
22304 unwind.personality_index = 0;
22305 }
bfae80f2 22306
c19d1205
ZW
22307 /* Space for the personality routine entry. */
22308 if (unwind.personality_index == 0)
22309 {
22310 if (unwind.opcode_count > 3)
22311 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22312
c19d1205
ZW
22313 if (!have_data)
22314 {
22315 /* All the data is inline in the index table. */
22316 data = 0x80;
22317 n = 3;
22318 while (unwind.opcode_count > 0)
22319 {
22320 unwind.opcode_count--;
22321 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22322 n--;
22323 }
bfae80f2 22324
c19d1205
ZW
22325 /* Pad with "finish" opcodes. */
22326 while (n--)
22327 data = (data << 8) | 0xb0;
bfae80f2 22328
c19d1205
ZW
22329 return data;
22330 }
22331 size = 0;
22332 }
22333 else
22334 /* We get two opcodes "free" in the first word. */
22335 size = unwind.opcode_count - 2;
22336 }
22337 else
5011093d 22338 {
cad0da33
NC
22339 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22340 if (unwind.personality_index != -1)
22341 {
22342 as_bad (_("attempt to recreate an unwind entry"));
22343 return 1;
22344 }
5011093d
NC
22345
22346 /* An extra byte is required for the opcode count. */
22347 size = unwind.opcode_count + 1;
22348 }
bfae80f2 22349
c19d1205
ZW
22350 size = (size + 3) >> 2;
22351 if (size > 0xff)
22352 as_bad (_("too many unwind opcodes"));
bfae80f2 22353
c19d1205
ZW
22354 frag_align (2, 0, 0);
22355 record_alignment (now_seg, 2);
22356 unwind.table_entry = expr_build_dot ();
22357
22358 /* Allocate the table entry. */
22359 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22360 /* PR 13449: Zero the table entries in case some of them are not used. */
22361 memset (ptr, 0, (size << 2) + 4);
c19d1205 22362 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22363
c19d1205 22364 switch (unwind.personality_index)
bfae80f2 22365 {
c19d1205
ZW
22366 case -1:
22367 /* ??? Should this be a PLT generating relocation? */
22368 /* Custom personality routine. */
22369 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22370 BFD_RELOC_ARM_PREL31);
bfae80f2 22371
c19d1205
ZW
22372 where += 4;
22373 ptr += 4;
bfae80f2 22374
c19d1205 22375 /* Set the first byte to the number of additional words. */
5011093d 22376 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22377 n = 3;
22378 break;
bfae80f2 22379
c19d1205
ZW
22380 /* ABI defined personality routines. */
22381 case 0:
22382 /* Three opcodes bytes are packed into the first word. */
22383 data = 0x80;
22384 n = 3;
22385 break;
bfae80f2 22386
c19d1205
ZW
22387 case 1:
22388 case 2:
22389 /* The size and first two opcode bytes go in the first word. */
22390 data = ((0x80 + unwind.personality_index) << 8) | size;
22391 n = 2;
22392 break;
bfae80f2 22393
c19d1205
ZW
22394 default:
22395 /* Should never happen. */
22396 abort ();
22397 }
bfae80f2 22398
c19d1205
ZW
22399 /* Pack the opcodes into words (MSB first), reversing the list at the same
22400 time. */
22401 while (unwind.opcode_count > 0)
22402 {
22403 if (n == 0)
22404 {
22405 md_number_to_chars (ptr, data, 4);
22406 ptr += 4;
22407 n = 4;
22408 data = 0;
22409 }
22410 unwind.opcode_count--;
22411 n--;
22412 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22413 }
22414
22415 /* Finish off the last word. */
22416 if (n < 4)
22417 {
22418 /* Pad with "finish" opcodes. */
22419 while (n--)
22420 data = (data << 8) | 0xb0;
22421
22422 md_number_to_chars (ptr, data, 4);
22423 }
22424
22425 if (!have_data)
22426 {
22427 /* Add an empty descriptor if there is no user-specified data. */
22428 ptr = frag_more (4);
22429 md_number_to_chars (ptr, 0, 4);
22430 }
22431
22432 return 0;
bfae80f2
RE
22433}
22434
f0927246
NC
22435
22436/* Initialize the DWARF-2 unwind information for this procedure. */
22437
22438void
22439tc_arm_frame_initial_instructions (void)
22440{
22441 cfi_add_CFA_def_cfa (REG_SP, 0);
22442}
22443#endif /* OBJ_ELF */
22444
c19d1205
ZW
22445/* Convert REGNAME to a DWARF-2 register number. */
22446
22447int
1df69f4f 22448tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22449{
1df69f4f 22450 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22451 if (reg != FAIL)
22452 return reg;
c19d1205 22453
1f5afe1c
NC
22454 /* PR 16694: Allow VFP registers as well. */
22455 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22456 if (reg != FAIL)
22457 return 64 + reg;
c19d1205 22458
1f5afe1c
NC
22459 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22460 if (reg != FAIL)
22461 return reg + 256;
22462
0198d5e6 22463 return FAIL;
bfae80f2
RE
22464}
22465
f0927246 22466#ifdef TE_PE
c19d1205 22467void
f0927246 22468tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22469{
91d6fa6a 22470 expressionS exp;
bfae80f2 22471
91d6fa6a
NC
22472 exp.X_op = O_secrel;
22473 exp.X_add_symbol = symbol;
22474 exp.X_add_number = 0;
22475 emit_expr (&exp, size);
f0927246
NC
22476}
22477#endif
bfae80f2 22478
c19d1205 22479/* MD interface: Symbol and relocation handling. */
bfae80f2 22480
2fc8bdac
ZW
22481/* Return the address within the segment that a PC-relative fixup is
22482 relative to. For ARM, PC-relative fixups applied to instructions
22483 are generally relative to the location of the fixup plus 8 bytes.
22484 Thumb branches are offset by 4, and Thumb loads relative to PC
22485 require special handling. */
bfae80f2 22486
c19d1205 22487long
2fc8bdac 22488md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22489{
2fc8bdac
ZW
22490 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22491
22492 /* If this is pc-relative and we are going to emit a relocation
22493 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22494 will need. Otherwise we want to use the calculated base.
22495 For WinCE we skip the bias for externals as well, since this
22496 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22497 if (fixP->fx_pcrel
2fc8bdac 22498 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22499 || (arm_force_relocation (fixP)
22500#ifdef TE_WINCE
22501 && !S_IS_EXTERNAL (fixP->fx_addsy)
22502#endif
22503 )))
2fc8bdac 22504 base = 0;
bfae80f2 22505
267bf995 22506
c19d1205 22507 switch (fixP->fx_r_type)
bfae80f2 22508 {
2fc8bdac
ZW
22509 /* PC relative addressing on the Thumb is slightly odd as the
22510 bottom two bits of the PC are forced to zero for the
22511 calculation. This happens *after* application of the
22512 pipeline offset. However, Thumb adrl already adjusts for
22513 this, so we need not do it again. */
c19d1205 22514 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22515 return base & ~3;
c19d1205
ZW
22516
22517 case BFD_RELOC_ARM_THUMB_OFFSET:
22518 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22519 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22520 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22521 return (base + 4) & ~3;
c19d1205 22522
2fc8bdac
ZW
22523 /* Thumb branches are simply offset by +4. */
22524 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22525 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22526 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22527 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22528 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22529 return base + 4;
bfae80f2 22530
267bf995 22531 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22532 if (fixP->fx_addsy
22533 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22534 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22535 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22536 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22537 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22538 return base + 4;
22539
00adf2d4
JB
22540 /* BLX is like branches above, but forces the low two bits of PC to
22541 zero. */
486499d0
CL
22542 case BFD_RELOC_THUMB_PCREL_BLX:
22543 if (fixP->fx_addsy
22544 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22545 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22546 && THUMB_IS_FUNC (fixP->fx_addsy)
22547 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22548 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22549 return (base + 4) & ~3;
22550
2fc8bdac
ZW
22551 /* ARM mode branches are offset by +8. However, the Windows CE
22552 loader expects the relocation not to take this into account. */
267bf995 22553 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
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 && ARM_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
486499d0
CL
22562 case BFD_RELOC_ARM_PCREL_CALL:
22563 if (fixP->fx_addsy
22564 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22565 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22566 && THUMB_IS_FUNC (fixP->fx_addsy)
22567 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22568 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22569 return base + 8;
267bf995 22570
2fc8bdac 22571 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22572 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22573 case BFD_RELOC_ARM_PLT32:
c19d1205 22574#ifdef TE_WINCE
5f4273c7 22575 /* When handling fixups immediately, because we have already
477330fc 22576 discovered the value of a symbol, or the address of the frag involved
53baae48 22577 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22578 see fixup_segment() in write.c
22579 The S_IS_EXTERNAL test handles the case of global symbols.
22580 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22581 if (fixP->fx_pcrel
22582 && fixP->fx_addsy != NULL
22583 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22584 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22585 return base + 8;
2fc8bdac 22586 return base;
c19d1205 22587#else
2fc8bdac 22588 return base + 8;
c19d1205 22589#endif
2fc8bdac 22590
267bf995 22591
2fc8bdac
ZW
22592 /* ARM mode loads relative to PC are also offset by +8. Unlike
22593 branches, the Windows CE loader *does* expect the relocation
22594 to take this into account. */
22595 case BFD_RELOC_ARM_OFFSET_IMM:
22596 case BFD_RELOC_ARM_OFFSET_IMM8:
22597 case BFD_RELOC_ARM_HWLITERAL:
22598 case BFD_RELOC_ARM_LITERAL:
22599 case BFD_RELOC_ARM_CP_OFF_IMM:
22600 return base + 8;
22601
22602
22603 /* Other PC-relative relocations are un-offset. */
22604 default:
22605 return base;
22606 }
bfae80f2
RE
22607}
22608
8b2d793c
NC
22609static bfd_boolean flag_warn_syms = TRUE;
22610
ae8714c2
NC
22611bfd_boolean
22612arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22613{
8b2d793c
NC
22614 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22615 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22616 does mean that the resulting code might be very confusing to the reader.
22617 Also this warning can be triggered if the user omits an operand before
22618 an immediate address, eg:
22619
22620 LDR =foo
22621
22622 GAS treats this as an assignment of the value of the symbol foo to a
22623 symbol LDR, and so (without this code) it will not issue any kind of
22624 warning or error message.
22625
22626 Note - ARM instructions are case-insensitive but the strings in the hash
22627 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22628 lower case too. */
22629 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22630 {
22631 char * nbuf = strdup (name);
22632 char * p;
22633
22634 for (p = nbuf; *p; p++)
22635 *p = TOLOWER (*p);
22636 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22637 {
22638 static struct hash_control * already_warned = NULL;
22639
22640 if (already_warned == NULL)
22641 already_warned = hash_new ();
22642 /* Only warn about the symbol once. To keep the code
22643 simple we let hash_insert do the lookup for us. */
22644 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22645 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22646 }
22647 else
22648 free (nbuf);
22649 }
3739860c 22650
ae8714c2
NC
22651 return FALSE;
22652}
22653
22654/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22655 Otherwise we have no need to default values of symbols. */
22656
22657symbolS *
22658md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22659{
22660#ifdef OBJ_ELF
22661 if (name[0] == '_' && name[1] == 'G'
22662 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22663 {
22664 if (!GOT_symbol)
22665 {
22666 if (symbol_find (name))
22667 as_bad (_("GOT already in the symbol table"));
22668
22669 GOT_symbol = symbol_new (name, undefined_section,
22670 (valueT) 0, & zero_address_frag);
22671 }
22672
22673 return GOT_symbol;
22674 }
22675#endif
22676
c921be7d 22677 return NULL;
bfae80f2
RE
22678}
22679
55cf6793 22680/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22681 computed as two separate immediate values, added together. We
22682 already know that this value cannot be computed by just one ARM
22683 instruction. */
22684
22685static unsigned int
22686validate_immediate_twopart (unsigned int val,
22687 unsigned int * highpart)
bfae80f2 22688{
c19d1205
ZW
22689 unsigned int a;
22690 unsigned int i;
bfae80f2 22691
c19d1205
ZW
22692 for (i = 0; i < 32; i += 2)
22693 if (((a = rotate_left (val, i)) & 0xff) != 0)
22694 {
22695 if (a & 0xff00)
22696 {
22697 if (a & ~ 0xffff)
22698 continue;
22699 * highpart = (a >> 8) | ((i + 24) << 7);
22700 }
22701 else if (a & 0xff0000)
22702 {
22703 if (a & 0xff000000)
22704 continue;
22705 * highpart = (a >> 16) | ((i + 16) << 7);
22706 }
22707 else
22708 {
9c2799c2 22709 gas_assert (a & 0xff000000);
c19d1205
ZW
22710 * highpart = (a >> 24) | ((i + 8) << 7);
22711 }
bfae80f2 22712
c19d1205
ZW
22713 return (a & 0xff) | (i << 7);
22714 }
bfae80f2 22715
c19d1205 22716 return FAIL;
bfae80f2
RE
22717}
22718
c19d1205
ZW
22719static int
22720validate_offset_imm (unsigned int val, int hwse)
22721{
22722 if ((hwse && val > 255) || val > 4095)
22723 return FAIL;
22724 return val;
22725}
bfae80f2 22726
55cf6793 22727/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22728 negative immediate constant by altering the instruction. A bit of
22729 a hack really.
22730 MOV <-> MVN
22731 AND <-> BIC
22732 ADC <-> SBC
22733 by inverting the second operand, and
22734 ADD <-> SUB
22735 CMP <-> CMN
22736 by negating the second operand. */
bfae80f2 22737
c19d1205
ZW
22738static int
22739negate_data_op (unsigned long * instruction,
22740 unsigned long value)
bfae80f2 22741{
c19d1205
ZW
22742 int op, new_inst;
22743 unsigned long negated, inverted;
bfae80f2 22744
c19d1205
ZW
22745 negated = encode_arm_immediate (-value);
22746 inverted = encode_arm_immediate (~value);
bfae80f2 22747
c19d1205
ZW
22748 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22749 switch (op)
bfae80f2 22750 {
c19d1205
ZW
22751 /* First negates. */
22752 case OPCODE_SUB: /* ADD <-> SUB */
22753 new_inst = OPCODE_ADD;
22754 value = negated;
22755 break;
bfae80f2 22756
c19d1205
ZW
22757 case OPCODE_ADD:
22758 new_inst = OPCODE_SUB;
22759 value = negated;
22760 break;
bfae80f2 22761
c19d1205
ZW
22762 case OPCODE_CMP: /* CMP <-> CMN */
22763 new_inst = OPCODE_CMN;
22764 value = negated;
22765 break;
bfae80f2 22766
c19d1205
ZW
22767 case OPCODE_CMN:
22768 new_inst = OPCODE_CMP;
22769 value = negated;
22770 break;
bfae80f2 22771
c19d1205
ZW
22772 /* Now Inverted ops. */
22773 case OPCODE_MOV: /* MOV <-> MVN */
22774 new_inst = OPCODE_MVN;
22775 value = inverted;
22776 break;
bfae80f2 22777
c19d1205
ZW
22778 case OPCODE_MVN:
22779 new_inst = OPCODE_MOV;
22780 value = inverted;
22781 break;
bfae80f2 22782
c19d1205
ZW
22783 case OPCODE_AND: /* AND <-> BIC */
22784 new_inst = OPCODE_BIC;
22785 value = inverted;
22786 break;
bfae80f2 22787
c19d1205
ZW
22788 case OPCODE_BIC:
22789 new_inst = OPCODE_AND;
22790 value = inverted;
22791 break;
bfae80f2 22792
c19d1205
ZW
22793 case OPCODE_ADC: /* ADC <-> SBC */
22794 new_inst = OPCODE_SBC;
22795 value = inverted;
22796 break;
bfae80f2 22797
c19d1205
ZW
22798 case OPCODE_SBC:
22799 new_inst = OPCODE_ADC;
22800 value = inverted;
22801 break;
bfae80f2 22802
c19d1205
ZW
22803 /* We cannot do anything. */
22804 default:
22805 return FAIL;
b99bd4ef
NC
22806 }
22807
c19d1205
ZW
22808 if (value == (unsigned) FAIL)
22809 return FAIL;
22810
22811 *instruction &= OPCODE_MASK;
22812 *instruction |= new_inst << DATA_OP_SHIFT;
22813 return value;
b99bd4ef
NC
22814}
22815
ef8d22e6
PB
22816/* Like negate_data_op, but for Thumb-2. */
22817
22818static unsigned int
16dd5e42 22819thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22820{
22821 int op, new_inst;
22822 int rd;
16dd5e42 22823 unsigned int negated, inverted;
ef8d22e6
PB
22824
22825 negated = encode_thumb32_immediate (-value);
22826 inverted = encode_thumb32_immediate (~value);
22827
22828 rd = (*instruction >> 8) & 0xf;
22829 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22830 switch (op)
22831 {
22832 /* ADD <-> SUB. Includes CMP <-> CMN. */
22833 case T2_OPCODE_SUB:
22834 new_inst = T2_OPCODE_ADD;
22835 value = negated;
22836 break;
22837
22838 case T2_OPCODE_ADD:
22839 new_inst = T2_OPCODE_SUB;
22840 value = negated;
22841 break;
22842
22843 /* ORR <-> ORN. Includes MOV <-> MVN. */
22844 case T2_OPCODE_ORR:
22845 new_inst = T2_OPCODE_ORN;
22846 value = inverted;
22847 break;
22848
22849 case T2_OPCODE_ORN:
22850 new_inst = T2_OPCODE_ORR;
22851 value = inverted;
22852 break;
22853
22854 /* AND <-> BIC. TST has no inverted equivalent. */
22855 case T2_OPCODE_AND:
22856 new_inst = T2_OPCODE_BIC;
22857 if (rd == 15)
22858 value = FAIL;
22859 else
22860 value = inverted;
22861 break;
22862
22863 case T2_OPCODE_BIC:
22864 new_inst = T2_OPCODE_AND;
22865 value = inverted;
22866 break;
22867
22868 /* ADC <-> SBC */
22869 case T2_OPCODE_ADC:
22870 new_inst = T2_OPCODE_SBC;
22871 value = inverted;
22872 break;
22873
22874 case T2_OPCODE_SBC:
22875 new_inst = T2_OPCODE_ADC;
22876 value = inverted;
22877 break;
22878
22879 /* We cannot do anything. */
22880 default:
22881 return FAIL;
22882 }
22883
16dd5e42 22884 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22885 return FAIL;
22886
22887 *instruction &= T2_OPCODE_MASK;
22888 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22889 return value;
22890}
22891
8f06b2d8 22892/* Read a 32-bit thumb instruction from buf. */
0198d5e6 22893
8f06b2d8
PB
22894static unsigned long
22895get_thumb32_insn (char * buf)
22896{
22897 unsigned long insn;
22898 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22899 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22900
22901 return insn;
22902}
22903
a8bc6c78
PB
22904/* We usually want to set the low bit on the address of thumb function
22905 symbols. In particular .word foo - . should have the low bit set.
22906 Generic code tries to fold the difference of two symbols to
22907 a constant. Prevent this and force a relocation when the first symbols
22908 is a thumb function. */
c921be7d
NC
22909
22910bfd_boolean
a8bc6c78
PB
22911arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22912{
22913 if (op == O_subtract
22914 && l->X_op == O_symbol
22915 && r->X_op == O_symbol
22916 && THUMB_IS_FUNC (l->X_add_symbol))
22917 {
22918 l->X_op = O_subtract;
22919 l->X_op_symbol = r->X_add_symbol;
22920 l->X_add_number -= r->X_add_number;
c921be7d 22921 return TRUE;
a8bc6c78 22922 }
c921be7d 22923
a8bc6c78 22924 /* Process as normal. */
c921be7d 22925 return FALSE;
a8bc6c78
PB
22926}
22927
4a42ebbc
RR
22928/* Encode Thumb2 unconditional branches and calls. The encoding
22929 for the 2 are identical for the immediate values. */
22930
22931static void
22932encode_thumb2_b_bl_offset (char * buf, offsetT value)
22933{
22934#define T2I1I2MASK ((1 << 13) | (1 << 11))
22935 offsetT newval;
22936 offsetT newval2;
22937 addressT S, I1, I2, lo, hi;
22938
22939 S = (value >> 24) & 0x01;
22940 I1 = (value >> 23) & 0x01;
22941 I2 = (value >> 22) & 0x01;
22942 hi = (value >> 12) & 0x3ff;
fa94de6b 22943 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22944 newval = md_chars_to_number (buf, THUMB_SIZE);
22945 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22946 newval |= (S << 10) | hi;
22947 newval2 &= ~T2I1I2MASK;
22948 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22949 md_number_to_chars (buf, newval, THUMB_SIZE);
22950 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22951}
22952
c19d1205 22953void
55cf6793 22954md_apply_fix (fixS * fixP,
c19d1205
ZW
22955 valueT * valP,
22956 segT seg)
22957{
22958 offsetT value = * valP;
22959 offsetT newval;
22960 unsigned int newimm;
22961 unsigned long temp;
22962 int sign;
22963 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22964
9c2799c2 22965 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22966
c19d1205 22967 /* Note whether this will delete the relocation. */
4962c51a 22968
c19d1205
ZW
22969 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22970 fixP->fx_done = 1;
b99bd4ef 22971
adbaf948 22972 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22973 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22974 for emit_reloc. */
22975 value &= 0xffffffff;
22976 value ^= 0x80000000;
5f4273c7 22977 value -= 0x80000000;
adbaf948
ZW
22978
22979 *valP = value;
c19d1205 22980 fixP->fx_addnumber = value;
b99bd4ef 22981
adbaf948
ZW
22982 /* Same treatment for fixP->fx_offset. */
22983 fixP->fx_offset &= 0xffffffff;
22984 fixP->fx_offset ^= 0x80000000;
22985 fixP->fx_offset -= 0x80000000;
22986
c19d1205 22987 switch (fixP->fx_r_type)
b99bd4ef 22988 {
c19d1205
ZW
22989 case BFD_RELOC_NONE:
22990 /* This will need to go in the object file. */
22991 fixP->fx_done = 0;
22992 break;
b99bd4ef 22993
c19d1205
ZW
22994 case BFD_RELOC_ARM_IMMEDIATE:
22995 /* We claim that this fixup has been processed here,
22996 even if in fact we generate an error because we do
22997 not have a reloc for it, so tc_gen_reloc will reject it. */
22998 fixP->fx_done = 1;
b99bd4ef 22999
77db8e2e 23000 if (fixP->fx_addsy)
b99bd4ef 23001 {
77db8e2e 23002 const char *msg = 0;
b99bd4ef 23003
77db8e2e
NC
23004 if (! S_IS_DEFINED (fixP->fx_addsy))
23005 msg = _("undefined symbol %s used as an immediate value");
23006 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23007 msg = _("symbol %s is in a different section");
23008 else if (S_IS_WEAK (fixP->fx_addsy))
23009 msg = _("symbol %s is weak and may be overridden later");
23010
23011 if (msg)
23012 {
23013 as_bad_where (fixP->fx_file, fixP->fx_line,
23014 msg, S_GET_NAME (fixP->fx_addsy));
23015 break;
23016 }
42e5fcbf
AS
23017 }
23018
c19d1205
ZW
23019 temp = md_chars_to_number (buf, INSN_SIZE);
23020
5e73442d
SL
23021 /* If the offset is negative, we should use encoding A2 for ADR. */
23022 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23023 newimm = negate_data_op (&temp, value);
23024 else
23025 {
23026 newimm = encode_arm_immediate (value);
23027
23028 /* If the instruction will fail, see if we can fix things up by
23029 changing the opcode. */
23030 if (newimm == (unsigned int) FAIL)
23031 newimm = negate_data_op (&temp, value);
bada4342
JW
23032 /* MOV accepts both ARM modified immediate (A1 encoding) and
23033 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23034 When disassembling, MOV is preferred when there is no encoding
23035 overlap. */
23036 if (newimm == (unsigned int) FAIL
23037 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23038 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23039 && !((temp >> SBIT_SHIFT) & 0x1)
23040 && value >= 0 && value <= 0xffff)
23041 {
23042 /* Clear bits[23:20] to change encoding from A1 to A2. */
23043 temp &= 0xff0fffff;
23044 /* Encoding high 4bits imm. Code below will encode the remaining
23045 low 12bits. */
23046 temp |= (value & 0x0000f000) << 4;
23047 newimm = value & 0x00000fff;
23048 }
5e73442d
SL
23049 }
23050
23051 if (newimm == (unsigned int) FAIL)
b99bd4ef 23052 {
c19d1205
ZW
23053 as_bad_where (fixP->fx_file, fixP->fx_line,
23054 _("invalid constant (%lx) after fixup"),
23055 (unsigned long) value);
23056 break;
b99bd4ef 23057 }
b99bd4ef 23058
c19d1205
ZW
23059 newimm |= (temp & 0xfffff000);
23060 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23061 break;
b99bd4ef 23062
c19d1205
ZW
23063 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23064 {
23065 unsigned int highpart = 0;
23066 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23067
77db8e2e 23068 if (fixP->fx_addsy)
42e5fcbf 23069 {
77db8e2e 23070 const char *msg = 0;
42e5fcbf 23071
77db8e2e
NC
23072 if (! S_IS_DEFINED (fixP->fx_addsy))
23073 msg = _("undefined symbol %s used as an immediate value");
23074 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23075 msg = _("symbol %s is in a different section");
23076 else if (S_IS_WEAK (fixP->fx_addsy))
23077 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23078
77db8e2e
NC
23079 if (msg)
23080 {
23081 as_bad_where (fixP->fx_file, fixP->fx_line,
23082 msg, S_GET_NAME (fixP->fx_addsy));
23083 break;
23084 }
23085 }
fa94de6b 23086
c19d1205
ZW
23087 newimm = encode_arm_immediate (value);
23088 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23089
c19d1205
ZW
23090 /* If the instruction will fail, see if we can fix things up by
23091 changing the opcode. */
23092 if (newimm == (unsigned int) FAIL
23093 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23094 {
23095 /* No ? OK - try using two ADD instructions to generate
23096 the value. */
23097 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23098
c19d1205
ZW
23099 /* Yes - then make sure that the second instruction is
23100 also an add. */
23101 if (newimm != (unsigned int) FAIL)
23102 newinsn = temp;
23103 /* Still No ? Try using a negated value. */
23104 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23105 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23106 /* Otherwise - give up. */
23107 else
23108 {
23109 as_bad_where (fixP->fx_file, fixP->fx_line,
23110 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23111 (long) value);
23112 break;
23113 }
b99bd4ef 23114
c19d1205
ZW
23115 /* Replace the first operand in the 2nd instruction (which
23116 is the PC) with the destination register. We have
23117 already added in the PC in the first instruction and we
23118 do not want to do it again. */
23119 newinsn &= ~ 0xf0000;
23120 newinsn |= ((newinsn & 0x0f000) << 4);
23121 }
b99bd4ef 23122
c19d1205
ZW
23123 newimm |= (temp & 0xfffff000);
23124 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23125
c19d1205
ZW
23126 highpart |= (newinsn & 0xfffff000);
23127 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23128 }
23129 break;
b99bd4ef 23130
c19d1205 23131 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23132 if (!fixP->fx_done && seg->use_rela_p)
23133 value = 0;
1a0670f3 23134 /* Fall through. */
00a97672 23135
c19d1205 23136 case BFD_RELOC_ARM_LITERAL:
26d97720 23137 sign = value > 0;
b99bd4ef 23138
c19d1205
ZW
23139 if (value < 0)
23140 value = - value;
b99bd4ef 23141
c19d1205 23142 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23143 {
c19d1205
ZW
23144 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23145 as_bad_where (fixP->fx_file, fixP->fx_line,
23146 _("invalid literal constant: pool needs to be closer"));
23147 else
23148 as_bad_where (fixP->fx_file, fixP->fx_line,
23149 _("bad immediate value for offset (%ld)"),
23150 (long) value);
23151 break;
f03698e6
RE
23152 }
23153
c19d1205 23154 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23155 if (value == 0)
23156 newval &= 0xfffff000;
23157 else
23158 {
23159 newval &= 0xff7ff000;
23160 newval |= value | (sign ? INDEX_UP : 0);
23161 }
c19d1205
ZW
23162 md_number_to_chars (buf, newval, INSN_SIZE);
23163 break;
b99bd4ef 23164
c19d1205
ZW
23165 case BFD_RELOC_ARM_OFFSET_IMM8:
23166 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23167 sign = value > 0;
b99bd4ef 23168
c19d1205
ZW
23169 if (value < 0)
23170 value = - value;
b99bd4ef 23171
c19d1205 23172 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23173 {
c19d1205
ZW
23174 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23175 as_bad_where (fixP->fx_file, fixP->fx_line,
23176 _("invalid literal constant: pool needs to be closer"));
23177 else
427d0db6
RM
23178 as_bad_where (fixP->fx_file, fixP->fx_line,
23179 _("bad immediate value for 8-bit offset (%ld)"),
23180 (long) value);
c19d1205 23181 break;
b99bd4ef
NC
23182 }
23183
c19d1205 23184 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23185 if (value == 0)
23186 newval &= 0xfffff0f0;
23187 else
23188 {
23189 newval &= 0xff7ff0f0;
23190 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23191 }
c19d1205
ZW
23192 md_number_to_chars (buf, newval, INSN_SIZE);
23193 break;
b99bd4ef 23194
c19d1205
ZW
23195 case BFD_RELOC_ARM_T32_OFFSET_U8:
23196 if (value < 0 || value > 1020 || value % 4 != 0)
23197 as_bad_where (fixP->fx_file, fixP->fx_line,
23198 _("bad immediate value for offset (%ld)"), (long) value);
23199 value /= 4;
b99bd4ef 23200
c19d1205 23201 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23202 newval |= value;
23203 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23204 break;
b99bd4ef 23205
c19d1205
ZW
23206 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23207 /* This is a complicated relocation used for all varieties of Thumb32
23208 load/store instruction with immediate offset:
23209
23210 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23211 *4, optional writeback(W)
c19d1205
ZW
23212 (doubleword load/store)
23213
23214 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23215 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23216 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23217 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23218 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23219
23220 Uppercase letters indicate bits that are already encoded at
23221 this point. Lowercase letters are our problem. For the
23222 second block of instructions, the secondary opcode nybble
23223 (bits 8..11) is present, and bit 23 is zero, even if this is
23224 a PC-relative operation. */
23225 newval = md_chars_to_number (buf, THUMB_SIZE);
23226 newval <<= 16;
23227 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23228
c19d1205 23229 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23230 {
c19d1205
ZW
23231 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23232 if (value >= 0)
23233 newval |= (1 << 23);
23234 else
23235 value = -value;
23236 if (value % 4 != 0)
23237 {
23238 as_bad_where (fixP->fx_file, fixP->fx_line,
23239 _("offset not a multiple of 4"));
23240 break;
23241 }
23242 value /= 4;
216d22bc 23243 if (value > 0xff)
c19d1205
ZW
23244 {
23245 as_bad_where (fixP->fx_file, fixP->fx_line,
23246 _("offset out of range"));
23247 break;
23248 }
23249 newval &= ~0xff;
b99bd4ef 23250 }
c19d1205 23251 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23252 {
c19d1205
ZW
23253 /* PC-relative, 12-bit offset. */
23254 if (value >= 0)
23255 newval |= (1 << 23);
23256 else
23257 value = -value;
216d22bc 23258 if (value > 0xfff)
c19d1205
ZW
23259 {
23260 as_bad_where (fixP->fx_file, fixP->fx_line,
23261 _("offset out of range"));
23262 break;
23263 }
23264 newval &= ~0xfff;
b99bd4ef 23265 }
c19d1205 23266 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23267 {
c19d1205
ZW
23268 /* Writeback: 8-bit, +/- offset. */
23269 if (value >= 0)
23270 newval |= (1 << 9);
23271 else
23272 value = -value;
216d22bc 23273 if (value > 0xff)
c19d1205
ZW
23274 {
23275 as_bad_where (fixP->fx_file, fixP->fx_line,
23276 _("offset out of range"));
23277 break;
23278 }
23279 newval &= ~0xff;
b99bd4ef 23280 }
c19d1205 23281 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23282 {
c19d1205 23283 /* T-instruction: positive 8-bit offset. */
216d22bc 23284 if (value < 0 || value > 0xff)
b99bd4ef 23285 {
c19d1205
ZW
23286 as_bad_where (fixP->fx_file, fixP->fx_line,
23287 _("offset out of range"));
23288 break;
b99bd4ef 23289 }
c19d1205
ZW
23290 newval &= ~0xff;
23291 newval |= value;
b99bd4ef
NC
23292 }
23293 else
b99bd4ef 23294 {
c19d1205
ZW
23295 /* Positive 12-bit or negative 8-bit offset. */
23296 int limit;
23297 if (value >= 0)
b99bd4ef 23298 {
c19d1205
ZW
23299 newval |= (1 << 23);
23300 limit = 0xfff;
23301 }
23302 else
23303 {
23304 value = -value;
23305 limit = 0xff;
23306 }
23307 if (value > limit)
23308 {
23309 as_bad_where (fixP->fx_file, fixP->fx_line,
23310 _("offset out of range"));
23311 break;
b99bd4ef 23312 }
c19d1205 23313 newval &= ~limit;
b99bd4ef 23314 }
b99bd4ef 23315
c19d1205
ZW
23316 newval |= value;
23317 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23318 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23319 break;
404ff6b5 23320
c19d1205
ZW
23321 case BFD_RELOC_ARM_SHIFT_IMM:
23322 newval = md_chars_to_number (buf, INSN_SIZE);
23323 if (((unsigned long) value) > 32
23324 || (value == 32
23325 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23326 {
23327 as_bad_where (fixP->fx_file, fixP->fx_line,
23328 _("shift expression is too large"));
23329 break;
23330 }
404ff6b5 23331
c19d1205
ZW
23332 if (value == 0)
23333 /* Shifts of zero must be done as lsl. */
23334 newval &= ~0x60;
23335 else if (value == 32)
23336 value = 0;
23337 newval &= 0xfffff07f;
23338 newval |= (value & 0x1f) << 7;
23339 md_number_to_chars (buf, newval, INSN_SIZE);
23340 break;
404ff6b5 23341
c19d1205 23342 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23343 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23344 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23345 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23346 /* We claim that this fixup has been processed here,
23347 even if in fact we generate an error because we do
23348 not have a reloc for it, so tc_gen_reloc will reject it. */
23349 fixP->fx_done = 1;
404ff6b5 23350
c19d1205
ZW
23351 if (fixP->fx_addsy
23352 && ! S_IS_DEFINED (fixP->fx_addsy))
23353 {
23354 as_bad_where (fixP->fx_file, fixP->fx_line,
23355 _("undefined symbol %s used as an immediate value"),
23356 S_GET_NAME (fixP->fx_addsy));
23357 break;
23358 }
404ff6b5 23359
c19d1205
ZW
23360 newval = md_chars_to_number (buf, THUMB_SIZE);
23361 newval <<= 16;
23362 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23363
16805f35 23364 newimm = FAIL;
bada4342
JW
23365 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23366 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23367 Thumb2 modified immediate encoding (T2). */
23368 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23369 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23370 {
23371 newimm = encode_thumb32_immediate (value);
23372 if (newimm == (unsigned int) FAIL)
23373 newimm = thumb32_negate_data_op (&newval, value);
23374 }
bada4342 23375 if (newimm == (unsigned int) FAIL)
92e90b6e 23376 {
bada4342 23377 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23378 {
bada4342
JW
23379 /* Turn add/sum into addw/subw. */
23380 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23381 newval = (newval & 0xfeffffff) | 0x02000000;
23382 /* No flat 12-bit imm encoding for addsw/subsw. */
23383 if ((newval & 0x00100000) == 0)
40f246e3 23384 {
bada4342
JW
23385 /* 12 bit immediate for addw/subw. */
23386 if (value < 0)
23387 {
23388 value = -value;
23389 newval ^= 0x00a00000;
23390 }
23391 if (value > 0xfff)
23392 newimm = (unsigned int) FAIL;
23393 else
23394 newimm = value;
23395 }
23396 }
23397 else
23398 {
23399 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23400 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23401 disassembling, MOV is preferred when there is no encoding
23402 overlap.
23403 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23404 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23405 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23406 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23407 && value >= 0 && value <=0xffff)
23408 {
23409 /* Toggle bit[25] to change encoding from T2 to T3. */
23410 newval ^= 1 << 25;
23411 /* Clear bits[19:16]. */
23412 newval &= 0xfff0ffff;
23413 /* Encoding high 4bits imm. Code below will encode the
23414 remaining low 12bits. */
23415 newval |= (value & 0x0000f000) << 4;
23416 newimm = value & 0x00000fff;
40f246e3 23417 }
e9f89963 23418 }
92e90b6e 23419 }
cc8a6dd0 23420
c19d1205 23421 if (newimm == (unsigned int)FAIL)
3631a3c8 23422 {
c19d1205
ZW
23423 as_bad_where (fixP->fx_file, fixP->fx_line,
23424 _("invalid constant (%lx) after fixup"),
23425 (unsigned long) value);
23426 break;
3631a3c8
NC
23427 }
23428
c19d1205
ZW
23429 newval |= (newimm & 0x800) << 15;
23430 newval |= (newimm & 0x700) << 4;
23431 newval |= (newimm & 0x0ff);
cc8a6dd0 23432
c19d1205
ZW
23433 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23434 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23435 break;
a737bd4d 23436
3eb17e6b 23437 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23438 if (((unsigned long) value) > 0xffff)
23439 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23440 _("invalid smc expression"));
2fc8bdac 23441 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23442 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23443 md_number_to_chars (buf, newval, INSN_SIZE);
23444 break;
a737bd4d 23445
90ec0d68
MGD
23446 case BFD_RELOC_ARM_HVC:
23447 if (((unsigned long) value) > 0xffff)
23448 as_bad_where (fixP->fx_file, fixP->fx_line,
23449 _("invalid hvc expression"));
23450 newval = md_chars_to_number (buf, INSN_SIZE);
23451 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23452 md_number_to_chars (buf, newval, INSN_SIZE);
23453 break;
23454
c19d1205 23455 case BFD_RELOC_ARM_SWI:
adbaf948 23456 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23457 {
23458 if (((unsigned long) value) > 0xff)
23459 as_bad_where (fixP->fx_file, fixP->fx_line,
23460 _("invalid swi expression"));
2fc8bdac 23461 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23462 newval |= value;
23463 md_number_to_chars (buf, newval, THUMB_SIZE);
23464 }
23465 else
23466 {
23467 if (((unsigned long) value) > 0x00ffffff)
23468 as_bad_where (fixP->fx_file, fixP->fx_line,
23469 _("invalid swi expression"));
2fc8bdac 23470 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23471 newval |= value;
23472 md_number_to_chars (buf, newval, INSN_SIZE);
23473 }
23474 break;
a737bd4d 23475
c19d1205
ZW
23476 case BFD_RELOC_ARM_MULTI:
23477 if (((unsigned long) value) > 0xffff)
23478 as_bad_where (fixP->fx_file, fixP->fx_line,
23479 _("invalid expression in load/store multiple"));
23480 newval = value | md_chars_to_number (buf, INSN_SIZE);
23481 md_number_to_chars (buf, newval, INSN_SIZE);
23482 break;
a737bd4d 23483
c19d1205 23484#ifdef OBJ_ELF
39b41c9c 23485 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23486
23487 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23488 && fixP->fx_addsy
34e77a92 23489 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23490 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23491 && THUMB_IS_FUNC (fixP->fx_addsy))
23492 /* Flip the bl to blx. This is a simple flip
23493 bit here because we generate PCREL_CALL for
23494 unconditional bls. */
23495 {
23496 newval = md_chars_to_number (buf, INSN_SIZE);
23497 newval = newval | 0x10000000;
23498 md_number_to_chars (buf, newval, INSN_SIZE);
23499 temp = 1;
23500 fixP->fx_done = 1;
23501 }
39b41c9c
PB
23502 else
23503 temp = 3;
23504 goto arm_branch_common;
23505
23506 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23507 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23508 && fixP->fx_addsy
34e77a92 23509 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23510 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23511 && THUMB_IS_FUNC (fixP->fx_addsy))
23512 {
23513 /* This would map to a bl<cond>, b<cond>,
23514 b<always> to a Thumb function. We
23515 need to force a relocation for this particular
23516 case. */
23517 newval = md_chars_to_number (buf, INSN_SIZE);
23518 fixP->fx_done = 0;
23519 }
1a0670f3 23520 /* Fall through. */
267bf995 23521
2fc8bdac 23522 case BFD_RELOC_ARM_PLT32:
c19d1205 23523#endif
39b41c9c
PB
23524 case BFD_RELOC_ARM_PCREL_BRANCH:
23525 temp = 3;
23526 goto arm_branch_common;
a737bd4d 23527
39b41c9c 23528 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23529
39b41c9c 23530 temp = 1;
267bf995
RR
23531 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23532 && fixP->fx_addsy
34e77a92 23533 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23534 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23535 && ARM_IS_FUNC (fixP->fx_addsy))
23536 {
23537 /* Flip the blx to a bl and warn. */
23538 const char *name = S_GET_NAME (fixP->fx_addsy);
23539 newval = 0xeb000000;
23540 as_warn_where (fixP->fx_file, fixP->fx_line,
23541 _("blx to '%s' an ARM ISA state function changed to bl"),
23542 name);
23543 md_number_to_chars (buf, newval, INSN_SIZE);
23544 temp = 3;
23545 fixP->fx_done = 1;
23546 }
23547
23548#ifdef OBJ_ELF
23549 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23550 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23551#endif
23552
39b41c9c 23553 arm_branch_common:
c19d1205 23554 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23555 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23556 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23557 also be clear. */
39b41c9c 23558 if (value & temp)
c19d1205 23559 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23560 _("misaligned branch destination"));
23561 if ((value & (offsetT)0xfe000000) != (offsetT)0
23562 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23563 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23564
2fc8bdac 23565 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23566 {
2fc8bdac
ZW
23567 newval = md_chars_to_number (buf, INSN_SIZE);
23568 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23569 /* Set the H bit on BLX instructions. */
23570 if (temp == 1)
23571 {
23572 if (value & 2)
23573 newval |= 0x01000000;
23574 else
23575 newval &= ~0x01000000;
23576 }
2fc8bdac 23577 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23578 }
c19d1205 23579 break;
a737bd4d 23580
25fe350b
MS
23581 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23582 /* CBZ can only branch forward. */
a737bd4d 23583
738755b0 23584 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23585 (which, strictly speaking, are prohibited) will be turned into
23586 no-ops.
738755b0
MS
23587
23588 FIXME: It may be better to remove the instruction completely and
23589 perform relaxation. */
23590 if (value == -2)
2fc8bdac
ZW
23591 {
23592 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23593 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23594 md_number_to_chars (buf, newval, THUMB_SIZE);
23595 }
738755b0
MS
23596 else
23597 {
23598 if (value & ~0x7e)
08f10d51 23599 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23600
477330fc 23601 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23602 {
23603 newval = md_chars_to_number (buf, THUMB_SIZE);
23604 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23605 md_number_to_chars (buf, newval, THUMB_SIZE);
23606 }
23607 }
c19d1205 23608 break;
a737bd4d 23609
c19d1205 23610 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23611 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23612 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23613
2fc8bdac
ZW
23614 if (fixP->fx_done || !seg->use_rela_p)
23615 {
23616 newval = md_chars_to_number (buf, THUMB_SIZE);
23617 newval |= (value & 0x1ff) >> 1;
23618 md_number_to_chars (buf, newval, THUMB_SIZE);
23619 }
c19d1205 23620 break;
a737bd4d 23621
c19d1205 23622 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23623 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23624 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23625
2fc8bdac
ZW
23626 if (fixP->fx_done || !seg->use_rela_p)
23627 {
23628 newval = md_chars_to_number (buf, THUMB_SIZE);
23629 newval |= (value & 0xfff) >> 1;
23630 md_number_to_chars (buf, newval, THUMB_SIZE);
23631 }
c19d1205 23632 break;
a737bd4d 23633
c19d1205 23634 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23635 if (fixP->fx_addsy
23636 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23637 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23638 && ARM_IS_FUNC (fixP->fx_addsy)
23639 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23640 {
23641 /* Force a relocation for a branch 20 bits wide. */
23642 fixP->fx_done = 0;
23643 }
08f10d51 23644 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23645 as_bad_where (fixP->fx_file, fixP->fx_line,
23646 _("conditional branch out of range"));
404ff6b5 23647
2fc8bdac
ZW
23648 if (fixP->fx_done || !seg->use_rela_p)
23649 {
23650 offsetT newval2;
23651 addressT S, J1, J2, lo, hi;
404ff6b5 23652
2fc8bdac
ZW
23653 S = (value & 0x00100000) >> 20;
23654 J2 = (value & 0x00080000) >> 19;
23655 J1 = (value & 0x00040000) >> 18;
23656 hi = (value & 0x0003f000) >> 12;
23657 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23658
2fc8bdac
ZW
23659 newval = md_chars_to_number (buf, THUMB_SIZE);
23660 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23661 newval |= (S << 10) | hi;
23662 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23663 md_number_to_chars (buf, newval, THUMB_SIZE);
23664 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23665 }
c19d1205 23666 break;
6c43fab6 23667
c19d1205 23668 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23669 /* If there is a blx from a thumb state function to
23670 another thumb function flip this to a bl and warn
23671 about it. */
23672
23673 if (fixP->fx_addsy
34e77a92 23674 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23675 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23676 && THUMB_IS_FUNC (fixP->fx_addsy))
23677 {
23678 const char *name = S_GET_NAME (fixP->fx_addsy);
23679 as_warn_where (fixP->fx_file, fixP->fx_line,
23680 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23681 name);
23682 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23683 newval = newval | 0x1000;
23684 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23685 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23686 fixP->fx_done = 1;
23687 }
23688
23689
23690 goto thumb_bl_common;
23691
c19d1205 23692 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23693 /* A bl from Thumb state ISA to an internal ARM state function
23694 is converted to a blx. */
23695 if (fixP->fx_addsy
23696 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23697 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23698 && ARM_IS_FUNC (fixP->fx_addsy)
23699 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23700 {
23701 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23702 newval = newval & ~0x1000;
23703 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23704 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23705 fixP->fx_done = 1;
23706 }
23707
23708 thumb_bl_common:
23709
2fc8bdac
ZW
23710 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23711 /* For a BLX instruction, make sure that the relocation is rounded up
23712 to a word boundary. This follows the semantics of the instruction
23713 which specifies that bit 1 of the target address will come from bit
23714 1 of the base address. */
d406f3e4
JB
23715 value = (value + 3) & ~ 3;
23716
23717#ifdef OBJ_ELF
23718 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23719 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23720 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23721#endif
404ff6b5 23722
2b2f5df9
NC
23723 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23724 {
fc289b0a 23725 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23726 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23727 else if ((value & ~0x1ffffff)
23728 && ((value & ~0x1ffffff) != ~0x1ffffff))
23729 as_bad_where (fixP->fx_file, fixP->fx_line,
23730 _("Thumb2 branch out of range"));
23731 }
4a42ebbc
RR
23732
23733 if (fixP->fx_done || !seg->use_rela_p)
23734 encode_thumb2_b_bl_offset (buf, value);
23735
c19d1205 23736 break;
404ff6b5 23737
c19d1205 23738 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23739 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23740 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23741
2fc8bdac 23742 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23743 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23744
2fc8bdac 23745 break;
a737bd4d 23746
2fc8bdac
ZW
23747 case BFD_RELOC_8:
23748 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23749 *buf = value;
c19d1205 23750 break;
a737bd4d 23751
c19d1205 23752 case BFD_RELOC_16:
2fc8bdac 23753 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23754 md_number_to_chars (buf, value, 2);
c19d1205 23755 break;
a737bd4d 23756
c19d1205 23757#ifdef OBJ_ELF
0855e32b
NS
23758 case BFD_RELOC_ARM_TLS_CALL:
23759 case BFD_RELOC_ARM_THM_TLS_CALL:
23760 case BFD_RELOC_ARM_TLS_DESCSEQ:
23761 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23762 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23763 case BFD_RELOC_ARM_TLS_GD32:
23764 case BFD_RELOC_ARM_TLS_LE32:
23765 case BFD_RELOC_ARM_TLS_IE32:
23766 case BFD_RELOC_ARM_TLS_LDM32:
23767 case BFD_RELOC_ARM_TLS_LDO32:
23768 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23769 break;
6c43fab6 23770
c19d1205
ZW
23771 case BFD_RELOC_ARM_GOT32:
23772 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23773 break;
b43420e6
NC
23774
23775 case BFD_RELOC_ARM_GOT_PREL:
23776 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23777 md_number_to_chars (buf, value, 4);
b43420e6
NC
23778 break;
23779
9a6f4e97
NS
23780 case BFD_RELOC_ARM_TARGET2:
23781 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23782 addend here for REL targets, because it won't be written out
23783 during reloc processing later. */
9a6f4e97
NS
23784 if (fixP->fx_done || !seg->use_rela_p)
23785 md_number_to_chars (buf, fixP->fx_offset, 4);
23786 break;
c19d1205 23787#endif
6c43fab6 23788
c19d1205
ZW
23789 case BFD_RELOC_RVA:
23790 case BFD_RELOC_32:
23791 case BFD_RELOC_ARM_TARGET1:
23792 case BFD_RELOC_ARM_ROSEGREL32:
23793 case BFD_RELOC_ARM_SBREL32:
23794 case BFD_RELOC_32_PCREL:
f0927246
NC
23795#ifdef TE_PE
23796 case BFD_RELOC_32_SECREL:
23797#endif
2fc8bdac 23798 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23799#ifdef TE_WINCE
23800 /* For WinCE we only do this for pcrel fixups. */
23801 if (fixP->fx_done || fixP->fx_pcrel)
23802#endif
23803 md_number_to_chars (buf, value, 4);
c19d1205 23804 break;
6c43fab6 23805
c19d1205
ZW
23806#ifdef OBJ_ELF
23807 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23808 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23809 {
23810 newval = md_chars_to_number (buf, 4) & 0x80000000;
23811 if ((value ^ (value >> 1)) & 0x40000000)
23812 {
23813 as_bad_where (fixP->fx_file, fixP->fx_line,
23814 _("rel31 relocation overflow"));
23815 }
23816 newval |= value & 0x7fffffff;
23817 md_number_to_chars (buf, newval, 4);
23818 }
23819 break;
c19d1205 23820#endif
a737bd4d 23821
c19d1205 23822 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23823 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23824 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23825 newval = md_chars_to_number (buf, INSN_SIZE);
23826 else
23827 newval = get_thumb32_insn (buf);
23828 if ((newval & 0x0f200f00) == 0x0d000900)
23829 {
23830 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23831 has permitted values that are multiples of 2, in the range 0
23832 to 510. */
23833 if (value < -510 || value > 510 || (value & 1))
23834 as_bad_where (fixP->fx_file, fixP->fx_line,
23835 _("co-processor offset out of range"));
23836 }
23837 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23838 as_bad_where (fixP->fx_file, fixP->fx_line,
23839 _("co-processor offset out of range"));
23840 cp_off_common:
26d97720 23841 sign = value > 0;
c19d1205
ZW
23842 if (value < 0)
23843 value = -value;
8f06b2d8
PB
23844 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23845 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23846 newval = md_chars_to_number (buf, INSN_SIZE);
23847 else
23848 newval = get_thumb32_insn (buf);
26d97720
NS
23849 if (value == 0)
23850 newval &= 0xffffff00;
23851 else
23852 {
23853 newval &= 0xff7fff00;
9db2f6b4
RL
23854 if ((newval & 0x0f200f00) == 0x0d000900)
23855 {
23856 /* This is a fp16 vstr/vldr.
23857
23858 It requires the immediate offset in the instruction is shifted
23859 left by 1 to be a half-word offset.
23860
23861 Here, left shift by 1 first, and later right shift by 2
23862 should get the right offset. */
23863 value <<= 1;
23864 }
26d97720
NS
23865 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23866 }
8f06b2d8
PB
23867 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23868 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23869 md_number_to_chars (buf, newval, INSN_SIZE);
23870 else
23871 put_thumb32_insn (buf, newval);
c19d1205 23872 break;
a737bd4d 23873
c19d1205 23874 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23875 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23876 if (value < -255 || value > 255)
23877 as_bad_where (fixP->fx_file, fixP->fx_line,
23878 _("co-processor offset out of range"));
df7849c5 23879 value *= 4;
c19d1205 23880 goto cp_off_common;
6c43fab6 23881
c19d1205
ZW
23882 case BFD_RELOC_ARM_THUMB_OFFSET:
23883 newval = md_chars_to_number (buf, THUMB_SIZE);
23884 /* Exactly what ranges, and where the offset is inserted depends
23885 on the type of instruction, we can establish this from the
23886 top 4 bits. */
23887 switch (newval >> 12)
23888 {
23889 case 4: /* PC load. */
23890 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23891 forced to zero for these loads; md_pcrel_from has already
23892 compensated for this. */
23893 if (value & 3)
23894 as_bad_where (fixP->fx_file, fixP->fx_line,
23895 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23896 (((unsigned long) fixP->fx_frag->fr_address
23897 + (unsigned long) fixP->fx_where) & ~3)
23898 + (unsigned long) value);
a737bd4d 23899
c19d1205
ZW
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);
a737bd4d 23904
c19d1205
ZW
23905 newval |= value >> 2;
23906 break;
a737bd4d 23907
c19d1205
ZW
23908 case 9: /* SP load/store. */
23909 if (value & ~0x3fc)
23910 as_bad_where (fixP->fx_file, fixP->fx_line,
23911 _("invalid offset, value too big (0x%08lX)"),
23912 (long) value);
23913 newval |= value >> 2;
23914 break;
6c43fab6 23915
c19d1205
ZW
23916 case 6: /* Word load/store. */
23917 if (value & ~0x7c)
23918 as_bad_where (fixP->fx_file, fixP->fx_line,
23919 _("invalid offset, value too big (0x%08lX)"),
23920 (long) value);
23921 newval |= value << 4; /* 6 - 2. */
23922 break;
a737bd4d 23923
c19d1205
ZW
23924 case 7: /* Byte load/store. */
23925 if (value & ~0x1f)
23926 as_bad_where (fixP->fx_file, fixP->fx_line,
23927 _("invalid offset, value too big (0x%08lX)"),
23928 (long) value);
23929 newval |= value << 6;
23930 break;
a737bd4d 23931
c19d1205
ZW
23932 case 8: /* Halfword load/store. */
23933 if (value & ~0x3e)
23934 as_bad_where (fixP->fx_file, fixP->fx_line,
23935 _("invalid offset, value too big (0x%08lX)"),
23936 (long) value);
23937 newval |= value << 5; /* 6 - 1. */
23938 break;
a737bd4d 23939
c19d1205
ZW
23940 default:
23941 as_bad_where (fixP->fx_file, fixP->fx_line,
23942 "Unable to process relocation for thumb opcode: %lx",
23943 (unsigned long) newval);
23944 break;
23945 }
23946 md_number_to_chars (buf, newval, THUMB_SIZE);
23947 break;
a737bd4d 23948
c19d1205
ZW
23949 case BFD_RELOC_ARM_THUMB_ADD:
23950 /* This is a complicated relocation, since we use it for all of
23951 the following immediate relocations:
a737bd4d 23952
c19d1205
ZW
23953 3bit ADD/SUB
23954 8bit ADD/SUB
23955 9bit ADD/SUB SP word-aligned
23956 10bit ADD PC/SP word-aligned
a737bd4d 23957
c19d1205
ZW
23958 The type of instruction being processed is encoded in the
23959 instruction field:
a737bd4d 23960
c19d1205
ZW
23961 0x8000 SUB
23962 0x00F0 Rd
23963 0x000F Rs
23964 */
23965 newval = md_chars_to_number (buf, THUMB_SIZE);
23966 {
23967 int rd = (newval >> 4) & 0xf;
23968 int rs = newval & 0xf;
23969 int subtract = !!(newval & 0x8000);
a737bd4d 23970
c19d1205
ZW
23971 /* Check for HI regs, only very restricted cases allowed:
23972 Adjusting SP, and using PC or SP to get an address. */
23973 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23974 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23975 as_bad_where (fixP->fx_file, fixP->fx_line,
23976 _("invalid Hi register with immediate"));
a737bd4d 23977
c19d1205
ZW
23978 /* If value is negative, choose the opposite instruction. */
23979 if (value < 0)
23980 {
23981 value = -value;
23982 subtract = !subtract;
23983 if (value < 0)
23984 as_bad_where (fixP->fx_file, fixP->fx_line,
23985 _("immediate value out of range"));
23986 }
a737bd4d 23987
c19d1205
ZW
23988 if (rd == REG_SP)
23989 {
75c11999 23990 if (value & ~0x1fc)
c19d1205
ZW
23991 as_bad_where (fixP->fx_file, fixP->fx_line,
23992 _("invalid immediate for stack address calculation"));
23993 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23994 newval |= value >> 2;
23995 }
23996 else if (rs == REG_PC || rs == REG_SP)
23997 {
c12d2c9d
NC
23998 /* PR gas/18541. If the addition is for a defined symbol
23999 within range of an ADR instruction then accept it. */
24000 if (subtract
24001 && value == 4
24002 && fixP->fx_addsy != NULL)
24003 {
24004 subtract = 0;
24005
24006 if (! S_IS_DEFINED (fixP->fx_addsy)
24007 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24008 || S_IS_WEAK (fixP->fx_addsy))
24009 {
24010 as_bad_where (fixP->fx_file, fixP->fx_line,
24011 _("address calculation needs a strongly defined nearby symbol"));
24012 }
24013 else
24014 {
24015 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24016
24017 /* Round up to the next 4-byte boundary. */
24018 if (v & 3)
24019 v = (v + 3) & ~ 3;
24020 else
24021 v += 4;
24022 v = S_GET_VALUE (fixP->fx_addsy) - v;
24023
24024 if (v & ~0x3fc)
24025 {
24026 as_bad_where (fixP->fx_file, fixP->fx_line,
24027 _("symbol too far away"));
24028 }
24029 else
24030 {
24031 fixP->fx_done = 1;
24032 value = v;
24033 }
24034 }
24035 }
24036
c19d1205
ZW
24037 if (subtract || value & ~0x3fc)
24038 as_bad_where (fixP->fx_file, fixP->fx_line,
24039 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24040 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24041 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24042 newval |= rd << 8;
24043 newval |= value >> 2;
24044 }
24045 else if (rs == rd)
24046 {
24047 if (value & ~0xff)
24048 as_bad_where (fixP->fx_file, fixP->fx_line,
24049 _("immediate value out of range"));
24050 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24051 newval |= (rd << 8) | value;
24052 }
24053 else
24054 {
24055 if (value & ~0x7)
24056 as_bad_where (fixP->fx_file, fixP->fx_line,
24057 _("immediate value out of range"));
24058 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24059 newval |= rd | (rs << 3) | (value << 6);
24060 }
24061 }
24062 md_number_to_chars (buf, newval, THUMB_SIZE);
24063 break;
a737bd4d 24064
c19d1205
ZW
24065 case BFD_RELOC_ARM_THUMB_IMM:
24066 newval = md_chars_to_number (buf, THUMB_SIZE);
24067 if (value < 0 || value > 255)
24068 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24069 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24070 (long) value);
24071 newval |= value;
24072 md_number_to_chars (buf, newval, THUMB_SIZE);
24073 break;
a737bd4d 24074
c19d1205
ZW
24075 case BFD_RELOC_ARM_THUMB_SHIFT:
24076 /* 5bit shift value (0..32). LSL cannot take 32. */
24077 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24078 temp = newval & 0xf800;
24079 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24080 as_bad_where (fixP->fx_file, fixP->fx_line,
24081 _("invalid shift value: %ld"), (long) value);
24082 /* Shifts of zero must be encoded as LSL. */
24083 if (value == 0)
24084 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24085 /* Shifts of 32 are encoded as zero. */
24086 else if (value == 32)
24087 value = 0;
24088 newval |= value << 6;
24089 md_number_to_chars (buf, newval, THUMB_SIZE);
24090 break;
a737bd4d 24091
c19d1205
ZW
24092 case BFD_RELOC_VTABLE_INHERIT:
24093 case BFD_RELOC_VTABLE_ENTRY:
24094 fixP->fx_done = 0;
24095 return;
6c43fab6 24096
b6895b4f
PB
24097 case BFD_RELOC_ARM_MOVW:
24098 case BFD_RELOC_ARM_MOVT:
24099 case BFD_RELOC_ARM_THUMB_MOVW:
24100 case BFD_RELOC_ARM_THUMB_MOVT:
24101 if (fixP->fx_done || !seg->use_rela_p)
24102 {
24103 /* REL format relocations are limited to a 16-bit addend. */
24104 if (!fixP->fx_done)
24105 {
39623e12 24106 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24107 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24108 _("offset out of range"));
b6895b4f
PB
24109 }
24110 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24111 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24112 {
24113 value >>= 16;
24114 }
24115
24116 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24117 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24118 {
24119 newval = get_thumb32_insn (buf);
24120 newval &= 0xfbf08f00;
24121 newval |= (value & 0xf000) << 4;
24122 newval |= (value & 0x0800) << 15;
24123 newval |= (value & 0x0700) << 4;
24124 newval |= (value & 0x00ff);
24125 put_thumb32_insn (buf, newval);
24126 }
24127 else
24128 {
24129 newval = md_chars_to_number (buf, 4);
24130 newval &= 0xfff0f000;
24131 newval |= value & 0x0fff;
24132 newval |= (value & 0xf000) << 4;
24133 md_number_to_chars (buf, newval, 4);
24134 }
24135 }
24136 return;
24137
72d98d16
MG
24138 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24139 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24140 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24141 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24142 gas_assert (!fixP->fx_done);
24143 {
24144 bfd_vma insn;
24145 bfd_boolean is_mov;
24146 bfd_vma encoded_addend = value;
24147
24148 /* Check that addend can be encoded in instruction. */
24149 if (!seg->use_rela_p && (value < 0 || value > 255))
24150 as_bad_where (fixP->fx_file, fixP->fx_line,
24151 _("the offset 0x%08lX is not representable"),
24152 (unsigned long) encoded_addend);
24153
24154 /* Extract the instruction. */
24155 insn = md_chars_to_number (buf, THUMB_SIZE);
24156 is_mov = (insn & 0xf800) == 0x2000;
24157
24158 /* Encode insn. */
24159 if (is_mov)
24160 {
24161 if (!seg->use_rela_p)
24162 insn |= encoded_addend;
24163 }
24164 else
24165 {
24166 int rd, rs;
24167
24168 /* Extract the instruction. */
24169 /* Encoding is the following
24170 0x8000 SUB
24171 0x00F0 Rd
24172 0x000F Rs
24173 */
24174 /* The following conditions must be true :
24175 - ADD
24176 - Rd == Rs
24177 - Rd <= 7
24178 */
24179 rd = (insn >> 4) & 0xf;
24180 rs = insn & 0xf;
24181 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24182 as_bad_where (fixP->fx_file, fixP->fx_line,
24183 _("Unable to process relocation for thumb opcode: %lx"),
24184 (unsigned long) insn);
24185
24186 /* Encode as ADD immediate8 thumb 1 code. */
24187 insn = 0x3000 | (rd << 8);
24188
24189 /* Place the encoded addend into the first 8 bits of the
24190 instruction. */
24191 if (!seg->use_rela_p)
24192 insn |= encoded_addend;
24193 }
24194
24195 /* Update the instruction. */
24196 md_number_to_chars (buf, insn, THUMB_SIZE);
24197 }
24198 break;
24199
4962c51a
MS
24200 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24201 case BFD_RELOC_ARM_ALU_PC_G0:
24202 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24203 case BFD_RELOC_ARM_ALU_PC_G1:
24204 case BFD_RELOC_ARM_ALU_PC_G2:
24205 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24206 case BFD_RELOC_ARM_ALU_SB_G0:
24207 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24208 case BFD_RELOC_ARM_ALU_SB_G1:
24209 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24210 gas_assert (!fixP->fx_done);
4962c51a
MS
24211 if (!seg->use_rela_p)
24212 {
477330fc
RM
24213 bfd_vma insn;
24214 bfd_vma encoded_addend;
24215 bfd_vma addend_abs = abs (value);
24216
24217 /* Check that the absolute value of the addend can be
24218 expressed as an 8-bit constant plus a rotation. */
24219 encoded_addend = encode_arm_immediate (addend_abs);
24220 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24221 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24222 _("the offset 0x%08lX is not representable"),
24223 (unsigned long) addend_abs);
24224
24225 /* Extract the instruction. */
24226 insn = md_chars_to_number (buf, INSN_SIZE);
24227
24228 /* If the addend is positive, use an ADD instruction.
24229 Otherwise use a SUB. Take care not to destroy the S bit. */
24230 insn &= 0xff1fffff;
24231 if (value < 0)
24232 insn |= 1 << 22;
24233 else
24234 insn |= 1 << 23;
24235
24236 /* Place the encoded addend into the first 12 bits of the
24237 instruction. */
24238 insn &= 0xfffff000;
24239 insn |= encoded_addend;
24240
24241 /* Update the instruction. */
24242 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24243 }
24244 break;
24245
24246 case BFD_RELOC_ARM_LDR_PC_G0:
24247 case BFD_RELOC_ARM_LDR_PC_G1:
24248 case BFD_RELOC_ARM_LDR_PC_G2:
24249 case BFD_RELOC_ARM_LDR_SB_G0:
24250 case BFD_RELOC_ARM_LDR_SB_G1:
24251 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24252 gas_assert (!fixP->fx_done);
4962c51a 24253 if (!seg->use_rela_p)
477330fc
RM
24254 {
24255 bfd_vma insn;
24256 bfd_vma addend_abs = abs (value);
4962c51a 24257
477330fc
RM
24258 /* Check that the absolute value of the addend can be
24259 encoded in 12 bits. */
24260 if (addend_abs >= 0x1000)
4962c51a 24261 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24262 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24263 (unsigned long) addend_abs);
24264
24265 /* Extract the instruction. */
24266 insn = md_chars_to_number (buf, INSN_SIZE);
24267
24268 /* If the addend is negative, clear bit 23 of the instruction.
24269 Otherwise set it. */
24270 if (value < 0)
24271 insn &= ~(1 << 23);
24272 else
24273 insn |= 1 << 23;
24274
24275 /* Place the absolute value of the addend into the first 12 bits
24276 of the instruction. */
24277 insn &= 0xfffff000;
24278 insn |= addend_abs;
24279
24280 /* Update the instruction. */
24281 md_number_to_chars (buf, insn, INSN_SIZE);
24282 }
4962c51a
MS
24283 break;
24284
24285 case BFD_RELOC_ARM_LDRS_PC_G0:
24286 case BFD_RELOC_ARM_LDRS_PC_G1:
24287 case BFD_RELOC_ARM_LDRS_PC_G2:
24288 case BFD_RELOC_ARM_LDRS_SB_G0:
24289 case BFD_RELOC_ARM_LDRS_SB_G1:
24290 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24291 gas_assert (!fixP->fx_done);
4962c51a 24292 if (!seg->use_rela_p)
477330fc
RM
24293 {
24294 bfd_vma insn;
24295 bfd_vma addend_abs = abs (value);
4962c51a 24296
477330fc
RM
24297 /* Check that the absolute value of the addend can be
24298 encoded in 8 bits. */
24299 if (addend_abs >= 0x100)
4962c51a 24300 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24301 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24302 (unsigned long) addend_abs);
24303
24304 /* Extract the instruction. */
24305 insn = md_chars_to_number (buf, INSN_SIZE);
24306
24307 /* If the addend is negative, clear bit 23 of the instruction.
24308 Otherwise set it. */
24309 if (value < 0)
24310 insn &= ~(1 << 23);
24311 else
24312 insn |= 1 << 23;
24313
24314 /* Place the first four bits of the absolute value of the addend
24315 into the first 4 bits of the instruction, and the remaining
24316 four into bits 8 .. 11. */
24317 insn &= 0xfffff0f0;
24318 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24319
24320 /* Update the instruction. */
24321 md_number_to_chars (buf, insn, INSN_SIZE);
24322 }
4962c51a
MS
24323 break;
24324
24325 case BFD_RELOC_ARM_LDC_PC_G0:
24326 case BFD_RELOC_ARM_LDC_PC_G1:
24327 case BFD_RELOC_ARM_LDC_PC_G2:
24328 case BFD_RELOC_ARM_LDC_SB_G0:
24329 case BFD_RELOC_ARM_LDC_SB_G1:
24330 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24331 gas_assert (!fixP->fx_done);
4962c51a 24332 if (!seg->use_rela_p)
477330fc
RM
24333 {
24334 bfd_vma insn;
24335 bfd_vma addend_abs = abs (value);
4962c51a 24336
477330fc
RM
24337 /* Check that the absolute value of the addend is a multiple of
24338 four and, when divided by four, fits in 8 bits. */
24339 if (addend_abs & 0x3)
4962c51a 24340 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24341 _("bad offset 0x%08lX (must be word-aligned)"),
24342 (unsigned long) addend_abs);
4962c51a 24343
477330fc 24344 if ((addend_abs >> 2) > 0xff)
4962c51a 24345 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24346 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24347 (unsigned long) addend_abs);
24348
24349 /* Extract the instruction. */
24350 insn = md_chars_to_number (buf, INSN_SIZE);
24351
24352 /* If the addend is negative, clear bit 23 of the instruction.
24353 Otherwise set it. */
24354 if (value < 0)
24355 insn &= ~(1 << 23);
24356 else
24357 insn |= 1 << 23;
24358
24359 /* Place the addend (divided by four) into the first eight
24360 bits of the instruction. */
24361 insn &= 0xfffffff0;
24362 insn |= addend_abs >> 2;
24363
24364 /* Update the instruction. */
24365 md_number_to_chars (buf, insn, INSN_SIZE);
24366 }
4962c51a
MS
24367 break;
24368
845b51d6
PB
24369 case BFD_RELOC_ARM_V4BX:
24370 /* This will need to go in the object file. */
24371 fixP->fx_done = 0;
24372 break;
24373
c19d1205
ZW
24374 case BFD_RELOC_UNUSED:
24375 default:
24376 as_bad_where (fixP->fx_file, fixP->fx_line,
24377 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24378 }
6c43fab6
RE
24379}
24380
c19d1205
ZW
24381/* Translate internal representation of relocation info to BFD target
24382 format. */
a737bd4d 24383
c19d1205 24384arelent *
00a97672 24385tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24386{
c19d1205
ZW
24387 arelent * reloc;
24388 bfd_reloc_code_real_type code;
a737bd4d 24389
325801bd 24390 reloc = XNEW (arelent);
a737bd4d 24391
325801bd 24392 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24393 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24394 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24395
2fc8bdac 24396 if (fixp->fx_pcrel)
00a97672
RS
24397 {
24398 if (section->use_rela_p)
24399 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24400 else
24401 fixp->fx_offset = reloc->address;
24402 }
c19d1205 24403 reloc->addend = fixp->fx_offset;
a737bd4d 24404
c19d1205 24405 switch (fixp->fx_r_type)
a737bd4d 24406 {
c19d1205
ZW
24407 case BFD_RELOC_8:
24408 if (fixp->fx_pcrel)
24409 {
24410 code = BFD_RELOC_8_PCREL;
24411 break;
24412 }
1a0670f3 24413 /* Fall through. */
a737bd4d 24414
c19d1205
ZW
24415 case BFD_RELOC_16:
24416 if (fixp->fx_pcrel)
24417 {
24418 code = BFD_RELOC_16_PCREL;
24419 break;
24420 }
1a0670f3 24421 /* Fall through. */
6c43fab6 24422
c19d1205
ZW
24423 case BFD_RELOC_32:
24424 if (fixp->fx_pcrel)
24425 {
24426 code = BFD_RELOC_32_PCREL;
24427 break;
24428 }
1a0670f3 24429 /* Fall through. */
a737bd4d 24430
b6895b4f
PB
24431 case BFD_RELOC_ARM_MOVW:
24432 if (fixp->fx_pcrel)
24433 {
24434 code = BFD_RELOC_ARM_MOVW_PCREL;
24435 break;
24436 }
1a0670f3 24437 /* Fall through. */
b6895b4f
PB
24438
24439 case BFD_RELOC_ARM_MOVT:
24440 if (fixp->fx_pcrel)
24441 {
24442 code = BFD_RELOC_ARM_MOVT_PCREL;
24443 break;
24444 }
1a0670f3 24445 /* Fall through. */
b6895b4f
PB
24446
24447 case BFD_RELOC_ARM_THUMB_MOVW:
24448 if (fixp->fx_pcrel)
24449 {
24450 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24451 break;
24452 }
1a0670f3 24453 /* Fall through. */
b6895b4f
PB
24454
24455 case BFD_RELOC_ARM_THUMB_MOVT:
24456 if (fixp->fx_pcrel)
24457 {
24458 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24459 break;
24460 }
1a0670f3 24461 /* Fall through. */
b6895b4f 24462
c19d1205
ZW
24463 case BFD_RELOC_NONE:
24464 case BFD_RELOC_ARM_PCREL_BRANCH:
24465 case BFD_RELOC_ARM_PCREL_BLX:
24466 case BFD_RELOC_RVA:
24467 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24468 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24469 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24470 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24471 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24472 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24473 case BFD_RELOC_VTABLE_ENTRY:
24474 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24475#ifdef TE_PE
24476 case BFD_RELOC_32_SECREL:
24477#endif
c19d1205
ZW
24478 code = fixp->fx_r_type;
24479 break;
a737bd4d 24480
00adf2d4
JB
24481 case BFD_RELOC_THUMB_PCREL_BLX:
24482#ifdef OBJ_ELF
24483 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24484 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24485 else
24486#endif
24487 code = BFD_RELOC_THUMB_PCREL_BLX;
24488 break;
24489
c19d1205
ZW
24490 case BFD_RELOC_ARM_LITERAL:
24491 case BFD_RELOC_ARM_HWLITERAL:
24492 /* If this is called then the a literal has
24493 been referenced across a section boundary. */
24494 as_bad_where (fixp->fx_file, fixp->fx_line,
24495 _("literal referenced across section boundary"));
24496 return NULL;
a737bd4d 24497
c19d1205 24498#ifdef OBJ_ELF
0855e32b
NS
24499 case BFD_RELOC_ARM_TLS_CALL:
24500 case BFD_RELOC_ARM_THM_TLS_CALL:
24501 case BFD_RELOC_ARM_TLS_DESCSEQ:
24502 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24503 case BFD_RELOC_ARM_GOT32:
24504 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24505 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24506 case BFD_RELOC_ARM_PLT32:
24507 case BFD_RELOC_ARM_TARGET1:
24508 case BFD_RELOC_ARM_ROSEGREL32:
24509 case BFD_RELOC_ARM_SBREL32:
24510 case BFD_RELOC_ARM_PREL31:
24511 case BFD_RELOC_ARM_TARGET2:
c19d1205 24512 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24513 case BFD_RELOC_ARM_PCREL_CALL:
24514 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24515 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24516 case BFD_RELOC_ARM_ALU_PC_G0:
24517 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24518 case BFD_RELOC_ARM_ALU_PC_G1:
24519 case BFD_RELOC_ARM_ALU_PC_G2:
24520 case BFD_RELOC_ARM_LDR_PC_G0:
24521 case BFD_RELOC_ARM_LDR_PC_G1:
24522 case BFD_RELOC_ARM_LDR_PC_G2:
24523 case BFD_RELOC_ARM_LDRS_PC_G0:
24524 case BFD_RELOC_ARM_LDRS_PC_G1:
24525 case BFD_RELOC_ARM_LDRS_PC_G2:
24526 case BFD_RELOC_ARM_LDC_PC_G0:
24527 case BFD_RELOC_ARM_LDC_PC_G1:
24528 case BFD_RELOC_ARM_LDC_PC_G2:
24529 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24530 case BFD_RELOC_ARM_ALU_SB_G0:
24531 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24532 case BFD_RELOC_ARM_ALU_SB_G1:
24533 case BFD_RELOC_ARM_ALU_SB_G2:
24534 case BFD_RELOC_ARM_LDR_SB_G0:
24535 case BFD_RELOC_ARM_LDR_SB_G1:
24536 case BFD_RELOC_ARM_LDR_SB_G2:
24537 case BFD_RELOC_ARM_LDRS_SB_G0:
24538 case BFD_RELOC_ARM_LDRS_SB_G1:
24539 case BFD_RELOC_ARM_LDRS_SB_G2:
24540 case BFD_RELOC_ARM_LDC_SB_G0:
24541 case BFD_RELOC_ARM_LDC_SB_G1:
24542 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24543 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24544 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24545 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24546 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24547 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24548 code = fixp->fx_r_type;
24549 break;
a737bd4d 24550
0855e32b 24551 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24552 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24553 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24554 case BFD_RELOC_ARM_TLS_IE32:
24555 case BFD_RELOC_ARM_TLS_LDM32:
24556 /* BFD will include the symbol's address in the addend.
24557 But we don't want that, so subtract it out again here. */
24558 if (!S_IS_COMMON (fixp->fx_addsy))
24559 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24560 code = fixp->fx_r_type;
24561 break;
24562#endif
a737bd4d 24563
c19d1205
ZW
24564 case BFD_RELOC_ARM_IMMEDIATE:
24565 as_bad_where (fixp->fx_file, fixp->fx_line,
24566 _("internal relocation (type: IMMEDIATE) not fixed up"));
24567 return NULL;
a737bd4d 24568
c19d1205
ZW
24569 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24570 as_bad_where (fixp->fx_file, fixp->fx_line,
24571 _("ADRL used for a symbol not defined in the same file"));
24572 return NULL;
a737bd4d 24573
c19d1205 24574 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24575 if (section->use_rela_p)
24576 {
24577 code = fixp->fx_r_type;
24578 break;
24579 }
24580
c19d1205
ZW
24581 if (fixp->fx_addsy != NULL
24582 && !S_IS_DEFINED (fixp->fx_addsy)
24583 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24584 {
c19d1205
ZW
24585 as_bad_where (fixp->fx_file, fixp->fx_line,
24586 _("undefined local label `%s'"),
24587 S_GET_NAME (fixp->fx_addsy));
24588 return NULL;
a737bd4d
NC
24589 }
24590
c19d1205
ZW
24591 as_bad_where (fixp->fx_file, fixp->fx_line,
24592 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24593 return NULL;
a737bd4d 24594
c19d1205
ZW
24595 default:
24596 {
e0471c16 24597 const char * type;
6c43fab6 24598
c19d1205
ZW
24599 switch (fixp->fx_r_type)
24600 {
24601 case BFD_RELOC_NONE: type = "NONE"; break;
24602 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24603 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24604 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24605 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24606 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24607 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24608 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24609 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24610 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24611 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24612 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24613 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24614 default: type = _("<unknown>"); break;
24615 }
24616 as_bad_where (fixp->fx_file, fixp->fx_line,
24617 _("cannot represent %s relocation in this object file format"),
24618 type);
24619 return NULL;
24620 }
a737bd4d 24621 }
6c43fab6 24622
c19d1205
ZW
24623#ifdef OBJ_ELF
24624 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24625 && GOT_symbol
24626 && fixp->fx_addsy == GOT_symbol)
24627 {
24628 code = BFD_RELOC_ARM_GOTPC;
24629 reloc->addend = fixp->fx_offset = reloc->address;
24630 }
24631#endif
6c43fab6 24632
c19d1205 24633 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24634
c19d1205
ZW
24635 if (reloc->howto == NULL)
24636 {
24637 as_bad_where (fixp->fx_file, fixp->fx_line,
24638 _("cannot represent %s relocation in this object file format"),
24639 bfd_get_reloc_code_name (code));
24640 return NULL;
24641 }
6c43fab6 24642
c19d1205
ZW
24643 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24644 vtable entry to be used in the relocation's section offset. */
24645 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24646 reloc->address = fixp->fx_offset;
6c43fab6 24647
c19d1205 24648 return reloc;
6c43fab6
RE
24649}
24650
c19d1205 24651/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24652
c19d1205
ZW
24653void
24654cons_fix_new_arm (fragS * frag,
24655 int where,
24656 int size,
62ebcb5c
AM
24657 expressionS * exp,
24658 bfd_reloc_code_real_type reloc)
6c43fab6 24659{
c19d1205 24660 int pcrel = 0;
6c43fab6 24661
c19d1205
ZW
24662 /* Pick a reloc.
24663 FIXME: @@ Should look at CPU word size. */
24664 switch (size)
24665 {
24666 case 1:
62ebcb5c 24667 reloc = BFD_RELOC_8;
c19d1205
ZW
24668 break;
24669 case 2:
62ebcb5c 24670 reloc = BFD_RELOC_16;
c19d1205
ZW
24671 break;
24672 case 4:
24673 default:
62ebcb5c 24674 reloc = BFD_RELOC_32;
c19d1205
ZW
24675 break;
24676 case 8:
62ebcb5c 24677 reloc = BFD_RELOC_64;
c19d1205
ZW
24678 break;
24679 }
6c43fab6 24680
f0927246
NC
24681#ifdef TE_PE
24682 if (exp->X_op == O_secrel)
24683 {
24684 exp->X_op = O_symbol;
62ebcb5c 24685 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24686 }
24687#endif
24688
62ebcb5c 24689 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24690}
6c43fab6 24691
4343666d 24692#if defined (OBJ_COFF)
c19d1205
ZW
24693void
24694arm_validate_fix (fixS * fixP)
6c43fab6 24695{
c19d1205
ZW
24696 /* If the destination of the branch is a defined symbol which does not have
24697 the THUMB_FUNC attribute, then we must be calling a function which has
24698 the (interfacearm) attribute. We look for the Thumb entry point to that
24699 function and change the branch to refer to that function instead. */
24700 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24701 && fixP->fx_addsy != NULL
24702 && S_IS_DEFINED (fixP->fx_addsy)
24703 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24704 {
c19d1205 24705 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24706 }
c19d1205
ZW
24707}
24708#endif
6c43fab6 24709
267bf995 24710
c19d1205
ZW
24711int
24712arm_force_relocation (struct fix * fixp)
24713{
24714#if defined (OBJ_COFF) && defined (TE_PE)
24715 if (fixp->fx_r_type == BFD_RELOC_RVA)
24716 return 1;
24717#endif
6c43fab6 24718
267bf995
RR
24719 /* In case we have a call or a branch to a function in ARM ISA mode from
24720 a thumb function or vice-versa force the relocation. These relocations
24721 are cleared off for some cores that might have blx and simple transformations
24722 are possible. */
24723
24724#ifdef OBJ_ELF
24725 switch (fixp->fx_r_type)
24726 {
24727 case BFD_RELOC_ARM_PCREL_JUMP:
24728 case BFD_RELOC_ARM_PCREL_CALL:
24729 case BFD_RELOC_THUMB_PCREL_BLX:
24730 if (THUMB_IS_FUNC (fixp->fx_addsy))
24731 return 1;
24732 break;
24733
24734 case BFD_RELOC_ARM_PCREL_BLX:
24735 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24736 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24737 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24738 if (ARM_IS_FUNC (fixp->fx_addsy))
24739 return 1;
24740 break;
24741
24742 default:
24743 break;
24744 }
24745#endif
24746
b5884301
PB
24747 /* Resolve these relocations even if the symbol is extern or weak.
24748 Technically this is probably wrong due to symbol preemption.
24749 In practice these relocations do not have enough range to be useful
24750 at dynamic link time, and some code (e.g. in the Linux kernel)
24751 expects these references to be resolved. */
c19d1205
ZW
24752 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24753 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24754 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24755 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24756 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24757 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24758 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24759 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24760 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24761 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24762 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24763 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24764 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24765 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24766 return 0;
a737bd4d 24767
4962c51a
MS
24768 /* Always leave these relocations for the linker. */
24769 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24770 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24771 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24772 return 1;
24773
f0291e4c
PB
24774 /* Always generate relocations against function symbols. */
24775 if (fixp->fx_r_type == BFD_RELOC_32
24776 && fixp->fx_addsy
24777 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24778 return 1;
24779
c19d1205 24780 return generic_force_reloc (fixp);
404ff6b5
AH
24781}
24782
0ffdc86c 24783#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24784/* Relocations against function names must be left unadjusted,
24785 so that the linker can use this information to generate interworking
24786 stubs. The MIPS version of this function
c19d1205
ZW
24787 also prevents relocations that are mips-16 specific, but I do not
24788 know why it does this.
404ff6b5 24789
c19d1205
ZW
24790 FIXME:
24791 There is one other problem that ought to be addressed here, but
24792 which currently is not: Taking the address of a label (rather
24793 than a function) and then later jumping to that address. Such
24794 addresses also ought to have their bottom bit set (assuming that
24795 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24796
c19d1205
ZW
24797bfd_boolean
24798arm_fix_adjustable (fixS * fixP)
404ff6b5 24799{
c19d1205
ZW
24800 if (fixP->fx_addsy == NULL)
24801 return 1;
404ff6b5 24802
e28387c3
PB
24803 /* Preserve relocations against symbols with function type. */
24804 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24805 return FALSE;
e28387c3 24806
c19d1205
ZW
24807 if (THUMB_IS_FUNC (fixP->fx_addsy)
24808 && fixP->fx_subsy == NULL)
c921be7d 24809 return FALSE;
a737bd4d 24810
c19d1205
ZW
24811 /* We need the symbol name for the VTABLE entries. */
24812 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24813 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24814 return FALSE;
404ff6b5 24815
c19d1205
ZW
24816 /* Don't allow symbols to be discarded on GOT related relocs. */
24817 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24818 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24819 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24820 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24821 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24822 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24823 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24824 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24825 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24826 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24827 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24828 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24829 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24830 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24831 return FALSE;
a737bd4d 24832
4962c51a
MS
24833 /* Similarly for group relocations. */
24834 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24835 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24836 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24837 return FALSE;
4962c51a 24838
79947c54
CD
24839 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24840 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24841 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24842 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24843 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24844 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24845 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24846 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24847 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24848 return FALSE;
79947c54 24849
72d98d16
MG
24850 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24851 offsets, so keep these symbols. */
24852 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24853 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24854 return FALSE;
24855
c921be7d 24856 return TRUE;
a737bd4d 24857}
0ffdc86c
NC
24858#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24859
24860#ifdef OBJ_ELF
c19d1205
ZW
24861const char *
24862elf32_arm_target_format (void)
404ff6b5 24863{
c19d1205
ZW
24864#ifdef TE_SYMBIAN
24865 return (target_big_endian
24866 ? "elf32-bigarm-symbian"
24867 : "elf32-littlearm-symbian");
24868#elif defined (TE_VXWORKS)
24869 return (target_big_endian
24870 ? "elf32-bigarm-vxworks"
24871 : "elf32-littlearm-vxworks");
b38cadfb
NC
24872#elif defined (TE_NACL)
24873 return (target_big_endian
24874 ? "elf32-bigarm-nacl"
24875 : "elf32-littlearm-nacl");
c19d1205
ZW
24876#else
24877 if (target_big_endian)
24878 return "elf32-bigarm";
24879 else
24880 return "elf32-littlearm";
24881#endif
404ff6b5
AH
24882}
24883
c19d1205
ZW
24884void
24885armelf_frob_symbol (symbolS * symp,
24886 int * puntp)
404ff6b5 24887{
c19d1205
ZW
24888 elf_frob_symbol (symp, puntp);
24889}
24890#endif
404ff6b5 24891
c19d1205 24892/* MD interface: Finalization. */
a737bd4d 24893
c19d1205
ZW
24894void
24895arm_cleanup (void)
24896{
24897 literal_pool * pool;
a737bd4d 24898
e07e6e58
NC
24899 /* Ensure that all the IT blocks are properly closed. */
24900 check_it_blocks_finished ();
24901
c19d1205
ZW
24902 for (pool = list_of_pools; pool; pool = pool->next)
24903 {
5f4273c7 24904 /* Put it at the end of the relevant section. */
c19d1205
ZW
24905 subseg_set (pool->section, pool->sub_section);
24906#ifdef OBJ_ELF
24907 arm_elf_change_section ();
24908#endif
24909 s_ltorg (0);
24910 }
404ff6b5
AH
24911}
24912
cd000bff
DJ
24913#ifdef OBJ_ELF
24914/* Remove any excess mapping symbols generated for alignment frags in
24915 SEC. We may have created a mapping symbol before a zero byte
24916 alignment; remove it if there's a mapping symbol after the
24917 alignment. */
24918static void
24919check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24920 void *dummy ATTRIBUTE_UNUSED)
24921{
24922 segment_info_type *seginfo = seg_info (sec);
24923 fragS *fragp;
24924
24925 if (seginfo == NULL || seginfo->frchainP == NULL)
24926 return;
24927
24928 for (fragp = seginfo->frchainP->frch_root;
24929 fragp != NULL;
24930 fragp = fragp->fr_next)
24931 {
24932 symbolS *sym = fragp->tc_frag_data.last_map;
24933 fragS *next = fragp->fr_next;
24934
24935 /* Variable-sized frags have been converted to fixed size by
24936 this point. But if this was variable-sized to start with,
24937 there will be a fixed-size frag after it. So don't handle
24938 next == NULL. */
24939 if (sym == NULL || next == NULL)
24940 continue;
24941
24942 if (S_GET_VALUE (sym) < next->fr_address)
24943 /* Not at the end of this frag. */
24944 continue;
24945 know (S_GET_VALUE (sym) == next->fr_address);
24946
24947 do
24948 {
24949 if (next->tc_frag_data.first_map != NULL)
24950 {
24951 /* Next frag starts with a mapping symbol. Discard this
24952 one. */
24953 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24954 break;
24955 }
24956
24957 if (next->fr_next == NULL)
24958 {
24959 /* This mapping symbol is at the end of the section. Discard
24960 it. */
24961 know (next->fr_fix == 0 && next->fr_var == 0);
24962 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24963 break;
24964 }
24965
24966 /* As long as we have empty frags without any mapping symbols,
24967 keep looking. */
24968 /* If the next frag is non-empty and does not start with a
24969 mapping symbol, then this mapping symbol is required. */
24970 if (next->fr_address != next->fr_next->fr_address)
24971 break;
24972
24973 next = next->fr_next;
24974 }
24975 while (next != NULL);
24976 }
24977}
24978#endif
24979
c19d1205
ZW
24980/* Adjust the symbol table. This marks Thumb symbols as distinct from
24981 ARM ones. */
404ff6b5 24982
c19d1205
ZW
24983void
24984arm_adjust_symtab (void)
404ff6b5 24985{
c19d1205
ZW
24986#ifdef OBJ_COFF
24987 symbolS * sym;
404ff6b5 24988
c19d1205
ZW
24989 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24990 {
24991 if (ARM_IS_THUMB (sym))
24992 {
24993 if (THUMB_IS_FUNC (sym))
24994 {
24995 /* Mark the symbol as a Thumb function. */
24996 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24997 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24998 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24999
c19d1205
ZW
25000 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25001 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25002 else
25003 as_bad (_("%s: unexpected function type: %d"),
25004 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25005 }
25006 else switch (S_GET_STORAGE_CLASS (sym))
25007 {
25008 case C_EXT:
25009 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25010 break;
25011 case C_STAT:
25012 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25013 break;
25014 case C_LABEL:
25015 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25016 break;
25017 default:
25018 /* Do nothing. */
25019 break;
25020 }
25021 }
a737bd4d 25022
c19d1205
ZW
25023 if (ARM_IS_INTERWORK (sym))
25024 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25025 }
c19d1205
ZW
25026#endif
25027#ifdef OBJ_ELF
25028 symbolS * sym;
25029 char bind;
404ff6b5 25030
c19d1205 25031 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25032 {
c19d1205
ZW
25033 if (ARM_IS_THUMB (sym))
25034 {
25035 elf_symbol_type * elf_sym;
404ff6b5 25036
c19d1205
ZW
25037 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25038 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25039
b0796911
PB
25040 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25041 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25042 {
25043 /* If it's a .thumb_func, declare it as so,
25044 otherwise tag label as .code 16. */
25045 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25046 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25047 ST_BRANCH_TO_THUMB);
3ba67470 25048 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25049 elf_sym->internal_elf_sym.st_info =
25050 ELF_ST_INFO (bind, STT_ARM_16BIT);
25051 }
25052 }
25053 }
cd000bff
DJ
25054
25055 /* Remove any overlapping mapping symbols generated by alignment frags. */
25056 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25057 /* Now do generic ELF adjustments. */
25058 elf_adjust_symtab ();
c19d1205 25059#endif
404ff6b5
AH
25060}
25061
c19d1205 25062/* MD interface: Initialization. */
404ff6b5 25063
a737bd4d 25064static void
c19d1205 25065set_constant_flonums (void)
a737bd4d 25066{
c19d1205 25067 int i;
404ff6b5 25068
c19d1205
ZW
25069 for (i = 0; i < NUM_FLOAT_VALS; i++)
25070 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25071 abort ();
a737bd4d 25072}
404ff6b5 25073
3e9e4fcf
JB
25074/* Auto-select Thumb mode if it's the only available instruction set for the
25075 given architecture. */
25076
25077static void
25078autoselect_thumb_from_cpu_variant (void)
25079{
25080 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25081 opcode_select (16);
25082}
25083
c19d1205
ZW
25084void
25085md_begin (void)
a737bd4d 25086{
c19d1205
ZW
25087 unsigned mach;
25088 unsigned int i;
404ff6b5 25089
c19d1205
ZW
25090 if ( (arm_ops_hsh = hash_new ()) == NULL
25091 || (arm_cond_hsh = hash_new ()) == NULL
25092 || (arm_shift_hsh = hash_new ()) == NULL
25093 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25094 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25095 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25096 || (arm_reloc_hsh = hash_new ()) == NULL
25097 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25098 as_fatal (_("virtual memory exhausted"));
25099
25100 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25101 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25102 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25103 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25104 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25105 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25106 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25107 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25108 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25109 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25110 (void *) (v7m_psrs + i));
c19d1205 25111 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25112 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25113 for (i = 0;
25114 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25115 i++)
d3ce72d0 25116 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25117 (void *) (barrier_opt_names + i));
c19d1205 25118#ifdef OBJ_ELF
3da1d841
NC
25119 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25120 {
25121 struct reloc_entry * entry = reloc_names + i;
25122
25123 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25124 /* This makes encode_branch() use the EABI versions of this relocation. */
25125 entry->reloc = BFD_RELOC_UNUSED;
25126
25127 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25128 }
c19d1205
ZW
25129#endif
25130
25131 set_constant_flonums ();
404ff6b5 25132
c19d1205
ZW
25133 /* Set the cpu variant based on the command-line options. We prefer
25134 -mcpu= over -march= if both are set (as for GCC); and we prefer
25135 -mfpu= over any other way of setting the floating point unit.
25136 Use of legacy options with new options are faulted. */
e74cfd16 25137 if (legacy_cpu)
404ff6b5 25138 {
e74cfd16 25139 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25140 as_bad (_("use of old and new-style options to set CPU type"));
25141
25142 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25143 }
e74cfd16 25144 else if (!mcpu_cpu_opt)
c168ce07
TP
25145 {
25146 mcpu_cpu_opt = march_cpu_opt;
25147 dyn_mcpu_ext_opt = dyn_march_ext_opt;
25148 /* Avoid double free in arm_md_end. */
25149 dyn_march_ext_opt = NULL;
25150 }
404ff6b5 25151
e74cfd16 25152 if (legacy_fpu)
c19d1205 25153 {
e74cfd16 25154 if (mfpu_opt)
c19d1205 25155 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25156
25157 mfpu_opt = legacy_fpu;
25158 }
e74cfd16 25159 else if (!mfpu_opt)
03b1477f 25160 {
45eb4c1b
NS
25161#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25162 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25163 /* Some environments specify a default FPU. If they don't, infer it
25164 from the processor. */
e74cfd16 25165 if (mcpu_fpu_opt)
03b1477f
RE
25166 mfpu_opt = mcpu_fpu_opt;
25167 else
25168 mfpu_opt = march_fpu_opt;
39c2da32 25169#else
e74cfd16 25170 mfpu_opt = &fpu_default;
39c2da32 25171#endif
03b1477f
RE
25172 }
25173
e74cfd16 25174 if (!mfpu_opt)
03b1477f 25175 {
493cb6ef 25176 if (mcpu_cpu_opt != NULL)
e74cfd16 25177 mfpu_opt = &fpu_default;
493cb6ef 25178 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25179 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25180 else
e74cfd16 25181 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25182 }
25183
ee065d83 25184#ifdef CPU_DEFAULT
e74cfd16 25185 if (!mcpu_cpu_opt)
ee065d83 25186 {
e74cfd16
PB
25187 mcpu_cpu_opt = &cpu_default;
25188 selected_cpu = cpu_default;
ee065d83 25189 }
c168ce07
TP
25190 else if (dyn_mcpu_ext_opt)
25191 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
62785b09
TP
25192 else
25193 selected_cpu = *mcpu_cpu_opt;
e74cfd16 25194#else
c168ce07
TP
25195 if (mcpu_cpu_opt && dyn_mcpu_ext_opt)
25196 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
25197 else if (mcpu_cpu_opt)
e74cfd16 25198 selected_cpu = *mcpu_cpu_opt;
ee065d83 25199 else
e74cfd16 25200 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25201#endif
03b1477f 25202
e74cfd16 25203 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
25204 if (dyn_mcpu_ext_opt)
25205 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
03b1477f 25206
3e9e4fcf
JB
25207 autoselect_thumb_from_cpu_variant ();
25208
e74cfd16 25209 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25210
f17c130b 25211#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25212 {
7cc69913
NC
25213 unsigned int flags = 0;
25214
25215#if defined OBJ_ELF
25216 flags = meabi_flags;
d507cf36
PB
25217
25218 switch (meabi_flags)
33a392fb 25219 {
d507cf36 25220 case EF_ARM_EABI_UNKNOWN:
7cc69913 25221#endif
d507cf36
PB
25222 /* Set the flags in the private structure. */
25223 if (uses_apcs_26) flags |= F_APCS26;
25224 if (support_interwork) flags |= F_INTERWORK;
25225 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25226 if (pic_code) flags |= F_PIC;
e74cfd16 25227 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25228 flags |= F_SOFT_FLOAT;
25229
d507cf36
PB
25230 switch (mfloat_abi_opt)
25231 {
25232 case ARM_FLOAT_ABI_SOFT:
25233 case ARM_FLOAT_ABI_SOFTFP:
25234 flags |= F_SOFT_FLOAT;
25235 break;
33a392fb 25236
d507cf36
PB
25237 case ARM_FLOAT_ABI_HARD:
25238 if (flags & F_SOFT_FLOAT)
25239 as_bad (_("hard-float conflicts with specified fpu"));
25240 break;
25241 }
03b1477f 25242
e74cfd16
PB
25243 /* Using pure-endian doubles (even if soft-float). */
25244 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25245 flags |= F_VFP_FLOAT;
f17c130b 25246
fde78edd 25247#if defined OBJ_ELF
e74cfd16 25248 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25249 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25250 break;
25251
8cb51566 25252 case EF_ARM_EABI_VER4:
3a4a14e9 25253 case EF_ARM_EABI_VER5:
c19d1205 25254 /* No additional flags to set. */
d507cf36
PB
25255 break;
25256
25257 default:
25258 abort ();
25259 }
7cc69913 25260#endif
b99bd4ef
NC
25261 bfd_set_private_flags (stdoutput, flags);
25262
25263 /* We have run out flags in the COFF header to encode the
25264 status of ATPCS support, so instead we create a dummy,
c19d1205 25265 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25266 if (atpcs)
25267 {
25268 asection * sec;
25269
25270 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25271
25272 if (sec != NULL)
25273 {
25274 bfd_set_section_flags
25275 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25276 bfd_set_section_size (stdoutput, sec, 0);
25277 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25278 }
25279 }
7cc69913 25280 }
f17c130b 25281#endif
b99bd4ef
NC
25282
25283 /* Record the CPU type as well. */
2d447fca
JM
25284 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25285 mach = bfd_mach_arm_iWMMXt2;
25286 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25287 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25288 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25289 mach = bfd_mach_arm_XScale;
e74cfd16 25290 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25291 mach = bfd_mach_arm_ep9312;
e74cfd16 25292 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25293 mach = bfd_mach_arm_5TE;
e74cfd16 25294 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25295 {
e74cfd16 25296 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25297 mach = bfd_mach_arm_5T;
25298 else
25299 mach = bfd_mach_arm_5;
25300 }
e74cfd16 25301 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25302 {
e74cfd16 25303 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25304 mach = bfd_mach_arm_4T;
25305 else
25306 mach = bfd_mach_arm_4;
25307 }
e74cfd16 25308 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25309 mach = bfd_mach_arm_3M;
e74cfd16
PB
25310 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25311 mach = bfd_mach_arm_3;
25312 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25313 mach = bfd_mach_arm_2a;
25314 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25315 mach = bfd_mach_arm_2;
25316 else
25317 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25318
25319 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25320}
25321
c19d1205 25322/* Command line processing. */
b99bd4ef 25323
c19d1205
ZW
25324/* md_parse_option
25325 Invocation line includes a switch not recognized by the base assembler.
25326 See if it's a processor-specific option.
b99bd4ef 25327
c19d1205
ZW
25328 This routine is somewhat complicated by the need for backwards
25329 compatibility (since older releases of gcc can't be changed).
25330 The new options try to make the interface as compatible as
25331 possible with GCC.
b99bd4ef 25332
c19d1205 25333 New options (supported) are:
b99bd4ef 25334
c19d1205
ZW
25335 -mcpu=<cpu name> Assemble for selected processor
25336 -march=<architecture name> Assemble for selected architecture
25337 -mfpu=<fpu architecture> Assemble for selected FPU.
25338 -EB/-mbig-endian Big-endian
25339 -EL/-mlittle-endian Little-endian
25340 -k Generate PIC code
25341 -mthumb Start in Thumb mode
25342 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25343
278df34e 25344 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25345 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25346
c19d1205 25347 For now we will also provide support for:
b99bd4ef 25348
c19d1205
ZW
25349 -mapcs-32 32-bit Program counter
25350 -mapcs-26 26-bit Program counter
25351 -macps-float Floats passed in FP registers
25352 -mapcs-reentrant Reentrant code
25353 -matpcs
25354 (sometime these will probably be replaced with -mapcs=<list of options>
25355 and -matpcs=<list of options>)
b99bd4ef 25356
c19d1205
ZW
25357 The remaining options are only supported for back-wards compatibility.
25358 Cpu variants, the arm part is optional:
25359 -m[arm]1 Currently not supported.
25360 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25361 -m[arm]3 Arm 3 processor
25362 -m[arm]6[xx], Arm 6 processors
25363 -m[arm]7[xx][t][[d]m] Arm 7 processors
25364 -m[arm]8[10] Arm 8 processors
25365 -m[arm]9[20][tdmi] Arm 9 processors
25366 -mstrongarm[110[0]] StrongARM processors
25367 -mxscale XScale processors
25368 -m[arm]v[2345[t[e]]] Arm architectures
25369 -mall All (except the ARM1)
25370 FP variants:
25371 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25372 -mfpe-old (No float load/store multiples)
25373 -mvfpxd VFP Single precision
25374 -mvfp All VFP
25375 -mno-fpu Disable all floating point instructions
b99bd4ef 25376
c19d1205
ZW
25377 The following CPU names are recognized:
25378 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25379 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25380 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25381 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25382 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25383 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25384 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25385
c19d1205 25386 */
b99bd4ef 25387
c19d1205 25388const char * md_shortopts = "m:k";
b99bd4ef 25389
c19d1205
ZW
25390#ifdef ARM_BI_ENDIAN
25391#define OPTION_EB (OPTION_MD_BASE + 0)
25392#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25393#else
c19d1205
ZW
25394#if TARGET_BYTES_BIG_ENDIAN
25395#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25396#else
c19d1205
ZW
25397#define OPTION_EL (OPTION_MD_BASE + 1)
25398#endif
b99bd4ef 25399#endif
845b51d6 25400#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25401
c19d1205 25402struct option md_longopts[] =
b99bd4ef 25403{
c19d1205
ZW
25404#ifdef OPTION_EB
25405 {"EB", no_argument, NULL, OPTION_EB},
25406#endif
25407#ifdef OPTION_EL
25408 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25409#endif
845b51d6 25410 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25411 {NULL, no_argument, NULL, 0}
25412};
b99bd4ef 25413
c19d1205 25414size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25415
c19d1205 25416struct arm_option_table
b99bd4ef 25417{
0198d5e6
TC
25418 const char * option; /* Option name to match. */
25419 const char * help; /* Help information. */
25420 int * var; /* Variable to change. */
25421 int value; /* What to change it to. */
25422 const char * deprecated; /* If non-null, print this message. */
c19d1205 25423};
b99bd4ef 25424
c19d1205
ZW
25425struct arm_option_table arm_opts[] =
25426{
25427 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25428 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25429 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25430 &support_interwork, 1, NULL},
25431 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25432 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25433 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25434 1, NULL},
25435 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25436 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25437 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25438 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25439 NULL},
b99bd4ef 25440
c19d1205
ZW
25441 /* These are recognized by the assembler, but have no affect on code. */
25442 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25443 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25444
25445 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25446 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25447 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25448 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25449 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25450 {NULL, NULL, NULL, 0, NULL}
25451};
25452
25453struct arm_legacy_option_table
25454{
0198d5e6
TC
25455 const char * option; /* Option name to match. */
25456 const arm_feature_set ** var; /* Variable to change. */
25457 const arm_feature_set value; /* What to change it to. */
25458 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25459};
b99bd4ef 25460
e74cfd16
PB
25461const struct arm_legacy_option_table arm_legacy_opts[] =
25462{
c19d1205
ZW
25463 /* DON'T add any new processors to this list -- we want the whole list
25464 to go away... Add them to the processors table instead. */
e74cfd16
PB
25465 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25466 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25467 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25468 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25469 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25470 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25471 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25472 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25473 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25474 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25475 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25476 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25477 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25478 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25479 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25480 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25481 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25482 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25483 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25484 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25485 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25486 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25487 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25488 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25489 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25490 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25491 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25492 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25493 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25494 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25495 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25496 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25497 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25498 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25499 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25500 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25501 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25502 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25503 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25504 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25505 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25506 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25507 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25508 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25509 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25510 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25511 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25512 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25513 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25514 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25515 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25516 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25517 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25518 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25519 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25520 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25521 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25522 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25523 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25524 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25525 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25526 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25527 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25528 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25529 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25530 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25531 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25532 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25533 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25534 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25535 N_("use -mcpu=strongarm110")},
e74cfd16 25536 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25537 N_("use -mcpu=strongarm1100")},
e74cfd16 25538 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25539 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25540 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25541 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25542 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25543
c19d1205 25544 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25545 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25546 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25547 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25548 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25549 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25550 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25551 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25552 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25553 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25554 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25555 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25556 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25557 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25558 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25559 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25560 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25561 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25562 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25563
c19d1205 25564 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
25565 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25566 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25567 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25568 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25569 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25570
e74cfd16 25571 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25572};
7ed4c4c5 25573
c19d1205 25574struct arm_cpu_option_table
7ed4c4c5 25575{
0198d5e6
TC
25576 const char * name;
25577 size_t name_len;
25578 const arm_feature_set value;
25579 const arm_feature_set ext;
c19d1205
ZW
25580 /* For some CPUs we assume an FPU unless the user explicitly sets
25581 -mfpu=... */
0198d5e6 25582 const arm_feature_set default_fpu;
ee065d83
PB
25583 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25584 case. */
0198d5e6 25585 const char * canonical_name;
c19d1205 25586};
7ed4c4c5 25587
c19d1205
ZW
25588/* This list should, at a minimum, contain all the cpu names
25589 recognized by GCC. */
996b5569 25590#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 25591
e74cfd16 25592static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25593{
996b5569
TP
25594 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25595 ARM_ARCH_NONE,
25596 FPU_ARCH_FPA),
25597 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25598 ARM_ARCH_NONE,
25599 FPU_ARCH_FPA),
25600 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25601 ARM_ARCH_NONE,
25602 FPU_ARCH_FPA),
25603 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25604 ARM_ARCH_NONE,
25605 FPU_ARCH_FPA),
25606 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25607 ARM_ARCH_NONE,
25608 FPU_ARCH_FPA),
25609 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25610 ARM_ARCH_NONE,
25611 FPU_ARCH_FPA),
25612 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25613 ARM_ARCH_NONE,
25614 FPU_ARCH_FPA),
25615 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25616 ARM_ARCH_NONE,
25617 FPU_ARCH_FPA),
25618 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25619 ARM_ARCH_NONE,
25620 FPU_ARCH_FPA),
25621 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25622 ARM_ARCH_NONE,
25623 FPU_ARCH_FPA),
25624 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25625 ARM_ARCH_NONE,
25626 FPU_ARCH_FPA),
25627 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25628 ARM_ARCH_NONE,
25629 FPU_ARCH_FPA),
25630 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25631 ARM_ARCH_NONE,
25632 FPU_ARCH_FPA),
25633 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25634 ARM_ARCH_NONE,
25635 FPU_ARCH_FPA),
25636 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25637 ARM_ARCH_NONE,
25638 FPU_ARCH_FPA),
25639 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25640 ARM_ARCH_NONE,
25641 FPU_ARCH_FPA),
25642 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25643 ARM_ARCH_NONE,
25644 FPU_ARCH_FPA),
25645 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25646 ARM_ARCH_NONE,
25647 FPU_ARCH_FPA),
25648 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25649 ARM_ARCH_NONE,
25650 FPU_ARCH_FPA),
25651 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25652 ARM_ARCH_NONE,
25653 FPU_ARCH_FPA),
25654 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25655 ARM_ARCH_NONE,
25656 FPU_ARCH_FPA),
25657 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25658 ARM_ARCH_NONE,
25659 FPU_ARCH_FPA),
25660 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25661 ARM_ARCH_NONE,
25662 FPU_ARCH_FPA),
25663 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25664 ARM_ARCH_NONE,
25665 FPU_ARCH_FPA),
25666 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25667 ARM_ARCH_NONE,
25668 FPU_ARCH_FPA),
25669 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25670 ARM_ARCH_NONE,
25671 FPU_ARCH_FPA),
25672 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25673 ARM_ARCH_NONE,
25674 FPU_ARCH_FPA),
25675 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25676 ARM_ARCH_NONE,
25677 FPU_ARCH_FPA),
25678 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25679 ARM_ARCH_NONE,
25680 FPU_ARCH_FPA),
25681 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25682 ARM_ARCH_NONE,
25683 FPU_ARCH_FPA),
25684 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25685 ARM_ARCH_NONE,
25686 FPU_ARCH_FPA),
25687 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25688 ARM_ARCH_NONE,
25689 FPU_ARCH_FPA),
25690 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25691 ARM_ARCH_NONE,
25692 FPU_ARCH_FPA),
25693 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25694 ARM_ARCH_NONE,
25695 FPU_ARCH_FPA),
25696 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25697 ARM_ARCH_NONE,
25698 FPU_ARCH_FPA),
25699 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25700 ARM_ARCH_NONE,
25701 FPU_ARCH_FPA),
25702 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25703 ARM_ARCH_NONE,
25704 FPU_ARCH_FPA),
25705 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25706 ARM_ARCH_NONE,
25707 FPU_ARCH_FPA),
25708 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25709 ARM_ARCH_NONE,
25710 FPU_ARCH_FPA),
25711 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25712 ARM_ARCH_NONE,
25713 FPU_ARCH_FPA),
25714 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25715 ARM_ARCH_NONE,
25716 FPU_ARCH_FPA),
25717 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25718 ARM_ARCH_NONE,
25719 FPU_ARCH_FPA),
25720 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25721 ARM_ARCH_NONE,
25722 FPU_ARCH_FPA),
25723 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25724 ARM_ARCH_NONE,
25725 FPU_ARCH_FPA),
25726 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25727 ARM_ARCH_NONE,
25728 FPU_ARCH_FPA),
25729 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25730 ARM_ARCH_NONE,
25731 FPU_ARCH_FPA),
25732
c19d1205
ZW
25733 /* For V5 or later processors we default to using VFP; but the user
25734 should really set the FPU type explicitly. */
996b5569
TP
25735 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25736 ARM_ARCH_NONE,
25737 FPU_ARCH_VFP_V2),
25738 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25739 ARM_ARCH_NONE,
25740 FPU_ARCH_VFP_V2),
25741 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25742 ARM_ARCH_NONE,
25743 FPU_ARCH_VFP_V2),
25744 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25745 ARM_ARCH_NONE,
25746 FPU_ARCH_VFP_V2),
25747 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25748 ARM_ARCH_NONE,
25749 FPU_ARCH_VFP_V2),
25750 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25751 ARM_ARCH_NONE,
25752 FPU_ARCH_VFP_V2),
25753 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25754 ARM_ARCH_NONE,
25755 FPU_ARCH_VFP_V2),
25756 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25757 ARM_ARCH_NONE,
25758 FPU_ARCH_VFP_V2),
25759 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25760 ARM_ARCH_NONE,
25761 FPU_ARCH_VFP_V2),
25762 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25763 ARM_ARCH_NONE,
25764 FPU_ARCH_VFP_V2),
25765 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
25766 ARM_ARCH_NONE,
25767 FPU_ARCH_VFP_V2),
25768 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
25769 ARM_ARCH_NONE,
25770 FPU_ARCH_VFP_V2),
25771 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
25772 ARM_ARCH_NONE,
25773 FPU_ARCH_VFP_V1),
25774 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
25775 ARM_ARCH_NONE,
25776 FPU_ARCH_VFP_V1),
25777 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
25778 ARM_ARCH_NONE,
25779 FPU_ARCH_VFP_V2),
25780 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
25781 ARM_ARCH_NONE,
25782 FPU_ARCH_VFP_V2),
25783 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
25784 ARM_ARCH_NONE,
25785 FPU_ARCH_VFP_V1),
25786 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
25787 ARM_ARCH_NONE,
25788 FPU_ARCH_VFP_V2),
25789 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
25790 ARM_ARCH_NONE,
25791 FPU_ARCH_VFP_V2),
25792 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
25793 ARM_ARCH_NONE,
25794 FPU_ARCH_VFP_V2),
25795 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
25796 ARM_ARCH_NONE,
25797 FPU_ARCH_VFP_V2),
25798 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
25799 ARM_ARCH_NONE,
25800 FPU_ARCH_VFP_V2),
25801 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
25802 ARM_ARCH_NONE,
25803 FPU_ARCH_VFP_V2),
25804 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
25805 ARM_ARCH_NONE,
25806 FPU_ARCH_VFP_V2),
25807 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
25808 ARM_ARCH_NONE,
25809 FPU_ARCH_VFP_V2),
25810 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
25811 ARM_ARCH_NONE,
25812 FPU_ARCH_VFP_V2),
25813 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
25814 ARM_ARCH_NONE,
25815 FPU_NONE),
25816 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
25817 ARM_ARCH_NONE,
25818 FPU_NONE),
25819 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
25820 ARM_ARCH_NONE,
25821 FPU_ARCH_VFP_V2),
25822 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
25823 ARM_ARCH_NONE,
25824 FPU_ARCH_VFP_V2),
25825 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
25826 ARM_ARCH_NONE,
25827 FPU_ARCH_VFP_V2),
25828 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
25829 ARM_ARCH_NONE,
25830 FPU_NONE),
25831 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
25832 ARM_ARCH_NONE,
25833 FPU_NONE),
25834 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
25835 ARM_ARCH_NONE,
25836 FPU_ARCH_VFP_V2),
25837 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
25838 ARM_ARCH_NONE,
25839 FPU_NONE),
25840 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
25841 ARM_ARCH_NONE,
25842 FPU_ARCH_VFP_V2),
25843 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
25844 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25845 FPU_NONE),
25846 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
25847 ARM_ARCH_NONE,
25848 FPU_ARCH_NEON_VFP_V4),
25849 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
25850 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25851 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25852 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
25853 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25854 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25855 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
25856 ARM_ARCH_NONE,
25857 FPU_ARCH_NEON_VFP_V4),
25858 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
25859 ARM_ARCH_NONE,
25860 FPU_ARCH_NEON_VFP_V4),
25861 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
25862 ARM_ARCH_NONE,
25863 FPU_ARCH_NEON_VFP_V4),
25864 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
25865 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25866 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25867 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
25868 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25869 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25870 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
25871 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25872 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
25873 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
25874 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 25875 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
25876 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
25877 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25878 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25879 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
25880 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25881 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25882 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
25883 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25884 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
25885 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
25886 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 25887 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
25888 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
25889 ARM_ARCH_NONE,
25890 FPU_NONE),
25891 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
25892 ARM_ARCH_NONE,
25893 FPU_ARCH_VFP_V3D16),
25894 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
25895 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25896 FPU_NONE),
25897 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
25898 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25899 FPU_ARCH_VFP_V3D16),
25900 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
25901 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25902 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
25903 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
25904 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25905 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
25906 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
25907 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25908 FPU_NONE),
25909 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
25910 ARM_ARCH_NONE,
25911 FPU_NONE),
25912 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
25913 ARM_ARCH_NONE,
25914 FPU_NONE),
25915 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
25916 ARM_ARCH_NONE,
25917 FPU_NONE),
25918 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
25919 ARM_ARCH_NONE,
25920 FPU_NONE),
25921 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
25922 ARM_ARCH_NONE,
25923 FPU_NONE),
25924 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
25925 ARM_ARCH_NONE,
25926 FPU_NONE),
25927 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
25928 ARM_ARCH_NONE,
25929 FPU_NONE),
25930 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
25931 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25932 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 25933
c19d1205 25934 /* ??? XSCALE is really an architecture. */
996b5569
TP
25935 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
25936 ARM_ARCH_NONE,
25937 FPU_ARCH_VFP_V2),
25938
c19d1205 25939 /* ??? iwmmxt is not a processor. */
996b5569
TP
25940 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
25941 ARM_ARCH_NONE,
25942 FPU_ARCH_VFP_V2),
25943 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
25944 ARM_ARCH_NONE,
25945 FPU_ARCH_VFP_V2),
25946 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
25947 ARM_ARCH_NONE,
25948 FPU_ARCH_VFP_V2),
25949
0198d5e6 25950 /* Maverick. */
996b5569
TP
25951 ARM_CPU_OPT ("ep9312", "ARM920T",
25952 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
25953 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
25954
da4339ed 25955 /* Marvell processors. */
996b5569
TP
25956 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
25957 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25958 FPU_ARCH_VFP_V3D16),
25959 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
25960 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25961 FPU_ARCH_NEON_VFP_V4),
da4339ed 25962
996b5569
TP
25963 /* APM X-Gene family. */
25964 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
25965 ARM_ARCH_NONE,
25966 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25967 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
25968 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25969 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25970
25971 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25972};
f3bad469 25973#undef ARM_CPU_OPT
7ed4c4c5 25974
c19d1205 25975struct arm_arch_option_table
7ed4c4c5 25976{
0198d5e6
TC
25977 const char * name;
25978 size_t name_len;
25979 const arm_feature_set value;
25980 const arm_feature_set default_fpu;
c19d1205 25981};
7ed4c4c5 25982
c19d1205
ZW
25983/* This list should, at a minimum, contain all the architecture names
25984 recognized by GCC. */
f3bad469 25985#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
0198d5e6 25986
e74cfd16 25987static const struct arm_arch_option_table arm_archs[] =
c19d1205 25988{
f3bad469
MGD
25989 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25990 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25991 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25992 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25993 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25994 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25995 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25996 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25997 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25998 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25999 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26000 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26001 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26002 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26003 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26004 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26005 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26006 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26007 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26008 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26009 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26010 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26011 kept to preserve existing behaviour. */
26012 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26013 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
26014 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26015 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26016 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26017 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26018 kept to preserve existing behaviour. */
26019 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26020 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
26021 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26022 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26023 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26024 /* The official spelling of the ARMv7 profile variants is the dashed form.
26025 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 26026 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 26027 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
26028 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26029 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26030 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26031 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26032 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26033 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 26034 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 26035 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 26036 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 26037 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 26038 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 26039 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
ced40572 26040 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
f3bad469
MGD
26041 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26042 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26043 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26044 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26045};
f3bad469 26046#undef ARM_ARCH_OPT
7ed4c4c5 26047
69133863 26048/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26049
69133863 26050struct arm_option_extension_value_table
c19d1205 26051{
0198d5e6
TC
26052 const char * name;
26053 size_t name_len;
26054 const arm_feature_set merge_value;
26055 const arm_feature_set clear_value;
d942732e
TP
26056 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26057 indicates that an extension is available for all architectures while
26058 ARM_ANY marks an empty entry. */
0198d5e6 26059 const arm_feature_set allowed_archs[2];
c19d1205 26060};
7ed4c4c5 26061
0198d5e6
TC
26062/* The following table must be in alphabetical order with a NULL last entry. */
26063
d942732e
TP
26064#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26065#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26066
69133863 26067static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26068{
823d2571
TG
26069 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26070 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26071 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26072 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26073 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26074 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26075 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26076 ARM_ARCH_V8_2A),
15afaa63
TP
26077 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26078 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26079 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26080 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26081 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26082 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26083 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26084 ARM_ARCH_V8_2A),
d942732e 26085 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26086 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26087 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26088 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26089 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26090 Thumb divide instruction. Due to this having the same name as the
26091 previous entry, this will be ignored when doing command-line parsing and
26092 only considered by build attribute selection code. */
26093 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26094 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26095 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26096 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26097 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26098 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26099 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26100 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26101 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26102 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26103 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26104 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26105 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26106 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26107 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26108 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26109 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26110 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26111 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
4d1464f2
MW
26112 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26113 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26114 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26115 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26116 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26117 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
d942732e 26118 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26119 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26120 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26121 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26122 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26123 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26124 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26125 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26126 | ARM_EXT_DIV),
26127 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26128 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26129 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26130 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26131 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26132};
f3bad469 26133#undef ARM_EXT_OPT
69133863
MGD
26134
26135/* ISA floating-point and Advanced SIMD extensions. */
26136struct arm_option_fpu_value_table
26137{
0198d5e6
TC
26138 const char * name;
26139 const arm_feature_set value;
c19d1205 26140};
7ed4c4c5 26141
c19d1205
ZW
26142/* This list should, at a minimum, contain all the fpu names
26143 recognized by GCC. */
69133863 26144static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26145{
26146 {"softfpa", FPU_NONE},
26147 {"fpe", FPU_ARCH_FPE},
26148 {"fpe2", FPU_ARCH_FPE},
26149 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26150 {"fpa", FPU_ARCH_FPA},
26151 {"fpa10", FPU_ARCH_FPA},
26152 {"fpa11", FPU_ARCH_FPA},
26153 {"arm7500fe", FPU_ARCH_FPA},
26154 {"softvfp", FPU_ARCH_VFP},
26155 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26156 {"vfp", FPU_ARCH_VFP_V2},
26157 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26158 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26159 {"vfp10", FPU_ARCH_VFP_V2},
26160 {"vfp10-r0", FPU_ARCH_VFP_V1},
26161 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26162 {"vfpv2", FPU_ARCH_VFP_V2},
26163 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26164 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26165 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26166 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26167 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26168 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26169 {"arm1020t", FPU_ARCH_VFP_V1},
26170 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26171 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26172 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26173 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26174 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26175 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26176 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26177 {"vfpv4", FPU_ARCH_VFP_V4},
26178 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26179 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26180 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26181 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26182 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26183 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26184 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26185 {"crypto-neon-fp-armv8",
26186 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26187 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26188 {"crypto-neon-fp-armv8.1",
26189 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26190 {NULL, ARM_ARCH_NONE}
26191};
26192
26193struct arm_option_value_table
26194{
e0471c16 26195 const char *name;
e74cfd16 26196 long value;
c19d1205 26197};
7ed4c4c5 26198
e74cfd16 26199static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26200{
26201 {"hard", ARM_FLOAT_ABI_HARD},
26202 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26203 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26204 {NULL, 0}
c19d1205 26205};
7ed4c4c5 26206
c19d1205 26207#ifdef OBJ_ELF
3a4a14e9 26208/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26209static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26210{
26211 {"gnu", EF_ARM_EABI_UNKNOWN},
26212 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26213 {"5", EF_ARM_EABI_VER5},
e74cfd16 26214 {NULL, 0}
c19d1205
ZW
26215};
26216#endif
7ed4c4c5 26217
c19d1205
ZW
26218struct arm_long_option_table
26219{
0198d5e6 26220 const char * option; /* Substring to match. */
e0471c16 26221 const char * help; /* Help information. */
17b9d67d 26222 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26223 const char * deprecated; /* If non-null, print this message. */
c19d1205 26224};
7ed4c4c5 26225
c921be7d 26226static bfd_boolean
c168ce07
TP
26227arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26228 arm_feature_set **ext_set_p)
7ed4c4c5 26229{
69133863 26230 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26231 extensions being added before being removed. We achieve this by having
26232 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26233 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26234 or removing it (0) and only allowing it to change in the order
69133863
MGD
26235 -1 -> 1 -> 0. */
26236 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26237 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26238 int adding_value = -1;
26239
c168ce07
TP
26240 if (!*ext_set_p)
26241 {
26242 *ext_set_p = XNEW (arm_feature_set);
26243 **ext_set_p = arm_arch_none;
26244 }
e74cfd16 26245
c19d1205 26246 while (str != NULL && *str != 0)
7ed4c4c5 26247 {
82b8a785 26248 const char *ext;
f3bad469 26249 size_t len;
7ed4c4c5 26250
c19d1205
ZW
26251 if (*str != '+')
26252 {
26253 as_bad (_("invalid architectural extension"));
c921be7d 26254 return FALSE;
c19d1205 26255 }
7ed4c4c5 26256
c19d1205
ZW
26257 str++;
26258 ext = strchr (str, '+');
7ed4c4c5 26259
c19d1205 26260 if (ext != NULL)
f3bad469 26261 len = ext - str;
c19d1205 26262 else
f3bad469 26263 len = strlen (str);
7ed4c4c5 26264
f3bad469 26265 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26266 {
26267 if (adding_value != 0)
26268 {
26269 adding_value = 0;
26270 opt = arm_extensions;
26271 }
26272
f3bad469 26273 len -= 2;
69133863
MGD
26274 str += 2;
26275 }
f3bad469 26276 else if (len > 0)
69133863
MGD
26277 {
26278 if (adding_value == -1)
26279 {
26280 adding_value = 1;
26281 opt = arm_extensions;
26282 }
26283 else if (adding_value != 1)
26284 {
26285 as_bad (_("must specify extensions to add before specifying "
26286 "those to remove"));
26287 return FALSE;
26288 }
26289 }
26290
f3bad469 26291 if (len == 0)
c19d1205
ZW
26292 {
26293 as_bad (_("missing architectural extension"));
c921be7d 26294 return FALSE;
c19d1205 26295 }
7ed4c4c5 26296
69133863
MGD
26297 gas_assert (adding_value != -1);
26298 gas_assert (opt != NULL);
26299
26300 /* Scan over the options table trying to find an exact match. */
26301 for (; opt->name != NULL; opt++)
f3bad469 26302 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26303 {
d942732e
TP
26304 int i, nb_allowed_archs =
26305 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26306 /* Check we can apply the extension to this architecture. */
d942732e
TP
26307 for (i = 0; i < nb_allowed_archs; i++)
26308 {
26309 /* Empty entry. */
26310 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26311 continue;
c168ce07 26312 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26313 break;
26314 }
26315 if (i == nb_allowed_archs)
69133863
MGD
26316 {
26317 as_bad (_("extension does not apply to the base architecture"));
26318 return FALSE;
26319 }
26320
26321 /* Add or remove the extension. */
26322 if (adding_value)
c168ce07
TP
26323 ARM_MERGE_FEATURE_SETS (**ext_set_p, **ext_set_p,
26324 opt->merge_value);
69133863 26325 else
c168ce07 26326 ARM_CLEAR_FEATURE (**ext_set_p, **ext_set_p, opt->clear_value);
69133863 26327
3d030cdb
TP
26328 /* Allowing Thumb division instructions for ARMv7 in autodetection
26329 rely on this break so that duplicate extensions (extensions
26330 with the same name as a previous extension in the list) are not
26331 considered for command-line parsing. */
c19d1205
ZW
26332 break;
26333 }
7ed4c4c5 26334
c19d1205
ZW
26335 if (opt->name == NULL)
26336 {
69133863
MGD
26337 /* Did we fail to find an extension because it wasn't specified in
26338 alphabetical order, or because it does not exist? */
26339
26340 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26341 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26342 break;
26343
26344 if (opt->name == NULL)
26345 as_bad (_("unknown architectural extension `%s'"), str);
26346 else
26347 as_bad (_("architectural extensions must be specified in "
26348 "alphabetical order"));
26349
c921be7d 26350 return FALSE;
c19d1205 26351 }
69133863
MGD
26352 else
26353 {
26354 /* We should skip the extension we've just matched the next time
26355 round. */
26356 opt++;
26357 }
7ed4c4c5 26358
c19d1205
ZW
26359 str = ext;
26360 };
7ed4c4c5 26361
c921be7d 26362 return TRUE;
c19d1205 26363}
7ed4c4c5 26364
c921be7d 26365static bfd_boolean
17b9d67d 26366arm_parse_cpu (const char *str)
7ed4c4c5 26367{
f3bad469 26368 const struct arm_cpu_option_table *opt;
82b8a785 26369 const char *ext = strchr (str, '+');
f3bad469 26370 size_t len;
7ed4c4c5 26371
c19d1205 26372 if (ext != NULL)
f3bad469 26373 len = ext - str;
7ed4c4c5 26374 else
f3bad469 26375 len = strlen (str);
7ed4c4c5 26376
f3bad469 26377 if (len == 0)
7ed4c4c5 26378 {
c19d1205 26379 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26380 return FALSE;
7ed4c4c5
NC
26381 }
26382
c19d1205 26383 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26384 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26385 {
c168ce07
TP
26386 mcpu_cpu_opt = &opt->value;
26387 if (!dyn_mcpu_ext_opt)
26388 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
26389 *dyn_mcpu_ext_opt = opt->ext;
e74cfd16 26390 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26391 if (opt->canonical_name)
ef8e6722
JW
26392 {
26393 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26394 strcpy (selected_cpu_name, opt->canonical_name);
26395 }
ee065d83
PB
26396 else
26397 {
f3bad469 26398 size_t i;
c921be7d 26399
ef8e6722
JW
26400 if (len >= sizeof selected_cpu_name)
26401 len = (sizeof selected_cpu_name) - 1;
26402
f3bad469 26403 for (i = 0; i < len; i++)
ee065d83
PB
26404 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26405 selected_cpu_name[i] = 0;
26406 }
7ed4c4c5 26407
c19d1205 26408 if (ext != NULL)
c168ce07 26409 return arm_parse_extension (ext, mcpu_cpu_opt, &dyn_mcpu_ext_opt);
7ed4c4c5 26410
c921be7d 26411 return TRUE;
c19d1205 26412 }
7ed4c4c5 26413
c19d1205 26414 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26415 return FALSE;
7ed4c4c5
NC
26416}
26417
c921be7d 26418static bfd_boolean
17b9d67d 26419arm_parse_arch (const char *str)
7ed4c4c5 26420{
e74cfd16 26421 const struct arm_arch_option_table *opt;
82b8a785 26422 const char *ext = strchr (str, '+');
f3bad469 26423 size_t len;
7ed4c4c5 26424
c19d1205 26425 if (ext != NULL)
f3bad469 26426 len = ext - str;
7ed4c4c5 26427 else
f3bad469 26428 len = strlen (str);
7ed4c4c5 26429
f3bad469 26430 if (len == 0)
7ed4c4c5 26431 {
c19d1205 26432 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26433 return FALSE;
7ed4c4c5
NC
26434 }
26435
c19d1205 26436 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26437 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26438 {
e74cfd16
PB
26439 march_cpu_opt = &opt->value;
26440 march_fpu_opt = &opt->default_fpu;
5f4273c7 26441 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26442
c19d1205 26443 if (ext != NULL)
c168ce07 26444 return arm_parse_extension (ext, march_cpu_opt, &dyn_march_ext_opt);
7ed4c4c5 26445
c921be7d 26446 return TRUE;
c19d1205
ZW
26447 }
26448
26449 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26450 return FALSE;
7ed4c4c5 26451}
eb043451 26452
c921be7d 26453static bfd_boolean
17b9d67d 26454arm_parse_fpu (const char * str)
c19d1205 26455{
69133863 26456 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26457
c19d1205
ZW
26458 for (opt = arm_fpus; opt->name != NULL; opt++)
26459 if (streq (opt->name, str))
26460 {
e74cfd16 26461 mfpu_opt = &opt->value;
c921be7d 26462 return TRUE;
c19d1205 26463 }
b99bd4ef 26464
c19d1205 26465 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26466 return FALSE;
c19d1205
ZW
26467}
26468
c921be7d 26469static bfd_boolean
17b9d67d 26470arm_parse_float_abi (const char * str)
b99bd4ef 26471{
e74cfd16 26472 const struct arm_option_value_table * opt;
b99bd4ef 26473
c19d1205
ZW
26474 for (opt = arm_float_abis; opt->name != NULL; opt++)
26475 if (streq (opt->name, str))
26476 {
26477 mfloat_abi_opt = opt->value;
c921be7d 26478 return TRUE;
c19d1205 26479 }
cc8a6dd0 26480
c19d1205 26481 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26482 return FALSE;
c19d1205 26483}
b99bd4ef 26484
c19d1205 26485#ifdef OBJ_ELF
c921be7d 26486static bfd_boolean
17b9d67d 26487arm_parse_eabi (const char * str)
c19d1205 26488{
e74cfd16 26489 const struct arm_option_value_table *opt;
cc8a6dd0 26490
c19d1205
ZW
26491 for (opt = arm_eabis; opt->name != NULL; opt++)
26492 if (streq (opt->name, str))
26493 {
26494 meabi_flags = opt->value;
c921be7d 26495 return TRUE;
c19d1205
ZW
26496 }
26497 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26498 return FALSE;
c19d1205
ZW
26499}
26500#endif
cc8a6dd0 26501
c921be7d 26502static bfd_boolean
17b9d67d 26503arm_parse_it_mode (const char * str)
e07e6e58 26504{
c921be7d 26505 bfd_boolean ret = TRUE;
e07e6e58
NC
26506
26507 if (streq ("arm", str))
26508 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26509 else if (streq ("thumb", str))
26510 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26511 else if (streq ("always", str))
26512 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26513 else if (streq ("never", str))
26514 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26515 else
26516 {
26517 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26518 "arm, thumb, always, or never."), str);
c921be7d 26519 ret = FALSE;
e07e6e58
NC
26520 }
26521
26522 return ret;
26523}
26524
2e6976a8 26525static bfd_boolean
17b9d67d 26526arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26527{
26528 codecomposer_syntax = TRUE;
26529 arm_comment_chars[0] = ';';
26530 arm_line_separator_chars[0] = 0;
26531 return TRUE;
26532}
26533
c19d1205
ZW
26534struct arm_long_option_table arm_long_opts[] =
26535{
26536 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26537 arm_parse_cpu, NULL},
26538 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26539 arm_parse_arch, NULL},
26540 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26541 arm_parse_fpu, NULL},
26542 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26543 arm_parse_float_abi, NULL},
26544#ifdef OBJ_ELF
7fac0536 26545 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26546 arm_parse_eabi, NULL},
26547#endif
e07e6e58
NC
26548 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26549 arm_parse_it_mode, NULL},
2e6976a8
DG
26550 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26551 arm_ccs_mode, NULL},
c19d1205
ZW
26552 {NULL, NULL, 0, NULL}
26553};
cc8a6dd0 26554
c19d1205 26555int
17b9d67d 26556md_parse_option (int c, const char * arg)
c19d1205
ZW
26557{
26558 struct arm_option_table *opt;
e74cfd16 26559 const struct arm_legacy_option_table *fopt;
c19d1205 26560 struct arm_long_option_table *lopt;
b99bd4ef 26561
c19d1205 26562 switch (c)
b99bd4ef 26563 {
c19d1205
ZW
26564#ifdef OPTION_EB
26565 case OPTION_EB:
26566 target_big_endian = 1;
26567 break;
26568#endif
cc8a6dd0 26569
c19d1205
ZW
26570#ifdef OPTION_EL
26571 case OPTION_EL:
26572 target_big_endian = 0;
26573 break;
26574#endif
b99bd4ef 26575
845b51d6
PB
26576 case OPTION_FIX_V4BX:
26577 fix_v4bx = TRUE;
26578 break;
26579
c19d1205
ZW
26580 case 'a':
26581 /* Listing option. Just ignore these, we don't support additional
26582 ones. */
26583 return 0;
b99bd4ef 26584
c19d1205
ZW
26585 default:
26586 for (opt = arm_opts; opt->option != NULL; opt++)
26587 {
26588 if (c == opt->option[0]
26589 && ((arg == NULL && opt->option[1] == 0)
26590 || streq (arg, opt->option + 1)))
26591 {
c19d1205 26592 /* If the option is deprecated, tell the user. */
278df34e 26593 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26594 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26595 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26596
c19d1205
ZW
26597 if (opt->var != NULL)
26598 *opt->var = opt->value;
cc8a6dd0 26599
c19d1205
ZW
26600 return 1;
26601 }
26602 }
b99bd4ef 26603
e74cfd16
PB
26604 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26605 {
26606 if (c == fopt->option[0]
26607 && ((arg == NULL && fopt->option[1] == 0)
26608 || streq (arg, fopt->option + 1)))
26609 {
e74cfd16 26610 /* If the option is deprecated, tell the user. */
278df34e 26611 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26612 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26613 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26614
26615 if (fopt->var != NULL)
26616 *fopt->var = &fopt->value;
26617
26618 return 1;
26619 }
26620 }
26621
c19d1205
ZW
26622 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26623 {
26624 /* These options are expected to have an argument. */
26625 if (c == lopt->option[0]
26626 && arg != NULL
26627 && strncmp (arg, lopt->option + 1,
26628 strlen (lopt->option + 1)) == 0)
26629 {
c19d1205 26630 /* If the option is deprecated, tell the user. */
278df34e 26631 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26632 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26633 _(lopt->deprecated));
b99bd4ef 26634
c19d1205
ZW
26635 /* Call the sup-option parser. */
26636 return lopt->func (arg + strlen (lopt->option) - 1);
26637 }
26638 }
a737bd4d 26639
c19d1205
ZW
26640 return 0;
26641 }
a394c00f 26642
c19d1205
ZW
26643 return 1;
26644}
a394c00f 26645
c19d1205
ZW
26646void
26647md_show_usage (FILE * fp)
a394c00f 26648{
c19d1205
ZW
26649 struct arm_option_table *opt;
26650 struct arm_long_option_table *lopt;
a394c00f 26651
c19d1205 26652 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26653
c19d1205
ZW
26654 for (opt = arm_opts; opt->option != NULL; opt++)
26655 if (opt->help != NULL)
26656 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26657
c19d1205
ZW
26658 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26659 if (lopt->help != NULL)
26660 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26661
c19d1205
ZW
26662#ifdef OPTION_EB
26663 fprintf (fp, _("\
26664 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26665#endif
26666
c19d1205
ZW
26667#ifdef OPTION_EL
26668 fprintf (fp, _("\
26669 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26670#endif
845b51d6
PB
26671
26672 fprintf (fp, _("\
26673 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26674}
ee065d83 26675
ee065d83 26676#ifdef OBJ_ELF
0198d5e6 26677
62b3e311
PB
26678typedef struct
26679{
26680 int val;
26681 arm_feature_set flags;
26682} cpu_arch_ver_table;
26683
2c6b98ea
TP
26684/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26685 chronologically for architectures, with an exception for ARMv6-M and
26686 ARMv6S-M due to legacy reasons. No new architecture should have a
26687 special case. This allows for build attribute selection results to be
26688 stable when new architectures are added. */
62b3e311
PB
26689static const cpu_arch_ver_table cpu_arch_ver[] =
26690{
2c6b98ea
TP
26691 {0, ARM_ARCH_V1},
26692 {0, ARM_ARCH_V2},
26693 {0, ARM_ARCH_V2S},
26694 {0, ARM_ARCH_V3},
26695 {0, ARM_ARCH_V3M},
26696 {1, ARM_ARCH_V4xM},
62b3e311 26697 {1, ARM_ARCH_V4},
2c6b98ea 26698 {2, ARM_ARCH_V4TxM},
62b3e311 26699 {2, ARM_ARCH_V4T},
2c6b98ea 26700 {3, ARM_ARCH_V5xM},
62b3e311 26701 {3, ARM_ARCH_V5},
2c6b98ea 26702 {3, ARM_ARCH_V5TxM},
ee3c0378 26703 {3, ARM_ARCH_V5T},
2c6b98ea 26704 {4, ARM_ARCH_V5TExP},
62b3e311
PB
26705 {4, ARM_ARCH_V5TE},
26706 {5, ARM_ARCH_V5TEJ},
26707 {6, ARM_ARCH_V6},
f4c65163 26708 {7, ARM_ARCH_V6Z},
2c6b98ea
TP
26709 {7, ARM_ARCH_V6KZ},
26710 {9, ARM_ARCH_V6K},
26711 {8, ARM_ARCH_V6T2},
26712 {8, ARM_ARCH_V6KT2},
26713 {8, ARM_ARCH_V6ZT2},
26714 {8, ARM_ARCH_V6KZT2},
26715
26716 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
26717 always selected build attributes to match those of ARMv6-M
26718 (resp. ARMv6S-M). However, due to these architectures being a strict
26719 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
26720 would be selected when fully respecting chronology of architectures.
26721 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
26722 move them before ARMv7 architectures. */
91e22acd 26723 {11, ARM_ARCH_V6M},
b2a5fbdc 26724 {12, ARM_ARCH_V6SM},
2c6b98ea
TP
26725
26726 {10, ARM_ARCH_V7},
26727 {10, ARM_ARCH_V7A},
62b3e311
PB
26728 {10, ARM_ARCH_V7R},
26729 {10, ARM_ARCH_V7M},
2c6b98ea
TP
26730 {10, ARM_ARCH_V7VE},
26731 {13, ARM_ARCH_V7EM},
bca38921 26732 {14, ARM_ARCH_V8A},
2c6b98ea
TP
26733 {14, ARM_ARCH_V8_1A},
26734 {14, ARM_ARCH_V8_2A},
26735 {14, ARM_ARCH_V8_3A},
ff8646ee 26736 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26737 {17, ARM_ARCH_V8M_MAIN},
ced40572 26738 {15, ARM_ARCH_V8R},
2c6b98ea 26739 {-1, ARM_ARCH_NONE}
62b3e311
PB
26740};
26741
ee3c0378 26742/* Set an attribute if it has not already been set by the user. */
0198d5e6 26743
ee3c0378
AS
26744static void
26745aeabi_set_attribute_int (int tag, int value)
26746{
26747 if (tag < 1
26748 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26749 || !attributes_set_explicitly[tag])
26750 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26751}
26752
26753static void
26754aeabi_set_attribute_string (int tag, const char *value)
26755{
26756 if (tag < 1
26757 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26758 || !attributes_set_explicitly[tag])
26759 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26760}
26761
2c6b98ea
TP
26762/* Return whether features in the *NEEDED feature set are available via
26763 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 26764
2c6b98ea
TP
26765static bfd_boolean
26766have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
26767 const arm_feature_set *needed)
26768{
26769 int i, nb_allowed_archs;
26770 arm_feature_set ext_fset;
26771 const struct arm_option_extension_value_table *opt;
26772
26773 ext_fset = arm_arch_none;
26774 for (opt = arm_extensions; opt->name != NULL; opt++)
26775 {
26776 /* Extension does not provide any feature we need. */
26777 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
26778 continue;
26779
26780 nb_allowed_archs =
26781 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
26782 for (i = 0; i < nb_allowed_archs; i++)
26783 {
26784 /* Empty entry. */
26785 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
26786 break;
26787
26788 /* Extension is available, add it. */
26789 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
26790 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
26791 }
26792 }
26793
26794 /* Can we enable all features in *needed? */
26795 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
26796}
26797
26798/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
26799 a given architecture feature set *ARCH_EXT_FSET including extension feature
26800 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
26801 - if true, check for an exact match of the architecture modulo extensions;
26802 - otherwise, select build attribute value of the first superset
26803 architecture released so that results remains stable when new architectures
26804 are added.
26805 For -march/-mcpu=all the build attribute value of the most featureful
26806 architecture is returned. Tag_CPU_arch_profile result is returned in
26807 PROFILE. */
0198d5e6 26808
2c6b98ea
TP
26809static int
26810get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
26811 const arm_feature_set *ext_fset,
26812 char *profile, int exact_match)
26813{
26814 arm_feature_set arch_fset;
26815 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
26816
26817 /* Select most featureful architecture with all its extensions if building
26818 for -march=all as the feature sets used to set build attributes. */
26819 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
26820 {
26821 /* Force revisiting of decision for each new architecture. */
26822 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
26823 *profile = 'A';
26824 return TAG_CPU_ARCH_V8;
26825 }
26826
26827 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
26828
26829 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
26830 {
26831 arm_feature_set known_arch_fset;
26832
26833 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
26834 if (exact_match)
26835 {
26836 /* Base architecture match user-specified architecture and
26837 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
26838 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
26839 {
26840 p_ver_ret = p_ver;
26841 goto found;
26842 }
26843 /* Base architecture match user-specified architecture only
26844 (eg. ARMv6-M in the same case as above). Record it in case we
26845 find a match with above condition. */
26846 else if (p_ver_ret == NULL
26847 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
26848 p_ver_ret = p_ver;
26849 }
26850 else
26851 {
26852
26853 /* Architecture has all features wanted. */
26854 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
26855 {
26856 arm_feature_set added_fset;
26857
26858 /* Compute features added by this architecture over the one
26859 recorded in p_ver_ret. */
26860 if (p_ver_ret != NULL)
26861 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
26862 p_ver_ret->flags);
26863 /* First architecture that match incl. with extensions, or the
26864 only difference in features over the recorded match is
26865 features that were optional and are now mandatory. */
26866 if (p_ver_ret == NULL
26867 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
26868 {
26869 p_ver_ret = p_ver;
26870 goto found;
26871 }
26872 }
26873 else if (p_ver_ret == NULL)
26874 {
26875 arm_feature_set needed_ext_fset;
26876
26877 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
26878
26879 /* Architecture has all features needed when using some
26880 extensions. Record it and continue searching in case there
26881 exist an architecture providing all needed features without
26882 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
26883 OS extension). */
26884 if (have_ext_for_needed_feat_p (&known_arch_fset,
26885 &needed_ext_fset))
26886 p_ver_ret = p_ver;
26887 }
26888 }
26889 }
26890
26891 if (p_ver_ret == NULL)
26892 return -1;
26893
26894found:
26895 /* Tag_CPU_arch_profile. */
26896 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
26897 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
26898 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
26899 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
26900 *profile = 'A';
26901 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
26902 *profile = 'R';
26903 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
26904 *profile = 'M';
26905 else
26906 *profile = '\0';
26907 return p_ver_ret->val;
26908}
26909
ee065d83 26910/* Set the public EABI object attributes. */
0198d5e6 26911
c168ce07 26912static void
ee065d83
PB
26913aeabi_set_public_attributes (void)
26914{
69239280 26915 char profile;
2c6b98ea 26916 int arch = -1;
90ec0d68 26917 int virt_sec = 0;
bca38921 26918 int fp16_optional = 0;
2c6b98ea
TP
26919 int skip_exact_match = 0;
26920 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 26921
54bab281
TP
26922 /* Autodetection mode, choose the architecture based the instructions
26923 actually used. */
26924 if (no_cpu_selected ())
26925 {
26926 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 26927
54bab281
TP
26928 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26929 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 26930
54bab281
TP
26931 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26932 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 26933
54bab281
TP
26934 /* Code run during relaxation relies on selected_cpu being set. */
26935 selected_cpu = flags;
26936 }
26937 /* Otherwise, choose the architecture based on the capabilities of the
26938 requested cpu. */
26939 else
26940 flags = selected_cpu;
26941 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
7f78eb34 26942
ddd7f988 26943 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26944 if (object_arch)
26945 {
2c6b98ea
TP
26946 ARM_CLEAR_FEATURE (flags_arch, *object_arch, fpu_any);
26947 flags_ext = arm_arch_none;
7a1d4c38 26948 }
2c6b98ea 26949 else
62b3e311 26950 {
2c6b98ea
TP
26951 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
26952 flags_ext = dyn_mcpu_ext_opt ? *dyn_mcpu_ext_opt : arm_arch_none;
26953 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
26954 }
26955
26956 /* When this function is run again after relaxation has happened there is no
26957 way to determine whether an architecture or CPU was specified by the user:
26958 - selected_cpu is set above for relaxation to work;
26959 - march_cpu_opt is not set if only -mcpu or .cpu is used;
26960 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
26961 Therefore, if not in -march=all case we first try an exact match and fall
26962 back to autodetection. */
26963 if (!skip_exact_match)
26964 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
26965 if (arch == -1)
26966 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
26967 if (arch == -1)
26968 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 26969
ee065d83
PB
26970 /* Tag_CPU_name. */
26971 if (selected_cpu_name[0])
26972 {
91d6fa6a 26973 char *q;
ee065d83 26974
91d6fa6a
NC
26975 q = selected_cpu_name;
26976 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26977 {
26978 int i;
5f4273c7 26979
91d6fa6a
NC
26980 q += 4;
26981 for (i = 0; q[i]; i++)
26982 q[i] = TOUPPER (q[i]);
ee065d83 26983 }
91d6fa6a 26984 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26985 }
62f3b8c8 26986
ee065d83 26987 /* Tag_CPU_arch. */
ee3c0378 26988 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26989
62b3e311 26990 /* Tag_CPU_arch_profile. */
69239280
MGD
26991 if (profile != '\0')
26992 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26993
15afaa63 26994 /* Tag_DSP_extension. */
6c290d53
TP
26995 if (dyn_mcpu_ext_opt && ARM_CPU_HAS_FEATURE (*dyn_mcpu_ext_opt, arm_ext_dsp))
26996 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 26997
2c6b98ea 26998 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 26999 /* Tag_ARM_ISA_use. */
ee3c0378 27000 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27001 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27002 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27003
ee065d83 27004 /* Tag_THUMB_ISA_use. */
ee3c0378 27005 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27006 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27007 {
27008 int thumb_isa_use;
27009
27010 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27011 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27012 thumb_isa_use = 3;
27013 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27014 thumb_isa_use = 2;
27015 else
27016 thumb_isa_use = 1;
27017 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27018 }
62f3b8c8 27019
ee065d83 27020 /* Tag_VFP_arch. */
a715796b
TG
27021 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27022 aeabi_set_attribute_int (Tag_VFP_arch,
27023 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27024 ? 7 : 8);
bca38921 27025 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27026 aeabi_set_attribute_int (Tag_VFP_arch,
27027 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27028 ? 5 : 6);
27029 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27030 {
27031 fp16_optional = 1;
27032 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27033 }
ada65aa3 27034 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27035 {
27036 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27037 fp16_optional = 1;
27038 }
ee3c0378
AS
27039 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27040 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27041 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27042 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27043 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27044
4547cb56
NC
27045 /* Tag_ABI_HardFP_use. */
27046 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27047 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27048 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27049
ee065d83 27050 /* Tag_WMMX_arch. */
ee3c0378
AS
27051 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27052 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27053 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27054 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27055
ee3c0378 27056 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27057 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27058 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27059 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27060 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27061 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27062 {
27063 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27064 {
27065 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27066 }
27067 else
27068 {
27069 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27070 fp16_optional = 1;
27071 }
27072 }
fa94de6b 27073
ee3c0378 27074 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27075 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27076 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27077
69239280
MGD
27078 /* Tag_DIV_use.
27079
27080 We set Tag_DIV_use to two when integer divide instructions have been used
27081 in ARM state, or when Thumb integer divide instructions have been used,
27082 but we have no architecture profile set, nor have we any ARM instructions.
27083
4ed7ed8d
TP
27084 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27085 by the base architecture.
bca38921 27086
69239280 27087 For new architectures we will have to check these tests. */
ced40572 27088 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27089 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27090 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27091 aeabi_set_attribute_int (Tag_DIV_use, 0);
27092 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27093 || (profile == '\0'
27094 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27095 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27096 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27097
27098 /* Tag_MP_extension_use. */
27099 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27100 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27101
27102 /* Tag Virtualization_use. */
27103 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27104 virt_sec |= 1;
27105 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27106 virt_sec |= 2;
27107 if (virt_sec != 0)
27108 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27109}
27110
c168ce07
TP
27111/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27112 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27113
c168ce07
TP
27114void
27115arm_md_post_relax (void)
27116{
27117 aeabi_set_public_attributes ();
27118 XDELETE (dyn_mcpu_ext_opt);
27119 dyn_mcpu_ext_opt = NULL;
27120 XDELETE (dyn_march_ext_opt);
27121 dyn_march_ext_opt = NULL;
27122}
27123
104d59d1 27124/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27125
ee065d83
PB
27126void
27127arm_md_end (void)
27128{
ee065d83
PB
27129 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27130 return;
27131
27132 aeabi_set_public_attributes ();
ee065d83 27133}
8463be01 27134#endif /* OBJ_ELF */
ee065d83 27135
ee065d83
PB
27136/* Parse a .cpu directive. */
27137
27138static void
27139s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27140{
e74cfd16 27141 const struct arm_cpu_option_table *opt;
ee065d83
PB
27142 char *name;
27143 char saved_char;
27144
27145 name = input_line_pointer;
5f4273c7 27146 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27147 input_line_pointer++;
27148 saved_char = *input_line_pointer;
27149 *input_line_pointer = 0;
27150
27151 /* Skip the first "all" entry. */
27152 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27153 if (streq (opt->name, name))
27154 {
c168ce07
TP
27155 mcpu_cpu_opt = &opt->value;
27156 if (!dyn_mcpu_ext_opt)
27157 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27158 *dyn_mcpu_ext_opt = opt->ext;
27159 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
ee065d83 27160 if (opt->canonical_name)
5f4273c7 27161 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27162 else
27163 {
27164 int i;
27165 for (i = 0; opt->name[i]; i++)
27166 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27167
ee065d83
PB
27168 selected_cpu_name[i] = 0;
27169 }
e74cfd16 27170 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27171 if (dyn_mcpu_ext_opt)
27172 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27173 *input_line_pointer = saved_char;
27174 demand_empty_rest_of_line ();
27175 return;
27176 }
27177 as_bad (_("unknown cpu `%s'"), name);
27178 *input_line_pointer = saved_char;
27179 ignore_rest_of_line ();
27180}
27181
ee065d83
PB
27182/* Parse a .arch directive. */
27183
27184static void
27185s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27186{
e74cfd16 27187 const struct arm_arch_option_table *opt;
ee065d83
PB
27188 char saved_char;
27189 char *name;
27190
27191 name = input_line_pointer;
5f4273c7 27192 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27193 input_line_pointer++;
27194 saved_char = *input_line_pointer;
27195 *input_line_pointer = 0;
27196
27197 /* Skip the first "all" entry. */
27198 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27199 if (streq (opt->name, name))
27200 {
e74cfd16 27201 mcpu_cpu_opt = &opt->value;
c168ce07
TP
27202 XDELETE (dyn_mcpu_ext_opt);
27203 dyn_mcpu_ext_opt = NULL;
27204 selected_cpu = *mcpu_cpu_opt;
5f4273c7 27205 strcpy (selected_cpu_name, opt->name);
c168ce07 27206 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
ee065d83
PB
27207 *input_line_pointer = saved_char;
27208 demand_empty_rest_of_line ();
27209 return;
27210 }
27211
27212 as_bad (_("unknown architecture `%s'\n"), name);
27213 *input_line_pointer = saved_char;
27214 ignore_rest_of_line ();
27215}
27216
7a1d4c38
PB
27217/* Parse a .object_arch directive. */
27218
27219static void
27220s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27221{
27222 const struct arm_arch_option_table *opt;
27223 char saved_char;
27224 char *name;
27225
27226 name = input_line_pointer;
5f4273c7 27227 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27228 input_line_pointer++;
27229 saved_char = *input_line_pointer;
27230 *input_line_pointer = 0;
27231
27232 /* Skip the first "all" entry. */
27233 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27234 if (streq (opt->name, name))
27235 {
27236 object_arch = &opt->value;
27237 *input_line_pointer = saved_char;
27238 demand_empty_rest_of_line ();
27239 return;
27240 }
27241
27242 as_bad (_("unknown architecture `%s'\n"), name);
27243 *input_line_pointer = saved_char;
27244 ignore_rest_of_line ();
27245}
27246
69133863
MGD
27247/* Parse a .arch_extension directive. */
27248
27249static void
27250s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27251{
27252 const struct arm_option_extension_value_table *opt;
d942732e 27253 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
27254 char saved_char;
27255 char *name;
27256 int adding_value = 1;
27257
27258 name = input_line_pointer;
27259 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27260 input_line_pointer++;
27261 saved_char = *input_line_pointer;
27262 *input_line_pointer = 0;
27263
27264 if (strlen (name) >= 2
27265 && strncmp (name, "no", 2) == 0)
27266 {
27267 adding_value = 0;
27268 name += 2;
27269 }
27270
27271 for (opt = arm_extensions; opt->name != NULL; opt++)
27272 if (streq (opt->name, name))
27273 {
d942732e
TP
27274 int i, nb_allowed_archs =
27275 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27276 for (i = 0; i < nb_allowed_archs; i++)
27277 {
27278 /* Empty entry. */
27279 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27280 continue;
27281 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
27282 break;
27283 }
27284
27285 if (i == nb_allowed_archs)
69133863
MGD
27286 {
27287 as_bad (_("architectural extension `%s' is not allowed for the "
27288 "current base architecture"), name);
27289 break;
27290 }
27291
c168ce07
TP
27292 if (!dyn_mcpu_ext_opt)
27293 {
27294 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27295 *dyn_mcpu_ext_opt = arm_arch_none;
27296 }
69133863 27297 if (adding_value)
c168ce07 27298 ARM_MERGE_FEATURE_SETS (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
5a70a223 27299 opt->merge_value);
69133863 27300 else
c168ce07
TP
27301 ARM_CLEAR_FEATURE (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
27302 opt->clear_value);
69133863 27303
c168ce07
TP
27304 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
27305 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
69133863
MGD
27306 *input_line_pointer = saved_char;
27307 demand_empty_rest_of_line ();
3d030cdb
TP
27308 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27309 on this return so that duplicate extensions (extensions with the
27310 same name as a previous extension in the list) are not considered
27311 for command-line parsing. */
69133863
MGD
27312 return;
27313 }
27314
27315 if (opt->name == NULL)
e673710a 27316 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27317
27318 *input_line_pointer = saved_char;
27319 ignore_rest_of_line ();
27320}
27321
ee065d83
PB
27322/* Parse a .fpu directive. */
27323
27324static void
27325s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27326{
69133863 27327 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27328 char saved_char;
27329 char *name;
27330
27331 name = input_line_pointer;
5f4273c7 27332 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27333 input_line_pointer++;
27334 saved_char = *input_line_pointer;
27335 *input_line_pointer = 0;
5f4273c7 27336
ee065d83
PB
27337 for (opt = arm_fpus; opt->name != NULL; opt++)
27338 if (streq (opt->name, name))
27339 {
e74cfd16
PB
27340 mfpu_opt = &opt->value;
27341 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27342 if (dyn_mcpu_ext_opt)
27343 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27344 *input_line_pointer = saved_char;
27345 demand_empty_rest_of_line ();
27346 return;
27347 }
27348
27349 as_bad (_("unknown floating point format `%s'\n"), name);
27350 *input_line_pointer = saved_char;
27351 ignore_rest_of_line ();
27352}
ee065d83 27353
794ba86a 27354/* Copy symbol information. */
f31fef98 27355
794ba86a
DJ
27356void
27357arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27358{
27359 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27360}
e04befd0 27361
f31fef98 27362#ifdef OBJ_ELF
e04befd0
AS
27363/* Given a symbolic attribute NAME, return the proper integer value.
27364 Returns -1 if the attribute is not known. */
f31fef98 27365
e04befd0
AS
27366int
27367arm_convert_symbolic_attribute (const char *name)
27368{
f31fef98
NC
27369 static const struct
27370 {
27371 const char * name;
27372 const int tag;
27373 }
27374 attribute_table[] =
27375 {
27376 /* When you modify this table you should
27377 also modify the list in doc/c-arm.texi. */
e04befd0 27378#define T(tag) {#tag, tag}
f31fef98
NC
27379 T (Tag_CPU_raw_name),
27380 T (Tag_CPU_name),
27381 T (Tag_CPU_arch),
27382 T (Tag_CPU_arch_profile),
27383 T (Tag_ARM_ISA_use),
27384 T (Tag_THUMB_ISA_use),
75375b3e 27385 T (Tag_FP_arch),
f31fef98
NC
27386 T (Tag_VFP_arch),
27387 T (Tag_WMMX_arch),
27388 T (Tag_Advanced_SIMD_arch),
27389 T (Tag_PCS_config),
27390 T (Tag_ABI_PCS_R9_use),
27391 T (Tag_ABI_PCS_RW_data),
27392 T (Tag_ABI_PCS_RO_data),
27393 T (Tag_ABI_PCS_GOT_use),
27394 T (Tag_ABI_PCS_wchar_t),
27395 T (Tag_ABI_FP_rounding),
27396 T (Tag_ABI_FP_denormal),
27397 T (Tag_ABI_FP_exceptions),
27398 T (Tag_ABI_FP_user_exceptions),
27399 T (Tag_ABI_FP_number_model),
75375b3e 27400 T (Tag_ABI_align_needed),
f31fef98 27401 T (Tag_ABI_align8_needed),
75375b3e 27402 T (Tag_ABI_align_preserved),
f31fef98
NC
27403 T (Tag_ABI_align8_preserved),
27404 T (Tag_ABI_enum_size),
27405 T (Tag_ABI_HardFP_use),
27406 T (Tag_ABI_VFP_args),
27407 T (Tag_ABI_WMMX_args),
27408 T (Tag_ABI_optimization_goals),
27409 T (Tag_ABI_FP_optimization_goals),
27410 T (Tag_compatibility),
27411 T (Tag_CPU_unaligned_access),
75375b3e 27412 T (Tag_FP_HP_extension),
f31fef98
NC
27413 T (Tag_VFP_HP_extension),
27414 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27415 T (Tag_MPextension_use),
27416 T (Tag_DIV_use),
f31fef98
NC
27417 T (Tag_nodefaults),
27418 T (Tag_also_compatible_with),
27419 T (Tag_conformance),
27420 T (Tag_T2EE_use),
27421 T (Tag_Virtualization_use),
15afaa63 27422 T (Tag_DSP_extension),
cd21e546 27423 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27424#undef T
f31fef98 27425 };
e04befd0
AS
27426 unsigned int i;
27427
27428 if (name == NULL)
27429 return -1;
27430
f31fef98 27431 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27432 if (streq (name, attribute_table[i].name))
e04befd0
AS
27433 return attribute_table[i].tag;
27434
27435 return -1;
27436}
267bf995 27437
93ef582d
NC
27438/* Apply sym value for relocations only in the case that they are for
27439 local symbols in the same segment as the fixup and you have the
27440 respective architectural feature for blx and simple switches. */
0198d5e6 27441
267bf995 27442int
93ef582d 27443arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27444{
27445 if (fixP->fx_addsy
27446 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27447 /* PR 17444: If the local symbol is in a different section then a reloc
27448 will always be generated for it, so applying the symbol value now
27449 will result in a double offset being stored in the relocation. */
27450 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27451 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27452 {
27453 switch (fixP->fx_r_type)
27454 {
27455 case BFD_RELOC_ARM_PCREL_BLX:
27456 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27457 if (ARM_IS_FUNC (fixP->fx_addsy))
27458 return 1;
27459 break;
27460
27461 case BFD_RELOC_ARM_PCREL_CALL:
27462 case BFD_RELOC_THUMB_PCREL_BLX:
27463 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27464 return 1;
267bf995
RR
27465 break;
27466
27467 default:
27468 break;
27469 }
27470
27471 }
27472 return 0;
27473}
f31fef98 27474#endif /* OBJ_ELF */