]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Remove no-longer applicable maintainer entries
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
2571583a 2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
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);
dec41383
JW
238static const arm_feature_set arm_ext_v8_2 =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
49e8a725
SN
240static const arm_feature_set arm_ext_v8_3 =
241 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
242
243static const arm_feature_set arm_arch_any = ARM_ANY;
49fa50ef 244#ifdef OBJ_ELF
2c6b98ea 245static const arm_feature_set fpu_any = FPU_ANY;
49fa50ef 246#endif
f85d59c3 247static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
248static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
249static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
250
2d447fca 251static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 252 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 253static const arm_feature_set arm_cext_iwmmxt =
823d2571 254 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 255static const arm_feature_set arm_cext_xscale =
823d2571 256 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 257static const arm_feature_set arm_cext_maverick =
823d2571
TG
258 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
259static const arm_feature_set fpu_fpa_ext_v1 =
260 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
261static const arm_feature_set fpu_fpa_ext_v2 =
262 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 263static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
264 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
265static const arm_feature_set fpu_vfp_ext_v1 =
266 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
267static const arm_feature_set fpu_vfp_ext_v2 =
268 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
269static const arm_feature_set fpu_vfp_ext_v3xd =
270 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
271static const arm_feature_set fpu_vfp_ext_v3 =
272 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 273static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
274 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
275static const arm_feature_set fpu_neon_ext_v1 =
276 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 277static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 278 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 279#ifdef OBJ_ELF
823d2571
TG
280static const arm_feature_set fpu_vfp_fp16 =
281 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
282static const arm_feature_set fpu_neon_ext_fma =
283 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 284#endif
823d2571
TG
285static const arm_feature_set fpu_vfp_ext_fma =
286 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 287static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 288 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 289static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 290 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 291static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 292 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 293static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 294 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 295static const arm_feature_set crc_ext_armv8 =
823d2571 296 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 297static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 298 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
c604a79a
JW
299static const arm_feature_set fpu_neon_ext_dotprod =
300 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
e74cfd16 301
33a392fb 302static int mfloat_abi_opt = -1;
e74cfd16
PB
303/* Record user cpu selection for object attributes. */
304static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 305/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 306static char selected_cpu_name[20];
8d67f500 307
aacf0b33
KT
308extern FLONUM_TYPE generic_floating_point_number;
309
8d67f500
NC
310/* Return if no cpu was selected on command-line. */
311static bfd_boolean
312no_cpu_selected (void)
313{
823d2571 314 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
315}
316
7cc69913 317#ifdef OBJ_ELF
deeaaff8
DJ
318# ifdef EABI_DEFAULT
319static int meabi_flags = EABI_DEFAULT;
320# else
d507cf36 321static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 322# endif
e1da3f5b 323
ee3c0378
AS
324static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
325
e1da3f5b 326bfd_boolean
5f4273c7 327arm_is_eabi (void)
e1da3f5b
PB
328{
329 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
330}
7cc69913 331#endif
b99bd4ef 332
b99bd4ef 333#ifdef OBJ_ELF
c19d1205 334/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
335symbolS * GOT_symbol;
336#endif
337
b99bd4ef
NC
338/* 0: assemble for ARM,
339 1: assemble for Thumb,
340 2: assemble for Thumb even though target CPU does not support thumb
341 instructions. */
342static int thumb_mode = 0;
8dc2430f
NC
343/* A value distinct from the possible values for thumb_mode that we
344 can use to record whether thumb_mode has been copied into the
345 tc_frag_data field of a frag. */
346#define MODE_RECORDED (1 << 4)
b99bd4ef 347
e07e6e58
NC
348/* Specifies the intrinsic IT insn behavior mode. */
349enum implicit_it_mode
350{
351 IMPLICIT_IT_MODE_NEVER = 0x00,
352 IMPLICIT_IT_MODE_ARM = 0x01,
353 IMPLICIT_IT_MODE_THUMB = 0x02,
354 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
355};
356static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
357
c19d1205
ZW
358/* If unified_syntax is true, we are processing the new unified
359 ARM/Thumb syntax. Important differences from the old ARM mode:
360
361 - Immediate operands do not require a # prefix.
362 - Conditional affixes always appear at the end of the
363 instruction. (For backward compatibility, those instructions
364 that formerly had them in the middle, continue to accept them
365 there.)
366 - The IT instruction may appear, and if it does is validated
367 against subsequent conditional affixes. It does not generate
368 machine code.
369
370 Important differences from the old Thumb mode:
371
372 - Immediate operands do not require a # prefix.
373 - Most of the V6T2 instructions are only available in unified mode.
374 - The .N and .W suffixes are recognized and honored (it is an error
375 if they cannot be honored).
376 - All instructions set the flags if and only if they have an 's' affix.
377 - Conditional affixes may be used. They are validated against
378 preceding IT instructions. Unlike ARM mode, you cannot use a
379 conditional affix except in the scope of an IT instruction. */
380
381static bfd_boolean unified_syntax = FALSE;
b99bd4ef 382
bacebabc
RM
383/* An immediate operand can start with #, and ld*, st*, pld operands
384 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
385 before a [, which can appear as the first operand for pld.
386 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
387const char arm_symbol_chars[] = "#[]{}";
bacebabc 388
5287ad62
JB
389enum neon_el_type
390{
dcbf9037 391 NT_invtype,
5287ad62
JB
392 NT_untyped,
393 NT_integer,
394 NT_float,
395 NT_poly,
396 NT_signed,
dcbf9037 397 NT_unsigned
5287ad62
JB
398};
399
400struct neon_type_el
401{
402 enum neon_el_type type;
403 unsigned size;
404};
405
406#define NEON_MAX_TYPE_ELS 4
407
408struct neon_type
409{
410 struct neon_type_el el[NEON_MAX_TYPE_ELS];
411 unsigned elems;
412};
413
e07e6e58
NC
414enum it_instruction_type
415{
416 OUTSIDE_IT_INSN,
417 INSIDE_IT_INSN,
418 INSIDE_IT_LAST_INSN,
419 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 420 if inside, should be the last one. */
e07e6e58 421 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 422 i.e. BKPT and NOP. */
e07e6e58
NC
423 IT_INSN /* The IT insn has been parsed. */
424};
425
ad6cec43
MGD
426/* The maximum number of operands we need. */
427#define ARM_IT_MAX_OPERANDS 6
428
b99bd4ef
NC
429struct arm_it
430{
c19d1205 431 const char * error;
b99bd4ef 432 unsigned long instruction;
c19d1205
ZW
433 int size;
434 int size_req;
435 int cond;
037e8744
JB
436 /* "uncond_value" is set to the value in place of the conditional field in
437 unconditional versions of the instruction, or -1 if nothing is
438 appropriate. */
439 int uncond_value;
5287ad62 440 struct neon_type vectype;
88714cb8
DG
441 /* This does not indicate an actual NEON instruction, only that
442 the mnemonic accepts neon-style type suffixes. */
443 int is_neon;
0110f2b8
PB
444 /* Set to the opcode if the instruction needs relaxation.
445 Zero if the instruction is not relaxed. */
446 unsigned long relax;
b99bd4ef
NC
447 struct
448 {
449 bfd_reloc_code_real_type type;
c19d1205
ZW
450 expressionS exp;
451 int pc_rel;
b99bd4ef 452 } reloc;
b99bd4ef 453
e07e6e58
NC
454 enum it_instruction_type it_insn_type;
455
c19d1205
ZW
456 struct
457 {
458 unsigned reg;
ca3f61f7 459 signed int imm;
dcbf9037 460 struct neon_type_el vectype;
ca3f61f7
NC
461 unsigned present : 1; /* Operand present. */
462 unsigned isreg : 1; /* Operand was a register. */
463 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
464 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
465 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 466 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
467 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
468 instructions. This allows us to disambiguate ARM <-> vector insns. */
469 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 470 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 471 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 472 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
473 unsigned hasreloc : 1; /* Operand has relocation suffix. */
474 unsigned writeback : 1; /* Operand has trailing ! */
475 unsigned preind : 1; /* Preindexed address. */
476 unsigned postind : 1; /* Postindexed address. */
477 unsigned negative : 1; /* Index register was negated. */
478 unsigned shifted : 1; /* Shift applied to operation. */
479 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 480 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
481};
482
c19d1205 483static struct arm_it inst;
b99bd4ef
NC
484
485#define NUM_FLOAT_VALS 8
486
05d2d07e 487const char * fp_const[] =
b99bd4ef
NC
488{
489 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
490};
491
c19d1205 492/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
493#define MAX_LITTLENUMS 6
494
495LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
496
497#define FAIL (-1)
498#define SUCCESS (0)
499
500#define SUFF_S 1
501#define SUFF_D 2
502#define SUFF_E 3
503#define SUFF_P 4
504
c19d1205
ZW
505#define CP_T_X 0x00008000
506#define CP_T_Y 0x00400000
b99bd4ef 507
c19d1205
ZW
508#define CONDS_BIT 0x00100000
509#define LOAD_BIT 0x00100000
b99bd4ef
NC
510
511#define DOUBLE_LOAD_FLAG 0x00000001
512
513struct asm_cond
514{
d3ce72d0 515 const char * template_name;
c921be7d 516 unsigned long value;
b99bd4ef
NC
517};
518
c19d1205 519#define COND_ALWAYS 0xE
b99bd4ef 520
b99bd4ef
NC
521struct asm_psr
522{
d3ce72d0 523 const char * template_name;
c921be7d 524 unsigned long field;
b99bd4ef
NC
525};
526
62b3e311
PB
527struct asm_barrier_opt
528{
e797f7e0
MGD
529 const char * template_name;
530 unsigned long value;
531 const arm_feature_set arch;
62b3e311
PB
532};
533
2d2255b5 534/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
535#define SPSR_BIT (1 << 22)
536
c19d1205
ZW
537/* The individual PSR flag bits. */
538#define PSR_c (1 << 16)
539#define PSR_x (1 << 17)
540#define PSR_s (1 << 18)
541#define PSR_f (1 << 19)
b99bd4ef 542
c19d1205 543struct reloc_entry
bfae80f2 544{
0198d5e6 545 const char * name;
c921be7d 546 bfd_reloc_code_real_type reloc;
bfae80f2
RE
547};
548
5287ad62 549enum vfp_reg_pos
bfae80f2 550{
5287ad62
JB
551 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
552 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
553};
554
555enum vfp_ldstm_type
556{
557 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
558};
559
dcbf9037
JB
560/* Bits for DEFINED field in neon_typed_alias. */
561#define NTA_HASTYPE 1
562#define NTA_HASINDEX 2
563
564struct neon_typed_alias
565{
c921be7d
NC
566 unsigned char defined;
567 unsigned char index;
568 struct neon_type_el eltype;
dcbf9037
JB
569};
570
c19d1205
ZW
571/* ARM register categories. This includes coprocessor numbers and various
572 architecture extensions' registers. */
573enum arm_reg_type
bfae80f2 574{
c19d1205
ZW
575 REG_TYPE_RN,
576 REG_TYPE_CP,
577 REG_TYPE_CN,
578 REG_TYPE_FN,
579 REG_TYPE_VFS,
580 REG_TYPE_VFD,
5287ad62 581 REG_TYPE_NQ,
037e8744 582 REG_TYPE_VFSD,
5287ad62 583 REG_TYPE_NDQ,
dec41383 584 REG_TYPE_NSD,
037e8744 585 REG_TYPE_NSDQ,
c19d1205
ZW
586 REG_TYPE_VFC,
587 REG_TYPE_MVF,
588 REG_TYPE_MVD,
589 REG_TYPE_MVFX,
590 REG_TYPE_MVDX,
591 REG_TYPE_MVAX,
592 REG_TYPE_DSPSC,
593 REG_TYPE_MMXWR,
594 REG_TYPE_MMXWC,
595 REG_TYPE_MMXWCG,
596 REG_TYPE_XSCALE,
90ec0d68 597 REG_TYPE_RNB
bfae80f2
RE
598};
599
dcbf9037
JB
600/* Structure for a hash table entry for a register.
601 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
602 information which states whether a vector type or index is specified (for a
603 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
604struct reg_entry
605{
c921be7d 606 const char * name;
90ec0d68 607 unsigned int number;
c921be7d
NC
608 unsigned char type;
609 unsigned char builtin;
610 struct neon_typed_alias * neon;
6c43fab6
RE
611};
612
c19d1205 613/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 614const char * const reg_expected_msgs[] =
c19d1205
ZW
615{
616 N_("ARM register expected"),
617 N_("bad or missing co-processor number"),
618 N_("co-processor register expected"),
619 N_("FPA register expected"),
620 N_("VFP single precision register expected"),
5287ad62
JB
621 N_("VFP/Neon double precision register expected"),
622 N_("Neon quad precision register expected"),
037e8744 623 N_("VFP single or double precision register expected"),
5287ad62 624 N_("Neon double or quad precision register expected"),
dec41383 625 N_("Neon single or double precision register expected"),
037e8744 626 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
627 N_("VFP system register expected"),
628 N_("Maverick MVF register expected"),
629 N_("Maverick MVD register expected"),
630 N_("Maverick MVFX register expected"),
631 N_("Maverick MVDX register expected"),
632 N_("Maverick MVAX register expected"),
633 N_("Maverick DSPSC register expected"),
634 N_("iWMMXt data register expected"),
635 N_("iWMMXt control register expected"),
636 N_("iWMMXt scalar register expected"),
637 N_("XScale accumulator register expected"),
6c43fab6
RE
638};
639
c19d1205 640/* Some well known registers that we refer to directly elsewhere. */
bd340a04 641#define REG_R12 12
c19d1205
ZW
642#define REG_SP 13
643#define REG_LR 14
644#define REG_PC 15
404ff6b5 645
b99bd4ef
NC
646/* ARM instructions take 4bytes in the object file, Thumb instructions
647 take 2: */
c19d1205 648#define INSN_SIZE 4
b99bd4ef
NC
649
650struct asm_opcode
651{
652 /* Basic string to match. */
d3ce72d0 653 const char * template_name;
c19d1205
ZW
654
655 /* Parameters to instruction. */
5be8be5d 656 unsigned int operands[8];
c19d1205
ZW
657
658 /* Conditional tag - see opcode_lookup. */
659 unsigned int tag : 4;
b99bd4ef
NC
660
661 /* Basic instruction code. */
c19d1205 662 unsigned int avalue : 28;
b99bd4ef 663
c19d1205
ZW
664 /* Thumb-format instruction code. */
665 unsigned int tvalue;
b99bd4ef 666
90e4755a 667 /* Which architecture variant provides this instruction. */
c921be7d
NC
668 const arm_feature_set * avariant;
669 const arm_feature_set * tvariant;
c19d1205
ZW
670
671 /* Function to call to encode instruction in ARM format. */
672 void (* aencode) (void);
b99bd4ef 673
c19d1205
ZW
674 /* Function to call to encode instruction in Thumb format. */
675 void (* tencode) (void);
b99bd4ef
NC
676};
677
a737bd4d
NC
678/* Defines for various bits that we will want to toggle. */
679#define INST_IMMEDIATE 0x02000000
680#define OFFSET_REG 0x02000000
c19d1205 681#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
682#define SHIFT_BY_REG 0x00000010
683#define PRE_INDEX 0x01000000
684#define INDEX_UP 0x00800000
685#define WRITE_BACK 0x00200000
686#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 687#define CPSI_MMOD 0x00020000
90e4755a 688
a737bd4d
NC
689#define LITERAL_MASK 0xf000f000
690#define OPCODE_MASK 0xfe1fffff
691#define V4_STR_BIT 0x00000020
8335d6aa 692#define VLDR_VMOV_SAME 0x0040f000
90e4755a 693
efd81785
PB
694#define T2_SUBS_PC_LR 0xf3de8f00
695
a737bd4d 696#define DATA_OP_SHIFT 21
bada4342 697#define SBIT_SHIFT 20
90e4755a 698
ef8d22e6
PB
699#define T2_OPCODE_MASK 0xfe1fffff
700#define T2_DATA_OP_SHIFT 21
bada4342 701#define T2_SBIT_SHIFT 20
ef8d22e6 702
6530b175
NC
703#define A_COND_MASK 0xf0000000
704#define A_PUSH_POP_OP_MASK 0x0fff0000
705
706/* Opcodes for pushing/poping registers to/from the stack. */
707#define A1_OPCODE_PUSH 0x092d0000
708#define A2_OPCODE_PUSH 0x052d0004
709#define A2_OPCODE_POP 0x049d0004
710
a737bd4d
NC
711/* Codes to distinguish the arithmetic instructions. */
712#define OPCODE_AND 0
713#define OPCODE_EOR 1
714#define OPCODE_SUB 2
715#define OPCODE_RSB 3
716#define OPCODE_ADD 4
717#define OPCODE_ADC 5
718#define OPCODE_SBC 6
719#define OPCODE_RSC 7
720#define OPCODE_TST 8
721#define OPCODE_TEQ 9
722#define OPCODE_CMP 10
723#define OPCODE_CMN 11
724#define OPCODE_ORR 12
725#define OPCODE_MOV 13
726#define OPCODE_BIC 14
727#define OPCODE_MVN 15
90e4755a 728
ef8d22e6
PB
729#define T2_OPCODE_AND 0
730#define T2_OPCODE_BIC 1
731#define T2_OPCODE_ORR 2
732#define T2_OPCODE_ORN 3
733#define T2_OPCODE_EOR 4
734#define T2_OPCODE_ADD 8
735#define T2_OPCODE_ADC 10
736#define T2_OPCODE_SBC 11
737#define T2_OPCODE_SUB 13
738#define T2_OPCODE_RSB 14
739
a737bd4d
NC
740#define T_OPCODE_MUL 0x4340
741#define T_OPCODE_TST 0x4200
742#define T_OPCODE_CMN 0x42c0
743#define T_OPCODE_NEG 0x4240
744#define T_OPCODE_MVN 0x43c0
90e4755a 745
a737bd4d
NC
746#define T_OPCODE_ADD_R3 0x1800
747#define T_OPCODE_SUB_R3 0x1a00
748#define T_OPCODE_ADD_HI 0x4400
749#define T_OPCODE_ADD_ST 0xb000
750#define T_OPCODE_SUB_ST 0xb080
751#define T_OPCODE_ADD_SP 0xa800
752#define T_OPCODE_ADD_PC 0xa000
753#define T_OPCODE_ADD_I8 0x3000
754#define T_OPCODE_SUB_I8 0x3800
755#define T_OPCODE_ADD_I3 0x1c00
756#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 757
a737bd4d
NC
758#define T_OPCODE_ASR_R 0x4100
759#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
760#define T_OPCODE_LSR_R 0x40c0
761#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
762#define T_OPCODE_ASR_I 0x1000
763#define T_OPCODE_LSL_I 0x0000
764#define T_OPCODE_LSR_I 0x0800
b99bd4ef 765
a737bd4d
NC
766#define T_OPCODE_MOV_I8 0x2000
767#define T_OPCODE_CMP_I8 0x2800
768#define T_OPCODE_CMP_LR 0x4280
769#define T_OPCODE_MOV_HR 0x4600
770#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 771
a737bd4d
NC
772#define T_OPCODE_LDR_PC 0x4800
773#define T_OPCODE_LDR_SP 0x9800
774#define T_OPCODE_STR_SP 0x9000
775#define T_OPCODE_LDR_IW 0x6800
776#define T_OPCODE_STR_IW 0x6000
777#define T_OPCODE_LDR_IH 0x8800
778#define T_OPCODE_STR_IH 0x8000
779#define T_OPCODE_LDR_IB 0x7800
780#define T_OPCODE_STR_IB 0x7000
781#define T_OPCODE_LDR_RW 0x5800
782#define T_OPCODE_STR_RW 0x5000
783#define T_OPCODE_LDR_RH 0x5a00
784#define T_OPCODE_STR_RH 0x5200
785#define T_OPCODE_LDR_RB 0x5c00
786#define T_OPCODE_STR_RB 0x5400
c9b604bd 787
a737bd4d
NC
788#define T_OPCODE_PUSH 0xb400
789#define T_OPCODE_POP 0xbc00
b99bd4ef 790
2fc8bdac 791#define T_OPCODE_BRANCH 0xe000
b99bd4ef 792
a737bd4d 793#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 794#define THUMB_PP_PC_LR 0x0100
c19d1205 795#define THUMB_LOAD_BIT 0x0800
53365c0d 796#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
797
798#define BAD_ARGS _("bad arguments to instruction")
fdfde340 799#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
800#define BAD_PC _("r15 not allowed here")
801#define BAD_COND _("instruction cannot be conditional")
802#define BAD_OVERLAP _("registers may not be the same")
803#define BAD_HIREG _("lo register required")
804#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 805#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
806#define BAD_BRANCH _("branch must be last instruction in IT block")
807#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 808#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
809#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
810#define BAD_IT_COND _("incorrect condition in IT block")
811#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 812#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
813#define BAD_PC_ADDRESSING \
814 _("cannot use register index with PC-relative addressing")
815#define BAD_PC_WRITEBACK \
816 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
817#define BAD_RANGE _("branch out of range")
818#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 819#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 820#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 821
c921be7d
NC
822static struct hash_control * arm_ops_hsh;
823static struct hash_control * arm_cond_hsh;
824static struct hash_control * arm_shift_hsh;
825static struct hash_control * arm_psr_hsh;
826static struct hash_control * arm_v7m_psr_hsh;
827static struct hash_control * arm_reg_hsh;
828static struct hash_control * arm_reloc_hsh;
829static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 830
b99bd4ef
NC
831/* Stuff needed to resolve the label ambiguity
832 As:
833 ...
834 label: <insn>
835 may differ from:
836 ...
837 label:
5f4273c7 838 <insn> */
b99bd4ef
NC
839
840symbolS * last_label_seen;
b34976b6 841static int label_is_thumb_function_name = FALSE;
e07e6e58 842
3d0c9500
NC
843/* Literal pool structure. Held on a per-section
844 and per-sub-section basis. */
a737bd4d 845
c19d1205 846#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 847typedef struct literal_pool
b99bd4ef 848{
c921be7d
NC
849 expressionS literals [MAX_LITERAL_POOL_SIZE];
850 unsigned int next_free_entry;
851 unsigned int id;
852 symbolS * symbol;
853 segT section;
854 subsegT sub_section;
a8040cf2
NC
855#ifdef OBJ_ELF
856 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
857#endif
c921be7d 858 struct literal_pool * next;
8335d6aa 859 unsigned int alignment;
3d0c9500 860} literal_pool;
b99bd4ef 861
3d0c9500
NC
862/* Pointer to a linked list of literal pools. */
863literal_pool * list_of_pools = NULL;
e27ec89e 864
2e6976a8
DG
865typedef enum asmfunc_states
866{
867 OUTSIDE_ASMFUNC,
868 WAITING_ASMFUNC_NAME,
869 WAITING_ENDASMFUNC
870} asmfunc_states;
871
872static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
873
e07e6e58
NC
874#ifdef OBJ_ELF
875# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
876#else
877static struct current_it now_it;
878#endif
879
880static inline int
881now_it_compatible (int cond)
882{
883 return (cond & ~1) == (now_it.cc & ~1);
884}
885
886static inline int
887conditional_insn (void)
888{
889 return inst.cond != COND_ALWAYS;
890}
891
892static int in_it_block (void);
893
894static int handle_it_state (void);
895
896static void force_automatic_it_block_close (void);
897
c921be7d
NC
898static void it_fsm_post_encode (void);
899
e07e6e58
NC
900#define set_it_insn_type(type) \
901 do \
902 { \
903 inst.it_insn_type = type; \
904 if (handle_it_state () == FAIL) \
477330fc 905 return; \
e07e6e58
NC
906 } \
907 while (0)
908
c921be7d
NC
909#define set_it_insn_type_nonvoid(type, failret) \
910 do \
911 { \
912 inst.it_insn_type = type; \
913 if (handle_it_state () == FAIL) \
477330fc 914 return failret; \
c921be7d
NC
915 } \
916 while(0)
917
e07e6e58
NC
918#define set_it_insn_type_last() \
919 do \
920 { \
921 if (inst.cond == COND_ALWAYS) \
477330fc 922 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 923 else \
477330fc 924 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
925 } \
926 while (0)
927
c19d1205 928/* Pure syntax. */
b99bd4ef 929
c19d1205
ZW
930/* This array holds the chars that always start a comment. If the
931 pre-processor is disabled, these aren't very useful. */
2e6976a8 932char arm_comment_chars[] = "@";
3d0c9500 933
c19d1205
ZW
934/* This array holds the chars that only start a comment at the beginning of
935 a line. If the line seems to have the form '# 123 filename'
936 .line and .file directives will appear in the pre-processed output. */
937/* Note that input_file.c hand checks for '#' at the beginning of the
938 first line of the input file. This is because the compiler outputs
939 #NO_APP at the beginning of its output. */
940/* Also note that comments like this one will always work. */
941const char line_comment_chars[] = "#";
3d0c9500 942
2e6976a8 943char arm_line_separator_chars[] = ";";
b99bd4ef 944
c19d1205
ZW
945/* Chars that can be used to separate mant
946 from exp in floating point numbers. */
947const char EXP_CHARS[] = "eE";
3d0c9500 948
c19d1205
ZW
949/* Chars that mean this number is a floating point constant. */
950/* As in 0f12.456 */
951/* or 0d1.2345e12 */
b99bd4ef 952
c19d1205 953const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 954
c19d1205
ZW
955/* Prefix characters that indicate the start of an immediate
956 value. */
957#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 958
c19d1205
ZW
959/* Separator character handling. */
960
961#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
962
963static inline int
964skip_past_char (char ** str, char c)
965{
8ab8155f
NC
966 /* PR gas/14987: Allow for whitespace before the expected character. */
967 skip_whitespace (*str);
427d0db6 968
c19d1205
ZW
969 if (**str == c)
970 {
971 (*str)++;
972 return SUCCESS;
3d0c9500 973 }
c19d1205
ZW
974 else
975 return FAIL;
976}
c921be7d 977
c19d1205 978#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 979
c19d1205
ZW
980/* Arithmetic expressions (possibly involving symbols). */
981
982/* Return TRUE if anything in the expression is a bignum. */
983
0198d5e6 984static bfd_boolean
c19d1205
ZW
985walk_no_bignums (symbolS * sp)
986{
987 if (symbol_get_value_expression (sp)->X_op == O_big)
0198d5e6 988 return TRUE;
c19d1205
ZW
989
990 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 991 {
c19d1205
ZW
992 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
993 || (symbol_get_value_expression (sp)->X_op_symbol
994 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
995 }
996
0198d5e6 997 return FALSE;
3d0c9500
NC
998}
999
0198d5e6 1000static bfd_boolean in_my_get_expression = FALSE;
c19d1205
ZW
1001
1002/* Third argument to my_get_expression. */
1003#define GE_NO_PREFIX 0
1004#define GE_IMM_PREFIX 1
1005#define GE_OPT_PREFIX 2
5287ad62
JB
1006/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1007 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1008#define GE_OPT_PREFIX_BIG 3
a737bd4d 1009
b99bd4ef 1010static int
c19d1205 1011my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1012{
c19d1205
ZW
1013 char * save_in;
1014 segT seg;
b99bd4ef 1015
c19d1205
ZW
1016 /* In unified syntax, all prefixes are optional. */
1017 if (unified_syntax)
5287ad62 1018 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1019 : GE_OPT_PREFIX;
b99bd4ef 1020
c19d1205 1021 switch (prefix_mode)
b99bd4ef 1022 {
c19d1205
ZW
1023 case GE_NO_PREFIX: break;
1024 case GE_IMM_PREFIX:
1025 if (!is_immediate_prefix (**str))
1026 {
1027 inst.error = _("immediate expression requires a # prefix");
1028 return FAIL;
1029 }
1030 (*str)++;
1031 break;
1032 case GE_OPT_PREFIX:
5287ad62 1033 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1034 if (is_immediate_prefix (**str))
1035 (*str)++;
1036 break;
0198d5e6
TC
1037 default:
1038 abort ();
c19d1205 1039 }
b99bd4ef 1040
c19d1205 1041 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1042
c19d1205
ZW
1043 save_in = input_line_pointer;
1044 input_line_pointer = *str;
0198d5e6 1045 in_my_get_expression = TRUE;
c19d1205 1046 seg = expression (ep);
0198d5e6 1047 in_my_get_expression = FALSE;
c19d1205 1048
f86adc07 1049 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1050 {
f86adc07 1051 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1052 *str = input_line_pointer;
1053 input_line_pointer = save_in;
1054 if (inst.error == NULL)
f86adc07
NS
1055 inst.error = (ep->X_op == O_absent
1056 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1057 return 1;
1058 }
b99bd4ef 1059
c19d1205
ZW
1060#ifdef OBJ_AOUT
1061 if (seg != absolute_section
1062 && seg != text_section
1063 && seg != data_section
1064 && seg != bss_section
1065 && seg != undefined_section)
1066 {
1067 inst.error = _("bad segment");
1068 *str = input_line_pointer;
1069 input_line_pointer = save_in;
1070 return 1;
b99bd4ef 1071 }
87975d2a
AM
1072#else
1073 (void) seg;
c19d1205 1074#endif
b99bd4ef 1075
c19d1205
ZW
1076 /* Get rid of any bignums now, so that we don't generate an error for which
1077 we can't establish a line number later on. Big numbers are never valid
1078 in instructions, which is where this routine is always called. */
5287ad62
JB
1079 if (prefix_mode != GE_OPT_PREFIX_BIG
1080 && (ep->X_op == O_big
477330fc 1081 || (ep->X_add_symbol
5287ad62 1082 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1083 || (ep->X_op_symbol
5287ad62 1084 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1085 {
1086 inst.error = _("invalid constant");
1087 *str = input_line_pointer;
1088 input_line_pointer = save_in;
1089 return 1;
1090 }
b99bd4ef 1091
c19d1205
ZW
1092 *str = input_line_pointer;
1093 input_line_pointer = save_in;
0198d5e6 1094 return SUCCESS;
b99bd4ef
NC
1095}
1096
c19d1205
ZW
1097/* Turn a string in input_line_pointer into a floating point constant
1098 of type TYPE, and store the appropriate bytes in *LITP. The number
1099 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1100 returned, or NULL on OK.
b99bd4ef 1101
c19d1205
ZW
1102 Note that fp constants aren't represent in the normal way on the ARM.
1103 In big endian mode, things are as expected. However, in little endian
1104 mode fp constants are big-endian word-wise, and little-endian byte-wise
1105 within the words. For example, (double) 1.1 in big endian mode is
1106 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1107 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1108
c19d1205 1109 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1110
6d4af3c2 1111const char *
c19d1205
ZW
1112md_atof (int type, char * litP, int * sizeP)
1113{
1114 int prec;
1115 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1116 char *t;
1117 int i;
b99bd4ef 1118
c19d1205
ZW
1119 switch (type)
1120 {
1121 case 'f':
1122 case 'F':
1123 case 's':
1124 case 'S':
1125 prec = 2;
1126 break;
b99bd4ef 1127
c19d1205
ZW
1128 case 'd':
1129 case 'D':
1130 case 'r':
1131 case 'R':
1132 prec = 4;
1133 break;
b99bd4ef 1134
c19d1205
ZW
1135 case 'x':
1136 case 'X':
499ac353 1137 prec = 5;
c19d1205 1138 break;
b99bd4ef 1139
c19d1205
ZW
1140 case 'p':
1141 case 'P':
499ac353 1142 prec = 5;
c19d1205 1143 break;
a737bd4d 1144
c19d1205
ZW
1145 default:
1146 *sizeP = 0;
499ac353 1147 return _("Unrecognized or unsupported floating point constant");
c19d1205 1148 }
b99bd4ef 1149
c19d1205
ZW
1150 t = atof_ieee (input_line_pointer, type, words);
1151 if (t)
1152 input_line_pointer = t;
499ac353 1153 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1154
c19d1205
ZW
1155 if (target_big_endian)
1156 {
1157 for (i = 0; i < prec; i++)
1158 {
499ac353
NC
1159 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1160 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1161 }
1162 }
1163 else
1164 {
e74cfd16 1165 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1166 for (i = prec - 1; i >= 0; i--)
1167 {
499ac353
NC
1168 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1169 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1170 }
1171 else
1172 /* For a 4 byte float the order of elements in `words' is 1 0.
1173 For an 8 byte float the order is 1 0 3 2. */
1174 for (i = 0; i < prec; i += 2)
1175 {
499ac353
NC
1176 md_number_to_chars (litP, (valueT) words[i + 1],
1177 sizeof (LITTLENUM_TYPE));
1178 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1179 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1180 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1181 }
1182 }
b99bd4ef 1183
499ac353 1184 return NULL;
c19d1205 1185}
b99bd4ef 1186
c19d1205
ZW
1187/* We handle all bad expressions here, so that we can report the faulty
1188 instruction in the error message. */
0198d5e6 1189
c19d1205 1190void
91d6fa6a 1191md_operand (expressionS * exp)
c19d1205
ZW
1192{
1193 if (in_my_get_expression)
91d6fa6a 1194 exp->X_op = O_illegal;
b99bd4ef
NC
1195}
1196
c19d1205 1197/* Immediate values. */
b99bd4ef 1198
0198d5e6 1199#ifdef OBJ_ELF
c19d1205
ZW
1200/* Generic immediate-value read function for use in directives.
1201 Accepts anything that 'expression' can fold to a constant.
1202 *val receives the number. */
0198d5e6 1203
c19d1205
ZW
1204static int
1205immediate_for_directive (int *val)
b99bd4ef 1206{
c19d1205
ZW
1207 expressionS exp;
1208 exp.X_op = O_illegal;
b99bd4ef 1209
c19d1205
ZW
1210 if (is_immediate_prefix (*input_line_pointer))
1211 {
1212 input_line_pointer++;
1213 expression (&exp);
1214 }
b99bd4ef 1215
c19d1205
ZW
1216 if (exp.X_op != O_constant)
1217 {
1218 as_bad (_("expected #constant"));
1219 ignore_rest_of_line ();
1220 return FAIL;
1221 }
1222 *val = exp.X_add_number;
1223 return SUCCESS;
b99bd4ef 1224}
c19d1205 1225#endif
b99bd4ef 1226
c19d1205 1227/* Register parsing. */
b99bd4ef 1228
c19d1205
ZW
1229/* Generic register parser. CCP points to what should be the
1230 beginning of a register name. If it is indeed a valid register
1231 name, advance CCP over it and return the reg_entry structure;
1232 otherwise return NULL. Does not issue diagnostics. */
1233
1234static struct reg_entry *
1235arm_reg_parse_multi (char **ccp)
b99bd4ef 1236{
c19d1205
ZW
1237 char *start = *ccp;
1238 char *p;
1239 struct reg_entry *reg;
b99bd4ef 1240
477330fc
RM
1241 skip_whitespace (start);
1242
c19d1205
ZW
1243#ifdef REGISTER_PREFIX
1244 if (*start != REGISTER_PREFIX)
01cfc07f 1245 return NULL;
c19d1205
ZW
1246 start++;
1247#endif
1248#ifdef OPTIONAL_REGISTER_PREFIX
1249 if (*start == OPTIONAL_REGISTER_PREFIX)
1250 start++;
1251#endif
b99bd4ef 1252
c19d1205
ZW
1253 p = start;
1254 if (!ISALPHA (*p) || !is_name_beginner (*p))
1255 return NULL;
b99bd4ef 1256
c19d1205
ZW
1257 do
1258 p++;
1259 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1260
1261 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1262
1263 if (!reg)
1264 return NULL;
1265
1266 *ccp = p;
1267 return reg;
b99bd4ef
NC
1268}
1269
1270static int
dcbf9037 1271arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1272 enum arm_reg_type type)
b99bd4ef 1273{
c19d1205
ZW
1274 /* Alternative syntaxes are accepted for a few register classes. */
1275 switch (type)
1276 {
1277 case REG_TYPE_MVF:
1278 case REG_TYPE_MVD:
1279 case REG_TYPE_MVFX:
1280 case REG_TYPE_MVDX:
1281 /* Generic coprocessor register names are allowed for these. */
79134647 1282 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1283 return reg->number;
1284 break;
69b97547 1285
c19d1205
ZW
1286 case REG_TYPE_CP:
1287 /* For backward compatibility, a bare number is valid here. */
1288 {
1289 unsigned long processor = strtoul (start, ccp, 10);
1290 if (*ccp != start && processor <= 15)
1291 return processor;
1292 }
1a0670f3 1293 /* Fall through. */
6057a28f 1294
c19d1205
ZW
1295 case REG_TYPE_MMXWC:
1296 /* WC includes WCG. ??? I'm not sure this is true for all
1297 instructions that take WC registers. */
79134647 1298 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1299 return reg->number;
6057a28f 1300 break;
c19d1205 1301
6057a28f 1302 default:
c19d1205 1303 break;
6057a28f
NC
1304 }
1305
dcbf9037
JB
1306 return FAIL;
1307}
1308
1309/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1310 return value is the register number or FAIL. */
1311
1312static int
1313arm_reg_parse (char **ccp, enum arm_reg_type type)
1314{
1315 char *start = *ccp;
1316 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1317 int ret;
1318
1319 /* Do not allow a scalar (reg+index) to parse as a register. */
1320 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1321 return FAIL;
1322
1323 if (reg && reg->type == type)
1324 return reg->number;
1325
1326 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1327 return ret;
1328
c19d1205
ZW
1329 *ccp = start;
1330 return FAIL;
1331}
69b97547 1332
dcbf9037
JB
1333/* Parse a Neon type specifier. *STR should point at the leading '.'
1334 character. Does no verification at this stage that the type fits the opcode
1335 properly. E.g.,
1336
1337 .i32.i32.s16
1338 .s32.f32
1339 .u16
1340
1341 Can all be legally parsed by this function.
1342
1343 Fills in neon_type struct pointer with parsed information, and updates STR
1344 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1345 type, FAIL if not. */
1346
1347static int
1348parse_neon_type (struct neon_type *type, char **str)
1349{
1350 char *ptr = *str;
1351
1352 if (type)
1353 type->elems = 0;
1354
1355 while (type->elems < NEON_MAX_TYPE_ELS)
1356 {
1357 enum neon_el_type thistype = NT_untyped;
1358 unsigned thissize = -1u;
1359
1360 if (*ptr != '.')
1361 break;
1362
1363 ptr++;
1364
1365 /* Just a size without an explicit type. */
1366 if (ISDIGIT (*ptr))
1367 goto parsesize;
1368
1369 switch (TOLOWER (*ptr))
1370 {
1371 case 'i': thistype = NT_integer; break;
1372 case 'f': thistype = NT_float; break;
1373 case 'p': thistype = NT_poly; break;
1374 case 's': thistype = NT_signed; break;
1375 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1376 case 'd':
1377 thistype = NT_float;
1378 thissize = 64;
1379 ptr++;
1380 goto done;
dcbf9037
JB
1381 default:
1382 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1383 return FAIL;
1384 }
1385
1386 ptr++;
1387
1388 /* .f is an abbreviation for .f32. */
1389 if (thistype == NT_float && !ISDIGIT (*ptr))
1390 thissize = 32;
1391 else
1392 {
1393 parsesize:
1394 thissize = strtoul (ptr, &ptr, 10);
1395
1396 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1397 && thissize != 64)
1398 {
1399 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1400 return FAIL;
1401 }
1402 }
1403
037e8744 1404 done:
dcbf9037 1405 if (type)
477330fc
RM
1406 {
1407 type->el[type->elems].type = thistype;
dcbf9037
JB
1408 type->el[type->elems].size = thissize;
1409 type->elems++;
1410 }
1411 }
1412
1413 /* Empty/missing type is not a successful parse. */
1414 if (type->elems == 0)
1415 return FAIL;
1416
1417 *str = ptr;
1418
1419 return SUCCESS;
1420}
1421
1422/* Errors may be set multiple times during parsing or bit encoding
1423 (particularly in the Neon bits), but usually the earliest error which is set
1424 will be the most meaningful. Avoid overwriting it with later (cascading)
1425 errors by calling this function. */
1426
1427static void
1428first_error (const char *err)
1429{
1430 if (!inst.error)
1431 inst.error = err;
1432}
1433
1434/* Parse a single type, e.g. ".s32", leading period included. */
1435static int
1436parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1437{
1438 char *str = *ccp;
1439 struct neon_type optype;
1440
1441 if (*str == '.')
1442 {
1443 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1444 {
1445 if (optype.elems == 1)
1446 *vectype = optype.el[0];
1447 else
1448 {
1449 first_error (_("only one type should be specified for operand"));
1450 return FAIL;
1451 }
1452 }
dcbf9037 1453 else
477330fc
RM
1454 {
1455 first_error (_("vector type expected"));
1456 return FAIL;
1457 }
dcbf9037
JB
1458 }
1459 else
1460 return FAIL;
5f4273c7 1461
dcbf9037 1462 *ccp = str;
5f4273c7 1463
dcbf9037
JB
1464 return SUCCESS;
1465}
1466
1467/* Special meanings for indices (which have a range of 0-7), which will fit into
1468 a 4-bit integer. */
1469
1470#define NEON_ALL_LANES 15
1471#define NEON_INTERLEAVE_LANES 14
1472
1473/* Parse either a register or a scalar, with an optional type. Return the
1474 register number, and optionally fill in the actual type of the register
1475 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1476 type/index information in *TYPEINFO. */
1477
1478static int
1479parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1480 enum arm_reg_type *rtype,
1481 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1482{
1483 char *str = *ccp;
1484 struct reg_entry *reg = arm_reg_parse_multi (&str);
1485 struct neon_typed_alias atype;
1486 struct neon_type_el parsetype;
1487
1488 atype.defined = 0;
1489 atype.index = -1;
1490 atype.eltype.type = NT_invtype;
1491 atype.eltype.size = -1;
1492
1493 /* Try alternate syntax for some types of register. Note these are mutually
1494 exclusive with the Neon syntax extensions. */
1495 if (reg == NULL)
1496 {
1497 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1498 if (altreg != FAIL)
477330fc 1499 *ccp = str;
dcbf9037 1500 if (typeinfo)
477330fc 1501 *typeinfo = atype;
dcbf9037
JB
1502 return altreg;
1503 }
1504
037e8744
JB
1505 /* Undo polymorphism when a set of register types may be accepted. */
1506 if ((type == REG_TYPE_NDQ
1507 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1508 || (type == REG_TYPE_VFSD
477330fc 1509 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1510 || (type == REG_TYPE_NSDQ
477330fc
RM
1511 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1512 || reg->type == REG_TYPE_NQ))
dec41383
JW
1513 || (type == REG_TYPE_NSD
1514 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
f512f76f
NC
1515 || (type == REG_TYPE_MMXWC
1516 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1517 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1518
1519 if (type != reg->type)
1520 return FAIL;
1521
1522 if (reg->neon)
1523 atype = *reg->neon;
5f4273c7 1524
dcbf9037
JB
1525 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1526 {
1527 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1528 {
1529 first_error (_("can't redefine type for operand"));
1530 return FAIL;
1531 }
dcbf9037
JB
1532 atype.defined |= NTA_HASTYPE;
1533 atype.eltype = parsetype;
1534 }
5f4273c7 1535
dcbf9037
JB
1536 if (skip_past_char (&str, '[') == SUCCESS)
1537 {
dec41383
JW
1538 if (type != REG_TYPE_VFD
1539 && !(type == REG_TYPE_VFS
1540 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
477330fc
RM
1541 {
1542 first_error (_("only D registers may be indexed"));
1543 return FAIL;
1544 }
5f4273c7 1545
dcbf9037 1546 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1547 {
1548 first_error (_("can't change index for operand"));
1549 return FAIL;
1550 }
dcbf9037
JB
1551
1552 atype.defined |= NTA_HASINDEX;
1553
1554 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1555 atype.index = NEON_ALL_LANES;
dcbf9037 1556 else
477330fc
RM
1557 {
1558 expressionS exp;
dcbf9037 1559
477330fc 1560 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1561
477330fc
RM
1562 if (exp.X_op != O_constant)
1563 {
1564 first_error (_("constant expression required"));
1565 return FAIL;
1566 }
dcbf9037 1567
477330fc
RM
1568 if (skip_past_char (&str, ']') == FAIL)
1569 return FAIL;
dcbf9037 1570
477330fc
RM
1571 atype.index = exp.X_add_number;
1572 }
dcbf9037 1573 }
5f4273c7 1574
dcbf9037
JB
1575 if (typeinfo)
1576 *typeinfo = atype;
5f4273c7 1577
dcbf9037
JB
1578 if (rtype)
1579 *rtype = type;
5f4273c7 1580
dcbf9037 1581 *ccp = str;
5f4273c7 1582
dcbf9037
JB
1583 return reg->number;
1584}
1585
1586/* Like arm_reg_parse, but allow allow the following extra features:
1587 - If RTYPE is non-zero, return the (possibly restricted) type of the
1588 register (e.g. Neon double or quad reg when either has been requested).
1589 - If this is a Neon vector type with additional type information, fill
1590 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1591 This function will fault on encountering a scalar. */
dcbf9037
JB
1592
1593static int
1594arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1595 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1596{
1597 struct neon_typed_alias atype;
1598 char *str = *ccp;
1599 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1600
1601 if (reg == FAIL)
1602 return FAIL;
1603
0855e32b
NS
1604 /* Do not allow regname(... to parse as a register. */
1605 if (*str == '(')
1606 return FAIL;
1607
dcbf9037
JB
1608 /* Do not allow a scalar (reg+index) to parse as a register. */
1609 if ((atype.defined & NTA_HASINDEX) != 0)
1610 {
1611 first_error (_("register operand expected, but got scalar"));
1612 return FAIL;
1613 }
1614
1615 if (vectype)
1616 *vectype = atype.eltype;
1617
1618 *ccp = str;
1619
1620 return reg;
1621}
1622
1623#define NEON_SCALAR_REG(X) ((X) >> 4)
1624#define NEON_SCALAR_INDEX(X) ((X) & 15)
1625
5287ad62
JB
1626/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1627 have enough information to be able to do a good job bounds-checking. So, we
1628 just do easy checks here, and do further checks later. */
1629
1630static int
dcbf9037 1631parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1632{
dcbf9037 1633 int reg;
5287ad62 1634 char *str = *ccp;
dcbf9037 1635 struct neon_typed_alias atype;
dec41383
JW
1636 enum arm_reg_type reg_type = REG_TYPE_VFD;
1637
1638 if (elsize == 4)
1639 reg_type = REG_TYPE_VFS;
5f4273c7 1640
dec41383 1641 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
5f4273c7 1642
dcbf9037 1643 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1644 return FAIL;
5f4273c7 1645
dcbf9037 1646 if (atype.index == NEON_ALL_LANES)
5287ad62 1647 {
dcbf9037 1648 first_error (_("scalar must have an index"));
5287ad62
JB
1649 return FAIL;
1650 }
dcbf9037 1651 else if (atype.index >= 64 / elsize)
5287ad62 1652 {
dcbf9037 1653 first_error (_("scalar index out of range"));
5287ad62
JB
1654 return FAIL;
1655 }
5f4273c7 1656
dcbf9037
JB
1657 if (type)
1658 *type = atype.eltype;
5f4273c7 1659
5287ad62 1660 *ccp = str;
5f4273c7 1661
dcbf9037 1662 return reg * 16 + atype.index;
5287ad62
JB
1663}
1664
c19d1205 1665/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1666
c19d1205
ZW
1667static long
1668parse_reg_list (char ** strp)
1669{
1670 char * str = * strp;
1671 long range = 0;
1672 int another_range;
a737bd4d 1673
c19d1205
ZW
1674 /* We come back here if we get ranges concatenated by '+' or '|'. */
1675 do
6057a28f 1676 {
477330fc
RM
1677 skip_whitespace (str);
1678
c19d1205 1679 another_range = 0;
a737bd4d 1680
c19d1205
ZW
1681 if (*str == '{')
1682 {
1683 int in_range = 0;
1684 int cur_reg = -1;
a737bd4d 1685
c19d1205
ZW
1686 str++;
1687 do
1688 {
1689 int reg;
6057a28f 1690
dcbf9037 1691 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1692 {
dcbf9037 1693 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1694 return FAIL;
1695 }
a737bd4d 1696
c19d1205
ZW
1697 if (in_range)
1698 {
1699 int i;
a737bd4d 1700
c19d1205
ZW
1701 if (reg <= cur_reg)
1702 {
dcbf9037 1703 first_error (_("bad range in register list"));
c19d1205
ZW
1704 return FAIL;
1705 }
40a18ebd 1706
c19d1205
ZW
1707 for (i = cur_reg + 1; i < reg; i++)
1708 {
1709 if (range & (1 << i))
1710 as_tsktsk
1711 (_("Warning: duplicated register (r%d) in register list"),
1712 i);
1713 else
1714 range |= 1 << i;
1715 }
1716 in_range = 0;
1717 }
a737bd4d 1718
c19d1205
ZW
1719 if (range & (1 << reg))
1720 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1721 reg);
1722 else if (reg <= cur_reg)
1723 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1724
c19d1205
ZW
1725 range |= 1 << reg;
1726 cur_reg = reg;
1727 }
1728 while (skip_past_comma (&str) != FAIL
1729 || (in_range = 1, *str++ == '-'));
1730 str--;
a737bd4d 1731
d996d970 1732 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1733 {
dcbf9037 1734 first_error (_("missing `}'"));
c19d1205
ZW
1735 return FAIL;
1736 }
1737 }
1738 else
1739 {
91d6fa6a 1740 expressionS exp;
40a18ebd 1741
91d6fa6a 1742 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1743 return FAIL;
40a18ebd 1744
91d6fa6a 1745 if (exp.X_op == O_constant)
c19d1205 1746 {
91d6fa6a
NC
1747 if (exp.X_add_number
1748 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1749 {
1750 inst.error = _("invalid register mask");
1751 return FAIL;
1752 }
a737bd4d 1753
91d6fa6a 1754 if ((range & exp.X_add_number) != 0)
c19d1205 1755 {
91d6fa6a 1756 int regno = range & exp.X_add_number;
a737bd4d 1757
c19d1205
ZW
1758 regno &= -regno;
1759 regno = (1 << regno) - 1;
1760 as_tsktsk
1761 (_("Warning: duplicated register (r%d) in register list"),
1762 regno);
1763 }
a737bd4d 1764
91d6fa6a 1765 range |= exp.X_add_number;
c19d1205
ZW
1766 }
1767 else
1768 {
1769 if (inst.reloc.type != 0)
1770 {
1771 inst.error = _("expression too complex");
1772 return FAIL;
1773 }
a737bd4d 1774
91d6fa6a 1775 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1776 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1777 inst.reloc.pc_rel = 0;
1778 }
1779 }
a737bd4d 1780
c19d1205
ZW
1781 if (*str == '|' || *str == '+')
1782 {
1783 str++;
1784 another_range = 1;
1785 }
a737bd4d 1786 }
c19d1205 1787 while (another_range);
a737bd4d 1788
c19d1205
ZW
1789 *strp = str;
1790 return range;
a737bd4d
NC
1791}
1792
5287ad62
JB
1793/* Types of registers in a list. */
1794
1795enum reg_list_els
1796{
1797 REGLIST_VFP_S,
1798 REGLIST_VFP_D,
1799 REGLIST_NEON_D
1800};
1801
c19d1205
ZW
1802/* Parse a VFP register list. If the string is invalid return FAIL.
1803 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1804 register. Parses registers of type ETYPE.
1805 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1806 - Q registers can be used to specify pairs of D registers
1807 - { } can be omitted from around a singleton register list
477330fc
RM
1808 FIXME: This is not implemented, as it would require backtracking in
1809 some cases, e.g.:
1810 vtbl.8 d3,d4,d5
1811 This could be done (the meaning isn't really ambiguous), but doesn't
1812 fit in well with the current parsing framework.
dcbf9037
JB
1813 - 32 D registers may be used (also true for VFPv3).
1814 FIXME: Types are ignored in these register lists, which is probably a
1815 bug. */
6057a28f 1816
c19d1205 1817static int
037e8744 1818parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1819{
037e8744 1820 char *str = *ccp;
c19d1205
ZW
1821 int base_reg;
1822 int new_base;
21d799b5 1823 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1824 int max_regs = 0;
c19d1205
ZW
1825 int count = 0;
1826 int warned = 0;
1827 unsigned long mask = 0;
a737bd4d 1828 int i;
6057a28f 1829
477330fc 1830 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1831 {
1832 inst.error = _("expecting {");
1833 return FAIL;
1834 }
6057a28f 1835
5287ad62 1836 switch (etype)
c19d1205 1837 {
5287ad62 1838 case REGLIST_VFP_S:
c19d1205
ZW
1839 regtype = REG_TYPE_VFS;
1840 max_regs = 32;
5287ad62 1841 break;
5f4273c7 1842
5287ad62
JB
1843 case REGLIST_VFP_D:
1844 regtype = REG_TYPE_VFD;
b7fc2769 1845 break;
5f4273c7 1846
b7fc2769
JB
1847 case REGLIST_NEON_D:
1848 regtype = REG_TYPE_NDQ;
1849 break;
1850 }
1851
1852 if (etype != REGLIST_VFP_S)
1853 {
b1cc4aeb
PB
1854 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1855 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1856 {
1857 max_regs = 32;
1858 if (thumb_mode)
1859 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1860 fpu_vfp_ext_d32);
1861 else
1862 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1863 fpu_vfp_ext_d32);
1864 }
5287ad62 1865 else
477330fc 1866 max_regs = 16;
c19d1205 1867 }
6057a28f 1868
c19d1205 1869 base_reg = max_regs;
a737bd4d 1870
c19d1205
ZW
1871 do
1872 {
5287ad62 1873 int setmask = 1, addregs = 1;
dcbf9037 1874
037e8744 1875 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1876
c19d1205 1877 if (new_base == FAIL)
a737bd4d 1878 {
dcbf9037 1879 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1880 return FAIL;
1881 }
5f4273c7 1882
b7fc2769 1883 if (new_base >= max_regs)
477330fc
RM
1884 {
1885 first_error (_("register out of range in list"));
1886 return FAIL;
1887 }
5f4273c7 1888
5287ad62
JB
1889 /* Note: a value of 2 * n is returned for the register Q<n>. */
1890 if (regtype == REG_TYPE_NQ)
477330fc
RM
1891 {
1892 setmask = 3;
1893 addregs = 2;
1894 }
5287ad62 1895
c19d1205
ZW
1896 if (new_base < base_reg)
1897 base_reg = new_base;
a737bd4d 1898
5287ad62 1899 if (mask & (setmask << new_base))
c19d1205 1900 {
dcbf9037 1901 first_error (_("invalid register list"));
c19d1205 1902 return FAIL;
a737bd4d 1903 }
a737bd4d 1904
c19d1205
ZW
1905 if ((mask >> new_base) != 0 && ! warned)
1906 {
1907 as_tsktsk (_("register list not in ascending order"));
1908 warned = 1;
1909 }
0bbf2aa4 1910
5287ad62
JB
1911 mask |= setmask << new_base;
1912 count += addregs;
0bbf2aa4 1913
037e8744 1914 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1915 {
1916 int high_range;
0bbf2aa4 1917
037e8744 1918 str++;
0bbf2aa4 1919
037e8744 1920 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1921 == FAIL)
c19d1205
ZW
1922 {
1923 inst.error = gettext (reg_expected_msgs[regtype]);
1924 return FAIL;
1925 }
0bbf2aa4 1926
477330fc
RM
1927 if (high_range >= max_regs)
1928 {
1929 first_error (_("register out of range in list"));
1930 return FAIL;
1931 }
b7fc2769 1932
477330fc
RM
1933 if (regtype == REG_TYPE_NQ)
1934 high_range = high_range + 1;
5287ad62 1935
c19d1205
ZW
1936 if (high_range <= new_base)
1937 {
1938 inst.error = _("register range not in ascending order");
1939 return FAIL;
1940 }
0bbf2aa4 1941
5287ad62 1942 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1943 {
5287ad62 1944 if (mask & (setmask << new_base))
0bbf2aa4 1945 {
c19d1205
ZW
1946 inst.error = _("invalid register list");
1947 return FAIL;
0bbf2aa4 1948 }
c19d1205 1949
5287ad62
JB
1950 mask |= setmask << new_base;
1951 count += addregs;
0bbf2aa4 1952 }
0bbf2aa4 1953 }
0bbf2aa4 1954 }
037e8744 1955 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1956
037e8744 1957 str++;
0bbf2aa4 1958
c19d1205
ZW
1959 /* Sanity check -- should have raised a parse error above. */
1960 if (count == 0 || count > max_regs)
1961 abort ();
1962
1963 *pbase = base_reg;
1964
1965 /* Final test -- the registers must be consecutive. */
1966 mask >>= base_reg;
1967 for (i = 0; i < count; i++)
1968 {
1969 if ((mask & (1u << i)) == 0)
1970 {
1971 inst.error = _("non-contiguous register range");
1972 return FAIL;
1973 }
1974 }
1975
037e8744
JB
1976 *ccp = str;
1977
c19d1205 1978 return count;
b99bd4ef
NC
1979}
1980
dcbf9037
JB
1981/* True if two alias types are the same. */
1982
c921be7d 1983static bfd_boolean
dcbf9037
JB
1984neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1985{
1986 if (!a && !b)
c921be7d 1987 return TRUE;
5f4273c7 1988
dcbf9037 1989 if (!a || !b)
c921be7d 1990 return FALSE;
dcbf9037
JB
1991
1992 if (a->defined != b->defined)
c921be7d 1993 return FALSE;
5f4273c7 1994
dcbf9037
JB
1995 if ((a->defined & NTA_HASTYPE) != 0
1996 && (a->eltype.type != b->eltype.type
477330fc 1997 || a->eltype.size != b->eltype.size))
c921be7d 1998 return FALSE;
dcbf9037
JB
1999
2000 if ((a->defined & NTA_HASINDEX) != 0
2001 && (a->index != b->index))
c921be7d 2002 return FALSE;
5f4273c7 2003
c921be7d 2004 return TRUE;
dcbf9037
JB
2005}
2006
5287ad62
JB
2007/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2008 The base register is put in *PBASE.
dcbf9037 2009 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
2010 the return value.
2011 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
2012 Bits [6:5] encode the list length (minus one).
2013 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 2014
5287ad62 2015#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 2016#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
2017#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2018
2019static int
dcbf9037 2020parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2021 struct neon_type_el *eltype)
5287ad62
JB
2022{
2023 char *ptr = *str;
2024 int base_reg = -1;
2025 int reg_incr = -1;
2026 int count = 0;
2027 int lane = -1;
2028 int leading_brace = 0;
2029 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2030 const char *const incr_error = _("register stride must be 1 or 2");
2031 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2032 struct neon_typed_alias firsttype;
f85d59c3
KT
2033 firsttype.defined = 0;
2034 firsttype.eltype.type = NT_invtype;
2035 firsttype.eltype.size = -1;
2036 firsttype.index = -1;
5f4273c7 2037
5287ad62
JB
2038 if (skip_past_char (&ptr, '{') == SUCCESS)
2039 leading_brace = 1;
5f4273c7 2040
5287ad62
JB
2041 do
2042 {
dcbf9037
JB
2043 struct neon_typed_alias atype;
2044 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2045
5287ad62 2046 if (getreg == FAIL)
477330fc
RM
2047 {
2048 first_error (_(reg_expected_msgs[rtype]));
2049 return FAIL;
2050 }
5f4273c7 2051
5287ad62 2052 if (base_reg == -1)
477330fc
RM
2053 {
2054 base_reg = getreg;
2055 if (rtype == REG_TYPE_NQ)
2056 {
2057 reg_incr = 1;
2058 }
2059 firsttype = atype;
2060 }
5287ad62 2061 else if (reg_incr == -1)
477330fc
RM
2062 {
2063 reg_incr = getreg - base_reg;
2064 if (reg_incr < 1 || reg_incr > 2)
2065 {
2066 first_error (_(incr_error));
2067 return FAIL;
2068 }
2069 }
5287ad62 2070 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2071 {
2072 first_error (_(incr_error));
2073 return FAIL;
2074 }
dcbf9037 2075
c921be7d 2076 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2077 {
2078 first_error (_(type_error));
2079 return FAIL;
2080 }
5f4273c7 2081
5287ad62 2082 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2083 modes. */
5287ad62 2084 if (ptr[0] == '-')
477330fc
RM
2085 {
2086 struct neon_typed_alias htype;
2087 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2088 if (lane == -1)
2089 lane = NEON_INTERLEAVE_LANES;
2090 else if (lane != NEON_INTERLEAVE_LANES)
2091 {
2092 first_error (_(type_error));
2093 return FAIL;
2094 }
2095 if (reg_incr == -1)
2096 reg_incr = 1;
2097 else if (reg_incr != 1)
2098 {
2099 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2100 return FAIL;
2101 }
2102 ptr++;
2103 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2104 if (hireg == FAIL)
2105 {
2106 first_error (_(reg_expected_msgs[rtype]));
2107 return FAIL;
2108 }
2109 if (! neon_alias_types_same (&htype, &firsttype))
2110 {
2111 first_error (_(type_error));
2112 return FAIL;
2113 }
2114 count += hireg + dregs - getreg;
2115 continue;
2116 }
5f4273c7 2117
5287ad62
JB
2118 /* If we're using Q registers, we can't use [] or [n] syntax. */
2119 if (rtype == REG_TYPE_NQ)
477330fc
RM
2120 {
2121 count += 2;
2122 continue;
2123 }
5f4273c7 2124
dcbf9037 2125 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2126 {
2127 if (lane == -1)
2128 lane = atype.index;
2129 else if (lane != atype.index)
2130 {
2131 first_error (_(type_error));
2132 return FAIL;
2133 }
2134 }
5287ad62 2135 else if (lane == -1)
477330fc 2136 lane = NEON_INTERLEAVE_LANES;
5287ad62 2137 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2138 {
2139 first_error (_(type_error));
2140 return FAIL;
2141 }
5287ad62
JB
2142 count++;
2143 }
2144 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2145
5287ad62
JB
2146 /* No lane set by [x]. We must be interleaving structures. */
2147 if (lane == -1)
2148 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2149
5287ad62
JB
2150 /* Sanity check. */
2151 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2152 || (count > 1 && reg_incr == -1))
2153 {
dcbf9037 2154 first_error (_("error parsing element/structure list"));
5287ad62
JB
2155 return FAIL;
2156 }
2157
2158 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2159 {
dcbf9037 2160 first_error (_("expected }"));
5287ad62
JB
2161 return FAIL;
2162 }
5f4273c7 2163
5287ad62
JB
2164 if (reg_incr == -1)
2165 reg_incr = 1;
2166
dcbf9037
JB
2167 if (eltype)
2168 *eltype = firsttype.eltype;
2169
5287ad62
JB
2170 *pbase = base_reg;
2171 *str = ptr;
5f4273c7 2172
5287ad62
JB
2173 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2174}
2175
c19d1205
ZW
2176/* Parse an explicit relocation suffix on an expression. This is
2177 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2178 arm_reloc_hsh contains no entries, so this function can only
2179 succeed if there is no () after the word. Returns -1 on error,
2180 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2181
c19d1205
ZW
2182static int
2183parse_reloc (char **str)
b99bd4ef 2184{
c19d1205
ZW
2185 struct reloc_entry *r;
2186 char *p, *q;
b99bd4ef 2187
c19d1205
ZW
2188 if (**str != '(')
2189 return BFD_RELOC_UNUSED;
b99bd4ef 2190
c19d1205
ZW
2191 p = *str + 1;
2192 q = p;
2193
2194 while (*q && *q != ')' && *q != ',')
2195 q++;
2196 if (*q != ')')
2197 return -1;
2198
21d799b5
NC
2199 if ((r = (struct reloc_entry *)
2200 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2201 return -1;
2202
2203 *str = q + 1;
2204 return r->reloc;
b99bd4ef
NC
2205}
2206
c19d1205
ZW
2207/* Directives: register aliases. */
2208
dcbf9037 2209static struct reg_entry *
90ec0d68 2210insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2211{
d3ce72d0 2212 struct reg_entry *new_reg;
c19d1205 2213 const char *name;
b99bd4ef 2214
d3ce72d0 2215 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2216 {
d3ce72d0 2217 if (new_reg->builtin)
c19d1205 2218 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2219
c19d1205
ZW
2220 /* Only warn about a redefinition if it's not defined as the
2221 same register. */
d3ce72d0 2222 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2223 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2224
d929913e 2225 return NULL;
c19d1205 2226 }
b99bd4ef 2227
c19d1205 2228 name = xstrdup (str);
325801bd 2229 new_reg = XNEW (struct reg_entry);
b99bd4ef 2230
d3ce72d0
NC
2231 new_reg->name = name;
2232 new_reg->number = number;
2233 new_reg->type = type;
2234 new_reg->builtin = FALSE;
2235 new_reg->neon = NULL;
b99bd4ef 2236
d3ce72d0 2237 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2238 abort ();
5f4273c7 2239
d3ce72d0 2240 return new_reg;
dcbf9037
JB
2241}
2242
2243static void
2244insert_neon_reg_alias (char *str, int number, int type,
477330fc 2245 struct neon_typed_alias *atype)
dcbf9037
JB
2246{
2247 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2248
dcbf9037
JB
2249 if (!reg)
2250 {
2251 first_error (_("attempt to redefine typed alias"));
2252 return;
2253 }
5f4273c7 2254
dcbf9037
JB
2255 if (atype)
2256 {
325801bd 2257 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2258 *reg->neon = *atype;
2259 }
c19d1205 2260}
b99bd4ef 2261
c19d1205 2262/* Look for the .req directive. This is of the form:
b99bd4ef 2263
c19d1205 2264 new_register_name .req existing_register_name
b99bd4ef 2265
c19d1205 2266 If we find one, or if it looks sufficiently like one that we want to
d929913e 2267 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2268
d929913e 2269static bfd_boolean
c19d1205
ZW
2270create_register_alias (char * newname, char *p)
2271{
2272 struct reg_entry *old;
2273 char *oldname, *nbuf;
2274 size_t nlen;
b99bd4ef 2275
c19d1205
ZW
2276 /* The input scrubber ensures that whitespace after the mnemonic is
2277 collapsed to single spaces. */
2278 oldname = p;
2279 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2280 return FALSE;
b99bd4ef 2281
c19d1205
ZW
2282 oldname += 6;
2283 if (*oldname == '\0')
d929913e 2284 return FALSE;
b99bd4ef 2285
21d799b5 2286 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2287 if (!old)
b99bd4ef 2288 {
c19d1205 2289 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2290 return TRUE;
b99bd4ef
NC
2291 }
2292
c19d1205
ZW
2293 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2294 the desired alias name, and p points to its end. If not, then
2295 the desired alias name is in the global original_case_string. */
2296#ifdef TC_CASE_SENSITIVE
2297 nlen = p - newname;
2298#else
2299 newname = original_case_string;
2300 nlen = strlen (newname);
2301#endif
b99bd4ef 2302
29a2809e 2303 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2304
c19d1205
ZW
2305 /* Create aliases under the new name as stated; an all-lowercase
2306 version of the new name; and an all-uppercase version of the new
2307 name. */
d929913e
NC
2308 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2309 {
2310 for (p = nbuf; *p; p++)
2311 *p = TOUPPER (*p);
c19d1205 2312
d929913e
NC
2313 if (strncmp (nbuf, newname, nlen))
2314 {
2315 /* If this attempt to create an additional alias fails, do not bother
2316 trying to create the all-lower case alias. We will fail and issue
2317 a second, duplicate error message. This situation arises when the
2318 programmer does something like:
2319 foo .req r0
2320 Foo .req r1
2321 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2322 the artificial FOO alias because it has already been created by the
d929913e
NC
2323 first .req. */
2324 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2325 {
2326 free (nbuf);
2327 return TRUE;
2328 }
d929913e 2329 }
c19d1205 2330
d929913e
NC
2331 for (p = nbuf; *p; p++)
2332 *p = TOLOWER (*p);
c19d1205 2333
d929913e
NC
2334 if (strncmp (nbuf, newname, nlen))
2335 insert_reg_alias (nbuf, old->number, old->type);
2336 }
c19d1205 2337
e1fa0163 2338 free (nbuf);
d929913e 2339 return TRUE;
b99bd4ef
NC
2340}
2341
dcbf9037
JB
2342/* Create a Neon typed/indexed register alias using directives, e.g.:
2343 X .dn d5.s32[1]
2344 Y .qn 6.s16
2345 Z .dn d7
2346 T .dn Z[0]
2347 These typed registers can be used instead of the types specified after the
2348 Neon mnemonic, so long as all operands given have types. Types can also be
2349 specified directly, e.g.:
5f4273c7 2350 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2351
c921be7d 2352static bfd_boolean
dcbf9037
JB
2353create_neon_reg_alias (char *newname, char *p)
2354{
2355 enum arm_reg_type basetype;
2356 struct reg_entry *basereg;
2357 struct reg_entry mybasereg;
2358 struct neon_type ntype;
2359 struct neon_typed_alias typeinfo;
12d6b0b7 2360 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2361 int namelen;
5f4273c7 2362
dcbf9037
JB
2363 typeinfo.defined = 0;
2364 typeinfo.eltype.type = NT_invtype;
2365 typeinfo.eltype.size = -1;
2366 typeinfo.index = -1;
5f4273c7 2367
dcbf9037 2368 nameend = p;
5f4273c7 2369
dcbf9037
JB
2370 if (strncmp (p, " .dn ", 5) == 0)
2371 basetype = REG_TYPE_VFD;
2372 else if (strncmp (p, " .qn ", 5) == 0)
2373 basetype = REG_TYPE_NQ;
2374 else
c921be7d 2375 return FALSE;
5f4273c7 2376
dcbf9037 2377 p += 5;
5f4273c7 2378
dcbf9037 2379 if (*p == '\0')
c921be7d 2380 return FALSE;
5f4273c7 2381
dcbf9037
JB
2382 basereg = arm_reg_parse_multi (&p);
2383
2384 if (basereg && basereg->type != basetype)
2385 {
2386 as_bad (_("bad type for register"));
c921be7d 2387 return FALSE;
dcbf9037
JB
2388 }
2389
2390 if (basereg == NULL)
2391 {
2392 expressionS exp;
2393 /* Try parsing as an integer. */
2394 my_get_expression (&exp, &p, GE_NO_PREFIX);
2395 if (exp.X_op != O_constant)
477330fc
RM
2396 {
2397 as_bad (_("expression must be constant"));
2398 return FALSE;
2399 }
dcbf9037
JB
2400 basereg = &mybasereg;
2401 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2402 : exp.X_add_number;
dcbf9037
JB
2403 basereg->neon = 0;
2404 }
2405
2406 if (basereg->neon)
2407 typeinfo = *basereg->neon;
2408
2409 if (parse_neon_type (&ntype, &p) == SUCCESS)
2410 {
2411 /* We got a type. */
2412 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2413 {
2414 as_bad (_("can't redefine the type of a register alias"));
2415 return FALSE;
2416 }
5f4273c7 2417
dcbf9037
JB
2418 typeinfo.defined |= NTA_HASTYPE;
2419 if (ntype.elems != 1)
477330fc
RM
2420 {
2421 as_bad (_("you must specify a single type only"));
2422 return FALSE;
2423 }
dcbf9037
JB
2424 typeinfo.eltype = ntype.el[0];
2425 }
5f4273c7 2426
dcbf9037
JB
2427 if (skip_past_char (&p, '[') == SUCCESS)
2428 {
2429 expressionS exp;
2430 /* We got a scalar index. */
5f4273c7 2431
dcbf9037 2432 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2433 {
2434 as_bad (_("can't redefine the index of a scalar alias"));
2435 return FALSE;
2436 }
5f4273c7 2437
dcbf9037 2438 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2439
dcbf9037 2440 if (exp.X_op != O_constant)
477330fc
RM
2441 {
2442 as_bad (_("scalar index must be constant"));
2443 return FALSE;
2444 }
5f4273c7 2445
dcbf9037
JB
2446 typeinfo.defined |= NTA_HASINDEX;
2447 typeinfo.index = exp.X_add_number;
5f4273c7 2448
dcbf9037 2449 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2450 {
2451 as_bad (_("expecting ]"));
2452 return FALSE;
2453 }
dcbf9037
JB
2454 }
2455
15735687
NS
2456 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2457 the desired alias name, and p points to its end. If not, then
2458 the desired alias name is in the global original_case_string. */
2459#ifdef TC_CASE_SENSITIVE
dcbf9037 2460 namelen = nameend - newname;
15735687
NS
2461#else
2462 newname = original_case_string;
2463 namelen = strlen (newname);
2464#endif
2465
29a2809e 2466 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2467
dcbf9037 2468 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2469 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2470
dcbf9037
JB
2471 /* Insert name in all uppercase. */
2472 for (p = namebuf; *p; p++)
2473 *p = TOUPPER (*p);
5f4273c7 2474
dcbf9037
JB
2475 if (strncmp (namebuf, newname, namelen))
2476 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2477 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2478
dcbf9037
JB
2479 /* Insert name in all lowercase. */
2480 for (p = namebuf; *p; p++)
2481 *p = TOLOWER (*p);
5f4273c7 2482
dcbf9037
JB
2483 if (strncmp (namebuf, newname, namelen))
2484 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2485 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2486
e1fa0163 2487 free (namebuf);
c921be7d 2488 return TRUE;
dcbf9037
JB
2489}
2490
c19d1205
ZW
2491/* Should never be called, as .req goes between the alias and the
2492 register name, not at the beginning of the line. */
c921be7d 2493
b99bd4ef 2494static void
c19d1205 2495s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2496{
c19d1205
ZW
2497 as_bad (_("invalid syntax for .req directive"));
2498}
b99bd4ef 2499
dcbf9037
JB
2500static void
2501s_dn (int a ATTRIBUTE_UNUSED)
2502{
2503 as_bad (_("invalid syntax for .dn directive"));
2504}
2505
2506static void
2507s_qn (int a ATTRIBUTE_UNUSED)
2508{
2509 as_bad (_("invalid syntax for .qn directive"));
2510}
2511
c19d1205
ZW
2512/* The .unreq directive deletes an alias which was previously defined
2513 by .req. For example:
b99bd4ef 2514
c19d1205
ZW
2515 my_alias .req r11
2516 .unreq my_alias */
b99bd4ef
NC
2517
2518static void
c19d1205 2519s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2520{
c19d1205
ZW
2521 char * name;
2522 char saved_char;
b99bd4ef 2523
c19d1205
ZW
2524 name = input_line_pointer;
2525
2526 while (*input_line_pointer != 0
2527 && *input_line_pointer != ' '
2528 && *input_line_pointer != '\n')
2529 ++input_line_pointer;
2530
2531 saved_char = *input_line_pointer;
2532 *input_line_pointer = 0;
2533
2534 if (!*name)
2535 as_bad (_("invalid syntax for .unreq directive"));
2536 else
2537 {
21d799b5 2538 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2539 name);
c19d1205
ZW
2540
2541 if (!reg)
2542 as_bad (_("unknown register alias '%s'"), name);
2543 else if (reg->builtin)
a1727c1a 2544 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2545 name);
2546 else
2547 {
d929913e
NC
2548 char * p;
2549 char * nbuf;
2550
db0bc284 2551 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2552 free ((char *) reg->name);
477330fc
RM
2553 if (reg->neon)
2554 free (reg->neon);
c19d1205 2555 free (reg);
d929913e
NC
2556
2557 /* Also locate the all upper case and all lower case versions.
2558 Do not complain if we cannot find one or the other as it
2559 was probably deleted above. */
5f4273c7 2560
d929913e
NC
2561 nbuf = strdup (name);
2562 for (p = nbuf; *p; p++)
2563 *p = TOUPPER (*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 for (p = nbuf; *p; p++)
2575 *p = TOLOWER (*p);
21d799b5 2576 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2577 if (reg)
2578 {
db0bc284 2579 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2580 free ((char *) reg->name);
2581 if (reg->neon)
2582 free (reg->neon);
2583 free (reg);
2584 }
2585
2586 free (nbuf);
c19d1205
ZW
2587 }
2588 }
b99bd4ef 2589
c19d1205 2590 *input_line_pointer = saved_char;
b99bd4ef
NC
2591 demand_empty_rest_of_line ();
2592}
2593
c19d1205
ZW
2594/* Directives: Instruction set selection. */
2595
2596#ifdef OBJ_ELF
2597/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2598 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2599 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2600 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2601
cd000bff
DJ
2602/* Create a new mapping symbol for the transition to STATE. */
2603
2604static void
2605make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2606{
a737bd4d 2607 symbolS * symbolP;
c19d1205
ZW
2608 const char * symname;
2609 int type;
b99bd4ef 2610
c19d1205 2611 switch (state)
b99bd4ef 2612 {
c19d1205
ZW
2613 case MAP_DATA:
2614 symname = "$d";
2615 type = BSF_NO_FLAGS;
2616 break;
2617 case MAP_ARM:
2618 symname = "$a";
2619 type = BSF_NO_FLAGS;
2620 break;
2621 case MAP_THUMB:
2622 symname = "$t";
2623 type = BSF_NO_FLAGS;
2624 break;
c19d1205
ZW
2625 default:
2626 abort ();
2627 }
2628
cd000bff 2629 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2630 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2631
2632 switch (state)
2633 {
2634 case MAP_ARM:
2635 THUMB_SET_FUNC (symbolP, 0);
2636 ARM_SET_THUMB (symbolP, 0);
2637 ARM_SET_INTERWORK (symbolP, support_interwork);
2638 break;
2639
2640 case MAP_THUMB:
2641 THUMB_SET_FUNC (symbolP, 1);
2642 ARM_SET_THUMB (symbolP, 1);
2643 ARM_SET_INTERWORK (symbolP, support_interwork);
2644 break;
2645
2646 case MAP_DATA:
2647 default:
cd000bff
DJ
2648 break;
2649 }
2650
2651 /* Save the mapping symbols for future reference. Also check that
2652 we do not place two mapping symbols at the same offset within a
2653 frag. We'll handle overlap between frags in
2de7820f
JZ
2654 check_mapping_symbols.
2655
2656 If .fill or other data filling directive generates zero sized data,
2657 the mapping symbol for the following code will have the same value
2658 as the one generated for the data filling directive. In this case,
2659 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2660 if (value == 0)
2661 {
2de7820f
JZ
2662 if (frag->tc_frag_data.first_map != NULL)
2663 {
2664 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2665 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2666 }
cd000bff
DJ
2667 frag->tc_frag_data.first_map = symbolP;
2668 }
2669 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2670 {
2671 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2672 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2673 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2674 }
cd000bff
DJ
2675 frag->tc_frag_data.last_map = symbolP;
2676}
2677
2678/* We must sometimes convert a region marked as code to data during
2679 code alignment, if an odd number of bytes have to be padded. The
2680 code mapping symbol is pushed to an aligned address. */
2681
2682static void
2683insert_data_mapping_symbol (enum mstate state,
2684 valueT value, fragS *frag, offsetT bytes)
2685{
2686 /* If there was already a mapping symbol, remove it. */
2687 if (frag->tc_frag_data.last_map != NULL
2688 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2689 {
2690 symbolS *symp = frag->tc_frag_data.last_map;
2691
2692 if (value == 0)
2693 {
2694 know (frag->tc_frag_data.first_map == symp);
2695 frag->tc_frag_data.first_map = NULL;
2696 }
2697 frag->tc_frag_data.last_map = NULL;
2698 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2699 }
cd000bff
DJ
2700
2701 make_mapping_symbol (MAP_DATA, value, frag);
2702 make_mapping_symbol (state, value + bytes, frag);
2703}
2704
2705static void mapping_state_2 (enum mstate state, int max_chars);
2706
2707/* Set the mapping state to STATE. Only call this when about to
2708 emit some STATE bytes to the file. */
2709
4e9aaefb 2710#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2711void
2712mapping_state (enum mstate state)
2713{
940b5ce0
DJ
2714 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2715
cd000bff
DJ
2716 if (mapstate == state)
2717 /* The mapping symbol has already been emitted.
2718 There is nothing else to do. */
2719 return;
49c62a33
NC
2720
2721 if (state == MAP_ARM || state == MAP_THUMB)
2722 /* PR gas/12931
2723 All ARM instructions require 4-byte alignment.
2724 (Almost) all Thumb instructions require 2-byte alignment.
2725
2726 When emitting instructions into any section, mark the section
2727 appropriately.
2728
2729 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2730 but themselves require 2-byte alignment; this applies to some
33eaf5de 2731 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2732 literal pool generation or an explicit .align >=2, both of
2733 which will cause the section to me marked with sufficient
2734 alignment. Thus, we don't handle those cases here. */
2735 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2736
2737 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2738 /* This case will be evaluated later. */
cd000bff 2739 return;
cd000bff
DJ
2740
2741 mapping_state_2 (state, 0);
cd000bff
DJ
2742}
2743
2744/* Same as mapping_state, but MAX_CHARS bytes have already been
2745 allocated. Put the mapping symbol that far back. */
2746
2747static void
2748mapping_state_2 (enum mstate state, int max_chars)
2749{
940b5ce0
DJ
2750 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2751
2752 if (!SEG_NORMAL (now_seg))
2753 return;
2754
cd000bff
DJ
2755 if (mapstate == state)
2756 /* The mapping symbol has already been emitted.
2757 There is nothing else to do. */
2758 return;
2759
4e9aaefb
SA
2760 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2761 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2762 {
2763 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2764 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2765
2766 if (add_symbol)
2767 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2768 }
2769
cd000bff
DJ
2770 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2771 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2772}
4e9aaefb 2773#undef TRANSITION
c19d1205 2774#else
d3106081
NS
2775#define mapping_state(x) ((void)0)
2776#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2777#endif
2778
2779/* Find the real, Thumb encoded start of a Thumb function. */
2780
4343666d 2781#ifdef OBJ_COFF
c19d1205
ZW
2782static symbolS *
2783find_real_start (symbolS * symbolP)
2784{
2785 char * real_start;
2786 const char * name = S_GET_NAME (symbolP);
2787 symbolS * new_target;
2788
2789 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2790#define STUB_NAME ".real_start_of"
2791
2792 if (name == NULL)
2793 abort ();
2794
37f6032b
ZW
2795 /* The compiler may generate BL instructions to local labels because
2796 it needs to perform a branch to a far away location. These labels
2797 do not have a corresponding ".real_start_of" label. We check
2798 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2799 the ".real_start_of" convention for nonlocal branches. */
2800 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2801 return symbolP;
2802
e1fa0163 2803 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2804 new_target = symbol_find (real_start);
e1fa0163 2805 free (real_start);
c19d1205
ZW
2806
2807 if (new_target == NULL)
2808 {
bd3ba5d1 2809 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2810 new_target = symbolP;
2811 }
2812
c19d1205
ZW
2813 return new_target;
2814}
4343666d 2815#endif
c19d1205
ZW
2816
2817static void
2818opcode_select (int width)
2819{
2820 switch (width)
2821 {
2822 case 16:
2823 if (! thumb_mode)
2824 {
e74cfd16 2825 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2826 as_bad (_("selected processor does not support THUMB opcodes"));
2827
2828 thumb_mode = 1;
2829 /* No need to force the alignment, since we will have been
2830 coming from ARM mode, which is word-aligned. */
2831 record_alignment (now_seg, 1);
2832 }
c19d1205
ZW
2833 break;
2834
2835 case 32:
2836 if (thumb_mode)
2837 {
e74cfd16 2838 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2839 as_bad (_("selected processor does not support ARM opcodes"));
2840
2841 thumb_mode = 0;
2842
2843 if (!need_pass_2)
2844 frag_align (2, 0, 0);
2845
2846 record_alignment (now_seg, 1);
2847 }
c19d1205
ZW
2848 break;
2849
2850 default:
2851 as_bad (_("invalid instruction size selected (%d)"), width);
2852 }
2853}
2854
2855static void
2856s_arm (int ignore ATTRIBUTE_UNUSED)
2857{
2858 opcode_select (32);
2859 demand_empty_rest_of_line ();
2860}
2861
2862static void
2863s_thumb (int ignore ATTRIBUTE_UNUSED)
2864{
2865 opcode_select (16);
2866 demand_empty_rest_of_line ();
2867}
2868
2869static void
2870s_code (int unused ATTRIBUTE_UNUSED)
2871{
2872 int temp;
2873
2874 temp = get_absolute_expression ();
2875 switch (temp)
2876 {
2877 case 16:
2878 case 32:
2879 opcode_select (temp);
2880 break;
2881
2882 default:
2883 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2884 }
2885}
2886
2887static void
2888s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2889{
2890 /* If we are not already in thumb mode go into it, EVEN if
2891 the target processor does not support thumb instructions.
2892 This is used by gcc/config/arm/lib1funcs.asm for example
2893 to compile interworking support functions even if the
2894 target processor should not support interworking. */
2895 if (! thumb_mode)
2896 {
2897 thumb_mode = 2;
2898 record_alignment (now_seg, 1);
2899 }
2900
2901 demand_empty_rest_of_line ();
2902}
2903
2904static void
2905s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2906{
2907 s_thumb (0);
2908
2909 /* The following label is the name/address of the start of a Thumb function.
2910 We need to know this for the interworking support. */
2911 label_is_thumb_function_name = TRUE;
2912}
2913
2914/* Perform a .set directive, but also mark the alias as
2915 being a thumb function. */
2916
2917static void
2918s_thumb_set (int equiv)
2919{
2920 /* XXX the following is a duplicate of the code for s_set() in read.c
2921 We cannot just call that code as we need to get at the symbol that
2922 is created. */
2923 char * name;
2924 char delim;
2925 char * end_name;
2926 symbolS * symbolP;
2927
2928 /* Especial apologies for the random logic:
2929 This just grew, and could be parsed much more simply!
2930 Dean - in haste. */
d02603dc 2931 delim = get_symbol_name (& name);
c19d1205 2932 end_name = input_line_pointer;
d02603dc 2933 (void) restore_line_pointer (delim);
c19d1205
ZW
2934
2935 if (*input_line_pointer != ',')
2936 {
2937 *end_name = 0;
2938 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2939 *end_name = delim;
2940 ignore_rest_of_line ();
2941 return;
2942 }
2943
2944 input_line_pointer++;
2945 *end_name = 0;
2946
2947 if (name[0] == '.' && name[1] == '\0')
2948 {
2949 /* XXX - this should not happen to .thumb_set. */
2950 abort ();
2951 }
2952
2953 if ((symbolP = symbol_find (name)) == NULL
2954 && (symbolP = md_undefined_symbol (name)) == NULL)
2955 {
2956#ifndef NO_LISTING
2957 /* When doing symbol listings, play games with dummy fragments living
2958 outside the normal fragment chain to record the file and line info
c19d1205 2959 for this symbol. */
b99bd4ef
NC
2960 if (listing & LISTING_SYMBOLS)
2961 {
2962 extern struct list_info_struct * listing_tail;
21d799b5 2963 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2964
2965 memset (dummy_frag, 0, sizeof (fragS));
2966 dummy_frag->fr_type = rs_fill;
2967 dummy_frag->line = listing_tail;
2968 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2969 dummy_frag->fr_symbol = symbolP;
2970 }
2971 else
2972#endif
2973 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2974
2975#ifdef OBJ_COFF
2976 /* "set" symbols are local unless otherwise specified. */
2977 SF_SET_LOCAL (symbolP);
2978#endif /* OBJ_COFF */
2979 } /* Make a new symbol. */
2980
2981 symbol_table_insert (symbolP);
2982
2983 * end_name = delim;
2984
2985 if (equiv
2986 && S_IS_DEFINED (symbolP)
2987 && S_GET_SEGMENT (symbolP) != reg_section)
2988 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2989
2990 pseudo_set (symbolP);
2991
2992 demand_empty_rest_of_line ();
2993
c19d1205 2994 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2995
2996 THUMB_SET_FUNC (symbolP, 1);
2997 ARM_SET_THUMB (symbolP, 1);
2998#if defined OBJ_ELF || defined OBJ_COFF
2999 ARM_SET_INTERWORK (symbolP, support_interwork);
3000#endif
3001}
3002
c19d1205 3003/* Directives: Mode selection. */
b99bd4ef 3004
c19d1205
ZW
3005/* .syntax [unified|divided] - choose the new unified syntax
3006 (same for Arm and Thumb encoding, modulo slight differences in what
3007 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 3008static void
c19d1205 3009s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 3010{
c19d1205
ZW
3011 char *name, delim;
3012
d02603dc 3013 delim = get_symbol_name (& name);
c19d1205
ZW
3014
3015 if (!strcasecmp (name, "unified"))
3016 unified_syntax = TRUE;
3017 else if (!strcasecmp (name, "divided"))
3018 unified_syntax = FALSE;
3019 else
3020 {
3021 as_bad (_("unrecognized syntax mode \"%s\""), name);
3022 return;
3023 }
d02603dc 3024 (void) restore_line_pointer (delim);
b99bd4ef
NC
3025 demand_empty_rest_of_line ();
3026}
3027
c19d1205
ZW
3028/* Directives: sectioning and alignment. */
3029
c19d1205
ZW
3030static void
3031s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3032{
c19d1205
ZW
3033 /* We don't support putting frags in the BSS segment, we fake it by
3034 marking in_bss, then looking at s_skip for clues. */
3035 subseg_set (bss_section, 0);
3036 demand_empty_rest_of_line ();
cd000bff
DJ
3037
3038#ifdef md_elf_section_change_hook
3039 md_elf_section_change_hook ();
3040#endif
c19d1205 3041}
b99bd4ef 3042
c19d1205
ZW
3043static void
3044s_even (int ignore ATTRIBUTE_UNUSED)
3045{
3046 /* Never make frag if expect extra pass. */
3047 if (!need_pass_2)
3048 frag_align (1, 0, 0);
b99bd4ef 3049
c19d1205 3050 record_alignment (now_seg, 1);
b99bd4ef 3051
c19d1205 3052 demand_empty_rest_of_line ();
b99bd4ef
NC
3053}
3054
2e6976a8
DG
3055/* Directives: CodeComposer Studio. */
3056
3057/* .ref (for CodeComposer Studio syntax only). */
3058static void
3059s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3060{
3061 if (codecomposer_syntax)
3062 ignore_rest_of_line ();
3063 else
3064 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3065}
3066
3067/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3068 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3069static void
3070asmfunc_debug (const char * name)
3071{
3072 static const char * last_name = NULL;
3073
3074 if (name != NULL)
3075 {
3076 gas_assert (last_name == NULL);
3077 last_name = name;
3078
3079 if (debug_type == DEBUG_STABS)
3080 stabs_generate_asm_func (name, name);
3081 }
3082 else
3083 {
3084 gas_assert (last_name != NULL);
3085
3086 if (debug_type == DEBUG_STABS)
3087 stabs_generate_asm_endfunc (last_name, last_name);
3088
3089 last_name = NULL;
3090 }
3091}
3092
3093static void
3094s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3095{
3096 if (codecomposer_syntax)
3097 {
3098 switch (asmfunc_state)
3099 {
3100 case OUTSIDE_ASMFUNC:
3101 asmfunc_state = WAITING_ASMFUNC_NAME;
3102 break;
3103
3104 case WAITING_ASMFUNC_NAME:
3105 as_bad (_(".asmfunc repeated."));
3106 break;
3107
3108 case WAITING_ENDASMFUNC:
3109 as_bad (_(".asmfunc without function."));
3110 break;
3111 }
3112 demand_empty_rest_of_line ();
3113 }
3114 else
3115 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3116}
3117
3118static void
3119s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3120{
3121 if (codecomposer_syntax)
3122 {
3123 switch (asmfunc_state)
3124 {
3125 case OUTSIDE_ASMFUNC:
3126 as_bad (_(".endasmfunc without a .asmfunc."));
3127 break;
3128
3129 case WAITING_ASMFUNC_NAME:
3130 as_bad (_(".endasmfunc without function."));
3131 break;
3132
3133 case WAITING_ENDASMFUNC:
3134 asmfunc_state = OUTSIDE_ASMFUNC;
3135 asmfunc_debug (NULL);
3136 break;
3137 }
3138 demand_empty_rest_of_line ();
3139 }
3140 else
3141 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3142}
3143
3144static void
3145s_ccs_def (int name)
3146{
3147 if (codecomposer_syntax)
3148 s_globl (name);
3149 else
3150 as_bad (_(".def pseudo-op only available with -mccs flag."));
3151}
3152
c19d1205 3153/* Directives: Literal pools. */
a737bd4d 3154
c19d1205
ZW
3155static literal_pool *
3156find_literal_pool (void)
a737bd4d 3157{
c19d1205 3158 literal_pool * pool;
a737bd4d 3159
c19d1205 3160 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3161 {
c19d1205
ZW
3162 if (pool->section == now_seg
3163 && pool->sub_section == now_subseg)
3164 break;
a737bd4d
NC
3165 }
3166
c19d1205 3167 return pool;
a737bd4d
NC
3168}
3169
c19d1205
ZW
3170static literal_pool *
3171find_or_make_literal_pool (void)
a737bd4d 3172{
c19d1205
ZW
3173 /* Next literal pool ID number. */
3174 static unsigned int latest_pool_num = 1;
3175 literal_pool * pool;
a737bd4d 3176
c19d1205 3177 pool = find_literal_pool ();
a737bd4d 3178
c19d1205 3179 if (pool == NULL)
a737bd4d 3180 {
c19d1205 3181 /* Create a new pool. */
325801bd 3182 pool = XNEW (literal_pool);
c19d1205
ZW
3183 if (! pool)
3184 return NULL;
a737bd4d 3185
c19d1205
ZW
3186 pool->next_free_entry = 0;
3187 pool->section = now_seg;
3188 pool->sub_section = now_subseg;
3189 pool->next = list_of_pools;
3190 pool->symbol = NULL;
8335d6aa 3191 pool->alignment = 2;
c19d1205
ZW
3192
3193 /* Add it to the list. */
3194 list_of_pools = pool;
a737bd4d 3195 }
a737bd4d 3196
c19d1205
ZW
3197 /* New pools, and emptied pools, will have a NULL symbol. */
3198 if (pool->symbol == NULL)
a737bd4d 3199 {
c19d1205
ZW
3200 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3201 (valueT) 0, &zero_address_frag);
3202 pool->id = latest_pool_num ++;
a737bd4d
NC
3203 }
3204
c19d1205
ZW
3205 /* Done. */
3206 return pool;
a737bd4d
NC
3207}
3208
c19d1205 3209/* Add the literal in the global 'inst'
5f4273c7 3210 structure to the relevant literal pool. */
b99bd4ef
NC
3211
3212static int
8335d6aa 3213add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3214{
8335d6aa
JW
3215#define PADDING_SLOT 0x1
3216#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3217 literal_pool * pool;
8335d6aa
JW
3218 unsigned int entry, pool_size = 0;
3219 bfd_boolean padding_slot_p = FALSE;
e56c722b 3220 unsigned imm1 = 0;
8335d6aa
JW
3221 unsigned imm2 = 0;
3222
3223 if (nbytes == 8)
3224 {
3225 imm1 = inst.operands[1].imm;
3226 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3227 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3228 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3229 if (target_big_endian)
3230 {
3231 imm1 = imm2;
3232 imm2 = inst.operands[1].imm;
3233 }
3234 }
b99bd4ef 3235
c19d1205
ZW
3236 pool = find_or_make_literal_pool ();
3237
3238 /* Check if this literal value is already in the pool. */
3239 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3240 {
8335d6aa
JW
3241 if (nbytes == 4)
3242 {
3243 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3244 && (inst.reloc.exp.X_op == O_constant)
3245 && (pool->literals[entry].X_add_number
3246 == inst.reloc.exp.X_add_number)
3247 && (pool->literals[entry].X_md == nbytes)
3248 && (pool->literals[entry].X_unsigned
3249 == inst.reloc.exp.X_unsigned))
3250 break;
3251
3252 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3253 && (inst.reloc.exp.X_op == O_symbol)
3254 && (pool->literals[entry].X_add_number
3255 == inst.reloc.exp.X_add_number)
3256 && (pool->literals[entry].X_add_symbol
3257 == inst.reloc.exp.X_add_symbol)
3258 && (pool->literals[entry].X_op_symbol
3259 == inst.reloc.exp.X_op_symbol)
3260 && (pool->literals[entry].X_md == nbytes))
3261 break;
3262 }
3263 else if ((nbytes == 8)
3264 && !(pool_size & 0x7)
3265 && ((entry + 1) != pool->next_free_entry)
3266 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3267 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3268 && (pool->literals[entry].X_unsigned
3269 == inst.reloc.exp.X_unsigned)
3270 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3271 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3272 && (pool->literals[entry + 1].X_unsigned
3273 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3274 break;
3275
8335d6aa
JW
3276 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3277 if (padding_slot_p && (nbytes == 4))
c19d1205 3278 break;
8335d6aa
JW
3279
3280 pool_size += 4;
b99bd4ef
NC
3281 }
3282
c19d1205
ZW
3283 /* Do we need to create a new entry? */
3284 if (entry == pool->next_free_entry)
3285 {
3286 if (entry >= MAX_LITERAL_POOL_SIZE)
3287 {
3288 inst.error = _("literal pool overflow");
3289 return FAIL;
3290 }
3291
8335d6aa
JW
3292 if (nbytes == 8)
3293 {
3294 /* For 8-byte entries, we align to an 8-byte boundary,
3295 and split it into two 4-byte entries, because on 32-bit
3296 host, 8-byte constants are treated as big num, thus
3297 saved in "generic_bignum" which will be overwritten
3298 by later assignments.
3299
3300 We also need to make sure there is enough space for
3301 the split.
3302
3303 We also check to make sure the literal operand is a
3304 constant number. */
19f2f6a9
JW
3305 if (!(inst.reloc.exp.X_op == O_constant
3306 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3307 {
3308 inst.error = _("invalid type for literal pool");
3309 return FAIL;
3310 }
3311 else if (pool_size & 0x7)
3312 {
3313 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3314 {
3315 inst.error = _("literal pool overflow");
3316 return FAIL;
3317 }
3318
3319 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3320 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3321 pool->literals[entry].X_add_number = 0;
3322 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3323 pool->next_free_entry += 1;
3324 pool_size += 4;
3325 }
3326 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3327 {
3328 inst.error = _("literal pool overflow");
3329 return FAIL;
3330 }
3331
3332 pool->literals[entry] = inst.reloc.exp;
3333 pool->literals[entry].X_op = O_constant;
3334 pool->literals[entry].X_add_number = imm1;
3335 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3336 pool->literals[entry++].X_md = 4;
3337 pool->literals[entry] = inst.reloc.exp;
3338 pool->literals[entry].X_op = O_constant;
3339 pool->literals[entry].X_add_number = imm2;
3340 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3341 pool->literals[entry].X_md = 4;
3342 pool->alignment = 3;
3343 pool->next_free_entry += 1;
3344 }
3345 else
3346 {
3347 pool->literals[entry] = inst.reloc.exp;
3348 pool->literals[entry].X_md = 4;
3349 }
3350
a8040cf2
NC
3351#ifdef OBJ_ELF
3352 /* PR ld/12974: Record the location of the first source line to reference
3353 this entry in the literal pool. If it turns out during linking that the
3354 symbol does not exist we will be able to give an accurate line number for
3355 the (first use of the) missing reference. */
3356 if (debug_type == DEBUG_DWARF2)
3357 dwarf2_where (pool->locs + entry);
3358#endif
c19d1205
ZW
3359 pool->next_free_entry += 1;
3360 }
8335d6aa
JW
3361 else if (padding_slot_p)
3362 {
3363 pool->literals[entry] = inst.reloc.exp;
3364 pool->literals[entry].X_md = nbytes;
3365 }
b99bd4ef 3366
c19d1205 3367 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3368 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3369 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3370
c19d1205 3371 return SUCCESS;
b99bd4ef
NC
3372}
3373
2e6976a8 3374bfd_boolean
2e57ce7b 3375tc_start_label_without_colon (void)
2e6976a8
DG
3376{
3377 bfd_boolean ret = TRUE;
3378
3379 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3380 {
2e57ce7b 3381 const char *label = input_line_pointer;
2e6976a8
DG
3382
3383 while (!is_end_of_line[(int) label[-1]])
3384 --label;
3385
3386 if (*label == '.')
3387 {
3388 as_bad (_("Invalid label '%s'"), label);
3389 ret = FALSE;
3390 }
3391
3392 asmfunc_debug (label);
3393
3394 asmfunc_state = WAITING_ENDASMFUNC;
3395 }
3396
3397 return ret;
3398}
3399
c19d1205 3400/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3401 a later date assign it a value. That's what these functions do. */
e16bb312 3402
c19d1205
ZW
3403static void
3404symbol_locate (symbolS * symbolP,
3405 const char * name, /* It is copied, the caller can modify. */
3406 segT segment, /* Segment identifier (SEG_<something>). */
3407 valueT valu, /* Symbol value. */
3408 fragS * frag) /* Associated fragment. */
3409{
e57e6ddc 3410 size_t name_length;
c19d1205 3411 char * preserved_copy_of_name;
e16bb312 3412
c19d1205
ZW
3413 name_length = strlen (name) + 1; /* +1 for \0. */
3414 obstack_grow (&notes, name, name_length);
21d799b5 3415 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3416
c19d1205
ZW
3417#ifdef tc_canonicalize_symbol_name
3418 preserved_copy_of_name =
3419 tc_canonicalize_symbol_name (preserved_copy_of_name);
3420#endif
b99bd4ef 3421
c19d1205 3422 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3423
c19d1205
ZW
3424 S_SET_SEGMENT (symbolP, segment);
3425 S_SET_VALUE (symbolP, valu);
3426 symbol_clear_list_pointers (symbolP);
b99bd4ef 3427
c19d1205 3428 symbol_set_frag (symbolP, frag);
b99bd4ef 3429
c19d1205
ZW
3430 /* Link to end of symbol chain. */
3431 {
3432 extern int symbol_table_frozen;
b99bd4ef 3433
c19d1205
ZW
3434 if (symbol_table_frozen)
3435 abort ();
3436 }
b99bd4ef 3437
c19d1205 3438 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3439
c19d1205 3440 obj_symbol_new_hook (symbolP);
b99bd4ef 3441
c19d1205
ZW
3442#ifdef tc_symbol_new_hook
3443 tc_symbol_new_hook (symbolP);
3444#endif
3445
3446#ifdef DEBUG_SYMS
3447 verify_symbol_chain (symbol_rootP, symbol_lastP);
3448#endif /* DEBUG_SYMS */
b99bd4ef
NC
3449}
3450
c19d1205
ZW
3451static void
3452s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3453{
c19d1205
ZW
3454 unsigned int entry;
3455 literal_pool * pool;
3456 char sym_name[20];
b99bd4ef 3457
c19d1205
ZW
3458 pool = find_literal_pool ();
3459 if (pool == NULL
3460 || pool->symbol == NULL
3461 || pool->next_free_entry == 0)
3462 return;
b99bd4ef 3463
c19d1205
ZW
3464 /* Align pool as you have word accesses.
3465 Only make a frag if we have to. */
3466 if (!need_pass_2)
8335d6aa 3467 frag_align (pool->alignment, 0, 0);
b99bd4ef 3468
c19d1205 3469 record_alignment (now_seg, 2);
b99bd4ef 3470
aaca88ef 3471#ifdef OBJ_ELF
47fc6e36
WN
3472 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3473 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3474#endif
c19d1205 3475 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3476
c19d1205
ZW
3477 symbol_locate (pool->symbol, sym_name, now_seg,
3478 (valueT) frag_now_fix (), frag_now);
3479 symbol_table_insert (pool->symbol);
b99bd4ef 3480
c19d1205 3481 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3482
c19d1205
ZW
3483#if defined OBJ_COFF || defined OBJ_ELF
3484 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3485#endif
6c43fab6 3486
c19d1205 3487 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3488 {
3489#ifdef OBJ_ELF
3490 if (debug_type == DEBUG_DWARF2)
3491 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3492#endif
3493 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3494 emit_expr (&(pool->literals[entry]),
3495 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3496 }
b99bd4ef 3497
c19d1205
ZW
3498 /* Mark the pool as empty. */
3499 pool->next_free_entry = 0;
3500 pool->symbol = NULL;
b99bd4ef
NC
3501}
3502
c19d1205
ZW
3503#ifdef OBJ_ELF
3504/* Forward declarations for functions below, in the MD interface
3505 section. */
3506static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3507static valueT create_unwind_entry (int);
3508static void start_unwind_section (const segT, int);
3509static void add_unwind_opcode (valueT, int);
3510static void flush_pending_unwind (void);
b99bd4ef 3511
c19d1205 3512/* Directives: Data. */
b99bd4ef 3513
c19d1205
ZW
3514static void
3515s_arm_elf_cons (int nbytes)
3516{
3517 expressionS exp;
b99bd4ef 3518
c19d1205
ZW
3519#ifdef md_flush_pending_output
3520 md_flush_pending_output ();
3521#endif
b99bd4ef 3522
c19d1205 3523 if (is_it_end_of_statement ())
b99bd4ef 3524 {
c19d1205
ZW
3525 demand_empty_rest_of_line ();
3526 return;
b99bd4ef
NC
3527 }
3528
c19d1205
ZW
3529#ifdef md_cons_align
3530 md_cons_align (nbytes);
3531#endif
b99bd4ef 3532
c19d1205
ZW
3533 mapping_state (MAP_DATA);
3534 do
b99bd4ef 3535 {
c19d1205
ZW
3536 int reloc;
3537 char *base = input_line_pointer;
b99bd4ef 3538
c19d1205 3539 expression (& exp);
b99bd4ef 3540
c19d1205
ZW
3541 if (exp.X_op != O_symbol)
3542 emit_expr (&exp, (unsigned int) nbytes);
3543 else
3544 {
3545 char *before_reloc = input_line_pointer;
3546 reloc = parse_reloc (&input_line_pointer);
3547 if (reloc == -1)
3548 {
3549 as_bad (_("unrecognized relocation suffix"));
3550 ignore_rest_of_line ();
3551 return;
3552 }
3553 else if (reloc == BFD_RELOC_UNUSED)
3554 emit_expr (&exp, (unsigned int) nbytes);
3555 else
3556 {
21d799b5 3557 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3558 bfd_reloc_type_lookup (stdoutput,
3559 (bfd_reloc_code_real_type) reloc);
c19d1205 3560 int size = bfd_get_reloc_size (howto);
b99bd4ef 3561
2fc8bdac
ZW
3562 if (reloc == BFD_RELOC_ARM_PLT32)
3563 {
3564 as_bad (_("(plt) is only valid on branch targets"));
3565 reloc = BFD_RELOC_UNUSED;
3566 size = 0;
3567 }
3568
c19d1205 3569 if (size > nbytes)
992a06ee
AM
3570 as_bad (ngettext ("%s relocations do not fit in %d byte",
3571 "%s relocations do not fit in %d bytes",
3572 nbytes),
c19d1205
ZW
3573 howto->name, nbytes);
3574 else
3575 {
3576 /* We've parsed an expression stopping at O_symbol.
3577 But there may be more expression left now that we
3578 have parsed the relocation marker. Parse it again.
3579 XXX Surely there is a cleaner way to do this. */
3580 char *p = input_line_pointer;
3581 int offset;
325801bd 3582 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3583
c19d1205
ZW
3584 memcpy (save_buf, base, input_line_pointer - base);
3585 memmove (base + (input_line_pointer - before_reloc),
3586 base, before_reloc - base);
3587
3588 input_line_pointer = base + (input_line_pointer-before_reloc);
3589 expression (&exp);
3590 memcpy (base, save_buf, p - base);
3591
3592 offset = nbytes - size;
4b1a927e
AM
3593 p = frag_more (nbytes);
3594 memset (p, 0, nbytes);
c19d1205 3595 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3596 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3597 free (save_buf);
c19d1205
ZW
3598 }
3599 }
3600 }
b99bd4ef 3601 }
c19d1205 3602 while (*input_line_pointer++ == ',');
b99bd4ef 3603
c19d1205
ZW
3604 /* Put terminator back into stream. */
3605 input_line_pointer --;
3606 demand_empty_rest_of_line ();
b99bd4ef
NC
3607}
3608
c921be7d
NC
3609/* Emit an expression containing a 32-bit thumb instruction.
3610 Implementation based on put_thumb32_insn. */
3611
3612static void
3613emit_thumb32_expr (expressionS * exp)
3614{
3615 expressionS exp_high = *exp;
3616
3617 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3618 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3619 exp->X_add_number &= 0xffff;
3620 emit_expr (exp, (unsigned int) THUMB_SIZE);
3621}
3622
3623/* Guess the instruction size based on the opcode. */
3624
3625static int
3626thumb_insn_size (int opcode)
3627{
3628 if ((unsigned int) opcode < 0xe800u)
3629 return 2;
3630 else if ((unsigned int) opcode >= 0xe8000000u)
3631 return 4;
3632 else
3633 return 0;
3634}
3635
3636static bfd_boolean
3637emit_insn (expressionS *exp, int nbytes)
3638{
3639 int size = 0;
3640
3641 if (exp->X_op == O_constant)
3642 {
3643 size = nbytes;
3644
3645 if (size == 0)
3646 size = thumb_insn_size (exp->X_add_number);
3647
3648 if (size != 0)
3649 {
3650 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3651 {
3652 as_bad (_(".inst.n operand too big. "\
3653 "Use .inst.w instead"));
3654 size = 0;
3655 }
3656 else
3657 {
3658 if (now_it.state == AUTOMATIC_IT_BLOCK)
3659 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3660 else
3661 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3662
3663 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3664 emit_thumb32_expr (exp);
3665 else
3666 emit_expr (exp, (unsigned int) size);
3667
3668 it_fsm_post_encode ();
3669 }
3670 }
3671 else
3672 as_bad (_("cannot determine Thumb instruction size. " \
3673 "Use .inst.n/.inst.w instead"));
3674 }
3675 else
3676 as_bad (_("constant expression required"));
3677
3678 return (size != 0);
3679}
3680
3681/* Like s_arm_elf_cons but do not use md_cons_align and
3682 set the mapping state to MAP_ARM/MAP_THUMB. */
3683
3684static void
3685s_arm_elf_inst (int nbytes)
3686{
3687 if (is_it_end_of_statement ())
3688 {
3689 demand_empty_rest_of_line ();
3690 return;
3691 }
3692
3693 /* Calling mapping_state () here will not change ARM/THUMB,
3694 but will ensure not to be in DATA state. */
3695
3696 if (thumb_mode)
3697 mapping_state (MAP_THUMB);
3698 else
3699 {
3700 if (nbytes != 0)
3701 {
3702 as_bad (_("width suffixes are invalid in ARM mode"));
3703 ignore_rest_of_line ();
3704 return;
3705 }
3706
3707 nbytes = 4;
3708
3709 mapping_state (MAP_ARM);
3710 }
3711
3712 do
3713 {
3714 expressionS exp;
3715
3716 expression (& exp);
3717
3718 if (! emit_insn (& exp, nbytes))
3719 {
3720 ignore_rest_of_line ();
3721 return;
3722 }
3723 }
3724 while (*input_line_pointer++ == ',');
3725
3726 /* Put terminator back into stream. */
3727 input_line_pointer --;
3728 demand_empty_rest_of_line ();
3729}
b99bd4ef 3730
c19d1205 3731/* Parse a .rel31 directive. */
b99bd4ef 3732
c19d1205
ZW
3733static void
3734s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3735{
3736 expressionS exp;
3737 char *p;
3738 valueT highbit;
b99bd4ef 3739
c19d1205
ZW
3740 highbit = 0;
3741 if (*input_line_pointer == '1')
3742 highbit = 0x80000000;
3743 else if (*input_line_pointer != '0')
3744 as_bad (_("expected 0 or 1"));
b99bd4ef 3745
c19d1205
ZW
3746 input_line_pointer++;
3747 if (*input_line_pointer != ',')
3748 as_bad (_("missing comma"));
3749 input_line_pointer++;
b99bd4ef 3750
c19d1205
ZW
3751#ifdef md_flush_pending_output
3752 md_flush_pending_output ();
3753#endif
b99bd4ef 3754
c19d1205
ZW
3755#ifdef md_cons_align
3756 md_cons_align (4);
3757#endif
b99bd4ef 3758
c19d1205 3759 mapping_state (MAP_DATA);
b99bd4ef 3760
c19d1205 3761 expression (&exp);
b99bd4ef 3762
c19d1205
ZW
3763 p = frag_more (4);
3764 md_number_to_chars (p, highbit, 4);
3765 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3766 BFD_RELOC_ARM_PREL31);
b99bd4ef 3767
c19d1205 3768 demand_empty_rest_of_line ();
b99bd4ef
NC
3769}
3770
c19d1205 3771/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3772
c19d1205 3773/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3774
c19d1205
ZW
3775static void
3776s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3777{
3778 demand_empty_rest_of_line ();
921e5f0a
PB
3779 if (unwind.proc_start)
3780 {
c921be7d 3781 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3782 return;
3783 }
3784
c19d1205
ZW
3785 /* Mark the start of the function. */
3786 unwind.proc_start = expr_build_dot ();
b99bd4ef 3787
c19d1205
ZW
3788 /* Reset the rest of the unwind info. */
3789 unwind.opcode_count = 0;
3790 unwind.table_entry = NULL;
3791 unwind.personality_routine = NULL;
3792 unwind.personality_index = -1;
3793 unwind.frame_size = 0;
3794 unwind.fp_offset = 0;
fdfde340 3795 unwind.fp_reg = REG_SP;
c19d1205
ZW
3796 unwind.fp_used = 0;
3797 unwind.sp_restored = 0;
3798}
b99bd4ef 3799
b99bd4ef 3800
c19d1205
ZW
3801/* Parse a handlerdata directive. Creates the exception handling table entry
3802 for the function. */
b99bd4ef 3803
c19d1205
ZW
3804static void
3805s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3806{
3807 demand_empty_rest_of_line ();
921e5f0a 3808 if (!unwind.proc_start)
c921be7d 3809 as_bad (MISSING_FNSTART);
921e5f0a 3810
c19d1205 3811 if (unwind.table_entry)
6decc662 3812 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3813
c19d1205
ZW
3814 create_unwind_entry (1);
3815}
a737bd4d 3816
c19d1205 3817/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3818
c19d1205
ZW
3819static void
3820s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3821{
3822 long where;
3823 char *ptr;
3824 valueT val;
940b5ce0 3825 unsigned int marked_pr_dependency;
f02232aa 3826
c19d1205 3827 demand_empty_rest_of_line ();
f02232aa 3828
921e5f0a
PB
3829 if (!unwind.proc_start)
3830 {
c921be7d 3831 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3832 return;
3833 }
3834
c19d1205
ZW
3835 /* Add eh table entry. */
3836 if (unwind.table_entry == NULL)
3837 val = create_unwind_entry (0);
3838 else
3839 val = 0;
f02232aa 3840
c19d1205
ZW
3841 /* Add index table entry. This is two words. */
3842 start_unwind_section (unwind.saved_seg, 1);
3843 frag_align (2, 0, 0);
3844 record_alignment (now_seg, 2);
b99bd4ef 3845
c19d1205 3846 ptr = frag_more (8);
5011093d 3847 memset (ptr, 0, 8);
c19d1205 3848 where = frag_now_fix () - 8;
f02232aa 3849
c19d1205
ZW
3850 /* Self relative offset of the function start. */
3851 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3852 BFD_RELOC_ARM_PREL31);
f02232aa 3853
c19d1205
ZW
3854 /* Indicate dependency on EHABI-defined personality routines to the
3855 linker, if it hasn't been done already. */
940b5ce0
DJ
3856 marked_pr_dependency
3857 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3858 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3859 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3860 {
5f4273c7
NC
3861 static const char *const name[] =
3862 {
3863 "__aeabi_unwind_cpp_pr0",
3864 "__aeabi_unwind_cpp_pr1",
3865 "__aeabi_unwind_cpp_pr2"
3866 };
c19d1205
ZW
3867 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3868 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3869 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3870 |= 1 << unwind.personality_index;
c19d1205 3871 }
f02232aa 3872
c19d1205
ZW
3873 if (val)
3874 /* Inline exception table entry. */
3875 md_number_to_chars (ptr + 4, val, 4);
3876 else
3877 /* Self relative offset of the table entry. */
3878 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3879 BFD_RELOC_ARM_PREL31);
f02232aa 3880
c19d1205
ZW
3881 /* Restore the original section. */
3882 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3883
3884 unwind.proc_start = NULL;
c19d1205 3885}
f02232aa 3886
f02232aa 3887
c19d1205 3888/* Parse an unwind_cantunwind directive. */
b99bd4ef 3889
c19d1205
ZW
3890static void
3891s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3892{
3893 demand_empty_rest_of_line ();
921e5f0a 3894 if (!unwind.proc_start)
c921be7d 3895 as_bad (MISSING_FNSTART);
921e5f0a 3896
c19d1205
ZW
3897 if (unwind.personality_routine || unwind.personality_index != -1)
3898 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3899
c19d1205
ZW
3900 unwind.personality_index = -2;
3901}
b99bd4ef 3902
b99bd4ef 3903
c19d1205 3904/* Parse a personalityindex directive. */
b99bd4ef 3905
c19d1205
ZW
3906static void
3907s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3908{
3909 expressionS exp;
b99bd4ef 3910
921e5f0a 3911 if (!unwind.proc_start)
c921be7d 3912 as_bad (MISSING_FNSTART);
921e5f0a 3913
c19d1205
ZW
3914 if (unwind.personality_routine || unwind.personality_index != -1)
3915 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3916
c19d1205 3917 expression (&exp);
b99bd4ef 3918
c19d1205
ZW
3919 if (exp.X_op != O_constant
3920 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3921 {
c19d1205
ZW
3922 as_bad (_("bad personality routine number"));
3923 ignore_rest_of_line ();
3924 return;
b99bd4ef
NC
3925 }
3926
c19d1205 3927 unwind.personality_index = exp.X_add_number;
b99bd4ef 3928
c19d1205
ZW
3929 demand_empty_rest_of_line ();
3930}
e16bb312 3931
e16bb312 3932
c19d1205 3933/* Parse a personality directive. */
e16bb312 3934
c19d1205
ZW
3935static void
3936s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3937{
3938 char *name, *p, c;
a737bd4d 3939
921e5f0a 3940 if (!unwind.proc_start)
c921be7d 3941 as_bad (MISSING_FNSTART);
921e5f0a 3942
c19d1205
ZW
3943 if (unwind.personality_routine || unwind.personality_index != -1)
3944 as_bad (_("duplicate .personality directive"));
a737bd4d 3945
d02603dc 3946 c = get_symbol_name (& name);
c19d1205 3947 p = input_line_pointer;
d02603dc
NC
3948 if (c == '"')
3949 ++ input_line_pointer;
c19d1205
ZW
3950 unwind.personality_routine = symbol_find_or_make (name);
3951 *p = c;
3952 demand_empty_rest_of_line ();
3953}
e16bb312 3954
e16bb312 3955
c19d1205 3956/* Parse a directive saving core registers. */
e16bb312 3957
c19d1205
ZW
3958static void
3959s_arm_unwind_save_core (void)
e16bb312 3960{
c19d1205
ZW
3961 valueT op;
3962 long range;
3963 int n;
e16bb312 3964
c19d1205
ZW
3965 range = parse_reg_list (&input_line_pointer);
3966 if (range == FAIL)
e16bb312 3967 {
c19d1205
ZW
3968 as_bad (_("expected register list"));
3969 ignore_rest_of_line ();
3970 return;
3971 }
e16bb312 3972
c19d1205 3973 demand_empty_rest_of_line ();
e16bb312 3974
c19d1205
ZW
3975 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3976 into .unwind_save {..., sp...}. We aren't bothered about the value of
3977 ip because it is clobbered by calls. */
3978 if (unwind.sp_restored && unwind.fp_reg == 12
3979 && (range & 0x3000) == 0x1000)
3980 {
3981 unwind.opcode_count--;
3982 unwind.sp_restored = 0;
3983 range = (range | 0x2000) & ~0x1000;
3984 unwind.pending_offset = 0;
3985 }
e16bb312 3986
01ae4198
DJ
3987 /* Pop r4-r15. */
3988 if (range & 0xfff0)
c19d1205 3989 {
01ae4198
DJ
3990 /* See if we can use the short opcodes. These pop a block of up to 8
3991 registers starting with r4, plus maybe r14. */
3992 for (n = 0; n < 8; n++)
3993 {
3994 /* Break at the first non-saved register. */
3995 if ((range & (1 << (n + 4))) == 0)
3996 break;
3997 }
3998 /* See if there are any other bits set. */
3999 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4000 {
4001 /* Use the long form. */
4002 op = 0x8000 | ((range >> 4) & 0xfff);
4003 add_unwind_opcode (op, 2);
4004 }
0dd132b6 4005 else
01ae4198
DJ
4006 {
4007 /* Use the short form. */
4008 if (range & 0x4000)
4009 op = 0xa8; /* Pop r14. */
4010 else
4011 op = 0xa0; /* Do not pop r14. */
4012 op |= (n - 1);
4013 add_unwind_opcode (op, 1);
4014 }
c19d1205 4015 }
0dd132b6 4016
c19d1205
ZW
4017 /* Pop r0-r3. */
4018 if (range & 0xf)
4019 {
4020 op = 0xb100 | (range & 0xf);
4021 add_unwind_opcode (op, 2);
0dd132b6
NC
4022 }
4023
c19d1205
ZW
4024 /* Record the number of bytes pushed. */
4025 for (n = 0; n < 16; n++)
4026 {
4027 if (range & (1 << n))
4028 unwind.frame_size += 4;
4029 }
0dd132b6
NC
4030}
4031
c19d1205
ZW
4032
4033/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4034
4035static void
c19d1205 4036s_arm_unwind_save_fpa (int reg)
b99bd4ef 4037{
c19d1205
ZW
4038 expressionS exp;
4039 int num_regs;
4040 valueT op;
b99bd4ef 4041
c19d1205
ZW
4042 /* Get Number of registers to transfer. */
4043 if (skip_past_comma (&input_line_pointer) != FAIL)
4044 expression (&exp);
4045 else
4046 exp.X_op = O_illegal;
b99bd4ef 4047
c19d1205 4048 if (exp.X_op != O_constant)
b99bd4ef 4049 {
c19d1205
ZW
4050 as_bad (_("expected , <constant>"));
4051 ignore_rest_of_line ();
b99bd4ef
NC
4052 return;
4053 }
4054
c19d1205
ZW
4055 num_regs = exp.X_add_number;
4056
4057 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4058 {
c19d1205
ZW
4059 as_bad (_("number of registers must be in the range [1:4]"));
4060 ignore_rest_of_line ();
b99bd4ef
NC
4061 return;
4062 }
4063
c19d1205 4064 demand_empty_rest_of_line ();
b99bd4ef 4065
c19d1205
ZW
4066 if (reg == 4)
4067 {
4068 /* Short form. */
4069 op = 0xb4 | (num_regs - 1);
4070 add_unwind_opcode (op, 1);
4071 }
b99bd4ef
NC
4072 else
4073 {
c19d1205
ZW
4074 /* Long form. */
4075 op = 0xc800 | (reg << 4) | (num_regs - 1);
4076 add_unwind_opcode (op, 2);
b99bd4ef 4077 }
c19d1205 4078 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4079}
4080
c19d1205 4081
fa073d69
MS
4082/* Parse a directive saving VFP registers for ARMv6 and above. */
4083
4084static void
4085s_arm_unwind_save_vfp_armv6 (void)
4086{
4087 int count;
4088 unsigned int start;
4089 valueT op;
4090 int num_vfpv3_regs = 0;
4091 int num_regs_below_16;
4092
4093 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4094 if (count == FAIL)
4095 {
4096 as_bad (_("expected register list"));
4097 ignore_rest_of_line ();
4098 return;
4099 }
4100
4101 demand_empty_rest_of_line ();
4102
4103 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4104 than FSTMX/FLDMX-style ones). */
4105
4106 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4107 if (start >= 16)
4108 num_vfpv3_regs = count;
4109 else if (start + count > 16)
4110 num_vfpv3_regs = start + count - 16;
4111
4112 if (num_vfpv3_regs > 0)
4113 {
4114 int start_offset = start > 16 ? start - 16 : 0;
4115 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4116 add_unwind_opcode (op, 2);
4117 }
4118
4119 /* Generate opcode for registers numbered in the range 0 .. 15. */
4120 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4121 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4122 if (num_regs_below_16 > 0)
4123 {
4124 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4125 add_unwind_opcode (op, 2);
4126 }
4127
4128 unwind.frame_size += count * 8;
4129}
4130
4131
4132/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4133
4134static void
c19d1205 4135s_arm_unwind_save_vfp (void)
b99bd4ef 4136{
c19d1205 4137 int count;
ca3f61f7 4138 unsigned int reg;
c19d1205 4139 valueT op;
b99bd4ef 4140
5287ad62 4141 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4142 if (count == FAIL)
b99bd4ef 4143 {
c19d1205
ZW
4144 as_bad (_("expected register list"));
4145 ignore_rest_of_line ();
b99bd4ef
NC
4146 return;
4147 }
4148
c19d1205 4149 demand_empty_rest_of_line ();
b99bd4ef 4150
c19d1205 4151 if (reg == 8)
b99bd4ef 4152 {
c19d1205
ZW
4153 /* Short form. */
4154 op = 0xb8 | (count - 1);
4155 add_unwind_opcode (op, 1);
b99bd4ef 4156 }
c19d1205 4157 else
b99bd4ef 4158 {
c19d1205
ZW
4159 /* Long form. */
4160 op = 0xb300 | (reg << 4) | (count - 1);
4161 add_unwind_opcode (op, 2);
b99bd4ef 4162 }
c19d1205
ZW
4163 unwind.frame_size += count * 8 + 4;
4164}
b99bd4ef 4165
b99bd4ef 4166
c19d1205
ZW
4167/* Parse a directive saving iWMMXt data registers. */
4168
4169static void
4170s_arm_unwind_save_mmxwr (void)
4171{
4172 int reg;
4173 int hi_reg;
4174 int i;
4175 unsigned mask = 0;
4176 valueT op;
b99bd4ef 4177
c19d1205
ZW
4178 if (*input_line_pointer == '{')
4179 input_line_pointer++;
b99bd4ef 4180
c19d1205 4181 do
b99bd4ef 4182 {
dcbf9037 4183 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4184
c19d1205 4185 if (reg == FAIL)
b99bd4ef 4186 {
9b7132d3 4187 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4188 goto error;
b99bd4ef
NC
4189 }
4190
c19d1205
ZW
4191 if (mask >> reg)
4192 as_tsktsk (_("register list not in ascending order"));
4193 mask |= 1 << reg;
b99bd4ef 4194
c19d1205
ZW
4195 if (*input_line_pointer == '-')
4196 {
4197 input_line_pointer++;
dcbf9037 4198 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4199 if (hi_reg == FAIL)
4200 {
9b7132d3 4201 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4202 goto error;
4203 }
4204 else if (reg >= hi_reg)
4205 {
4206 as_bad (_("bad register range"));
4207 goto error;
4208 }
4209 for (; reg < hi_reg; reg++)
4210 mask |= 1 << reg;
4211 }
4212 }
4213 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4214
d996d970 4215 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4216
c19d1205 4217 demand_empty_rest_of_line ();
b99bd4ef 4218
708587a4 4219 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4220 the list. */
4221 flush_pending_unwind ();
b99bd4ef 4222
c19d1205 4223 for (i = 0; i < 16; i++)
b99bd4ef 4224 {
c19d1205
ZW
4225 if (mask & (1 << i))
4226 unwind.frame_size += 8;
b99bd4ef
NC
4227 }
4228
c19d1205
ZW
4229 /* Attempt to combine with a previous opcode. We do this because gcc
4230 likes to output separate unwind directives for a single block of
4231 registers. */
4232 if (unwind.opcode_count > 0)
b99bd4ef 4233 {
c19d1205
ZW
4234 i = unwind.opcodes[unwind.opcode_count - 1];
4235 if ((i & 0xf8) == 0xc0)
4236 {
4237 i &= 7;
4238 /* Only merge if the blocks are contiguous. */
4239 if (i < 6)
4240 {
4241 if ((mask & 0xfe00) == (1 << 9))
4242 {
4243 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4244 unwind.opcode_count--;
4245 }
4246 }
4247 else if (i == 6 && unwind.opcode_count >= 2)
4248 {
4249 i = unwind.opcodes[unwind.opcode_count - 2];
4250 reg = i >> 4;
4251 i &= 0xf;
b99bd4ef 4252
c19d1205
ZW
4253 op = 0xffff << (reg - 1);
4254 if (reg > 0
87a1fd79 4255 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4256 {
4257 op = (1 << (reg + i + 1)) - 1;
4258 op &= ~((1 << reg) - 1);
4259 mask |= op;
4260 unwind.opcode_count -= 2;
4261 }
4262 }
4263 }
b99bd4ef
NC
4264 }
4265
c19d1205
ZW
4266 hi_reg = 15;
4267 /* We want to generate opcodes in the order the registers have been
4268 saved, ie. descending order. */
4269 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4270 {
c19d1205
ZW
4271 /* Save registers in blocks. */
4272 if (reg < 0
4273 || !(mask & (1 << reg)))
4274 {
4275 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4276 preceding block. */
c19d1205
ZW
4277 if (reg != hi_reg)
4278 {
4279 if (reg == 9)
4280 {
4281 /* Short form. */
4282 op = 0xc0 | (hi_reg - 10);
4283 add_unwind_opcode (op, 1);
4284 }
4285 else
4286 {
4287 /* Long form. */
4288 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4289 add_unwind_opcode (op, 2);
4290 }
4291 }
4292 hi_reg = reg - 1;
4293 }
b99bd4ef
NC
4294 }
4295
c19d1205
ZW
4296 return;
4297error:
4298 ignore_rest_of_line ();
b99bd4ef
NC
4299}
4300
4301static void
c19d1205 4302s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4303{
c19d1205
ZW
4304 int reg;
4305 int hi_reg;
4306 unsigned mask = 0;
4307 valueT op;
b99bd4ef 4308
c19d1205
ZW
4309 if (*input_line_pointer == '{')
4310 input_line_pointer++;
b99bd4ef 4311
477330fc
RM
4312 skip_whitespace (input_line_pointer);
4313
c19d1205 4314 do
b99bd4ef 4315 {
dcbf9037 4316 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4317
c19d1205
ZW
4318 if (reg == FAIL)
4319 {
9b7132d3 4320 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4321 goto error;
4322 }
b99bd4ef 4323
c19d1205
ZW
4324 reg -= 8;
4325 if (mask >> reg)
4326 as_tsktsk (_("register list not in ascending order"));
4327 mask |= 1 << reg;
b99bd4ef 4328
c19d1205
ZW
4329 if (*input_line_pointer == '-')
4330 {
4331 input_line_pointer++;
dcbf9037 4332 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4333 if (hi_reg == FAIL)
4334 {
9b7132d3 4335 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4336 goto error;
4337 }
4338 else if (reg >= hi_reg)
4339 {
4340 as_bad (_("bad register range"));
4341 goto error;
4342 }
4343 for (; reg < hi_reg; reg++)
4344 mask |= 1 << reg;
4345 }
b99bd4ef 4346 }
c19d1205 4347 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4348
d996d970 4349 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4350
c19d1205
ZW
4351 demand_empty_rest_of_line ();
4352
708587a4 4353 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4354 the list. */
4355 flush_pending_unwind ();
b99bd4ef 4356
c19d1205 4357 for (reg = 0; reg < 16; reg++)
b99bd4ef 4358 {
c19d1205
ZW
4359 if (mask & (1 << reg))
4360 unwind.frame_size += 4;
b99bd4ef 4361 }
c19d1205
ZW
4362 op = 0xc700 | mask;
4363 add_unwind_opcode (op, 2);
4364 return;
4365error:
4366 ignore_rest_of_line ();
b99bd4ef
NC
4367}
4368
c19d1205 4369
fa073d69
MS
4370/* Parse an unwind_save directive.
4371 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4372
b99bd4ef 4373static void
fa073d69 4374s_arm_unwind_save (int arch_v6)
b99bd4ef 4375{
c19d1205
ZW
4376 char *peek;
4377 struct reg_entry *reg;
4378 bfd_boolean had_brace = FALSE;
b99bd4ef 4379
921e5f0a 4380 if (!unwind.proc_start)
c921be7d 4381 as_bad (MISSING_FNSTART);
921e5f0a 4382
c19d1205
ZW
4383 /* Figure out what sort of save we have. */
4384 peek = input_line_pointer;
b99bd4ef 4385
c19d1205 4386 if (*peek == '{')
b99bd4ef 4387 {
c19d1205
ZW
4388 had_brace = TRUE;
4389 peek++;
b99bd4ef
NC
4390 }
4391
c19d1205 4392 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4393
c19d1205 4394 if (!reg)
b99bd4ef 4395 {
c19d1205
ZW
4396 as_bad (_("register expected"));
4397 ignore_rest_of_line ();
b99bd4ef
NC
4398 return;
4399 }
4400
c19d1205 4401 switch (reg->type)
b99bd4ef 4402 {
c19d1205
ZW
4403 case REG_TYPE_FN:
4404 if (had_brace)
4405 {
4406 as_bad (_("FPA .unwind_save does not take a register list"));
4407 ignore_rest_of_line ();
4408 return;
4409 }
93ac2687 4410 input_line_pointer = peek;
c19d1205 4411 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4412 return;
c19d1205 4413
1f5afe1c
NC
4414 case REG_TYPE_RN:
4415 s_arm_unwind_save_core ();
4416 return;
4417
fa073d69
MS
4418 case REG_TYPE_VFD:
4419 if (arch_v6)
477330fc 4420 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4421 else
477330fc 4422 s_arm_unwind_save_vfp ();
fa073d69 4423 return;
1f5afe1c
NC
4424
4425 case REG_TYPE_MMXWR:
4426 s_arm_unwind_save_mmxwr ();
4427 return;
4428
4429 case REG_TYPE_MMXWCG:
4430 s_arm_unwind_save_mmxwcg ();
4431 return;
c19d1205
ZW
4432
4433 default:
4434 as_bad (_(".unwind_save does not support this kind of register"));
4435 ignore_rest_of_line ();
b99bd4ef 4436 }
c19d1205 4437}
b99bd4ef 4438
b99bd4ef 4439
c19d1205
ZW
4440/* Parse an unwind_movsp directive. */
4441
4442static void
4443s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4444{
4445 int reg;
4446 valueT op;
4fa3602b 4447 int offset;
c19d1205 4448
921e5f0a 4449 if (!unwind.proc_start)
c921be7d 4450 as_bad (MISSING_FNSTART);
921e5f0a 4451
dcbf9037 4452 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4453 if (reg == FAIL)
b99bd4ef 4454 {
9b7132d3 4455 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4456 ignore_rest_of_line ();
b99bd4ef
NC
4457 return;
4458 }
4fa3602b
PB
4459
4460 /* Optional constant. */
4461 if (skip_past_comma (&input_line_pointer) != FAIL)
4462 {
4463 if (immediate_for_directive (&offset) == FAIL)
4464 return;
4465 }
4466 else
4467 offset = 0;
4468
c19d1205 4469 demand_empty_rest_of_line ();
b99bd4ef 4470
c19d1205 4471 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4472 {
c19d1205 4473 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4474 return;
4475 }
4476
c19d1205
ZW
4477 if (unwind.fp_reg != REG_SP)
4478 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4479
c19d1205
ZW
4480 /* Generate opcode to restore the value. */
4481 op = 0x90 | reg;
4482 add_unwind_opcode (op, 1);
4483
4484 /* Record the information for later. */
4485 unwind.fp_reg = reg;
4fa3602b 4486 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4487 unwind.sp_restored = 1;
b05fe5cf
ZW
4488}
4489
c19d1205
ZW
4490/* Parse an unwind_pad directive. */
4491
b05fe5cf 4492static void
c19d1205 4493s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4494{
c19d1205 4495 int offset;
b05fe5cf 4496
921e5f0a 4497 if (!unwind.proc_start)
c921be7d 4498 as_bad (MISSING_FNSTART);
921e5f0a 4499
c19d1205
ZW
4500 if (immediate_for_directive (&offset) == FAIL)
4501 return;
b99bd4ef 4502
c19d1205
ZW
4503 if (offset & 3)
4504 {
4505 as_bad (_("stack increment must be multiple of 4"));
4506 ignore_rest_of_line ();
4507 return;
4508 }
b99bd4ef 4509
c19d1205
ZW
4510 /* Don't generate any opcodes, just record the details for later. */
4511 unwind.frame_size += offset;
4512 unwind.pending_offset += offset;
4513
4514 demand_empty_rest_of_line ();
4515}
4516
4517/* Parse an unwind_setfp directive. */
4518
4519static void
4520s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4521{
c19d1205
ZW
4522 int sp_reg;
4523 int fp_reg;
4524 int offset;
4525
921e5f0a 4526 if (!unwind.proc_start)
c921be7d 4527 as_bad (MISSING_FNSTART);
921e5f0a 4528
dcbf9037 4529 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4530 if (skip_past_comma (&input_line_pointer) == FAIL)
4531 sp_reg = FAIL;
4532 else
dcbf9037 4533 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4534
c19d1205
ZW
4535 if (fp_reg == FAIL || sp_reg == FAIL)
4536 {
4537 as_bad (_("expected <reg>, <reg>"));
4538 ignore_rest_of_line ();
4539 return;
4540 }
b99bd4ef 4541
c19d1205
ZW
4542 /* Optional constant. */
4543 if (skip_past_comma (&input_line_pointer) != FAIL)
4544 {
4545 if (immediate_for_directive (&offset) == FAIL)
4546 return;
4547 }
4548 else
4549 offset = 0;
a737bd4d 4550
c19d1205 4551 demand_empty_rest_of_line ();
a737bd4d 4552
fdfde340 4553 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4554 {
c19d1205
ZW
4555 as_bad (_("register must be either sp or set by a previous"
4556 "unwind_movsp directive"));
4557 return;
a737bd4d
NC
4558 }
4559
c19d1205
ZW
4560 /* Don't generate any opcodes, just record the information for later. */
4561 unwind.fp_reg = fp_reg;
4562 unwind.fp_used = 1;
fdfde340 4563 if (sp_reg == REG_SP)
c19d1205
ZW
4564 unwind.fp_offset = unwind.frame_size - offset;
4565 else
4566 unwind.fp_offset -= offset;
a737bd4d
NC
4567}
4568
c19d1205
ZW
4569/* Parse an unwind_raw directive. */
4570
4571static void
4572s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4573{
c19d1205 4574 expressionS exp;
708587a4 4575 /* This is an arbitrary limit. */
c19d1205
ZW
4576 unsigned char op[16];
4577 int count;
a737bd4d 4578
921e5f0a 4579 if (!unwind.proc_start)
c921be7d 4580 as_bad (MISSING_FNSTART);
921e5f0a 4581
c19d1205
ZW
4582 expression (&exp);
4583 if (exp.X_op == O_constant
4584 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4585 {
c19d1205
ZW
4586 unwind.frame_size += exp.X_add_number;
4587 expression (&exp);
4588 }
4589 else
4590 exp.X_op = O_illegal;
a737bd4d 4591
c19d1205
ZW
4592 if (exp.X_op != O_constant)
4593 {
4594 as_bad (_("expected <offset>, <opcode>"));
4595 ignore_rest_of_line ();
4596 return;
4597 }
a737bd4d 4598
c19d1205 4599 count = 0;
a737bd4d 4600
c19d1205
ZW
4601 /* Parse the opcode. */
4602 for (;;)
4603 {
4604 if (count >= 16)
4605 {
4606 as_bad (_("unwind opcode too long"));
4607 ignore_rest_of_line ();
a737bd4d 4608 }
c19d1205 4609 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4610 {
c19d1205
ZW
4611 as_bad (_("invalid unwind opcode"));
4612 ignore_rest_of_line ();
4613 return;
a737bd4d 4614 }
c19d1205 4615 op[count++] = exp.X_add_number;
a737bd4d 4616
c19d1205
ZW
4617 /* Parse the next byte. */
4618 if (skip_past_comma (&input_line_pointer) == FAIL)
4619 break;
a737bd4d 4620
c19d1205
ZW
4621 expression (&exp);
4622 }
b99bd4ef 4623
c19d1205
ZW
4624 /* Add the opcode bytes in reverse order. */
4625 while (count--)
4626 add_unwind_opcode (op[count], 1);
b99bd4ef 4627
c19d1205 4628 demand_empty_rest_of_line ();
b99bd4ef 4629}
ee065d83
PB
4630
4631
4632/* Parse a .eabi_attribute directive. */
4633
4634static void
4635s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4636{
0420f52b 4637 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4638
4639 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4640 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4641}
4642
0855e32b
NS
4643/* Emit a tls fix for the symbol. */
4644
4645static void
4646s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4647{
4648 char *p;
4649 expressionS exp;
4650#ifdef md_flush_pending_output
4651 md_flush_pending_output ();
4652#endif
4653
4654#ifdef md_cons_align
4655 md_cons_align (4);
4656#endif
4657
4658 /* Since we're just labelling the code, there's no need to define a
4659 mapping symbol. */
4660 expression (&exp);
4661 p = obstack_next_free (&frchain_now->frch_obstack);
4662 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4663 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4664 : BFD_RELOC_ARM_TLS_DESCSEQ);
4665}
cdf9ccec 4666#endif /* OBJ_ELF */
0855e32b 4667
ee065d83 4668static void s_arm_arch (int);
7a1d4c38 4669static void s_arm_object_arch (int);
ee065d83
PB
4670static void s_arm_cpu (int);
4671static void s_arm_fpu (int);
69133863 4672static void s_arm_arch_extension (int);
b99bd4ef 4673
f0927246
NC
4674#ifdef TE_PE
4675
4676static void
5f4273c7 4677pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4678{
4679 expressionS exp;
4680
4681 do
4682 {
4683 expression (&exp);
4684 if (exp.X_op == O_symbol)
4685 exp.X_op = O_secrel;
4686
4687 emit_expr (&exp, 4);
4688 }
4689 while (*input_line_pointer++ == ',');
4690
4691 input_line_pointer--;
4692 demand_empty_rest_of_line ();
4693}
4694#endif /* TE_PE */
4695
c19d1205
ZW
4696/* This table describes all the machine specific pseudo-ops the assembler
4697 has to support. The fields are:
4698 pseudo-op name without dot
4699 function to call to execute this pseudo-op
4700 Integer arg to pass to the function. */
b99bd4ef 4701
c19d1205 4702const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4703{
c19d1205
ZW
4704 /* Never called because '.req' does not start a line. */
4705 { "req", s_req, 0 },
dcbf9037
JB
4706 /* Following two are likewise never called. */
4707 { "dn", s_dn, 0 },
4708 { "qn", s_qn, 0 },
c19d1205
ZW
4709 { "unreq", s_unreq, 0 },
4710 { "bss", s_bss, 0 },
db2ed2e0 4711 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4712 { "arm", s_arm, 0 },
4713 { "thumb", s_thumb, 0 },
4714 { "code", s_code, 0 },
4715 { "force_thumb", s_force_thumb, 0 },
4716 { "thumb_func", s_thumb_func, 0 },
4717 { "thumb_set", s_thumb_set, 0 },
4718 { "even", s_even, 0 },
4719 { "ltorg", s_ltorg, 0 },
4720 { "pool", s_ltorg, 0 },
4721 { "syntax", s_syntax, 0 },
8463be01
PB
4722 { "cpu", s_arm_cpu, 0 },
4723 { "arch", s_arm_arch, 0 },
7a1d4c38 4724 { "object_arch", s_arm_object_arch, 0 },
8463be01 4725 { "fpu", s_arm_fpu, 0 },
69133863 4726 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4727#ifdef OBJ_ELF
c921be7d
NC
4728 { "word", s_arm_elf_cons, 4 },
4729 { "long", s_arm_elf_cons, 4 },
4730 { "inst.n", s_arm_elf_inst, 2 },
4731 { "inst.w", s_arm_elf_inst, 4 },
4732 { "inst", s_arm_elf_inst, 0 },
4733 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4734 { "fnstart", s_arm_unwind_fnstart, 0 },
4735 { "fnend", s_arm_unwind_fnend, 0 },
4736 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4737 { "personality", s_arm_unwind_personality, 0 },
4738 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4739 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4740 { "save", s_arm_unwind_save, 0 },
fa073d69 4741 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4742 { "movsp", s_arm_unwind_movsp, 0 },
4743 { "pad", s_arm_unwind_pad, 0 },
4744 { "setfp", s_arm_unwind_setfp, 0 },
4745 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4746 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4747 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4748#else
4749 { "word", cons, 4},
f0927246
NC
4750
4751 /* These are used for dwarf. */
4752 {"2byte", cons, 2},
4753 {"4byte", cons, 4},
4754 {"8byte", cons, 8},
4755 /* These are used for dwarf2. */
4756 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4757 { "loc", dwarf2_directive_loc, 0 },
4758 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4759#endif
4760 { "extend", float_cons, 'x' },
4761 { "ldouble", float_cons, 'x' },
4762 { "packed", float_cons, 'p' },
f0927246
NC
4763#ifdef TE_PE
4764 {"secrel32", pe_directive_secrel, 0},
4765#endif
2e6976a8
DG
4766
4767 /* These are for compatibility with CodeComposer Studio. */
4768 {"ref", s_ccs_ref, 0},
4769 {"def", s_ccs_def, 0},
4770 {"asmfunc", s_ccs_asmfunc, 0},
4771 {"endasmfunc", s_ccs_endasmfunc, 0},
4772
c19d1205
ZW
4773 { 0, 0, 0 }
4774};
4775\f
4776/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4777
c19d1205
ZW
4778/* Generic immediate-value read function for use in insn parsing.
4779 STR points to the beginning of the immediate (the leading #);
4780 VAL receives the value; if the value is outside [MIN, MAX]
4781 issue an error. PREFIX_OPT is true if the immediate prefix is
4782 optional. */
b99bd4ef 4783
c19d1205
ZW
4784static int
4785parse_immediate (char **str, int *val, int min, int max,
4786 bfd_boolean prefix_opt)
4787{
4788 expressionS exp;
0198d5e6 4789
c19d1205
ZW
4790 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4791 if (exp.X_op != O_constant)
b99bd4ef 4792 {
c19d1205
ZW
4793 inst.error = _("constant expression required");
4794 return FAIL;
4795 }
b99bd4ef 4796
c19d1205
ZW
4797 if (exp.X_add_number < min || exp.X_add_number > max)
4798 {
4799 inst.error = _("immediate value out of range");
4800 return FAIL;
4801 }
b99bd4ef 4802
c19d1205
ZW
4803 *val = exp.X_add_number;
4804 return SUCCESS;
4805}
b99bd4ef 4806
5287ad62 4807/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4808 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4809 instructions. Puts the result directly in inst.operands[i]. */
4810
4811static int
8335d6aa
JW
4812parse_big_immediate (char **str, int i, expressionS *in_exp,
4813 bfd_boolean allow_symbol_p)
5287ad62
JB
4814{
4815 expressionS exp;
8335d6aa 4816 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4817 char *ptr = *str;
4818
8335d6aa 4819 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4820
8335d6aa 4821 if (exp_p->X_op == O_constant)
036dc3f7 4822 {
8335d6aa 4823 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4824 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4825 O_constant. We have to be careful not to break compilation for
4826 32-bit X_add_number, though. */
8335d6aa 4827 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4828 {
8335d6aa
JW
4829 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4830 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4831 & 0xffffffff);
036dc3f7
PB
4832 inst.operands[i].regisimm = 1;
4833 }
4834 }
8335d6aa
JW
4835 else if (exp_p->X_op == O_big
4836 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4837 {
4838 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4839
5287ad62 4840 /* Bignums have their least significant bits in
477330fc
RM
4841 generic_bignum[0]. Make sure we put 32 bits in imm and
4842 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4843 gas_assert (parts != 0);
95b75c01
NC
4844
4845 /* Make sure that the number is not too big.
4846 PR 11972: Bignums can now be sign-extended to the
4847 size of a .octa so check that the out of range bits
4848 are all zero or all one. */
8335d6aa 4849 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4850 {
4851 LITTLENUM_TYPE m = -1;
4852
4853 if (generic_bignum[parts * 2] != 0
4854 && generic_bignum[parts * 2] != m)
4855 return FAIL;
4856
8335d6aa 4857 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4858 if (generic_bignum[j] != generic_bignum[j-1])
4859 return FAIL;
4860 }
4861
5287ad62
JB
4862 inst.operands[i].imm = 0;
4863 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4864 inst.operands[i].imm |= generic_bignum[idx]
4865 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4866 inst.operands[i].reg = 0;
4867 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4868 inst.operands[i].reg |= generic_bignum[idx]
4869 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4870 inst.operands[i].regisimm = 1;
4871 }
8335d6aa 4872 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4873 return FAIL;
5f4273c7 4874
5287ad62
JB
4875 *str = ptr;
4876
4877 return SUCCESS;
4878}
4879
c19d1205
ZW
4880/* Returns the pseudo-register number of an FPA immediate constant,
4881 or FAIL if there isn't a valid constant here. */
b99bd4ef 4882
c19d1205
ZW
4883static int
4884parse_fpa_immediate (char ** str)
4885{
4886 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4887 char * save_in;
4888 expressionS exp;
4889 int i;
4890 int j;
b99bd4ef 4891
c19d1205
ZW
4892 /* First try and match exact strings, this is to guarantee
4893 that some formats will work even for cross assembly. */
b99bd4ef 4894
c19d1205
ZW
4895 for (i = 0; fp_const[i]; i++)
4896 {
4897 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4898 {
c19d1205 4899 char *start = *str;
b99bd4ef 4900
c19d1205
ZW
4901 *str += strlen (fp_const[i]);
4902 if (is_end_of_line[(unsigned char) **str])
4903 return i + 8;
4904 *str = start;
4905 }
4906 }
b99bd4ef 4907
c19d1205
ZW
4908 /* Just because we didn't get a match doesn't mean that the constant
4909 isn't valid, just that it is in a format that we don't
4910 automatically recognize. Try parsing it with the standard
4911 expression routines. */
b99bd4ef 4912
c19d1205 4913 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4914
c19d1205
ZW
4915 /* Look for a raw floating point number. */
4916 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4917 && is_end_of_line[(unsigned char) *save_in])
4918 {
4919 for (i = 0; i < NUM_FLOAT_VALS; i++)
4920 {
4921 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4922 {
c19d1205
ZW
4923 if (words[j] != fp_values[i][j])
4924 break;
b99bd4ef
NC
4925 }
4926
c19d1205 4927 if (j == MAX_LITTLENUMS)
b99bd4ef 4928 {
c19d1205
ZW
4929 *str = save_in;
4930 return i + 8;
b99bd4ef
NC
4931 }
4932 }
4933 }
b99bd4ef 4934
c19d1205
ZW
4935 /* Try and parse a more complex expression, this will probably fail
4936 unless the code uses a floating point prefix (eg "0f"). */
4937 save_in = input_line_pointer;
4938 input_line_pointer = *str;
4939 if (expression (&exp) == absolute_section
4940 && exp.X_op == O_big
4941 && exp.X_add_number < 0)
4942 {
4943 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4944 Ditto for 15. */
ba592044
AM
4945#define X_PRECISION 5
4946#define E_PRECISION 15L
4947 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4948 {
4949 for (i = 0; i < NUM_FLOAT_VALS; i++)
4950 {
4951 for (j = 0; j < MAX_LITTLENUMS; j++)
4952 {
4953 if (words[j] != fp_values[i][j])
4954 break;
4955 }
b99bd4ef 4956
c19d1205
ZW
4957 if (j == MAX_LITTLENUMS)
4958 {
4959 *str = input_line_pointer;
4960 input_line_pointer = save_in;
4961 return i + 8;
4962 }
4963 }
4964 }
b99bd4ef
NC
4965 }
4966
c19d1205
ZW
4967 *str = input_line_pointer;
4968 input_line_pointer = save_in;
4969 inst.error = _("invalid FPA immediate expression");
4970 return FAIL;
b99bd4ef
NC
4971}
4972
136da414
JB
4973/* Returns 1 if a number has "quarter-precision" float format
4974 0baBbbbbbc defgh000 00000000 00000000. */
4975
4976static int
4977is_quarter_float (unsigned imm)
4978{
4979 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4980 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4981}
4982
aacf0b33
KT
4983
4984/* Detect the presence of a floating point or integer zero constant,
4985 i.e. #0.0 or #0. */
4986
4987static bfd_boolean
4988parse_ifimm_zero (char **in)
4989{
4990 int error_code;
4991
4992 if (!is_immediate_prefix (**in))
3c6452ae
TP
4993 {
4994 /* In unified syntax, all prefixes are optional. */
4995 if (!unified_syntax)
4996 return FALSE;
4997 }
4998 else
4999 ++*in;
0900a05b
JW
5000
5001 /* Accept #0x0 as a synonym for #0. */
5002 if (strncmp (*in, "0x", 2) == 0)
5003 {
5004 int val;
5005 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5006 return FALSE;
5007 return TRUE;
5008 }
5009
aacf0b33
KT
5010 error_code = atof_generic (in, ".", EXP_CHARS,
5011 &generic_floating_point_number);
5012
5013 if (!error_code
5014 && generic_floating_point_number.sign == '+'
5015 && (generic_floating_point_number.low
5016 > generic_floating_point_number.leader))
5017 return TRUE;
5018
5019 return FALSE;
5020}
5021
136da414
JB
5022/* Parse an 8-bit "quarter-precision" floating point number of the form:
5023 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5024 The zero and minus-zero cases need special handling, since they can't be
5025 encoded in the "quarter-precision" float format, but can nonetheless be
5026 loaded as integer constants. */
136da414
JB
5027
5028static unsigned
5029parse_qfloat_immediate (char **ccp, int *immed)
5030{
5031 char *str = *ccp;
c96612cc 5032 char *fpnum;
136da414 5033 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5034 int found_fpchar = 0;
5f4273c7 5035
136da414 5036 skip_past_char (&str, '#');
5f4273c7 5037
c96612cc
JB
5038 /* We must not accidentally parse an integer as a floating-point number. Make
5039 sure that the value we parse is not an integer by checking for special
5040 characters '.' or 'e'.
5041 FIXME: This is a horrible hack, but doing better is tricky because type
5042 information isn't in a very usable state at parse time. */
5043 fpnum = str;
5044 skip_whitespace (fpnum);
5045
5046 if (strncmp (fpnum, "0x", 2) == 0)
5047 return FAIL;
5048 else
5049 {
5050 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5051 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5052 {
5053 found_fpchar = 1;
5054 break;
5055 }
c96612cc
JB
5056
5057 if (!found_fpchar)
477330fc 5058 return FAIL;
c96612cc 5059 }
5f4273c7 5060
136da414
JB
5061 if ((str = atof_ieee (str, 's', words)) != NULL)
5062 {
5063 unsigned fpword = 0;
5064 int i;
5f4273c7 5065
136da414
JB
5066 /* Our FP word must be 32 bits (single-precision FP). */
5067 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5068 {
5069 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5070 fpword |= words[i];
5071 }
5f4273c7 5072
c96612cc 5073 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5074 *immed = fpword;
136da414 5075 else
477330fc 5076 return FAIL;
136da414
JB
5077
5078 *ccp = str;
5f4273c7 5079
136da414
JB
5080 return SUCCESS;
5081 }
5f4273c7 5082
136da414
JB
5083 return FAIL;
5084}
5085
c19d1205
ZW
5086/* Shift operands. */
5087enum shift_kind
b99bd4ef 5088{
c19d1205
ZW
5089 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5090};
b99bd4ef 5091
c19d1205
ZW
5092struct asm_shift_name
5093{
5094 const char *name;
5095 enum shift_kind kind;
5096};
b99bd4ef 5097
c19d1205
ZW
5098/* Third argument to parse_shift. */
5099enum parse_shift_mode
5100{
5101 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5102 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5103 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5104 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5105 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5106};
b99bd4ef 5107
c19d1205
ZW
5108/* Parse a <shift> specifier on an ARM data processing instruction.
5109 This has three forms:
b99bd4ef 5110
c19d1205
ZW
5111 (LSL|LSR|ASL|ASR|ROR) Rs
5112 (LSL|LSR|ASL|ASR|ROR) #imm
5113 RRX
b99bd4ef 5114
c19d1205
ZW
5115 Note that ASL is assimilated to LSL in the instruction encoding, and
5116 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5117
c19d1205
ZW
5118static int
5119parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5120{
c19d1205
ZW
5121 const struct asm_shift_name *shift_name;
5122 enum shift_kind shift;
5123 char *s = *str;
5124 char *p = s;
5125 int reg;
b99bd4ef 5126
c19d1205
ZW
5127 for (p = *str; ISALPHA (*p); p++)
5128 ;
b99bd4ef 5129
c19d1205 5130 if (p == *str)
b99bd4ef 5131 {
c19d1205
ZW
5132 inst.error = _("shift expression expected");
5133 return FAIL;
b99bd4ef
NC
5134 }
5135
21d799b5 5136 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5137 p - *str);
c19d1205
ZW
5138
5139 if (shift_name == NULL)
b99bd4ef 5140 {
c19d1205
ZW
5141 inst.error = _("shift expression expected");
5142 return FAIL;
b99bd4ef
NC
5143 }
5144
c19d1205 5145 shift = shift_name->kind;
b99bd4ef 5146
c19d1205
ZW
5147 switch (mode)
5148 {
5149 case NO_SHIFT_RESTRICT:
5150 case SHIFT_IMMEDIATE: break;
b99bd4ef 5151
c19d1205
ZW
5152 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5153 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5154 {
5155 inst.error = _("'LSL' or 'ASR' required");
5156 return FAIL;
5157 }
5158 break;
b99bd4ef 5159
c19d1205
ZW
5160 case SHIFT_LSL_IMMEDIATE:
5161 if (shift != SHIFT_LSL)
5162 {
5163 inst.error = _("'LSL' required");
5164 return FAIL;
5165 }
5166 break;
b99bd4ef 5167
c19d1205
ZW
5168 case SHIFT_ASR_IMMEDIATE:
5169 if (shift != SHIFT_ASR)
5170 {
5171 inst.error = _("'ASR' required");
5172 return FAIL;
5173 }
5174 break;
b99bd4ef 5175
c19d1205
ZW
5176 default: abort ();
5177 }
b99bd4ef 5178
c19d1205
ZW
5179 if (shift != SHIFT_RRX)
5180 {
5181 /* Whitespace can appear here if the next thing is a bare digit. */
5182 skip_whitespace (p);
b99bd4ef 5183
c19d1205 5184 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5185 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5186 {
5187 inst.operands[i].imm = reg;
5188 inst.operands[i].immisreg = 1;
5189 }
5190 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5191 return FAIL;
5192 }
5193 inst.operands[i].shift_kind = shift;
5194 inst.operands[i].shifted = 1;
5195 *str = p;
5196 return SUCCESS;
b99bd4ef
NC
5197}
5198
c19d1205 5199/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5200
c19d1205
ZW
5201 #<immediate>
5202 #<immediate>, <rotate>
5203 <Rm>
5204 <Rm>, <shift>
b99bd4ef 5205
c19d1205
ZW
5206 where <shift> is defined by parse_shift above, and <rotate> is a
5207 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5208 is deferred to md_apply_fix. */
b99bd4ef 5209
c19d1205
ZW
5210static int
5211parse_shifter_operand (char **str, int i)
5212{
5213 int value;
91d6fa6a 5214 expressionS exp;
b99bd4ef 5215
dcbf9037 5216 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5217 {
5218 inst.operands[i].reg = value;
5219 inst.operands[i].isreg = 1;
b99bd4ef 5220
c19d1205
ZW
5221 /* parse_shift will override this if appropriate */
5222 inst.reloc.exp.X_op = O_constant;
5223 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5224
c19d1205
ZW
5225 if (skip_past_comma (str) == FAIL)
5226 return SUCCESS;
b99bd4ef 5227
c19d1205
ZW
5228 /* Shift operation on register. */
5229 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5230 }
5231
c19d1205
ZW
5232 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5233 return FAIL;
b99bd4ef 5234
c19d1205 5235 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5236 {
c19d1205 5237 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5238 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5239 return FAIL;
b99bd4ef 5240
91d6fa6a 5241 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5242 {
5243 inst.error = _("constant expression expected");
5244 return FAIL;
5245 }
b99bd4ef 5246
91d6fa6a 5247 value = exp.X_add_number;
c19d1205
ZW
5248 if (value < 0 || value > 30 || value % 2 != 0)
5249 {
5250 inst.error = _("invalid rotation");
5251 return FAIL;
5252 }
5253 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5254 {
5255 inst.error = _("invalid constant");
5256 return FAIL;
5257 }
09d92015 5258
a415b1cd
JB
5259 /* Encode as specified. */
5260 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5261 return SUCCESS;
09d92015
MM
5262 }
5263
c19d1205
ZW
5264 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5265 inst.reloc.pc_rel = 0;
5266 return SUCCESS;
09d92015
MM
5267}
5268
4962c51a
MS
5269/* Group relocation information. Each entry in the table contains the
5270 textual name of the relocation as may appear in assembler source
5271 and must end with a colon.
5272 Along with this textual name are the relocation codes to be used if
5273 the corresponding instruction is an ALU instruction (ADD or SUB only),
5274 an LDR, an LDRS, or an LDC. */
5275
5276struct group_reloc_table_entry
5277{
5278 const char *name;
5279 int alu_code;
5280 int ldr_code;
5281 int ldrs_code;
5282 int ldc_code;
5283};
5284
5285typedef enum
5286{
5287 /* Varieties of non-ALU group relocation. */
5288
5289 GROUP_LDR,
5290 GROUP_LDRS,
5291 GROUP_LDC
5292} group_reloc_type;
5293
5294static struct group_reloc_table_entry group_reloc_table[] =
5295 { /* Program counter relative: */
5296 { "pc_g0_nc",
5297 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5298 0, /* LDR */
5299 0, /* LDRS */
5300 0 }, /* LDC */
5301 { "pc_g0",
5302 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5303 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5304 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5305 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5306 { "pc_g1_nc",
5307 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5308 0, /* LDR */
5309 0, /* LDRS */
5310 0 }, /* LDC */
5311 { "pc_g1",
5312 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5313 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5314 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5315 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5316 { "pc_g2",
5317 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5318 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5319 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5320 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5321 /* Section base relative */
5322 { "sb_g0_nc",
5323 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5324 0, /* LDR */
5325 0, /* LDRS */
5326 0 }, /* LDC */
5327 { "sb_g0",
5328 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5329 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5330 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5331 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5332 { "sb_g1_nc",
5333 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5334 0, /* LDR */
5335 0, /* LDRS */
5336 0 }, /* LDC */
5337 { "sb_g1",
5338 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5339 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5340 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5341 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5342 { "sb_g2",
5343 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5344 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5345 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5346 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5347 /* Absolute thumb alu relocations. */
5348 { "lower0_7",
5349 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5350 0, /* LDR. */
5351 0, /* LDRS. */
5352 0 }, /* LDC. */
5353 { "lower8_15",
5354 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5355 0, /* LDR. */
5356 0, /* LDRS. */
5357 0 }, /* LDC. */
5358 { "upper0_7",
5359 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5360 0, /* LDR. */
5361 0, /* LDRS. */
5362 0 }, /* LDC. */
5363 { "upper8_15",
5364 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5365 0, /* LDR. */
5366 0, /* LDRS. */
5367 0 } }; /* LDC. */
4962c51a
MS
5368
5369/* Given the address of a pointer pointing to the textual name of a group
5370 relocation as may appear in assembler source, attempt to find its details
5371 in group_reloc_table. The pointer will be updated to the character after
5372 the trailing colon. On failure, FAIL will be returned; SUCCESS
5373 otherwise. On success, *entry will be updated to point at the relevant
5374 group_reloc_table entry. */
5375
5376static int
5377find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5378{
5379 unsigned int i;
5380 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5381 {
5382 int length = strlen (group_reloc_table[i].name);
5383
5f4273c7
NC
5384 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5385 && (*str)[length] == ':')
477330fc
RM
5386 {
5387 *out = &group_reloc_table[i];
5388 *str += (length + 1);
5389 return SUCCESS;
5390 }
4962c51a
MS
5391 }
5392
5393 return FAIL;
5394}
5395
5396/* Parse a <shifter_operand> for an ARM data processing instruction
5397 (as for parse_shifter_operand) where group relocations are allowed:
5398
5399 #<immediate>
5400 #<immediate>, <rotate>
5401 #:<group_reloc>:<expression>
5402 <Rm>
5403 <Rm>, <shift>
5404
5405 where <group_reloc> is one of the strings defined in group_reloc_table.
5406 The hashes are optional.
5407
5408 Everything else is as for parse_shifter_operand. */
5409
5410static parse_operand_result
5411parse_shifter_operand_group_reloc (char **str, int i)
5412{
5413 /* Determine if we have the sequence of characters #: or just :
5414 coming next. If we do, then we check for a group relocation.
5415 If we don't, punt the whole lot to parse_shifter_operand. */
5416
5417 if (((*str)[0] == '#' && (*str)[1] == ':')
5418 || (*str)[0] == ':')
5419 {
5420 struct group_reloc_table_entry *entry;
5421
5422 if ((*str)[0] == '#')
477330fc 5423 (*str) += 2;
4962c51a 5424 else
477330fc 5425 (*str)++;
4962c51a
MS
5426
5427 /* Try to parse a group relocation. Anything else is an error. */
5428 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5429 {
5430 inst.error = _("unknown group relocation");
5431 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5432 }
4962c51a
MS
5433
5434 /* We now have the group relocation table entry corresponding to
477330fc 5435 the name in the assembler source. Next, we parse the expression. */
4962c51a 5436 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5437 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5438
5439 /* Record the relocation type (always the ALU variant here). */
21d799b5 5440 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5441 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5442
5443 return PARSE_OPERAND_SUCCESS;
5444 }
5445 else
5446 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5447 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5448
5449 /* Never reached. */
5450}
5451
8e560766
MGD
5452/* Parse a Neon alignment expression. Information is written to
5453 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5454
8e560766
MGD
5455 align .imm = align << 8, .immisalign=1, .preind=0 */
5456static parse_operand_result
5457parse_neon_alignment (char **str, int i)
5458{
5459 char *p = *str;
5460 expressionS exp;
5461
5462 my_get_expression (&exp, &p, GE_NO_PREFIX);
5463
5464 if (exp.X_op != O_constant)
5465 {
5466 inst.error = _("alignment must be constant");
5467 return PARSE_OPERAND_FAIL;
5468 }
5469
5470 inst.operands[i].imm = exp.X_add_number << 8;
5471 inst.operands[i].immisalign = 1;
5472 /* Alignments are not pre-indexes. */
5473 inst.operands[i].preind = 0;
5474
5475 *str = p;
5476 return PARSE_OPERAND_SUCCESS;
5477}
5478
c19d1205
ZW
5479/* Parse all forms of an ARM address expression. Information is written
5480 to inst.operands[i] and/or inst.reloc.
09d92015 5481
c19d1205 5482 Preindexed addressing (.preind=1):
09d92015 5483
c19d1205
ZW
5484 [Rn, #offset] .reg=Rn .reloc.exp=offset
5485 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5486 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5487 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5488
c19d1205 5489 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5490
c19d1205 5491 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5492
c19d1205
ZW
5493 [Rn], #offset .reg=Rn .reloc.exp=offset
5494 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5495 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5496 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5497
c19d1205 5498 Unindexed addressing (.preind=0, .postind=0):
09d92015 5499
c19d1205 5500 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5501
c19d1205 5502 Other:
09d92015 5503
c19d1205
ZW
5504 [Rn]{!} shorthand for [Rn,#0]{!}
5505 =immediate .isreg=0 .reloc.exp=immediate
5506 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5507
c19d1205
ZW
5508 It is the caller's responsibility to check for addressing modes not
5509 supported by the instruction, and to set inst.reloc.type. */
5510
4962c51a
MS
5511static parse_operand_result
5512parse_address_main (char **str, int i, int group_relocations,
477330fc 5513 group_reloc_type group_type)
09d92015 5514{
c19d1205
ZW
5515 char *p = *str;
5516 int reg;
09d92015 5517
c19d1205 5518 if (skip_past_char (&p, '[') == FAIL)
09d92015 5519 {
c19d1205
ZW
5520 if (skip_past_char (&p, '=') == FAIL)
5521 {
974da60d 5522 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5523 inst.reloc.pc_rel = 1;
5524 inst.operands[i].reg = REG_PC;
5525 inst.operands[i].isreg = 1;
5526 inst.operands[i].preind = 1;
09d92015 5527
8335d6aa
JW
5528 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5529 return PARSE_OPERAND_FAIL;
5530 }
5531 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5532 /*allow_symbol_p=*/TRUE))
4962c51a 5533 return PARSE_OPERAND_FAIL;
09d92015 5534
c19d1205 5535 *str = p;
4962c51a 5536 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5537 }
5538
8ab8155f
NC
5539 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5540 skip_whitespace (p);
5541
dcbf9037 5542 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5543 {
c19d1205 5544 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5545 return PARSE_OPERAND_FAIL;
09d92015 5546 }
c19d1205
ZW
5547 inst.operands[i].reg = reg;
5548 inst.operands[i].isreg = 1;
09d92015 5549
c19d1205 5550 if (skip_past_comma (&p) == SUCCESS)
09d92015 5551 {
c19d1205 5552 inst.operands[i].preind = 1;
09d92015 5553
c19d1205
ZW
5554 if (*p == '+') p++;
5555 else if (*p == '-') p++, inst.operands[i].negative = 1;
5556
dcbf9037 5557 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5558 {
c19d1205
ZW
5559 inst.operands[i].imm = reg;
5560 inst.operands[i].immisreg = 1;
5561
5562 if (skip_past_comma (&p) == SUCCESS)
5563 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5564 return PARSE_OPERAND_FAIL;
c19d1205 5565 }
5287ad62 5566 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5567 {
5568 /* FIXME: '@' should be used here, but it's filtered out by generic
5569 code before we get to see it here. This may be subject to
5570 change. */
5571 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5572
8e560766
MGD
5573 if (result != PARSE_OPERAND_SUCCESS)
5574 return result;
5575 }
c19d1205
ZW
5576 else
5577 {
5578 if (inst.operands[i].negative)
5579 {
5580 inst.operands[i].negative = 0;
5581 p--;
5582 }
4962c51a 5583
5f4273c7
NC
5584 if (group_relocations
5585 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5586 {
5587 struct group_reloc_table_entry *entry;
5588
477330fc
RM
5589 /* Skip over the #: or : sequence. */
5590 if (*p == '#')
5591 p += 2;
5592 else
5593 p++;
4962c51a
MS
5594
5595 /* Try to parse a group relocation. Anything else is an
477330fc 5596 error. */
4962c51a
MS
5597 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5598 {
5599 inst.error = _("unknown group relocation");
5600 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5601 }
5602
5603 /* We now have the group relocation table entry corresponding to
5604 the name in the assembler source. Next, we parse the
477330fc 5605 expression. */
4962c51a
MS
5606 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5607 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5608
5609 /* Record the relocation type. */
477330fc
RM
5610 switch (group_type)
5611 {
5612 case GROUP_LDR:
5613 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5614 break;
4962c51a 5615
477330fc
RM
5616 case GROUP_LDRS:
5617 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5618 break;
4962c51a 5619
477330fc
RM
5620 case GROUP_LDC:
5621 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5622 break;
4962c51a 5623
477330fc
RM
5624 default:
5625 gas_assert (0);
5626 }
4962c51a 5627
477330fc 5628 if (inst.reloc.type == 0)
4962c51a
MS
5629 {
5630 inst.error = _("this group relocation is not allowed on this instruction");
5631 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5632 }
477330fc
RM
5633 }
5634 else
26d97720
NS
5635 {
5636 char *q = p;
0198d5e6 5637
26d97720
NS
5638 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5639 return PARSE_OPERAND_FAIL;
5640 /* If the offset is 0, find out if it's a +0 or -0. */
5641 if (inst.reloc.exp.X_op == O_constant
5642 && inst.reloc.exp.X_add_number == 0)
5643 {
5644 skip_whitespace (q);
5645 if (*q == '#')
5646 {
5647 q++;
5648 skip_whitespace (q);
5649 }
5650 if (*q == '-')
5651 inst.operands[i].negative = 1;
5652 }
5653 }
09d92015
MM
5654 }
5655 }
8e560766
MGD
5656 else if (skip_past_char (&p, ':') == SUCCESS)
5657 {
5658 /* FIXME: '@' should be used here, but it's filtered out by generic code
5659 before we get to see it here. This may be subject to change. */
5660 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5661
8e560766
MGD
5662 if (result != PARSE_OPERAND_SUCCESS)
5663 return result;
5664 }
09d92015 5665
c19d1205 5666 if (skip_past_char (&p, ']') == FAIL)
09d92015 5667 {
c19d1205 5668 inst.error = _("']' expected");
4962c51a 5669 return PARSE_OPERAND_FAIL;
09d92015
MM
5670 }
5671
c19d1205
ZW
5672 if (skip_past_char (&p, '!') == SUCCESS)
5673 inst.operands[i].writeback = 1;
09d92015 5674
c19d1205 5675 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5676 {
c19d1205
ZW
5677 if (skip_past_char (&p, '{') == SUCCESS)
5678 {
5679 /* [Rn], {expr} - unindexed, with option */
5680 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5681 0, 255, TRUE) == FAIL)
4962c51a 5682 return PARSE_OPERAND_FAIL;
09d92015 5683
c19d1205
ZW
5684 if (skip_past_char (&p, '}') == FAIL)
5685 {
5686 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5687 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5688 }
5689 if (inst.operands[i].preind)
5690 {
5691 inst.error = _("cannot combine index with option");
4962c51a 5692 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5693 }
5694 *str = p;
4962c51a 5695 return PARSE_OPERAND_SUCCESS;
09d92015 5696 }
c19d1205
ZW
5697 else
5698 {
5699 inst.operands[i].postind = 1;
5700 inst.operands[i].writeback = 1;
09d92015 5701
c19d1205
ZW
5702 if (inst.operands[i].preind)
5703 {
5704 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5705 return PARSE_OPERAND_FAIL;
c19d1205 5706 }
09d92015 5707
c19d1205
ZW
5708 if (*p == '+') p++;
5709 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5710
dcbf9037 5711 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5712 {
477330fc
RM
5713 /* We might be using the immediate for alignment already. If we
5714 are, OR the register number into the low-order bits. */
5715 if (inst.operands[i].immisalign)
5716 inst.operands[i].imm |= reg;
5717 else
5718 inst.operands[i].imm = reg;
c19d1205 5719 inst.operands[i].immisreg = 1;
a737bd4d 5720
c19d1205
ZW
5721 if (skip_past_comma (&p) == SUCCESS)
5722 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5723 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5724 }
5725 else
5726 {
26d97720 5727 char *q = p;
0198d5e6 5728
c19d1205
ZW
5729 if (inst.operands[i].negative)
5730 {
5731 inst.operands[i].negative = 0;
5732 p--;
5733 }
5734 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5735 return PARSE_OPERAND_FAIL;
26d97720
NS
5736 /* If the offset is 0, find out if it's a +0 or -0. */
5737 if (inst.reloc.exp.X_op == O_constant
5738 && inst.reloc.exp.X_add_number == 0)
5739 {
5740 skip_whitespace (q);
5741 if (*q == '#')
5742 {
5743 q++;
5744 skip_whitespace (q);
5745 }
5746 if (*q == '-')
5747 inst.operands[i].negative = 1;
5748 }
c19d1205
ZW
5749 }
5750 }
a737bd4d
NC
5751 }
5752
c19d1205
ZW
5753 /* If at this point neither .preind nor .postind is set, we have a
5754 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5755 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5756 {
5757 inst.operands[i].preind = 1;
5758 inst.reloc.exp.X_op = O_constant;
5759 inst.reloc.exp.X_add_number = 0;
5760 }
5761 *str = p;
4962c51a
MS
5762 return PARSE_OPERAND_SUCCESS;
5763}
5764
5765static int
5766parse_address (char **str, int i)
5767{
21d799b5 5768 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5769 ? SUCCESS : FAIL;
4962c51a
MS
5770}
5771
5772static parse_operand_result
5773parse_address_group_reloc (char **str, int i, group_reloc_type type)
5774{
5775 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5776}
5777
b6895b4f
PB
5778/* Parse an operand for a MOVW or MOVT instruction. */
5779static int
5780parse_half (char **str)
5781{
5782 char * p;
5f4273c7 5783
b6895b4f
PB
5784 p = *str;
5785 skip_past_char (&p, '#');
5f4273c7 5786 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5787 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5788 else if (strncasecmp (p, ":upper16:", 9) == 0)
5789 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5790
5791 if (inst.reloc.type != BFD_RELOC_UNUSED)
5792 {
5793 p += 9;
5f4273c7 5794 skip_whitespace (p);
b6895b4f
PB
5795 }
5796
5797 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5798 return FAIL;
5799
5800 if (inst.reloc.type == BFD_RELOC_UNUSED)
5801 {
5802 if (inst.reloc.exp.X_op != O_constant)
5803 {
5804 inst.error = _("constant expression expected");
5805 return FAIL;
5806 }
5807 if (inst.reloc.exp.X_add_number < 0
5808 || inst.reloc.exp.X_add_number > 0xffff)
5809 {
5810 inst.error = _("immediate value out of range");
5811 return FAIL;
5812 }
5813 }
5814 *str = p;
5815 return SUCCESS;
5816}
5817
c19d1205 5818/* Miscellaneous. */
a737bd4d 5819
c19d1205
ZW
5820/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5821 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5822static int
d2cd1205 5823parse_psr (char **str, bfd_boolean lhs)
09d92015 5824{
c19d1205
ZW
5825 char *p;
5826 unsigned long psr_field;
62b3e311
PB
5827 const struct asm_psr *psr;
5828 char *start;
d2cd1205 5829 bfd_boolean is_apsr = FALSE;
ac7f631b 5830 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5831
a4482bb6
NC
5832 /* PR gas/12698: If the user has specified -march=all then m_profile will
5833 be TRUE, but we want to ignore it in this case as we are building for any
5834 CPU type, including non-m variants. */
823d2571 5835 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5836 m_profile = FALSE;
5837
c19d1205
ZW
5838 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5839 feature for ease of use and backwards compatibility. */
5840 p = *str;
62b3e311 5841 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5842 {
5843 if (m_profile)
5844 goto unsupported_psr;
fa94de6b 5845
d2cd1205
JB
5846 psr_field = SPSR_BIT;
5847 }
5848 else if (strncasecmp (p, "CPSR", 4) == 0)
5849 {
5850 if (m_profile)
5851 goto unsupported_psr;
5852
5853 psr_field = 0;
5854 }
5855 else if (strncasecmp (p, "APSR", 4) == 0)
5856 {
5857 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5858 and ARMv7-R architecture CPUs. */
5859 is_apsr = TRUE;
5860 psr_field = 0;
5861 }
5862 else if (m_profile)
62b3e311
PB
5863 {
5864 start = p;
5865 do
5866 p++;
5867 while (ISALNUM (*p) || *p == '_');
5868
d2cd1205
JB
5869 if (strncasecmp (start, "iapsr", 5) == 0
5870 || strncasecmp (start, "eapsr", 5) == 0
5871 || strncasecmp (start, "xpsr", 4) == 0
5872 || strncasecmp (start, "psr", 3) == 0)
5873 p = start + strcspn (start, "rR") + 1;
5874
21d799b5 5875 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5876 p - start);
d2cd1205 5877
62b3e311
PB
5878 if (!psr)
5879 return FAIL;
09d92015 5880
d2cd1205
JB
5881 /* If APSR is being written, a bitfield may be specified. Note that
5882 APSR itself is handled above. */
5883 if (psr->field <= 3)
5884 {
5885 psr_field = psr->field;
5886 is_apsr = TRUE;
5887 goto check_suffix;
5888 }
5889
62b3e311 5890 *str = p;
d2cd1205
JB
5891 /* M-profile MSR instructions have the mask field set to "10", except
5892 *PSR variants which modify APSR, which may use a different mask (and
5893 have been handled already). Do that by setting the PSR_f field
5894 here. */
5895 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5896 }
d2cd1205
JB
5897 else
5898 goto unsupported_psr;
09d92015 5899
62b3e311 5900 p += 4;
d2cd1205 5901check_suffix:
c19d1205
ZW
5902 if (*p == '_')
5903 {
5904 /* A suffix follows. */
c19d1205
ZW
5905 p++;
5906 start = p;
a737bd4d 5907
c19d1205
ZW
5908 do
5909 p++;
5910 while (ISALNUM (*p) || *p == '_');
a737bd4d 5911
d2cd1205
JB
5912 if (is_apsr)
5913 {
5914 /* APSR uses a notation for bits, rather than fields. */
5915 unsigned int nzcvq_bits = 0;
5916 unsigned int g_bit = 0;
5917 char *bit;
fa94de6b 5918
d2cd1205
JB
5919 for (bit = start; bit != p; bit++)
5920 {
5921 switch (TOLOWER (*bit))
477330fc 5922 {
d2cd1205
JB
5923 case 'n':
5924 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5925 break;
5926
5927 case 'z':
5928 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5929 break;
5930
5931 case 'c':
5932 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5933 break;
5934
5935 case 'v':
5936 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5937 break;
fa94de6b 5938
d2cd1205
JB
5939 case 'q':
5940 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5941 break;
fa94de6b 5942
d2cd1205
JB
5943 case 'g':
5944 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5945 break;
fa94de6b 5946
d2cd1205
JB
5947 default:
5948 inst.error = _("unexpected bit specified after APSR");
5949 return FAIL;
5950 }
5951 }
fa94de6b 5952
d2cd1205
JB
5953 if (nzcvq_bits == 0x1f)
5954 psr_field |= PSR_f;
fa94de6b 5955
d2cd1205
JB
5956 if (g_bit == 0x1)
5957 {
5958 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5959 {
d2cd1205
JB
5960 inst.error = _("selected processor does not "
5961 "support DSP extension");
5962 return FAIL;
5963 }
5964
5965 psr_field |= PSR_s;
5966 }
fa94de6b 5967
d2cd1205
JB
5968 if ((nzcvq_bits & 0x20) != 0
5969 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5970 || (g_bit & 0x2) != 0)
5971 {
5972 inst.error = _("bad bitmask specified after APSR");
5973 return FAIL;
5974 }
5975 }
5976 else
477330fc 5977 {
d2cd1205 5978 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5979 p - start);
d2cd1205 5980 if (!psr)
477330fc 5981 goto error;
a737bd4d 5982
d2cd1205
JB
5983 psr_field |= psr->field;
5984 }
a737bd4d 5985 }
c19d1205 5986 else
a737bd4d 5987 {
c19d1205
ZW
5988 if (ISALNUM (*p))
5989 goto error; /* Garbage after "[CS]PSR". */
5990
d2cd1205 5991 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5992 is deprecated, but allow it anyway. */
d2cd1205
JB
5993 if (is_apsr && lhs)
5994 {
5995 psr_field |= PSR_f;
5996 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5997 "deprecated"));
5998 }
5999 else if (!m_profile)
6000 /* These bits are never right for M-profile devices: don't set them
6001 (only code paths which read/write APSR reach here). */
6002 psr_field |= (PSR_c | PSR_f);
a737bd4d 6003 }
c19d1205
ZW
6004 *str = p;
6005 return psr_field;
a737bd4d 6006
d2cd1205
JB
6007 unsupported_psr:
6008 inst.error = _("selected processor does not support requested special "
6009 "purpose register");
6010 return FAIL;
6011
c19d1205
ZW
6012 error:
6013 inst.error = _("flag for {c}psr instruction expected");
6014 return FAIL;
a737bd4d
NC
6015}
6016
c19d1205
ZW
6017/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6018 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 6019
c19d1205
ZW
6020static int
6021parse_cps_flags (char **str)
a737bd4d 6022{
c19d1205
ZW
6023 int val = 0;
6024 int saw_a_flag = 0;
6025 char *s = *str;
a737bd4d 6026
c19d1205
ZW
6027 for (;;)
6028 switch (*s++)
6029 {
6030 case '\0': case ',':
6031 goto done;
a737bd4d 6032
c19d1205
ZW
6033 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6034 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6035 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6036
c19d1205
ZW
6037 default:
6038 inst.error = _("unrecognized CPS flag");
6039 return FAIL;
6040 }
a737bd4d 6041
c19d1205
ZW
6042 done:
6043 if (saw_a_flag == 0)
a737bd4d 6044 {
c19d1205
ZW
6045 inst.error = _("missing CPS flags");
6046 return FAIL;
a737bd4d 6047 }
a737bd4d 6048
c19d1205
ZW
6049 *str = s - 1;
6050 return val;
a737bd4d
NC
6051}
6052
c19d1205
ZW
6053/* Parse an endian specifier ("BE" or "LE", case insensitive);
6054 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6055
6056static int
c19d1205 6057parse_endian_specifier (char **str)
a737bd4d 6058{
c19d1205
ZW
6059 int little_endian;
6060 char *s = *str;
a737bd4d 6061
c19d1205
ZW
6062 if (strncasecmp (s, "BE", 2))
6063 little_endian = 0;
6064 else if (strncasecmp (s, "LE", 2))
6065 little_endian = 1;
6066 else
a737bd4d 6067 {
c19d1205 6068 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6069 return FAIL;
6070 }
6071
c19d1205 6072 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6073 {
c19d1205 6074 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6075 return FAIL;
6076 }
6077
c19d1205
ZW
6078 *str = s + 2;
6079 return little_endian;
6080}
a737bd4d 6081
c19d1205
ZW
6082/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6083 value suitable for poking into the rotate field of an sxt or sxta
6084 instruction, or FAIL on error. */
6085
6086static int
6087parse_ror (char **str)
6088{
6089 int rot;
6090 char *s = *str;
6091
6092 if (strncasecmp (s, "ROR", 3) == 0)
6093 s += 3;
6094 else
a737bd4d 6095 {
c19d1205 6096 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6097 return FAIL;
6098 }
c19d1205
ZW
6099
6100 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6101 return FAIL;
6102
6103 switch (rot)
a737bd4d 6104 {
c19d1205
ZW
6105 case 0: *str = s; return 0x0;
6106 case 8: *str = s; return 0x1;
6107 case 16: *str = s; return 0x2;
6108 case 24: *str = s; return 0x3;
6109
6110 default:
6111 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6112 return FAIL;
6113 }
c19d1205 6114}
a737bd4d 6115
c19d1205
ZW
6116/* Parse a conditional code (from conds[] below). The value returned is in the
6117 range 0 .. 14, or FAIL. */
6118static int
6119parse_cond (char **str)
6120{
c462b453 6121 char *q;
c19d1205 6122 const struct asm_cond *c;
c462b453
PB
6123 int n;
6124 /* Condition codes are always 2 characters, so matching up to
6125 3 characters is sufficient. */
6126 char cond[3];
a737bd4d 6127
c462b453
PB
6128 q = *str;
6129 n = 0;
6130 while (ISALPHA (*q) && n < 3)
6131 {
e07e6e58 6132 cond[n] = TOLOWER (*q);
c462b453
PB
6133 q++;
6134 n++;
6135 }
a737bd4d 6136
21d799b5 6137 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6138 if (!c)
a737bd4d 6139 {
c19d1205 6140 inst.error = _("condition required");
a737bd4d
NC
6141 return FAIL;
6142 }
6143
c19d1205
ZW
6144 *str = q;
6145 return c->value;
6146}
6147
643afb90
MW
6148/* Record a use of the given feature. */
6149static void
6150record_feature_use (const arm_feature_set *feature)
6151{
6152 if (thumb_mode)
6153 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6154 else
6155 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6156}
6157
e797f7e0
MGD
6158/* If the given feature available in the selected CPU, mark it as used.
6159 Returns TRUE iff feature is available. */
6160static bfd_boolean
6161mark_feature_used (const arm_feature_set *feature)
6162{
6163 /* Ensure the option is valid on the current architecture. */
6164 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6165 return FALSE;
6166
6167 /* Add the appropriate architecture feature for the barrier option used.
6168 */
643afb90 6169 record_feature_use (feature);
e797f7e0
MGD
6170
6171 return TRUE;
6172}
6173
62b3e311
PB
6174/* Parse an option for a barrier instruction. Returns the encoding for the
6175 option, or FAIL. */
6176static int
6177parse_barrier (char **str)
6178{
6179 char *p, *q;
6180 const struct asm_barrier_opt *o;
6181
6182 p = q = *str;
6183 while (ISALPHA (*q))
6184 q++;
6185
21d799b5 6186 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6187 q - p);
62b3e311
PB
6188 if (!o)
6189 return FAIL;
6190
e797f7e0
MGD
6191 if (!mark_feature_used (&o->arch))
6192 return FAIL;
6193
62b3e311
PB
6194 *str = q;
6195 return o->value;
6196}
6197
92e90b6e
PB
6198/* Parse the operands of a table branch instruction. Similar to a memory
6199 operand. */
6200static int
6201parse_tb (char **str)
6202{
6203 char * p = *str;
6204 int reg;
6205
6206 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6207 {
6208 inst.error = _("'[' expected");
6209 return FAIL;
6210 }
92e90b6e 6211
dcbf9037 6212 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6213 {
6214 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6215 return FAIL;
6216 }
6217 inst.operands[0].reg = reg;
6218
6219 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6220 {
6221 inst.error = _("',' expected");
6222 return FAIL;
6223 }
5f4273c7 6224
dcbf9037 6225 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6226 {
6227 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6228 return FAIL;
6229 }
6230 inst.operands[0].imm = reg;
6231
6232 if (skip_past_comma (&p) == SUCCESS)
6233 {
6234 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6235 return FAIL;
6236 if (inst.reloc.exp.X_add_number != 1)
6237 {
6238 inst.error = _("invalid shift");
6239 return FAIL;
6240 }
6241 inst.operands[0].shifted = 1;
6242 }
6243
6244 if (skip_past_char (&p, ']') == FAIL)
6245 {
6246 inst.error = _("']' expected");
6247 return FAIL;
6248 }
6249 *str = p;
6250 return SUCCESS;
6251}
6252
5287ad62
JB
6253/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6254 information on the types the operands can take and how they are encoded.
037e8744
JB
6255 Up to four operands may be read; this function handles setting the
6256 ".present" field for each read operand itself.
5287ad62
JB
6257 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6258 else returns FAIL. */
6259
6260static int
6261parse_neon_mov (char **str, int *which_operand)
6262{
6263 int i = *which_operand, val;
6264 enum arm_reg_type rtype;
6265 char *ptr = *str;
dcbf9037 6266 struct neon_type_el optype;
5f4273c7 6267
dcbf9037 6268 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6269 {
6270 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6271 inst.operands[i].reg = val;
6272 inst.operands[i].isscalar = 1;
dcbf9037 6273 inst.operands[i].vectype = optype;
5287ad62
JB
6274 inst.operands[i++].present = 1;
6275
6276 if (skip_past_comma (&ptr) == FAIL)
477330fc 6277 goto wanted_comma;
5f4273c7 6278
dcbf9037 6279 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6280 goto wanted_arm;
5f4273c7 6281
5287ad62
JB
6282 inst.operands[i].reg = val;
6283 inst.operands[i].isreg = 1;
6284 inst.operands[i].present = 1;
6285 }
037e8744 6286 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6287 != FAIL)
5287ad62
JB
6288 {
6289 /* Cases 0, 1, 2, 3, 5 (D only). */
6290 if (skip_past_comma (&ptr) == FAIL)
477330fc 6291 goto wanted_comma;
5f4273c7 6292
5287ad62
JB
6293 inst.operands[i].reg = val;
6294 inst.operands[i].isreg = 1;
6295 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6296 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6297 inst.operands[i].isvec = 1;
dcbf9037 6298 inst.operands[i].vectype = optype;
5287ad62
JB
6299 inst.operands[i++].present = 1;
6300
dcbf9037 6301 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6302 {
6303 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6304 Case 13: VMOV <Sd>, <Rm> */
6305 inst.operands[i].reg = val;
6306 inst.operands[i].isreg = 1;
6307 inst.operands[i].present = 1;
6308
6309 if (rtype == REG_TYPE_NQ)
6310 {
6311 first_error (_("can't use Neon quad register here"));
6312 return FAIL;
6313 }
6314 else if (rtype != REG_TYPE_VFS)
6315 {
6316 i++;
6317 if (skip_past_comma (&ptr) == FAIL)
6318 goto wanted_comma;
6319 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6320 goto wanted_arm;
6321 inst.operands[i].reg = val;
6322 inst.operands[i].isreg = 1;
6323 inst.operands[i].present = 1;
6324 }
6325 }
037e8744 6326 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6327 &optype)) != FAIL)
6328 {
6329 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6330 Case 1: VMOV<c><q> <Dd>, <Dm>
6331 Case 8: VMOV.F32 <Sd>, <Sm>
6332 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6333
6334 inst.operands[i].reg = val;
6335 inst.operands[i].isreg = 1;
6336 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6337 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6338 inst.operands[i].isvec = 1;
6339 inst.operands[i].vectype = optype;
6340 inst.operands[i].present = 1;
6341
6342 if (skip_past_comma (&ptr) == SUCCESS)
6343 {
6344 /* Case 15. */
6345 i++;
6346
6347 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6348 goto wanted_arm;
6349
6350 inst.operands[i].reg = val;
6351 inst.operands[i].isreg = 1;
6352 inst.operands[i++].present = 1;
6353
6354 if (skip_past_comma (&ptr) == FAIL)
6355 goto wanted_comma;
6356
6357 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6358 goto wanted_arm;
6359
6360 inst.operands[i].reg = val;
6361 inst.operands[i].isreg = 1;
6362 inst.operands[i].present = 1;
6363 }
6364 }
4641781c 6365 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6366 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6367 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6368 Case 10: VMOV.F32 <Sd>, #<imm>
6369 Case 11: VMOV.F64 <Dd>, #<imm> */
6370 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6371 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6372 == SUCCESS)
477330fc
RM
6373 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6374 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6375 ;
5287ad62 6376 else
477330fc
RM
6377 {
6378 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6379 return FAIL;
6380 }
5287ad62 6381 }
dcbf9037 6382 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6383 {
6384 /* Cases 6, 7. */
6385 inst.operands[i].reg = val;
6386 inst.operands[i].isreg = 1;
6387 inst.operands[i++].present = 1;
5f4273c7 6388
5287ad62 6389 if (skip_past_comma (&ptr) == FAIL)
477330fc 6390 goto wanted_comma;
5f4273c7 6391
dcbf9037 6392 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6393 {
6394 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6395 inst.operands[i].reg = val;
6396 inst.operands[i].isscalar = 1;
6397 inst.operands[i].present = 1;
6398 inst.operands[i].vectype = optype;
6399 }
dcbf9037 6400 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6401 {
6402 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6403 inst.operands[i].reg = val;
6404 inst.operands[i].isreg = 1;
6405 inst.operands[i++].present = 1;
6406
6407 if (skip_past_comma (&ptr) == FAIL)
6408 goto wanted_comma;
6409
6410 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6411 == FAIL)
6412 {
6413 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6414 return FAIL;
6415 }
6416
6417 inst.operands[i].reg = val;
6418 inst.operands[i].isreg = 1;
6419 inst.operands[i].isvec = 1;
6420 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6421 inst.operands[i].vectype = optype;
6422 inst.operands[i].present = 1;
6423
6424 if (rtype == REG_TYPE_VFS)
6425 {
6426 /* Case 14. */
6427 i++;
6428 if (skip_past_comma (&ptr) == FAIL)
6429 goto wanted_comma;
6430 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6431 &optype)) == FAIL)
6432 {
6433 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6434 return FAIL;
6435 }
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 }
6443 }
037e8744 6444 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6445 != FAIL)
6446 {
6447 /* Case 13. */
6448 inst.operands[i].reg = val;
6449 inst.operands[i].isreg = 1;
6450 inst.operands[i].isvec = 1;
6451 inst.operands[i].issingle = 1;
6452 inst.operands[i].vectype = optype;
6453 inst.operands[i].present = 1;
6454 }
5287ad62
JB
6455 }
6456 else
6457 {
dcbf9037 6458 first_error (_("parse error"));
5287ad62
JB
6459 return FAIL;
6460 }
6461
6462 /* Successfully parsed the operands. Update args. */
6463 *which_operand = i;
6464 *str = ptr;
6465 return SUCCESS;
6466
5f4273c7 6467 wanted_comma:
dcbf9037 6468 first_error (_("expected comma"));
5287ad62 6469 return FAIL;
5f4273c7
NC
6470
6471 wanted_arm:
dcbf9037 6472 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6473 return FAIL;
5287ad62
JB
6474}
6475
5be8be5d
DG
6476/* Use this macro when the operand constraints are different
6477 for ARM and THUMB (e.g. ldrd). */
6478#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6479 ((arm_operand) | ((thumb_operand) << 16))
6480
c19d1205
ZW
6481/* Matcher codes for parse_operands. */
6482enum operand_parse_code
6483{
6484 OP_stop, /* end of line */
6485
6486 OP_RR, /* ARM register */
6487 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6488 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6489 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6490 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6491 optional trailing ! */
c19d1205
ZW
6492 OP_RRw, /* ARM register, not r15, optional trailing ! */
6493 OP_RCP, /* Coprocessor number */
6494 OP_RCN, /* Coprocessor register */
6495 OP_RF, /* FPA register */
6496 OP_RVS, /* VFP single precision register */
5287ad62
JB
6497 OP_RVD, /* VFP double precision register (0..15) */
6498 OP_RND, /* Neon double precision register (0..31) */
6499 OP_RNQ, /* Neon quad precision register */
037e8744 6500 OP_RVSD, /* VFP single or double precision register */
dec41383 6501 OP_RNSD, /* Neon single or double precision register */
5287ad62 6502 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6503 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6504 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6505 OP_RVC, /* VFP control register */
6506 OP_RMF, /* Maverick F register */
6507 OP_RMD, /* Maverick D register */
6508 OP_RMFX, /* Maverick FX register */
6509 OP_RMDX, /* Maverick DX register */
6510 OP_RMAX, /* Maverick AX register */
6511 OP_RMDS, /* Maverick DSPSC register */
6512 OP_RIWR, /* iWMMXt wR register */
6513 OP_RIWC, /* iWMMXt wC register */
6514 OP_RIWG, /* iWMMXt wCG register */
6515 OP_RXA, /* XScale accumulator register */
6516
6517 OP_REGLST, /* ARM register list */
6518 OP_VRSLST, /* VFP single-precision register list */
6519 OP_VRDLST, /* VFP double-precision register list */
037e8744 6520 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6521 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6522 OP_NSTRLST, /* Neon element/structure list */
6523
5287ad62 6524 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6525 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6526 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6527 OP_RR_RNSC, /* ARM reg or Neon scalar. */
dec41383 6528 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
037e8744 6529 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6530 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6531 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6532 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6533 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6534 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6535 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6536
6537 OP_I0, /* immediate zero */
c19d1205
ZW
6538 OP_I7, /* immediate value 0 .. 7 */
6539 OP_I15, /* 0 .. 15 */
6540 OP_I16, /* 1 .. 16 */
5287ad62 6541 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6542 OP_I31, /* 0 .. 31 */
6543 OP_I31w, /* 0 .. 31, optional trailing ! */
6544 OP_I32, /* 1 .. 32 */
5287ad62
JB
6545 OP_I32z, /* 0 .. 32 */
6546 OP_I63, /* 0 .. 63 */
c19d1205 6547 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6548 OP_I64, /* 1 .. 64 */
6549 OP_I64z, /* 0 .. 64 */
c19d1205 6550 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6551
6552 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6553 OP_I7b, /* 0 .. 7 */
6554 OP_I15b, /* 0 .. 15 */
6555 OP_I31b, /* 0 .. 31 */
6556
6557 OP_SH, /* shifter operand */
4962c51a 6558 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6559 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6560 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6561 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6562 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6563 OP_EXP, /* arbitrary expression */
6564 OP_EXPi, /* same, with optional immediate prefix */
6565 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6566 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6567 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6568 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6569
6570 OP_CPSF, /* CPS flags */
6571 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6572 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6573 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6574 OP_COND, /* conditional code */
92e90b6e 6575 OP_TB, /* Table branch. */
c19d1205 6576
037e8744
JB
6577 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6578
c19d1205 6579 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6580 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6581 OP_RR_EXi, /* ARM register or expression with imm prefix */
6582 OP_RF_IF, /* FPA register or immediate */
6583 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6584 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6585
6586 /* Optional operands. */
6587 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6588 OP_oI31b, /* 0 .. 31 */
5287ad62 6589 OP_oI32b, /* 1 .. 32 */
5f1af56b 6590 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6591 OP_oIffffb, /* 0 .. 65535 */
6592 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6593
6594 OP_oRR, /* ARM register */
6595 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6596 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6597 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6598 OP_oRND, /* Optional Neon double precision register */
6599 OP_oRNQ, /* Optional Neon quad precision register */
6600 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6601 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6602 OP_oSHll, /* LSL immediate */
6603 OP_oSHar, /* ASR immediate */
6604 OP_oSHllar, /* LSL or ASR immediate */
6605 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6606 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6607
5be8be5d
DG
6608 /* Some pre-defined mixed (ARM/THUMB) operands. */
6609 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6610 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6611 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6612
c19d1205
ZW
6613 OP_FIRST_OPTIONAL = OP_oI7b
6614};
a737bd4d 6615
c19d1205
ZW
6616/* Generic instruction operand parser. This does no encoding and no
6617 semantic validation; it merely squirrels values away in the inst
6618 structure. Returns SUCCESS or FAIL depending on whether the
6619 specified grammar matched. */
6620static int
5be8be5d 6621parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6622{
5be8be5d 6623 unsigned const int *upat = pattern;
c19d1205
ZW
6624 char *backtrack_pos = 0;
6625 const char *backtrack_error = 0;
99aad254 6626 int i, val = 0, backtrack_index = 0;
5287ad62 6627 enum arm_reg_type rtype;
4962c51a 6628 parse_operand_result result;
5be8be5d 6629 unsigned int op_parse_code;
c19d1205 6630
e07e6e58
NC
6631#define po_char_or_fail(chr) \
6632 do \
6633 { \
6634 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6635 goto bad_args; \
e07e6e58
NC
6636 } \
6637 while (0)
c19d1205 6638
e07e6e58
NC
6639#define po_reg_or_fail(regtype) \
6640 do \
dcbf9037 6641 { \
e07e6e58 6642 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6643 & inst.operands[i].vectype); \
e07e6e58 6644 if (val == FAIL) \
477330fc
RM
6645 { \
6646 first_error (_(reg_expected_msgs[regtype])); \
6647 goto failure; \
6648 } \
e07e6e58
NC
6649 inst.operands[i].reg = val; \
6650 inst.operands[i].isreg = 1; \
6651 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6652 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6653 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6654 || rtype == REG_TYPE_VFD \
6655 || rtype == REG_TYPE_NQ); \
dcbf9037 6656 } \
e07e6e58
NC
6657 while (0)
6658
6659#define po_reg_or_goto(regtype, label) \
6660 do \
6661 { \
6662 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6663 & inst.operands[i].vectype); \
6664 if (val == FAIL) \
6665 goto label; \
dcbf9037 6666 \
e07e6e58
NC
6667 inst.operands[i].reg = val; \
6668 inst.operands[i].isreg = 1; \
6669 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6670 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6671 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6672 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6673 || rtype == REG_TYPE_NQ); \
6674 } \
6675 while (0)
6676
6677#define po_imm_or_fail(min, max, popt) \
6678 do \
6679 { \
6680 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6681 goto failure; \
6682 inst.operands[i].imm = val; \
6683 } \
6684 while (0)
6685
6686#define po_scalar_or_goto(elsz, label) \
6687 do \
6688 { \
6689 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6690 if (val == FAIL) \
6691 goto label; \
6692 inst.operands[i].reg = val; \
6693 inst.operands[i].isscalar = 1; \
6694 } \
6695 while (0)
6696
6697#define po_misc_or_fail(expr) \
6698 do \
6699 { \
6700 if (expr) \
6701 goto failure; \
6702 } \
6703 while (0)
6704
6705#define po_misc_or_fail_no_backtrack(expr) \
6706 do \
6707 { \
6708 result = expr; \
6709 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6710 backtrack_pos = 0; \
6711 if (result != PARSE_OPERAND_SUCCESS) \
6712 goto failure; \
6713 } \
6714 while (0)
4962c51a 6715
52e7f43d
RE
6716#define po_barrier_or_imm(str) \
6717 do \
6718 { \
6719 val = parse_barrier (&str); \
ccb84d65
JB
6720 if (val == FAIL && ! ISALPHA (*str)) \
6721 goto immediate; \
6722 if (val == FAIL \
6723 /* ISB can only take SY as an option. */ \
6724 || ((inst.instruction & 0xf0) == 0x60 \
6725 && val != 0xf)) \
52e7f43d 6726 { \
ccb84d65
JB
6727 inst.error = _("invalid barrier type"); \
6728 backtrack_pos = 0; \
6729 goto failure; \
52e7f43d
RE
6730 } \
6731 } \
6732 while (0)
6733
c19d1205
ZW
6734 skip_whitespace (str);
6735
6736 for (i = 0; upat[i] != OP_stop; i++)
6737 {
5be8be5d
DG
6738 op_parse_code = upat[i];
6739 if (op_parse_code >= 1<<16)
6740 op_parse_code = thumb ? (op_parse_code >> 16)
6741 : (op_parse_code & ((1<<16)-1));
6742
6743 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6744 {
6745 /* Remember where we are in case we need to backtrack. */
9c2799c2 6746 gas_assert (!backtrack_pos);
c19d1205
ZW
6747 backtrack_pos = str;
6748 backtrack_error = inst.error;
6749 backtrack_index = i;
6750 }
6751
b6702015 6752 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6753 po_char_or_fail (',');
6754
5be8be5d 6755 switch (op_parse_code)
c19d1205
ZW
6756 {
6757 /* Registers */
6758 case OP_oRRnpc:
5be8be5d 6759 case OP_oRRnpcsp:
c19d1205 6760 case OP_RRnpc:
5be8be5d 6761 case OP_RRnpcsp:
c19d1205
ZW
6762 case OP_oRR:
6763 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6764 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6765 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6766 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6767 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6768 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6769 case OP_oRND:
5287ad62 6770 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6771 case OP_RVC:
6772 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6773 break;
6774 /* Also accept generic coprocessor regs for unknown registers. */
6775 coproc_reg:
6776 po_reg_or_fail (REG_TYPE_CN);
6777 break;
c19d1205
ZW
6778 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6779 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6780 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6781 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6782 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6783 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6784 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6785 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6786 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6787 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6788 case OP_oRNQ:
5287ad62 6789 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
dec41383 6790 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
477330fc 6791 case OP_oRNDQ:
5287ad62 6792 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6793 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6794 case OP_oRNSDQ:
6795 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6796
6797 /* Neon scalar. Using an element size of 8 means that some invalid
6798 scalars are accepted here, so deal with those in later code. */
6799 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6800
6801 case OP_RNDQ_I0:
6802 {
6803 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6804 break;
6805 try_imm0:
6806 po_imm_or_fail (0, 0, TRUE);
6807 }
6808 break;
6809
6810 case OP_RVSD_I0:
6811 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6812 break;
6813
aacf0b33
KT
6814 case OP_RSVD_FI0:
6815 {
6816 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6817 break;
6818 try_ifimm0:
6819 if (parse_ifimm_zero (&str))
6820 inst.operands[i].imm = 0;
6821 else
6822 {
6823 inst.error
6824 = _("only floating point zero is allowed as immediate value");
6825 goto failure;
6826 }
6827 }
6828 break;
6829
477330fc
RM
6830 case OP_RR_RNSC:
6831 {
6832 po_scalar_or_goto (8, try_rr);
6833 break;
6834 try_rr:
6835 po_reg_or_fail (REG_TYPE_RN);
6836 }
6837 break;
6838
6839 case OP_RNSDQ_RNSC:
6840 {
6841 po_scalar_or_goto (8, try_nsdq);
6842 break;
6843 try_nsdq:
6844 po_reg_or_fail (REG_TYPE_NSDQ);
6845 }
6846 break;
6847
dec41383
JW
6848 case OP_RNSD_RNSC:
6849 {
6850 po_scalar_or_goto (8, try_s_scalar);
6851 break;
6852 try_s_scalar:
6853 po_scalar_or_goto (4, try_nsd);
6854 break;
6855 try_nsd:
6856 po_reg_or_fail (REG_TYPE_NSD);
6857 }
6858 break;
6859
477330fc
RM
6860 case OP_RNDQ_RNSC:
6861 {
6862 po_scalar_or_goto (8, try_ndq);
6863 break;
6864 try_ndq:
6865 po_reg_or_fail (REG_TYPE_NDQ);
6866 }
6867 break;
6868
6869 case OP_RND_RNSC:
6870 {
6871 po_scalar_or_goto (8, try_vfd);
6872 break;
6873 try_vfd:
6874 po_reg_or_fail (REG_TYPE_VFD);
6875 }
6876 break;
6877
6878 case OP_VMOV:
6879 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6880 not careful then bad things might happen. */
6881 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6882 break;
6883
6884 case OP_RNDQ_Ibig:
6885 {
6886 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6887 break;
6888 try_immbig:
6889 /* There's a possibility of getting a 64-bit immediate here, so
6890 we need special handling. */
8335d6aa
JW
6891 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6892 == FAIL)
477330fc
RM
6893 {
6894 inst.error = _("immediate value is out of range");
6895 goto failure;
6896 }
6897 }
6898 break;
6899
6900 case OP_RNDQ_I63b:
6901 {
6902 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6903 break;
6904 try_shimm:
6905 po_imm_or_fail (0, 63, TRUE);
6906 }
6907 break;
c19d1205
ZW
6908
6909 case OP_RRnpcb:
6910 po_char_or_fail ('[');
6911 po_reg_or_fail (REG_TYPE_RN);
6912 po_char_or_fail (']');
6913 break;
a737bd4d 6914
55881a11 6915 case OP_RRnpctw:
c19d1205 6916 case OP_RRw:
b6702015 6917 case OP_oRRw:
c19d1205
ZW
6918 po_reg_or_fail (REG_TYPE_RN);
6919 if (skip_past_char (&str, '!') == SUCCESS)
6920 inst.operands[i].writeback = 1;
6921 break;
6922
6923 /* Immediates */
6924 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6925 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6926 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6927 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6928 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6929 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6930 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6931 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6932 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6933 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6934 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6935 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6936
6937 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6938 case OP_oI7b:
6939 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6940 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6941 case OP_oI31b:
6942 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6943 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6944 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6945 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6946
6947 /* Immediate variants */
6948 case OP_oI255c:
6949 po_char_or_fail ('{');
6950 po_imm_or_fail (0, 255, TRUE);
6951 po_char_or_fail ('}');
6952 break;
6953
6954 case OP_I31w:
6955 /* The expression parser chokes on a trailing !, so we have
6956 to find it first and zap it. */
6957 {
6958 char *s = str;
6959 while (*s && *s != ',')
6960 s++;
6961 if (s[-1] == '!')
6962 {
6963 s[-1] = '\0';
6964 inst.operands[i].writeback = 1;
6965 }
6966 po_imm_or_fail (0, 31, TRUE);
6967 if (str == s - 1)
6968 str = s;
6969 }
6970 break;
6971
6972 /* Expressions */
6973 case OP_EXPi: EXPi:
6974 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6975 GE_OPT_PREFIX));
6976 break;
6977
6978 case OP_EXP:
6979 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6980 GE_NO_PREFIX));
6981 break;
6982
6983 case OP_EXPr: EXPr:
6984 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6985 GE_NO_PREFIX));
6986 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6987 {
c19d1205
ZW
6988 val = parse_reloc (&str);
6989 if (val == -1)
6990 {
6991 inst.error = _("unrecognized relocation suffix");
6992 goto failure;
6993 }
6994 else if (val != BFD_RELOC_UNUSED)
6995 {
6996 inst.operands[i].imm = val;
6997 inst.operands[i].hasreloc = 1;
6998 }
a737bd4d 6999 }
c19d1205 7000 break;
a737bd4d 7001
b6895b4f
PB
7002 /* Operand for MOVW or MOVT. */
7003 case OP_HALF:
7004 po_misc_or_fail (parse_half (&str));
7005 break;
7006
e07e6e58 7007 /* Register or expression. */
c19d1205
ZW
7008 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7009 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 7010
e07e6e58 7011 /* Register or immediate. */
c19d1205
ZW
7012 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7013 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 7014
c19d1205
ZW
7015 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7016 IF:
7017 if (!is_immediate_prefix (*str))
7018 goto bad_args;
7019 str++;
7020 val = parse_fpa_immediate (&str);
7021 if (val == FAIL)
7022 goto failure;
7023 /* FPA immediates are encoded as registers 8-15.
7024 parse_fpa_immediate has already applied the offset. */
7025 inst.operands[i].reg = val;
7026 inst.operands[i].isreg = 1;
7027 break;
09d92015 7028
2d447fca
JM
7029 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7030 I32z: po_imm_or_fail (0, 32, FALSE); break;
7031
e07e6e58 7032 /* Two kinds of register. */
c19d1205
ZW
7033 case OP_RIWR_RIWC:
7034 {
7035 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
7036 if (!rege
7037 || (rege->type != REG_TYPE_MMXWR
7038 && rege->type != REG_TYPE_MMXWC
7039 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7040 {
7041 inst.error = _("iWMMXt data or control register expected");
7042 goto failure;
7043 }
7044 inst.operands[i].reg = rege->number;
7045 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7046 }
7047 break;
09d92015 7048
41adaa5c
JM
7049 case OP_RIWC_RIWG:
7050 {
7051 struct reg_entry *rege = arm_reg_parse_multi (&str);
7052 if (!rege
7053 || (rege->type != REG_TYPE_MMXWC
7054 && rege->type != REG_TYPE_MMXWCG))
7055 {
7056 inst.error = _("iWMMXt control register expected");
7057 goto failure;
7058 }
7059 inst.operands[i].reg = rege->number;
7060 inst.operands[i].isreg = 1;
7061 }
7062 break;
7063
c19d1205
ZW
7064 /* Misc */
7065 case OP_CPSF: val = parse_cps_flags (&str); break;
7066 case OP_ENDI: val = parse_endian_specifier (&str); break;
7067 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7068 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7069 case OP_oBARRIER_I15:
7070 po_barrier_or_imm (str); break;
7071 immediate:
7072 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7073 goto failure;
52e7f43d 7074 break;
c19d1205 7075
fa94de6b 7076 case OP_wPSR:
d2cd1205 7077 case OP_rPSR:
90ec0d68
MGD
7078 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7079 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7080 {
7081 inst.error = _("Banked registers are not available with this "
7082 "architecture.");
7083 goto failure;
7084 }
7085 break;
d2cd1205
JB
7086 try_psr:
7087 val = parse_psr (&str, op_parse_code == OP_wPSR);
7088 break;
037e8744 7089
477330fc
RM
7090 case OP_APSR_RR:
7091 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7092 break;
7093 try_apsr:
7094 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7095 instruction). */
7096 if (strncasecmp (str, "APSR_", 5) == 0)
7097 {
7098 unsigned found = 0;
7099 str += 5;
7100 while (found < 15)
7101 switch (*str++)
7102 {
7103 case 'c': found = (found & 1) ? 16 : found | 1; break;
7104 case 'n': found = (found & 2) ? 16 : found | 2; break;
7105 case 'z': found = (found & 4) ? 16 : found | 4; break;
7106 case 'v': found = (found & 8) ? 16 : found | 8; break;
7107 default: found = 16;
7108 }
7109 if (found != 15)
7110 goto failure;
7111 inst.operands[i].isvec = 1;
f7c21dc7
NC
7112 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7113 inst.operands[i].reg = REG_PC;
477330fc
RM
7114 }
7115 else
7116 goto failure;
7117 break;
037e8744 7118
92e90b6e
PB
7119 case OP_TB:
7120 po_misc_or_fail (parse_tb (&str));
7121 break;
7122
e07e6e58 7123 /* Register lists. */
c19d1205
ZW
7124 case OP_REGLST:
7125 val = parse_reg_list (&str);
7126 if (*str == '^')
7127 {
5e0d7f77 7128 inst.operands[i].writeback = 1;
c19d1205
ZW
7129 str++;
7130 }
7131 break;
09d92015 7132
c19d1205 7133 case OP_VRSLST:
5287ad62 7134 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7135 break;
09d92015 7136
c19d1205 7137 case OP_VRDLST:
5287ad62 7138 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7139 break;
a737bd4d 7140
477330fc
RM
7141 case OP_VRSDLST:
7142 /* Allow Q registers too. */
7143 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7144 REGLIST_NEON_D);
7145 if (val == FAIL)
7146 {
7147 inst.error = NULL;
7148 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7149 REGLIST_VFP_S);
7150 inst.operands[i].issingle = 1;
7151 }
7152 break;
7153
7154 case OP_NRDLST:
7155 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7156 REGLIST_NEON_D);
7157 break;
5287ad62
JB
7158
7159 case OP_NSTRLST:
477330fc
RM
7160 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7161 &inst.operands[i].vectype);
7162 break;
5287ad62 7163
c19d1205
ZW
7164 /* Addressing modes */
7165 case OP_ADDR:
7166 po_misc_or_fail (parse_address (&str, i));
7167 break;
09d92015 7168
4962c51a
MS
7169 case OP_ADDRGLDR:
7170 po_misc_or_fail_no_backtrack (
477330fc 7171 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7172 break;
7173
7174 case OP_ADDRGLDRS:
7175 po_misc_or_fail_no_backtrack (
477330fc 7176 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7177 break;
7178
7179 case OP_ADDRGLDC:
7180 po_misc_or_fail_no_backtrack (
477330fc 7181 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7182 break;
7183
c19d1205
ZW
7184 case OP_SH:
7185 po_misc_or_fail (parse_shifter_operand (&str, i));
7186 break;
09d92015 7187
4962c51a
MS
7188 case OP_SHG:
7189 po_misc_or_fail_no_backtrack (
477330fc 7190 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7191 break;
7192
c19d1205
ZW
7193 case OP_oSHll:
7194 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7195 break;
09d92015 7196
c19d1205
ZW
7197 case OP_oSHar:
7198 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7199 break;
09d92015 7200
c19d1205
ZW
7201 case OP_oSHllar:
7202 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7203 break;
09d92015 7204
c19d1205 7205 default:
5be8be5d 7206 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7207 }
09d92015 7208
c19d1205
ZW
7209 /* Various value-based sanity checks and shared operations. We
7210 do not signal immediate failures for the register constraints;
7211 this allows a syntax error to take precedence. */
5be8be5d 7212 switch (op_parse_code)
c19d1205
ZW
7213 {
7214 case OP_oRRnpc:
7215 case OP_RRnpc:
7216 case OP_RRnpcb:
7217 case OP_RRw:
b6702015 7218 case OP_oRRw:
c19d1205
ZW
7219 case OP_RRnpc_I0:
7220 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7221 inst.error = BAD_PC;
7222 break;
09d92015 7223
5be8be5d
DG
7224 case OP_oRRnpcsp:
7225 case OP_RRnpcsp:
7226 if (inst.operands[i].isreg)
7227 {
7228 if (inst.operands[i].reg == REG_PC)
7229 inst.error = BAD_PC;
5c8ed6a4
JW
7230 else if (inst.operands[i].reg == REG_SP
7231 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7232 relaxed since ARMv8-A. */
7233 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7234 {
7235 gas_assert (thumb);
7236 inst.error = BAD_SP;
7237 }
5be8be5d
DG
7238 }
7239 break;
7240
55881a11 7241 case OP_RRnpctw:
fa94de6b
RM
7242 if (inst.operands[i].isreg
7243 && inst.operands[i].reg == REG_PC
55881a11
MGD
7244 && (inst.operands[i].writeback || thumb))
7245 inst.error = BAD_PC;
7246 break;
7247
c19d1205
ZW
7248 case OP_CPSF:
7249 case OP_ENDI:
7250 case OP_oROR:
d2cd1205
JB
7251 case OP_wPSR:
7252 case OP_rPSR:
c19d1205 7253 case OP_COND:
52e7f43d 7254 case OP_oBARRIER_I15:
c19d1205
ZW
7255 case OP_REGLST:
7256 case OP_VRSLST:
7257 case OP_VRDLST:
477330fc
RM
7258 case OP_VRSDLST:
7259 case OP_NRDLST:
7260 case OP_NSTRLST:
c19d1205
ZW
7261 if (val == FAIL)
7262 goto failure;
7263 inst.operands[i].imm = val;
7264 break;
a737bd4d 7265
c19d1205
ZW
7266 default:
7267 break;
7268 }
09d92015 7269
c19d1205
ZW
7270 /* If we get here, this operand was successfully parsed. */
7271 inst.operands[i].present = 1;
7272 continue;
09d92015 7273
c19d1205 7274 bad_args:
09d92015 7275 inst.error = BAD_ARGS;
c19d1205
ZW
7276
7277 failure:
7278 if (!backtrack_pos)
d252fdde
PB
7279 {
7280 /* The parse routine should already have set inst.error, but set a
5f4273c7 7281 default here just in case. */
d252fdde
PB
7282 if (!inst.error)
7283 inst.error = _("syntax error");
7284 return FAIL;
7285 }
c19d1205
ZW
7286
7287 /* Do not backtrack over a trailing optional argument that
7288 absorbed some text. We will only fail again, with the
7289 'garbage following instruction' error message, which is
7290 probably less helpful than the current one. */
7291 if (backtrack_index == i && backtrack_pos != str
7292 && upat[i+1] == OP_stop)
d252fdde
PB
7293 {
7294 if (!inst.error)
7295 inst.error = _("syntax error");
7296 return FAIL;
7297 }
c19d1205
ZW
7298
7299 /* Try again, skipping the optional argument at backtrack_pos. */
7300 str = backtrack_pos;
7301 inst.error = backtrack_error;
7302 inst.operands[backtrack_index].present = 0;
7303 i = backtrack_index;
7304 backtrack_pos = 0;
09d92015 7305 }
09d92015 7306
c19d1205
ZW
7307 /* Check that we have parsed all the arguments. */
7308 if (*str != '\0' && !inst.error)
7309 inst.error = _("garbage following instruction");
09d92015 7310
c19d1205 7311 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7312}
7313
c19d1205
ZW
7314#undef po_char_or_fail
7315#undef po_reg_or_fail
7316#undef po_reg_or_goto
7317#undef po_imm_or_fail
5287ad62 7318#undef po_scalar_or_fail
52e7f43d 7319#undef po_barrier_or_imm
e07e6e58 7320
c19d1205 7321/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7322#define constraint(expr, err) \
7323 do \
c19d1205 7324 { \
e07e6e58
NC
7325 if (expr) \
7326 { \
7327 inst.error = err; \
7328 return; \
7329 } \
c19d1205 7330 } \
e07e6e58 7331 while (0)
c19d1205 7332
fdfde340
JM
7333/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7334 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7335 is the BadReg predicate in ARM's Thumb-2 documentation.
7336
7337 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7338 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7339#define reject_bad_reg(reg) \
7340 do \
7341 if (reg == REG_PC) \
7342 { \
7343 inst.error = BAD_PC; \
7344 return; \
7345 } \
7346 else if (reg == REG_SP \
7347 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7348 { \
7349 inst.error = BAD_SP; \
7350 return; \
7351 } \
fdfde340
JM
7352 while (0)
7353
94206790
MM
7354/* If REG is R13 (the stack pointer), warn that its use is
7355 deprecated. */
7356#define warn_deprecated_sp(reg) \
7357 do \
7358 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7359 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7360 while (0)
7361
c19d1205
ZW
7362/* Functions for operand encoding. ARM, then Thumb. */
7363
d840c081 7364#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7365
9db2f6b4
RL
7366/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7367
7368 The only binary encoding difference is the Coprocessor number. Coprocessor
7369 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7370 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7371 exists for Single-Precision operation. */
7372
7373static void
7374do_scalar_fp16_v82_encode (void)
7375{
7376 if (inst.cond != COND_ALWAYS)
7377 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7378 " the behaviour is UNPREDICTABLE"));
7379 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7380 _(BAD_FP16));
7381
7382 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7383 mark_feature_used (&arm_ext_fp16);
7384}
7385
c19d1205
ZW
7386/* If VAL can be encoded in the immediate field of an ARM instruction,
7387 return the encoded form. Otherwise, return FAIL. */
7388
7389static unsigned int
7390encode_arm_immediate (unsigned int val)
09d92015 7391{
c19d1205
ZW
7392 unsigned int a, i;
7393
4f1d6205
L
7394 if (val <= 0xff)
7395 return val;
7396
7397 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7398 if ((a = rotate_left (val, i)) <= 0xff)
7399 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7400
7401 return FAIL;
09d92015
MM
7402}
7403
c19d1205
ZW
7404/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7405 return the encoded form. Otherwise, return FAIL. */
7406static unsigned int
7407encode_thumb32_immediate (unsigned int val)
09d92015 7408{
c19d1205 7409 unsigned int a, i;
09d92015 7410
9c3c69f2 7411 if (val <= 0xff)
c19d1205 7412 return val;
a737bd4d 7413
9c3c69f2 7414 for (i = 1; i <= 24; i++)
09d92015 7415 {
9c3c69f2
PB
7416 a = val >> i;
7417 if ((val & ~(0xff << i)) == 0)
7418 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7419 }
a737bd4d 7420
c19d1205
ZW
7421 a = val & 0xff;
7422 if (val == ((a << 16) | a))
7423 return 0x100 | a;
7424 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7425 return 0x300 | a;
09d92015 7426
c19d1205
ZW
7427 a = val & 0xff00;
7428 if (val == ((a << 16) | a))
7429 return 0x200 | (a >> 8);
a737bd4d 7430
c19d1205 7431 return FAIL;
09d92015 7432}
5287ad62 7433/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7434
7435static void
5287ad62
JB
7436encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7437{
7438 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7439 && reg > 15)
7440 {
b1cc4aeb 7441 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7442 {
7443 if (thumb_mode)
7444 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7445 fpu_vfp_ext_d32);
7446 else
7447 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7448 fpu_vfp_ext_d32);
7449 }
5287ad62 7450 else
477330fc
RM
7451 {
7452 first_error (_("D register out of range for selected VFP version"));
7453 return;
7454 }
5287ad62
JB
7455 }
7456
c19d1205 7457 switch (pos)
09d92015 7458 {
c19d1205
ZW
7459 case VFP_REG_Sd:
7460 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7461 break;
7462
7463 case VFP_REG_Sn:
7464 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7465 break;
7466
7467 case VFP_REG_Sm:
7468 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7469 break;
7470
5287ad62
JB
7471 case VFP_REG_Dd:
7472 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7473 break;
5f4273c7 7474
5287ad62
JB
7475 case VFP_REG_Dn:
7476 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7477 break;
5f4273c7 7478
5287ad62
JB
7479 case VFP_REG_Dm:
7480 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7481 break;
7482
c19d1205
ZW
7483 default:
7484 abort ();
09d92015 7485 }
09d92015
MM
7486}
7487
c19d1205 7488/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7489 if any, is handled by md_apply_fix. */
09d92015 7490static void
c19d1205 7491encode_arm_shift (int i)
09d92015 7492{
008a97ef
RL
7493 /* register-shifted register. */
7494 if (inst.operands[i].immisreg)
7495 {
bf355b69
MR
7496 int op_index;
7497 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7498 {
5689c942
RL
7499 /* Check the operand only when it's presented. In pre-UAL syntax,
7500 if the destination register is the same as the first operand, two
7501 register form of the instruction can be used. */
bf355b69
MR
7502 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7503 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7504 as_warn (UNPRED_REG ("r15"));
7505 }
7506
7507 if (inst.operands[i].imm == REG_PC)
7508 as_warn (UNPRED_REG ("r15"));
7509 }
7510
c19d1205
ZW
7511 if (inst.operands[i].shift_kind == SHIFT_RRX)
7512 inst.instruction |= SHIFT_ROR << 5;
7513 else
09d92015 7514 {
c19d1205
ZW
7515 inst.instruction |= inst.operands[i].shift_kind << 5;
7516 if (inst.operands[i].immisreg)
7517 {
7518 inst.instruction |= SHIFT_BY_REG;
7519 inst.instruction |= inst.operands[i].imm << 8;
7520 }
7521 else
7522 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7523 }
c19d1205 7524}
09d92015 7525
c19d1205
ZW
7526static void
7527encode_arm_shifter_operand (int i)
7528{
7529 if (inst.operands[i].isreg)
09d92015 7530 {
c19d1205
ZW
7531 inst.instruction |= inst.operands[i].reg;
7532 encode_arm_shift (i);
09d92015 7533 }
c19d1205 7534 else
a415b1cd
JB
7535 {
7536 inst.instruction |= INST_IMMEDIATE;
7537 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7538 inst.instruction |= inst.operands[i].imm;
7539 }
09d92015
MM
7540}
7541
c19d1205 7542/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7543static void
c19d1205 7544encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7545{
2b2f5df9
NC
7546 /* PR 14260:
7547 Generate an error if the operand is not a register. */
7548 constraint (!inst.operands[i].isreg,
7549 _("Instruction does not support =N addresses"));
7550
c19d1205 7551 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7552
c19d1205 7553 if (inst.operands[i].preind)
09d92015 7554 {
c19d1205
ZW
7555 if (is_t)
7556 {
7557 inst.error = _("instruction does not accept preindexed addressing");
7558 return;
7559 }
7560 inst.instruction |= PRE_INDEX;
7561 if (inst.operands[i].writeback)
7562 inst.instruction |= WRITE_BACK;
09d92015 7563
c19d1205
ZW
7564 }
7565 else if (inst.operands[i].postind)
7566 {
9c2799c2 7567 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7568 if (is_t)
7569 inst.instruction |= WRITE_BACK;
7570 }
7571 else /* unindexed - only for coprocessor */
09d92015 7572 {
c19d1205 7573 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7574 return;
7575 }
7576
c19d1205
ZW
7577 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7578 && (((inst.instruction & 0x000f0000) >> 16)
7579 == ((inst.instruction & 0x0000f000) >> 12)))
7580 as_warn ((inst.instruction & LOAD_BIT)
7581 ? _("destination register same as write-back base")
7582 : _("source register same as write-back base"));
09d92015
MM
7583}
7584
c19d1205
ZW
7585/* inst.operands[i] was set up by parse_address. Encode it into an
7586 ARM-format mode 2 load or store instruction. If is_t is true,
7587 reject forms that cannot be used with a T instruction (i.e. not
7588 post-indexed). */
a737bd4d 7589static void
c19d1205 7590encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7591{
5be8be5d
DG
7592 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7593
c19d1205 7594 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7595
c19d1205 7596 if (inst.operands[i].immisreg)
09d92015 7597 {
5be8be5d
DG
7598 constraint ((inst.operands[i].imm == REG_PC
7599 || (is_pc && inst.operands[i].writeback)),
7600 BAD_PC_ADDRESSING);
c19d1205
ZW
7601 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7602 inst.instruction |= inst.operands[i].imm;
7603 if (!inst.operands[i].negative)
7604 inst.instruction |= INDEX_UP;
7605 if (inst.operands[i].shifted)
7606 {
7607 if (inst.operands[i].shift_kind == SHIFT_RRX)
7608 inst.instruction |= SHIFT_ROR << 5;
7609 else
7610 {
7611 inst.instruction |= inst.operands[i].shift_kind << 5;
7612 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7613 }
7614 }
09d92015 7615 }
c19d1205 7616 else /* immediate offset in inst.reloc */
09d92015 7617 {
5be8be5d
DG
7618 if (is_pc && !inst.reloc.pc_rel)
7619 {
7620 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7621
7622 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7623 cannot use PC in addressing.
7624 PC cannot be used in writeback addressing, either. */
7625 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7626 BAD_PC_ADDRESSING);
23a10334 7627
dc5ec521 7628 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7629 if (warn_on_deprecated
7630 && !is_load
7631 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7632 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7633 }
7634
c19d1205 7635 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7636 {
7637 /* Prefer + for zero encoded value. */
7638 if (!inst.operands[i].negative)
7639 inst.instruction |= INDEX_UP;
7640 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7641 }
09d92015 7642 }
09d92015
MM
7643}
7644
c19d1205
ZW
7645/* inst.operands[i] was set up by parse_address. Encode it into an
7646 ARM-format mode 3 load or store instruction. Reject forms that
7647 cannot be used with such instructions. If is_t is true, reject
7648 forms that cannot be used with a T instruction (i.e. not
7649 post-indexed). */
7650static void
7651encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7652{
c19d1205 7653 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7654 {
c19d1205
ZW
7655 inst.error = _("instruction does not accept scaled register index");
7656 return;
09d92015 7657 }
a737bd4d 7658
c19d1205 7659 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7660
c19d1205
ZW
7661 if (inst.operands[i].immisreg)
7662 {
5be8be5d 7663 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7664 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7665 BAD_PC_ADDRESSING);
eb9f3f00
JB
7666 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7667 BAD_PC_WRITEBACK);
c19d1205
ZW
7668 inst.instruction |= inst.operands[i].imm;
7669 if (!inst.operands[i].negative)
7670 inst.instruction |= INDEX_UP;
7671 }
7672 else /* immediate offset in inst.reloc */
7673 {
5be8be5d
DG
7674 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7675 && inst.operands[i].writeback),
7676 BAD_PC_WRITEBACK);
c19d1205
ZW
7677 inst.instruction |= HWOFFSET_IMM;
7678 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7679 {
7680 /* Prefer + for zero encoded value. */
7681 if (!inst.operands[i].negative)
7682 inst.instruction |= INDEX_UP;
7683
7684 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7685 }
c19d1205 7686 }
a737bd4d
NC
7687}
7688
8335d6aa
JW
7689/* Write immediate bits [7:0] to the following locations:
7690
7691 |28/24|23 19|18 16|15 4|3 0|
7692 | 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|
7693
7694 This function is used by VMOV/VMVN/VORR/VBIC. */
7695
7696static void
7697neon_write_immbits (unsigned immbits)
7698{
7699 inst.instruction |= immbits & 0xf;
7700 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7701 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7702}
7703
7704/* Invert low-order SIZE bits of XHI:XLO. */
7705
7706static void
7707neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7708{
7709 unsigned immlo = xlo ? *xlo : 0;
7710 unsigned immhi = xhi ? *xhi : 0;
7711
7712 switch (size)
7713 {
7714 case 8:
7715 immlo = (~immlo) & 0xff;
7716 break;
7717
7718 case 16:
7719 immlo = (~immlo) & 0xffff;
7720 break;
7721
7722 case 64:
7723 immhi = (~immhi) & 0xffffffff;
7724 /* fall through. */
7725
7726 case 32:
7727 immlo = (~immlo) & 0xffffffff;
7728 break;
7729
7730 default:
7731 abort ();
7732 }
7733
7734 if (xlo)
7735 *xlo = immlo;
7736
7737 if (xhi)
7738 *xhi = immhi;
7739}
7740
7741/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7742 A, B, C, D. */
09d92015 7743
c19d1205 7744static int
8335d6aa 7745neon_bits_same_in_bytes (unsigned imm)
09d92015 7746{
8335d6aa
JW
7747 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7748 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7749 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7750 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7751}
a737bd4d 7752
8335d6aa 7753/* For immediate of above form, return 0bABCD. */
09d92015 7754
8335d6aa
JW
7755static unsigned
7756neon_squash_bits (unsigned imm)
7757{
7758 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7759 | ((imm & 0x01000000) >> 21);
7760}
7761
7762/* Compress quarter-float representation to 0b...000 abcdefgh. */
7763
7764static unsigned
7765neon_qfloat_bits (unsigned imm)
7766{
7767 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7768}
7769
7770/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7771 the instruction. *OP is passed as the initial value of the op field, and
7772 may be set to a different value depending on the constant (i.e.
7773 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7774 MVN). If the immediate looks like a repeated pattern then also
7775 try smaller element sizes. */
7776
7777static int
7778neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7779 unsigned *immbits, int *op, int size,
7780 enum neon_el_type type)
7781{
7782 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7783 float. */
7784 if (type == NT_float && !float_p)
7785 return FAIL;
7786
7787 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7788 {
8335d6aa
JW
7789 if (size != 32 || *op == 1)
7790 return FAIL;
7791 *immbits = neon_qfloat_bits (immlo);
7792 return 0xf;
7793 }
7794
7795 if (size == 64)
7796 {
7797 if (neon_bits_same_in_bytes (immhi)
7798 && neon_bits_same_in_bytes (immlo))
c19d1205 7799 {
8335d6aa
JW
7800 if (*op == 1)
7801 return FAIL;
7802 *immbits = (neon_squash_bits (immhi) << 4)
7803 | neon_squash_bits (immlo);
7804 *op = 1;
7805 return 0xe;
c19d1205 7806 }
a737bd4d 7807
8335d6aa
JW
7808 if (immhi != immlo)
7809 return FAIL;
7810 }
a737bd4d 7811
8335d6aa 7812 if (size >= 32)
09d92015 7813 {
8335d6aa 7814 if (immlo == (immlo & 0x000000ff))
c19d1205 7815 {
8335d6aa
JW
7816 *immbits = immlo;
7817 return 0x0;
c19d1205 7818 }
8335d6aa 7819 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7820 {
8335d6aa
JW
7821 *immbits = immlo >> 8;
7822 return 0x2;
c19d1205 7823 }
8335d6aa
JW
7824 else if (immlo == (immlo & 0x00ff0000))
7825 {
7826 *immbits = immlo >> 16;
7827 return 0x4;
7828 }
7829 else if (immlo == (immlo & 0xff000000))
7830 {
7831 *immbits = immlo >> 24;
7832 return 0x6;
7833 }
7834 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7835 {
7836 *immbits = (immlo >> 8) & 0xff;
7837 return 0xc;
7838 }
7839 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7840 {
7841 *immbits = (immlo >> 16) & 0xff;
7842 return 0xd;
7843 }
7844
7845 if ((immlo & 0xffff) != (immlo >> 16))
7846 return FAIL;
7847 immlo &= 0xffff;
09d92015 7848 }
a737bd4d 7849
8335d6aa 7850 if (size >= 16)
4962c51a 7851 {
8335d6aa
JW
7852 if (immlo == (immlo & 0x000000ff))
7853 {
7854 *immbits = immlo;
7855 return 0x8;
7856 }
7857 else if (immlo == (immlo & 0x0000ff00))
7858 {
7859 *immbits = immlo >> 8;
7860 return 0xa;
7861 }
7862
7863 if ((immlo & 0xff) != (immlo >> 8))
7864 return FAIL;
7865 immlo &= 0xff;
4962c51a
MS
7866 }
7867
8335d6aa
JW
7868 if (immlo == (immlo & 0x000000ff))
7869 {
7870 /* Don't allow MVN with 8-bit immediate. */
7871 if (*op == 1)
7872 return FAIL;
7873 *immbits = immlo;
7874 return 0xe;
7875 }
26d97720 7876
8335d6aa 7877 return FAIL;
c19d1205 7878}
a737bd4d 7879
5fc177c8 7880#if defined BFD_HOST_64_BIT
ba592044
AM
7881/* Returns TRUE if double precision value V may be cast
7882 to single precision without loss of accuracy. */
7883
7884static bfd_boolean
5fc177c8 7885is_double_a_single (bfd_int64_t v)
ba592044 7886{
5fc177c8 7887 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7888 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7889
7890 return (exp == 0 || exp == 0x7FF
7891 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7892 && (mantissa & 0x1FFFFFFFl) == 0;
7893}
7894
3739860c 7895/* Returns a double precision value casted to single precision
ba592044
AM
7896 (ignoring the least significant bits in exponent and mantissa). */
7897
7898static int
5fc177c8 7899double_to_single (bfd_int64_t v)
ba592044
AM
7900{
7901 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7902 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7903 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7904
7905 if (exp == 0x7FF)
7906 exp = 0xFF;
7907 else
7908 {
7909 exp = exp - 1023 + 127;
7910 if (exp >= 0xFF)
7911 {
7912 /* Infinity. */
7913 exp = 0x7F;
7914 mantissa = 0;
7915 }
7916 else if (exp < 0)
7917 {
7918 /* No denormalized numbers. */
7919 exp = 0;
7920 mantissa = 0;
7921 }
7922 }
7923 mantissa >>= 29;
7924 return (sign << 31) | (exp << 23) | mantissa;
7925}
5fc177c8 7926#endif /* BFD_HOST_64_BIT */
ba592044 7927
8335d6aa
JW
7928enum lit_type
7929{
7930 CONST_THUMB,
7931 CONST_ARM,
7932 CONST_VEC
7933};
7934
ba592044
AM
7935static void do_vfp_nsyn_opcode (const char *);
7936
c19d1205
ZW
7937/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7938 Determine whether it can be performed with a move instruction; if
7939 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7940 return TRUE; if it can't, convert inst.instruction to a literal-pool
7941 load and return FALSE. If this is not a valid thing to do in the
7942 current context, set inst.error and return TRUE.
a737bd4d 7943
c19d1205
ZW
7944 inst.operands[i] describes the destination register. */
7945
c921be7d 7946static bfd_boolean
8335d6aa 7947move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7948{
53365c0d 7949 unsigned long tbit;
8335d6aa
JW
7950 bfd_boolean thumb_p = (t == CONST_THUMB);
7951 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7952
7953 if (thumb_p)
7954 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7955 else
7956 tbit = LOAD_BIT;
7957
7958 if ((inst.instruction & tbit) == 0)
09d92015 7959 {
c19d1205 7960 inst.error = _("invalid pseudo operation");
c921be7d 7961 return TRUE;
09d92015 7962 }
ba592044 7963
8335d6aa
JW
7964 if (inst.reloc.exp.X_op != O_constant
7965 && inst.reloc.exp.X_op != O_symbol
7966 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7967 {
7968 inst.error = _("constant expression expected");
c921be7d 7969 return TRUE;
09d92015 7970 }
ba592044
AM
7971
7972 if (inst.reloc.exp.X_op == O_constant
7973 || inst.reloc.exp.X_op == O_big)
8335d6aa 7974 {
5fc177c8
NC
7975#if defined BFD_HOST_64_BIT
7976 bfd_int64_t v;
7977#else
ba592044 7978 offsetT v;
5fc177c8 7979#endif
ba592044 7980 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7981 {
ba592044
AM
7982 LITTLENUM_TYPE w[X_PRECISION];
7983 LITTLENUM_TYPE * l;
7984
7985 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7986 {
ba592044
AM
7987 gen_to_words (w, X_PRECISION, E_PRECISION);
7988 l = w;
7989 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7990 }
ba592044
AM
7991 else
7992 l = generic_bignum;
3739860c 7993
5fc177c8
NC
7994#if defined BFD_HOST_64_BIT
7995 v =
7996 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7997 << LITTLENUM_NUMBER_OF_BITS)
7998 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7999 << LITTLENUM_NUMBER_OF_BITS)
8000 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8001 << LITTLENUM_NUMBER_OF_BITS)
8002 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8003#else
ba592044
AM
8004 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8005 | (l[0] & LITTLENUM_MASK);
5fc177c8 8006#endif
8335d6aa 8007 }
ba592044
AM
8008 else
8009 v = inst.reloc.exp.X_add_number;
8010
8011 if (!inst.operands[i].issingle)
8335d6aa 8012 {
12569877 8013 if (thumb_p)
8335d6aa 8014 {
53445554
TP
8015 /* LDR should not use lead in a flag-setting instruction being
8016 chosen so we do not check whether movs can be used. */
12569877 8017
53445554 8018 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 8019 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
8020 && inst.operands[i].reg != 13
8021 && inst.operands[i].reg != 15)
12569877 8022 {
fc289b0a
TP
8023 /* Check if on thumb2 it can be done with a mov.w, mvn or
8024 movw instruction. */
12569877
AM
8025 unsigned int newimm;
8026 bfd_boolean isNegated;
8027
8028 newimm = encode_thumb32_immediate (v);
8029 if (newimm != (unsigned int) FAIL)
8030 isNegated = FALSE;
8031 else
8032 {
582cfe03 8033 newimm = encode_thumb32_immediate (~v);
12569877
AM
8034 if (newimm != (unsigned int) FAIL)
8035 isNegated = TRUE;
8036 }
8037
fc289b0a
TP
8038 /* The number can be loaded with a mov.w or mvn
8039 instruction. */
ff8646ee
TP
8040 if (newimm != (unsigned int) FAIL
8041 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8042 {
fc289b0a 8043 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8044 | (inst.operands[i].reg << 8));
fc289b0a 8045 /* Change to MOVN. */
582cfe03 8046 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8047 inst.instruction |= (newimm & 0x800) << 15;
8048 inst.instruction |= (newimm & 0x700) << 4;
8049 inst.instruction |= (newimm & 0x0ff);
8050 return TRUE;
8051 }
fc289b0a 8052 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8053 else if ((v & ~0xFFFF) == 0
8054 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8055 {
582cfe03 8056 int imm = v & 0xFFFF;
12569877 8057
582cfe03 8058 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8059 inst.instruction |= (inst.operands[i].reg << 8);
8060 inst.instruction |= (imm & 0xf000) << 4;
8061 inst.instruction |= (imm & 0x0800) << 15;
8062 inst.instruction |= (imm & 0x0700) << 4;
8063 inst.instruction |= (imm & 0x00ff);
8064 return TRUE;
8065 }
8066 }
8335d6aa 8067 }
12569877 8068 else if (arm_p)
ba592044
AM
8069 {
8070 int value = encode_arm_immediate (v);
12569877 8071
ba592044
AM
8072 if (value != FAIL)
8073 {
8074 /* This can be done with a mov instruction. */
8075 inst.instruction &= LITERAL_MASK;
8076 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8077 inst.instruction |= value & 0xfff;
8078 return TRUE;
8079 }
8335d6aa 8080
ba592044
AM
8081 value = encode_arm_immediate (~ v);
8082 if (value != FAIL)
8083 {
8084 /* This can be done with a mvn instruction. */
8085 inst.instruction &= LITERAL_MASK;
8086 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8087 inst.instruction |= value & 0xfff;
8088 return TRUE;
8089 }
8090 }
934c2632 8091 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8092 {
ba592044
AM
8093 int op = 0;
8094 unsigned immbits = 0;
8095 unsigned immlo = inst.operands[1].imm;
8096 unsigned immhi = inst.operands[1].regisimm
8097 ? inst.operands[1].reg
8098 : inst.reloc.exp.X_unsigned
8099 ? 0
8100 : ((bfd_int64_t)((int) immlo)) >> 32;
8101 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8102 &op, 64, NT_invtype);
8103
8104 if (cmode == FAIL)
8105 {
8106 neon_invert_size (&immlo, &immhi, 64);
8107 op = !op;
8108 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8109 &op, 64, NT_invtype);
8110 }
8111
8112 if (cmode != FAIL)
8113 {
8114 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8115 | (1 << 23)
8116 | (cmode << 8)
8117 | (op << 5)
8118 | (1 << 4);
8119
8120 /* Fill other bits in vmov encoding for both thumb and arm. */
8121 if (thumb_mode)
eff0bc54 8122 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8123 else
eff0bc54 8124 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8125 neon_write_immbits (immbits);
8126 return TRUE;
8127 }
8335d6aa
JW
8128 }
8129 }
8335d6aa 8130
ba592044
AM
8131 if (t == CONST_VEC)
8132 {
8133 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8134 if (inst.operands[i].issingle
8135 && is_quarter_float (inst.operands[1].imm)
8136 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8137 {
ba592044
AM
8138 inst.operands[1].imm =
8139 neon_qfloat_bits (v);
8140 do_vfp_nsyn_opcode ("fconsts");
8141 return TRUE;
8335d6aa 8142 }
5fc177c8
NC
8143
8144 /* If our host does not support a 64-bit type then we cannot perform
8145 the following optimization. This mean that there will be a
8146 discrepancy between the output produced by an assembler built for
8147 a 32-bit-only host and the output produced from a 64-bit host, but
8148 this cannot be helped. */
8149#if defined BFD_HOST_64_BIT
ba592044
AM
8150 else if (!inst.operands[1].issingle
8151 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8152 {
ba592044
AM
8153 if (is_double_a_single (v)
8154 && is_quarter_float (double_to_single (v)))
8155 {
8156 inst.operands[1].imm =
8157 neon_qfloat_bits (double_to_single (v));
8158 do_vfp_nsyn_opcode ("fconstd");
8159 return TRUE;
8160 }
8335d6aa 8161 }
5fc177c8 8162#endif
8335d6aa
JW
8163 }
8164 }
8165
8166 if (add_to_lit_pool ((!inst.operands[i].isvec
8167 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8168 return TRUE;
8169
8170 inst.operands[1].reg = REG_PC;
8171 inst.operands[1].isreg = 1;
8172 inst.operands[1].preind = 1;
8173 inst.reloc.pc_rel = 1;
8174 inst.reloc.type = (thumb_p
8175 ? BFD_RELOC_ARM_THUMB_OFFSET
8176 : (mode_3
8177 ? BFD_RELOC_ARM_HWLITERAL
8178 : BFD_RELOC_ARM_LITERAL));
8179 return FALSE;
8180}
8181
8182/* inst.operands[i] was set up by parse_address. Encode it into an
8183 ARM-format instruction. Reject all forms which cannot be encoded
8184 into a coprocessor load/store instruction. If wb_ok is false,
8185 reject use of writeback; if unind_ok is false, reject use of
8186 unindexed addressing. If reloc_override is not 0, use it instead
8187 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8188 (in which case it is preserved). */
8189
8190static int
8191encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8192{
8193 if (!inst.operands[i].isreg)
8194 {
99b2a2dd
NC
8195 /* PR 18256 */
8196 if (! inst.operands[0].isvec)
8197 {
8198 inst.error = _("invalid co-processor operand");
8199 return FAIL;
8200 }
8335d6aa
JW
8201 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8202 return SUCCESS;
8203 }
8204
8205 inst.instruction |= inst.operands[i].reg << 16;
8206
8207 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8208
8209 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8210 {
8211 gas_assert (!inst.operands[i].writeback);
8212 if (!unind_ok)
8213 {
8214 inst.error = _("instruction does not support unindexed addressing");
8215 return FAIL;
8216 }
8217 inst.instruction |= inst.operands[i].imm;
8218 inst.instruction |= INDEX_UP;
8219 return SUCCESS;
8220 }
8221
8222 if (inst.operands[i].preind)
8223 inst.instruction |= PRE_INDEX;
8224
8225 if (inst.operands[i].writeback)
09d92015 8226 {
8335d6aa 8227 if (inst.operands[i].reg == REG_PC)
c19d1205 8228 {
8335d6aa
JW
8229 inst.error = _("pc may not be used with write-back");
8230 return FAIL;
c19d1205 8231 }
8335d6aa 8232 if (!wb_ok)
c19d1205 8233 {
8335d6aa
JW
8234 inst.error = _("instruction does not support writeback");
8235 return FAIL;
c19d1205 8236 }
8335d6aa 8237 inst.instruction |= WRITE_BACK;
09d92015
MM
8238 }
8239
8335d6aa
JW
8240 if (reloc_override)
8241 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8242 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8243 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8244 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8245 {
8335d6aa
JW
8246 if (thumb_mode)
8247 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8248 else
8249 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8250 }
8335d6aa
JW
8251
8252 /* Prefer + for zero encoded value. */
8253 if (!inst.operands[i].negative)
8254 inst.instruction |= INDEX_UP;
8255
8256 return SUCCESS;
09d92015
MM
8257}
8258
5f4273c7 8259/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8260 First some generics; their names are taken from the conventional
8261 bit positions for register arguments in ARM format instructions. */
09d92015 8262
a737bd4d 8263static void
c19d1205 8264do_noargs (void)
09d92015 8265{
c19d1205 8266}
a737bd4d 8267
c19d1205
ZW
8268static void
8269do_rd (void)
8270{
8271 inst.instruction |= inst.operands[0].reg << 12;
8272}
a737bd4d 8273
16a1fa25
TP
8274static void
8275do_rn (void)
8276{
8277 inst.instruction |= inst.operands[0].reg << 16;
8278}
8279
c19d1205
ZW
8280static void
8281do_rd_rm (void)
8282{
8283 inst.instruction |= inst.operands[0].reg << 12;
8284 inst.instruction |= inst.operands[1].reg;
8285}
09d92015 8286
9eb6c0f1
MGD
8287static void
8288do_rm_rn (void)
8289{
8290 inst.instruction |= inst.operands[0].reg;
8291 inst.instruction |= inst.operands[1].reg << 16;
8292}
8293
c19d1205
ZW
8294static void
8295do_rd_rn (void)
8296{
8297 inst.instruction |= inst.operands[0].reg << 12;
8298 inst.instruction |= inst.operands[1].reg << 16;
8299}
a737bd4d 8300
c19d1205
ZW
8301static void
8302do_rn_rd (void)
8303{
8304 inst.instruction |= inst.operands[0].reg << 16;
8305 inst.instruction |= inst.operands[1].reg << 12;
8306}
09d92015 8307
4ed7ed8d
TP
8308static void
8309do_tt (void)
8310{
8311 inst.instruction |= inst.operands[0].reg << 8;
8312 inst.instruction |= inst.operands[1].reg << 16;
8313}
8314
59d09be6
MGD
8315static bfd_boolean
8316check_obsolete (const arm_feature_set *feature, const char *msg)
8317{
8318 if (ARM_CPU_IS_ANY (cpu_variant))
8319 {
5c3696f8 8320 as_tsktsk ("%s", msg);
59d09be6
MGD
8321 return TRUE;
8322 }
8323 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8324 {
8325 as_bad ("%s", msg);
8326 return TRUE;
8327 }
8328
8329 return FALSE;
8330}
8331
c19d1205
ZW
8332static void
8333do_rd_rm_rn (void)
8334{
9a64e435 8335 unsigned Rn = inst.operands[2].reg;
708587a4 8336 /* Enforce restrictions on SWP instruction. */
9a64e435 8337 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8338 {
8339 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8340 _("Rn must not overlap other operands"));
8341
59d09be6
MGD
8342 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8343 */
8344 if (!check_obsolete (&arm_ext_v8,
8345 _("swp{b} use is obsoleted for ARMv8 and later"))
8346 && warn_on_deprecated
8347 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8348 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8349 }
59d09be6 8350
c19d1205
ZW
8351 inst.instruction |= inst.operands[0].reg << 12;
8352 inst.instruction |= inst.operands[1].reg;
9a64e435 8353 inst.instruction |= Rn << 16;
c19d1205 8354}
09d92015 8355
c19d1205
ZW
8356static void
8357do_rd_rn_rm (void)
8358{
8359 inst.instruction |= inst.operands[0].reg << 12;
8360 inst.instruction |= inst.operands[1].reg << 16;
8361 inst.instruction |= inst.operands[2].reg;
8362}
a737bd4d 8363
c19d1205
ZW
8364static void
8365do_rm_rd_rn (void)
8366{
5be8be5d
DG
8367 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8368 constraint (((inst.reloc.exp.X_op != O_constant
8369 && inst.reloc.exp.X_op != O_illegal)
8370 || inst.reloc.exp.X_add_number != 0),
8371 BAD_ADDR_MODE);
c19d1205
ZW
8372 inst.instruction |= inst.operands[0].reg;
8373 inst.instruction |= inst.operands[1].reg << 12;
8374 inst.instruction |= inst.operands[2].reg << 16;
8375}
09d92015 8376
c19d1205
ZW
8377static void
8378do_imm0 (void)
8379{
8380 inst.instruction |= inst.operands[0].imm;
8381}
09d92015 8382
c19d1205
ZW
8383static void
8384do_rd_cpaddr (void)
8385{
8386 inst.instruction |= inst.operands[0].reg << 12;
8387 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8388}
a737bd4d 8389
c19d1205
ZW
8390/* ARM instructions, in alphabetical order by function name (except
8391 that wrapper functions appear immediately after the function they
8392 wrap). */
09d92015 8393
c19d1205
ZW
8394/* This is a pseudo-op of the form "adr rd, label" to be converted
8395 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8396
8397static void
c19d1205 8398do_adr (void)
09d92015 8399{
c19d1205 8400 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8401
c19d1205
ZW
8402 /* Frag hacking will turn this into a sub instruction if the offset turns
8403 out to be negative. */
8404 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8405 inst.reloc.pc_rel = 1;
2fc8bdac 8406 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8407
8408 if (inst.reloc.exp.X_op == O_symbol
8409 && inst.reloc.exp.X_add_symbol != NULL
8410 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8411 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8412 inst.reloc.exp.X_add_number += 1;
c19d1205 8413}
b99bd4ef 8414
c19d1205
ZW
8415/* This is a pseudo-op of the form "adrl rd, label" to be converted
8416 into a relative address of the form:
8417 add rd, pc, #low(label-.-8)"
8418 add rd, rd, #high(label-.-8)" */
b99bd4ef 8419
c19d1205
ZW
8420static void
8421do_adrl (void)
8422{
8423 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8424
c19d1205
ZW
8425 /* Frag hacking will turn this into a sub instruction if the offset turns
8426 out to be negative. */
8427 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8428 inst.reloc.pc_rel = 1;
8429 inst.size = INSN_SIZE * 2;
2fc8bdac 8430 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8431
8432 if (inst.reloc.exp.X_op == O_symbol
8433 && inst.reloc.exp.X_add_symbol != NULL
8434 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8435 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
0198d5e6 8436 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8437}
8438
b99bd4ef 8439static void
c19d1205 8440do_arit (void)
b99bd4ef 8441{
a9f02af8
MG
8442 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8443 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8444 THUMB1_RELOC_ONLY);
c19d1205
ZW
8445 if (!inst.operands[1].present)
8446 inst.operands[1].reg = inst.operands[0].reg;
8447 inst.instruction |= inst.operands[0].reg << 12;
8448 inst.instruction |= inst.operands[1].reg << 16;
8449 encode_arm_shifter_operand (2);
8450}
b99bd4ef 8451
62b3e311
PB
8452static void
8453do_barrier (void)
8454{
8455 if (inst.operands[0].present)
ccb84d65 8456 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8457 else
8458 inst.instruction |= 0xf;
8459}
8460
c19d1205
ZW
8461static void
8462do_bfc (void)
8463{
8464 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8465 constraint (msb > 32, _("bit-field extends past end of register"));
8466 /* The instruction encoding stores the LSB and MSB,
8467 not the LSB and width. */
8468 inst.instruction |= inst.operands[0].reg << 12;
8469 inst.instruction |= inst.operands[1].imm << 7;
8470 inst.instruction |= (msb - 1) << 16;
8471}
b99bd4ef 8472
c19d1205
ZW
8473static void
8474do_bfi (void)
8475{
8476 unsigned int msb;
b99bd4ef 8477
c19d1205
ZW
8478 /* #0 in second position is alternative syntax for bfc, which is
8479 the same instruction but with REG_PC in the Rm field. */
8480 if (!inst.operands[1].isreg)
8481 inst.operands[1].reg = REG_PC;
b99bd4ef 8482
c19d1205
ZW
8483 msb = inst.operands[2].imm + inst.operands[3].imm;
8484 constraint (msb > 32, _("bit-field extends past end of register"));
8485 /* The instruction encoding stores the LSB and MSB,
8486 not the LSB and width. */
8487 inst.instruction |= inst.operands[0].reg << 12;
8488 inst.instruction |= inst.operands[1].reg;
8489 inst.instruction |= inst.operands[2].imm << 7;
8490 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8491}
8492
b99bd4ef 8493static void
c19d1205 8494do_bfx (void)
b99bd4ef 8495{
c19d1205
ZW
8496 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8497 _("bit-field extends past end of register"));
8498 inst.instruction |= inst.operands[0].reg << 12;
8499 inst.instruction |= inst.operands[1].reg;
8500 inst.instruction |= inst.operands[2].imm << 7;
8501 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8502}
09d92015 8503
c19d1205
ZW
8504/* ARM V5 breakpoint instruction (argument parse)
8505 BKPT <16 bit unsigned immediate>
8506 Instruction is not conditional.
8507 The bit pattern given in insns[] has the COND_ALWAYS condition,
8508 and it is an error if the caller tried to override that. */
b99bd4ef 8509
c19d1205
ZW
8510static void
8511do_bkpt (void)
8512{
8513 /* Top 12 of 16 bits to bits 19:8. */
8514 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8515
c19d1205
ZW
8516 /* Bottom 4 of 16 bits to bits 3:0. */
8517 inst.instruction |= inst.operands[0].imm & 0xf;
8518}
09d92015 8519
c19d1205
ZW
8520static void
8521encode_branch (int default_reloc)
8522{
8523 if (inst.operands[0].hasreloc)
8524 {
0855e32b
NS
8525 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8526 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8527 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8528 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8529 ? BFD_RELOC_ARM_PLT32
8530 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8531 }
b99bd4ef 8532 else
9ae92b05 8533 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8534 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8535}
8536
b99bd4ef 8537static void
c19d1205 8538do_branch (void)
b99bd4ef 8539{
39b41c9c
PB
8540#ifdef OBJ_ELF
8541 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8542 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8543 else
8544#endif
8545 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8546}
8547
8548static void
8549do_bl (void)
8550{
8551#ifdef OBJ_ELF
8552 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8553 {
8554 if (inst.cond == COND_ALWAYS)
8555 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8556 else
8557 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8558 }
8559 else
8560#endif
8561 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8562}
b99bd4ef 8563
c19d1205
ZW
8564/* ARM V5 branch-link-exchange instruction (argument parse)
8565 BLX <target_addr> ie BLX(1)
8566 BLX{<condition>} <Rm> ie BLX(2)
8567 Unfortunately, there are two different opcodes for this mnemonic.
8568 So, the insns[].value is not used, and the code here zaps values
8569 into inst.instruction.
8570 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8571
c19d1205
ZW
8572static void
8573do_blx (void)
8574{
8575 if (inst.operands[0].isreg)
b99bd4ef 8576 {
c19d1205
ZW
8577 /* Arg is a register; the opcode provided by insns[] is correct.
8578 It is not illegal to do "blx pc", just useless. */
8579 if (inst.operands[0].reg == REG_PC)
8580 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8581
c19d1205
ZW
8582 inst.instruction |= inst.operands[0].reg;
8583 }
8584 else
b99bd4ef 8585 {
c19d1205 8586 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8587 conditionally, and the opcode must be adjusted.
8588 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8589 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8590 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8591 inst.instruction = 0xfa000000;
267bf995 8592 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8593 }
c19d1205
ZW
8594}
8595
8596static void
8597do_bx (void)
8598{
845b51d6
PB
8599 bfd_boolean want_reloc;
8600
c19d1205
ZW
8601 if (inst.operands[0].reg == REG_PC)
8602 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8603
c19d1205 8604 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8605 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8606 it is for ARMv4t or earlier. */
8607 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8608 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8609 want_reloc = TRUE;
8610
5ad34203 8611#ifdef OBJ_ELF
845b51d6 8612 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8613#endif
584206db 8614 want_reloc = FALSE;
845b51d6
PB
8615
8616 if (want_reloc)
8617 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8618}
8619
c19d1205
ZW
8620
8621/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8622
8623static void
c19d1205 8624do_bxj (void)
a737bd4d 8625{
c19d1205
ZW
8626 if (inst.operands[0].reg == REG_PC)
8627 as_tsktsk (_("use of r15 in bxj is not really useful"));
8628
8629 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8630}
8631
c19d1205
ZW
8632/* Co-processor data operation:
8633 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8634 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8635static void
8636do_cdp (void)
8637{
8638 inst.instruction |= inst.operands[0].reg << 8;
8639 inst.instruction |= inst.operands[1].imm << 20;
8640 inst.instruction |= inst.operands[2].reg << 12;
8641 inst.instruction |= inst.operands[3].reg << 16;
8642 inst.instruction |= inst.operands[4].reg;
8643 inst.instruction |= inst.operands[5].imm << 5;
8644}
a737bd4d
NC
8645
8646static void
c19d1205 8647do_cmp (void)
a737bd4d 8648{
c19d1205
ZW
8649 inst.instruction |= inst.operands[0].reg << 16;
8650 encode_arm_shifter_operand (1);
a737bd4d
NC
8651}
8652
c19d1205
ZW
8653/* Transfer between coprocessor and ARM registers.
8654 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8655 MRC2
8656 MCR{cond}
8657 MCR2
8658
8659 No special properties. */
09d92015 8660
dcbd0d71
MGD
8661struct deprecated_coproc_regs_s
8662{
8663 unsigned cp;
8664 int opc1;
8665 unsigned crn;
8666 unsigned crm;
8667 int opc2;
8668 arm_feature_set deprecated;
8669 arm_feature_set obsoleted;
8670 const char *dep_msg;
8671 const char *obs_msg;
8672};
8673
8674#define DEPR_ACCESS_V8 \
8675 N_("This coprocessor register access is deprecated in ARMv8")
8676
8677/* Table of all deprecated coprocessor registers. */
8678static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8679{
8680 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8681 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8682 DEPR_ACCESS_V8, NULL},
8683 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8684 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8685 DEPR_ACCESS_V8, NULL},
8686 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8687 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8688 DEPR_ACCESS_V8, NULL},
8689 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8690 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8691 DEPR_ACCESS_V8, NULL},
8692 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8693 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8694 DEPR_ACCESS_V8, NULL},
8695};
8696
8697#undef DEPR_ACCESS_V8
8698
8699static const size_t deprecated_coproc_reg_count =
8700 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8701
09d92015 8702static void
c19d1205 8703do_co_reg (void)
09d92015 8704{
fdfde340 8705 unsigned Rd;
dcbd0d71 8706 size_t i;
fdfde340
JM
8707
8708 Rd = inst.operands[2].reg;
8709 if (thumb_mode)
8710 {
8711 if (inst.instruction == 0xee000010
8712 || inst.instruction == 0xfe000010)
8713 /* MCR, MCR2 */
8714 reject_bad_reg (Rd);
5c8ed6a4 8715 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8716 /* MRC, MRC2 */
8717 constraint (Rd == REG_SP, BAD_SP);
8718 }
8719 else
8720 {
8721 /* MCR */
8722 if (inst.instruction == 0xe000010)
8723 constraint (Rd == REG_PC, BAD_PC);
8724 }
8725
dcbd0d71
MGD
8726 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8727 {
8728 const struct deprecated_coproc_regs_s *r =
8729 deprecated_coproc_regs + i;
8730
8731 if (inst.operands[0].reg == r->cp
8732 && inst.operands[1].imm == r->opc1
8733 && inst.operands[3].reg == r->crn
8734 && inst.operands[4].reg == r->crm
8735 && inst.operands[5].imm == r->opc2)
8736 {
b10bf8c5 8737 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8738 && warn_on_deprecated
dcbd0d71 8739 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8740 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8741 }
8742 }
fdfde340 8743
c19d1205
ZW
8744 inst.instruction |= inst.operands[0].reg << 8;
8745 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8746 inst.instruction |= Rd << 12;
c19d1205
ZW
8747 inst.instruction |= inst.operands[3].reg << 16;
8748 inst.instruction |= inst.operands[4].reg;
8749 inst.instruction |= inst.operands[5].imm << 5;
8750}
09d92015 8751
c19d1205
ZW
8752/* Transfer between coprocessor register and pair of ARM registers.
8753 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8754 MCRR2
8755 MRRC{cond}
8756 MRRC2
b99bd4ef 8757
c19d1205 8758 Two XScale instructions are special cases of these:
09d92015 8759
c19d1205
ZW
8760 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8761 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8762
5f4273c7 8763 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8764
c19d1205
ZW
8765static void
8766do_co_reg2c (void)
8767{
fdfde340
JM
8768 unsigned Rd, Rn;
8769
8770 Rd = inst.operands[2].reg;
8771 Rn = inst.operands[3].reg;
8772
8773 if (thumb_mode)
8774 {
8775 reject_bad_reg (Rd);
8776 reject_bad_reg (Rn);
8777 }
8778 else
8779 {
8780 constraint (Rd == REG_PC, BAD_PC);
8781 constraint (Rn == REG_PC, BAD_PC);
8782 }
8783
873f10f0
TC
8784 /* Only check the MRRC{2} variants. */
8785 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8786 {
8787 /* If Rd == Rn, error that the operation is
8788 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8789 constraint (Rd == Rn, BAD_OVERLAP);
8790 }
8791
c19d1205
ZW
8792 inst.instruction |= inst.operands[0].reg << 8;
8793 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8794 inst.instruction |= Rd << 12;
8795 inst.instruction |= Rn << 16;
c19d1205 8796 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8797}
8798
c19d1205
ZW
8799static void
8800do_cpsi (void)
8801{
8802 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8803 if (inst.operands[1].present)
8804 {
8805 inst.instruction |= CPSI_MMOD;
8806 inst.instruction |= inst.operands[1].imm;
8807 }
c19d1205 8808}
b99bd4ef 8809
62b3e311
PB
8810static void
8811do_dbg (void)
8812{
8813 inst.instruction |= inst.operands[0].imm;
8814}
8815
eea54501
MGD
8816static void
8817do_div (void)
8818{
8819 unsigned Rd, Rn, Rm;
8820
8821 Rd = inst.operands[0].reg;
8822 Rn = (inst.operands[1].present
8823 ? inst.operands[1].reg : Rd);
8824 Rm = inst.operands[2].reg;
8825
8826 constraint ((Rd == REG_PC), BAD_PC);
8827 constraint ((Rn == REG_PC), BAD_PC);
8828 constraint ((Rm == REG_PC), BAD_PC);
8829
8830 inst.instruction |= Rd << 16;
8831 inst.instruction |= Rn << 0;
8832 inst.instruction |= Rm << 8;
8833}
8834
b99bd4ef 8835static void
c19d1205 8836do_it (void)
b99bd4ef 8837{
c19d1205 8838 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8839 process it to do the validation as if in
8840 thumb mode, just in case the code gets
8841 assembled for thumb using the unified syntax. */
8842
c19d1205 8843 inst.size = 0;
e07e6e58
NC
8844 if (unified_syntax)
8845 {
8846 set_it_insn_type (IT_INSN);
8847 now_it.mask = (inst.instruction & 0xf) | 0x10;
8848 now_it.cc = inst.operands[0].imm;
8849 }
09d92015 8850}
b99bd4ef 8851
6530b175
NC
8852/* If there is only one register in the register list,
8853 then return its register number. Otherwise return -1. */
8854static int
8855only_one_reg_in_list (int range)
8856{
8857 int i = ffs (range) - 1;
8858 return (i > 15 || range != (1 << i)) ? -1 : i;
8859}
8860
09d92015 8861static void
6530b175 8862encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8863{
c19d1205
ZW
8864 int base_reg = inst.operands[0].reg;
8865 int range = inst.operands[1].imm;
6530b175 8866 int one_reg;
ea6ef066 8867
c19d1205
ZW
8868 inst.instruction |= base_reg << 16;
8869 inst.instruction |= range;
ea6ef066 8870
c19d1205
ZW
8871 if (inst.operands[1].writeback)
8872 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8873
c19d1205 8874 if (inst.operands[0].writeback)
ea6ef066 8875 {
c19d1205
ZW
8876 inst.instruction |= WRITE_BACK;
8877 /* Check for unpredictable uses of writeback. */
8878 if (inst.instruction & LOAD_BIT)
09d92015 8879 {
c19d1205
ZW
8880 /* Not allowed in LDM type 2. */
8881 if ((inst.instruction & LDM_TYPE_2_OR_3)
8882 && ((range & (1 << REG_PC)) == 0))
8883 as_warn (_("writeback of base register is UNPREDICTABLE"));
8884 /* Only allowed if base reg not in list for other types. */
8885 else if (range & (1 << base_reg))
8886 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8887 }
8888 else /* STM. */
8889 {
8890 /* Not allowed for type 2. */
8891 if (inst.instruction & LDM_TYPE_2_OR_3)
8892 as_warn (_("writeback of base register is UNPREDICTABLE"));
8893 /* Only allowed if base reg not in list, or first in list. */
8894 else if ((range & (1 << base_reg))
8895 && (range & ((1 << base_reg) - 1)))
8896 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8897 }
ea6ef066 8898 }
6530b175
NC
8899
8900 /* If PUSH/POP has only one register, then use the A2 encoding. */
8901 one_reg = only_one_reg_in_list (range);
8902 if (from_push_pop_mnem && one_reg >= 0)
8903 {
8904 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8905
8906 inst.instruction &= A_COND_MASK;
8907 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8908 inst.instruction |= one_reg << 12;
8909 }
8910}
8911
8912static void
8913do_ldmstm (void)
8914{
8915 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8916}
8917
c19d1205
ZW
8918/* ARMv5TE load-consecutive (argument parse)
8919 Mode is like LDRH.
8920
8921 LDRccD R, mode
8922 STRccD R, mode. */
8923
a737bd4d 8924static void
c19d1205 8925do_ldrd (void)
a737bd4d 8926{
c19d1205 8927 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8928 _("first transfer register must be even"));
c19d1205
ZW
8929 constraint (inst.operands[1].present
8930 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8931 _("can only transfer two consecutive registers"));
c19d1205
ZW
8932 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8933 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8934
c19d1205
ZW
8935 if (!inst.operands[1].present)
8936 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8937
c56791bb
RE
8938 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8939 register and the first register written; we have to diagnose
8940 overlap between the base and the second register written here. */
ea6ef066 8941
c56791bb
RE
8942 if (inst.operands[2].reg == inst.operands[1].reg
8943 && (inst.operands[2].writeback || inst.operands[2].postind))
8944 as_warn (_("base register written back, and overlaps "
8945 "second transfer register"));
b05fe5cf 8946
c56791bb
RE
8947 if (!(inst.instruction & V4_STR_BIT))
8948 {
c19d1205 8949 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8950 destination (even if not write-back). */
8951 if (inst.operands[2].immisreg
8952 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8953 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8954 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8955 }
c19d1205
ZW
8956 inst.instruction |= inst.operands[0].reg << 12;
8957 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8958}
8959
8960static void
c19d1205 8961do_ldrex (void)
b05fe5cf 8962{
c19d1205
ZW
8963 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8964 || inst.operands[1].postind || inst.operands[1].writeback
8965 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8966 || inst.operands[1].negative
8967 /* This can arise if the programmer has written
8968 strex rN, rM, foo
8969 or if they have mistakenly used a register name as the last
8970 operand, eg:
8971 strex rN, rM, rX
8972 It is very difficult to distinguish between these two cases
8973 because "rX" might actually be a label. ie the register
8974 name has been occluded by a symbol of the same name. So we
8975 just generate a general 'bad addressing mode' type error
8976 message and leave it up to the programmer to discover the
8977 true cause and fix their mistake. */
8978 || (inst.operands[1].reg == REG_PC),
8979 BAD_ADDR_MODE);
b05fe5cf 8980
c19d1205
ZW
8981 constraint (inst.reloc.exp.X_op != O_constant
8982 || inst.reloc.exp.X_add_number != 0,
8983 _("offset must be zero in ARM encoding"));
b05fe5cf 8984
5be8be5d
DG
8985 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8986
c19d1205
ZW
8987 inst.instruction |= inst.operands[0].reg << 12;
8988 inst.instruction |= inst.operands[1].reg << 16;
8989 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8990}
8991
8992static void
c19d1205 8993do_ldrexd (void)
b05fe5cf 8994{
c19d1205
ZW
8995 constraint (inst.operands[0].reg % 2 != 0,
8996 _("even register required"));
8997 constraint (inst.operands[1].present
8998 && inst.operands[1].reg != inst.operands[0].reg + 1,
8999 _("can only load two consecutive registers"));
9000 /* If op 1 were present and equal to PC, this function wouldn't
9001 have been called in the first place. */
9002 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 9003
c19d1205
ZW
9004 inst.instruction |= inst.operands[0].reg << 12;
9005 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
9006}
9007
1be5fd2e
NC
9008/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9009 which is not a multiple of four is UNPREDICTABLE. */
9010static void
9011check_ldr_r15_aligned (void)
9012{
9013 constraint (!(inst.operands[1].immisreg)
9014 && (inst.operands[0].reg == REG_PC
9015 && inst.operands[1].reg == REG_PC
9016 && (inst.reloc.exp.X_add_number & 0x3)),
de194d85 9017 _("ldr to register 15 must be 4-byte aligned"));
1be5fd2e
NC
9018}
9019
b05fe5cf 9020static void
c19d1205 9021do_ldst (void)
b05fe5cf 9022{
c19d1205
ZW
9023 inst.instruction |= inst.operands[0].reg << 12;
9024 if (!inst.operands[1].isreg)
8335d6aa 9025 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 9026 return;
c19d1205 9027 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 9028 check_ldr_r15_aligned ();
b05fe5cf
ZW
9029}
9030
9031static void
c19d1205 9032do_ldstt (void)
b05fe5cf 9033{
c19d1205
ZW
9034 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9035 reject [Rn,...]. */
9036 if (inst.operands[1].preind)
b05fe5cf 9037 {
bd3ba5d1
NC
9038 constraint (inst.reloc.exp.X_op != O_constant
9039 || inst.reloc.exp.X_add_number != 0,
c19d1205 9040 _("this instruction requires a post-indexed address"));
b05fe5cf 9041
c19d1205
ZW
9042 inst.operands[1].preind = 0;
9043 inst.operands[1].postind = 1;
9044 inst.operands[1].writeback = 1;
b05fe5cf 9045 }
c19d1205
ZW
9046 inst.instruction |= inst.operands[0].reg << 12;
9047 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9048}
b05fe5cf 9049
c19d1205 9050/* Halfword and signed-byte load/store operations. */
b05fe5cf 9051
c19d1205
ZW
9052static void
9053do_ldstv4 (void)
9054{
ff4a8d2b 9055 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9056 inst.instruction |= inst.operands[0].reg << 12;
9057 if (!inst.operands[1].isreg)
8335d6aa 9058 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9059 return;
c19d1205 9060 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9061}
9062
9063static void
c19d1205 9064do_ldsttv4 (void)
b05fe5cf 9065{
c19d1205
ZW
9066 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9067 reject [Rn,...]. */
9068 if (inst.operands[1].preind)
b05fe5cf 9069 {
bd3ba5d1
NC
9070 constraint (inst.reloc.exp.X_op != O_constant
9071 || inst.reloc.exp.X_add_number != 0,
c19d1205 9072 _("this instruction requires a post-indexed address"));
b05fe5cf 9073
c19d1205
ZW
9074 inst.operands[1].preind = 0;
9075 inst.operands[1].postind = 1;
9076 inst.operands[1].writeback = 1;
b05fe5cf 9077 }
c19d1205
ZW
9078 inst.instruction |= inst.operands[0].reg << 12;
9079 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9080}
b05fe5cf 9081
c19d1205
ZW
9082/* Co-processor register load/store.
9083 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9084static void
9085do_lstc (void)
9086{
9087 inst.instruction |= inst.operands[0].reg << 8;
9088 inst.instruction |= inst.operands[1].reg << 12;
9089 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9090}
9091
b05fe5cf 9092static void
c19d1205 9093do_mlas (void)
b05fe5cf 9094{
8fb9d7b9 9095 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9096 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9097 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9098 && !(inst.instruction & 0x00400000))
8fb9d7b9 9099 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9100
c19d1205
ZW
9101 inst.instruction |= inst.operands[0].reg << 16;
9102 inst.instruction |= inst.operands[1].reg;
9103 inst.instruction |= inst.operands[2].reg << 8;
9104 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9105}
b05fe5cf 9106
c19d1205
ZW
9107static void
9108do_mov (void)
9109{
a9f02af8
MG
9110 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9111 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9112 THUMB1_RELOC_ONLY);
c19d1205
ZW
9113 inst.instruction |= inst.operands[0].reg << 12;
9114 encode_arm_shifter_operand (1);
9115}
b05fe5cf 9116
c19d1205
ZW
9117/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9118static void
9119do_mov16 (void)
9120{
b6895b4f
PB
9121 bfd_vma imm;
9122 bfd_boolean top;
9123
9124 top = (inst.instruction & 0x00400000) != 0;
9125 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9126 _(":lower16: not allowed in this instruction"));
b6895b4f 9127 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9128 _(":upper16: not allowed in this instruction"));
c19d1205 9129 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9130 if (inst.reloc.type == BFD_RELOC_UNUSED)
9131 {
9132 imm = inst.reloc.exp.X_add_number;
9133 /* The value is in two pieces: 0:11, 16:19. */
9134 inst.instruction |= (imm & 0x00000fff);
9135 inst.instruction |= (imm & 0x0000f000) << 4;
9136 }
b05fe5cf 9137}
b99bd4ef 9138
037e8744
JB
9139static int
9140do_vfp_nsyn_mrs (void)
9141{
9142 if (inst.operands[0].isvec)
9143 {
9144 if (inst.operands[1].reg != 1)
477330fc 9145 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9146 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9147 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9148 do_vfp_nsyn_opcode ("fmstat");
9149 }
9150 else if (inst.operands[1].isvec)
9151 do_vfp_nsyn_opcode ("fmrx");
9152 else
9153 return FAIL;
5f4273c7 9154
037e8744
JB
9155 return SUCCESS;
9156}
9157
9158static int
9159do_vfp_nsyn_msr (void)
9160{
9161 if (inst.operands[0].isvec)
9162 do_vfp_nsyn_opcode ("fmxr");
9163 else
9164 return FAIL;
9165
9166 return SUCCESS;
9167}
9168
f7c21dc7
NC
9169static void
9170do_vmrs (void)
9171{
9172 unsigned Rt = inst.operands[0].reg;
fa94de6b 9173
16d02dc9 9174 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9175 {
9176 inst.error = BAD_SP;
9177 return;
9178 }
9179
40c7d507
RR
9180 /* MVFR2 is only valid at ARMv8-A. */
9181 if (inst.operands[1].reg == 5)
9182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9183 _(BAD_FPU));
9184
f7c21dc7 9185 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9186 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9187 {
9188 inst.error = BAD_PC;
9189 return;
9190 }
9191
16d02dc9
JB
9192 /* If we get through parsing the register name, we just insert the number
9193 generated into the instruction without further validation. */
9194 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9195 inst.instruction |= (Rt << 12);
9196}
9197
9198static void
9199do_vmsr (void)
9200{
9201 unsigned Rt = inst.operands[1].reg;
fa94de6b 9202
f7c21dc7
NC
9203 if (thumb_mode)
9204 reject_bad_reg (Rt);
9205 else if (Rt == REG_PC)
9206 {
9207 inst.error = BAD_PC;
9208 return;
9209 }
9210
40c7d507
RR
9211 /* MVFR2 is only valid for ARMv8-A. */
9212 if (inst.operands[0].reg == 5)
9213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9214 _(BAD_FPU));
9215
16d02dc9
JB
9216 /* If we get through parsing the register name, we just insert the number
9217 generated into the instruction without further validation. */
9218 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9219 inst.instruction |= (Rt << 12);
9220}
9221
b99bd4ef 9222static void
c19d1205 9223do_mrs (void)
b99bd4ef 9224{
90ec0d68
MGD
9225 unsigned br;
9226
037e8744
JB
9227 if (do_vfp_nsyn_mrs () == SUCCESS)
9228 return;
9229
ff4a8d2b 9230 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9231 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9232
9233 if (inst.operands[1].isreg)
9234 {
9235 br = inst.operands[1].reg;
9236 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9237 as_bad (_("bad register for mrs"));
9238 }
9239 else
9240 {
9241 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9242 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9243 != (PSR_c|PSR_f),
d2cd1205 9244 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9245 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9246 }
9247
9248 inst.instruction |= br;
c19d1205 9249}
b99bd4ef 9250
c19d1205
ZW
9251/* Two possible forms:
9252 "{C|S}PSR_<field>, Rm",
9253 "{C|S}PSR_f, #expression". */
b99bd4ef 9254
c19d1205
ZW
9255static void
9256do_msr (void)
9257{
037e8744
JB
9258 if (do_vfp_nsyn_msr () == SUCCESS)
9259 return;
9260
c19d1205
ZW
9261 inst.instruction |= inst.operands[0].imm;
9262 if (inst.operands[1].isreg)
9263 inst.instruction |= inst.operands[1].reg;
9264 else
b99bd4ef 9265 {
c19d1205
ZW
9266 inst.instruction |= INST_IMMEDIATE;
9267 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9268 inst.reloc.pc_rel = 0;
b99bd4ef 9269 }
b99bd4ef
NC
9270}
9271
c19d1205
ZW
9272static void
9273do_mul (void)
a737bd4d 9274{
ff4a8d2b
NC
9275 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9276
c19d1205
ZW
9277 if (!inst.operands[2].present)
9278 inst.operands[2].reg = inst.operands[0].reg;
9279 inst.instruction |= inst.operands[0].reg << 16;
9280 inst.instruction |= inst.operands[1].reg;
9281 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9282
8fb9d7b9
MS
9283 if (inst.operands[0].reg == inst.operands[1].reg
9284 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9285 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9286}
9287
c19d1205
ZW
9288/* Long Multiply Parser
9289 UMULL RdLo, RdHi, Rm, Rs
9290 SMULL RdLo, RdHi, Rm, Rs
9291 UMLAL RdLo, RdHi, Rm, Rs
9292 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9293
9294static void
c19d1205 9295do_mull (void)
b99bd4ef 9296{
c19d1205
ZW
9297 inst.instruction |= inst.operands[0].reg << 12;
9298 inst.instruction |= inst.operands[1].reg << 16;
9299 inst.instruction |= inst.operands[2].reg;
9300 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9301
682b27ad
PB
9302 /* rdhi and rdlo must be different. */
9303 if (inst.operands[0].reg == inst.operands[1].reg)
9304 as_tsktsk (_("rdhi and rdlo must be different"));
9305
9306 /* rdhi, rdlo and rm must all be different before armv6. */
9307 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9308 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9309 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9310 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9311}
b99bd4ef 9312
c19d1205
ZW
9313static void
9314do_nop (void)
9315{
e7495e45
NS
9316 if (inst.operands[0].present
9317 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9318 {
9319 /* Architectural NOP hints are CPSR sets with no bits selected. */
9320 inst.instruction &= 0xf0000000;
e7495e45
NS
9321 inst.instruction |= 0x0320f000;
9322 if (inst.operands[0].present)
9323 inst.instruction |= inst.operands[0].imm;
c19d1205 9324 }
b99bd4ef
NC
9325}
9326
c19d1205
ZW
9327/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9328 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9329 Condition defaults to COND_ALWAYS.
9330 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9331
9332static void
c19d1205 9333do_pkhbt (void)
b99bd4ef 9334{
c19d1205
ZW
9335 inst.instruction |= inst.operands[0].reg << 12;
9336 inst.instruction |= inst.operands[1].reg << 16;
9337 inst.instruction |= inst.operands[2].reg;
9338 if (inst.operands[3].present)
9339 encode_arm_shift (3);
9340}
b99bd4ef 9341
c19d1205 9342/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9343
c19d1205
ZW
9344static void
9345do_pkhtb (void)
9346{
9347 if (!inst.operands[3].present)
b99bd4ef 9348 {
c19d1205
ZW
9349 /* If the shift specifier is omitted, turn the instruction
9350 into pkhbt rd, rm, rn. */
9351 inst.instruction &= 0xfff00010;
9352 inst.instruction |= inst.operands[0].reg << 12;
9353 inst.instruction |= inst.operands[1].reg;
9354 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9355 }
9356 else
9357 {
c19d1205
ZW
9358 inst.instruction |= inst.operands[0].reg << 12;
9359 inst.instruction |= inst.operands[1].reg << 16;
9360 inst.instruction |= inst.operands[2].reg;
9361 encode_arm_shift (3);
b99bd4ef
NC
9362 }
9363}
9364
c19d1205 9365/* ARMv5TE: Preload-Cache
60e5ef9f 9366 MP Extensions: Preload for write
c19d1205 9367
60e5ef9f 9368 PLD(W) <addr_mode>
c19d1205
ZW
9369
9370 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9371
9372static void
c19d1205 9373do_pld (void)
b99bd4ef 9374{
c19d1205
ZW
9375 constraint (!inst.operands[0].isreg,
9376 _("'[' expected after PLD mnemonic"));
9377 constraint (inst.operands[0].postind,
9378 _("post-indexed expression used in preload instruction"));
9379 constraint (inst.operands[0].writeback,
9380 _("writeback used in preload instruction"));
9381 constraint (!inst.operands[0].preind,
9382 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9383 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9384}
b99bd4ef 9385
62b3e311
PB
9386/* ARMv7: PLI <addr_mode> */
9387static void
9388do_pli (void)
9389{
9390 constraint (!inst.operands[0].isreg,
9391 _("'[' expected after PLI mnemonic"));
9392 constraint (inst.operands[0].postind,
9393 _("post-indexed expression used in preload instruction"));
9394 constraint (inst.operands[0].writeback,
9395 _("writeback used in preload instruction"));
9396 constraint (!inst.operands[0].preind,
9397 _("unindexed addressing used in preload instruction"));
9398 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9399 inst.instruction &= ~PRE_INDEX;
9400}
9401
c19d1205
ZW
9402static void
9403do_push_pop (void)
9404{
5e0d7f77
MP
9405 constraint (inst.operands[0].writeback,
9406 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9407 inst.operands[1] = inst.operands[0];
9408 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9409 inst.operands[0].isreg = 1;
9410 inst.operands[0].writeback = 1;
9411 inst.operands[0].reg = REG_SP;
6530b175 9412 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9413}
b99bd4ef 9414
c19d1205
ZW
9415/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9416 word at the specified address and the following word
9417 respectively.
9418 Unconditionally executed.
9419 Error if Rn is R15. */
b99bd4ef 9420
c19d1205
ZW
9421static void
9422do_rfe (void)
9423{
9424 inst.instruction |= inst.operands[0].reg << 16;
9425 if (inst.operands[0].writeback)
9426 inst.instruction |= WRITE_BACK;
9427}
b99bd4ef 9428
c19d1205 9429/* ARM V6 ssat (argument parse). */
b99bd4ef 9430
c19d1205
ZW
9431static void
9432do_ssat (void)
9433{
9434 inst.instruction |= inst.operands[0].reg << 12;
9435 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9436 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9437
c19d1205
ZW
9438 if (inst.operands[3].present)
9439 encode_arm_shift (3);
b99bd4ef
NC
9440}
9441
c19d1205 9442/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9443
9444static void
c19d1205 9445do_usat (void)
b99bd4ef 9446{
c19d1205
ZW
9447 inst.instruction |= inst.operands[0].reg << 12;
9448 inst.instruction |= inst.operands[1].imm << 16;
9449 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9450
c19d1205
ZW
9451 if (inst.operands[3].present)
9452 encode_arm_shift (3);
b99bd4ef
NC
9453}
9454
c19d1205 9455/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9456
9457static void
c19d1205 9458do_ssat16 (void)
09d92015 9459{
c19d1205
ZW
9460 inst.instruction |= inst.operands[0].reg << 12;
9461 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9462 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9463}
9464
c19d1205
ZW
9465static void
9466do_usat16 (void)
a737bd4d 9467{
c19d1205
ZW
9468 inst.instruction |= inst.operands[0].reg << 12;
9469 inst.instruction |= inst.operands[1].imm << 16;
9470 inst.instruction |= inst.operands[2].reg;
9471}
a737bd4d 9472
c19d1205
ZW
9473/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9474 preserving the other bits.
a737bd4d 9475
c19d1205
ZW
9476 setend <endian_specifier>, where <endian_specifier> is either
9477 BE or LE. */
a737bd4d 9478
c19d1205
ZW
9479static void
9480do_setend (void)
9481{
12e37cbc
MGD
9482 if (warn_on_deprecated
9483 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9484 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9485
c19d1205
ZW
9486 if (inst.operands[0].imm)
9487 inst.instruction |= 0x200;
a737bd4d
NC
9488}
9489
9490static void
c19d1205 9491do_shift (void)
a737bd4d 9492{
c19d1205
ZW
9493 unsigned int Rm = (inst.operands[1].present
9494 ? inst.operands[1].reg
9495 : inst.operands[0].reg);
a737bd4d 9496
c19d1205
ZW
9497 inst.instruction |= inst.operands[0].reg << 12;
9498 inst.instruction |= Rm;
9499 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9500 {
c19d1205
ZW
9501 inst.instruction |= inst.operands[2].reg << 8;
9502 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9503 /* PR 12854: Error on extraneous shifts. */
9504 constraint (inst.operands[2].shifted,
9505 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9506 }
9507 else
c19d1205 9508 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9509}
9510
09d92015 9511static void
3eb17e6b 9512do_smc (void)
09d92015 9513{
3eb17e6b 9514 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9515 inst.reloc.pc_rel = 0;
09d92015
MM
9516}
9517
90ec0d68
MGD
9518static void
9519do_hvc (void)
9520{
9521 inst.reloc.type = BFD_RELOC_ARM_HVC;
9522 inst.reloc.pc_rel = 0;
9523}
9524
09d92015 9525static void
c19d1205 9526do_swi (void)
09d92015 9527{
c19d1205
ZW
9528 inst.reloc.type = BFD_RELOC_ARM_SWI;
9529 inst.reloc.pc_rel = 0;
09d92015
MM
9530}
9531
ddfded2f
MW
9532static void
9533do_setpan (void)
9534{
9535 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9536 _("selected processor does not support SETPAN instruction"));
9537
9538 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9539}
9540
9541static void
9542do_t_setpan (void)
9543{
9544 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9545 _("selected processor does not support SETPAN instruction"));
9546
9547 inst.instruction |= (inst.operands[0].imm << 3);
9548}
9549
c19d1205
ZW
9550/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9551 SMLAxy{cond} Rd,Rm,Rs,Rn
9552 SMLAWy{cond} Rd,Rm,Rs,Rn
9553 Error if any register is R15. */
e16bb312 9554
c19d1205
ZW
9555static void
9556do_smla (void)
e16bb312 9557{
c19d1205
ZW
9558 inst.instruction |= inst.operands[0].reg << 16;
9559 inst.instruction |= inst.operands[1].reg;
9560 inst.instruction |= inst.operands[2].reg << 8;
9561 inst.instruction |= inst.operands[3].reg << 12;
9562}
a737bd4d 9563
c19d1205
ZW
9564/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9565 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9566 Error if any register is R15.
9567 Warning if Rdlo == Rdhi. */
a737bd4d 9568
c19d1205
ZW
9569static void
9570do_smlal (void)
9571{
9572 inst.instruction |= inst.operands[0].reg << 12;
9573 inst.instruction |= inst.operands[1].reg << 16;
9574 inst.instruction |= inst.operands[2].reg;
9575 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9576
c19d1205
ZW
9577 if (inst.operands[0].reg == inst.operands[1].reg)
9578 as_tsktsk (_("rdhi and rdlo must be different"));
9579}
a737bd4d 9580
c19d1205
ZW
9581/* ARM V5E (El Segundo) signed-multiply (argument parse)
9582 SMULxy{cond} Rd,Rm,Rs
9583 Error if any register is R15. */
a737bd4d 9584
c19d1205
ZW
9585static void
9586do_smul (void)
9587{
9588 inst.instruction |= inst.operands[0].reg << 16;
9589 inst.instruction |= inst.operands[1].reg;
9590 inst.instruction |= inst.operands[2].reg << 8;
9591}
a737bd4d 9592
b6702015
PB
9593/* ARM V6 srs (argument parse). The variable fields in the encoding are
9594 the same for both ARM and Thumb-2. */
a737bd4d 9595
c19d1205
ZW
9596static void
9597do_srs (void)
9598{
b6702015
PB
9599 int reg;
9600
9601 if (inst.operands[0].present)
9602 {
9603 reg = inst.operands[0].reg;
fdfde340 9604 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9605 }
9606 else
fdfde340 9607 reg = REG_SP;
b6702015
PB
9608
9609 inst.instruction |= reg << 16;
9610 inst.instruction |= inst.operands[1].imm;
9611 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9612 inst.instruction |= WRITE_BACK;
9613}
a737bd4d 9614
c19d1205 9615/* ARM V6 strex (argument parse). */
a737bd4d 9616
c19d1205
ZW
9617static void
9618do_strex (void)
9619{
9620 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9621 || inst.operands[2].postind || inst.operands[2].writeback
9622 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9623 || inst.operands[2].negative
9624 /* See comment in do_ldrex(). */
9625 || (inst.operands[2].reg == REG_PC),
9626 BAD_ADDR_MODE);
a737bd4d 9627
c19d1205
ZW
9628 constraint (inst.operands[0].reg == inst.operands[1].reg
9629 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9630
c19d1205
ZW
9631 constraint (inst.reloc.exp.X_op != O_constant
9632 || inst.reloc.exp.X_add_number != 0,
9633 _("offset must be zero in ARM encoding"));
a737bd4d 9634
c19d1205
ZW
9635 inst.instruction |= inst.operands[0].reg << 12;
9636 inst.instruction |= inst.operands[1].reg;
9637 inst.instruction |= inst.operands[2].reg << 16;
9638 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9639}
9640
877807f8
NC
9641static void
9642do_t_strexbh (void)
9643{
9644 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9645 || inst.operands[2].postind || inst.operands[2].writeback
9646 || inst.operands[2].immisreg || inst.operands[2].shifted
9647 || inst.operands[2].negative,
9648 BAD_ADDR_MODE);
9649
9650 constraint (inst.operands[0].reg == inst.operands[1].reg
9651 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9652
9653 do_rm_rd_rn ();
9654}
9655
e16bb312 9656static void
c19d1205 9657do_strexd (void)
e16bb312 9658{
c19d1205
ZW
9659 constraint (inst.operands[1].reg % 2 != 0,
9660 _("even register required"));
9661 constraint (inst.operands[2].present
9662 && inst.operands[2].reg != inst.operands[1].reg + 1,
9663 _("can only store two consecutive registers"));
9664 /* If op 2 were present and equal to PC, this function wouldn't
9665 have been called in the first place. */
9666 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9667
c19d1205
ZW
9668 constraint (inst.operands[0].reg == inst.operands[1].reg
9669 || inst.operands[0].reg == inst.operands[1].reg + 1
9670 || inst.operands[0].reg == inst.operands[3].reg,
9671 BAD_OVERLAP);
e16bb312 9672
c19d1205
ZW
9673 inst.instruction |= inst.operands[0].reg << 12;
9674 inst.instruction |= inst.operands[1].reg;
9675 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9676}
9677
9eb6c0f1
MGD
9678/* ARM V8 STRL. */
9679static void
4b8c8c02 9680do_stlex (void)
9eb6c0f1
MGD
9681{
9682 constraint (inst.operands[0].reg == inst.operands[1].reg
9683 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9684
9685 do_rd_rm_rn ();
9686}
9687
9688static void
4b8c8c02 9689do_t_stlex (void)
9eb6c0f1
MGD
9690{
9691 constraint (inst.operands[0].reg == inst.operands[1].reg
9692 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9693
9694 do_rm_rd_rn ();
9695}
9696
c19d1205
ZW
9697/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9698 extends it to 32-bits, and adds the result to a value in another
9699 register. You can specify a rotation by 0, 8, 16, or 24 bits
9700 before extracting the 16-bit value.
9701 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9702 Condition defaults to COND_ALWAYS.
9703 Error if any register uses R15. */
9704
e16bb312 9705static void
c19d1205 9706do_sxtah (void)
e16bb312 9707{
c19d1205
ZW
9708 inst.instruction |= inst.operands[0].reg << 12;
9709 inst.instruction |= inst.operands[1].reg << 16;
9710 inst.instruction |= inst.operands[2].reg;
9711 inst.instruction |= inst.operands[3].imm << 10;
9712}
e16bb312 9713
c19d1205 9714/* ARM V6 SXTH.
e16bb312 9715
c19d1205
ZW
9716 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9717 Condition defaults to COND_ALWAYS.
9718 Error if any register uses R15. */
e16bb312
NC
9719
9720static void
c19d1205 9721do_sxth (void)
e16bb312 9722{
c19d1205
ZW
9723 inst.instruction |= inst.operands[0].reg << 12;
9724 inst.instruction |= inst.operands[1].reg;
9725 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9726}
c19d1205
ZW
9727\f
9728/* VFP instructions. In a logical order: SP variant first, monad
9729 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9730
9731static void
c19d1205 9732do_vfp_sp_monadic (void)
e16bb312 9733{
5287ad62
JB
9734 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9736}
9737
9738static void
c19d1205 9739do_vfp_sp_dyadic (void)
e16bb312 9740{
5287ad62
JB
9741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9742 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9743 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9744}
9745
9746static void
c19d1205 9747do_vfp_sp_compare_z (void)
e16bb312 9748{
5287ad62 9749 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9750}
9751
9752static void
c19d1205 9753do_vfp_dp_sp_cvt (void)
e16bb312 9754{
5287ad62
JB
9755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9757}
9758
9759static void
c19d1205 9760do_vfp_sp_dp_cvt (void)
e16bb312 9761{
5287ad62
JB
9762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9763 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9764}
9765
9766static void
c19d1205 9767do_vfp_reg_from_sp (void)
e16bb312 9768{
c19d1205 9769 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9770 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9771}
9772
9773static void
c19d1205 9774do_vfp_reg2_from_sp2 (void)
e16bb312 9775{
c19d1205
ZW
9776 constraint (inst.operands[2].imm != 2,
9777 _("only two consecutive VFP SP registers allowed here"));
9778 inst.instruction |= inst.operands[0].reg << 12;
9779 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9780 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9781}
9782
9783static void
c19d1205 9784do_vfp_sp_from_reg (void)
e16bb312 9785{
5287ad62 9786 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9787 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9788}
9789
9790static void
c19d1205 9791do_vfp_sp2_from_reg2 (void)
e16bb312 9792{
c19d1205
ZW
9793 constraint (inst.operands[0].imm != 2,
9794 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9795 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9796 inst.instruction |= inst.operands[1].reg << 12;
9797 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9798}
9799
9800static void
c19d1205 9801do_vfp_sp_ldst (void)
e16bb312 9802{
5287ad62 9803 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9804 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9805}
9806
9807static void
c19d1205 9808do_vfp_dp_ldst (void)
e16bb312 9809{
5287ad62 9810 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9811 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9812}
9813
c19d1205 9814
e16bb312 9815static void
c19d1205 9816vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9817{
c19d1205
ZW
9818 if (inst.operands[0].writeback)
9819 inst.instruction |= WRITE_BACK;
9820 else
9821 constraint (ldstm_type != VFP_LDSTMIA,
9822 _("this addressing mode requires base-register writeback"));
9823 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9824 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9825 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9826}
9827
9828static void
c19d1205 9829vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9830{
c19d1205 9831 int count;
e16bb312 9832
c19d1205
ZW
9833 if (inst.operands[0].writeback)
9834 inst.instruction |= WRITE_BACK;
9835 else
9836 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9837 _("this addressing mode requires base-register writeback"));
e16bb312 9838
c19d1205 9839 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9840 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9841
c19d1205
ZW
9842 count = inst.operands[1].imm << 1;
9843 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9844 count += 1;
e16bb312 9845
c19d1205 9846 inst.instruction |= count;
e16bb312
NC
9847}
9848
9849static void
c19d1205 9850do_vfp_sp_ldstmia (void)
e16bb312 9851{
c19d1205 9852 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9853}
9854
9855static void
c19d1205 9856do_vfp_sp_ldstmdb (void)
e16bb312 9857{
c19d1205 9858 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9859}
9860
9861static void
c19d1205 9862do_vfp_dp_ldstmia (void)
e16bb312 9863{
c19d1205 9864 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9865}
9866
9867static void
c19d1205 9868do_vfp_dp_ldstmdb (void)
e16bb312 9869{
c19d1205 9870 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9871}
9872
9873static void
c19d1205 9874do_vfp_xp_ldstmia (void)
e16bb312 9875{
c19d1205
ZW
9876 vfp_dp_ldstm (VFP_LDSTMIAX);
9877}
e16bb312 9878
c19d1205
ZW
9879static void
9880do_vfp_xp_ldstmdb (void)
9881{
9882 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9883}
5287ad62
JB
9884
9885static void
9886do_vfp_dp_rd_rm (void)
9887{
9888 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9889 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9890}
9891
9892static void
9893do_vfp_dp_rn_rd (void)
9894{
9895 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9896 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9897}
9898
9899static void
9900do_vfp_dp_rd_rn (void)
9901{
9902 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9903 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9904}
9905
9906static void
9907do_vfp_dp_rd_rn_rm (void)
9908{
9909 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9910 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9911 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9912}
9913
9914static void
9915do_vfp_dp_rd (void)
9916{
9917 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9918}
9919
9920static void
9921do_vfp_dp_rm_rd_rn (void)
9922{
9923 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9924 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9925 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9926}
9927
9928/* VFPv3 instructions. */
9929static void
9930do_vfp_sp_const (void)
9931{
9932 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9933 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9934 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9935}
9936
9937static void
9938do_vfp_dp_const (void)
9939{
9940 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9941 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9942 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9943}
9944
9945static void
9946vfp_conv (int srcsize)
9947{
5f1af56b
MGD
9948 int immbits = srcsize - inst.operands[1].imm;
9949
fa94de6b
RM
9950 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9951 {
5f1af56b 9952 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9953 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9954 inst.error = _("immediate value out of range, expected range [0, 16]");
9955 return;
9956 }
fa94de6b 9957 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9958 {
9959 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9960 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9961 inst.error = _("immediate value out of range, expected range [1, 32]");
9962 return;
9963 }
9964
5287ad62
JB
9965 inst.instruction |= (immbits & 1) << 5;
9966 inst.instruction |= (immbits >> 1);
9967}
9968
9969static void
9970do_vfp_sp_conv_16 (void)
9971{
9972 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9973 vfp_conv (16);
9974}
9975
9976static void
9977do_vfp_dp_conv_16 (void)
9978{
9979 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9980 vfp_conv (16);
9981}
9982
9983static void
9984do_vfp_sp_conv_32 (void)
9985{
9986 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9987 vfp_conv (32);
9988}
9989
9990static void
9991do_vfp_dp_conv_32 (void)
9992{
9993 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9994 vfp_conv (32);
9995}
c19d1205
ZW
9996\f
9997/* FPA instructions. Also in a logical order. */
e16bb312 9998
c19d1205
ZW
9999static void
10000do_fpa_cmp (void)
10001{
10002 inst.instruction |= inst.operands[0].reg << 16;
10003 inst.instruction |= inst.operands[1].reg;
10004}
b99bd4ef
NC
10005
10006static void
c19d1205 10007do_fpa_ldmstm (void)
b99bd4ef 10008{
c19d1205
ZW
10009 inst.instruction |= inst.operands[0].reg << 12;
10010 switch (inst.operands[1].imm)
10011 {
10012 case 1: inst.instruction |= CP_T_X; break;
10013 case 2: inst.instruction |= CP_T_Y; break;
10014 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10015 case 4: break;
10016 default: abort ();
10017 }
b99bd4ef 10018
c19d1205
ZW
10019 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10020 {
10021 /* The instruction specified "ea" or "fd", so we can only accept
10022 [Rn]{!}. The instruction does not really support stacking or
10023 unstacking, so we have to emulate these by setting appropriate
10024 bits and offsets. */
10025 constraint (inst.reloc.exp.X_op != O_constant
10026 || inst.reloc.exp.X_add_number != 0,
10027 _("this instruction does not support indexing"));
b99bd4ef 10028
c19d1205
ZW
10029 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10030 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 10031
c19d1205
ZW
10032 if (!(inst.instruction & INDEX_UP))
10033 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 10034
c19d1205
ZW
10035 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10036 {
10037 inst.operands[2].preind = 0;
10038 inst.operands[2].postind = 1;
10039 }
10040 }
b99bd4ef 10041
c19d1205 10042 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 10043}
c19d1205
ZW
10044\f
10045/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 10046
c19d1205
ZW
10047static void
10048do_iwmmxt_tandorc (void)
10049{
10050 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10051}
b99bd4ef 10052
c19d1205
ZW
10053static void
10054do_iwmmxt_textrc (void)
10055{
10056 inst.instruction |= inst.operands[0].reg << 12;
10057 inst.instruction |= inst.operands[1].imm;
10058}
b99bd4ef
NC
10059
10060static void
c19d1205 10061do_iwmmxt_textrm (void)
b99bd4ef 10062{
c19d1205
ZW
10063 inst.instruction |= inst.operands[0].reg << 12;
10064 inst.instruction |= inst.operands[1].reg << 16;
10065 inst.instruction |= inst.operands[2].imm;
10066}
b99bd4ef 10067
c19d1205
ZW
10068static void
10069do_iwmmxt_tinsr (void)
10070{
10071 inst.instruction |= inst.operands[0].reg << 16;
10072 inst.instruction |= inst.operands[1].reg << 12;
10073 inst.instruction |= inst.operands[2].imm;
10074}
b99bd4ef 10075
c19d1205
ZW
10076static void
10077do_iwmmxt_tmia (void)
10078{
10079 inst.instruction |= inst.operands[0].reg << 5;
10080 inst.instruction |= inst.operands[1].reg;
10081 inst.instruction |= inst.operands[2].reg << 12;
10082}
b99bd4ef 10083
c19d1205
ZW
10084static void
10085do_iwmmxt_waligni (void)
10086{
10087 inst.instruction |= inst.operands[0].reg << 12;
10088 inst.instruction |= inst.operands[1].reg << 16;
10089 inst.instruction |= inst.operands[2].reg;
10090 inst.instruction |= inst.operands[3].imm << 20;
10091}
b99bd4ef 10092
2d447fca
JM
10093static void
10094do_iwmmxt_wmerge (void)
10095{
10096 inst.instruction |= inst.operands[0].reg << 12;
10097 inst.instruction |= inst.operands[1].reg << 16;
10098 inst.instruction |= inst.operands[2].reg;
10099 inst.instruction |= inst.operands[3].imm << 21;
10100}
10101
c19d1205
ZW
10102static void
10103do_iwmmxt_wmov (void)
10104{
10105 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10106 inst.instruction |= inst.operands[0].reg << 12;
10107 inst.instruction |= inst.operands[1].reg << 16;
10108 inst.instruction |= inst.operands[1].reg;
10109}
b99bd4ef 10110
c19d1205
ZW
10111static void
10112do_iwmmxt_wldstbh (void)
10113{
8f06b2d8 10114 int reloc;
c19d1205 10115 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10116 if (thumb_mode)
10117 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10118 else
10119 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10120 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10121}
10122
c19d1205
ZW
10123static void
10124do_iwmmxt_wldstw (void)
10125{
10126 /* RIWR_RIWC clears .isreg for a control register. */
10127 if (!inst.operands[0].isreg)
10128 {
10129 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10130 inst.instruction |= 0xf0000000;
10131 }
b99bd4ef 10132
c19d1205
ZW
10133 inst.instruction |= inst.operands[0].reg << 12;
10134 encode_arm_cp_address (1, TRUE, TRUE, 0);
10135}
b99bd4ef
NC
10136
10137static void
c19d1205 10138do_iwmmxt_wldstd (void)
b99bd4ef 10139{
c19d1205 10140 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10141 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10142 && inst.operands[1].immisreg)
10143 {
10144 inst.instruction &= ~0x1a000ff;
eff0bc54 10145 inst.instruction |= (0xfU << 28);
2d447fca
JM
10146 if (inst.operands[1].preind)
10147 inst.instruction |= PRE_INDEX;
10148 if (!inst.operands[1].negative)
10149 inst.instruction |= INDEX_UP;
10150 if (inst.operands[1].writeback)
10151 inst.instruction |= WRITE_BACK;
10152 inst.instruction |= inst.operands[1].reg << 16;
10153 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10154 inst.instruction |= inst.operands[1].imm;
10155 }
10156 else
10157 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10158}
b99bd4ef 10159
c19d1205
ZW
10160static void
10161do_iwmmxt_wshufh (void)
10162{
10163 inst.instruction |= inst.operands[0].reg << 12;
10164 inst.instruction |= inst.operands[1].reg << 16;
10165 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10166 inst.instruction |= (inst.operands[2].imm & 0x0f);
10167}
b99bd4ef 10168
c19d1205
ZW
10169static void
10170do_iwmmxt_wzero (void)
10171{
10172 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10173 inst.instruction |= inst.operands[0].reg;
10174 inst.instruction |= inst.operands[0].reg << 12;
10175 inst.instruction |= inst.operands[0].reg << 16;
10176}
2d447fca
JM
10177
10178static void
10179do_iwmmxt_wrwrwr_or_imm5 (void)
10180{
10181 if (inst.operands[2].isreg)
10182 do_rd_rn_rm ();
10183 else {
10184 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10185 _("immediate operand requires iWMMXt2"));
10186 do_rd_rn ();
10187 if (inst.operands[2].imm == 0)
10188 {
10189 switch ((inst.instruction >> 20) & 0xf)
10190 {
10191 case 4:
10192 case 5:
10193 case 6:
5f4273c7 10194 case 7:
2d447fca
JM
10195 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10196 inst.operands[2].imm = 16;
10197 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10198 break;
10199 case 8:
10200 case 9:
10201 case 10:
10202 case 11:
10203 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10204 inst.operands[2].imm = 32;
10205 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10206 break;
10207 case 12:
10208 case 13:
10209 case 14:
10210 case 15:
10211 {
10212 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10213 unsigned long wrn;
10214 wrn = (inst.instruction >> 16) & 0xf;
10215 inst.instruction &= 0xff0fff0f;
10216 inst.instruction |= wrn;
10217 /* Bail out here; the instruction is now assembled. */
10218 return;
10219 }
10220 }
10221 }
10222 /* Map 32 -> 0, etc. */
10223 inst.operands[2].imm &= 0x1f;
eff0bc54 10224 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10225 }
10226}
c19d1205
ZW
10227\f
10228/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10229 operations first, then control, shift, and load/store. */
b99bd4ef 10230
c19d1205 10231/* Insns like "foo X,Y,Z". */
b99bd4ef 10232
c19d1205
ZW
10233static void
10234do_mav_triple (void)
10235{
10236 inst.instruction |= inst.operands[0].reg << 16;
10237 inst.instruction |= inst.operands[1].reg;
10238 inst.instruction |= inst.operands[2].reg << 12;
10239}
b99bd4ef 10240
c19d1205
ZW
10241/* Insns like "foo W,X,Y,Z".
10242 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10243
c19d1205
ZW
10244static void
10245do_mav_quad (void)
10246{
10247 inst.instruction |= inst.operands[0].reg << 5;
10248 inst.instruction |= inst.operands[1].reg << 12;
10249 inst.instruction |= inst.operands[2].reg << 16;
10250 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10251}
10252
c19d1205
ZW
10253/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10254static void
10255do_mav_dspsc (void)
a737bd4d 10256{
c19d1205
ZW
10257 inst.instruction |= inst.operands[1].reg << 12;
10258}
a737bd4d 10259
c19d1205
ZW
10260/* Maverick shift immediate instructions.
10261 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10262 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10263
c19d1205
ZW
10264static void
10265do_mav_shift (void)
10266{
10267 int imm = inst.operands[2].imm;
a737bd4d 10268
c19d1205
ZW
10269 inst.instruction |= inst.operands[0].reg << 12;
10270 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10271
c19d1205
ZW
10272 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10273 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10274 Bit 4 should be 0. */
10275 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10276
c19d1205
ZW
10277 inst.instruction |= imm;
10278}
10279\f
10280/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10281
c19d1205
ZW
10282/* Xscale multiply-accumulate (argument parse)
10283 MIAcc acc0,Rm,Rs
10284 MIAPHcc acc0,Rm,Rs
10285 MIAxycc acc0,Rm,Rs. */
a737bd4d 10286
c19d1205
ZW
10287static void
10288do_xsc_mia (void)
10289{
10290 inst.instruction |= inst.operands[1].reg;
10291 inst.instruction |= inst.operands[2].reg << 12;
10292}
a737bd4d 10293
c19d1205 10294/* Xscale move-accumulator-register (argument parse)
a737bd4d 10295
c19d1205 10296 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10297
c19d1205
ZW
10298static void
10299do_xsc_mar (void)
10300{
10301 inst.instruction |= inst.operands[1].reg << 12;
10302 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10303}
10304
c19d1205 10305/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10306
c19d1205 10307 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10308
10309static void
c19d1205 10310do_xsc_mra (void)
b99bd4ef 10311{
c19d1205
ZW
10312 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10313 inst.instruction |= inst.operands[0].reg << 12;
10314 inst.instruction |= inst.operands[1].reg << 16;
10315}
10316\f
10317/* Encoding functions relevant only to Thumb. */
b99bd4ef 10318
c19d1205
ZW
10319/* inst.operands[i] is a shifted-register operand; encode
10320 it into inst.instruction in the format used by Thumb32. */
10321
10322static void
10323encode_thumb32_shifted_operand (int i)
10324{
10325 unsigned int value = inst.reloc.exp.X_add_number;
10326 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10327
9c3c69f2
PB
10328 constraint (inst.operands[i].immisreg,
10329 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10330 inst.instruction |= inst.operands[i].reg;
10331 if (shift == SHIFT_RRX)
10332 inst.instruction |= SHIFT_ROR << 4;
10333 else
b99bd4ef 10334 {
c19d1205
ZW
10335 constraint (inst.reloc.exp.X_op != O_constant,
10336 _("expression too complex"));
10337
10338 constraint (value > 32
10339 || (value == 32 && (shift == SHIFT_LSL
10340 || shift == SHIFT_ROR)),
10341 _("shift expression is too large"));
10342
10343 if (value == 0)
10344 shift = SHIFT_LSL;
10345 else if (value == 32)
10346 value = 0;
10347
10348 inst.instruction |= shift << 4;
10349 inst.instruction |= (value & 0x1c) << 10;
10350 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10351 }
c19d1205 10352}
b99bd4ef 10353
b99bd4ef 10354
c19d1205
ZW
10355/* inst.operands[i] was set up by parse_address. Encode it into a
10356 Thumb32 format load or store instruction. Reject forms that cannot
10357 be used with such instructions. If is_t is true, reject forms that
10358 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10359 that cannot be used with a D instruction. If it is a store insn,
10360 reject PC in Rn. */
b99bd4ef 10361
c19d1205
ZW
10362static void
10363encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10364{
5be8be5d 10365 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10366
10367 constraint (!inst.operands[i].isreg,
53365c0d 10368 _("Instruction does not support =N addresses"));
b99bd4ef 10369
c19d1205
ZW
10370 inst.instruction |= inst.operands[i].reg << 16;
10371 if (inst.operands[i].immisreg)
b99bd4ef 10372 {
5be8be5d 10373 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10374 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10375 constraint (inst.operands[i].negative,
10376 _("Thumb does not support negative register indexing"));
10377 constraint (inst.operands[i].postind,
10378 _("Thumb does not support register post-indexing"));
10379 constraint (inst.operands[i].writeback,
10380 _("Thumb does not support register indexing with writeback"));
10381 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10382 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10383
f40d1643 10384 inst.instruction |= inst.operands[i].imm;
c19d1205 10385 if (inst.operands[i].shifted)
b99bd4ef 10386 {
c19d1205
ZW
10387 constraint (inst.reloc.exp.X_op != O_constant,
10388 _("expression too complex"));
9c3c69f2
PB
10389 constraint (inst.reloc.exp.X_add_number < 0
10390 || inst.reloc.exp.X_add_number > 3,
c19d1205 10391 _("shift out of range"));
9c3c69f2 10392 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10393 }
10394 inst.reloc.type = BFD_RELOC_UNUSED;
10395 }
10396 else if (inst.operands[i].preind)
10397 {
5be8be5d 10398 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10399 constraint (is_t && inst.operands[i].writeback,
c19d1205 10400 _("cannot use writeback with this instruction"));
4755303e
WN
10401 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10402 BAD_PC_ADDRESSING);
c19d1205
ZW
10403
10404 if (is_d)
10405 {
10406 inst.instruction |= 0x01000000;
10407 if (inst.operands[i].writeback)
10408 inst.instruction |= 0x00200000;
b99bd4ef 10409 }
c19d1205 10410 else
b99bd4ef 10411 {
c19d1205
ZW
10412 inst.instruction |= 0x00000c00;
10413 if (inst.operands[i].writeback)
10414 inst.instruction |= 0x00000100;
b99bd4ef 10415 }
c19d1205 10416 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10417 }
c19d1205 10418 else if (inst.operands[i].postind)
b99bd4ef 10419 {
9c2799c2 10420 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10421 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10422 constraint (is_t, _("cannot use post-indexing with this instruction"));
10423
10424 if (is_d)
10425 inst.instruction |= 0x00200000;
10426 else
10427 inst.instruction |= 0x00000900;
10428 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10429 }
10430 else /* unindexed - only for coprocessor */
10431 inst.error = _("instruction does not accept unindexed addressing");
10432}
10433
10434/* Table of Thumb instructions which exist in both 16- and 32-bit
10435 encodings (the latter only in post-V6T2 cores). The index is the
10436 value used in the insns table below. When there is more than one
10437 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10438 holds variant (1).
10439 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10440#define T16_32_TAB \
21d799b5
NC
10441 X(_adc, 4140, eb400000), \
10442 X(_adcs, 4140, eb500000), \
10443 X(_add, 1c00, eb000000), \
10444 X(_adds, 1c00, eb100000), \
10445 X(_addi, 0000, f1000000), \
10446 X(_addis, 0000, f1100000), \
10447 X(_add_pc,000f, f20f0000), \
10448 X(_add_sp,000d, f10d0000), \
10449 X(_adr, 000f, f20f0000), \
10450 X(_and, 4000, ea000000), \
10451 X(_ands, 4000, ea100000), \
10452 X(_asr, 1000, fa40f000), \
10453 X(_asrs, 1000, fa50f000), \
10454 X(_b, e000, f000b000), \
10455 X(_bcond, d000, f0008000), \
10456 X(_bic, 4380, ea200000), \
10457 X(_bics, 4380, ea300000), \
10458 X(_cmn, 42c0, eb100f00), \
10459 X(_cmp, 2800, ebb00f00), \
10460 X(_cpsie, b660, f3af8400), \
10461 X(_cpsid, b670, f3af8600), \
10462 X(_cpy, 4600, ea4f0000), \
10463 X(_dec_sp,80dd, f1ad0d00), \
10464 X(_eor, 4040, ea800000), \
10465 X(_eors, 4040, ea900000), \
10466 X(_inc_sp,00dd, f10d0d00), \
10467 X(_ldmia, c800, e8900000), \
10468 X(_ldr, 6800, f8500000), \
10469 X(_ldrb, 7800, f8100000), \
10470 X(_ldrh, 8800, f8300000), \
10471 X(_ldrsb, 5600, f9100000), \
10472 X(_ldrsh, 5e00, f9300000), \
10473 X(_ldr_pc,4800, f85f0000), \
10474 X(_ldr_pc2,4800, f85f0000), \
10475 X(_ldr_sp,9800, f85d0000), \
10476 X(_lsl, 0000, fa00f000), \
10477 X(_lsls, 0000, fa10f000), \
10478 X(_lsr, 0800, fa20f000), \
10479 X(_lsrs, 0800, fa30f000), \
10480 X(_mov, 2000, ea4f0000), \
10481 X(_movs, 2000, ea5f0000), \
10482 X(_mul, 4340, fb00f000), \
10483 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10484 X(_mvn, 43c0, ea6f0000), \
10485 X(_mvns, 43c0, ea7f0000), \
10486 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10487 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10488 X(_orr, 4300, ea400000), \
10489 X(_orrs, 4300, ea500000), \
10490 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10491 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10492 X(_rev, ba00, fa90f080), \
10493 X(_rev16, ba40, fa90f090), \
10494 X(_revsh, bac0, fa90f0b0), \
10495 X(_ror, 41c0, fa60f000), \
10496 X(_rors, 41c0, fa70f000), \
10497 X(_sbc, 4180, eb600000), \
10498 X(_sbcs, 4180, eb700000), \
10499 X(_stmia, c000, e8800000), \
10500 X(_str, 6000, f8400000), \
10501 X(_strb, 7000, f8000000), \
10502 X(_strh, 8000, f8200000), \
10503 X(_str_sp,9000, f84d0000), \
10504 X(_sub, 1e00, eba00000), \
10505 X(_subs, 1e00, ebb00000), \
10506 X(_subi, 8000, f1a00000), \
10507 X(_subis, 8000, f1b00000), \
10508 X(_sxtb, b240, fa4ff080), \
10509 X(_sxth, b200, fa0ff080), \
10510 X(_tst, 4200, ea100f00), \
10511 X(_uxtb, b2c0, fa5ff080), \
10512 X(_uxth, b280, fa1ff080), \
10513 X(_nop, bf00, f3af8000), \
10514 X(_yield, bf10, f3af8001), \
10515 X(_wfe, bf20, f3af8002), \
10516 X(_wfi, bf30, f3af8003), \
53c4b28b 10517 X(_sev, bf40, f3af8004), \
74db7efb
NC
10518 X(_sevl, bf50, f3af8005), \
10519 X(_udf, de00, f7f0a000)
c19d1205
ZW
10520
10521/* To catch errors in encoding functions, the codes are all offset by
10522 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10523 as 16-bit instructions. */
21d799b5 10524#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10525enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10526#undef X
10527
10528#define X(a,b,c) 0x##b
10529static const unsigned short thumb_op16[] = { T16_32_TAB };
10530#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10531#undef X
10532
10533#define X(a,b,c) 0x##c
10534static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10535#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10536#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10537#undef X
10538#undef T16_32_TAB
10539
10540/* Thumb instruction encoders, in alphabetical order. */
10541
92e90b6e 10542/* ADDW or SUBW. */
c921be7d 10543
92e90b6e
PB
10544static void
10545do_t_add_sub_w (void)
10546{
10547 int Rd, Rn;
10548
10549 Rd = inst.operands[0].reg;
10550 Rn = inst.operands[1].reg;
10551
539d4391
NC
10552 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10553 is the SP-{plus,minus}-immediate form of the instruction. */
10554 if (Rn == REG_SP)
10555 constraint (Rd == REG_PC, BAD_PC);
10556 else
10557 reject_bad_reg (Rd);
fdfde340 10558
92e90b6e
PB
10559 inst.instruction |= (Rn << 16) | (Rd << 8);
10560 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10561}
10562
c19d1205 10563/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10564 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10565
10566static void
10567do_t_add_sub (void)
10568{
10569 int Rd, Rs, Rn;
10570
10571 Rd = inst.operands[0].reg;
10572 Rs = (inst.operands[1].present
10573 ? inst.operands[1].reg /* Rd, Rs, foo */
10574 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10575
e07e6e58
NC
10576 if (Rd == REG_PC)
10577 set_it_insn_type_last ();
10578
c19d1205
ZW
10579 if (unified_syntax)
10580 {
0110f2b8
PB
10581 bfd_boolean flags;
10582 bfd_boolean narrow;
10583 int opcode;
10584
10585 flags = (inst.instruction == T_MNEM_adds
10586 || inst.instruction == T_MNEM_subs);
10587 if (flags)
e07e6e58 10588 narrow = !in_it_block ();
0110f2b8 10589 else
e07e6e58 10590 narrow = in_it_block ();
c19d1205 10591 if (!inst.operands[2].isreg)
b99bd4ef 10592 {
16805f35
PB
10593 int add;
10594
5c8ed6a4
JW
10595 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10596 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10597
16805f35
PB
10598 add = (inst.instruction == T_MNEM_add
10599 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10600 opcode = 0;
10601 if (inst.size_req != 4)
10602 {
0110f2b8 10603 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10604 appropriate. */
0110f2b8
PB
10605 if (Rd == REG_SP && Rs == REG_SP && !flags)
10606 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10607 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10608 opcode = T_MNEM_add_sp;
10609 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10610 opcode = T_MNEM_add_pc;
10611 else if (Rd <= 7 && Rs <= 7 && narrow)
10612 {
10613 if (flags)
10614 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10615 else
10616 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10617 }
10618 if (opcode)
10619 {
10620 inst.instruction = THUMB_OP16(opcode);
10621 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10622 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10623 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10624 {
10625 if (inst.size_req == 2)
10626 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10627 else
10628 inst.relax = opcode;
10629 }
0110f2b8
PB
10630 }
10631 else
10632 constraint (inst.size_req == 2, BAD_HIREG);
10633 }
10634 if (inst.size_req == 4
10635 || (inst.size_req != 2 && !opcode))
10636 {
a9f02af8
MG
10637 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10638 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10639 THUMB1_RELOC_ONLY);
efd81785
PB
10640 if (Rd == REG_PC)
10641 {
fdfde340 10642 constraint (add, BAD_PC);
efd81785
PB
10643 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10644 _("only SUBS PC, LR, #const allowed"));
10645 constraint (inst.reloc.exp.X_op != O_constant,
10646 _("expression too complex"));
10647 constraint (inst.reloc.exp.X_add_number < 0
10648 || inst.reloc.exp.X_add_number > 0xff,
10649 _("immediate value out of range"));
10650 inst.instruction = T2_SUBS_PC_LR
10651 | inst.reloc.exp.X_add_number;
10652 inst.reloc.type = BFD_RELOC_UNUSED;
10653 return;
10654 }
10655 else if (Rs == REG_PC)
16805f35
PB
10656 {
10657 /* Always use addw/subw. */
10658 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10659 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10660 }
10661 else
10662 {
10663 inst.instruction = THUMB_OP32 (inst.instruction);
10664 inst.instruction = (inst.instruction & 0xe1ffffff)
10665 | 0x10000000;
10666 if (flags)
10667 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10668 else
10669 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10670 }
dc4503c6
PB
10671 inst.instruction |= Rd << 8;
10672 inst.instruction |= Rs << 16;
0110f2b8 10673 }
b99bd4ef 10674 }
c19d1205
ZW
10675 else
10676 {
5f4cb198
NC
10677 unsigned int value = inst.reloc.exp.X_add_number;
10678 unsigned int shift = inst.operands[2].shift_kind;
10679
c19d1205
ZW
10680 Rn = inst.operands[2].reg;
10681 /* See if we can do this with a 16-bit instruction. */
10682 if (!inst.operands[2].shifted && inst.size_req != 4)
10683 {
e27ec89e
PB
10684 if (Rd > 7 || Rs > 7 || Rn > 7)
10685 narrow = FALSE;
10686
10687 if (narrow)
c19d1205 10688 {
e27ec89e
PB
10689 inst.instruction = ((inst.instruction == T_MNEM_adds
10690 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10691 ? T_OPCODE_ADD_R3
10692 : T_OPCODE_SUB_R3);
10693 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10694 return;
10695 }
b99bd4ef 10696
7e806470 10697 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10698 {
7e806470
PB
10699 /* Thumb-1 cores (except v6-M) require at least one high
10700 register in a narrow non flag setting add. */
10701 if (Rd > 7 || Rn > 7
10702 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10703 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10704 {
7e806470
PB
10705 if (Rd == Rn)
10706 {
10707 Rn = Rs;
10708 Rs = Rd;
10709 }
c19d1205
ZW
10710 inst.instruction = T_OPCODE_ADD_HI;
10711 inst.instruction |= (Rd & 8) << 4;
10712 inst.instruction |= (Rd & 7);
10713 inst.instruction |= Rn << 3;
10714 return;
10715 }
c19d1205
ZW
10716 }
10717 }
c921be7d 10718
fdfde340 10719 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10720 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10721 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10722 constraint (Rs == REG_PC, BAD_PC);
10723 reject_bad_reg (Rn);
10724
c19d1205
ZW
10725 /* If we get here, it can't be done in 16 bits. */
10726 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10727 _("shift must be constant"));
10728 inst.instruction = THUMB_OP32 (inst.instruction);
10729 inst.instruction |= Rd << 8;
10730 inst.instruction |= Rs << 16;
5f4cb198
NC
10731 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10732 _("shift value over 3 not allowed in thumb mode"));
10733 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10734 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10735 encode_thumb32_shifted_operand (2);
10736 }
10737 }
10738 else
10739 {
10740 constraint (inst.instruction == T_MNEM_adds
10741 || inst.instruction == T_MNEM_subs,
10742 BAD_THUMB32);
b99bd4ef 10743
c19d1205 10744 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10745 {
c19d1205
ZW
10746 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10747 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10748 BAD_HIREG);
10749
10750 inst.instruction = (inst.instruction == T_MNEM_add
10751 ? 0x0000 : 0x8000);
10752 inst.instruction |= (Rd << 4) | Rs;
10753 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10754 return;
10755 }
10756
c19d1205
ZW
10757 Rn = inst.operands[2].reg;
10758 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10759
c19d1205
ZW
10760 /* We now have Rd, Rs, and Rn set to registers. */
10761 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10762 {
c19d1205
ZW
10763 /* Can't do this for SUB. */
10764 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10765 inst.instruction = T_OPCODE_ADD_HI;
10766 inst.instruction |= (Rd & 8) << 4;
10767 inst.instruction |= (Rd & 7);
10768 if (Rs == Rd)
10769 inst.instruction |= Rn << 3;
10770 else if (Rn == Rd)
10771 inst.instruction |= Rs << 3;
10772 else
10773 constraint (1, _("dest must overlap one source register"));
10774 }
10775 else
10776 {
10777 inst.instruction = (inst.instruction == T_MNEM_add
10778 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10779 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10780 }
b99bd4ef 10781 }
b99bd4ef
NC
10782}
10783
c19d1205
ZW
10784static void
10785do_t_adr (void)
10786{
fdfde340
JM
10787 unsigned Rd;
10788
10789 Rd = inst.operands[0].reg;
10790 reject_bad_reg (Rd);
10791
10792 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10793 {
10794 /* Defer to section relaxation. */
10795 inst.relax = inst.instruction;
10796 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10797 inst.instruction |= Rd << 4;
0110f2b8
PB
10798 }
10799 else if (unified_syntax && inst.size_req != 2)
e9f89963 10800 {
0110f2b8 10801 /* Generate a 32-bit opcode. */
e9f89963 10802 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10803 inst.instruction |= Rd << 8;
e9f89963
PB
10804 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10805 inst.reloc.pc_rel = 1;
10806 }
10807 else
10808 {
0110f2b8 10809 /* Generate a 16-bit opcode. */
e9f89963
PB
10810 inst.instruction = THUMB_OP16 (inst.instruction);
10811 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10812 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10813 inst.reloc.pc_rel = 1;
fdfde340 10814 inst.instruction |= Rd << 4;
e9f89963 10815 }
52a86f84
NC
10816
10817 if (inst.reloc.exp.X_op == O_symbol
10818 && inst.reloc.exp.X_add_symbol != NULL
10819 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10820 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10821 inst.reloc.exp.X_add_number += 1;
c19d1205 10822}
b99bd4ef 10823
c19d1205
ZW
10824/* Arithmetic instructions for which there is just one 16-bit
10825 instruction encoding, and it allows only two low registers.
10826 For maximal compatibility with ARM syntax, we allow three register
10827 operands even when Thumb-32 instructions are not available, as long
10828 as the first two are identical. For instance, both "sbc r0,r1" and
10829 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10830static void
c19d1205 10831do_t_arit3 (void)
b99bd4ef 10832{
c19d1205 10833 int Rd, Rs, Rn;
b99bd4ef 10834
c19d1205
ZW
10835 Rd = inst.operands[0].reg;
10836 Rs = (inst.operands[1].present
10837 ? inst.operands[1].reg /* Rd, Rs, foo */
10838 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10839 Rn = inst.operands[2].reg;
b99bd4ef 10840
fdfde340
JM
10841 reject_bad_reg (Rd);
10842 reject_bad_reg (Rs);
10843 if (inst.operands[2].isreg)
10844 reject_bad_reg (Rn);
10845
c19d1205 10846 if (unified_syntax)
b99bd4ef 10847 {
c19d1205
ZW
10848 if (!inst.operands[2].isreg)
10849 {
10850 /* For an immediate, we always generate a 32-bit opcode;
10851 section relaxation will shrink it later if possible. */
10852 inst.instruction = THUMB_OP32 (inst.instruction);
10853 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10854 inst.instruction |= Rd << 8;
10855 inst.instruction |= Rs << 16;
10856 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10857 }
10858 else
10859 {
e27ec89e
PB
10860 bfd_boolean narrow;
10861
c19d1205 10862 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10863 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10864 narrow = !in_it_block ();
e27ec89e 10865 else
e07e6e58 10866 narrow = in_it_block ();
e27ec89e
PB
10867
10868 if (Rd > 7 || Rn > 7 || Rs > 7)
10869 narrow = FALSE;
10870 if (inst.operands[2].shifted)
10871 narrow = FALSE;
10872 if (inst.size_req == 4)
10873 narrow = FALSE;
10874
10875 if (narrow
c19d1205
ZW
10876 && Rd == Rs)
10877 {
10878 inst.instruction = THUMB_OP16 (inst.instruction);
10879 inst.instruction |= Rd;
10880 inst.instruction |= Rn << 3;
10881 return;
10882 }
b99bd4ef 10883
c19d1205
ZW
10884 /* If we get here, it can't be done in 16 bits. */
10885 constraint (inst.operands[2].shifted
10886 && inst.operands[2].immisreg,
10887 _("shift must be constant"));
10888 inst.instruction = THUMB_OP32 (inst.instruction);
10889 inst.instruction |= Rd << 8;
10890 inst.instruction |= Rs << 16;
10891 encode_thumb32_shifted_operand (2);
10892 }
a737bd4d 10893 }
c19d1205 10894 else
b99bd4ef 10895 {
c19d1205
ZW
10896 /* On its face this is a lie - the instruction does set the
10897 flags. However, the only supported mnemonic in this mode
10898 says it doesn't. */
10899 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10900
c19d1205
ZW
10901 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10902 _("unshifted register required"));
10903 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10904 constraint (Rd != Rs,
10905 _("dest and source1 must be the same register"));
a737bd4d 10906
c19d1205
ZW
10907 inst.instruction = THUMB_OP16 (inst.instruction);
10908 inst.instruction |= Rd;
10909 inst.instruction |= Rn << 3;
b99bd4ef 10910 }
a737bd4d 10911}
b99bd4ef 10912
c19d1205
ZW
10913/* Similarly, but for instructions where the arithmetic operation is
10914 commutative, so we can allow either of them to be different from
10915 the destination operand in a 16-bit instruction. For instance, all
10916 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10917 accepted. */
10918static void
10919do_t_arit3c (void)
a737bd4d 10920{
c19d1205 10921 int Rd, Rs, Rn;
b99bd4ef 10922
c19d1205
ZW
10923 Rd = inst.operands[0].reg;
10924 Rs = (inst.operands[1].present
10925 ? inst.operands[1].reg /* Rd, Rs, foo */
10926 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10927 Rn = inst.operands[2].reg;
c921be7d 10928
fdfde340
JM
10929 reject_bad_reg (Rd);
10930 reject_bad_reg (Rs);
10931 if (inst.operands[2].isreg)
10932 reject_bad_reg (Rn);
a737bd4d 10933
c19d1205 10934 if (unified_syntax)
a737bd4d 10935 {
c19d1205 10936 if (!inst.operands[2].isreg)
b99bd4ef 10937 {
c19d1205
ZW
10938 /* For an immediate, we always generate a 32-bit opcode;
10939 section relaxation will shrink it later if possible. */
10940 inst.instruction = THUMB_OP32 (inst.instruction);
10941 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10942 inst.instruction |= Rd << 8;
10943 inst.instruction |= Rs << 16;
10944 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10945 }
c19d1205 10946 else
a737bd4d 10947 {
e27ec89e
PB
10948 bfd_boolean narrow;
10949
c19d1205 10950 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10951 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10952 narrow = !in_it_block ();
e27ec89e 10953 else
e07e6e58 10954 narrow = in_it_block ();
e27ec89e
PB
10955
10956 if (Rd > 7 || Rn > 7 || Rs > 7)
10957 narrow = FALSE;
10958 if (inst.operands[2].shifted)
10959 narrow = FALSE;
10960 if (inst.size_req == 4)
10961 narrow = FALSE;
10962
10963 if (narrow)
a737bd4d 10964 {
c19d1205 10965 if (Rd == Rs)
a737bd4d 10966 {
c19d1205
ZW
10967 inst.instruction = THUMB_OP16 (inst.instruction);
10968 inst.instruction |= Rd;
10969 inst.instruction |= Rn << 3;
10970 return;
a737bd4d 10971 }
c19d1205 10972 if (Rd == Rn)
a737bd4d 10973 {
c19d1205
ZW
10974 inst.instruction = THUMB_OP16 (inst.instruction);
10975 inst.instruction |= Rd;
10976 inst.instruction |= Rs << 3;
10977 return;
a737bd4d
NC
10978 }
10979 }
c19d1205
ZW
10980
10981 /* If we get here, it can't be done in 16 bits. */
10982 constraint (inst.operands[2].shifted
10983 && inst.operands[2].immisreg,
10984 _("shift must be constant"));
10985 inst.instruction = THUMB_OP32 (inst.instruction);
10986 inst.instruction |= Rd << 8;
10987 inst.instruction |= Rs << 16;
10988 encode_thumb32_shifted_operand (2);
a737bd4d 10989 }
b99bd4ef 10990 }
c19d1205
ZW
10991 else
10992 {
10993 /* On its face this is a lie - the instruction does set the
10994 flags. However, the only supported mnemonic in this mode
10995 says it doesn't. */
10996 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10997
c19d1205
ZW
10998 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10999 _("unshifted register required"));
11000 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11001
11002 inst.instruction = THUMB_OP16 (inst.instruction);
11003 inst.instruction |= Rd;
11004
11005 if (Rd == Rs)
11006 inst.instruction |= Rn << 3;
11007 else if (Rd == Rn)
11008 inst.instruction |= Rs << 3;
11009 else
11010 constraint (1, _("dest must overlap one source register"));
11011 }
a737bd4d
NC
11012}
11013
c19d1205
ZW
11014static void
11015do_t_bfc (void)
a737bd4d 11016{
fdfde340 11017 unsigned Rd;
c19d1205
ZW
11018 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11019 constraint (msb > 32, _("bit-field extends past end of register"));
11020 /* The instruction encoding stores the LSB and MSB,
11021 not the LSB and width. */
fdfde340
JM
11022 Rd = inst.operands[0].reg;
11023 reject_bad_reg (Rd);
11024 inst.instruction |= Rd << 8;
c19d1205
ZW
11025 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11026 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11027 inst.instruction |= msb - 1;
b99bd4ef
NC
11028}
11029
c19d1205
ZW
11030static void
11031do_t_bfi (void)
b99bd4ef 11032{
fdfde340 11033 int Rd, Rn;
c19d1205 11034 unsigned int msb;
b99bd4ef 11035
fdfde340
JM
11036 Rd = inst.operands[0].reg;
11037 reject_bad_reg (Rd);
11038
c19d1205
ZW
11039 /* #0 in second position is alternative syntax for bfc, which is
11040 the same instruction but with REG_PC in the Rm field. */
11041 if (!inst.operands[1].isreg)
fdfde340
JM
11042 Rn = REG_PC;
11043 else
11044 {
11045 Rn = inst.operands[1].reg;
11046 reject_bad_reg (Rn);
11047 }
b99bd4ef 11048
c19d1205
ZW
11049 msb = inst.operands[2].imm + inst.operands[3].imm;
11050 constraint (msb > 32, _("bit-field extends past end of register"));
11051 /* The instruction encoding stores the LSB and MSB,
11052 not the LSB and width. */
fdfde340
JM
11053 inst.instruction |= Rd << 8;
11054 inst.instruction |= Rn << 16;
c19d1205
ZW
11055 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11056 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11057 inst.instruction |= msb - 1;
b99bd4ef
NC
11058}
11059
c19d1205
ZW
11060static void
11061do_t_bfx (void)
b99bd4ef 11062{
fdfde340
JM
11063 unsigned Rd, Rn;
11064
11065 Rd = inst.operands[0].reg;
11066 Rn = inst.operands[1].reg;
11067
11068 reject_bad_reg (Rd);
11069 reject_bad_reg (Rn);
11070
c19d1205
ZW
11071 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11072 _("bit-field extends past end of register"));
fdfde340
JM
11073 inst.instruction |= Rd << 8;
11074 inst.instruction |= Rn << 16;
c19d1205
ZW
11075 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11076 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11077 inst.instruction |= inst.operands[3].imm - 1;
11078}
b99bd4ef 11079
c19d1205
ZW
11080/* ARM V5 Thumb BLX (argument parse)
11081 BLX <target_addr> which is BLX(1)
11082 BLX <Rm> which is BLX(2)
11083 Unfortunately, there are two different opcodes for this mnemonic.
11084 So, the insns[].value is not used, and the code here zaps values
11085 into inst.instruction.
b99bd4ef 11086
c19d1205
ZW
11087 ??? How to take advantage of the additional two bits of displacement
11088 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11089
c19d1205
ZW
11090static void
11091do_t_blx (void)
11092{
e07e6e58
NC
11093 set_it_insn_type_last ();
11094
c19d1205 11095 if (inst.operands[0].isreg)
fdfde340
JM
11096 {
11097 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11098 /* We have a register, so this is BLX(2). */
11099 inst.instruction |= inst.operands[0].reg << 3;
11100 }
b99bd4ef
NC
11101 else
11102 {
c19d1205 11103 /* No register. This must be BLX(1). */
2fc8bdac 11104 inst.instruction = 0xf000e800;
0855e32b 11105 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11106 }
11107}
11108
c19d1205
ZW
11109static void
11110do_t_branch (void)
b99bd4ef 11111{
0110f2b8 11112 int opcode;
dfa9f0d5 11113 int cond;
2fe88214 11114 bfd_reloc_code_real_type reloc;
dfa9f0d5 11115
e07e6e58
NC
11116 cond = inst.cond;
11117 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11118
11119 if (in_it_block ())
dfa9f0d5
PB
11120 {
11121 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11122 branches. */
dfa9f0d5 11123 cond = COND_ALWAYS;
dfa9f0d5
PB
11124 }
11125 else
11126 cond = inst.cond;
11127
11128 if (cond != COND_ALWAYS)
0110f2b8
PB
11129 opcode = T_MNEM_bcond;
11130 else
11131 opcode = inst.instruction;
11132
12d6b0b7
RS
11133 if (unified_syntax
11134 && (inst.size_req == 4
10960bfb
PB
11135 || (inst.size_req != 2
11136 && (inst.operands[0].hasreloc
11137 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11138 {
0110f2b8 11139 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11140 if (cond == COND_ALWAYS)
9ae92b05 11141 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11142 else
11143 {
ff8646ee
TP
11144 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11145 _("selected architecture does not support "
11146 "wide conditional branch instruction"));
11147
9c2799c2 11148 gas_assert (cond != 0xF);
dfa9f0d5 11149 inst.instruction |= cond << 22;
9ae92b05 11150 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11151 }
11152 }
b99bd4ef
NC
11153 else
11154 {
0110f2b8 11155 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11156 if (cond == COND_ALWAYS)
9ae92b05 11157 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11158 else
b99bd4ef 11159 {
dfa9f0d5 11160 inst.instruction |= cond << 8;
9ae92b05 11161 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11162 }
0110f2b8
PB
11163 /* Allow section relaxation. */
11164 if (unified_syntax && inst.size_req != 2)
11165 inst.relax = opcode;
b99bd4ef 11166 }
9ae92b05 11167 inst.reloc.type = reloc;
c19d1205 11168 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11169}
11170
8884b720 11171/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11172 between the two is the maximum immediate allowed - which is passed in
8884b720 11173 RANGE. */
b99bd4ef 11174static void
8884b720 11175do_t_bkpt_hlt1 (int range)
b99bd4ef 11176{
dfa9f0d5
PB
11177 constraint (inst.cond != COND_ALWAYS,
11178 _("instruction is always unconditional"));
c19d1205 11179 if (inst.operands[0].present)
b99bd4ef 11180 {
8884b720 11181 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11182 _("immediate value out of range"));
11183 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11184 }
8884b720
MGD
11185
11186 set_it_insn_type (NEUTRAL_IT_INSN);
11187}
11188
11189static void
11190do_t_hlt (void)
11191{
11192 do_t_bkpt_hlt1 (63);
11193}
11194
11195static void
11196do_t_bkpt (void)
11197{
11198 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11199}
11200
11201static void
c19d1205 11202do_t_branch23 (void)
b99bd4ef 11203{
e07e6e58 11204 set_it_insn_type_last ();
0855e32b 11205 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11206
0855e32b
NS
11207 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11208 this file. We used to simply ignore the PLT reloc type here --
11209 the branch encoding is now needed to deal with TLSCALL relocs.
11210 So if we see a PLT reloc now, put it back to how it used to be to
11211 keep the preexisting behaviour. */
11212 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11213 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11214
4343666d 11215#if defined(OBJ_COFF)
c19d1205
ZW
11216 /* If the destination of the branch is a defined symbol which does not have
11217 the THUMB_FUNC attribute, then we must be calling a function which has
11218 the (interfacearm) attribute. We look for the Thumb entry point to that
11219 function and change the branch to refer to that function instead. */
11220 if ( inst.reloc.exp.X_op == O_symbol
11221 && inst.reloc.exp.X_add_symbol != NULL
11222 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11223 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11224 inst.reloc.exp.X_add_symbol =
11225 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11226#endif
90e4755a
RE
11227}
11228
11229static void
c19d1205 11230do_t_bx (void)
90e4755a 11231{
e07e6e58 11232 set_it_insn_type_last ();
c19d1205
ZW
11233 inst.instruction |= inst.operands[0].reg << 3;
11234 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11235 should cause the alignment to be checked once it is known. This is
11236 because BX PC only works if the instruction is word aligned. */
11237}
90e4755a 11238
c19d1205
ZW
11239static void
11240do_t_bxj (void)
11241{
fdfde340 11242 int Rm;
90e4755a 11243
e07e6e58 11244 set_it_insn_type_last ();
fdfde340
JM
11245 Rm = inst.operands[0].reg;
11246 reject_bad_reg (Rm);
11247 inst.instruction |= Rm << 16;
90e4755a
RE
11248}
11249
11250static void
c19d1205 11251do_t_clz (void)
90e4755a 11252{
fdfde340
JM
11253 unsigned Rd;
11254 unsigned Rm;
11255
11256 Rd = inst.operands[0].reg;
11257 Rm = inst.operands[1].reg;
11258
11259 reject_bad_reg (Rd);
11260 reject_bad_reg (Rm);
11261
11262 inst.instruction |= Rd << 8;
11263 inst.instruction |= Rm << 16;
11264 inst.instruction |= Rm;
c19d1205 11265}
90e4755a 11266
dfa9f0d5
PB
11267static void
11268do_t_cps (void)
11269{
e07e6e58 11270 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11271 inst.instruction |= inst.operands[0].imm;
11272}
11273
c19d1205
ZW
11274static void
11275do_t_cpsi (void)
11276{
e07e6e58 11277 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11278 if (unified_syntax
62b3e311
PB
11279 && (inst.operands[1].present || inst.size_req == 4)
11280 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11281 {
c19d1205
ZW
11282 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11283 inst.instruction = 0xf3af8000;
11284 inst.instruction |= imod << 9;
11285 inst.instruction |= inst.operands[0].imm << 5;
11286 if (inst.operands[1].present)
11287 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11288 }
c19d1205 11289 else
90e4755a 11290 {
62b3e311
PB
11291 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11292 && (inst.operands[0].imm & 4),
11293 _("selected processor does not support 'A' form "
11294 "of this instruction"));
11295 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11296 _("Thumb does not support the 2-argument "
11297 "form of this instruction"));
11298 inst.instruction |= inst.operands[0].imm;
90e4755a 11299 }
90e4755a
RE
11300}
11301
c19d1205
ZW
11302/* THUMB CPY instruction (argument parse). */
11303
90e4755a 11304static void
c19d1205 11305do_t_cpy (void)
90e4755a 11306{
c19d1205 11307 if (inst.size_req == 4)
90e4755a 11308 {
c19d1205
ZW
11309 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11310 inst.instruction |= inst.operands[0].reg << 8;
11311 inst.instruction |= inst.operands[1].reg;
90e4755a 11312 }
c19d1205 11313 else
90e4755a 11314 {
c19d1205
ZW
11315 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11316 inst.instruction |= (inst.operands[0].reg & 0x7);
11317 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11318 }
90e4755a
RE
11319}
11320
90e4755a 11321static void
25fe350b 11322do_t_cbz (void)
90e4755a 11323{
e07e6e58 11324 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11325 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11326 inst.instruction |= inst.operands[0].reg;
11327 inst.reloc.pc_rel = 1;
11328 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11329}
90e4755a 11330
62b3e311
PB
11331static void
11332do_t_dbg (void)
11333{
11334 inst.instruction |= inst.operands[0].imm;
11335}
11336
11337static void
11338do_t_div (void)
11339{
fdfde340
JM
11340 unsigned Rd, Rn, Rm;
11341
11342 Rd = inst.operands[0].reg;
11343 Rn = (inst.operands[1].present
11344 ? inst.operands[1].reg : Rd);
11345 Rm = inst.operands[2].reg;
11346
11347 reject_bad_reg (Rd);
11348 reject_bad_reg (Rn);
11349 reject_bad_reg (Rm);
11350
11351 inst.instruction |= Rd << 8;
11352 inst.instruction |= Rn << 16;
11353 inst.instruction |= Rm;
62b3e311
PB
11354}
11355
c19d1205
ZW
11356static void
11357do_t_hint (void)
11358{
11359 if (unified_syntax && inst.size_req == 4)
11360 inst.instruction = THUMB_OP32 (inst.instruction);
11361 else
11362 inst.instruction = THUMB_OP16 (inst.instruction);
11363}
90e4755a 11364
c19d1205
ZW
11365static void
11366do_t_it (void)
11367{
11368 unsigned int cond = inst.operands[0].imm;
e27ec89e 11369
e07e6e58
NC
11370 set_it_insn_type (IT_INSN);
11371 now_it.mask = (inst.instruction & 0xf) | 0x10;
11372 now_it.cc = cond;
5a01bb1d 11373 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11374
11375 /* If the condition is a negative condition, invert the mask. */
c19d1205 11376 if ((cond & 0x1) == 0x0)
90e4755a 11377 {
c19d1205 11378 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11379
c19d1205 11380 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11381 {
11382 /* No conversion needed. */
11383 now_it.block_length = 1;
11384 }
c19d1205 11385 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11386 {
11387 mask ^= 0x8;
11388 now_it.block_length = 2;
11389 }
e27ec89e 11390 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11391 {
11392 mask ^= 0xC;
11393 now_it.block_length = 3;
11394 }
c19d1205 11395 else
5a01bb1d
MGD
11396 {
11397 mask ^= 0xE;
11398 now_it.block_length = 4;
11399 }
90e4755a 11400
e27ec89e
PB
11401 inst.instruction &= 0xfff0;
11402 inst.instruction |= mask;
c19d1205 11403 }
90e4755a 11404
c19d1205
ZW
11405 inst.instruction |= cond << 4;
11406}
90e4755a 11407
3c707909
PB
11408/* Helper function used for both push/pop and ldm/stm. */
11409static void
11410encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11411{
11412 bfd_boolean load;
11413
11414 load = (inst.instruction & (1 << 20)) != 0;
11415
11416 if (mask & (1 << 13))
11417 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11418
11419 if ((mask & (1 << base)) != 0
11420 && writeback)
11421 inst.error = _("having the base register in the register list when "
11422 "using write back is UNPREDICTABLE");
11423
3c707909
PB
11424 if (load)
11425 {
e07e6e58 11426 if (mask & (1 << 15))
477330fc
RM
11427 {
11428 if (mask & (1 << 14))
11429 inst.error = _("LR and PC should not both be in register list");
11430 else
11431 set_it_insn_type_last ();
11432 }
3c707909
PB
11433 }
11434 else
11435 {
11436 if (mask & (1 << 15))
11437 inst.error = _("PC not allowed in register list");
3c707909
PB
11438 }
11439
11440 if ((mask & (mask - 1)) == 0)
11441 {
11442 /* Single register transfers implemented as str/ldr. */
11443 if (writeback)
11444 {
11445 if (inst.instruction & (1 << 23))
11446 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11447 else
11448 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11449 }
11450 else
11451 {
11452 if (inst.instruction & (1 << 23))
11453 inst.instruction = 0x00800000; /* ia -> [base] */
11454 else
11455 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11456 }
11457
11458 inst.instruction |= 0xf8400000;
11459 if (load)
11460 inst.instruction |= 0x00100000;
11461
5f4273c7 11462 mask = ffs (mask) - 1;
3c707909
PB
11463 mask <<= 12;
11464 }
11465 else if (writeback)
11466 inst.instruction |= WRITE_BACK;
11467
11468 inst.instruction |= mask;
11469 inst.instruction |= base << 16;
11470}
11471
c19d1205
ZW
11472static void
11473do_t_ldmstm (void)
11474{
11475 /* This really doesn't seem worth it. */
11476 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11477 _("expression too complex"));
11478 constraint (inst.operands[1].writeback,
11479 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11480
c19d1205
ZW
11481 if (unified_syntax)
11482 {
3c707909
PB
11483 bfd_boolean narrow;
11484 unsigned mask;
11485
11486 narrow = FALSE;
c19d1205
ZW
11487 /* See if we can use a 16-bit instruction. */
11488 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11489 && inst.size_req != 4
3c707909 11490 && !(inst.operands[1].imm & ~0xff))
90e4755a 11491 {
3c707909 11492 mask = 1 << inst.operands[0].reg;
90e4755a 11493
eab4f823 11494 if (inst.operands[0].reg <= 7)
90e4755a 11495 {
3c707909 11496 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11497 ? inst.operands[0].writeback
11498 : (inst.operands[0].writeback
11499 == !(inst.operands[1].imm & mask)))
477330fc 11500 {
eab4f823
MGD
11501 if (inst.instruction == T_MNEM_stmia
11502 && (inst.operands[1].imm & mask)
11503 && (inst.operands[1].imm & (mask - 1)))
11504 as_warn (_("value stored for r%d is UNKNOWN"),
11505 inst.operands[0].reg);
3c707909 11506
eab4f823
MGD
11507 inst.instruction = THUMB_OP16 (inst.instruction);
11508 inst.instruction |= inst.operands[0].reg << 8;
11509 inst.instruction |= inst.operands[1].imm;
11510 narrow = TRUE;
11511 }
11512 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11513 {
11514 /* This means 1 register in reg list one of 3 situations:
11515 1. Instruction is stmia, but without writeback.
11516 2. lmdia without writeback, but with Rn not in
477330fc 11517 reglist.
eab4f823
MGD
11518 3. ldmia with writeback, but with Rn in reglist.
11519 Case 3 is UNPREDICTABLE behaviour, so we handle
11520 case 1 and 2 which can be converted into a 16-bit
11521 str or ldr. The SP cases are handled below. */
11522 unsigned long opcode;
11523 /* First, record an error for Case 3. */
11524 if (inst.operands[1].imm & mask
11525 && inst.operands[0].writeback)
fa94de6b 11526 inst.error =
eab4f823
MGD
11527 _("having the base register in the register list when "
11528 "using write back is UNPREDICTABLE");
fa94de6b
RM
11529
11530 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11531 : T_MNEM_ldr);
11532 inst.instruction = THUMB_OP16 (opcode);
11533 inst.instruction |= inst.operands[0].reg << 3;
11534 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11535 narrow = TRUE;
11536 }
90e4755a 11537 }
eab4f823 11538 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11539 {
eab4f823
MGD
11540 if (inst.operands[0].writeback)
11541 {
fa94de6b 11542 inst.instruction =
eab4f823 11543 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11544 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11545 inst.instruction |= inst.operands[1].imm;
477330fc 11546 narrow = TRUE;
eab4f823
MGD
11547 }
11548 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11549 {
fa94de6b 11550 inst.instruction =
eab4f823 11551 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11552 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11553 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11554 narrow = TRUE;
eab4f823 11555 }
90e4755a 11556 }
3c707909
PB
11557 }
11558
11559 if (!narrow)
11560 {
c19d1205
ZW
11561 if (inst.instruction < 0xffff)
11562 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11563
5f4273c7
NC
11564 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11565 inst.operands[0].writeback);
90e4755a
RE
11566 }
11567 }
c19d1205 11568 else
90e4755a 11569 {
c19d1205
ZW
11570 constraint (inst.operands[0].reg > 7
11571 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11572 constraint (inst.instruction != T_MNEM_ldmia
11573 && inst.instruction != T_MNEM_stmia,
11574 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11575 if (inst.instruction == T_MNEM_stmia)
f03698e6 11576 {
c19d1205
ZW
11577 if (!inst.operands[0].writeback)
11578 as_warn (_("this instruction will write back the base register"));
11579 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11580 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11581 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11582 inst.operands[0].reg);
f03698e6 11583 }
c19d1205 11584 else
90e4755a 11585 {
c19d1205
ZW
11586 if (!inst.operands[0].writeback
11587 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11588 as_warn (_("this instruction will write back the base register"));
11589 else if (inst.operands[0].writeback
11590 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11591 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11592 }
11593
c19d1205
ZW
11594 inst.instruction = THUMB_OP16 (inst.instruction);
11595 inst.instruction |= inst.operands[0].reg << 8;
11596 inst.instruction |= inst.operands[1].imm;
11597 }
11598}
e28cd48c 11599
c19d1205
ZW
11600static void
11601do_t_ldrex (void)
11602{
11603 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11604 || inst.operands[1].postind || inst.operands[1].writeback
11605 || inst.operands[1].immisreg || inst.operands[1].shifted
11606 || inst.operands[1].negative,
01cfc07f 11607 BAD_ADDR_MODE);
e28cd48c 11608
5be8be5d
DG
11609 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11610
c19d1205
ZW
11611 inst.instruction |= inst.operands[0].reg << 12;
11612 inst.instruction |= inst.operands[1].reg << 16;
11613 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11614}
e28cd48c 11615
c19d1205
ZW
11616static void
11617do_t_ldrexd (void)
11618{
11619 if (!inst.operands[1].present)
1cac9012 11620 {
c19d1205
ZW
11621 constraint (inst.operands[0].reg == REG_LR,
11622 _("r14 not allowed as first register "
11623 "when second register is omitted"));
11624 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11625 }
c19d1205
ZW
11626 constraint (inst.operands[0].reg == inst.operands[1].reg,
11627 BAD_OVERLAP);
b99bd4ef 11628
c19d1205
ZW
11629 inst.instruction |= inst.operands[0].reg << 12;
11630 inst.instruction |= inst.operands[1].reg << 8;
11631 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11632}
11633
11634static void
c19d1205 11635do_t_ldst (void)
b99bd4ef 11636{
0110f2b8
PB
11637 unsigned long opcode;
11638 int Rn;
11639
e07e6e58
NC
11640 if (inst.operands[0].isreg
11641 && !inst.operands[0].preind
11642 && inst.operands[0].reg == REG_PC)
11643 set_it_insn_type_last ();
11644
0110f2b8 11645 opcode = inst.instruction;
c19d1205 11646 if (unified_syntax)
b99bd4ef 11647 {
53365c0d
PB
11648 if (!inst.operands[1].isreg)
11649 {
11650 if (opcode <= 0xffff)
11651 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11652 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11653 return;
11654 }
0110f2b8
PB
11655 if (inst.operands[1].isreg
11656 && !inst.operands[1].writeback
c19d1205
ZW
11657 && !inst.operands[1].shifted && !inst.operands[1].postind
11658 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11659 && opcode <= 0xffff
11660 && inst.size_req != 4)
c19d1205 11661 {
0110f2b8
PB
11662 /* Insn may have a 16-bit form. */
11663 Rn = inst.operands[1].reg;
11664 if (inst.operands[1].immisreg)
11665 {
11666 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11667 /* [Rn, Rik] */
0110f2b8
PB
11668 if (Rn <= 7 && inst.operands[1].imm <= 7)
11669 goto op16;
5be8be5d
DG
11670 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11671 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11672 }
11673 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11674 && opcode != T_MNEM_ldrsb)
11675 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11676 || (Rn == REG_SP && opcode == T_MNEM_str))
11677 {
11678 /* [Rn, #const] */
11679 if (Rn > 7)
11680 {
11681 if (Rn == REG_PC)
11682 {
11683 if (inst.reloc.pc_rel)
11684 opcode = T_MNEM_ldr_pc2;
11685 else
11686 opcode = T_MNEM_ldr_pc;
11687 }
11688 else
11689 {
11690 if (opcode == T_MNEM_ldr)
11691 opcode = T_MNEM_ldr_sp;
11692 else
11693 opcode = T_MNEM_str_sp;
11694 }
11695 inst.instruction = inst.operands[0].reg << 8;
11696 }
11697 else
11698 {
11699 inst.instruction = inst.operands[0].reg;
11700 inst.instruction |= inst.operands[1].reg << 3;
11701 }
11702 inst.instruction |= THUMB_OP16 (opcode);
11703 if (inst.size_req == 2)
11704 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11705 else
11706 inst.relax = opcode;
11707 return;
11708 }
c19d1205 11709 }
0110f2b8 11710 /* Definitely a 32-bit variant. */
5be8be5d 11711
8d67f500
NC
11712 /* Warning for Erratum 752419. */
11713 if (opcode == T_MNEM_ldr
11714 && inst.operands[0].reg == REG_SP
11715 && inst.operands[1].writeback == 1
11716 && !inst.operands[1].immisreg)
11717 {
11718 if (no_cpu_selected ()
11719 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11720 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11721 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11722 as_warn (_("This instruction may be unpredictable "
11723 "if executed on M-profile cores "
11724 "with interrupts enabled."));
11725 }
11726
5be8be5d 11727 /* Do some validations regarding addressing modes. */
1be5fd2e 11728 if (inst.operands[1].immisreg)
5be8be5d
DG
11729 reject_bad_reg (inst.operands[1].imm);
11730
1be5fd2e
NC
11731 constraint (inst.operands[1].writeback == 1
11732 && inst.operands[0].reg == inst.operands[1].reg,
11733 BAD_OVERLAP);
11734
0110f2b8 11735 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11736 inst.instruction |= inst.operands[0].reg << 12;
11737 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11738 check_ldr_r15_aligned ();
b99bd4ef
NC
11739 return;
11740 }
11741
c19d1205
ZW
11742 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11743
11744 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11745 {
c19d1205
ZW
11746 /* Only [Rn,Rm] is acceptable. */
11747 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11748 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11749 || inst.operands[1].postind || inst.operands[1].shifted
11750 || inst.operands[1].negative,
11751 _("Thumb does not support this addressing mode"));
11752 inst.instruction = THUMB_OP16 (inst.instruction);
11753 goto op16;
b99bd4ef 11754 }
5f4273c7 11755
c19d1205
ZW
11756 inst.instruction = THUMB_OP16 (inst.instruction);
11757 if (!inst.operands[1].isreg)
8335d6aa 11758 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11759 return;
b99bd4ef 11760
c19d1205
ZW
11761 constraint (!inst.operands[1].preind
11762 || inst.operands[1].shifted
11763 || inst.operands[1].writeback,
11764 _("Thumb does not support this addressing mode"));
11765 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11766 {
c19d1205
ZW
11767 constraint (inst.instruction & 0x0600,
11768 _("byte or halfword not valid for base register"));
11769 constraint (inst.operands[1].reg == REG_PC
11770 && !(inst.instruction & THUMB_LOAD_BIT),
11771 _("r15 based store not allowed"));
11772 constraint (inst.operands[1].immisreg,
11773 _("invalid base register for register offset"));
b99bd4ef 11774
c19d1205
ZW
11775 if (inst.operands[1].reg == REG_PC)
11776 inst.instruction = T_OPCODE_LDR_PC;
11777 else if (inst.instruction & THUMB_LOAD_BIT)
11778 inst.instruction = T_OPCODE_LDR_SP;
11779 else
11780 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11781
c19d1205
ZW
11782 inst.instruction |= inst.operands[0].reg << 8;
11783 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11784 return;
11785 }
90e4755a 11786
c19d1205
ZW
11787 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11788 if (!inst.operands[1].immisreg)
11789 {
11790 /* Immediate offset. */
11791 inst.instruction |= inst.operands[0].reg;
11792 inst.instruction |= inst.operands[1].reg << 3;
11793 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11794 return;
11795 }
90e4755a 11796
c19d1205
ZW
11797 /* Register offset. */
11798 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11799 constraint (inst.operands[1].negative,
11800 _("Thumb does not support this addressing mode"));
90e4755a 11801
c19d1205
ZW
11802 op16:
11803 switch (inst.instruction)
11804 {
11805 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11806 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11807 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11808 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11809 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11810 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11811 case 0x5600 /* ldrsb */:
11812 case 0x5e00 /* ldrsh */: break;
11813 default: abort ();
11814 }
90e4755a 11815
c19d1205
ZW
11816 inst.instruction |= inst.operands[0].reg;
11817 inst.instruction |= inst.operands[1].reg << 3;
11818 inst.instruction |= inst.operands[1].imm << 6;
11819}
90e4755a 11820
c19d1205
ZW
11821static void
11822do_t_ldstd (void)
11823{
11824 if (!inst.operands[1].present)
b99bd4ef 11825 {
c19d1205
ZW
11826 inst.operands[1].reg = inst.operands[0].reg + 1;
11827 constraint (inst.operands[0].reg == REG_LR,
11828 _("r14 not allowed here"));
bd340a04 11829 constraint (inst.operands[0].reg == REG_R12,
477330fc 11830 _("r12 not allowed here"));
b99bd4ef 11831 }
bd340a04
MGD
11832
11833 if (inst.operands[2].writeback
11834 && (inst.operands[0].reg == inst.operands[2].reg
11835 || inst.operands[1].reg == inst.operands[2].reg))
11836 as_warn (_("base register written back, and overlaps "
477330fc 11837 "one of transfer registers"));
bd340a04 11838
c19d1205
ZW
11839 inst.instruction |= inst.operands[0].reg << 12;
11840 inst.instruction |= inst.operands[1].reg << 8;
11841 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11842}
11843
c19d1205
ZW
11844static void
11845do_t_ldstt (void)
11846{
11847 inst.instruction |= inst.operands[0].reg << 12;
11848 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11849}
a737bd4d 11850
b99bd4ef 11851static void
c19d1205 11852do_t_mla (void)
b99bd4ef 11853{
fdfde340 11854 unsigned Rd, Rn, Rm, Ra;
c921be7d 11855
fdfde340
JM
11856 Rd = inst.operands[0].reg;
11857 Rn = inst.operands[1].reg;
11858 Rm = inst.operands[2].reg;
11859 Ra = inst.operands[3].reg;
11860
11861 reject_bad_reg (Rd);
11862 reject_bad_reg (Rn);
11863 reject_bad_reg (Rm);
11864 reject_bad_reg (Ra);
11865
11866 inst.instruction |= Rd << 8;
11867 inst.instruction |= Rn << 16;
11868 inst.instruction |= Rm;
11869 inst.instruction |= Ra << 12;
c19d1205 11870}
b99bd4ef 11871
c19d1205
ZW
11872static void
11873do_t_mlal (void)
11874{
fdfde340
JM
11875 unsigned RdLo, RdHi, Rn, Rm;
11876
11877 RdLo = inst.operands[0].reg;
11878 RdHi = inst.operands[1].reg;
11879 Rn = inst.operands[2].reg;
11880 Rm = inst.operands[3].reg;
11881
11882 reject_bad_reg (RdLo);
11883 reject_bad_reg (RdHi);
11884 reject_bad_reg (Rn);
11885 reject_bad_reg (Rm);
11886
11887 inst.instruction |= RdLo << 12;
11888 inst.instruction |= RdHi << 8;
11889 inst.instruction |= Rn << 16;
11890 inst.instruction |= Rm;
c19d1205 11891}
b99bd4ef 11892
c19d1205
ZW
11893static void
11894do_t_mov_cmp (void)
11895{
fdfde340
JM
11896 unsigned Rn, Rm;
11897
11898 Rn = inst.operands[0].reg;
11899 Rm = inst.operands[1].reg;
11900
e07e6e58
NC
11901 if (Rn == REG_PC)
11902 set_it_insn_type_last ();
11903
c19d1205 11904 if (unified_syntax)
b99bd4ef 11905 {
c19d1205
ZW
11906 int r0off = (inst.instruction == T_MNEM_mov
11907 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11908 unsigned long opcode;
3d388997
PB
11909 bfd_boolean narrow;
11910 bfd_boolean low_regs;
11911
fdfde340 11912 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11913 opcode = inst.instruction;
e07e6e58 11914 if (in_it_block ())
0110f2b8 11915 narrow = opcode != T_MNEM_movs;
3d388997 11916 else
0110f2b8 11917 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11918 if (inst.size_req == 4
11919 || inst.operands[1].shifted)
11920 narrow = FALSE;
11921
efd81785
PB
11922 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11923 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11924 && !inst.operands[1].shifted
fdfde340
JM
11925 && Rn == REG_PC
11926 && Rm == REG_LR)
efd81785
PB
11927 {
11928 inst.instruction = T2_SUBS_PC_LR;
11929 return;
11930 }
11931
fdfde340
JM
11932 if (opcode == T_MNEM_cmp)
11933 {
11934 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11935 if (narrow)
11936 {
11937 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11938 but valid. */
11939 warn_deprecated_sp (Rm);
11940 /* R15 was documented as a valid choice for Rm in ARMv6,
11941 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11942 tools reject R15, so we do too. */
11943 constraint (Rm == REG_PC, BAD_PC);
11944 }
11945 else
11946 reject_bad_reg (Rm);
fdfde340
JM
11947 }
11948 else if (opcode == T_MNEM_mov
11949 || opcode == T_MNEM_movs)
11950 {
11951 if (inst.operands[1].isreg)
11952 {
11953 if (opcode == T_MNEM_movs)
11954 {
11955 reject_bad_reg (Rn);
11956 reject_bad_reg (Rm);
11957 }
76fa04a4
MGD
11958 else if (narrow)
11959 {
11960 /* This is mov.n. */
11961 if ((Rn == REG_SP || Rn == REG_PC)
11962 && (Rm == REG_SP || Rm == REG_PC))
11963 {
5c3696f8 11964 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11965 "deprecated when r%u is the destination "
11966 "register."), Rm, Rn);
11967 }
11968 }
11969 else
11970 {
11971 /* This is mov.w. */
11972 constraint (Rn == REG_PC, BAD_PC);
11973 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
11974 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11975 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 11976 }
fdfde340
JM
11977 }
11978 else
11979 reject_bad_reg (Rn);
11980 }
11981
c19d1205
ZW
11982 if (!inst.operands[1].isreg)
11983 {
0110f2b8 11984 /* Immediate operand. */
e07e6e58 11985 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11986 narrow = 0;
11987 if (low_regs && narrow)
11988 {
11989 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11990 inst.instruction |= Rn << 8;
a9f02af8
MG
11991 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11992 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11993 {
a9f02af8 11994 if (inst.size_req == 2)
72d98d16 11995 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11996 else
11997 inst.relax = opcode;
72d98d16 11998 }
0110f2b8
PB
11999 }
12000 else
12001 {
a9f02af8
MG
12002 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12003 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
12004 THUMB1_RELOC_ONLY);
12005
0110f2b8
PB
12006 inst.instruction = THUMB_OP32 (inst.instruction);
12007 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12008 inst.instruction |= Rn << r0off;
0110f2b8
PB
12009 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12010 }
c19d1205 12011 }
728ca7c9
PB
12012 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12013 && (inst.instruction == T_MNEM_mov
12014 || inst.instruction == T_MNEM_movs))
12015 {
12016 /* Register shifts are encoded as separate shift instructions. */
12017 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12018
e07e6e58 12019 if (in_it_block ())
728ca7c9
PB
12020 narrow = !flags;
12021 else
12022 narrow = flags;
12023
12024 if (inst.size_req == 4)
12025 narrow = FALSE;
12026
12027 if (!low_regs || inst.operands[1].imm > 7)
12028 narrow = FALSE;
12029
fdfde340 12030 if (Rn != Rm)
728ca7c9
PB
12031 narrow = FALSE;
12032
12033 switch (inst.operands[1].shift_kind)
12034 {
12035 case SHIFT_LSL:
12036 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12037 break;
12038 case SHIFT_ASR:
12039 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12040 break;
12041 case SHIFT_LSR:
12042 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12043 break;
12044 case SHIFT_ROR:
12045 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12046 break;
12047 default:
5f4273c7 12048 abort ();
728ca7c9
PB
12049 }
12050
12051 inst.instruction = opcode;
12052 if (narrow)
12053 {
fdfde340 12054 inst.instruction |= Rn;
728ca7c9
PB
12055 inst.instruction |= inst.operands[1].imm << 3;
12056 }
12057 else
12058 {
12059 if (flags)
12060 inst.instruction |= CONDS_BIT;
12061
fdfde340
JM
12062 inst.instruction |= Rn << 8;
12063 inst.instruction |= Rm << 16;
728ca7c9
PB
12064 inst.instruction |= inst.operands[1].imm;
12065 }
12066 }
3d388997 12067 else if (!narrow)
c19d1205 12068 {
728ca7c9
PB
12069 /* Some mov with immediate shift have narrow variants.
12070 Register shifts are handled above. */
12071 if (low_regs && inst.operands[1].shifted
12072 && (inst.instruction == T_MNEM_mov
12073 || inst.instruction == T_MNEM_movs))
12074 {
e07e6e58 12075 if (in_it_block ())
728ca7c9
PB
12076 narrow = (inst.instruction == T_MNEM_mov);
12077 else
12078 narrow = (inst.instruction == T_MNEM_movs);
12079 }
12080
12081 if (narrow)
12082 {
12083 switch (inst.operands[1].shift_kind)
12084 {
12085 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12086 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12087 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12088 default: narrow = FALSE; break;
12089 }
12090 }
12091
12092 if (narrow)
12093 {
fdfde340
JM
12094 inst.instruction |= Rn;
12095 inst.instruction |= Rm << 3;
728ca7c9
PB
12096 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12097 }
12098 else
12099 {
12100 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12101 inst.instruction |= Rn << r0off;
728ca7c9
PB
12102 encode_thumb32_shifted_operand (1);
12103 }
c19d1205
ZW
12104 }
12105 else
12106 switch (inst.instruction)
12107 {
12108 case T_MNEM_mov:
837b3435 12109 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12110 results. Don't allow this. */
12111 if (low_regs)
12112 {
12113 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12114 "MOV Rd, Rs with two low registers is not "
12115 "permitted on this architecture");
fa94de6b 12116 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12117 arm_ext_v6);
12118 }
12119
c19d1205 12120 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12121 inst.instruction |= (Rn & 0x8) << 4;
12122 inst.instruction |= (Rn & 0x7);
12123 inst.instruction |= Rm << 3;
c19d1205 12124 break;
b99bd4ef 12125
c19d1205
ZW
12126 case T_MNEM_movs:
12127 /* We know we have low registers at this point.
941a8a52
MGD
12128 Generate LSLS Rd, Rs, #0. */
12129 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12130 inst.instruction |= Rn;
12131 inst.instruction |= Rm << 3;
c19d1205
ZW
12132 break;
12133
12134 case T_MNEM_cmp:
3d388997 12135 if (low_regs)
c19d1205
ZW
12136 {
12137 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12138 inst.instruction |= Rn;
12139 inst.instruction |= Rm << 3;
c19d1205
ZW
12140 }
12141 else
12142 {
12143 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12144 inst.instruction |= (Rn & 0x8) << 4;
12145 inst.instruction |= (Rn & 0x7);
12146 inst.instruction |= Rm << 3;
c19d1205
ZW
12147 }
12148 break;
12149 }
b99bd4ef
NC
12150 return;
12151 }
12152
c19d1205 12153 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12154
12155 /* PR 10443: Do not silently ignore shifted operands. */
12156 constraint (inst.operands[1].shifted,
12157 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12158
c19d1205 12159 if (inst.operands[1].isreg)
b99bd4ef 12160 {
fdfde340 12161 if (Rn < 8 && Rm < 8)
b99bd4ef 12162 {
c19d1205
ZW
12163 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12164 since a MOV instruction produces unpredictable results. */
12165 if (inst.instruction == T_OPCODE_MOV_I8)
12166 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12167 else
c19d1205 12168 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12169
fdfde340
JM
12170 inst.instruction |= Rn;
12171 inst.instruction |= Rm << 3;
b99bd4ef
NC
12172 }
12173 else
12174 {
c19d1205
ZW
12175 if (inst.instruction == T_OPCODE_MOV_I8)
12176 inst.instruction = T_OPCODE_MOV_HR;
12177 else
12178 inst.instruction = T_OPCODE_CMP_HR;
12179 do_t_cpy ();
b99bd4ef
NC
12180 }
12181 }
c19d1205 12182 else
b99bd4ef 12183 {
fdfde340 12184 constraint (Rn > 7,
c19d1205 12185 _("only lo regs allowed with immediate"));
fdfde340 12186 inst.instruction |= Rn << 8;
c19d1205
ZW
12187 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12188 }
12189}
b99bd4ef 12190
c19d1205
ZW
12191static void
12192do_t_mov16 (void)
12193{
fdfde340 12194 unsigned Rd;
b6895b4f
PB
12195 bfd_vma imm;
12196 bfd_boolean top;
12197
12198 top = (inst.instruction & 0x00800000) != 0;
12199 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12200 {
33eaf5de 12201 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12202 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12203 }
12204 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12205 {
33eaf5de 12206 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12207 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12208 }
12209
fdfde340
JM
12210 Rd = inst.operands[0].reg;
12211 reject_bad_reg (Rd);
12212
12213 inst.instruction |= Rd << 8;
b6895b4f
PB
12214 if (inst.reloc.type == BFD_RELOC_UNUSED)
12215 {
12216 imm = inst.reloc.exp.X_add_number;
12217 inst.instruction |= (imm & 0xf000) << 4;
12218 inst.instruction |= (imm & 0x0800) << 15;
12219 inst.instruction |= (imm & 0x0700) << 4;
12220 inst.instruction |= (imm & 0x00ff);
12221 }
c19d1205 12222}
b99bd4ef 12223
c19d1205
ZW
12224static void
12225do_t_mvn_tst (void)
12226{
fdfde340 12227 unsigned Rn, Rm;
c921be7d 12228
fdfde340
JM
12229 Rn = inst.operands[0].reg;
12230 Rm = inst.operands[1].reg;
12231
12232 if (inst.instruction == T_MNEM_cmp
12233 || inst.instruction == T_MNEM_cmn)
12234 constraint (Rn == REG_PC, BAD_PC);
12235 else
12236 reject_bad_reg (Rn);
12237 reject_bad_reg (Rm);
12238
c19d1205
ZW
12239 if (unified_syntax)
12240 {
12241 int r0off = (inst.instruction == T_MNEM_mvn
12242 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12243 bfd_boolean narrow;
12244
12245 if (inst.size_req == 4
12246 || inst.instruction > 0xffff
12247 || inst.operands[1].shifted
fdfde340 12248 || Rn > 7 || Rm > 7)
3d388997 12249 narrow = FALSE;
fe8b4cc3
KT
12250 else if (inst.instruction == T_MNEM_cmn
12251 || inst.instruction == T_MNEM_tst)
3d388997
PB
12252 narrow = TRUE;
12253 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12254 narrow = !in_it_block ();
3d388997 12255 else
e07e6e58 12256 narrow = in_it_block ();
3d388997 12257
c19d1205 12258 if (!inst.operands[1].isreg)
b99bd4ef 12259 {
c19d1205
ZW
12260 /* For an immediate, we always generate a 32-bit opcode;
12261 section relaxation will shrink it later if possible. */
12262 if (inst.instruction < 0xffff)
12263 inst.instruction = THUMB_OP32 (inst.instruction);
12264 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12265 inst.instruction |= Rn << r0off;
c19d1205 12266 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12267 }
c19d1205 12268 else
b99bd4ef 12269 {
c19d1205 12270 /* See if we can do this with a 16-bit instruction. */
3d388997 12271 if (narrow)
b99bd4ef 12272 {
c19d1205 12273 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12274 inst.instruction |= Rn;
12275 inst.instruction |= Rm << 3;
b99bd4ef 12276 }
c19d1205 12277 else
b99bd4ef 12278 {
c19d1205
ZW
12279 constraint (inst.operands[1].shifted
12280 && inst.operands[1].immisreg,
12281 _("shift must be constant"));
12282 if (inst.instruction < 0xffff)
12283 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12284 inst.instruction |= Rn << r0off;
c19d1205 12285 encode_thumb32_shifted_operand (1);
b99bd4ef 12286 }
b99bd4ef
NC
12287 }
12288 }
12289 else
12290 {
c19d1205
ZW
12291 constraint (inst.instruction > 0xffff
12292 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12293 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12294 _("unshifted register required"));
fdfde340 12295 constraint (Rn > 7 || Rm > 7,
c19d1205 12296 BAD_HIREG);
b99bd4ef 12297
c19d1205 12298 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12299 inst.instruction |= Rn;
12300 inst.instruction |= Rm << 3;
b99bd4ef 12301 }
b99bd4ef
NC
12302}
12303
b05fe5cf 12304static void
c19d1205 12305do_t_mrs (void)
b05fe5cf 12306{
fdfde340 12307 unsigned Rd;
037e8744
JB
12308
12309 if (do_vfp_nsyn_mrs () == SUCCESS)
12310 return;
12311
90ec0d68
MGD
12312 Rd = inst.operands[0].reg;
12313 reject_bad_reg (Rd);
12314 inst.instruction |= Rd << 8;
12315
12316 if (inst.operands[1].isreg)
62b3e311 12317 {
90ec0d68
MGD
12318 unsigned br = inst.operands[1].reg;
12319 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12320 as_bad (_("bad register for mrs"));
12321
12322 inst.instruction |= br & (0xf << 16);
12323 inst.instruction |= (br & 0x300) >> 4;
12324 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12325 }
12326 else
12327 {
90ec0d68 12328 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12329
d2cd1205 12330 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12331 {
12332 /* PR gas/12698: The constraint is only applied for m_profile.
12333 If the user has specified -march=all, we want to ignore it as
12334 we are building for any CPU type, including non-m variants. */
823d2571
TG
12335 bfd_boolean m_profile =
12336 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12337 constraint ((flags != 0) && m_profile, _("selected processor does "
12338 "not support requested special purpose register"));
12339 }
90ec0d68 12340 else
d2cd1205
JB
12341 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12342 devices). */
12343 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12344 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12345
90ec0d68
MGD
12346 inst.instruction |= (flags & SPSR_BIT) >> 2;
12347 inst.instruction |= inst.operands[1].imm & 0xff;
12348 inst.instruction |= 0xf0000;
12349 }
c19d1205 12350}
b05fe5cf 12351
c19d1205
ZW
12352static void
12353do_t_msr (void)
12354{
62b3e311 12355 int flags;
fdfde340 12356 unsigned Rn;
62b3e311 12357
037e8744
JB
12358 if (do_vfp_nsyn_msr () == SUCCESS)
12359 return;
12360
c19d1205
ZW
12361 constraint (!inst.operands[1].isreg,
12362 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12363
12364 if (inst.operands[0].isreg)
12365 flags = (int)(inst.operands[0].reg);
12366 else
12367 flags = inst.operands[0].imm;
12368
d2cd1205 12369 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12370 {
d2cd1205
JB
12371 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12372
1a43faaf 12373 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12374 If the user has specified -march=all, we want to ignore it as
12375 we are building for any CPU type, including non-m variants. */
823d2571
TG
12376 bfd_boolean m_profile =
12377 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12378 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12379 && (bits & ~(PSR_s | PSR_f)) != 0)
12380 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12381 && bits != PSR_f)) && m_profile,
12382 _("selected processor does not support requested special "
12383 "purpose register"));
62b3e311
PB
12384 }
12385 else
d2cd1205
JB
12386 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12387 "requested special purpose register"));
c921be7d 12388
fdfde340
JM
12389 Rn = inst.operands[1].reg;
12390 reject_bad_reg (Rn);
12391
62b3e311 12392 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12393 inst.instruction |= (flags & 0xf0000) >> 8;
12394 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12395 inst.instruction |= (flags & 0xff);
fdfde340 12396 inst.instruction |= Rn << 16;
c19d1205 12397}
b05fe5cf 12398
c19d1205
ZW
12399static void
12400do_t_mul (void)
12401{
17828f45 12402 bfd_boolean narrow;
fdfde340 12403 unsigned Rd, Rn, Rm;
17828f45 12404
c19d1205
ZW
12405 if (!inst.operands[2].present)
12406 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12407
fdfde340
JM
12408 Rd = inst.operands[0].reg;
12409 Rn = inst.operands[1].reg;
12410 Rm = inst.operands[2].reg;
12411
17828f45 12412 if (unified_syntax)
b05fe5cf 12413 {
17828f45 12414 if (inst.size_req == 4
fdfde340
JM
12415 || (Rd != Rn
12416 && Rd != Rm)
12417 || Rn > 7
12418 || Rm > 7)
17828f45
JM
12419 narrow = FALSE;
12420 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12421 narrow = !in_it_block ();
17828f45 12422 else
e07e6e58 12423 narrow = in_it_block ();
b05fe5cf 12424 }
c19d1205 12425 else
b05fe5cf 12426 {
17828f45 12427 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12428 constraint (Rn > 7 || Rm > 7,
c19d1205 12429 BAD_HIREG);
17828f45
JM
12430 narrow = TRUE;
12431 }
b05fe5cf 12432
17828f45
JM
12433 if (narrow)
12434 {
12435 /* 16-bit MULS/Conditional MUL. */
c19d1205 12436 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12437 inst.instruction |= Rd;
b05fe5cf 12438
fdfde340
JM
12439 if (Rd == Rn)
12440 inst.instruction |= Rm << 3;
12441 else if (Rd == Rm)
12442 inst.instruction |= Rn << 3;
c19d1205
ZW
12443 else
12444 constraint (1, _("dest must overlap one source register"));
12445 }
17828f45
JM
12446 else
12447 {
e07e6e58
NC
12448 constraint (inst.instruction != T_MNEM_mul,
12449 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12450 /* 32-bit MUL. */
12451 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12452 inst.instruction |= Rd << 8;
12453 inst.instruction |= Rn << 16;
12454 inst.instruction |= Rm << 0;
12455
12456 reject_bad_reg (Rd);
12457 reject_bad_reg (Rn);
12458 reject_bad_reg (Rm);
17828f45 12459 }
c19d1205 12460}
b05fe5cf 12461
c19d1205
ZW
12462static void
12463do_t_mull (void)
12464{
fdfde340 12465 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12466
fdfde340
JM
12467 RdLo = inst.operands[0].reg;
12468 RdHi = inst.operands[1].reg;
12469 Rn = inst.operands[2].reg;
12470 Rm = inst.operands[3].reg;
12471
12472 reject_bad_reg (RdLo);
12473 reject_bad_reg (RdHi);
12474 reject_bad_reg (Rn);
12475 reject_bad_reg (Rm);
12476
12477 inst.instruction |= RdLo << 12;
12478 inst.instruction |= RdHi << 8;
12479 inst.instruction |= Rn << 16;
12480 inst.instruction |= Rm;
12481
12482 if (RdLo == RdHi)
c19d1205
ZW
12483 as_tsktsk (_("rdhi and rdlo must be different"));
12484}
b05fe5cf 12485
c19d1205
ZW
12486static void
12487do_t_nop (void)
12488{
e07e6e58
NC
12489 set_it_insn_type (NEUTRAL_IT_INSN);
12490
c19d1205
ZW
12491 if (unified_syntax)
12492 {
12493 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12494 {
c19d1205
ZW
12495 inst.instruction = THUMB_OP32 (inst.instruction);
12496 inst.instruction |= inst.operands[0].imm;
12497 }
12498 else
12499 {
bc2d1808
NC
12500 /* PR9722: Check for Thumb2 availability before
12501 generating a thumb2 nop instruction. */
afa62d5e 12502 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12503 {
12504 inst.instruction = THUMB_OP16 (inst.instruction);
12505 inst.instruction |= inst.operands[0].imm << 4;
12506 }
12507 else
12508 inst.instruction = 0x46c0;
c19d1205
ZW
12509 }
12510 }
12511 else
12512 {
12513 constraint (inst.operands[0].present,
12514 _("Thumb does not support NOP with hints"));
12515 inst.instruction = 0x46c0;
12516 }
12517}
b05fe5cf 12518
c19d1205
ZW
12519static void
12520do_t_neg (void)
12521{
12522 if (unified_syntax)
12523 {
3d388997
PB
12524 bfd_boolean narrow;
12525
12526 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12527 narrow = !in_it_block ();
3d388997 12528 else
e07e6e58 12529 narrow = in_it_block ();
3d388997
PB
12530 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12531 narrow = FALSE;
12532 if (inst.size_req == 4)
12533 narrow = FALSE;
12534
12535 if (!narrow)
c19d1205
ZW
12536 {
12537 inst.instruction = THUMB_OP32 (inst.instruction);
12538 inst.instruction |= inst.operands[0].reg << 8;
12539 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12540 }
12541 else
12542 {
c19d1205
ZW
12543 inst.instruction = THUMB_OP16 (inst.instruction);
12544 inst.instruction |= inst.operands[0].reg;
12545 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12546 }
12547 }
12548 else
12549 {
c19d1205
ZW
12550 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12551 BAD_HIREG);
12552 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12553
12554 inst.instruction = THUMB_OP16 (inst.instruction);
12555 inst.instruction |= inst.operands[0].reg;
12556 inst.instruction |= inst.operands[1].reg << 3;
12557 }
12558}
12559
1c444d06
JM
12560static void
12561do_t_orn (void)
12562{
12563 unsigned Rd, Rn;
12564
12565 Rd = inst.operands[0].reg;
12566 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12567
fdfde340
JM
12568 reject_bad_reg (Rd);
12569 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12570 reject_bad_reg (Rn);
12571
1c444d06
JM
12572 inst.instruction |= Rd << 8;
12573 inst.instruction |= Rn << 16;
12574
12575 if (!inst.operands[2].isreg)
12576 {
12577 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12578 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12579 }
12580 else
12581 {
12582 unsigned Rm;
12583
12584 Rm = inst.operands[2].reg;
fdfde340 12585 reject_bad_reg (Rm);
1c444d06
JM
12586
12587 constraint (inst.operands[2].shifted
12588 && inst.operands[2].immisreg,
12589 _("shift must be constant"));
12590 encode_thumb32_shifted_operand (2);
12591 }
12592}
12593
c19d1205
ZW
12594static void
12595do_t_pkhbt (void)
12596{
fdfde340
JM
12597 unsigned Rd, Rn, Rm;
12598
12599 Rd = inst.operands[0].reg;
12600 Rn = inst.operands[1].reg;
12601 Rm = inst.operands[2].reg;
12602
12603 reject_bad_reg (Rd);
12604 reject_bad_reg (Rn);
12605 reject_bad_reg (Rm);
12606
12607 inst.instruction |= Rd << 8;
12608 inst.instruction |= Rn << 16;
12609 inst.instruction |= Rm;
c19d1205
ZW
12610 if (inst.operands[3].present)
12611 {
12612 unsigned int val = inst.reloc.exp.X_add_number;
12613 constraint (inst.reloc.exp.X_op != O_constant,
12614 _("expression too complex"));
12615 inst.instruction |= (val & 0x1c) << 10;
12616 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12617 }
c19d1205 12618}
b05fe5cf 12619
c19d1205
ZW
12620static void
12621do_t_pkhtb (void)
12622{
12623 if (!inst.operands[3].present)
1ef52f49
NC
12624 {
12625 unsigned Rtmp;
12626
12627 inst.instruction &= ~0x00000020;
12628
12629 /* PR 10168. Swap the Rm and Rn registers. */
12630 Rtmp = inst.operands[1].reg;
12631 inst.operands[1].reg = inst.operands[2].reg;
12632 inst.operands[2].reg = Rtmp;
12633 }
c19d1205 12634 do_t_pkhbt ();
b05fe5cf
ZW
12635}
12636
c19d1205
ZW
12637static void
12638do_t_pld (void)
12639{
fdfde340
JM
12640 if (inst.operands[0].immisreg)
12641 reject_bad_reg (inst.operands[0].imm);
12642
c19d1205
ZW
12643 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12644}
b05fe5cf 12645
c19d1205
ZW
12646static void
12647do_t_push_pop (void)
b99bd4ef 12648{
e9f89963 12649 unsigned mask;
5f4273c7 12650
c19d1205
ZW
12651 constraint (inst.operands[0].writeback,
12652 _("push/pop do not support {reglist}^"));
12653 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12654 _("expression too complex"));
b99bd4ef 12655
e9f89963 12656 mask = inst.operands[0].imm;
d3bfe16e 12657 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12658 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12659 else if (inst.size_req != 4
c6025a80 12660 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12661 ? REG_LR : REG_PC)))
b99bd4ef 12662 {
c19d1205
ZW
12663 inst.instruction = THUMB_OP16 (inst.instruction);
12664 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12665 inst.instruction |= mask & 0xff;
c19d1205
ZW
12666 }
12667 else if (unified_syntax)
12668 {
3c707909 12669 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12670 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12671 }
12672 else
12673 {
12674 inst.error = _("invalid register list to push/pop instruction");
12675 return;
12676 }
c19d1205 12677}
b99bd4ef 12678
c19d1205
ZW
12679static void
12680do_t_rbit (void)
12681{
fdfde340
JM
12682 unsigned Rd, Rm;
12683
12684 Rd = inst.operands[0].reg;
12685 Rm = inst.operands[1].reg;
12686
12687 reject_bad_reg (Rd);
12688 reject_bad_reg (Rm);
12689
12690 inst.instruction |= Rd << 8;
12691 inst.instruction |= Rm << 16;
12692 inst.instruction |= Rm;
c19d1205 12693}
b99bd4ef 12694
c19d1205
ZW
12695static void
12696do_t_rev (void)
12697{
fdfde340
JM
12698 unsigned Rd, Rm;
12699
12700 Rd = inst.operands[0].reg;
12701 Rm = inst.operands[1].reg;
12702
12703 reject_bad_reg (Rd);
12704 reject_bad_reg (Rm);
12705
12706 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12707 && inst.size_req != 4)
12708 {
12709 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12710 inst.instruction |= Rd;
12711 inst.instruction |= Rm << 3;
c19d1205
ZW
12712 }
12713 else if (unified_syntax)
12714 {
12715 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12716 inst.instruction |= Rd << 8;
12717 inst.instruction |= Rm << 16;
12718 inst.instruction |= Rm;
c19d1205
ZW
12719 }
12720 else
12721 inst.error = BAD_HIREG;
12722}
b99bd4ef 12723
1c444d06
JM
12724static void
12725do_t_rrx (void)
12726{
12727 unsigned Rd, Rm;
12728
12729 Rd = inst.operands[0].reg;
12730 Rm = inst.operands[1].reg;
12731
fdfde340
JM
12732 reject_bad_reg (Rd);
12733 reject_bad_reg (Rm);
c921be7d 12734
1c444d06
JM
12735 inst.instruction |= Rd << 8;
12736 inst.instruction |= Rm;
12737}
12738
c19d1205
ZW
12739static void
12740do_t_rsb (void)
12741{
fdfde340 12742 unsigned Rd, Rs;
b99bd4ef 12743
c19d1205
ZW
12744 Rd = inst.operands[0].reg;
12745 Rs = (inst.operands[1].present
12746 ? inst.operands[1].reg /* Rd, Rs, foo */
12747 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12748
fdfde340
JM
12749 reject_bad_reg (Rd);
12750 reject_bad_reg (Rs);
12751 if (inst.operands[2].isreg)
12752 reject_bad_reg (inst.operands[2].reg);
12753
c19d1205
ZW
12754 inst.instruction |= Rd << 8;
12755 inst.instruction |= Rs << 16;
12756 if (!inst.operands[2].isreg)
12757 {
026d3abb
PB
12758 bfd_boolean narrow;
12759
12760 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12761 narrow = !in_it_block ();
026d3abb 12762 else
e07e6e58 12763 narrow = in_it_block ();
026d3abb
PB
12764
12765 if (Rd > 7 || Rs > 7)
12766 narrow = FALSE;
12767
12768 if (inst.size_req == 4 || !unified_syntax)
12769 narrow = FALSE;
12770
12771 if (inst.reloc.exp.X_op != O_constant
12772 || inst.reloc.exp.X_add_number != 0)
12773 narrow = FALSE;
12774
12775 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12776 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12777 if (narrow)
12778 {
12779 inst.reloc.type = BFD_RELOC_UNUSED;
12780 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12781 inst.instruction |= Rs << 3;
12782 inst.instruction |= Rd;
12783 }
12784 else
12785 {
12786 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12787 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12788 }
c19d1205
ZW
12789 }
12790 else
12791 encode_thumb32_shifted_operand (2);
12792}
b99bd4ef 12793
c19d1205
ZW
12794static void
12795do_t_setend (void)
12796{
12e37cbc
MGD
12797 if (warn_on_deprecated
12798 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12799 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12800
e07e6e58 12801 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12802 if (inst.operands[0].imm)
12803 inst.instruction |= 0x8;
12804}
b99bd4ef 12805
c19d1205
ZW
12806static void
12807do_t_shift (void)
12808{
12809 if (!inst.operands[1].present)
12810 inst.operands[1].reg = inst.operands[0].reg;
12811
12812 if (unified_syntax)
12813 {
3d388997
PB
12814 bfd_boolean narrow;
12815 int shift_kind;
12816
12817 switch (inst.instruction)
12818 {
12819 case T_MNEM_asr:
12820 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12821 case T_MNEM_lsl:
12822 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12823 case T_MNEM_lsr:
12824 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12825 case T_MNEM_ror:
12826 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12827 default: abort ();
12828 }
12829
12830 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12831 narrow = !in_it_block ();
3d388997 12832 else
e07e6e58 12833 narrow = in_it_block ();
3d388997
PB
12834 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12835 narrow = FALSE;
12836 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12837 narrow = FALSE;
12838 if (inst.operands[2].isreg
12839 && (inst.operands[1].reg != inst.operands[0].reg
12840 || inst.operands[2].reg > 7))
12841 narrow = FALSE;
12842 if (inst.size_req == 4)
12843 narrow = FALSE;
12844
fdfde340
JM
12845 reject_bad_reg (inst.operands[0].reg);
12846 reject_bad_reg (inst.operands[1].reg);
c921be7d 12847
3d388997 12848 if (!narrow)
c19d1205
ZW
12849 {
12850 if (inst.operands[2].isreg)
b99bd4ef 12851 {
fdfde340 12852 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12853 inst.instruction = THUMB_OP32 (inst.instruction);
12854 inst.instruction |= inst.operands[0].reg << 8;
12855 inst.instruction |= inst.operands[1].reg << 16;
12856 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12857
12858 /* PR 12854: Error on extraneous shifts. */
12859 constraint (inst.operands[2].shifted,
12860 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12861 }
12862 else
12863 {
12864 inst.operands[1].shifted = 1;
3d388997 12865 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12866 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12867 ? T_MNEM_movs : T_MNEM_mov);
12868 inst.instruction |= inst.operands[0].reg << 8;
12869 encode_thumb32_shifted_operand (1);
12870 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12871 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12872 }
12873 }
12874 else
12875 {
c19d1205 12876 if (inst.operands[2].isreg)
b99bd4ef 12877 {
3d388997 12878 switch (shift_kind)
b99bd4ef 12879 {
3d388997
PB
12880 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12881 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12882 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12883 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12884 default: abort ();
b99bd4ef 12885 }
5f4273c7 12886
c19d1205
ZW
12887 inst.instruction |= inst.operands[0].reg;
12888 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12889
12890 /* PR 12854: Error on extraneous shifts. */
12891 constraint (inst.operands[2].shifted,
12892 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12893 }
12894 else
12895 {
3d388997 12896 switch (shift_kind)
b99bd4ef 12897 {
3d388997
PB
12898 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12899 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12900 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12901 default: abort ();
b99bd4ef 12902 }
c19d1205
ZW
12903 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12904 inst.instruction |= inst.operands[0].reg;
12905 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12906 }
12907 }
c19d1205
ZW
12908 }
12909 else
12910 {
12911 constraint (inst.operands[0].reg > 7
12912 || inst.operands[1].reg > 7, BAD_HIREG);
12913 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12914
c19d1205
ZW
12915 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12916 {
12917 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12918 constraint (inst.operands[0].reg != inst.operands[1].reg,
12919 _("source1 and dest must be same register"));
b99bd4ef 12920
c19d1205
ZW
12921 switch (inst.instruction)
12922 {
12923 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12924 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12925 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12926 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12927 default: abort ();
12928 }
5f4273c7 12929
c19d1205
ZW
12930 inst.instruction |= inst.operands[0].reg;
12931 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12932
12933 /* PR 12854: Error on extraneous shifts. */
12934 constraint (inst.operands[2].shifted,
12935 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12936 }
12937 else
b99bd4ef 12938 {
c19d1205
ZW
12939 switch (inst.instruction)
12940 {
12941 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12942 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12943 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12944 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12945 default: abort ();
12946 }
12947 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12948 inst.instruction |= inst.operands[0].reg;
12949 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12950 }
12951 }
b99bd4ef
NC
12952}
12953
12954static void
c19d1205 12955do_t_simd (void)
b99bd4ef 12956{
fdfde340
JM
12957 unsigned Rd, Rn, Rm;
12958
12959 Rd = inst.operands[0].reg;
12960 Rn = inst.operands[1].reg;
12961 Rm = inst.operands[2].reg;
12962
12963 reject_bad_reg (Rd);
12964 reject_bad_reg (Rn);
12965 reject_bad_reg (Rm);
12966
12967 inst.instruction |= Rd << 8;
12968 inst.instruction |= Rn << 16;
12969 inst.instruction |= Rm;
c19d1205 12970}
b99bd4ef 12971
03ee1b7f
NC
12972static void
12973do_t_simd2 (void)
12974{
12975 unsigned Rd, Rn, Rm;
12976
12977 Rd = inst.operands[0].reg;
12978 Rm = inst.operands[1].reg;
12979 Rn = inst.operands[2].reg;
12980
12981 reject_bad_reg (Rd);
12982 reject_bad_reg (Rn);
12983 reject_bad_reg (Rm);
12984
12985 inst.instruction |= Rd << 8;
12986 inst.instruction |= Rn << 16;
12987 inst.instruction |= Rm;
12988}
12989
c19d1205 12990static void
3eb17e6b 12991do_t_smc (void)
c19d1205
ZW
12992{
12993 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12994 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12995 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12996 constraint (inst.reloc.exp.X_op != O_constant,
12997 _("expression too complex"));
12998 inst.reloc.type = BFD_RELOC_UNUSED;
12999 inst.instruction |= (value & 0xf000) >> 12;
13000 inst.instruction |= (value & 0x0ff0);
13001 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
13002 /* PR gas/15623: SMC instructions must be last in an IT block. */
13003 set_it_insn_type_last ();
c19d1205 13004}
b99bd4ef 13005
90ec0d68
MGD
13006static void
13007do_t_hvc (void)
13008{
13009 unsigned int value = inst.reloc.exp.X_add_number;
13010
13011 inst.reloc.type = BFD_RELOC_UNUSED;
13012 inst.instruction |= (value & 0x0fff);
13013 inst.instruction |= (value & 0xf000) << 4;
13014}
13015
c19d1205 13016static void
3a21c15a 13017do_t_ssat_usat (int bias)
c19d1205 13018{
fdfde340
JM
13019 unsigned Rd, Rn;
13020
13021 Rd = inst.operands[0].reg;
13022 Rn = inst.operands[2].reg;
13023
13024 reject_bad_reg (Rd);
13025 reject_bad_reg (Rn);
13026
13027 inst.instruction |= Rd << 8;
3a21c15a 13028 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 13029 inst.instruction |= Rn << 16;
b99bd4ef 13030
c19d1205 13031 if (inst.operands[3].present)
b99bd4ef 13032 {
3a21c15a
NC
13033 offsetT shift_amount = inst.reloc.exp.X_add_number;
13034
13035 inst.reloc.type = BFD_RELOC_UNUSED;
13036
c19d1205
ZW
13037 constraint (inst.reloc.exp.X_op != O_constant,
13038 _("expression too complex"));
b99bd4ef 13039
3a21c15a 13040 if (shift_amount != 0)
6189168b 13041 {
3a21c15a
NC
13042 constraint (shift_amount > 31,
13043 _("shift expression is too large"));
13044
c19d1205 13045 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
13046 inst.instruction |= 0x00200000; /* sh bit. */
13047
13048 inst.instruction |= (shift_amount & 0x1c) << 10;
13049 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13050 }
13051 }
b99bd4ef 13052}
c921be7d 13053
3a21c15a
NC
13054static void
13055do_t_ssat (void)
13056{
13057 do_t_ssat_usat (1);
13058}
b99bd4ef 13059
0dd132b6 13060static void
c19d1205 13061do_t_ssat16 (void)
0dd132b6 13062{
fdfde340
JM
13063 unsigned Rd, Rn;
13064
13065 Rd = inst.operands[0].reg;
13066 Rn = inst.operands[2].reg;
13067
13068 reject_bad_reg (Rd);
13069 reject_bad_reg (Rn);
13070
13071 inst.instruction |= Rd << 8;
c19d1205 13072 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13073 inst.instruction |= Rn << 16;
c19d1205 13074}
0dd132b6 13075
c19d1205
ZW
13076static void
13077do_t_strex (void)
13078{
13079 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13080 || inst.operands[2].postind || inst.operands[2].writeback
13081 || inst.operands[2].immisreg || inst.operands[2].shifted
13082 || inst.operands[2].negative,
01cfc07f 13083 BAD_ADDR_MODE);
0dd132b6 13084
5be8be5d
DG
13085 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13086
c19d1205
ZW
13087 inst.instruction |= inst.operands[0].reg << 8;
13088 inst.instruction |= inst.operands[1].reg << 12;
13089 inst.instruction |= inst.operands[2].reg << 16;
13090 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13091}
13092
b99bd4ef 13093static void
c19d1205 13094do_t_strexd (void)
b99bd4ef 13095{
c19d1205
ZW
13096 if (!inst.operands[2].present)
13097 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13098
c19d1205
ZW
13099 constraint (inst.operands[0].reg == inst.operands[1].reg
13100 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13101 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13102 BAD_OVERLAP);
b99bd4ef 13103
c19d1205
ZW
13104 inst.instruction |= inst.operands[0].reg;
13105 inst.instruction |= inst.operands[1].reg << 12;
13106 inst.instruction |= inst.operands[2].reg << 8;
13107 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13108}
13109
13110static void
c19d1205 13111do_t_sxtah (void)
b99bd4ef 13112{
fdfde340
JM
13113 unsigned Rd, Rn, Rm;
13114
13115 Rd = inst.operands[0].reg;
13116 Rn = inst.operands[1].reg;
13117 Rm = inst.operands[2].reg;
13118
13119 reject_bad_reg (Rd);
13120 reject_bad_reg (Rn);
13121 reject_bad_reg (Rm);
13122
13123 inst.instruction |= Rd << 8;
13124 inst.instruction |= Rn << 16;
13125 inst.instruction |= Rm;
c19d1205
ZW
13126 inst.instruction |= inst.operands[3].imm << 4;
13127}
b99bd4ef 13128
c19d1205
ZW
13129static void
13130do_t_sxth (void)
13131{
fdfde340
JM
13132 unsigned Rd, Rm;
13133
13134 Rd = inst.operands[0].reg;
13135 Rm = inst.operands[1].reg;
13136
13137 reject_bad_reg (Rd);
13138 reject_bad_reg (Rm);
c921be7d
NC
13139
13140 if (inst.instruction <= 0xffff
13141 && inst.size_req != 4
fdfde340 13142 && Rd <= 7 && Rm <= 7
c19d1205 13143 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13144 {
c19d1205 13145 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13146 inst.instruction |= Rd;
13147 inst.instruction |= Rm << 3;
b99bd4ef 13148 }
c19d1205 13149 else if (unified_syntax)
b99bd4ef 13150 {
c19d1205
ZW
13151 if (inst.instruction <= 0xffff)
13152 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13153 inst.instruction |= Rd << 8;
13154 inst.instruction |= Rm;
c19d1205 13155 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13156 }
c19d1205 13157 else
b99bd4ef 13158 {
c19d1205
ZW
13159 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13160 _("Thumb encoding does not support rotation"));
13161 constraint (1, BAD_HIREG);
b99bd4ef 13162 }
c19d1205 13163}
b99bd4ef 13164
c19d1205
ZW
13165static void
13166do_t_swi (void)
13167{
13168 inst.reloc.type = BFD_RELOC_ARM_SWI;
13169}
b99bd4ef 13170
92e90b6e
PB
13171static void
13172do_t_tb (void)
13173{
fdfde340 13174 unsigned Rn, Rm;
92e90b6e
PB
13175 int half;
13176
13177 half = (inst.instruction & 0x10) != 0;
e07e6e58 13178 set_it_insn_type_last ();
dfa9f0d5
PB
13179 constraint (inst.operands[0].immisreg,
13180 _("instruction requires register index"));
fdfde340
JM
13181
13182 Rn = inst.operands[0].reg;
13183 Rm = inst.operands[0].imm;
c921be7d 13184
5c8ed6a4
JW
13185 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13186 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13187 reject_bad_reg (Rm);
13188
92e90b6e
PB
13189 constraint (!half && inst.operands[0].shifted,
13190 _("instruction does not allow shifted index"));
fdfde340 13191 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13192}
13193
74db7efb
NC
13194static void
13195do_t_udf (void)
13196{
13197 if (!inst.operands[0].present)
13198 inst.operands[0].imm = 0;
13199
13200 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13201 {
13202 constraint (inst.size_req == 2,
13203 _("immediate value out of range"));
13204 inst.instruction = THUMB_OP32 (inst.instruction);
13205 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13206 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13207 }
13208 else
13209 {
13210 inst.instruction = THUMB_OP16 (inst.instruction);
13211 inst.instruction |= inst.operands[0].imm;
13212 }
13213
13214 set_it_insn_type (NEUTRAL_IT_INSN);
13215}
13216
13217
c19d1205
ZW
13218static void
13219do_t_usat (void)
13220{
3a21c15a 13221 do_t_ssat_usat (0);
b99bd4ef
NC
13222}
13223
13224static void
c19d1205 13225do_t_usat16 (void)
b99bd4ef 13226{
fdfde340
JM
13227 unsigned Rd, Rn;
13228
13229 Rd = inst.operands[0].reg;
13230 Rn = inst.operands[2].reg;
13231
13232 reject_bad_reg (Rd);
13233 reject_bad_reg (Rn);
13234
13235 inst.instruction |= Rd << 8;
c19d1205 13236 inst.instruction |= inst.operands[1].imm;
fdfde340 13237 inst.instruction |= Rn << 16;
b99bd4ef 13238}
c19d1205 13239
5287ad62 13240/* Neon instruction encoder helpers. */
5f4273c7 13241
5287ad62 13242/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13243
5287ad62
JB
13244/* An "invalid" code for the following tables. */
13245#define N_INV -1u
13246
13247struct neon_tab_entry
b99bd4ef 13248{
5287ad62
JB
13249 unsigned integer;
13250 unsigned float_or_poly;
13251 unsigned scalar_or_imm;
13252};
5f4273c7 13253
5287ad62
JB
13254/* Map overloaded Neon opcodes to their respective encodings. */
13255#define NEON_ENC_TAB \
13256 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13257 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13258 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13259 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13260 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13261 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13262 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13263 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13264 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13265 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13266 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13267 /* Register variants of the following two instructions are encoded as
e07e6e58 13268 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13269 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13270 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13271 X(vfma, N_INV, 0x0000c10, N_INV), \
13272 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13273 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13274 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13275 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13276 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13277 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13278 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13279 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13280 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13281 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13282 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13283 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13284 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13285 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13286 X(vshl, 0x0000400, N_INV, 0x0800510), \
13287 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13288 X(vand, 0x0000110, N_INV, 0x0800030), \
13289 X(vbic, 0x0100110, N_INV, 0x0800030), \
13290 X(veor, 0x1000110, N_INV, N_INV), \
13291 X(vorn, 0x0300110, N_INV, 0x0800010), \
13292 X(vorr, 0x0200110, N_INV, 0x0800010), \
13293 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13294 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13295 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13296 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13297 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13298 X(vst1, 0x0000000, 0x0800000, N_INV), \
13299 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13300 X(vst2, 0x0000100, 0x0800100, N_INV), \
13301 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13302 X(vst3, 0x0000200, 0x0800200, N_INV), \
13303 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13304 X(vst4, 0x0000300, 0x0800300, N_INV), \
13305 X(vmovn, 0x1b20200, N_INV, N_INV), \
13306 X(vtrn, 0x1b20080, N_INV, N_INV), \
13307 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13308 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13309 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13310 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13311 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13312 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13313 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13314 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13315 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13316 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13317 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13318 X(vseleq, 0xe000a00, N_INV, N_INV), \
13319 X(vselvs, 0xe100a00, N_INV, N_INV), \
13320 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13321 X(vselgt, 0xe300a00, N_INV, N_INV), \
13322 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13323 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13324 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13325 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13326 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13327 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13328 X(sha3op, 0x2000c00, N_INV, N_INV), \
13329 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13330 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13331
13332enum neon_opc
13333{
13334#define X(OPC,I,F,S) N_MNEM_##OPC
13335NEON_ENC_TAB
13336#undef X
13337};
b99bd4ef 13338
5287ad62
JB
13339static const struct neon_tab_entry neon_enc_tab[] =
13340{
13341#define X(OPC,I,F,S) { (I), (F), (S) }
13342NEON_ENC_TAB
13343#undef X
13344};
b99bd4ef 13345
88714cb8
DG
13346/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13347#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13348#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13349#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13350#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13351#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13352#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13353#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13354#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13355#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13356#define NEON_ENC_SINGLE_(X) \
037e8744 13357 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13358#define NEON_ENC_DOUBLE_(X) \
037e8744 13359 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13360#define NEON_ENC_FPV8_(X) \
13361 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13362
88714cb8
DG
13363#define NEON_ENCODE(type, inst) \
13364 do \
13365 { \
13366 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13367 inst.is_neon = 1; \
13368 } \
13369 while (0)
13370
13371#define check_neon_suffixes \
13372 do \
13373 { \
13374 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13375 { \
13376 as_bad (_("invalid neon suffix for non neon instruction")); \
13377 return; \
13378 } \
13379 } \
13380 while (0)
13381
037e8744
JB
13382/* Define shapes for instruction operands. The following mnemonic characters
13383 are used in this table:
5287ad62 13384
037e8744 13385 F - VFP S<n> register
5287ad62
JB
13386 D - Neon D<n> register
13387 Q - Neon Q<n> register
13388 I - Immediate
13389 S - Scalar
13390 R - ARM register
13391 L - D<n> register list
5f4273c7 13392
037e8744
JB
13393 This table is used to generate various data:
13394 - enumerations of the form NS_DDR to be used as arguments to
13395 neon_select_shape.
13396 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13397 - a table used to drive neon_select_shape. */
b99bd4ef 13398
037e8744
JB
13399#define NEON_SHAPE_DEF \
13400 X(3, (D, D, D), DOUBLE), \
13401 X(3, (Q, Q, Q), QUAD), \
13402 X(3, (D, D, I), DOUBLE), \
13403 X(3, (Q, Q, I), QUAD), \
13404 X(3, (D, D, S), DOUBLE), \
13405 X(3, (Q, Q, S), QUAD), \
13406 X(2, (D, D), DOUBLE), \
13407 X(2, (Q, Q), QUAD), \
13408 X(2, (D, S), DOUBLE), \
13409 X(2, (Q, S), QUAD), \
13410 X(2, (D, R), DOUBLE), \
13411 X(2, (Q, R), QUAD), \
13412 X(2, (D, I), DOUBLE), \
13413 X(2, (Q, I), QUAD), \
13414 X(3, (D, L, D), DOUBLE), \
13415 X(2, (D, Q), MIXED), \
13416 X(2, (Q, D), MIXED), \
13417 X(3, (D, Q, I), MIXED), \
13418 X(3, (Q, D, I), MIXED), \
13419 X(3, (Q, D, D), MIXED), \
13420 X(3, (D, Q, Q), MIXED), \
13421 X(3, (Q, Q, D), MIXED), \
13422 X(3, (Q, D, S), MIXED), \
13423 X(3, (D, Q, S), MIXED), \
13424 X(4, (D, D, D, I), DOUBLE), \
13425 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13426 X(4, (D, D, S, I), DOUBLE), \
13427 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13428 X(2, (F, F), SINGLE), \
13429 X(3, (F, F, F), SINGLE), \
13430 X(2, (F, I), SINGLE), \
13431 X(2, (F, D), MIXED), \
13432 X(2, (D, F), MIXED), \
13433 X(3, (F, F, I), MIXED), \
13434 X(4, (R, R, F, F), SINGLE), \
13435 X(4, (F, F, R, R), SINGLE), \
13436 X(3, (D, R, R), DOUBLE), \
13437 X(3, (R, R, D), DOUBLE), \
13438 X(2, (S, R), SINGLE), \
13439 X(2, (R, S), SINGLE), \
13440 X(2, (F, R), SINGLE), \
d54af2d0
RL
13441 X(2, (R, F), SINGLE), \
13442/* Half float shape supported so far. */\
13443 X (2, (H, D), MIXED), \
13444 X (2, (D, H), MIXED), \
13445 X (2, (H, F), MIXED), \
13446 X (2, (F, H), MIXED), \
13447 X (2, (H, H), HALF), \
13448 X (2, (H, R), HALF), \
13449 X (2, (R, H), HALF), \
13450 X (2, (H, I), HALF), \
13451 X (3, (H, H, H), HALF), \
13452 X (3, (H, F, I), MIXED), \
dec41383
JW
13453 X (3, (F, H, I), MIXED), \
13454 X (3, (D, H, H), MIXED), \
13455 X (3, (D, H, S), MIXED)
037e8744
JB
13456
13457#define S2(A,B) NS_##A##B
13458#define S3(A,B,C) NS_##A##B##C
13459#define S4(A,B,C,D) NS_##A##B##C##D
13460
13461#define X(N, L, C) S##N L
13462
5287ad62
JB
13463enum neon_shape
13464{
037e8744
JB
13465 NEON_SHAPE_DEF,
13466 NS_NULL
5287ad62 13467};
b99bd4ef 13468
037e8744
JB
13469#undef X
13470#undef S2
13471#undef S3
13472#undef S4
13473
13474enum neon_shape_class
13475{
d54af2d0 13476 SC_HALF,
037e8744
JB
13477 SC_SINGLE,
13478 SC_DOUBLE,
13479 SC_QUAD,
13480 SC_MIXED
13481};
13482
13483#define X(N, L, C) SC_##C
13484
13485static enum neon_shape_class neon_shape_class[] =
13486{
13487 NEON_SHAPE_DEF
13488};
13489
13490#undef X
13491
13492enum neon_shape_el
13493{
d54af2d0 13494 SE_H,
037e8744
JB
13495 SE_F,
13496 SE_D,
13497 SE_Q,
13498 SE_I,
13499 SE_S,
13500 SE_R,
13501 SE_L
13502};
13503
13504/* Register widths of above. */
13505static unsigned neon_shape_el_size[] =
13506{
d54af2d0 13507 16,
037e8744
JB
13508 32,
13509 64,
13510 128,
13511 0,
13512 32,
13513 32,
13514 0
13515};
13516
13517struct neon_shape_info
13518{
13519 unsigned els;
13520 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13521};
13522
13523#define S2(A,B) { SE_##A, SE_##B }
13524#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13525#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13526
13527#define X(N, L, C) { N, S##N L }
13528
13529static struct neon_shape_info neon_shape_tab[] =
13530{
13531 NEON_SHAPE_DEF
13532};
13533
13534#undef X
13535#undef S2
13536#undef S3
13537#undef S4
13538
5287ad62
JB
13539/* Bit masks used in type checking given instructions.
13540 'N_EQK' means the type must be the same as (or based on in some way) the key
13541 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13542 set, various other bits can be set as well in order to modify the meaning of
13543 the type constraint. */
13544
13545enum neon_type_mask
13546{
8e79c3df
CM
13547 N_S8 = 0x0000001,
13548 N_S16 = 0x0000002,
13549 N_S32 = 0x0000004,
13550 N_S64 = 0x0000008,
13551 N_U8 = 0x0000010,
13552 N_U16 = 0x0000020,
13553 N_U32 = 0x0000040,
13554 N_U64 = 0x0000080,
13555 N_I8 = 0x0000100,
13556 N_I16 = 0x0000200,
13557 N_I32 = 0x0000400,
13558 N_I64 = 0x0000800,
13559 N_8 = 0x0001000,
13560 N_16 = 0x0002000,
13561 N_32 = 0x0004000,
13562 N_64 = 0x0008000,
13563 N_P8 = 0x0010000,
13564 N_P16 = 0x0020000,
13565 N_F16 = 0x0040000,
13566 N_F32 = 0x0080000,
13567 N_F64 = 0x0100000,
4f51b4bd 13568 N_P64 = 0x0200000,
c921be7d
NC
13569 N_KEY = 0x1000000, /* Key element (main type specifier). */
13570 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13571 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13572 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13573 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13574 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13575 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13576 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13577 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13578 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13579 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13580 N_UTYP = 0,
4f51b4bd 13581 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13582};
13583
dcbf9037
JB
13584#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13585
5287ad62
JB
13586#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13587#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13588#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13589#define N_S_32 (N_S8 | N_S16 | N_S32)
13590#define N_F_16_32 (N_F16 | N_F32)
13591#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13592#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13593#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13594#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13595
13596/* Pass this as the first type argument to neon_check_type to ignore types
13597 altogether. */
13598#define N_IGNORE_TYPE (N_KEY | N_EQK)
13599
037e8744
JB
13600/* Select a "shape" for the current instruction (describing register types or
13601 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13602 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13603 function of operand parsing, so this function doesn't need to be called.
13604 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13605
13606static enum neon_shape
037e8744 13607neon_select_shape (enum neon_shape shape, ...)
5287ad62 13608{
037e8744
JB
13609 va_list ap;
13610 enum neon_shape first_shape = shape;
5287ad62
JB
13611
13612 /* Fix missing optional operands. FIXME: we don't know at this point how
13613 many arguments we should have, so this makes the assumption that we have
13614 > 1. This is true of all current Neon opcodes, I think, but may not be
13615 true in the future. */
13616 if (!inst.operands[1].present)
13617 inst.operands[1] = inst.operands[0];
13618
037e8744 13619 va_start (ap, shape);
5f4273c7 13620
21d799b5 13621 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13622 {
13623 unsigned j;
13624 int matches = 1;
13625
13626 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13627 {
13628 if (!inst.operands[j].present)
13629 {
13630 matches = 0;
13631 break;
13632 }
13633
13634 switch (neon_shape_tab[shape].el[j])
13635 {
d54af2d0
RL
13636 /* If a .f16, .16, .u16, .s16 type specifier is given over
13637 a VFP single precision register operand, it's essentially
13638 means only half of the register is used.
13639
13640 If the type specifier is given after the mnemonics, the
13641 information is stored in inst.vectype. If the type specifier
13642 is given after register operand, the information is stored
13643 in inst.operands[].vectype.
13644
13645 When there is only one type specifier, and all the register
13646 operands are the same type of hardware register, the type
13647 specifier applies to all register operands.
13648
13649 If no type specifier is given, the shape is inferred from
13650 operand information.
13651
13652 for example:
13653 vadd.f16 s0, s1, s2: NS_HHH
13654 vabs.f16 s0, s1: NS_HH
13655 vmov.f16 s0, r1: NS_HR
13656 vmov.f16 r0, s1: NS_RH
13657 vcvt.f16 r0, s1: NS_RH
13658 vcvt.f16.s32 s2, s2, #29: NS_HFI
13659 vcvt.f16.s32 s2, s2: NS_HF
13660 */
13661 case SE_H:
13662 if (!(inst.operands[j].isreg
13663 && inst.operands[j].isvec
13664 && inst.operands[j].issingle
13665 && !inst.operands[j].isquad
13666 && ((inst.vectype.elems == 1
13667 && inst.vectype.el[0].size == 16)
13668 || (inst.vectype.elems > 1
13669 && inst.vectype.el[j].size == 16)
13670 || (inst.vectype.elems == 0
13671 && inst.operands[j].vectype.type != NT_invtype
13672 && inst.operands[j].vectype.size == 16))))
13673 matches = 0;
13674 break;
13675
477330fc
RM
13676 case SE_F:
13677 if (!(inst.operands[j].isreg
13678 && inst.operands[j].isvec
13679 && inst.operands[j].issingle
d54af2d0
RL
13680 && !inst.operands[j].isquad
13681 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13682 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13683 || (inst.vectype.elems == 0
13684 && (inst.operands[j].vectype.size == 32
13685 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13686 matches = 0;
13687 break;
13688
13689 case SE_D:
13690 if (!(inst.operands[j].isreg
13691 && inst.operands[j].isvec
13692 && !inst.operands[j].isquad
13693 && !inst.operands[j].issingle))
13694 matches = 0;
13695 break;
13696
13697 case SE_R:
13698 if (!(inst.operands[j].isreg
13699 && !inst.operands[j].isvec))
13700 matches = 0;
13701 break;
13702
13703 case SE_Q:
13704 if (!(inst.operands[j].isreg
13705 && inst.operands[j].isvec
13706 && inst.operands[j].isquad
13707 && !inst.operands[j].issingle))
13708 matches = 0;
13709 break;
13710
13711 case SE_I:
13712 if (!(!inst.operands[j].isreg
13713 && !inst.operands[j].isscalar))
13714 matches = 0;
13715 break;
13716
13717 case SE_S:
13718 if (!(!inst.operands[j].isreg
13719 && inst.operands[j].isscalar))
13720 matches = 0;
13721 break;
13722
13723 case SE_L:
13724 break;
13725 }
3fde54a2
JZ
13726 if (!matches)
13727 break;
477330fc 13728 }
ad6cec43
MGD
13729 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13730 /* We've matched all the entries in the shape table, and we don't
13731 have any left over operands which have not been matched. */
477330fc 13732 break;
037e8744 13733 }
5f4273c7 13734
037e8744 13735 va_end (ap);
5287ad62 13736
037e8744
JB
13737 if (shape == NS_NULL && first_shape != NS_NULL)
13738 first_error (_("invalid instruction shape"));
5287ad62 13739
037e8744
JB
13740 return shape;
13741}
5287ad62 13742
037e8744
JB
13743/* True if SHAPE is predominantly a quadword operation (most of the time, this
13744 means the Q bit should be set). */
13745
13746static int
13747neon_quad (enum neon_shape shape)
13748{
13749 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13750}
037e8744 13751
5287ad62
JB
13752static void
13753neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13754 unsigned *g_size)
5287ad62
JB
13755{
13756 /* Allow modification to be made to types which are constrained to be
13757 based on the key element, based on bits set alongside N_EQK. */
13758 if ((typebits & N_EQK) != 0)
13759 {
13760 if ((typebits & N_HLF) != 0)
13761 *g_size /= 2;
13762 else if ((typebits & N_DBL) != 0)
13763 *g_size *= 2;
13764 if ((typebits & N_SGN) != 0)
13765 *g_type = NT_signed;
13766 else if ((typebits & N_UNS) != 0)
477330fc 13767 *g_type = NT_unsigned;
5287ad62 13768 else if ((typebits & N_INT) != 0)
477330fc 13769 *g_type = NT_integer;
5287ad62 13770 else if ((typebits & N_FLT) != 0)
477330fc 13771 *g_type = NT_float;
dcbf9037 13772 else if ((typebits & N_SIZ) != 0)
477330fc 13773 *g_type = NT_untyped;
5287ad62
JB
13774 }
13775}
5f4273c7 13776
5287ad62
JB
13777/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13778 operand type, i.e. the single type specified in a Neon instruction when it
13779 is the only one given. */
13780
13781static struct neon_type_el
13782neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13783{
13784 struct neon_type_el dest = *key;
5f4273c7 13785
9c2799c2 13786 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13787
5287ad62
JB
13788 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13789
13790 return dest;
13791}
13792
13793/* Convert Neon type and size into compact bitmask representation. */
13794
13795static enum neon_type_mask
13796type_chk_of_el_type (enum neon_el_type type, unsigned size)
13797{
13798 switch (type)
13799 {
13800 case NT_untyped:
13801 switch (size)
477330fc
RM
13802 {
13803 case 8: return N_8;
13804 case 16: return N_16;
13805 case 32: return N_32;
13806 case 64: return N_64;
13807 default: ;
13808 }
5287ad62
JB
13809 break;
13810
13811 case NT_integer:
13812 switch (size)
477330fc
RM
13813 {
13814 case 8: return N_I8;
13815 case 16: return N_I16;
13816 case 32: return N_I32;
13817 case 64: return N_I64;
13818 default: ;
13819 }
5287ad62
JB
13820 break;
13821
13822 case NT_float:
037e8744 13823 switch (size)
477330fc 13824 {
8e79c3df 13825 case 16: return N_F16;
477330fc
RM
13826 case 32: return N_F32;
13827 case 64: return N_F64;
13828 default: ;
13829 }
5287ad62
JB
13830 break;
13831
13832 case NT_poly:
13833 switch (size)
477330fc
RM
13834 {
13835 case 8: return N_P8;
13836 case 16: return N_P16;
4f51b4bd 13837 case 64: return N_P64;
477330fc
RM
13838 default: ;
13839 }
5287ad62
JB
13840 break;
13841
13842 case NT_signed:
13843 switch (size)
477330fc
RM
13844 {
13845 case 8: return N_S8;
13846 case 16: return N_S16;
13847 case 32: return N_S32;
13848 case 64: return N_S64;
13849 default: ;
13850 }
5287ad62
JB
13851 break;
13852
13853 case NT_unsigned:
13854 switch (size)
477330fc
RM
13855 {
13856 case 8: return N_U8;
13857 case 16: return N_U16;
13858 case 32: return N_U32;
13859 case 64: return N_U64;
13860 default: ;
13861 }
5287ad62
JB
13862 break;
13863
13864 default: ;
13865 }
5f4273c7 13866
5287ad62
JB
13867 return N_UTYP;
13868}
13869
13870/* Convert compact Neon bitmask type representation to a type and size. Only
13871 handles the case where a single bit is set in the mask. */
13872
dcbf9037 13873static int
5287ad62 13874el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13875 enum neon_type_mask mask)
5287ad62 13876{
dcbf9037
JB
13877 if ((mask & N_EQK) != 0)
13878 return FAIL;
13879
5287ad62
JB
13880 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13881 *size = 8;
c70a8987 13882 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13883 *size = 16;
dcbf9037 13884 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13885 *size = 32;
4f51b4bd 13886 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13887 *size = 64;
dcbf9037
JB
13888 else
13889 return FAIL;
13890
5287ad62
JB
13891 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13892 *type = NT_signed;
dcbf9037 13893 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13894 *type = NT_unsigned;
dcbf9037 13895 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13896 *type = NT_integer;
dcbf9037 13897 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13898 *type = NT_untyped;
4f51b4bd 13899 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13900 *type = NT_poly;
d54af2d0 13901 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13902 *type = NT_float;
dcbf9037
JB
13903 else
13904 return FAIL;
5f4273c7 13905
dcbf9037 13906 return SUCCESS;
5287ad62
JB
13907}
13908
13909/* Modify a bitmask of allowed types. This is only needed for type
13910 relaxation. */
13911
13912static unsigned
13913modify_types_allowed (unsigned allowed, unsigned mods)
13914{
13915 unsigned size;
13916 enum neon_el_type type;
13917 unsigned destmask;
13918 int i;
5f4273c7 13919
5287ad62 13920 destmask = 0;
5f4273c7 13921
5287ad62
JB
13922 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13923 {
21d799b5 13924 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13925 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13926 {
13927 neon_modify_type_size (mods, &type, &size);
13928 destmask |= type_chk_of_el_type (type, size);
13929 }
5287ad62 13930 }
5f4273c7 13931
5287ad62
JB
13932 return destmask;
13933}
13934
13935/* Check type and return type classification.
13936 The manual states (paraphrase): If one datatype is given, it indicates the
13937 type given in:
13938 - the second operand, if there is one
13939 - the operand, if there is no second operand
13940 - the result, if there are no operands.
13941 This isn't quite good enough though, so we use a concept of a "key" datatype
13942 which is set on a per-instruction basis, which is the one which matters when
13943 only one data type is written.
13944 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13945 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13946
13947static struct neon_type_el
13948neon_check_type (unsigned els, enum neon_shape ns, ...)
13949{
13950 va_list ap;
13951 unsigned i, pass, key_el = 0;
13952 unsigned types[NEON_MAX_TYPE_ELS];
13953 enum neon_el_type k_type = NT_invtype;
13954 unsigned k_size = -1u;
13955 struct neon_type_el badtype = {NT_invtype, -1};
13956 unsigned key_allowed = 0;
13957
13958 /* Optional registers in Neon instructions are always (not) in operand 1.
13959 Fill in the missing operand here, if it was omitted. */
13960 if (els > 1 && !inst.operands[1].present)
13961 inst.operands[1] = inst.operands[0];
13962
13963 /* Suck up all the varargs. */
13964 va_start (ap, ns);
13965 for (i = 0; i < els; i++)
13966 {
13967 unsigned thisarg = va_arg (ap, unsigned);
13968 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13969 {
13970 va_end (ap);
13971 return badtype;
13972 }
5287ad62
JB
13973 types[i] = thisarg;
13974 if ((thisarg & N_KEY) != 0)
477330fc 13975 key_el = i;
5287ad62
JB
13976 }
13977 va_end (ap);
13978
dcbf9037
JB
13979 if (inst.vectype.elems > 0)
13980 for (i = 0; i < els; i++)
13981 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13982 {
13983 first_error (_("types specified in both the mnemonic and operands"));
13984 return badtype;
13985 }
dcbf9037 13986
5287ad62
JB
13987 /* Duplicate inst.vectype elements here as necessary.
13988 FIXME: No idea if this is exactly the same as the ARM assembler,
13989 particularly when an insn takes one register and one non-register
13990 operand. */
13991 if (inst.vectype.elems == 1 && els > 1)
13992 {
13993 unsigned j;
13994 inst.vectype.elems = els;
13995 inst.vectype.el[key_el] = inst.vectype.el[0];
13996 for (j = 0; j < els; j++)
477330fc
RM
13997 if (j != key_el)
13998 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13999 types[j]);
dcbf9037
JB
14000 }
14001 else if (inst.vectype.elems == 0 && els > 0)
14002 {
14003 unsigned j;
14004 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
14005 after each operand. We allow some flexibility here; as long as the
14006 "key" operand has a type, we can infer the others. */
dcbf9037 14007 for (j = 0; j < els; j++)
477330fc
RM
14008 if (inst.operands[j].vectype.type != NT_invtype)
14009 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
14010
14011 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
14012 {
14013 for (j = 0; j < els; j++)
14014 if (inst.operands[j].vectype.type == NT_invtype)
14015 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14016 types[j]);
14017 }
dcbf9037 14018 else
477330fc
RM
14019 {
14020 first_error (_("operand types can't be inferred"));
14021 return badtype;
14022 }
5287ad62
JB
14023 }
14024 else if (inst.vectype.elems != els)
14025 {
dcbf9037 14026 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
14027 return badtype;
14028 }
14029
14030 for (pass = 0; pass < 2; pass++)
14031 {
14032 for (i = 0; i < els; i++)
477330fc
RM
14033 {
14034 unsigned thisarg = types[i];
14035 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14036 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14037 enum neon_el_type g_type = inst.vectype.el[i].type;
14038 unsigned g_size = inst.vectype.el[i].size;
14039
14040 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14041 integer types if sign-specific variants are unavailable. */
477330fc 14042 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14043 && (types_allowed & N_SU_ALL) == 0)
14044 g_type = NT_integer;
14045
477330fc 14046 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14047 them. Some instructions only care about signs for some element
14048 sizes, so handle that properly. */
477330fc 14049 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14050 && ((g_size == 8 && (types_allowed & N_8) != 0)
14051 || (g_size == 16 && (types_allowed & N_16) != 0)
14052 || (g_size == 32 && (types_allowed & N_32) != 0)
14053 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14054 g_type = NT_untyped;
14055
477330fc
RM
14056 if (pass == 0)
14057 {
14058 if ((thisarg & N_KEY) != 0)
14059 {
14060 k_type = g_type;
14061 k_size = g_size;
14062 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14063
14064 /* Check architecture constraint on FP16 extension. */
14065 if (k_size == 16
14066 && k_type == NT_float
14067 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14068 {
14069 inst.error = _(BAD_FP16);
14070 return badtype;
14071 }
477330fc
RM
14072 }
14073 }
14074 else
14075 {
14076 if ((thisarg & N_VFP) != 0)
14077 {
14078 enum neon_shape_el regshape;
14079 unsigned regwidth, match;
99b253c5
NC
14080
14081 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14082 if (ns == NS_NULL)
14083 {
14084 first_error (_("invalid instruction shape"));
14085 return badtype;
14086 }
477330fc
RM
14087 regshape = neon_shape_tab[ns].el[i];
14088 regwidth = neon_shape_el_size[regshape];
14089
14090 /* In VFP mode, operands must match register widths. If we
14091 have a key operand, use its width, else use the width of
14092 the current operand. */
14093 if (k_size != -1u)
14094 match = k_size;
14095 else
14096 match = g_size;
14097
9db2f6b4
RL
14098 /* FP16 will use a single precision register. */
14099 if (regwidth == 32 && match == 16)
14100 {
14101 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14102 match = regwidth;
14103 else
14104 {
14105 inst.error = _(BAD_FP16);
14106 return badtype;
14107 }
14108 }
14109
477330fc
RM
14110 if (regwidth != match)
14111 {
14112 first_error (_("operand size must match register width"));
14113 return badtype;
14114 }
14115 }
14116
14117 if ((thisarg & N_EQK) == 0)
14118 {
14119 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14120
14121 if ((given_type & types_allowed) == 0)
14122 {
14123 first_error (_("bad type in Neon instruction"));
14124 return badtype;
14125 }
14126 }
14127 else
14128 {
14129 enum neon_el_type mod_k_type = k_type;
14130 unsigned mod_k_size = k_size;
14131 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14132 if (g_type != mod_k_type || g_size != mod_k_size)
14133 {
14134 first_error (_("inconsistent types in Neon instruction"));
14135 return badtype;
14136 }
14137 }
14138 }
14139 }
5287ad62
JB
14140 }
14141
14142 return inst.vectype.el[key_el];
14143}
14144
037e8744 14145/* Neon-style VFP instruction forwarding. */
5287ad62 14146
037e8744
JB
14147/* Thumb VFP instructions have 0xE in the condition field. */
14148
14149static void
14150do_vfp_cond_or_thumb (void)
5287ad62 14151{
88714cb8
DG
14152 inst.is_neon = 1;
14153
5287ad62 14154 if (thumb_mode)
037e8744 14155 inst.instruction |= 0xe0000000;
5287ad62 14156 else
037e8744 14157 inst.instruction |= inst.cond << 28;
5287ad62
JB
14158}
14159
037e8744
JB
14160/* Look up and encode a simple mnemonic, for use as a helper function for the
14161 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14162 etc. It is assumed that operand parsing has already been done, and that the
14163 operands are in the form expected by the given opcode (this isn't necessarily
14164 the same as the form in which they were parsed, hence some massaging must
14165 take place before this function is called).
14166 Checks current arch version against that in the looked-up opcode. */
5287ad62 14167
037e8744
JB
14168static void
14169do_vfp_nsyn_opcode (const char *opname)
5287ad62 14170{
037e8744 14171 const struct asm_opcode *opcode;
5f4273c7 14172
21d799b5 14173 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14174
037e8744
JB
14175 if (!opcode)
14176 abort ();
5287ad62 14177
037e8744 14178 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14179 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14180 _(BAD_FPU));
5287ad62 14181
88714cb8
DG
14182 inst.is_neon = 1;
14183
037e8744
JB
14184 if (thumb_mode)
14185 {
14186 inst.instruction = opcode->tvalue;
14187 opcode->tencode ();
14188 }
14189 else
14190 {
14191 inst.instruction = (inst.cond << 28) | opcode->avalue;
14192 opcode->aencode ();
14193 }
14194}
5287ad62
JB
14195
14196static void
037e8744 14197do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14198{
037e8744
JB
14199 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14200
9db2f6b4 14201 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14202 {
14203 if (is_add)
477330fc 14204 do_vfp_nsyn_opcode ("fadds");
037e8744 14205 else
477330fc 14206 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14207
14208 /* ARMv8.2 fp16 instruction. */
14209 if (rs == NS_HHH)
14210 do_scalar_fp16_v82_encode ();
037e8744
JB
14211 }
14212 else
14213 {
14214 if (is_add)
477330fc 14215 do_vfp_nsyn_opcode ("faddd");
037e8744 14216 else
477330fc 14217 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14218 }
14219}
14220
14221/* Check operand types to see if this is a VFP instruction, and if so call
14222 PFN (). */
14223
14224static int
14225try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14226{
14227 enum neon_shape rs;
14228 struct neon_type_el et;
14229
14230 switch (args)
14231 {
14232 case 2:
9db2f6b4
RL
14233 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14234 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14235 break;
5f4273c7 14236
037e8744 14237 case 3:
9db2f6b4
RL
14238 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14239 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14240 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14241 break;
14242
14243 default:
14244 abort ();
14245 }
14246
14247 if (et.type != NT_invtype)
14248 {
14249 pfn (rs);
14250 return SUCCESS;
14251 }
037e8744 14252
99b253c5 14253 inst.error = NULL;
037e8744
JB
14254 return FAIL;
14255}
14256
14257static void
14258do_vfp_nsyn_mla_mls (enum neon_shape rs)
14259{
14260 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14261
9db2f6b4 14262 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14263 {
14264 if (is_mla)
477330fc 14265 do_vfp_nsyn_opcode ("fmacs");
037e8744 14266 else
477330fc 14267 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14268
14269 /* ARMv8.2 fp16 instruction. */
14270 if (rs == NS_HHH)
14271 do_scalar_fp16_v82_encode ();
037e8744
JB
14272 }
14273 else
14274 {
14275 if (is_mla)
477330fc 14276 do_vfp_nsyn_opcode ("fmacd");
037e8744 14277 else
477330fc 14278 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14279 }
14280}
14281
62f3b8c8
PB
14282static void
14283do_vfp_nsyn_fma_fms (enum neon_shape rs)
14284{
14285 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14286
9db2f6b4 14287 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14288 {
14289 if (is_fma)
477330fc 14290 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14291 else
477330fc 14292 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14293
14294 /* ARMv8.2 fp16 instruction. */
14295 if (rs == NS_HHH)
14296 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14297 }
14298 else
14299 {
14300 if (is_fma)
477330fc 14301 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14302 else
477330fc 14303 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14304 }
14305}
14306
037e8744
JB
14307static void
14308do_vfp_nsyn_mul (enum neon_shape rs)
14309{
9db2f6b4
RL
14310 if (rs == NS_FFF || rs == NS_HHH)
14311 {
14312 do_vfp_nsyn_opcode ("fmuls");
14313
14314 /* ARMv8.2 fp16 instruction. */
14315 if (rs == NS_HHH)
14316 do_scalar_fp16_v82_encode ();
14317 }
037e8744
JB
14318 else
14319 do_vfp_nsyn_opcode ("fmuld");
14320}
14321
14322static void
14323do_vfp_nsyn_abs_neg (enum neon_shape rs)
14324{
14325 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14326 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14327
9db2f6b4 14328 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14329 {
14330 if (is_neg)
477330fc 14331 do_vfp_nsyn_opcode ("fnegs");
037e8744 14332 else
477330fc 14333 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14334
14335 /* ARMv8.2 fp16 instruction. */
14336 if (rs == NS_HH)
14337 do_scalar_fp16_v82_encode ();
037e8744
JB
14338 }
14339 else
14340 {
14341 if (is_neg)
477330fc 14342 do_vfp_nsyn_opcode ("fnegd");
037e8744 14343 else
477330fc 14344 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14345 }
14346}
14347
14348/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14349 insns belong to Neon, and are handled elsewhere. */
14350
14351static void
14352do_vfp_nsyn_ldm_stm (int is_dbmode)
14353{
14354 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14355 if (is_ldm)
14356 {
14357 if (is_dbmode)
477330fc 14358 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14359 else
477330fc 14360 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14361 }
14362 else
14363 {
14364 if (is_dbmode)
477330fc 14365 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14366 else
477330fc 14367 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14368 }
14369}
14370
037e8744
JB
14371static void
14372do_vfp_nsyn_sqrt (void)
14373{
9db2f6b4
RL
14374 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14375 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14376
9db2f6b4
RL
14377 if (rs == NS_FF || rs == NS_HH)
14378 {
14379 do_vfp_nsyn_opcode ("fsqrts");
14380
14381 /* ARMv8.2 fp16 instruction. */
14382 if (rs == NS_HH)
14383 do_scalar_fp16_v82_encode ();
14384 }
037e8744
JB
14385 else
14386 do_vfp_nsyn_opcode ("fsqrtd");
14387}
14388
14389static void
14390do_vfp_nsyn_div (void)
14391{
9db2f6b4 14392 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14393 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14394 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14395
9db2f6b4
RL
14396 if (rs == NS_FFF || rs == NS_HHH)
14397 {
14398 do_vfp_nsyn_opcode ("fdivs");
14399
14400 /* ARMv8.2 fp16 instruction. */
14401 if (rs == NS_HHH)
14402 do_scalar_fp16_v82_encode ();
14403 }
037e8744
JB
14404 else
14405 do_vfp_nsyn_opcode ("fdivd");
14406}
14407
14408static void
14409do_vfp_nsyn_nmul (void)
14410{
9db2f6b4 14411 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14412 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14413 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14414
9db2f6b4 14415 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14416 {
88714cb8 14417 NEON_ENCODE (SINGLE, inst);
037e8744 14418 do_vfp_sp_dyadic ();
9db2f6b4
RL
14419
14420 /* ARMv8.2 fp16 instruction. */
14421 if (rs == NS_HHH)
14422 do_scalar_fp16_v82_encode ();
037e8744
JB
14423 }
14424 else
14425 {
88714cb8 14426 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14427 do_vfp_dp_rd_rn_rm ();
14428 }
14429 do_vfp_cond_or_thumb ();
9db2f6b4 14430
037e8744
JB
14431}
14432
14433static void
14434do_vfp_nsyn_cmp (void)
14435{
9db2f6b4 14436 enum neon_shape rs;
037e8744
JB
14437 if (inst.operands[1].isreg)
14438 {
9db2f6b4
RL
14439 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14440 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14441
9db2f6b4 14442 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14443 {
14444 NEON_ENCODE (SINGLE, inst);
14445 do_vfp_sp_monadic ();
14446 }
037e8744 14447 else
477330fc
RM
14448 {
14449 NEON_ENCODE (DOUBLE, inst);
14450 do_vfp_dp_rd_rm ();
14451 }
037e8744
JB
14452 }
14453 else
14454 {
9db2f6b4
RL
14455 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14456 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14457
14458 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14459 {
14460 case N_MNEM_vcmp:
14461 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14462 break;
14463 case N_MNEM_vcmpe:
14464 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14465 break;
14466 default:
14467 abort ();
14468 }
5f4273c7 14469
9db2f6b4 14470 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14471 {
14472 NEON_ENCODE (SINGLE, inst);
14473 do_vfp_sp_compare_z ();
14474 }
037e8744 14475 else
477330fc
RM
14476 {
14477 NEON_ENCODE (DOUBLE, inst);
14478 do_vfp_dp_rd ();
14479 }
037e8744
JB
14480 }
14481 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14482
14483 /* ARMv8.2 fp16 instruction. */
14484 if (rs == NS_HI || rs == NS_HH)
14485 do_scalar_fp16_v82_encode ();
037e8744
JB
14486}
14487
14488static void
14489nsyn_insert_sp (void)
14490{
14491 inst.operands[1] = inst.operands[0];
14492 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14493 inst.operands[0].reg = REG_SP;
037e8744
JB
14494 inst.operands[0].isreg = 1;
14495 inst.operands[0].writeback = 1;
14496 inst.operands[0].present = 1;
14497}
14498
14499static void
14500do_vfp_nsyn_push (void)
14501{
14502 nsyn_insert_sp ();
b126985e
NC
14503
14504 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14505 _("register list must contain at least 1 and at most 16 "
14506 "registers"));
14507
037e8744
JB
14508 if (inst.operands[1].issingle)
14509 do_vfp_nsyn_opcode ("fstmdbs");
14510 else
14511 do_vfp_nsyn_opcode ("fstmdbd");
14512}
14513
14514static void
14515do_vfp_nsyn_pop (void)
14516{
14517 nsyn_insert_sp ();
b126985e
NC
14518
14519 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14520 _("register list must contain at least 1 and at most 16 "
14521 "registers"));
14522
037e8744 14523 if (inst.operands[1].issingle)
22b5b651 14524 do_vfp_nsyn_opcode ("fldmias");
037e8744 14525 else
22b5b651 14526 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14527}
14528
14529/* Fix up Neon data-processing instructions, ORing in the correct bits for
14530 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14531
88714cb8
DG
14532static void
14533neon_dp_fixup (struct arm_it* insn)
037e8744 14534{
88714cb8
DG
14535 unsigned int i = insn->instruction;
14536 insn->is_neon = 1;
14537
037e8744
JB
14538 if (thumb_mode)
14539 {
14540 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14541 if (i & (1 << 24))
477330fc 14542 i |= 1 << 28;
5f4273c7 14543
037e8744 14544 i &= ~(1 << 24);
5f4273c7 14545
037e8744
JB
14546 i |= 0xef000000;
14547 }
14548 else
14549 i |= 0xf2000000;
5f4273c7 14550
88714cb8 14551 insn->instruction = i;
037e8744
JB
14552}
14553
14554/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14555 (0, 1, 2, 3). */
14556
14557static unsigned
14558neon_logbits (unsigned x)
14559{
14560 return ffs (x) - 4;
14561}
14562
14563#define LOW4(R) ((R) & 0xf)
14564#define HI1(R) (((R) >> 4) & 1)
14565
14566/* Encode insns with bit pattern:
14567
14568 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14569 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14570
037e8744
JB
14571 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14572 different meaning for some instruction. */
14573
14574static void
14575neon_three_same (int isquad, int ubit, int size)
14576{
14577 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14578 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14579 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14580 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14581 inst.instruction |= LOW4 (inst.operands[2].reg);
14582 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14583 inst.instruction |= (isquad != 0) << 6;
14584 inst.instruction |= (ubit != 0) << 24;
14585 if (size != -1)
14586 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14587
88714cb8 14588 neon_dp_fixup (&inst);
037e8744
JB
14589}
14590
14591/* Encode instructions of the form:
14592
14593 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14594 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14595
14596 Don't write size if SIZE == -1. */
14597
14598static void
14599neon_two_same (int qbit, int ubit, int size)
14600{
14601 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14602 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14603 inst.instruction |= LOW4 (inst.operands[1].reg);
14604 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14605 inst.instruction |= (qbit != 0) << 6;
14606 inst.instruction |= (ubit != 0) << 24;
14607
14608 if (size != -1)
14609 inst.instruction |= neon_logbits (size) << 18;
14610
88714cb8 14611 neon_dp_fixup (&inst);
5287ad62
JB
14612}
14613
14614/* Neon instruction encoders, in approximate order of appearance. */
14615
14616static void
14617do_neon_dyadic_i_su (void)
14618{
037e8744 14619 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14620 struct neon_type_el et = neon_check_type (3, rs,
14621 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14622 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14623}
14624
14625static void
14626do_neon_dyadic_i64_su (void)
14627{
037e8744 14628 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14629 struct neon_type_el et = neon_check_type (3, rs,
14630 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14631 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14632}
14633
14634static void
14635neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14636 unsigned immbits)
5287ad62
JB
14637{
14638 unsigned size = et.size >> 3;
14639 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14640 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14641 inst.instruction |= LOW4 (inst.operands[1].reg);
14642 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14643 inst.instruction |= (isquad != 0) << 6;
14644 inst.instruction |= immbits << 16;
14645 inst.instruction |= (size >> 3) << 7;
14646 inst.instruction |= (size & 0x7) << 19;
14647 if (write_ubit)
14648 inst.instruction |= (uval != 0) << 24;
14649
88714cb8 14650 neon_dp_fixup (&inst);
5287ad62
JB
14651}
14652
14653static void
14654do_neon_shl_imm (void)
14655{
14656 if (!inst.operands[2].isreg)
14657 {
037e8744 14658 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14659 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14660 int imm = inst.operands[2].imm;
14661
14662 constraint (imm < 0 || (unsigned)imm >= et.size,
14663 _("immediate out of range for shift"));
88714cb8 14664 NEON_ENCODE (IMMED, inst);
cb3b1e65 14665 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14666 }
14667 else
14668 {
037e8744 14669 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14670 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14671 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14672 unsigned int tmp;
14673
14674 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14675 vshl.xx Dd, Dm, Dn
14676 whereas other 3-register operations encoded by neon_three_same have
14677 syntax like:
14678 vadd.xx Dd, Dn, Dm
14679 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14680 here. */
627907b7
JB
14681 tmp = inst.operands[2].reg;
14682 inst.operands[2].reg = inst.operands[1].reg;
14683 inst.operands[1].reg = tmp;
88714cb8 14684 NEON_ENCODE (INTEGER, inst);
037e8744 14685 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14686 }
14687}
14688
14689static void
14690do_neon_qshl_imm (void)
14691{
14692 if (!inst.operands[2].isreg)
14693 {
037e8744 14694 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14695 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14696 int imm = inst.operands[2].imm;
627907b7 14697
cb3b1e65
JB
14698 constraint (imm < 0 || (unsigned)imm >= et.size,
14699 _("immediate out of range for shift"));
88714cb8 14700 NEON_ENCODE (IMMED, inst);
cb3b1e65 14701 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14702 }
14703 else
14704 {
037e8744 14705 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14706 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14707 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14708 unsigned int tmp;
14709
14710 /* See note in do_neon_shl_imm. */
14711 tmp = inst.operands[2].reg;
14712 inst.operands[2].reg = inst.operands[1].reg;
14713 inst.operands[1].reg = tmp;
88714cb8 14714 NEON_ENCODE (INTEGER, inst);
037e8744 14715 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14716 }
14717}
14718
627907b7
JB
14719static void
14720do_neon_rshl (void)
14721{
14722 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14723 struct neon_type_el et = neon_check_type (3, rs,
14724 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14725 unsigned int tmp;
14726
14727 tmp = inst.operands[2].reg;
14728 inst.operands[2].reg = inst.operands[1].reg;
14729 inst.operands[1].reg = tmp;
14730 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14731}
14732
5287ad62
JB
14733static int
14734neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14735{
036dc3f7
PB
14736 /* Handle .I8 pseudo-instructions. */
14737 if (size == 8)
5287ad62 14738 {
5287ad62 14739 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14740 FIXME is this the intended semantics? There doesn't seem much point in
14741 accepting .I8 if so. */
5287ad62
JB
14742 immediate |= immediate << 8;
14743 size = 16;
036dc3f7
PB
14744 }
14745
14746 if (size >= 32)
14747 {
14748 if (immediate == (immediate & 0x000000ff))
14749 {
14750 *immbits = immediate;
14751 return 0x1;
14752 }
14753 else if (immediate == (immediate & 0x0000ff00))
14754 {
14755 *immbits = immediate >> 8;
14756 return 0x3;
14757 }
14758 else if (immediate == (immediate & 0x00ff0000))
14759 {
14760 *immbits = immediate >> 16;
14761 return 0x5;
14762 }
14763 else if (immediate == (immediate & 0xff000000))
14764 {
14765 *immbits = immediate >> 24;
14766 return 0x7;
14767 }
14768 if ((immediate & 0xffff) != (immediate >> 16))
14769 goto bad_immediate;
14770 immediate &= 0xffff;
5287ad62
JB
14771 }
14772
14773 if (immediate == (immediate & 0x000000ff))
14774 {
14775 *immbits = immediate;
036dc3f7 14776 return 0x9;
5287ad62
JB
14777 }
14778 else if (immediate == (immediate & 0x0000ff00))
14779 {
14780 *immbits = immediate >> 8;
036dc3f7 14781 return 0xb;
5287ad62
JB
14782 }
14783
14784 bad_immediate:
dcbf9037 14785 first_error (_("immediate value out of range"));
5287ad62
JB
14786 return FAIL;
14787}
14788
5287ad62
JB
14789static void
14790do_neon_logic (void)
14791{
14792 if (inst.operands[2].present && inst.operands[2].isreg)
14793 {
037e8744 14794 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14795 neon_check_type (3, rs, N_IGNORE_TYPE);
14796 /* U bit and size field were set as part of the bitmask. */
88714cb8 14797 NEON_ENCODE (INTEGER, inst);
037e8744 14798 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14799 }
14800 else
14801 {
4316f0d2
DG
14802 const int three_ops_form = (inst.operands[2].present
14803 && !inst.operands[2].isreg);
14804 const int immoperand = (three_ops_form ? 2 : 1);
14805 enum neon_shape rs = (three_ops_form
14806 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14807 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14808 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14809 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14810 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14811 unsigned immbits;
14812 int cmode;
5f4273c7 14813
5287ad62 14814 if (et.type == NT_invtype)
477330fc 14815 return;
5f4273c7 14816
4316f0d2
DG
14817 if (three_ops_form)
14818 constraint (inst.operands[0].reg != inst.operands[1].reg,
14819 _("first and second operands shall be the same register"));
14820
88714cb8 14821 NEON_ENCODE (IMMED, inst);
5287ad62 14822
4316f0d2 14823 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14824 if (et.size == 64)
14825 {
14826 /* .i64 is a pseudo-op, so the immediate must be a repeating
14827 pattern. */
4316f0d2
DG
14828 if (immbits != (inst.operands[immoperand].regisimm ?
14829 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14830 {
14831 /* Set immbits to an invalid constant. */
14832 immbits = 0xdeadbeef;
14833 }
14834 }
14835
5287ad62 14836 switch (opcode)
477330fc
RM
14837 {
14838 case N_MNEM_vbic:
14839 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14840 break;
14841
14842 case N_MNEM_vorr:
14843 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14844 break;
14845
14846 case N_MNEM_vand:
14847 /* Pseudo-instruction for VBIC. */
14848 neon_invert_size (&immbits, 0, et.size);
14849 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14850 break;
14851
14852 case N_MNEM_vorn:
14853 /* Pseudo-instruction for VORR. */
14854 neon_invert_size (&immbits, 0, et.size);
14855 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14856 break;
14857
14858 default:
14859 abort ();
14860 }
5287ad62
JB
14861
14862 if (cmode == FAIL)
477330fc 14863 return;
5287ad62 14864
037e8744 14865 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14866 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14867 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14868 inst.instruction |= cmode << 8;
14869 neon_write_immbits (immbits);
5f4273c7 14870
88714cb8 14871 neon_dp_fixup (&inst);
5287ad62
JB
14872 }
14873}
14874
14875static void
14876do_neon_bitfield (void)
14877{
037e8744 14878 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14879 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14880 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14881}
14882
14883static void
dcbf9037 14884neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14885 unsigned destbits)
5287ad62 14886{
037e8744 14887 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14888 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14889 types | N_KEY);
5287ad62
JB
14890 if (et.type == NT_float)
14891 {
88714cb8 14892 NEON_ENCODE (FLOAT, inst);
cc933301 14893 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14894 }
14895 else
14896 {
88714cb8 14897 NEON_ENCODE (INTEGER, inst);
037e8744 14898 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14899 }
14900}
14901
14902static void
14903do_neon_dyadic_if_su (void)
14904{
dcbf9037 14905 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14906}
14907
14908static void
14909do_neon_dyadic_if_su_d (void)
14910{
14911 /* This version only allow D registers, but that constraint is enforced during
14912 operand parsing so we don't need to do anything extra here. */
dcbf9037 14913 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14914}
14915
5287ad62
JB
14916static void
14917do_neon_dyadic_if_i_d (void)
14918{
428e3f1f
PB
14919 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14920 affected if we specify unsigned args. */
14921 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14922}
14923
037e8744
JB
14924enum vfp_or_neon_is_neon_bits
14925{
14926 NEON_CHECK_CC = 1,
73924fbc
MGD
14927 NEON_CHECK_ARCH = 2,
14928 NEON_CHECK_ARCH8 = 4
037e8744
JB
14929};
14930
14931/* Call this function if an instruction which may have belonged to the VFP or
14932 Neon instruction sets, but turned out to be a Neon instruction (due to the
14933 operand types involved, etc.). We have to check and/or fix-up a couple of
14934 things:
14935
14936 - Make sure the user hasn't attempted to make a Neon instruction
14937 conditional.
14938 - Alter the value in the condition code field if necessary.
14939 - Make sure that the arch supports Neon instructions.
14940
14941 Which of these operations take place depends on bits from enum
14942 vfp_or_neon_is_neon_bits.
14943
14944 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14945 current instruction's condition is COND_ALWAYS, the condition field is
14946 changed to inst.uncond_value. This is necessary because instructions shared
14947 between VFP and Neon may be conditional for the VFP variants only, and the
14948 unconditional Neon version must have, e.g., 0xF in the condition field. */
14949
14950static int
14951vfp_or_neon_is_neon (unsigned check)
14952{
14953 /* Conditions are always legal in Thumb mode (IT blocks). */
14954 if (!thumb_mode && (check & NEON_CHECK_CC))
14955 {
14956 if (inst.cond != COND_ALWAYS)
477330fc
RM
14957 {
14958 first_error (_(BAD_COND));
14959 return FAIL;
14960 }
037e8744 14961 if (inst.uncond_value != -1)
477330fc 14962 inst.instruction |= inst.uncond_value << 28;
037e8744 14963 }
5f4273c7 14964
037e8744 14965 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14966 && !mark_feature_used (&fpu_neon_ext_v1))
14967 {
14968 first_error (_(BAD_FPU));
14969 return FAIL;
14970 }
14971
14972 if ((check & NEON_CHECK_ARCH8)
14973 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14974 {
14975 first_error (_(BAD_FPU));
14976 return FAIL;
14977 }
5f4273c7 14978
037e8744
JB
14979 return SUCCESS;
14980}
14981
5287ad62
JB
14982static void
14983do_neon_addsub_if_i (void)
14984{
037e8744
JB
14985 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14986 return;
14987
14988 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14989 return;
14990
5287ad62
JB
14991 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14992 affected if we specify unsigned args. */
dcbf9037 14993 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14994}
14995
14996/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14997 result to be:
14998 V<op> A,B (A is operand 0, B is operand 2)
14999 to mean:
15000 V<op> A,B,A
15001 not:
15002 V<op> A,B,B
15003 so handle that case specially. */
15004
15005static void
15006neon_exchange_operands (void)
15007{
5287ad62
JB
15008 if (inst.operands[1].present)
15009 {
e1fa0163
NC
15010 void *scratch = xmalloc (sizeof (inst.operands[0]));
15011
5287ad62
JB
15012 /* Swap operands[1] and operands[2]. */
15013 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15014 inst.operands[1] = inst.operands[2];
15015 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 15016 free (scratch);
5287ad62
JB
15017 }
15018 else
15019 {
15020 inst.operands[1] = inst.operands[2];
15021 inst.operands[2] = inst.operands[0];
15022 }
15023}
15024
15025static void
15026neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15027{
15028 if (inst.operands[2].isreg)
15029 {
15030 if (invert)
477330fc 15031 neon_exchange_operands ();
dcbf9037 15032 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
15033 }
15034 else
15035 {
037e8744 15036 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 15037 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15038 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15039
88714cb8 15040 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15042 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15043 inst.instruction |= LOW4 (inst.operands[1].reg);
15044 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15045 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15046 inst.instruction |= (et.type == NT_float) << 10;
15047 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15048
88714cb8 15049 neon_dp_fixup (&inst);
5287ad62
JB
15050 }
15051}
15052
15053static void
15054do_neon_cmp (void)
15055{
cc933301 15056 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15057}
15058
15059static void
15060do_neon_cmp_inv (void)
15061{
cc933301 15062 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15063}
15064
15065static void
15066do_neon_ceq (void)
15067{
15068 neon_compare (N_IF_32, N_IF_32, FALSE);
15069}
15070
15071/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15072 scalars, which are encoded in 5 bits, M : Rm.
15073 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15074 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
c604a79a
JW
15075 index in M.
15076
15077 Dot Product instructions are similar to multiply instructions except elsize
15078 should always be 32.
15079
15080 This function translates SCALAR, which is GAS's internal encoding of indexed
15081 scalar register, to raw encoding. There is also register and index range
15082 check based on ELSIZE. */
5287ad62
JB
15083
15084static unsigned
15085neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15086{
dcbf9037
JB
15087 unsigned regno = NEON_SCALAR_REG (scalar);
15088 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15089
15090 switch (elsize)
15091 {
15092 case 16:
15093 if (regno > 7 || elno > 3)
477330fc 15094 goto bad_scalar;
5287ad62 15095 return regno | (elno << 3);
5f4273c7 15096
5287ad62
JB
15097 case 32:
15098 if (regno > 15 || elno > 1)
477330fc 15099 goto bad_scalar;
5287ad62
JB
15100 return regno | (elno << 4);
15101
15102 default:
15103 bad_scalar:
dcbf9037 15104 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15105 }
15106
15107 return 0;
15108}
15109
15110/* Encode multiply / multiply-accumulate scalar instructions. */
15111
15112static void
15113neon_mul_mac (struct neon_type_el et, int ubit)
15114{
dcbf9037
JB
15115 unsigned scalar;
15116
15117 /* Give a more helpful error message if we have an invalid type. */
15118 if (et.type == NT_invtype)
15119 return;
5f4273c7 15120
dcbf9037 15121 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15122 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15123 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15124 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15125 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15126 inst.instruction |= LOW4 (scalar);
15127 inst.instruction |= HI1 (scalar) << 5;
15128 inst.instruction |= (et.type == NT_float) << 8;
15129 inst.instruction |= neon_logbits (et.size) << 20;
15130 inst.instruction |= (ubit != 0) << 24;
15131
88714cb8 15132 neon_dp_fixup (&inst);
5287ad62
JB
15133}
15134
15135static void
15136do_neon_mac_maybe_scalar (void)
15137{
037e8744
JB
15138 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15139 return;
15140
15141 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15142 return;
15143
5287ad62
JB
15144 if (inst.operands[2].isscalar)
15145 {
037e8744 15146 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15147 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15148 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15149 NEON_ENCODE (SCALAR, inst);
037e8744 15150 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15151 }
15152 else
428e3f1f
PB
15153 {
15154 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15155 affected if we specify unsigned args. */
15156 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15157 }
5287ad62
JB
15158}
15159
62f3b8c8
PB
15160static void
15161do_neon_fmac (void)
15162{
15163 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15164 return;
15165
15166 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15167 return;
15168
15169 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15170}
15171
5287ad62
JB
15172static void
15173do_neon_tst (void)
15174{
037e8744 15175 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15176 struct neon_type_el et = neon_check_type (3, rs,
15177 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15178 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15179}
15180
15181/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15182 same types as the MAC equivalents. The polynomial type for this instruction
15183 is encoded the same as the integer type. */
15184
15185static void
15186do_neon_mul (void)
15187{
037e8744
JB
15188 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15189 return;
15190
15191 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15192 return;
15193
5287ad62
JB
15194 if (inst.operands[2].isscalar)
15195 do_neon_mac_maybe_scalar ();
15196 else
cc933301 15197 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15198}
15199
15200static void
15201do_neon_qdmulh (void)
15202{
15203 if (inst.operands[2].isscalar)
15204 {
037e8744 15205 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15206 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15207 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15208 NEON_ENCODE (SCALAR, inst);
037e8744 15209 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15210 }
15211 else
15212 {
037e8744 15213 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15214 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15215 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15216 NEON_ENCODE (INTEGER, inst);
5287ad62 15217 /* The U bit (rounding) comes from bit mask. */
037e8744 15218 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15219 }
15220}
15221
643afb90
MW
15222static void
15223do_neon_qrdmlah (void)
15224{
15225 /* Check we're on the correct architecture. */
15226 if (!mark_feature_used (&fpu_neon_ext_armv8))
15227 inst.error =
15228 _("instruction form not available on this architecture.");
15229 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15230 {
15231 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15232 record_feature_use (&fpu_neon_ext_v8_1);
15233 }
15234
15235 if (inst.operands[2].isscalar)
15236 {
15237 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15238 struct neon_type_el et = neon_check_type (3, rs,
15239 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15240 NEON_ENCODE (SCALAR, inst);
15241 neon_mul_mac (et, neon_quad (rs));
15242 }
15243 else
15244 {
15245 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15246 struct neon_type_el et = neon_check_type (3, rs,
15247 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15248 NEON_ENCODE (INTEGER, inst);
15249 /* The U bit (rounding) comes from bit mask. */
15250 neon_three_same (neon_quad (rs), 0, et.size);
15251 }
15252}
15253
5287ad62
JB
15254static void
15255do_neon_fcmp_absolute (void)
15256{
037e8744 15257 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15258 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15259 N_F_16_32 | N_KEY);
5287ad62 15260 /* Size field comes from bit mask. */
cc933301 15261 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15262}
15263
15264static void
15265do_neon_fcmp_absolute_inv (void)
15266{
15267 neon_exchange_operands ();
15268 do_neon_fcmp_absolute ();
15269}
15270
15271static void
15272do_neon_step (void)
15273{
037e8744 15274 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15275 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15276 N_F_16_32 | N_KEY);
15277 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15278}
15279
15280static void
15281do_neon_abs_neg (void)
15282{
037e8744
JB
15283 enum neon_shape rs;
15284 struct neon_type_el et;
5f4273c7 15285
037e8744
JB
15286 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15287 return;
15288
15289 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15290 return;
15291
15292 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15293 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15294
5287ad62
JB
15295 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15296 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15297 inst.instruction |= LOW4 (inst.operands[1].reg);
15298 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15299 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15300 inst.instruction |= (et.type == NT_float) << 10;
15301 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15302
88714cb8 15303 neon_dp_fixup (&inst);
5287ad62
JB
15304}
15305
15306static void
15307do_neon_sli (void)
15308{
037e8744 15309 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15310 struct neon_type_el et = neon_check_type (2, rs,
15311 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15312 int imm = inst.operands[2].imm;
15313 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15314 _("immediate out of range for insert"));
037e8744 15315 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15316}
15317
15318static void
15319do_neon_sri (void)
15320{
037e8744 15321 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15322 struct neon_type_el et = neon_check_type (2, rs,
15323 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15324 int imm = inst.operands[2].imm;
15325 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15326 _("immediate out of range for insert"));
037e8744 15327 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15328}
15329
15330static void
15331do_neon_qshlu_imm (void)
15332{
037e8744 15333 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15334 struct neon_type_el et = neon_check_type (2, rs,
15335 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15336 int imm = inst.operands[2].imm;
15337 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15338 _("immediate out of range for shift"));
5287ad62
JB
15339 /* Only encodes the 'U present' variant of the instruction.
15340 In this case, signed types have OP (bit 8) set to 0.
15341 Unsigned types have OP set to 1. */
15342 inst.instruction |= (et.type == NT_unsigned) << 8;
15343 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15344 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15345}
15346
15347static void
15348do_neon_qmovn (void)
15349{
15350 struct neon_type_el et = neon_check_type (2, NS_DQ,
15351 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15352 /* Saturating move where operands can be signed or unsigned, and the
15353 destination has the same signedness. */
88714cb8 15354 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15355 if (et.type == NT_unsigned)
15356 inst.instruction |= 0xc0;
15357 else
15358 inst.instruction |= 0x80;
15359 neon_two_same (0, 1, et.size / 2);
15360}
15361
15362static void
15363do_neon_qmovun (void)
15364{
15365 struct neon_type_el et = neon_check_type (2, NS_DQ,
15366 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15367 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15368 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15369 neon_two_same (0, 1, et.size / 2);
15370}
15371
15372static void
15373do_neon_rshift_sat_narrow (void)
15374{
15375 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15376 or unsigned. If operands are unsigned, results must also be unsigned. */
15377 struct neon_type_el et = neon_check_type (2, NS_DQI,
15378 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15379 int imm = inst.operands[2].imm;
15380 /* This gets the bounds check, size encoding and immediate bits calculation
15381 right. */
15382 et.size /= 2;
5f4273c7 15383
5287ad62
JB
15384 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15385 VQMOVN.I<size> <Dd>, <Qm>. */
15386 if (imm == 0)
15387 {
15388 inst.operands[2].present = 0;
15389 inst.instruction = N_MNEM_vqmovn;
15390 do_neon_qmovn ();
15391 return;
15392 }
5f4273c7 15393
5287ad62 15394 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15395 _("immediate out of range"));
5287ad62
JB
15396 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15397}
15398
15399static void
15400do_neon_rshift_sat_narrow_u (void)
15401{
15402 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15403 or unsigned. If operands are unsigned, results must also be unsigned. */
15404 struct neon_type_el et = neon_check_type (2, NS_DQI,
15405 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15406 int imm = inst.operands[2].imm;
15407 /* This gets the bounds check, size encoding and immediate bits calculation
15408 right. */
15409 et.size /= 2;
15410
15411 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15412 VQMOVUN.I<size> <Dd>, <Qm>. */
15413 if (imm == 0)
15414 {
15415 inst.operands[2].present = 0;
15416 inst.instruction = N_MNEM_vqmovun;
15417 do_neon_qmovun ();
15418 return;
15419 }
15420
15421 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15422 _("immediate out of range"));
5287ad62
JB
15423 /* FIXME: The manual is kind of unclear about what value U should have in
15424 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15425 must be 1. */
15426 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15427}
15428
15429static void
15430do_neon_movn (void)
15431{
15432 struct neon_type_el et = neon_check_type (2, NS_DQ,
15433 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15434 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15435 neon_two_same (0, 1, et.size / 2);
15436}
15437
15438static void
15439do_neon_rshift_narrow (void)
15440{
15441 struct neon_type_el et = neon_check_type (2, NS_DQI,
15442 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15443 int imm = inst.operands[2].imm;
15444 /* This gets the bounds check, size encoding and immediate bits calculation
15445 right. */
15446 et.size /= 2;
5f4273c7 15447
5287ad62
JB
15448 /* If immediate is zero then we are a pseudo-instruction for
15449 VMOVN.I<size> <Dd>, <Qm> */
15450 if (imm == 0)
15451 {
15452 inst.operands[2].present = 0;
15453 inst.instruction = N_MNEM_vmovn;
15454 do_neon_movn ();
15455 return;
15456 }
5f4273c7 15457
5287ad62 15458 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15459 _("immediate out of range for narrowing operation"));
5287ad62
JB
15460 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15461}
15462
15463static void
15464do_neon_shll (void)
15465{
15466 /* FIXME: Type checking when lengthening. */
15467 struct neon_type_el et = neon_check_type (2, NS_QDI,
15468 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15469 unsigned imm = inst.operands[2].imm;
15470
15471 if (imm == et.size)
15472 {
15473 /* Maximum shift variant. */
88714cb8 15474 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15475 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15476 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15477 inst.instruction |= LOW4 (inst.operands[1].reg);
15478 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15479 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15480
88714cb8 15481 neon_dp_fixup (&inst);
5287ad62
JB
15482 }
15483 else
15484 {
15485 /* A more-specific type check for non-max versions. */
15486 et = neon_check_type (2, NS_QDI,
477330fc 15487 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15488 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15489 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15490 }
15491}
15492
037e8744 15493/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15494 the current instruction is. */
15495
6b9a8b67
MGD
15496#define CVT_FLAVOUR_VAR \
15497 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15498 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15499 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15500 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15501 /* Half-precision conversions. */ \
cc933301
JW
15502 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15503 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15504 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15505 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15506 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15507 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15508 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15509 Compared with single/double precision variants, only the co-processor \
15510 field is different, so the encoding flow is reused here. */ \
15511 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15512 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15513 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15514 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15515 /* VFP instructions. */ \
15516 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15517 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15518 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15519 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15520 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15521 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15522 /* VFP instructions with bitshift. */ \
15523 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15524 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15525 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15526 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15527 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15528 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15529 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15530 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15531
15532#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15533 neon_cvt_flavour_##C,
15534
15535/* The different types of conversions we can do. */
15536enum neon_cvt_flavour
15537{
15538 CVT_FLAVOUR_VAR
15539 neon_cvt_flavour_invalid,
15540 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15541};
15542
15543#undef CVT_VAR
15544
15545static enum neon_cvt_flavour
15546get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15547{
6b9a8b67
MGD
15548#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15549 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15550 if (et.type != NT_invtype) \
15551 { \
15552 inst.error = NULL; \
15553 return (neon_cvt_flavour_##C); \
5287ad62 15554 }
6b9a8b67 15555
5287ad62 15556 struct neon_type_el et;
037e8744 15557 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15558 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15559 /* The instruction versions which take an immediate take one register
15560 argument, which is extended to the width of the full register. Thus the
15561 "source" and "destination" registers must have the same width. Hack that
15562 here by making the size equal to the key (wider, in this case) operand. */
15563 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15564
6b9a8b67
MGD
15565 CVT_FLAVOUR_VAR;
15566
15567 return neon_cvt_flavour_invalid;
5287ad62
JB
15568#undef CVT_VAR
15569}
15570
7e8e6784
MGD
15571enum neon_cvt_mode
15572{
15573 neon_cvt_mode_a,
15574 neon_cvt_mode_n,
15575 neon_cvt_mode_p,
15576 neon_cvt_mode_m,
15577 neon_cvt_mode_z,
30bdf752
MGD
15578 neon_cvt_mode_x,
15579 neon_cvt_mode_r
7e8e6784
MGD
15580};
15581
037e8744
JB
15582/* Neon-syntax VFP conversions. */
15583
5287ad62 15584static void
6b9a8b67 15585do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15586{
037e8744 15587 const char *opname = 0;
5f4273c7 15588
d54af2d0
RL
15589 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15590 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15591 {
037e8744
JB
15592 /* Conversions with immediate bitshift. */
15593 const char *enc[] =
477330fc 15594 {
6b9a8b67
MGD
15595#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15596 CVT_FLAVOUR_VAR
15597 NULL
15598#undef CVT_VAR
477330fc 15599 };
037e8744 15600
6b9a8b67 15601 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15602 {
15603 opname = enc[flavour];
15604 constraint (inst.operands[0].reg != inst.operands[1].reg,
15605 _("operands 0 and 1 must be the same register"));
15606 inst.operands[1] = inst.operands[2];
15607 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15608 }
5287ad62
JB
15609 }
15610 else
15611 {
037e8744
JB
15612 /* Conversions without bitshift. */
15613 const char *enc[] =
477330fc 15614 {
6b9a8b67
MGD
15615#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15616 CVT_FLAVOUR_VAR
15617 NULL
15618#undef CVT_VAR
477330fc 15619 };
037e8744 15620
6b9a8b67 15621 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15622 opname = enc[flavour];
037e8744
JB
15623 }
15624
15625 if (opname)
15626 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15627
15628 /* ARMv8.2 fp16 VCVT instruction. */
15629 if (flavour == neon_cvt_flavour_s32_f16
15630 || flavour == neon_cvt_flavour_u32_f16
15631 || flavour == neon_cvt_flavour_f16_u32
15632 || flavour == neon_cvt_flavour_f16_s32)
15633 do_scalar_fp16_v82_encode ();
037e8744
JB
15634}
15635
15636static void
15637do_vfp_nsyn_cvtz (void)
15638{
d54af2d0 15639 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15640 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15641 const char *enc[] =
15642 {
6b9a8b67
MGD
15643#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15644 CVT_FLAVOUR_VAR
15645 NULL
15646#undef CVT_VAR
037e8744
JB
15647 };
15648
6b9a8b67 15649 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15650 do_vfp_nsyn_opcode (enc[flavour]);
15651}
f31fef98 15652
037e8744 15653static void
bacebabc 15654do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15655 enum neon_cvt_mode mode)
15656{
15657 int sz, op;
15658 int rm;
15659
a715796b
TG
15660 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15661 D register operands. */
15662 if (flavour == neon_cvt_flavour_s32_f64
15663 || flavour == neon_cvt_flavour_u32_f64)
15664 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15665 _(BAD_FPU));
15666
9db2f6b4
RL
15667 if (flavour == neon_cvt_flavour_s32_f16
15668 || flavour == neon_cvt_flavour_u32_f16)
15669 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15670 _(BAD_FP16));
15671
7e8e6784
MGD
15672 set_it_insn_type (OUTSIDE_IT_INSN);
15673
15674 switch (flavour)
15675 {
15676 case neon_cvt_flavour_s32_f64:
15677 sz = 1;
827f64ff 15678 op = 1;
7e8e6784
MGD
15679 break;
15680 case neon_cvt_flavour_s32_f32:
15681 sz = 0;
15682 op = 1;
15683 break;
9db2f6b4
RL
15684 case neon_cvt_flavour_s32_f16:
15685 sz = 0;
15686 op = 1;
15687 break;
7e8e6784
MGD
15688 case neon_cvt_flavour_u32_f64:
15689 sz = 1;
15690 op = 0;
15691 break;
15692 case neon_cvt_flavour_u32_f32:
15693 sz = 0;
15694 op = 0;
15695 break;
9db2f6b4
RL
15696 case neon_cvt_flavour_u32_f16:
15697 sz = 0;
15698 op = 0;
15699 break;
7e8e6784
MGD
15700 default:
15701 first_error (_("invalid instruction shape"));
15702 return;
15703 }
15704
15705 switch (mode)
15706 {
15707 case neon_cvt_mode_a: rm = 0; break;
15708 case neon_cvt_mode_n: rm = 1; break;
15709 case neon_cvt_mode_p: rm = 2; break;
15710 case neon_cvt_mode_m: rm = 3; break;
15711 default: first_error (_("invalid rounding mode")); return;
15712 }
15713
15714 NEON_ENCODE (FPV8, inst);
15715 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15716 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15717 inst.instruction |= sz << 8;
9db2f6b4
RL
15718
15719 /* ARMv8.2 fp16 VCVT instruction. */
15720 if (flavour == neon_cvt_flavour_s32_f16
15721 ||flavour == neon_cvt_flavour_u32_f16)
15722 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15723 inst.instruction |= op << 7;
15724 inst.instruction |= rm << 16;
15725 inst.instruction |= 0xf0000000;
15726 inst.is_neon = TRUE;
15727}
15728
15729static void
15730do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15731{
15732 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15733 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15734 NS_FH, NS_HF, NS_FHI, NS_HFI,
15735 NS_NULL);
6b9a8b67 15736 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15737
cc933301
JW
15738 if (flavour == neon_cvt_flavour_invalid)
15739 return;
15740
e3e535bc 15741 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15742 if (mode == neon_cvt_mode_z
e3e535bc 15743 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15744 && (flavour == neon_cvt_flavour_s16_f16
15745 || flavour == neon_cvt_flavour_u16_f16
15746 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15747 || flavour == neon_cvt_flavour_u32_f32
15748 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15749 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15750 && (rs == NS_FD || rs == NS_FF))
15751 {
15752 do_vfp_nsyn_cvtz ();
15753 return;
15754 }
15755
9db2f6b4
RL
15756 /* ARMv8.2 fp16 VCVT conversions. */
15757 if (mode == neon_cvt_mode_z
15758 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15759 && (flavour == neon_cvt_flavour_s32_f16
15760 || flavour == neon_cvt_flavour_u32_f16)
15761 && (rs == NS_FH))
15762 {
15763 do_vfp_nsyn_cvtz ();
15764 do_scalar_fp16_v82_encode ();
15765 return;
15766 }
15767
037e8744 15768 /* VFP rather than Neon conversions. */
6b9a8b67 15769 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15770 {
7e8e6784
MGD
15771 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15772 do_vfp_nsyn_cvt (rs, flavour);
15773 else
15774 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15775
037e8744
JB
15776 return;
15777 }
15778
15779 switch (rs)
15780 {
15781 case NS_DDI:
15782 case NS_QQI:
15783 {
477330fc 15784 unsigned immbits;
cc933301
JW
15785 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15786 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15787
477330fc
RM
15788 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15789 return;
037e8744 15790
477330fc
RM
15791 /* Fixed-point conversion with #0 immediate is encoded as an
15792 integer conversion. */
15793 if (inst.operands[2].present && inst.operands[2].imm == 0)
15794 goto int_encode;
477330fc
RM
15795 NEON_ENCODE (IMMED, inst);
15796 if (flavour != neon_cvt_flavour_invalid)
15797 inst.instruction |= enctab[flavour];
15798 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15799 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15800 inst.instruction |= LOW4 (inst.operands[1].reg);
15801 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15802 inst.instruction |= neon_quad (rs) << 6;
15803 inst.instruction |= 1 << 21;
cc933301
JW
15804 if (flavour < neon_cvt_flavour_s16_f16)
15805 {
15806 inst.instruction |= 1 << 21;
15807 immbits = 32 - inst.operands[2].imm;
15808 inst.instruction |= immbits << 16;
15809 }
15810 else
15811 {
15812 inst.instruction |= 3 << 20;
15813 immbits = 16 - inst.operands[2].imm;
15814 inst.instruction |= immbits << 16;
15815 inst.instruction &= ~(1 << 9);
15816 }
477330fc
RM
15817
15818 neon_dp_fixup (&inst);
037e8744
JB
15819 }
15820 break;
15821
15822 case NS_DD:
15823 case NS_QQ:
7e8e6784
MGD
15824 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15825 {
15826 NEON_ENCODE (FLOAT, inst);
15827 set_it_insn_type (OUTSIDE_IT_INSN);
15828
15829 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15830 return;
15831
15832 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15833 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15834 inst.instruction |= LOW4 (inst.operands[1].reg);
15835 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15836 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15837 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15838 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15839 inst.instruction |= mode << 8;
cc933301
JW
15840 if (flavour == neon_cvt_flavour_u16_f16
15841 || flavour == neon_cvt_flavour_s16_f16)
15842 /* Mask off the original size bits and reencode them. */
15843 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15844
7e8e6784
MGD
15845 if (thumb_mode)
15846 inst.instruction |= 0xfc000000;
15847 else
15848 inst.instruction |= 0xf0000000;
15849 }
15850 else
15851 {
037e8744 15852 int_encode:
7e8e6784 15853 {
cc933301
JW
15854 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15855 0x100, 0x180, 0x0, 0x080};
037e8744 15856
7e8e6784 15857 NEON_ENCODE (INTEGER, inst);
037e8744 15858
7e8e6784
MGD
15859 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15860 return;
037e8744 15861
7e8e6784
MGD
15862 if (flavour != neon_cvt_flavour_invalid)
15863 inst.instruction |= enctab[flavour];
037e8744 15864
7e8e6784
MGD
15865 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15866 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15867 inst.instruction |= LOW4 (inst.operands[1].reg);
15868 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15869 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15870 if (flavour >= neon_cvt_flavour_s16_f16
15871 && flavour <= neon_cvt_flavour_f16_u16)
15872 /* Half precision. */
15873 inst.instruction |= 1 << 18;
15874 else
15875 inst.instruction |= 2 << 18;
037e8744 15876
7e8e6784
MGD
15877 neon_dp_fixup (&inst);
15878 }
15879 }
15880 break;
037e8744 15881
8e79c3df
CM
15882 /* Half-precision conversions for Advanced SIMD -- neon. */
15883 case NS_QD:
15884 case NS_DQ:
15885
15886 if ((rs == NS_DQ)
15887 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15888 {
15889 as_bad (_("operand size must match register width"));
15890 break;
15891 }
15892
15893 if ((rs == NS_QD)
15894 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15895 {
15896 as_bad (_("operand size must match register width"));
15897 break;
15898 }
15899
15900 if (rs == NS_DQ)
477330fc 15901 inst.instruction = 0x3b60600;
8e79c3df
CM
15902 else
15903 inst.instruction = 0x3b60700;
15904
15905 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15906 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15907 inst.instruction |= LOW4 (inst.operands[1].reg);
15908 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15909 neon_dp_fixup (&inst);
8e79c3df
CM
15910 break;
15911
037e8744
JB
15912 default:
15913 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15914 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15915 do_vfp_nsyn_cvt (rs, flavour);
15916 else
15917 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15918 }
5287ad62
JB
15919}
15920
e3e535bc
NC
15921static void
15922do_neon_cvtr (void)
15923{
7e8e6784 15924 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15925}
15926
15927static void
15928do_neon_cvt (void)
15929{
7e8e6784
MGD
15930 do_neon_cvt_1 (neon_cvt_mode_z);
15931}
15932
15933static void
15934do_neon_cvta (void)
15935{
15936 do_neon_cvt_1 (neon_cvt_mode_a);
15937}
15938
15939static void
15940do_neon_cvtn (void)
15941{
15942 do_neon_cvt_1 (neon_cvt_mode_n);
15943}
15944
15945static void
15946do_neon_cvtp (void)
15947{
15948 do_neon_cvt_1 (neon_cvt_mode_p);
15949}
15950
15951static void
15952do_neon_cvtm (void)
15953{
15954 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15955}
15956
8e79c3df 15957static void
c70a8987 15958do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15959{
c70a8987
MGD
15960 if (is_double)
15961 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15962
c70a8987
MGD
15963 encode_arm_vfp_reg (inst.operands[0].reg,
15964 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15965 encode_arm_vfp_reg (inst.operands[1].reg,
15966 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15967 inst.instruction |= to ? 0x10000 : 0;
15968 inst.instruction |= t ? 0x80 : 0;
15969 inst.instruction |= is_double ? 0x100 : 0;
15970 do_vfp_cond_or_thumb ();
15971}
8e79c3df 15972
c70a8987
MGD
15973static void
15974do_neon_cvttb_1 (bfd_boolean t)
15975{
d54af2d0
RL
15976 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15977 NS_DF, NS_DH, NS_NULL);
8e79c3df 15978
c70a8987
MGD
15979 if (rs == NS_NULL)
15980 return;
15981 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15982 {
15983 inst.error = NULL;
15984 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15985 }
15986 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15987 {
15988 inst.error = NULL;
15989 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15990 }
15991 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15992 {
a715796b
TG
15993 /* The VCVTB and VCVTT instructions with D-register operands
15994 don't work for SP only targets. */
15995 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15996 _(BAD_FPU));
15997
c70a8987
MGD
15998 inst.error = NULL;
15999 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16000 }
16001 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16002 {
a715796b
TG
16003 /* The VCVTB and VCVTT instructions with D-register operands
16004 don't work for SP only targets. */
16005 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16006 _(BAD_FPU));
16007
c70a8987
MGD
16008 inst.error = NULL;
16009 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16010 }
16011 else
16012 return;
16013}
16014
16015static void
16016do_neon_cvtb (void)
16017{
16018 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
16019}
16020
16021
16022static void
16023do_neon_cvtt (void)
16024{
c70a8987 16025 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
16026}
16027
5287ad62
JB
16028static void
16029neon_move_immediate (void)
16030{
037e8744
JB
16031 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16032 struct neon_type_el et = neon_check_type (2, rs,
16033 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 16034 unsigned immlo, immhi = 0, immbits;
c96612cc 16035 int op, cmode, float_p;
5287ad62 16036
037e8744 16037 constraint (et.type == NT_invtype,
477330fc 16038 _("operand size must be specified for immediate VMOV"));
037e8744 16039
5287ad62
JB
16040 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16041 op = (inst.instruction & (1 << 5)) != 0;
16042
16043 immlo = inst.operands[1].imm;
16044 if (inst.operands[1].regisimm)
16045 immhi = inst.operands[1].reg;
16046
16047 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16048 _("immediate has bits set outside the operand size"));
5287ad62 16049
c96612cc
JB
16050 float_p = inst.operands[1].immisfloat;
16051
16052 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16053 et.size, et.type)) == FAIL)
5287ad62
JB
16054 {
16055 /* Invert relevant bits only. */
16056 neon_invert_size (&immlo, &immhi, et.size);
16057 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16058 with one or the other; those cases are caught by
16059 neon_cmode_for_move_imm. */
5287ad62 16060 op = !op;
c96612cc
JB
16061 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16062 &op, et.size, et.type)) == FAIL)
477330fc
RM
16063 {
16064 first_error (_("immediate out of range"));
16065 return;
16066 }
5287ad62
JB
16067 }
16068
16069 inst.instruction &= ~(1 << 5);
16070 inst.instruction |= op << 5;
16071
16072 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16073 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16074 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16075 inst.instruction |= cmode << 8;
16076
16077 neon_write_immbits (immbits);
16078}
16079
16080static void
16081do_neon_mvn (void)
16082{
16083 if (inst.operands[1].isreg)
16084 {
037e8744 16085 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16086
88714cb8 16087 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16088 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16089 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16090 inst.instruction |= LOW4 (inst.operands[1].reg);
16091 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16092 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16093 }
16094 else
16095 {
88714cb8 16096 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16097 neon_move_immediate ();
16098 }
16099
88714cb8 16100 neon_dp_fixup (&inst);
5287ad62
JB
16101}
16102
16103/* Encode instructions of form:
16104
16105 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16106 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16107
16108static void
16109neon_mixed_length (struct neon_type_el et, unsigned size)
16110{
16111 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16112 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16113 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16114 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16115 inst.instruction |= LOW4 (inst.operands[2].reg);
16116 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16117 inst.instruction |= (et.type == NT_unsigned) << 24;
16118 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16119
88714cb8 16120 neon_dp_fixup (&inst);
5287ad62
JB
16121}
16122
16123static void
16124do_neon_dyadic_long (void)
16125{
16126 /* FIXME: Type checking for lengthening op. */
16127 struct neon_type_el et = neon_check_type (3, NS_QDD,
16128 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16129 neon_mixed_length (et, et.size);
16130}
16131
16132static void
16133do_neon_abal (void)
16134{
16135 struct neon_type_el et = neon_check_type (3, NS_QDD,
16136 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16137 neon_mixed_length (et, et.size);
16138}
16139
16140static void
16141neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16142{
16143 if (inst.operands[2].isscalar)
16144 {
dcbf9037 16145 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16146 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16147 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16148 neon_mul_mac (et, et.type == NT_unsigned);
16149 }
16150 else
16151 {
16152 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16153 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16154 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16155 neon_mixed_length (et, et.size);
16156 }
16157}
16158
16159static void
16160do_neon_mac_maybe_scalar_long (void)
16161{
16162 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16163}
16164
dec41383
JW
16165/* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16166 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16167
16168static unsigned
16169neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16170{
16171 unsigned regno = NEON_SCALAR_REG (scalar);
16172 unsigned elno = NEON_SCALAR_INDEX (scalar);
16173
16174 if (quad_p)
16175 {
16176 if (regno > 7 || elno > 3)
16177 goto bad_scalar;
16178
16179 return ((regno & 0x7)
16180 | ((elno & 0x1) << 3)
16181 | (((elno >> 1) & 0x1) << 5));
16182 }
16183 else
16184 {
16185 if (regno > 15 || elno > 1)
16186 goto bad_scalar;
16187
16188 return (((regno & 0x1) << 5)
16189 | ((regno >> 1) & 0x7)
16190 | ((elno & 0x1) << 3));
16191 }
16192
16193bad_scalar:
16194 first_error (_("scalar out of range for multiply instruction"));
16195 return 0;
16196}
16197
16198static void
16199do_neon_fmac_maybe_scalar_long (int subtype)
16200{
16201 enum neon_shape rs;
16202 int high8;
16203 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16204 field (bits[21:20]) has different meaning. For scalar index variant, it's
16205 used to differentiate add and subtract, otherwise it's with fixed value
16206 0x2. */
16207 int size = -1;
16208
16209 if (inst.cond != COND_ALWAYS)
16210 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16211 "behaviour is UNPREDICTABLE"));
16212
16213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
16214 _(BAD_FP16));
16215
16216 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16217 _(BAD_FPU));
16218
16219 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16220 be a scalar index register. */
16221 if (inst.operands[2].isscalar)
16222 {
16223 high8 = 0xfe000000;
16224 if (subtype)
16225 size = 16;
16226 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16227 }
16228 else
16229 {
16230 high8 = 0xfc000000;
16231 size = 32;
16232 if (subtype)
16233 inst.instruction |= (0x1 << 23);
16234 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16235 }
16236
16237 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16238
16239 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16240 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16241 so we simply pass -1 as size. */
16242 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16243 neon_three_same (quad_p, 0, size);
16244
16245 /* Undo neon_dp_fixup. Redo the high eight bits. */
16246 inst.instruction &= 0x00ffffff;
16247 inst.instruction |= high8;
16248
16249#define LOW1(R) ((R) & 0x1)
16250#define HI4(R) (((R) >> 1) & 0xf)
16251 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16252 whether the instruction is in Q form and whether Vm is a scalar indexed
16253 operand. */
16254 if (inst.operands[2].isscalar)
16255 {
16256 unsigned rm
16257 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16258 inst.instruction &= 0xffffffd0;
16259 inst.instruction |= rm;
16260
16261 if (!quad_p)
16262 {
16263 /* Redo Rn as well. */
16264 inst.instruction &= 0xfff0ff7f;
16265 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16266 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16267 }
16268 }
16269 else if (!quad_p)
16270 {
16271 /* Redo Rn and Rm. */
16272 inst.instruction &= 0xfff0ff50;
16273 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16274 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16275 inst.instruction |= HI4 (inst.operands[2].reg);
16276 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16277 }
16278}
16279
16280static void
16281do_neon_vfmal (void)
16282{
16283 return do_neon_fmac_maybe_scalar_long (0);
16284}
16285
16286static void
16287do_neon_vfmsl (void)
16288{
16289 return do_neon_fmac_maybe_scalar_long (1);
16290}
16291
5287ad62
JB
16292static void
16293do_neon_dyadic_wide (void)
16294{
16295 struct neon_type_el et = neon_check_type (3, NS_QQD,
16296 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16297 neon_mixed_length (et, et.size);
16298}
16299
16300static void
16301do_neon_dyadic_narrow (void)
16302{
16303 struct neon_type_el et = neon_check_type (3, NS_QDD,
16304 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16305 /* Operand sign is unimportant, and the U bit is part of the opcode,
16306 so force the operand type to integer. */
16307 et.type = NT_integer;
5287ad62
JB
16308 neon_mixed_length (et, et.size / 2);
16309}
16310
16311static void
16312do_neon_mul_sat_scalar_long (void)
16313{
16314 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16315}
16316
16317static void
16318do_neon_vmull (void)
16319{
16320 if (inst.operands[2].isscalar)
16321 do_neon_mac_maybe_scalar_long ();
16322 else
16323 {
16324 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16325 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16326
5287ad62 16327 if (et.type == NT_poly)
477330fc 16328 NEON_ENCODE (POLY, inst);
5287ad62 16329 else
477330fc 16330 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16331
16332 /* For polynomial encoding the U bit must be zero, and the size must
16333 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16334 obviously, as 0b10). */
16335 if (et.size == 64)
16336 {
16337 /* Check we're on the correct architecture. */
16338 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16339 inst.error =
16340 _("Instruction form not available on this architecture.");
16341
16342 et.size = 32;
16343 }
16344
5287ad62
JB
16345 neon_mixed_length (et, et.size);
16346 }
16347}
16348
16349static void
16350do_neon_ext (void)
16351{
037e8744 16352 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16353 struct neon_type_el et = neon_check_type (3, rs,
16354 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16355 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16356
16357 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16358 _("shift out of range"));
5287ad62
JB
16359 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16360 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16361 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16362 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16363 inst.instruction |= LOW4 (inst.operands[2].reg);
16364 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16365 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16366 inst.instruction |= imm << 8;
5f4273c7 16367
88714cb8 16368 neon_dp_fixup (&inst);
5287ad62
JB
16369}
16370
16371static void
16372do_neon_rev (void)
16373{
037e8744 16374 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16375 struct neon_type_el et = neon_check_type (2, rs,
16376 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16377 unsigned op = (inst.instruction >> 7) & 3;
16378 /* N (width of reversed regions) is encoded as part of the bitmask. We
16379 extract it here to check the elements to be reversed are smaller.
16380 Otherwise we'd get a reserved instruction. */
16381 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16382 gas_assert (elsize != 0);
5287ad62 16383 constraint (et.size >= elsize,
477330fc 16384 _("elements must be smaller than reversal region"));
037e8744 16385 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16386}
16387
16388static void
16389do_neon_dup (void)
16390{
16391 if (inst.operands[1].isscalar)
16392 {
037e8744 16393 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16394 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16395 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16396 unsigned sizebits = et.size >> 3;
dcbf9037 16397 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16398 int logsize = neon_logbits (et.size);
dcbf9037 16399 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16400
16401 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16402 return;
037e8744 16403
88714cb8 16404 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16405 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16406 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16407 inst.instruction |= LOW4 (dm);
16408 inst.instruction |= HI1 (dm) << 5;
037e8744 16409 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16410 inst.instruction |= x << 17;
16411 inst.instruction |= sizebits << 16;
5f4273c7 16412
88714cb8 16413 neon_dp_fixup (&inst);
5287ad62
JB
16414 }
16415 else
16416 {
037e8744
JB
16417 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16418 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16419 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16420 /* Duplicate ARM register to lanes of vector. */
88714cb8 16421 NEON_ENCODE (ARMREG, inst);
5287ad62 16422 switch (et.size)
477330fc
RM
16423 {
16424 case 8: inst.instruction |= 0x400000; break;
16425 case 16: inst.instruction |= 0x000020; break;
16426 case 32: inst.instruction |= 0x000000; break;
16427 default: break;
16428 }
5287ad62
JB
16429 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16430 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16431 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16432 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16433 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16434 variants, except for the condition field. */
037e8744 16435 do_vfp_cond_or_thumb ();
5287ad62
JB
16436 }
16437}
16438
16439/* VMOV has particularly many variations. It can be one of:
16440 0. VMOV<c><q> <Qd>, <Qm>
16441 1. VMOV<c><q> <Dd>, <Dm>
16442 (Register operations, which are VORR with Rm = Rn.)
16443 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16444 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16445 (Immediate loads.)
16446 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16447 (ARM register to scalar.)
16448 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16449 (Two ARM registers to vector.)
16450 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16451 (Scalar to ARM register.)
16452 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16453 (Vector to two ARM registers.)
037e8744
JB
16454 8. VMOV.F32 <Sd>, <Sm>
16455 9. VMOV.F64 <Dd>, <Dm>
16456 (VFP register moves.)
16457 10. VMOV.F32 <Sd>, #imm
16458 11. VMOV.F64 <Dd>, #imm
16459 (VFP float immediate load.)
16460 12. VMOV <Rd>, <Sm>
16461 (VFP single to ARM reg.)
16462 13. VMOV <Sd>, <Rm>
16463 (ARM reg to VFP single.)
16464 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16465 (Two ARM regs to two VFP singles.)
16466 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16467 (Two VFP singles to two ARM regs.)
5f4273c7 16468
037e8744
JB
16469 These cases can be disambiguated using neon_select_shape, except cases 1/9
16470 and 3/11 which depend on the operand type too.
5f4273c7 16471
5287ad62 16472 All the encoded bits are hardcoded by this function.
5f4273c7 16473
b7fc2769
JB
16474 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16475 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16476
5287ad62 16477 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16478 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16479
16480static void
16481do_neon_mov (void)
16482{
037e8744 16483 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16484 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16485 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16486 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16487 struct neon_type_el et;
16488 const char *ldconst = 0;
5287ad62 16489
037e8744 16490 switch (rs)
5287ad62 16491 {
037e8744
JB
16492 case NS_DD: /* case 1/9. */
16493 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16494 /* It is not an error here if no type is given. */
16495 inst.error = NULL;
16496 if (et.type == NT_float && et.size == 64)
477330fc
RM
16497 {
16498 do_vfp_nsyn_opcode ("fcpyd");
16499 break;
16500 }
037e8744 16501 /* fall through. */
5287ad62 16502
037e8744
JB
16503 case NS_QQ: /* case 0/1. */
16504 {
477330fc
RM
16505 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16506 return;
16507 /* The architecture manual I have doesn't explicitly state which
16508 value the U bit should have for register->register moves, but
16509 the equivalent VORR instruction has U = 0, so do that. */
16510 inst.instruction = 0x0200110;
16511 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16512 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16513 inst.instruction |= LOW4 (inst.operands[1].reg);
16514 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16515 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16516 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16517 inst.instruction |= neon_quad (rs) << 6;
16518
16519 neon_dp_fixup (&inst);
037e8744
JB
16520 }
16521 break;
5f4273c7 16522
037e8744
JB
16523 case NS_DI: /* case 3/11. */
16524 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16525 inst.error = NULL;
16526 if (et.type == NT_float && et.size == 64)
477330fc
RM
16527 {
16528 /* case 11 (fconstd). */
16529 ldconst = "fconstd";
16530 goto encode_fconstd;
16531 }
037e8744
JB
16532 /* fall through. */
16533
16534 case NS_QI: /* case 2/3. */
16535 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16536 return;
037e8744
JB
16537 inst.instruction = 0x0800010;
16538 neon_move_immediate ();
88714cb8 16539 neon_dp_fixup (&inst);
5287ad62 16540 break;
5f4273c7 16541
037e8744
JB
16542 case NS_SR: /* case 4. */
16543 {
477330fc
RM
16544 unsigned bcdebits = 0;
16545 int logsize;
16546 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16547 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16548
05ac0ffb
JB
16549 /* .<size> is optional here, defaulting to .32. */
16550 if (inst.vectype.elems == 0
16551 && inst.operands[0].vectype.type == NT_invtype
16552 && inst.operands[1].vectype.type == NT_invtype)
16553 {
16554 inst.vectype.el[0].type = NT_untyped;
16555 inst.vectype.el[0].size = 32;
16556 inst.vectype.elems = 1;
16557 }
16558
477330fc
RM
16559 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16560 logsize = neon_logbits (et.size);
16561
16562 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16563 _(BAD_FPU));
16564 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16565 && et.size != 32, _(BAD_FPU));
16566 constraint (et.type == NT_invtype, _("bad type for scalar"));
16567 constraint (x >= 64 / et.size, _("scalar index out of range"));
16568
16569 switch (et.size)
16570 {
16571 case 8: bcdebits = 0x8; break;
16572 case 16: bcdebits = 0x1; break;
16573 case 32: bcdebits = 0x0; break;
16574 default: ;
16575 }
16576
16577 bcdebits |= x << logsize;
16578
16579 inst.instruction = 0xe000b10;
16580 do_vfp_cond_or_thumb ();
16581 inst.instruction |= LOW4 (dn) << 16;
16582 inst.instruction |= HI1 (dn) << 7;
16583 inst.instruction |= inst.operands[1].reg << 12;
16584 inst.instruction |= (bcdebits & 3) << 5;
16585 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16586 }
16587 break;
5f4273c7 16588
037e8744 16589 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16590 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16591 _(BAD_FPU));
b7fc2769 16592
037e8744
JB
16593 inst.instruction = 0xc400b10;
16594 do_vfp_cond_or_thumb ();
16595 inst.instruction |= LOW4 (inst.operands[0].reg);
16596 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16597 inst.instruction |= inst.operands[1].reg << 12;
16598 inst.instruction |= inst.operands[2].reg << 16;
16599 break;
5f4273c7 16600
037e8744
JB
16601 case NS_RS: /* case 6. */
16602 {
477330fc
RM
16603 unsigned logsize;
16604 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16605 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16606 unsigned abcdebits = 0;
037e8744 16607
05ac0ffb
JB
16608 /* .<dt> is optional here, defaulting to .32. */
16609 if (inst.vectype.elems == 0
16610 && inst.operands[0].vectype.type == NT_invtype
16611 && inst.operands[1].vectype.type == NT_invtype)
16612 {
16613 inst.vectype.el[0].type = NT_untyped;
16614 inst.vectype.el[0].size = 32;
16615 inst.vectype.elems = 1;
16616 }
16617
91d6fa6a
NC
16618 et = neon_check_type (2, NS_NULL,
16619 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16620 logsize = neon_logbits (et.size);
16621
16622 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16623 _(BAD_FPU));
16624 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16625 && et.size != 32, _(BAD_FPU));
16626 constraint (et.type == NT_invtype, _("bad type for scalar"));
16627 constraint (x >= 64 / et.size, _("scalar index out of range"));
16628
16629 switch (et.size)
16630 {
16631 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16632 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16633 case 32: abcdebits = 0x00; break;
16634 default: ;
16635 }
16636
16637 abcdebits |= x << logsize;
16638 inst.instruction = 0xe100b10;
16639 do_vfp_cond_or_thumb ();
16640 inst.instruction |= LOW4 (dn) << 16;
16641 inst.instruction |= HI1 (dn) << 7;
16642 inst.instruction |= inst.operands[0].reg << 12;
16643 inst.instruction |= (abcdebits & 3) << 5;
16644 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16645 }
16646 break;
5f4273c7 16647
037e8744
JB
16648 case NS_RRD: /* case 7 (fmrrd). */
16649 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16650 _(BAD_FPU));
037e8744
JB
16651
16652 inst.instruction = 0xc500b10;
16653 do_vfp_cond_or_thumb ();
16654 inst.instruction |= inst.operands[0].reg << 12;
16655 inst.instruction |= inst.operands[1].reg << 16;
16656 inst.instruction |= LOW4 (inst.operands[2].reg);
16657 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16658 break;
5f4273c7 16659
037e8744
JB
16660 case NS_FF: /* case 8 (fcpys). */
16661 do_vfp_nsyn_opcode ("fcpys");
16662 break;
5f4273c7 16663
9db2f6b4 16664 case NS_HI:
037e8744
JB
16665 case NS_FI: /* case 10 (fconsts). */
16666 ldconst = "fconsts";
16667 encode_fconstd:
16668 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16669 {
16670 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16671 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16672
16673 /* ARMv8.2 fp16 vmov.f16 instruction. */
16674 if (rs == NS_HI)
16675 do_scalar_fp16_v82_encode ();
477330fc 16676 }
5287ad62 16677 else
477330fc 16678 first_error (_("immediate out of range"));
037e8744 16679 break;
5f4273c7 16680
9db2f6b4 16681 case NS_RH:
037e8744
JB
16682 case NS_RF: /* case 12 (fmrs). */
16683 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16684 /* ARMv8.2 fp16 vmov.f16 instruction. */
16685 if (rs == NS_RH)
16686 do_scalar_fp16_v82_encode ();
037e8744 16687 break;
5f4273c7 16688
9db2f6b4 16689 case NS_HR:
037e8744
JB
16690 case NS_FR: /* case 13 (fmsr). */
16691 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16692 /* ARMv8.2 fp16 vmov.f16 instruction. */
16693 if (rs == NS_HR)
16694 do_scalar_fp16_v82_encode ();
037e8744 16695 break;
5f4273c7 16696
037e8744
JB
16697 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16698 (one of which is a list), but we have parsed four. Do some fiddling to
16699 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16700 expect. */
16701 case NS_RRFF: /* case 14 (fmrrs). */
16702 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16703 _("VFP registers must be adjacent"));
037e8744
JB
16704 inst.operands[2].imm = 2;
16705 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16706 do_vfp_nsyn_opcode ("fmrrs");
16707 break;
5f4273c7 16708
037e8744
JB
16709 case NS_FFRR: /* case 15 (fmsrr). */
16710 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16711 _("VFP registers must be adjacent"));
037e8744
JB
16712 inst.operands[1] = inst.operands[2];
16713 inst.operands[2] = inst.operands[3];
16714 inst.operands[0].imm = 2;
16715 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16716 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16717 break;
5f4273c7 16718
4c261dff
NC
16719 case NS_NULL:
16720 /* neon_select_shape has determined that the instruction
16721 shape is wrong and has already set the error message. */
16722 break;
16723
5287ad62
JB
16724 default:
16725 abort ();
16726 }
16727}
16728
16729static void
16730do_neon_rshift_round_imm (void)
16731{
037e8744 16732 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16733 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16734 int imm = inst.operands[2].imm;
16735
16736 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16737 if (imm == 0)
16738 {
16739 inst.operands[2].present = 0;
16740 do_neon_mov ();
16741 return;
16742 }
16743
16744 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16745 _("immediate out of range for shift"));
037e8744 16746 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16747 et.size - imm);
5287ad62
JB
16748}
16749
9db2f6b4
RL
16750static void
16751do_neon_movhf (void)
16752{
16753 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16754 constraint (rs != NS_HH, _("invalid suffix"));
16755
16756 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16757 _(BAD_FPU));
16758
16759 do_vfp_sp_monadic ();
16760
16761 inst.is_neon = 1;
16762 inst.instruction |= 0xf0000000;
16763}
16764
5287ad62
JB
16765static void
16766do_neon_movl (void)
16767{
16768 struct neon_type_el et = neon_check_type (2, NS_QD,
16769 N_EQK | N_DBL, N_SU_32 | N_KEY);
16770 unsigned sizebits = et.size >> 3;
16771 inst.instruction |= sizebits << 19;
16772 neon_two_same (0, et.type == NT_unsigned, -1);
16773}
16774
16775static void
16776do_neon_trn (void)
16777{
037e8744 16778 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16779 struct neon_type_el et = neon_check_type (2, rs,
16780 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16781 NEON_ENCODE (INTEGER, inst);
037e8744 16782 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16783}
16784
16785static void
16786do_neon_zip_uzp (void)
16787{
037e8744 16788 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16789 struct neon_type_el et = neon_check_type (2, rs,
16790 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16791 if (rs == NS_DD && et.size == 32)
16792 {
16793 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16794 inst.instruction = N_MNEM_vtrn;
16795 do_neon_trn ();
16796 return;
16797 }
037e8744 16798 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16799}
16800
16801static void
16802do_neon_sat_abs_neg (void)
16803{
037e8744 16804 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16805 struct neon_type_el et = neon_check_type (2, rs,
16806 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16807 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16808}
16809
16810static void
16811do_neon_pair_long (void)
16812{
037e8744 16813 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16814 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16815 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16816 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16817 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16818}
16819
16820static void
16821do_neon_recip_est (void)
16822{
037e8744 16823 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16824 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16825 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16826 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16827 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16828}
16829
16830static void
16831do_neon_cls (void)
16832{
037e8744 16833 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16834 struct neon_type_el et = neon_check_type (2, rs,
16835 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16836 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16837}
16838
16839static void
16840do_neon_clz (void)
16841{
037e8744 16842 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16843 struct neon_type_el et = neon_check_type (2, rs,
16844 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16845 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16846}
16847
16848static void
16849do_neon_cnt (void)
16850{
037e8744 16851 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16852 struct neon_type_el et = neon_check_type (2, rs,
16853 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16854 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16855}
16856
16857static void
16858do_neon_swp (void)
16859{
037e8744
JB
16860 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16861 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16862}
16863
16864static void
16865do_neon_tbl_tbx (void)
16866{
16867 unsigned listlenbits;
dcbf9037 16868 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16869
5287ad62
JB
16870 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16871 {
dcbf9037 16872 first_error (_("bad list length for table lookup"));
5287ad62
JB
16873 return;
16874 }
5f4273c7 16875
5287ad62
JB
16876 listlenbits = inst.operands[1].imm - 1;
16877 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16878 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16879 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16880 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16881 inst.instruction |= LOW4 (inst.operands[2].reg);
16882 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16883 inst.instruction |= listlenbits << 8;
5f4273c7 16884
88714cb8 16885 neon_dp_fixup (&inst);
5287ad62
JB
16886}
16887
16888static void
16889do_neon_ldm_stm (void)
16890{
16891 /* P, U and L bits are part of bitmask. */
16892 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16893 unsigned offsetbits = inst.operands[1].imm * 2;
16894
037e8744
JB
16895 if (inst.operands[1].issingle)
16896 {
16897 do_vfp_nsyn_ldm_stm (is_dbmode);
16898 return;
16899 }
16900
5287ad62 16901 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16902 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16903
16904 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16905 _("register list must contain at least 1 and at most 16 "
16906 "registers"));
5287ad62
JB
16907
16908 inst.instruction |= inst.operands[0].reg << 16;
16909 inst.instruction |= inst.operands[0].writeback << 21;
16910 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16911 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16912
16913 inst.instruction |= offsetbits;
5f4273c7 16914
037e8744 16915 do_vfp_cond_or_thumb ();
5287ad62
JB
16916}
16917
16918static void
16919do_neon_ldr_str (void)
16920{
5287ad62 16921 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16922
6844b2c2
MGD
16923 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16924 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16925 if (!is_ldr
6844b2c2 16926 && inst.operands[1].reg == REG_PC
ba86b375 16927 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16928 {
94dcf8bf 16929 if (thumb_mode)
6844b2c2 16930 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16931 else if (warn_on_deprecated)
5c3696f8 16932 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16933 }
16934
037e8744
JB
16935 if (inst.operands[0].issingle)
16936 {
cd2f129f 16937 if (is_ldr)
477330fc 16938 do_vfp_nsyn_opcode ("flds");
cd2f129f 16939 else
477330fc 16940 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16941
16942 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16943 if (inst.vectype.el[0].size == 16)
16944 do_scalar_fp16_v82_encode ();
5287ad62
JB
16945 }
16946 else
5287ad62 16947 {
cd2f129f 16948 if (is_ldr)
477330fc 16949 do_vfp_nsyn_opcode ("fldd");
5287ad62 16950 else
477330fc 16951 do_vfp_nsyn_opcode ("fstd");
5287ad62 16952 }
5287ad62
JB
16953}
16954
16955/* "interleave" version also handles non-interleaving register VLD1/VST1
16956 instructions. */
16957
16958static void
16959do_neon_ld_st_interleave (void)
16960{
037e8744 16961 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16962 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16963 unsigned alignbits = 0;
16964 unsigned idx;
16965 /* The bits in this table go:
16966 0: register stride of one (0) or two (1)
16967 1,2: register list length, minus one (1, 2, 3, 4).
16968 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16969 We use -1 for invalid entries. */
16970 const int typetable[] =
16971 {
16972 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16973 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16974 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16975 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16976 };
16977 int typebits;
16978
dcbf9037
JB
16979 if (et.type == NT_invtype)
16980 return;
16981
5287ad62
JB
16982 if (inst.operands[1].immisalign)
16983 switch (inst.operands[1].imm >> 8)
16984 {
16985 case 64: alignbits = 1; break;
16986 case 128:
477330fc 16987 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16988 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16989 goto bad_alignment;
16990 alignbits = 2;
16991 break;
5287ad62 16992 case 256:
477330fc
RM
16993 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16994 goto bad_alignment;
16995 alignbits = 3;
16996 break;
5287ad62
JB
16997 default:
16998 bad_alignment:
477330fc
RM
16999 first_error (_("bad alignment"));
17000 return;
5287ad62
JB
17001 }
17002
17003 inst.instruction |= alignbits << 4;
17004 inst.instruction |= neon_logbits (et.size) << 6;
17005
17006 /* Bits [4:6] of the immediate in a list specifier encode register stride
17007 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17008 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17009 up the right value for "type" in a table based on this value and the given
17010 list style, then stick it back. */
17011 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 17012 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
17013
17014 typebits = typetable[idx];
5f4273c7 17015
5287ad62 17016 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
17017 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17018 _("bad element type for instruction"));
5287ad62
JB
17019
17020 inst.instruction &= ~0xf00;
17021 inst.instruction |= typebits << 8;
17022}
17023
17024/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17025 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17026 otherwise. The variable arguments are a list of pairs of legal (size, align)
17027 values, terminated with -1. */
17028
17029static int
aa8a0863 17030neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
17031{
17032 va_list ap;
17033 int result = FAIL, thissize, thisalign;
5f4273c7 17034
5287ad62
JB
17035 if (!inst.operands[1].immisalign)
17036 {
aa8a0863 17037 *do_alignment = 0;
5287ad62
JB
17038 return SUCCESS;
17039 }
5f4273c7 17040
aa8a0863 17041 va_start (ap, do_alignment);
5287ad62
JB
17042
17043 do
17044 {
17045 thissize = va_arg (ap, int);
17046 if (thissize == -1)
477330fc 17047 break;
5287ad62
JB
17048 thisalign = va_arg (ap, int);
17049
17050 if (size == thissize && align == thisalign)
477330fc 17051 result = SUCCESS;
5287ad62
JB
17052 }
17053 while (result != SUCCESS);
17054
17055 va_end (ap);
17056
17057 if (result == SUCCESS)
aa8a0863 17058 *do_alignment = 1;
5287ad62 17059 else
dcbf9037 17060 first_error (_("unsupported alignment for instruction"));
5f4273c7 17061
5287ad62
JB
17062 return result;
17063}
17064
17065static void
17066do_neon_ld_st_lane (void)
17067{
037e8744 17068 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17069 int align_good, do_alignment = 0;
5287ad62
JB
17070 int logsize = neon_logbits (et.size);
17071 int align = inst.operands[1].imm >> 8;
17072 int n = (inst.instruction >> 8) & 3;
17073 int max_el = 64 / et.size;
5f4273c7 17074
dcbf9037
JB
17075 if (et.type == NT_invtype)
17076 return;
5f4273c7 17077
5287ad62 17078 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 17079 _("bad list length"));
5287ad62 17080 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 17081 _("scalar index out of range"));
5287ad62 17082 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
17083 && et.size == 8,
17084 _("stride of 2 unavailable when element size is 8"));
5f4273c7 17085
5287ad62
JB
17086 switch (n)
17087 {
17088 case 0: /* VLD1 / VST1. */
aa8a0863 17089 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 17090 32, 32, -1);
5287ad62 17091 if (align_good == FAIL)
477330fc 17092 return;
aa8a0863 17093 if (do_alignment)
477330fc
RM
17094 {
17095 unsigned alignbits = 0;
17096 switch (et.size)
17097 {
17098 case 16: alignbits = 0x1; break;
17099 case 32: alignbits = 0x3; break;
17100 default: ;
17101 }
17102 inst.instruction |= alignbits << 4;
17103 }
5287ad62
JB
17104 break;
17105
17106 case 1: /* VLD2 / VST2. */
aa8a0863
TS
17107 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17108 16, 32, 32, 64, -1);
5287ad62 17109 if (align_good == FAIL)
477330fc 17110 return;
aa8a0863 17111 if (do_alignment)
477330fc 17112 inst.instruction |= 1 << 4;
5287ad62
JB
17113 break;
17114
17115 case 2: /* VLD3 / VST3. */
17116 constraint (inst.operands[1].immisalign,
477330fc 17117 _("can't use alignment with this instruction"));
5287ad62
JB
17118 break;
17119
17120 case 3: /* VLD4 / VST4. */
aa8a0863 17121 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 17122 16, 64, 32, 64, 32, 128, -1);
5287ad62 17123 if (align_good == FAIL)
477330fc 17124 return;
aa8a0863 17125 if (do_alignment)
477330fc
RM
17126 {
17127 unsigned alignbits = 0;
17128 switch (et.size)
17129 {
17130 case 8: alignbits = 0x1; break;
17131 case 16: alignbits = 0x1; break;
17132 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17133 default: ;
17134 }
17135 inst.instruction |= alignbits << 4;
17136 }
5287ad62
JB
17137 break;
17138
17139 default: ;
17140 }
17141
17142 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17143 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17144 inst.instruction |= 1 << (4 + logsize);
5f4273c7 17145
5287ad62
JB
17146 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17147 inst.instruction |= logsize << 10;
17148}
17149
17150/* Encode single n-element structure to all lanes VLD<n> instructions. */
17151
17152static void
17153do_neon_ld_dup (void)
17154{
037e8744 17155 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 17156 int align_good, do_alignment = 0;
5287ad62 17157
dcbf9037
JB
17158 if (et.type == NT_invtype)
17159 return;
17160
5287ad62
JB
17161 switch ((inst.instruction >> 8) & 3)
17162 {
17163 case 0: /* VLD1. */
9c2799c2 17164 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 17165 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 17166 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 17167 if (align_good == FAIL)
477330fc 17168 return;
5287ad62 17169 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
17170 {
17171 case 1: break;
17172 case 2: inst.instruction |= 1 << 5; break;
17173 default: first_error (_("bad list length")); return;
17174 }
5287ad62
JB
17175 inst.instruction |= neon_logbits (et.size) << 6;
17176 break;
17177
17178 case 1: /* VLD2. */
17179 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17180 &do_alignment, 8, 16, 16, 32, 32, 64,
17181 -1);
5287ad62 17182 if (align_good == FAIL)
477330fc 17183 return;
5287ad62 17184 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17185 _("bad list length"));
5287ad62 17186 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17187 inst.instruction |= 1 << 5;
5287ad62
JB
17188 inst.instruction |= neon_logbits (et.size) << 6;
17189 break;
17190
17191 case 2: /* VLD3. */
17192 constraint (inst.operands[1].immisalign,
477330fc 17193 _("can't use alignment with this instruction"));
5287ad62 17194 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17195 _("bad list length"));
5287ad62 17196 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17197 inst.instruction |= 1 << 5;
5287ad62
JB
17198 inst.instruction |= neon_logbits (et.size) << 6;
17199 break;
17200
17201 case 3: /* VLD4. */
17202 {
477330fc 17203 int align = inst.operands[1].imm >> 8;
aa8a0863 17204 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17205 16, 64, 32, 64, 32, 128, -1);
17206 if (align_good == FAIL)
17207 return;
17208 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17209 _("bad list length"));
17210 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17211 inst.instruction |= 1 << 5;
17212 if (et.size == 32 && align == 128)
17213 inst.instruction |= 0x3 << 6;
17214 else
17215 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17216 }
17217 break;
17218
17219 default: ;
17220 }
17221
aa8a0863 17222 inst.instruction |= do_alignment << 4;
5287ad62
JB
17223}
17224
17225/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17226 apart from bits [11:4]. */
17227
17228static void
17229do_neon_ldx_stx (void)
17230{
b1a769ed
DG
17231 if (inst.operands[1].isreg)
17232 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17233
5287ad62
JB
17234 switch (NEON_LANE (inst.operands[0].imm))
17235 {
17236 case NEON_INTERLEAVE_LANES:
88714cb8 17237 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17238 do_neon_ld_st_interleave ();
17239 break;
5f4273c7 17240
5287ad62 17241 case NEON_ALL_LANES:
88714cb8 17242 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17243 if (inst.instruction == N_INV)
17244 {
17245 first_error ("only loads support such operands");
17246 break;
17247 }
5287ad62
JB
17248 do_neon_ld_dup ();
17249 break;
5f4273c7 17250
5287ad62 17251 default:
88714cb8 17252 NEON_ENCODE (LANE, inst);
5287ad62
JB
17253 do_neon_ld_st_lane ();
17254 }
17255
17256 /* L bit comes from bit mask. */
17257 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17258 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17259 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17260
5287ad62
JB
17261 if (inst.operands[1].postind)
17262 {
17263 int postreg = inst.operands[1].imm & 0xf;
17264 constraint (!inst.operands[1].immisreg,
477330fc 17265 _("post-index must be a register"));
5287ad62 17266 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17267 _("bad register for post-index"));
5287ad62
JB
17268 inst.instruction |= postreg;
17269 }
4f2374c7 17270 else
5287ad62 17271 {
4f2374c7
WN
17272 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17273 constraint (inst.reloc.exp.X_op != O_constant
17274 || inst.reloc.exp.X_add_number != 0,
17275 BAD_ADDR_MODE);
17276
17277 if (inst.operands[1].writeback)
17278 {
17279 inst.instruction |= 0xd;
17280 }
17281 else
17282 inst.instruction |= 0xf;
5287ad62 17283 }
5f4273c7 17284
5287ad62
JB
17285 if (thumb_mode)
17286 inst.instruction |= 0xf9000000;
17287 else
17288 inst.instruction |= 0xf4000000;
17289}
33399f07
MGD
17290
17291/* FP v8. */
17292static void
17293do_vfp_nsyn_fpv8 (enum neon_shape rs)
17294{
a715796b
TG
17295 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17296 D register operands. */
17297 if (neon_shape_class[rs] == SC_DOUBLE)
17298 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17299 _(BAD_FPU));
17300
33399f07
MGD
17301 NEON_ENCODE (FPV8, inst);
17302
9db2f6b4
RL
17303 if (rs == NS_FFF || rs == NS_HHH)
17304 {
17305 do_vfp_sp_dyadic ();
17306
17307 /* ARMv8.2 fp16 instruction. */
17308 if (rs == NS_HHH)
17309 do_scalar_fp16_v82_encode ();
17310 }
33399f07
MGD
17311 else
17312 do_vfp_dp_rd_rn_rm ();
17313
17314 if (rs == NS_DDD)
17315 inst.instruction |= 0x100;
17316
17317 inst.instruction |= 0xf0000000;
17318}
17319
17320static void
17321do_vsel (void)
17322{
17323 set_it_insn_type (OUTSIDE_IT_INSN);
17324
17325 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17326 first_error (_("invalid instruction shape"));
17327}
17328
73924fbc
MGD
17329static void
17330do_vmaxnm (void)
17331{
17332 set_it_insn_type (OUTSIDE_IT_INSN);
17333
17334 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17335 return;
17336
17337 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17338 return;
17339
cc933301 17340 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17341}
17342
30bdf752
MGD
17343static void
17344do_vrint_1 (enum neon_cvt_mode mode)
17345{
9db2f6b4 17346 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17347 struct neon_type_el et;
17348
17349 if (rs == NS_NULL)
17350 return;
17351
a715796b
TG
17352 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17353 D register operands. */
17354 if (neon_shape_class[rs] == SC_DOUBLE)
17355 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17356 _(BAD_FPU));
17357
9db2f6b4
RL
17358 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17359 | N_VFP);
30bdf752
MGD
17360 if (et.type != NT_invtype)
17361 {
17362 /* VFP encodings. */
17363 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17364 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17365 set_it_insn_type (OUTSIDE_IT_INSN);
17366
17367 NEON_ENCODE (FPV8, inst);
9db2f6b4 17368 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17369 do_vfp_sp_monadic ();
17370 else
17371 do_vfp_dp_rd_rm ();
17372
17373 switch (mode)
17374 {
17375 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17376 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17377 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17378 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17379 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17380 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17381 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17382 default: abort ();
17383 }
17384
17385 inst.instruction |= (rs == NS_DD) << 8;
17386 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17387
17388 /* ARMv8.2 fp16 vrint instruction. */
17389 if (rs == NS_HH)
17390 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17391 }
17392 else
17393 {
17394 /* Neon encodings (or something broken...). */
17395 inst.error = NULL;
cc933301 17396 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17397
17398 if (et.type == NT_invtype)
17399 return;
17400
17401 set_it_insn_type (OUTSIDE_IT_INSN);
17402 NEON_ENCODE (FLOAT, inst);
17403
17404 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17405 return;
17406
17407 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17408 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17409 inst.instruction |= LOW4 (inst.operands[1].reg);
17410 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17411 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17412 /* Mask off the original size bits and reencode them. */
17413 inst.instruction = ((inst.instruction & 0xfff3ffff)
17414 | neon_logbits (et.size) << 18);
17415
30bdf752
MGD
17416 switch (mode)
17417 {
17418 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17419 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17420 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17421 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17422 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17423 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17424 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17425 default: abort ();
17426 }
17427
17428 if (thumb_mode)
17429 inst.instruction |= 0xfc000000;
17430 else
17431 inst.instruction |= 0xf0000000;
17432 }
17433}
17434
17435static void
17436do_vrintx (void)
17437{
17438 do_vrint_1 (neon_cvt_mode_x);
17439}
17440
17441static void
17442do_vrintz (void)
17443{
17444 do_vrint_1 (neon_cvt_mode_z);
17445}
17446
17447static void
17448do_vrintr (void)
17449{
17450 do_vrint_1 (neon_cvt_mode_r);
17451}
17452
17453static void
17454do_vrinta (void)
17455{
17456 do_vrint_1 (neon_cvt_mode_a);
17457}
17458
17459static void
17460do_vrintn (void)
17461{
17462 do_vrint_1 (neon_cvt_mode_n);
17463}
17464
17465static void
17466do_vrintp (void)
17467{
17468 do_vrint_1 (neon_cvt_mode_p);
17469}
17470
17471static void
17472do_vrintm (void)
17473{
17474 do_vrint_1 (neon_cvt_mode_m);
17475}
17476
c28eeff2
SN
17477static unsigned
17478neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17479{
17480 unsigned regno = NEON_SCALAR_REG (opnd);
17481 unsigned elno = NEON_SCALAR_INDEX (opnd);
17482
17483 if (elsize == 16 && elno < 2 && regno < 16)
17484 return regno | (elno << 4);
17485 else if (elsize == 32 && elno == 0)
17486 return regno;
17487
17488 first_error (_("scalar out of range"));
17489 return 0;
17490}
17491
17492static void
17493do_vcmla (void)
17494{
17495 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17496 _(BAD_FPU));
17497 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17498 unsigned rot = inst.reloc.exp.X_add_number;
17499 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17500 _("immediate out of range"));
17501 rot /= 90;
17502 if (inst.operands[2].isscalar)
17503 {
17504 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17505 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17506 N_KEY | N_F16 | N_F32).size;
17507 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17508 inst.is_neon = 1;
17509 inst.instruction = 0xfe000800;
17510 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17511 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17512 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17513 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17514 inst.instruction |= LOW4 (m);
17515 inst.instruction |= HI1 (m) << 5;
17516 inst.instruction |= neon_quad (rs) << 6;
17517 inst.instruction |= rot << 20;
17518 inst.instruction |= (size == 32) << 23;
17519 }
17520 else
17521 {
17522 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17523 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17524 N_KEY | N_F16 | N_F32).size;
17525 neon_three_same (neon_quad (rs), 0, -1);
17526 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17527 inst.instruction |= 0xfc200800;
17528 inst.instruction |= rot << 23;
17529 inst.instruction |= (size == 32) << 20;
17530 }
17531}
17532
17533static void
17534do_vcadd (void)
17535{
17536 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17537 _(BAD_FPU));
17538 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17539 unsigned rot = inst.reloc.exp.X_add_number;
17540 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17541 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17542 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17543 N_KEY | N_F16 | N_F32).size;
17544 neon_three_same (neon_quad (rs), 0, -1);
17545 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17546 inst.instruction |= 0xfc800800;
17547 inst.instruction |= (rot == 270) << 24;
17548 inst.instruction |= (size == 32) << 20;
17549}
17550
c604a79a
JW
17551/* Dot Product instructions encoding support. */
17552
17553static void
17554do_neon_dotproduct (int unsigned_p)
17555{
17556 enum neon_shape rs;
17557 unsigned scalar_oprd2 = 0;
17558 int high8;
17559
17560 if (inst.cond != COND_ALWAYS)
17561 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17562 "is UNPREDICTABLE"));
17563
17564 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17565 _(BAD_FPU));
17566
17567 /* Dot Product instructions are in three-same D/Q register format or the third
17568 operand can be a scalar index register. */
17569 if (inst.operands[2].isscalar)
17570 {
17571 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17572 high8 = 0xfe000000;
17573 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17574 }
17575 else
17576 {
17577 high8 = 0xfc000000;
17578 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17579 }
17580
17581 if (unsigned_p)
17582 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17583 else
17584 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17585
17586 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17587 Product instruction, so we pass 0 as the "ubit" parameter. And the
17588 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17589 neon_three_same (neon_quad (rs), 0, 32);
17590
17591 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17592 different NEON three-same encoding. */
17593 inst.instruction &= 0x00ffffff;
17594 inst.instruction |= high8;
17595 /* Encode 'U' bit which indicates signedness. */
17596 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17597 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17598 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17599 the instruction encoding. */
17600 if (inst.operands[2].isscalar)
17601 {
17602 inst.instruction &= 0xffffffd0;
17603 inst.instruction |= LOW4 (scalar_oprd2);
17604 inst.instruction |= HI1 (scalar_oprd2) << 5;
17605 }
17606}
17607
17608/* Dot Product instructions for signed integer. */
17609
17610static void
17611do_neon_dotproduct_s (void)
17612{
17613 return do_neon_dotproduct (0);
17614}
17615
17616/* Dot Product instructions for unsigned integer. */
17617
17618static void
17619do_neon_dotproduct_u (void)
17620{
17621 return do_neon_dotproduct (1);
17622}
17623
91ff7894
MGD
17624/* Crypto v1 instructions. */
17625static void
17626do_crypto_2op_1 (unsigned elttype, int op)
17627{
17628 set_it_insn_type (OUTSIDE_IT_INSN);
17629
17630 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17631 == NT_invtype)
17632 return;
17633
17634 inst.error = NULL;
17635
17636 NEON_ENCODE (INTEGER, inst);
17637 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17638 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17639 inst.instruction |= LOW4 (inst.operands[1].reg);
17640 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17641 if (op != -1)
17642 inst.instruction |= op << 6;
17643
17644 if (thumb_mode)
17645 inst.instruction |= 0xfc000000;
17646 else
17647 inst.instruction |= 0xf0000000;
17648}
17649
48adcd8e
MGD
17650static void
17651do_crypto_3op_1 (int u, int op)
17652{
17653 set_it_insn_type (OUTSIDE_IT_INSN);
17654
17655 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17656 N_32 | N_UNT | N_KEY).type == NT_invtype)
17657 return;
17658
17659 inst.error = NULL;
17660
17661 NEON_ENCODE (INTEGER, inst);
17662 neon_three_same (1, u, 8 << op);
17663}
17664
91ff7894
MGD
17665static void
17666do_aese (void)
17667{
17668 do_crypto_2op_1 (N_8, 0);
17669}
17670
17671static void
17672do_aesd (void)
17673{
17674 do_crypto_2op_1 (N_8, 1);
17675}
17676
17677static void
17678do_aesmc (void)
17679{
17680 do_crypto_2op_1 (N_8, 2);
17681}
17682
17683static void
17684do_aesimc (void)
17685{
17686 do_crypto_2op_1 (N_8, 3);
17687}
17688
48adcd8e
MGD
17689static void
17690do_sha1c (void)
17691{
17692 do_crypto_3op_1 (0, 0);
17693}
17694
17695static void
17696do_sha1p (void)
17697{
17698 do_crypto_3op_1 (0, 1);
17699}
17700
17701static void
17702do_sha1m (void)
17703{
17704 do_crypto_3op_1 (0, 2);
17705}
17706
17707static void
17708do_sha1su0 (void)
17709{
17710 do_crypto_3op_1 (0, 3);
17711}
91ff7894 17712
48adcd8e
MGD
17713static void
17714do_sha256h (void)
17715{
17716 do_crypto_3op_1 (1, 0);
17717}
17718
17719static void
17720do_sha256h2 (void)
17721{
17722 do_crypto_3op_1 (1, 1);
17723}
17724
17725static void
17726do_sha256su1 (void)
17727{
17728 do_crypto_3op_1 (1, 2);
17729}
3c9017d2
MGD
17730
17731static void
17732do_sha1h (void)
17733{
17734 do_crypto_2op_1 (N_32, -1);
17735}
17736
17737static void
17738do_sha1su1 (void)
17739{
17740 do_crypto_2op_1 (N_32, 0);
17741}
17742
17743static void
17744do_sha256su0 (void)
17745{
17746 do_crypto_2op_1 (N_32, 1);
17747}
dd5181d5
KT
17748
17749static void
17750do_crc32_1 (unsigned int poly, unsigned int sz)
17751{
17752 unsigned int Rd = inst.operands[0].reg;
17753 unsigned int Rn = inst.operands[1].reg;
17754 unsigned int Rm = inst.operands[2].reg;
17755
17756 set_it_insn_type (OUTSIDE_IT_INSN);
17757 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17758 inst.instruction |= LOW4 (Rn) << 16;
17759 inst.instruction |= LOW4 (Rm);
17760 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17761 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17762
17763 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17764 as_warn (UNPRED_REG ("r15"));
dd5181d5
KT
17765}
17766
17767static void
17768do_crc32b (void)
17769{
17770 do_crc32_1 (0, 0);
17771}
17772
17773static void
17774do_crc32h (void)
17775{
17776 do_crc32_1 (0, 1);
17777}
17778
17779static void
17780do_crc32w (void)
17781{
17782 do_crc32_1 (0, 2);
17783}
17784
17785static void
17786do_crc32cb (void)
17787{
17788 do_crc32_1 (1, 0);
17789}
17790
17791static void
17792do_crc32ch (void)
17793{
17794 do_crc32_1 (1, 1);
17795}
17796
17797static void
17798do_crc32cw (void)
17799{
17800 do_crc32_1 (1, 2);
17801}
17802
49e8a725
SN
17803static void
17804do_vjcvt (void)
17805{
17806 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17807 _(BAD_FPU));
17808 neon_check_type (2, NS_FD, N_S32, N_F64);
17809 do_vfp_sp_dp_cvt ();
17810 do_vfp_cond_or_thumb ();
17811}
17812
5287ad62
JB
17813\f
17814/* Overall per-instruction processing. */
17815
17816/* We need to be able to fix up arbitrary expressions in some statements.
17817 This is so that we can handle symbols that are an arbitrary distance from
17818 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17819 which returns part of an address in a form which will be valid for
17820 a data instruction. We do this by pushing the expression into a symbol
17821 in the expr_section, and creating a fix for that. */
17822
17823static void
17824fix_new_arm (fragS * frag,
17825 int where,
17826 short int size,
17827 expressionS * exp,
17828 int pc_rel,
17829 int reloc)
17830{
17831 fixS * new_fix;
17832
17833 switch (exp->X_op)
17834 {
17835 case O_constant:
6e7ce2cd
PB
17836 if (pc_rel)
17837 {
17838 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17839 refer to in the object file. Unfortunately for us, gas's
17840 generic expression parsing will already have folded out
17841 any use of .set foo/.type foo %function that may have
17842 been used to set type information of the target location,
17843 that's being specified symbolically. We have to presume
17844 the user knows what they are doing. */
6e7ce2cd
PB
17845 char name[16 + 8];
17846 symbolS *symbol;
17847
17848 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17849
17850 symbol = symbol_find_or_make (name);
17851 S_SET_SEGMENT (symbol, absolute_section);
17852 symbol_set_frag (symbol, &zero_address_frag);
17853 S_SET_VALUE (symbol, exp->X_add_number);
17854 exp->X_op = O_symbol;
17855 exp->X_add_symbol = symbol;
17856 exp->X_add_number = 0;
17857 }
17858 /* FALLTHROUGH */
5287ad62
JB
17859 case O_symbol:
17860 case O_add:
17861 case O_subtract:
21d799b5 17862 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17863 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17864 break;
17865
17866 default:
21d799b5 17867 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17868 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17869 break;
17870 }
17871
17872 /* Mark whether the fix is to a THUMB instruction, or an ARM
17873 instruction. */
17874 new_fix->tc_fix_data = thumb_mode;
17875}
17876
17877/* Create a frg for an instruction requiring relaxation. */
17878static void
17879output_relax_insn (void)
17880{
17881 char * to;
17882 symbolS *sym;
0110f2b8
PB
17883 int offset;
17884
6e1cb1a6
PB
17885 /* The size of the instruction is unknown, so tie the debug info to the
17886 start of the instruction. */
17887 dwarf2_emit_insn (0);
6e1cb1a6 17888
0110f2b8
PB
17889 switch (inst.reloc.exp.X_op)
17890 {
17891 case O_symbol:
17892 sym = inst.reloc.exp.X_add_symbol;
17893 offset = inst.reloc.exp.X_add_number;
17894 break;
17895 case O_constant:
17896 sym = NULL;
17897 offset = inst.reloc.exp.X_add_number;
17898 break;
17899 default:
17900 sym = make_expr_symbol (&inst.reloc.exp);
17901 offset = 0;
17902 break;
17903 }
17904 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17905 inst.relax, sym, offset, NULL/*offset, opcode*/);
17906 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17907}
17908
17909/* Write a 32-bit thumb instruction to buf. */
17910static void
17911put_thumb32_insn (char * buf, unsigned long insn)
17912{
17913 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17914 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17915}
17916
b99bd4ef 17917static void
c19d1205 17918output_inst (const char * str)
b99bd4ef 17919{
c19d1205 17920 char * to = NULL;
b99bd4ef 17921
c19d1205 17922 if (inst.error)
b99bd4ef 17923 {
c19d1205 17924 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17925 return;
17926 }
5f4273c7
NC
17927 if (inst.relax)
17928 {
17929 output_relax_insn ();
0110f2b8 17930 return;
5f4273c7 17931 }
c19d1205
ZW
17932 if (inst.size == 0)
17933 return;
b99bd4ef 17934
c19d1205 17935 to = frag_more (inst.size);
8dc2430f
NC
17936 /* PR 9814: Record the thumb mode into the current frag so that we know
17937 what type of NOP padding to use, if necessary. We override any previous
17938 setting so that if the mode has changed then the NOPS that we use will
17939 match the encoding of the last instruction in the frag. */
cd000bff 17940 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17941
17942 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17943 {
9c2799c2 17944 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17945 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17946 }
c19d1205 17947 else if (inst.size > INSN_SIZE)
b99bd4ef 17948 {
9c2799c2 17949 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17950 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17951 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17952 }
c19d1205
ZW
17953 else
17954 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17955
c19d1205
ZW
17956 if (inst.reloc.type != BFD_RELOC_UNUSED)
17957 fix_new_arm (frag_now, to - frag_now->fr_literal,
17958 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17959 inst.reloc.type);
b99bd4ef 17960
c19d1205 17961 dwarf2_emit_insn (inst.size);
c19d1205 17962}
b99bd4ef 17963
e07e6e58
NC
17964static char *
17965output_it_inst (int cond, int mask, char * to)
17966{
17967 unsigned long instruction = 0xbf00;
17968
17969 mask &= 0xf;
17970 instruction |= mask;
17971 instruction |= cond << 4;
17972
17973 if (to == NULL)
17974 {
17975 to = frag_more (2);
17976#ifdef OBJ_ELF
17977 dwarf2_emit_insn (2);
17978#endif
17979 }
17980
17981 md_number_to_chars (to, instruction, 2);
17982
17983 return to;
17984}
17985
c19d1205
ZW
17986/* Tag values used in struct asm_opcode's tag field. */
17987enum opcode_tag
17988{
17989 OT_unconditional, /* Instruction cannot be conditionalized.
17990 The ARM condition field is still 0xE. */
17991 OT_unconditionalF, /* Instruction cannot be conditionalized
17992 and carries 0xF in its ARM condition field. */
17993 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17994 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17995 suffix, others place 0xF where the condition field
17996 would be. */
c19d1205
ZW
17997 OT_cinfix3, /* Instruction takes a conditional infix,
17998 beginning at character index 3. (In
17999 unified mode, it becomes a suffix.) */
088fa78e
KH
18000 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18001 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
18002 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18003 character index 3, even in unified mode. Used for
18004 legacy instructions where suffix and infix forms
18005 may be ambiguous. */
c19d1205 18006 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 18007 suffix or an infix at character index 3. */
c19d1205
ZW
18008 OT_odd_infix_unc, /* This is the unconditional variant of an
18009 instruction that takes a conditional infix
18010 at an unusual position. In unified mode,
18011 this variant will accept a suffix. */
18012 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18013 are the conditional variants of instructions that
18014 take conditional infixes in unusual positions.
18015 The infix appears at character index
18016 (tag - OT_odd_infix_0). These are not accepted
18017 in unified mode. */
18018};
b99bd4ef 18019
c19d1205
ZW
18020/* Subroutine of md_assemble, responsible for looking up the primary
18021 opcode from the mnemonic the user wrote. STR points to the
18022 beginning of the mnemonic.
18023
18024 This is not simply a hash table lookup, because of conditional
18025 variants. Most instructions have conditional variants, which are
18026 expressed with a _conditional affix_ to the mnemonic. If we were
18027 to encode each conditional variant as a literal string in the opcode
18028 table, it would have approximately 20,000 entries.
18029
18030 Most mnemonics take this affix as a suffix, and in unified syntax,
18031 'most' is upgraded to 'all'. However, in the divided syntax, some
18032 instructions take the affix as an infix, notably the s-variants of
18033 the arithmetic instructions. Of those instructions, all but six
18034 have the infix appear after the third character of the mnemonic.
18035
18036 Accordingly, the algorithm for looking up primary opcodes given
18037 an identifier is:
18038
18039 1. Look up the identifier in the opcode table.
18040 If we find a match, go to step U.
18041
18042 2. Look up the last two characters of the identifier in the
18043 conditions table. If we find a match, look up the first N-2
18044 characters of the identifier in the opcode table. If we
18045 find a match, go to step CE.
18046
18047 3. Look up the fourth and fifth characters of the identifier in
18048 the conditions table. If we find a match, extract those
18049 characters from the identifier, and look up the remaining
18050 characters in the opcode table. If we find a match, go
18051 to step CM.
18052
18053 4. Fail.
18054
18055 U. Examine the tag field of the opcode structure, in case this is
18056 one of the six instructions with its conditional infix in an
18057 unusual place. If it is, the tag tells us where to find the
18058 infix; look it up in the conditions table and set inst.cond
18059 accordingly. Otherwise, this is an unconditional instruction.
18060 Again set inst.cond accordingly. Return the opcode structure.
18061
18062 CE. Examine the tag field to make sure this is an instruction that
18063 should receive a conditional suffix. If it is not, fail.
18064 Otherwise, set inst.cond from the suffix we already looked up,
18065 and return the opcode structure.
18066
18067 CM. Examine the tag field to make sure this is an instruction that
18068 should receive a conditional infix after the third character.
18069 If it is not, fail. Otherwise, undo the edits to the current
18070 line of input and proceed as for case CE. */
18071
18072static const struct asm_opcode *
18073opcode_lookup (char **str)
18074{
18075 char *end, *base;
18076 char *affix;
18077 const struct asm_opcode *opcode;
18078 const struct asm_cond *cond;
e3cb604e 18079 char save[2];
c19d1205
ZW
18080
18081 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 18082 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 18083 for (base = end = *str; *end != '\0'; end++)
721a8186 18084 if (*end == ' ' || *end == '.')
c19d1205 18085 break;
b99bd4ef 18086
c19d1205 18087 if (end == base)
c921be7d 18088 return NULL;
b99bd4ef 18089
5287ad62 18090 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 18091 if (end[0] == '.')
b99bd4ef 18092 {
5287ad62 18093 int offset = 2;
5f4273c7 18094
267d2029 18095 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 18096 use. */
267d2029 18097 if (unified_syntax && end[1] == 'w')
c19d1205 18098 inst.size_req = 4;
267d2029 18099 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
18100 inst.size_req = 2;
18101 else
477330fc 18102 offset = 0;
5287ad62
JB
18103
18104 inst.vectype.elems = 0;
18105
18106 *str = end + offset;
b99bd4ef 18107
5f4273c7 18108 if (end[offset] == '.')
5287ad62 18109 {
267d2029 18110 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
18111 non-unified ARM syntax mode). */
18112 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 18113 return NULL;
477330fc 18114 }
5287ad62 18115 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 18116 return NULL;
b99bd4ef 18117 }
c19d1205
ZW
18118 else
18119 *str = end;
b99bd4ef 18120
c19d1205 18121 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 18122 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18123 end - base);
c19d1205 18124 if (opcode)
b99bd4ef 18125 {
c19d1205
ZW
18126 /* step U */
18127 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 18128 {
c19d1205
ZW
18129 inst.cond = COND_ALWAYS;
18130 return opcode;
b99bd4ef 18131 }
b99bd4ef 18132
278df34e 18133 if (warn_on_deprecated && unified_syntax)
5c3696f8 18134 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 18135 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 18136 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 18137 gas_assert (cond);
b99bd4ef 18138
c19d1205
ZW
18139 inst.cond = cond->value;
18140 return opcode;
18141 }
b99bd4ef 18142
c19d1205
ZW
18143 /* Cannot have a conditional suffix on a mnemonic of less than two
18144 characters. */
18145 if (end - base < 3)
c921be7d 18146 return NULL;
b99bd4ef 18147
c19d1205
ZW
18148 /* Look for suffixed mnemonic. */
18149 affix = end - 2;
21d799b5
NC
18150 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18151 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18152 affix - base);
c19d1205
ZW
18153 if (opcode && cond)
18154 {
18155 /* step CE */
18156 switch (opcode->tag)
18157 {
e3cb604e
PB
18158 case OT_cinfix3_legacy:
18159 /* Ignore conditional suffixes matched on infix only mnemonics. */
18160 break;
18161
c19d1205 18162 case OT_cinfix3:
088fa78e 18163 case OT_cinfix3_deprecated:
c19d1205
ZW
18164 case OT_odd_infix_unc:
18165 if (!unified_syntax)
0198d5e6 18166 return NULL;
1a0670f3 18167 /* Fall through. */
c19d1205
ZW
18168
18169 case OT_csuffix:
477330fc 18170 case OT_csuffixF:
c19d1205
ZW
18171 case OT_csuf_or_in3:
18172 inst.cond = cond->value;
18173 return opcode;
18174
18175 case OT_unconditional:
18176 case OT_unconditionalF:
dfa9f0d5 18177 if (thumb_mode)
c921be7d 18178 inst.cond = cond->value;
dfa9f0d5
PB
18179 else
18180 {
c921be7d 18181 /* Delayed diagnostic. */
dfa9f0d5
PB
18182 inst.error = BAD_COND;
18183 inst.cond = COND_ALWAYS;
18184 }
c19d1205 18185 return opcode;
b99bd4ef 18186
c19d1205 18187 default:
c921be7d 18188 return NULL;
c19d1205
ZW
18189 }
18190 }
b99bd4ef 18191
c19d1205
ZW
18192 /* Cannot have a usual-position infix on a mnemonic of less than
18193 six characters (five would be a suffix). */
18194 if (end - base < 6)
c921be7d 18195 return NULL;
b99bd4ef 18196
c19d1205
ZW
18197 /* Look for infixed mnemonic in the usual position. */
18198 affix = base + 3;
21d799b5 18199 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 18200 if (!cond)
c921be7d 18201 return NULL;
e3cb604e
PB
18202
18203 memcpy (save, affix, 2);
18204 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 18205 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 18206 (end - base) - 2);
e3cb604e
PB
18207 memmove (affix + 2, affix, (end - affix) - 2);
18208 memcpy (affix, save, 2);
18209
088fa78e
KH
18210 if (opcode
18211 && (opcode->tag == OT_cinfix3
18212 || opcode->tag == OT_cinfix3_deprecated
18213 || opcode->tag == OT_csuf_or_in3
18214 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 18215 {
c921be7d 18216 /* Step CM. */
278df34e 18217 if (warn_on_deprecated && unified_syntax
088fa78e
KH
18218 && (opcode->tag == OT_cinfix3
18219 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 18220 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
18221
18222 inst.cond = cond->value;
18223 return opcode;
b99bd4ef
NC
18224 }
18225
c921be7d 18226 return NULL;
b99bd4ef
NC
18227}
18228
e07e6e58
NC
18229/* This function generates an initial IT instruction, leaving its block
18230 virtually open for the new instructions. Eventually,
18231 the mask will be updated by now_it_add_mask () each time
18232 a new instruction needs to be included in the IT block.
18233 Finally, the block is closed with close_automatic_it_block ().
18234 The block closure can be requested either from md_assemble (),
18235 a tencode (), or due to a label hook. */
18236
18237static void
18238new_automatic_it_block (int cond)
18239{
18240 now_it.state = AUTOMATIC_IT_BLOCK;
18241 now_it.mask = 0x18;
18242 now_it.cc = cond;
18243 now_it.block_length = 1;
cd000bff 18244 mapping_state (MAP_THUMB);
e07e6e58 18245 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18246 now_it.warn_deprecated = FALSE;
18247 now_it.insn_cond = TRUE;
e07e6e58
NC
18248}
18249
18250/* Close an automatic IT block.
18251 See comments in new_automatic_it_block (). */
18252
18253static void
18254close_automatic_it_block (void)
18255{
18256 now_it.mask = 0x10;
18257 now_it.block_length = 0;
18258}
18259
18260/* Update the mask of the current automatically-generated IT
18261 instruction. See comments in new_automatic_it_block (). */
18262
18263static void
18264now_it_add_mask (int cond)
18265{
18266#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18267#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18268 | ((bitvalue) << (nbit)))
e07e6e58 18269 const int resulting_bit = (cond & 1);
c921be7d 18270
e07e6e58
NC
18271 now_it.mask &= 0xf;
18272 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18273 resulting_bit,
18274 (5 - now_it.block_length));
e07e6e58 18275 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18276 1,
18277 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18278 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18279
18280#undef CLEAR_BIT
18281#undef SET_BIT_VALUE
e07e6e58
NC
18282}
18283
18284/* The IT blocks handling machinery is accessed through the these functions:
18285 it_fsm_pre_encode () from md_assemble ()
18286 set_it_insn_type () optional, from the tencode functions
18287 set_it_insn_type_last () ditto
18288 in_it_block () ditto
18289 it_fsm_post_encode () from md_assemble ()
33eaf5de 18290 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18291
18292 Rationale:
18293 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18294 initializing the IT insn type with a generic initial value depending
18295 on the inst.condition.
e07e6e58 18296 2) During the tencode function, two things may happen:
477330fc
RM
18297 a) The tencode function overrides the IT insn type by
18298 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18299 b) The tencode function queries the IT block state by
18300 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18301
18302 Both set_it_insn_type and in_it_block run the internal FSM state
18303 handling function (handle_it_state), because: a) setting the IT insn
18304 type may incur in an invalid state (exiting the function),
18305 and b) querying the state requires the FSM to be updated.
18306 Specifically we want to avoid creating an IT block for conditional
18307 branches, so it_fsm_pre_encode is actually a guess and we can't
18308 determine whether an IT block is required until the tencode () routine
18309 has decided what type of instruction this actually it.
18310 Because of this, if set_it_insn_type and in_it_block have to be used,
18311 set_it_insn_type has to be called first.
18312
18313 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18314 determines the insn IT type depending on the inst.cond code.
18315 When a tencode () routine encodes an instruction that can be
18316 either outside an IT block, or, in the case of being inside, has to be
18317 the last one, set_it_insn_type_last () will determine the proper
18318 IT instruction type based on the inst.cond code. Otherwise,
18319 set_it_insn_type can be called for overriding that logic or
18320 for covering other cases.
18321
18322 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18323 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18324 still queried. Instead, if the FSM determines that the state should
18325 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18326 after the tencode () function: that's what it_fsm_post_encode () does.
18327
18328 Since in_it_block () calls the state handling function to get an
18329 updated state, an error may occur (due to invalid insns combination).
18330 In that case, inst.error is set.
18331 Therefore, inst.error has to be checked after the execution of
18332 the tencode () routine.
e07e6e58
NC
18333
18334 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18335 any pending state change (if any) that didn't take place in
18336 handle_it_state () as explained above. */
e07e6e58
NC
18337
18338static void
18339it_fsm_pre_encode (void)
18340{
18341 if (inst.cond != COND_ALWAYS)
18342 inst.it_insn_type = INSIDE_IT_INSN;
18343 else
18344 inst.it_insn_type = OUTSIDE_IT_INSN;
18345
18346 now_it.state_handled = 0;
18347}
18348
18349/* IT state FSM handling function. */
18350
18351static int
18352handle_it_state (void)
18353{
18354 now_it.state_handled = 1;
5a01bb1d 18355 now_it.insn_cond = FALSE;
e07e6e58
NC
18356
18357 switch (now_it.state)
18358 {
18359 case OUTSIDE_IT_BLOCK:
18360 switch (inst.it_insn_type)
18361 {
18362 case OUTSIDE_IT_INSN:
18363 break;
18364
18365 case INSIDE_IT_INSN:
18366 case INSIDE_IT_LAST_INSN:
18367 if (thumb_mode == 0)
18368 {
c921be7d 18369 if (unified_syntax
e07e6e58
NC
18370 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18371 as_tsktsk (_("Warning: conditional outside an IT block"\
18372 " for Thumb."));
18373 }
18374 else
18375 {
18376 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18377 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18378 {
18379 /* Automatically generate the IT instruction. */
18380 new_automatic_it_block (inst.cond);
18381 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18382 close_automatic_it_block ();
18383 }
18384 else
18385 {
18386 inst.error = BAD_OUT_IT;
18387 return FAIL;
18388 }
18389 }
18390 break;
18391
18392 case IF_INSIDE_IT_LAST_INSN:
18393 case NEUTRAL_IT_INSN:
18394 break;
18395
18396 case IT_INSN:
18397 now_it.state = MANUAL_IT_BLOCK;
18398 now_it.block_length = 0;
18399 break;
18400 }
18401 break;
18402
18403 case AUTOMATIC_IT_BLOCK:
18404 /* Three things may happen now:
18405 a) We should increment current it block size;
18406 b) We should close current it block (closing insn or 4 insns);
18407 c) We should close current it block and start a new one (due
18408 to incompatible conditions or
18409 4 insns-length block reached). */
18410
18411 switch (inst.it_insn_type)
18412 {
18413 case OUTSIDE_IT_INSN:
2b0f3761 18414 /* The closure of the block shall happen immediately,
e07e6e58
NC
18415 so any in_it_block () call reports the block as closed. */
18416 force_automatic_it_block_close ();
18417 break;
18418
18419 case INSIDE_IT_INSN:
18420 case INSIDE_IT_LAST_INSN:
18421 case IF_INSIDE_IT_LAST_INSN:
18422 now_it.block_length++;
18423
18424 if (now_it.block_length > 4
18425 || !now_it_compatible (inst.cond))
18426 {
18427 force_automatic_it_block_close ();
18428 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18429 new_automatic_it_block (inst.cond);
18430 }
18431 else
18432 {
5a01bb1d 18433 now_it.insn_cond = TRUE;
e07e6e58
NC
18434 now_it_add_mask (inst.cond);
18435 }
18436
18437 if (now_it.state == AUTOMATIC_IT_BLOCK
18438 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18439 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18440 close_automatic_it_block ();
18441 break;
18442
18443 case NEUTRAL_IT_INSN:
18444 now_it.block_length++;
5a01bb1d 18445 now_it.insn_cond = TRUE;
e07e6e58
NC
18446
18447 if (now_it.block_length > 4)
18448 force_automatic_it_block_close ();
18449 else
18450 now_it_add_mask (now_it.cc & 1);
18451 break;
18452
18453 case IT_INSN:
18454 close_automatic_it_block ();
18455 now_it.state = MANUAL_IT_BLOCK;
18456 break;
18457 }
18458 break;
18459
18460 case MANUAL_IT_BLOCK:
18461 {
18462 /* Check conditional suffixes. */
18463 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18464 int is_last;
18465 now_it.mask <<= 1;
18466 now_it.mask &= 0x1f;
18467 is_last = (now_it.mask == 0x10);
5a01bb1d 18468 now_it.insn_cond = TRUE;
e07e6e58
NC
18469
18470 switch (inst.it_insn_type)
18471 {
18472 case OUTSIDE_IT_INSN:
18473 inst.error = BAD_NOT_IT;
18474 return FAIL;
18475
18476 case INSIDE_IT_INSN:
18477 if (cond != inst.cond)
18478 {
18479 inst.error = BAD_IT_COND;
18480 return FAIL;
18481 }
18482 break;
18483
18484 case INSIDE_IT_LAST_INSN:
18485 case IF_INSIDE_IT_LAST_INSN:
18486 if (cond != inst.cond)
18487 {
18488 inst.error = BAD_IT_COND;
18489 return FAIL;
18490 }
18491 if (!is_last)
18492 {
18493 inst.error = BAD_BRANCH;
18494 return FAIL;
18495 }
18496 break;
18497
18498 case NEUTRAL_IT_INSN:
18499 /* The BKPT instruction is unconditional even in an IT block. */
18500 break;
18501
18502 case IT_INSN:
18503 inst.error = BAD_IT_IT;
18504 return FAIL;
18505 }
18506 }
18507 break;
18508 }
18509
18510 return SUCCESS;
18511}
18512
5a01bb1d
MGD
18513struct depr_insn_mask
18514{
18515 unsigned long pattern;
18516 unsigned long mask;
18517 const char* description;
18518};
18519
18520/* List of 16-bit instruction patterns deprecated in an IT block in
18521 ARMv8. */
18522static const struct depr_insn_mask depr_it_insns[] = {
18523 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18524 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18525 { 0xa000, 0xb800, N_("ADR") },
18526 { 0x4800, 0xf800, N_("Literal loads") },
18527 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18528 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18529 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18530 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18531 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18532 { 0, 0, NULL }
18533};
18534
e07e6e58
NC
18535static void
18536it_fsm_post_encode (void)
18537{
18538 int is_last;
18539
18540 if (!now_it.state_handled)
18541 handle_it_state ();
18542
5a01bb1d
MGD
18543 if (now_it.insn_cond
18544 && !now_it.warn_deprecated
18545 && warn_on_deprecated
18546 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18547 {
18548 if (inst.instruction >= 0x10000)
18549 {
5c3696f8 18550 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18551 "deprecated in ARMv8"));
18552 now_it.warn_deprecated = TRUE;
18553 }
18554 else
18555 {
18556 const struct depr_insn_mask *p = depr_it_insns;
18557
18558 while (p->mask != 0)
18559 {
18560 if ((inst.instruction & p->mask) == p->pattern)
18561 {
5c3696f8 18562 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18563 "of the following class are deprecated in ARMv8: "
18564 "%s"), p->description);
18565 now_it.warn_deprecated = TRUE;
18566 break;
18567 }
18568
18569 ++p;
18570 }
18571 }
18572
18573 if (now_it.block_length > 1)
18574 {
5c3696f8 18575 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18576 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18577 now_it.warn_deprecated = TRUE;
18578 }
18579 }
18580
e07e6e58
NC
18581 is_last = (now_it.mask == 0x10);
18582 if (is_last)
18583 {
18584 now_it.state = OUTSIDE_IT_BLOCK;
18585 now_it.mask = 0;
18586 }
18587}
18588
18589static void
18590force_automatic_it_block_close (void)
18591{
18592 if (now_it.state == AUTOMATIC_IT_BLOCK)
18593 {
18594 close_automatic_it_block ();
18595 now_it.state = OUTSIDE_IT_BLOCK;
18596 now_it.mask = 0;
18597 }
18598}
18599
18600static int
18601in_it_block (void)
18602{
18603 if (!now_it.state_handled)
18604 handle_it_state ();
18605
18606 return now_it.state != OUTSIDE_IT_BLOCK;
18607}
18608
ff8646ee
TP
18609/* Whether OPCODE only has T32 encoding. Since this function is only used by
18610 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18611 here, hence the "known" in the function name. */
fc289b0a
TP
18612
18613static bfd_boolean
ff8646ee 18614known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18615{
18616 /* Original Thumb-1 wide instruction. */
18617 if (opcode->tencode == do_t_blx
18618 || opcode->tencode == do_t_branch23
18619 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18620 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18621 return TRUE;
18622
16a1fa25
TP
18623 /* Wide-only instruction added to ARMv8-M Baseline. */
18624 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18625 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18626 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18627 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18628 return TRUE;
18629
18630 return FALSE;
18631}
18632
18633/* Whether wide instruction variant can be used if available for a valid OPCODE
18634 in ARCH. */
18635
18636static bfd_boolean
18637t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18638{
18639 if (known_t32_only_insn (opcode))
18640 return TRUE;
18641
18642 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18643 of variant T3 of B.W is checked in do_t_branch. */
18644 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18645 && opcode->tencode == do_t_branch)
18646 return TRUE;
18647
bada4342
JW
18648 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18649 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18650 && opcode->tencode == do_t_mov_cmp
18651 /* Make sure CMP instruction is not affected. */
18652 && opcode->aencode == do_mov)
18653 return TRUE;
18654
ff8646ee
TP
18655 /* Wide instruction variants of all instructions with narrow *and* wide
18656 variants become available with ARMv6t2. Other opcodes are either
18657 narrow-only or wide-only and are thus available if OPCODE is valid. */
18658 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18659 return TRUE;
18660
18661 /* OPCODE with narrow only instruction variant or wide variant not
18662 available. */
fc289b0a
TP
18663 return FALSE;
18664}
18665
c19d1205
ZW
18666void
18667md_assemble (char *str)
b99bd4ef 18668{
c19d1205
ZW
18669 char *p = str;
18670 const struct asm_opcode * opcode;
b99bd4ef 18671
c19d1205
ZW
18672 /* Align the previous label if needed. */
18673 if (last_label_seen != NULL)
b99bd4ef 18674 {
c19d1205
ZW
18675 symbol_set_frag (last_label_seen, frag_now);
18676 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18677 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18678 }
18679
c19d1205
ZW
18680 memset (&inst, '\0', sizeof (inst));
18681 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18682
c19d1205
ZW
18683 opcode = opcode_lookup (&p);
18684 if (!opcode)
b99bd4ef 18685 {
c19d1205 18686 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18687 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18688 if (! create_register_alias (str, p)
477330fc 18689 && ! create_neon_reg_alias (str, p))
c19d1205 18690 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18691
b99bd4ef
NC
18692 return;
18693 }
18694
278df34e 18695 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18696 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18697
037e8744
JB
18698 /* The value which unconditional instructions should have in place of the
18699 condition field. */
18700 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18701
c19d1205 18702 if (thumb_mode)
b99bd4ef 18703 {
e74cfd16 18704 arm_feature_set variant;
8f06b2d8
PB
18705
18706 variant = cpu_variant;
18707 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18708 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18709 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18710 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18711 if (!opcode->tvariant
18712 || (thumb_mode == 1
18713 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18714 {
173205ca
TP
18715 if (opcode->tencode == do_t_swi)
18716 as_bad (_("SVC is not permitted on this architecture"));
18717 else
18718 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18719 return;
18720 }
c19d1205
ZW
18721 if (inst.cond != COND_ALWAYS && !unified_syntax
18722 && opcode->tencode != do_t_branch)
b99bd4ef 18723 {
c19d1205 18724 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18725 return;
18726 }
18727
fc289b0a
TP
18728 /* Two things are addressed here:
18729 1) Implicit require narrow instructions on Thumb-1.
18730 This avoids relaxation accidentally introducing Thumb-2
18731 instructions.
18732 2) Reject wide instructions in non Thumb-2 cores.
18733
18734 Only instructions with narrow and wide variants need to be handled
18735 but selecting all non wide-only instructions is easier. */
18736 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18737 && !t32_insn_ok (variant, opcode))
076d447c 18738 {
fc289b0a
TP
18739 if (inst.size_req == 0)
18740 inst.size_req = 2;
18741 else if (inst.size_req == 4)
752d5da4 18742 {
ff8646ee
TP
18743 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18744 as_bad (_("selected processor does not support 32bit wide "
18745 "variant of instruction `%s'"), str);
18746 else
18747 as_bad (_("selected processor does not support `%s' in "
18748 "Thumb-2 mode"), str);
fc289b0a 18749 return;
752d5da4 18750 }
076d447c
PB
18751 }
18752
c19d1205
ZW
18753 inst.instruction = opcode->tvalue;
18754
5be8be5d 18755 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18756 {
18757 /* Prepare the it_insn_type for those encodings that don't set
18758 it. */
18759 it_fsm_pre_encode ();
c19d1205 18760
477330fc 18761 opcode->tencode ();
e07e6e58 18762
477330fc
RM
18763 it_fsm_post_encode ();
18764 }
e27ec89e 18765
0110f2b8 18766 if (!(inst.error || inst.relax))
b99bd4ef 18767 {
9c2799c2 18768 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18769 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18770 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18771 {
c19d1205 18772 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18773 return;
18774 }
18775 }
076d447c
PB
18776
18777 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18778 instruction. */
9c2799c2 18779 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18780
e74cfd16
PB
18781 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18782 *opcode->tvariant);
ee065d83 18783 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18784 set those bits when Thumb-2 32-bit instructions are seen. The impact
18785 of relaxable instructions will be considered later after we finish all
18786 relaxation. */
ff8646ee
TP
18787 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18788 variant = arm_arch_none;
18789 else
18790 variant = cpu_variant;
18791 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18792 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18793 arm_ext_v6t2);
cd000bff 18794
88714cb8
DG
18795 check_neon_suffixes;
18796
cd000bff 18797 if (!inst.error)
c877a2f2
NC
18798 {
18799 mapping_state (MAP_THUMB);
18800 }
c19d1205 18801 }
3e9e4fcf 18802 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18803 {
845b51d6
PB
18804 bfd_boolean is_bx;
18805
18806 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18807 is_bx = (opcode->aencode == do_bx);
18808
c19d1205 18809 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18810 if (!(is_bx && fix_v4bx)
18811 && !(opcode->avariant &&
18812 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18813 {
84b52b66 18814 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18815 return;
b99bd4ef 18816 }
c19d1205 18817 if (inst.size_req)
b99bd4ef 18818 {
c19d1205
ZW
18819 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18820 return;
b99bd4ef
NC
18821 }
18822
c19d1205
ZW
18823 inst.instruction = opcode->avalue;
18824 if (opcode->tag == OT_unconditionalF)
eff0bc54 18825 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18826 else
18827 inst.instruction |= inst.cond << 28;
18828 inst.size = INSN_SIZE;
5be8be5d 18829 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18830 {
18831 it_fsm_pre_encode ();
18832 opcode->aencode ();
18833 it_fsm_post_encode ();
18834 }
ee065d83 18835 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18836 on a hypothetical non-thumb v5 core. */
845b51d6 18837 if (is_bx)
e74cfd16 18838 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18839 else
e74cfd16
PB
18840 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18841 *opcode->avariant);
88714cb8
DG
18842
18843 check_neon_suffixes;
18844
cd000bff 18845 if (!inst.error)
c877a2f2
NC
18846 {
18847 mapping_state (MAP_ARM);
18848 }
b99bd4ef 18849 }
3e9e4fcf
JB
18850 else
18851 {
18852 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18853 "-- `%s'"), str);
18854 return;
18855 }
c19d1205
ZW
18856 output_inst (str);
18857}
b99bd4ef 18858
e07e6e58
NC
18859static void
18860check_it_blocks_finished (void)
18861{
18862#ifdef OBJ_ELF
18863 asection *sect;
18864
18865 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18866 if (seg_info (sect)->tc_segment_info_data.current_it.state
18867 == MANUAL_IT_BLOCK)
18868 {
18869 as_warn (_("section '%s' finished with an open IT block."),
18870 sect->name);
18871 }
18872#else
18873 if (now_it.state == MANUAL_IT_BLOCK)
18874 as_warn (_("file finished with an open IT block."));
18875#endif
18876}
18877
c19d1205
ZW
18878/* Various frobbings of labels and their addresses. */
18879
18880void
18881arm_start_line_hook (void)
18882{
18883 last_label_seen = NULL;
b99bd4ef
NC
18884}
18885
c19d1205
ZW
18886void
18887arm_frob_label (symbolS * sym)
b99bd4ef 18888{
c19d1205 18889 last_label_seen = sym;
b99bd4ef 18890
c19d1205 18891 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18892
c19d1205
ZW
18893#if defined OBJ_COFF || defined OBJ_ELF
18894 ARM_SET_INTERWORK (sym, support_interwork);
18895#endif
b99bd4ef 18896
e07e6e58
NC
18897 force_automatic_it_block_close ();
18898
5f4273c7 18899 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18900 as Thumb functions. This is because these labels, whilst
18901 they exist inside Thumb code, are not the entry points for
18902 possible ARM->Thumb calls. Also, these labels can be used
18903 as part of a computed goto or switch statement. eg gcc
18904 can generate code that looks like this:
b99bd4ef 18905
c19d1205
ZW
18906 ldr r2, [pc, .Laaa]
18907 lsl r3, r3, #2
18908 ldr r2, [r3, r2]
18909 mov pc, r2
b99bd4ef 18910
c19d1205
ZW
18911 .Lbbb: .word .Lxxx
18912 .Lccc: .word .Lyyy
18913 ..etc...
18914 .Laaa: .word Lbbb
b99bd4ef 18915
c19d1205
ZW
18916 The first instruction loads the address of the jump table.
18917 The second instruction converts a table index into a byte offset.
18918 The third instruction gets the jump address out of the table.
18919 The fourth instruction performs the jump.
b99bd4ef 18920
c19d1205
ZW
18921 If the address stored at .Laaa is that of a symbol which has the
18922 Thumb_Func bit set, then the linker will arrange for this address
18923 to have the bottom bit set, which in turn would mean that the
18924 address computation performed by the third instruction would end
18925 up with the bottom bit set. Since the ARM is capable of unaligned
18926 word loads, the instruction would then load the incorrect address
18927 out of the jump table, and chaos would ensue. */
18928 if (label_is_thumb_function_name
18929 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18930 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18931 {
c19d1205
ZW
18932 /* When the address of a Thumb function is taken the bottom
18933 bit of that address should be set. This will allow
18934 interworking between Arm and Thumb functions to work
18935 correctly. */
b99bd4ef 18936
c19d1205 18937 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18938
c19d1205 18939 label_is_thumb_function_name = FALSE;
b99bd4ef 18940 }
07a53e5c 18941
07a53e5c 18942 dwarf2_emit_label (sym);
b99bd4ef
NC
18943}
18944
c921be7d 18945bfd_boolean
c19d1205 18946arm_data_in_code (void)
b99bd4ef 18947{
c19d1205 18948 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18949 {
c19d1205
ZW
18950 *input_line_pointer = '/';
18951 input_line_pointer += 5;
18952 *input_line_pointer = 0;
c921be7d 18953 return TRUE;
b99bd4ef
NC
18954 }
18955
c921be7d 18956 return FALSE;
b99bd4ef
NC
18957}
18958
c19d1205
ZW
18959char *
18960arm_canonicalize_symbol_name (char * name)
b99bd4ef 18961{
c19d1205 18962 int len;
b99bd4ef 18963
c19d1205
ZW
18964 if (thumb_mode && (len = strlen (name)) > 5
18965 && streq (name + len - 5, "/data"))
18966 *(name + len - 5) = 0;
b99bd4ef 18967
c19d1205 18968 return name;
b99bd4ef 18969}
c19d1205
ZW
18970\f
18971/* Table of all register names defined by default. The user can
18972 define additional names with .req. Note that all register names
18973 should appear in both upper and lowercase variants. Some registers
18974 also have mixed-case names. */
b99bd4ef 18975
dcbf9037 18976#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18977#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18978#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18979#define REGSET(p,t) \
18980 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18981 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18982 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18983 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18984#define REGSETH(p,t) \
18985 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18986 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18987 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18988 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18989#define REGSET2(p,t) \
18990 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18991 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18992 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18993 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18994#define SPLRBANK(base,bank,t) \
18995 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18996 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18997 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18998 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18999 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19000 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 19001
c19d1205 19002static const struct reg_entry reg_names[] =
7ed4c4c5 19003{
c19d1205
ZW
19004 /* ARM integer registers. */
19005 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 19006
c19d1205
ZW
19007 /* ATPCS synonyms. */
19008 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19009 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19010 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 19011
c19d1205
ZW
19012 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19013 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19014 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 19015
c19d1205
ZW
19016 /* Well-known aliases. */
19017 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19018 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19019
19020 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19021 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19022
19023 /* Coprocessor numbers. */
19024 REGSET(p, CP), REGSET(P, CP),
19025
19026 /* Coprocessor register numbers. The "cr" variants are for backward
19027 compatibility. */
19028 REGSET(c, CN), REGSET(C, CN),
19029 REGSET(cr, CN), REGSET(CR, CN),
19030
90ec0d68
MGD
19031 /* ARM banked registers. */
19032 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19033 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19034 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19035 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19036 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19037 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19038 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19039
19040 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19041 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19042 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19043 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19044 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 19045 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
19046 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19047 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19048
19049 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19050 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19051 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19052 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19053 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19054 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19055 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 19056 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
19057 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19058
c19d1205
ZW
19059 /* FPA registers. */
19060 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19061 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19062
19063 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19064 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19065
19066 /* VFP SP registers. */
5287ad62
JB
19067 REGSET(s,VFS), REGSET(S,VFS),
19068 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
19069
19070 /* VFP DP Registers. */
5287ad62
JB
19071 REGSET(d,VFD), REGSET(D,VFD),
19072 /* Extra Neon DP registers. */
19073 REGSETH(d,VFD), REGSETH(D,VFD),
19074
19075 /* Neon QP registers. */
19076 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
19077
19078 /* VFP control registers. */
19079 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19080 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
19081 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19082 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19083 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19084 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
40c7d507 19085 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
c19d1205
ZW
19086
19087 /* Maverick DSP coprocessor registers. */
19088 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19089 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19090
19091 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19092 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19093 REGDEF(dspsc,0,DSPSC),
19094
19095 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19096 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19097 REGDEF(DSPSC,0,DSPSC),
19098
19099 /* iWMMXt data registers - p0, c0-15. */
19100 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19101
19102 /* iWMMXt control registers - p1, c0-3. */
19103 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19104 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19105 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19106 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19107
19108 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19109 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19110 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19111 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19112 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19113
19114 /* XScale accumulator registers. */
19115 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19116};
19117#undef REGDEF
19118#undef REGNUM
19119#undef REGSET
7ed4c4c5 19120
c19d1205
ZW
19121/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19122 within psr_required_here. */
19123static const struct asm_psr psrs[] =
19124{
19125 /* Backward compatibility notation. Note that "all" is no longer
19126 truly all possible PSR bits. */
19127 {"all", PSR_c | PSR_f},
19128 {"flg", PSR_f},
19129 {"ctl", PSR_c},
19130
19131 /* Individual flags. */
19132 {"f", PSR_f},
19133 {"c", PSR_c},
19134 {"x", PSR_x},
19135 {"s", PSR_s},
59b42a0d 19136
c19d1205
ZW
19137 /* Combinations of flags. */
19138 {"fs", PSR_f | PSR_s},
19139 {"fx", PSR_f | PSR_x},
19140 {"fc", PSR_f | PSR_c},
19141 {"sf", PSR_s | PSR_f},
19142 {"sx", PSR_s | PSR_x},
19143 {"sc", PSR_s | PSR_c},
19144 {"xf", PSR_x | PSR_f},
19145 {"xs", PSR_x | PSR_s},
19146 {"xc", PSR_x | PSR_c},
19147 {"cf", PSR_c | PSR_f},
19148 {"cs", PSR_c | PSR_s},
19149 {"cx", PSR_c | PSR_x},
19150 {"fsx", PSR_f | PSR_s | PSR_x},
19151 {"fsc", PSR_f | PSR_s | PSR_c},
19152 {"fxs", PSR_f | PSR_x | PSR_s},
19153 {"fxc", PSR_f | PSR_x | PSR_c},
19154 {"fcs", PSR_f | PSR_c | PSR_s},
19155 {"fcx", PSR_f | PSR_c | PSR_x},
19156 {"sfx", PSR_s | PSR_f | PSR_x},
19157 {"sfc", PSR_s | PSR_f | PSR_c},
19158 {"sxf", PSR_s | PSR_x | PSR_f},
19159 {"sxc", PSR_s | PSR_x | PSR_c},
19160 {"scf", PSR_s | PSR_c | PSR_f},
19161 {"scx", PSR_s | PSR_c | PSR_x},
19162 {"xfs", PSR_x | PSR_f | PSR_s},
19163 {"xfc", PSR_x | PSR_f | PSR_c},
19164 {"xsf", PSR_x | PSR_s | PSR_f},
19165 {"xsc", PSR_x | PSR_s | PSR_c},
19166 {"xcf", PSR_x | PSR_c | PSR_f},
19167 {"xcs", PSR_x | PSR_c | PSR_s},
19168 {"cfs", PSR_c | PSR_f | PSR_s},
19169 {"cfx", PSR_c | PSR_f | PSR_x},
19170 {"csf", PSR_c | PSR_s | PSR_f},
19171 {"csx", PSR_c | PSR_s | PSR_x},
19172 {"cxf", PSR_c | PSR_x | PSR_f},
19173 {"cxs", PSR_c | PSR_x | PSR_s},
19174 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19175 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19176 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19177 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19178 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19179 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19180 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19181 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19182 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19183 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19184 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19185 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19186 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19187 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19188 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19189 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19190 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19191 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19192 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19193 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19194 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19195 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19196 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19197 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19198};
19199
62b3e311
PB
19200/* Table of V7M psr names. */
19201static const struct asm_psr v7m_psrs[] =
19202{
1a336194
TP
19203 {"apsr", 0x0 }, {"APSR", 0x0 },
19204 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19205 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19206 {"psr", 0x3 }, {"PSR", 0x3 },
19207 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19208 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19209 {"epsr", 0x6 }, {"EPSR", 0x6 },
19210 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19211 {"msp", 0x8 }, {"MSP", 0x8 },
19212 {"psp", 0x9 }, {"PSP", 0x9 },
19213 {"msplim", 0xa }, {"MSPLIM", 0xa },
19214 {"psplim", 0xb }, {"PSPLIM", 0xb },
19215 {"primask", 0x10}, {"PRIMASK", 0x10},
19216 {"basepri", 0x11}, {"BASEPRI", 0x11},
19217 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
19218 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19219 {"control", 0x14}, {"CONTROL", 0x14},
19220 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19221 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19222 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19223 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19224 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19225 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19226 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19227 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19228 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
19229};
19230
c19d1205
ZW
19231/* Table of all shift-in-operand names. */
19232static const struct asm_shift_name shift_names [] =
b99bd4ef 19233{
c19d1205
ZW
19234 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19235 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19236 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19237 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19238 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19239 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19240};
b99bd4ef 19241
c19d1205
ZW
19242/* Table of all explicit relocation names. */
19243#ifdef OBJ_ELF
19244static struct reloc_entry reloc_names[] =
19245{
19246 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19247 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19248 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19249 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19250 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19251 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19252 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19253 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19254 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19255 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19256 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19257 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19258 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19259 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19260 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19261 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19262 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19263 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19264};
19265#endif
b99bd4ef 19266
c19d1205
ZW
19267/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19268static const struct asm_cond conds[] =
19269{
19270 {"eq", 0x0},
19271 {"ne", 0x1},
19272 {"cs", 0x2}, {"hs", 0x2},
19273 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19274 {"mi", 0x4},
19275 {"pl", 0x5},
19276 {"vs", 0x6},
19277 {"vc", 0x7},
19278 {"hi", 0x8},
19279 {"ls", 0x9},
19280 {"ge", 0xa},
19281 {"lt", 0xb},
19282 {"gt", 0xc},
19283 {"le", 0xd},
19284 {"al", 0xe}
19285};
bfae80f2 19286
e797f7e0 19287#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19288 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19289 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19290
62b3e311
PB
19291static struct asm_barrier_opt barrier_opt_names[] =
19292{
e797f7e0
MGD
19293 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19294 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19295 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19296 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19297 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19298 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19299 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19300 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19301 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19302 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19303 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19304 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19305 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19306 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19307 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19308 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19309};
19310
e797f7e0
MGD
19311#undef UL_BARRIER
19312
c19d1205
ZW
19313/* Table of ARM-format instructions. */
19314
19315/* Macros for gluing together operand strings. N.B. In all cases
19316 other than OPS0, the trailing OP_stop comes from default
19317 zero-initialization of the unspecified elements of the array. */
19318#define OPS0() { OP_stop, }
19319#define OPS1(a) { OP_##a, }
19320#define OPS2(a,b) { OP_##a,OP_##b, }
19321#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19322#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19323#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19324#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19325
5be8be5d
DG
19326/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19327 This is useful when mixing operands for ARM and THUMB, i.e. using the
19328 MIX_ARM_THUMB_OPERANDS macro.
19329 In order to use these macros, prefix the number of operands with _
19330 e.g. _3. */
19331#define OPS_1(a) { a, }
19332#define OPS_2(a,b) { a,b, }
19333#define OPS_3(a,b,c) { a,b,c, }
19334#define OPS_4(a,b,c,d) { a,b,c,d, }
19335#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19336#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19337
c19d1205
ZW
19338/* These macros abstract out the exact format of the mnemonic table and
19339 save some repeated characters. */
19340
19341/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19342#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19343 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19344 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19345
19346/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19347 a T_MNEM_xyz enumerator. */
19348#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19349 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19350#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19351 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19352
19353/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19354 infix after the third character. */
19355#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19356 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19357 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19358#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19359 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19360 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19361#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19362 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19363#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19364 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19365#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19366 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19367#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19368 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19369
c19d1205 19370/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19371 field is still 0xE. Many of the Thumb variants can be executed
19372 conditionally, so this is checked separately. */
c19d1205 19373#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19374 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19375 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19376
dd5181d5
KT
19377/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19378 Used by mnemonics that have very minimal differences in the encoding for
19379 ARM and Thumb variants and can be handled in a common function. */
19380#define TUEc(mnem, op, top, nops, ops, en) \
19381 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19382 THUMB_VARIANT, do_##en, do_##en }
19383
c19d1205
ZW
19384/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19385 condition code field. */
19386#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19387 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19388 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19389
19390/* ARM-only variants of all the above. */
6a86118a 19391#define CE(mnem, op, nops, ops, ae) \
21d799b5 19392 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19393
19394#define C3(mnem, op, nops, ops, ae) \
19395 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19396
e3cb604e
PB
19397/* Legacy mnemonics that always have conditional infix after the third
19398 character. */
19399#define CL(mnem, op, nops, ops, ae) \
21d799b5 19400 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19401 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19402
8f06b2d8
PB
19403/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19404#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19405 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19406
e3cb604e
PB
19407/* Legacy coprocessor instructions where conditional infix and conditional
19408 suffix are ambiguous. For consistency this includes all FPA instructions,
19409 not just the potentially ambiguous ones. */
19410#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19411 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19412 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19413
19414/* Coprocessor, takes either a suffix or a position-3 infix
19415 (for an FPA corner case). */
19416#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19417 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19418 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19419
6a86118a 19420#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19421 { m1 #m2 m3, OPS##nops ops, \
19422 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19423 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19424
19425#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19426 xCM_ (m1, , m2, op, nops, ops, ae), \
19427 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19428 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19429 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19430 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19431 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19432 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19433 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19434 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19435 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19436 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19437 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19438 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19439 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19440 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19441 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19442 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19443 xCM_ (m1, le, m2, op, nops, ops, ae), \
19444 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19445
19446#define UE(mnem, op, nops, ops, ae) \
19447 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19448
19449#define UF(mnem, op, nops, ops, ae) \
19450 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19451
5287ad62
JB
19452/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19453 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19454 use the same encoding function for each. */
19455#define NUF(mnem, op, nops, ops, enc) \
19456 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19457 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19458
19459/* Neon data processing, version which indirects through neon_enc_tab for
19460 the various overloaded versions of opcodes. */
19461#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19462 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19463 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19464
19465/* Neon insn with conditional suffix for the ARM version, non-overloaded
19466 version. */
037e8744
JB
19467#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19468 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19469 THUMB_VARIANT, do_##enc, do_##enc }
19470
037e8744 19471#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19472 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19473
19474#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19475 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19476
5287ad62 19477/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19478#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19479 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19480 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19481
037e8744 19482#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19483 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19484
19485#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19486 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19487
c19d1205
ZW
19488#define do_0 0
19489
c19d1205 19490static const struct asm_opcode insns[] =
bfae80f2 19491{
74db7efb
NC
19492#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19493#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19494 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19495 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19496 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19497 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19498 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19499 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19500 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19501 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19502 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19503 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19504 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19505 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19506 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19507 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19508 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19509 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19510
19511 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19512 for setting PSR flag bits. They are obsolete in V6 and do not
19513 have Thumb equivalents. */
21d799b5
NC
19514 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19515 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19516 CL("tstp", 110f000, 2, (RR, SH), cmp),
19517 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19518 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19519 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19520 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19521 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19522 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19523
19524 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19525 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19526 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19527 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19528
19529 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19530 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19531 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19532 OP_RRnpc),
19533 OP_ADDRGLDR),ldst, t_ldst),
19534 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19535
19536 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19537 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19538 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19539 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19540 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19541 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19542
21d799b5
NC
19543 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19544 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19545
c19d1205 19546 /* Pseudo ops. */
21d799b5 19547 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19548 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19549 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19550 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19551
19552 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19553 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19554 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19555 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19556 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19557 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19558 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19559 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19560 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19561 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19562 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19563 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19564 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19565
16a4cf17 19566 /* These may simplify to neg. */
21d799b5
NC
19567 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19568 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19569
173205ca
TP
19570#undef THUMB_VARIANT
19571#define THUMB_VARIANT & arm_ext_os
19572
19573 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19574 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19575
c921be7d
NC
19576#undef THUMB_VARIANT
19577#define THUMB_VARIANT & arm_ext_v6
19578
21d799b5 19579 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19580
19581 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19582#undef THUMB_VARIANT
19583#define THUMB_VARIANT & arm_ext_v6t2
19584
21d799b5
NC
19585 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19586 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19587 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19588
5be8be5d
DG
19589 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19590 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19591 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19592 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19593
21d799b5
NC
19594 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19595 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19596
21d799b5
NC
19597 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19598 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19599
19600 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19601 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19602 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19603
19604 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19605 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19606 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19607 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19608 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19609 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19610 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19611 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19612
c921be7d
NC
19613#undef ARM_VARIANT
19614#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19615#undef THUMB_VARIANT
19616#define THUMB_VARIANT & arm_ext_v4t
19617
21d799b5
NC
19618 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19619 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19620
c921be7d
NC
19621#undef THUMB_VARIANT
19622#define THUMB_VARIANT & arm_ext_v6t2
19623
21d799b5 19624 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19625 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19626
19627 /* Generic coprocessor instructions. */
21d799b5
NC
19628 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19629 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19630 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19631 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19632 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19633 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19634 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19635
c921be7d
NC
19636#undef ARM_VARIANT
19637#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19638
21d799b5 19639 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19640 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19641
c921be7d
NC
19642#undef ARM_VARIANT
19643#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19644#undef THUMB_VARIANT
19645#define THUMB_VARIANT & arm_ext_msr
19646
d2cd1205
JB
19647 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19648 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19649
c921be7d
NC
19650#undef ARM_VARIANT
19651#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19652#undef THUMB_VARIANT
19653#define THUMB_VARIANT & arm_ext_v6t2
19654
21d799b5
NC
19655 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19656 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19657 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19658 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19659 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19660 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19661 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19662 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19663
c921be7d
NC
19664#undef ARM_VARIANT
19665#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19666#undef THUMB_VARIANT
19667#define THUMB_VARIANT & arm_ext_v4t
19668
5be8be5d
DG
19669 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19670 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19671 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19672 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19673 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19674 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19675
c921be7d
NC
19676#undef ARM_VARIANT
19677#define ARM_VARIANT & arm_ext_v4t_5
19678
c19d1205
ZW
19679 /* ARM Architecture 4T. */
19680 /* Note: bx (and blx) are required on V5, even if the processor does
19681 not support Thumb. */
21d799b5 19682 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19683
c921be7d
NC
19684#undef ARM_VARIANT
19685#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19686#undef THUMB_VARIANT
19687#define THUMB_VARIANT & arm_ext_v5t
19688
c19d1205
ZW
19689 /* Note: blx has 2 variants; the .value coded here is for
19690 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19691 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19692 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19693
c921be7d
NC
19694#undef THUMB_VARIANT
19695#define THUMB_VARIANT & arm_ext_v6t2
19696
21d799b5
NC
19697 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19698 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19699 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19700 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19701 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19702 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19703 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19704 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19705
c921be7d 19706#undef ARM_VARIANT
74db7efb
NC
19707#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19708#undef THUMB_VARIANT
19709#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19710
21d799b5
NC
19711 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19712 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19713 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19714 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19715
21d799b5
NC
19716 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19717 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19718
21d799b5
NC
19719 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19720 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19721 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19722 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19723
21d799b5
NC
19724 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19725 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19726 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19727 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19728
21d799b5
NC
19729 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19730 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19731
03ee1b7f
NC
19732 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19733 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19734 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19735 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19736
c921be7d 19737#undef ARM_VARIANT
74db7efb
NC
19738#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19739#undef THUMB_VARIANT
19740#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19741
21d799b5 19742 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19743 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19744 ldrd, t_ldstd),
19745 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19746 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19747
21d799b5
NC
19748 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19749 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19750
c921be7d
NC
19751#undef ARM_VARIANT
19752#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19753
21d799b5 19754 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19755
c921be7d
NC
19756#undef ARM_VARIANT
19757#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19758#undef THUMB_VARIANT
19759#define THUMB_VARIANT & arm_ext_v6
19760
21d799b5
NC
19761 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19762 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19763 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19764 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19765 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19766 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19767 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19768 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19769 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19770 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19771
c921be7d 19772#undef THUMB_VARIANT
ff8646ee 19773#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19774
5be8be5d
DG
19775 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19776 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19777 strex, t_strex),
ff8646ee
TP
19778#undef THUMB_VARIANT
19779#define THUMB_VARIANT & arm_ext_v6t2
19780
21d799b5
NC
19781 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19782 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19783
21d799b5
NC
19784 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19785 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19786
9e3c6df6 19787/* ARM V6 not included in V7M. */
c921be7d
NC
19788#undef THUMB_VARIANT
19789#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19790 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19791 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19792 UF(rfeib, 9900a00, 1, (RRw), rfe),
19793 UF(rfeda, 8100a00, 1, (RRw), rfe),
19794 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19795 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19796 UF(rfefa, 8100a00, 1, (RRw), rfe),
19797 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19798 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19799 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19800 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19801 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19802 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19803 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19804 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19805 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19806 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19807 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19808 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19809
9e3c6df6
PB
19810/* ARM V6 not included in V7M (eg. integer SIMD). */
19811#undef THUMB_VARIANT
19812#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19813 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19814 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19815 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19816 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19817 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19818 /* Old name for QASX. */
74db7efb 19819 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19820 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19821 /* Old name for QSAX. */
74db7efb 19822 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19823 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19824 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19825 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19826 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19827 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19828 /* Old name for SASX. */
74db7efb 19829 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19830 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19831 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19832 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19833 /* Old name for SHASX. */
21d799b5 19834 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19835 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19836 /* Old name for SHSAX. */
21d799b5
NC
19837 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19838 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19839 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19840 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19841 /* Old name for SSAX. */
74db7efb 19842 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19843 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19844 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19845 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19846 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19847 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19848 /* Old name for UASX. */
74db7efb 19849 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19850 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19851 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19852 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19853 /* Old name for UHASX. */
21d799b5
NC
19854 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19855 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19856 /* Old name for UHSAX. */
21d799b5
NC
19857 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19858 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19859 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19860 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19861 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19862 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19863 /* Old name for UQASX. */
21d799b5
NC
19864 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19865 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19866 /* Old name for UQSAX. */
21d799b5
NC
19867 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19868 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19869 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19870 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19871 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19872 /* Old name for USAX. */
74db7efb 19873 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19874 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19875 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19876 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19877 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19878 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19879 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19880 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19881 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19882 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19883 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19884 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19885 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19886 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19887 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19888 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19889 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19890 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19891 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19892 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19893 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19894 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19895 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19896 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19897 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19898 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19899 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19900 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19901 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19902 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19903 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19904 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19905 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19906 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19907
c921be7d
NC
19908#undef ARM_VARIANT
19909#define ARM_VARIANT & arm_ext_v6k
19910#undef THUMB_VARIANT
19911#define THUMB_VARIANT & arm_ext_v6k
19912
21d799b5
NC
19913 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19914 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19915 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19916 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19917
c921be7d
NC
19918#undef THUMB_VARIANT
19919#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19920 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19921 ldrexd, t_ldrexd),
19922 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19923 RRnpcb), strexd, t_strexd),
ebdca51a 19924
c921be7d 19925#undef THUMB_VARIANT
ff8646ee 19926#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19927 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19928 rd_rn, rd_rn),
19929 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19930 rd_rn, rd_rn),
19931 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19932 strex, t_strexbh),
5be8be5d 19933 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19934 strex, t_strexbh),
21d799b5 19935 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19936
c921be7d 19937#undef ARM_VARIANT
f4c65163 19938#define ARM_VARIANT & arm_ext_sec
74db7efb 19939#undef THUMB_VARIANT
f4c65163 19940#define THUMB_VARIANT & arm_ext_sec
c921be7d 19941
21d799b5 19942 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19943
90ec0d68
MGD
19944#undef ARM_VARIANT
19945#define ARM_VARIANT & arm_ext_virt
19946#undef THUMB_VARIANT
19947#define THUMB_VARIANT & arm_ext_virt
19948
19949 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19950 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19951
ddfded2f
MW
19952#undef ARM_VARIANT
19953#define ARM_VARIANT & arm_ext_pan
19954#undef THUMB_VARIANT
19955#define THUMB_VARIANT & arm_ext_pan
19956
19957 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19958
c921be7d 19959#undef ARM_VARIANT
74db7efb 19960#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19961#undef THUMB_VARIANT
19962#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19963
21d799b5
NC
19964 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19965 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19966 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19967 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19968
21d799b5 19969 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19970 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19971
5be8be5d
DG
19972 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19973 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19974 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19975 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19976
ff8646ee
TP
19977#undef THUMB_VARIANT
19978#define THUMB_VARIANT & arm_ext_v6t2_v8m
19979 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19980 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19981
bf3eeda7 19982 /* Thumb-only instructions. */
74db7efb 19983#undef ARM_VARIANT
bf3eeda7
NS
19984#define ARM_VARIANT NULL
19985 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19986 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19987
19988 /* ARM does not really have an IT instruction, so always allow it.
19989 The opcode is copied from Thumb in order to allow warnings in
19990 -mimplicit-it=[never | arm] modes. */
19991#undef ARM_VARIANT
19992#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19993#undef THUMB_VARIANT
19994#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19995
21d799b5
NC
19996 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19997 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19998 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19999 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20000 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20001 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20002 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20003 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20004 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20005 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20006 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20007 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20008 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20009 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20010 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 20011 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
20012 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20013 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 20014
92e90b6e 20015 /* Thumb2 only instructions. */
c921be7d
NC
20016#undef ARM_VARIANT
20017#define ARM_VARIANT NULL
92e90b6e 20018
21d799b5
NC
20019 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20020 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20021 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20022 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20023 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20024 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 20025
eea54501
MGD
20026 /* Hardware division instructions. */
20027#undef ARM_VARIANT
20028#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
20029#undef THUMB_VARIANT
20030#define THUMB_VARIANT & arm_ext_div
20031
eea54501
MGD
20032 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20033 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 20034
7e806470 20035 /* ARM V6M/V7 instructions. */
c921be7d
NC
20036#undef ARM_VARIANT
20037#define ARM_VARIANT & arm_ext_barrier
20038#undef THUMB_VARIANT
20039#define THUMB_VARIANT & arm_ext_barrier
20040
ccb84d65
JB
20041 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20042 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20043 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 20044
62b3e311 20045 /* ARM V7 instructions. */
c921be7d
NC
20046#undef ARM_VARIANT
20047#define ARM_VARIANT & arm_ext_v7
20048#undef THUMB_VARIANT
20049#define THUMB_VARIANT & arm_ext_v7
20050
21d799b5
NC
20051 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20052 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 20053
74db7efb 20054#undef ARM_VARIANT
60e5ef9f 20055#define ARM_VARIANT & arm_ext_mp
74db7efb 20056#undef THUMB_VARIANT
60e5ef9f
MGD
20057#define THUMB_VARIANT & arm_ext_mp
20058
20059 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20060
53c4b28b
MGD
20061 /* AArchv8 instructions. */
20062#undef ARM_VARIANT
20063#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
20064
20065/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 20066#undef THUMB_VARIANT
4ed7ed8d 20067#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 20068
4ed7ed8d
TP
20069 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20070 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20071 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20072 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20073 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20074 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 20075 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
20076 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20077 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20078 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20079 stlex, t_stlex),
4b8c8c02
RE
20080 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20081 stlex, t_stlex),
20082 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20083 stlex, t_stlex),
4ed7ed8d
TP
20084#undef THUMB_VARIANT
20085#define THUMB_VARIANT & arm_ext_v8
53c4b28b 20086
4ed7ed8d
TP
20087 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
20088 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20089 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20090 ldrexd, t_ldrexd),
20091 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20092 strexd, t_strexd),
8884b720 20093 /* ARMv8 T32 only. */
74db7efb 20094#undef ARM_VARIANT
b79f7053
MGD
20095#define ARM_VARIANT NULL
20096 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20097 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20098 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20099
33399f07
MGD
20100 /* FP for ARMv8. */
20101#undef ARM_VARIANT
a715796b 20102#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 20103#undef THUMB_VARIANT
a715796b 20104#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
20105
20106 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20107 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20108 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20109 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
20110 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20111 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
20112 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20113 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20114 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20115 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
20116 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20117 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20118 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20119 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20120 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20121 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20122 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 20123
91ff7894
MGD
20124 /* Crypto v1 extensions. */
20125#undef ARM_VARIANT
20126#define ARM_VARIANT & fpu_crypto_ext_armv8
20127#undef THUMB_VARIANT
20128#define THUMB_VARIANT & fpu_crypto_ext_armv8
20129
20130 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20131 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20132 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20133 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
20134 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20135 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20136 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20137 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20138 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20139 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20140 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
20141 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20142 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20143 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 20144
dd5181d5 20145#undef ARM_VARIANT
74db7efb 20146#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
20147#undef THUMB_VARIANT
20148#define THUMB_VARIANT & crc_ext_armv8
20149 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20150 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20151 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20152 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20153 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20154 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20155
105bde57
MW
20156 /* ARMv8.2 RAS extension. */
20157#undef ARM_VARIANT
4d1464f2 20158#define ARM_VARIANT & arm_ext_ras
105bde57 20159#undef THUMB_VARIANT
4d1464f2 20160#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
20161 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20162
49e8a725
SN
20163#undef ARM_VARIANT
20164#define ARM_VARIANT & arm_ext_v8_3
20165#undef THUMB_VARIANT
20166#define THUMB_VARIANT & arm_ext_v8_3
20167 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
20168 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20169 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 20170
c604a79a
JW
20171#undef ARM_VARIANT
20172#define ARM_VARIANT & fpu_neon_ext_dotprod
20173#undef THUMB_VARIANT
20174#define THUMB_VARIANT & fpu_neon_ext_dotprod
20175 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20176 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20177
c921be7d
NC
20178#undef ARM_VARIANT
20179#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
20180#undef THUMB_VARIANT
20181#define THUMB_VARIANT NULL
c921be7d 20182
21d799b5
NC
20183 cCE("wfs", e200110, 1, (RR), rd),
20184 cCE("rfs", e300110, 1, (RR), rd),
20185 cCE("wfc", e400110, 1, (RR), rd),
20186 cCE("rfc", e500110, 1, (RR), rd),
20187
20188 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20189 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20190 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20191 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20192
20193 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20194 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20195 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20196 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20197
20198 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20199 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20200 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20201 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20202 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20203 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20204 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20205 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20206 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20207 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20208 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20209 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20210
20211 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20212 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20213 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20214 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20215 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20216 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20217 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20218 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20219 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20220 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20221 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20222 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20223
20224 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20225 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20226 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20227 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20228 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20229 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20230 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20231 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20232 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20233 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20234 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20235 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20236
20237 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20238 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20239 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20240 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20241 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20242 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20243 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20244 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20245 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20246 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20247 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20248 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20249
20250 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20251 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20252 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20253 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20254 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20255 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20256 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20257 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20258 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20259 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20260 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20261 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20262
20263 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20264 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20265 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20266 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20267 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20268 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20269 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20270 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20271 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20272 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20273 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20274 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20275
20276 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20277 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20278 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20279 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20280 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20281 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20282 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20283 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20284 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20285 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20286 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20287 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20288
20289 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20290 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20291 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20292 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20293 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20294 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20295 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20296 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20297 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20298 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20299 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20300 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20301
20302 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20303 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20304 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20305 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20306 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20307 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20308 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20309 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20310 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20311 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20312 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20313 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20314
20315 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20316 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20317 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20318 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20319 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20320 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20321 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20322 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20323 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20324 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20325 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20326 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20327
20328 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20329 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20330 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20331 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20332 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20333 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20334 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20335 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20336 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20337 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20338 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20339 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20340
20341 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20342 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20343 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20344 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20345 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20346 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20347 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20348 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20349 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20350 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20351 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20352 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20353
20354 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20355 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20356 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20357 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20358 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20359 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20360 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20361 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20362 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20363 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20364 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20365 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20366
20367 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20368 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20369 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20370 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20371 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20372 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20373 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20374 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20375 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20376 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20377 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20378 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20379
20380 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20381 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20382 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20383 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20384 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20385 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20386 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20387 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20388 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20389 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20390 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20391 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20392
20393 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20394 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20395 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20396 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20397 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20398 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20399 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20400 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20401 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20402 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20403 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20404 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20405
20406 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20407 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20408 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20409 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20410 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20411 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20412 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20413 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20414 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20415 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20416 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20417 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20418
20419 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20420 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20421 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20422 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20423 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20424 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20425 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20426 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20427 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20428 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20429 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20430 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20431
20432 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20433 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20434 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20435 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20436 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20437 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20438 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20439 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20440 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20441 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20442 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20443 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20444
20445 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20446 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20447 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20448 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20449 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20450 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20451 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20452 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20453 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20454 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20455 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20456 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20457
20458 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20459 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20460 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20461 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20462 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20463 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20464 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20465 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20466 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20467 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20468 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20469 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20470
20471 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20472 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20473 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20474 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20475 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20476 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20477 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20478 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20479 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20480 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20481 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20482 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20483
20484 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20485 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20486 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20487 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20488 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20489 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20490 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20491 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20492 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20493 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20494 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20495 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20496
20497 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20498 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20499 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20500 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20501 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20502 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20503 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20504 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20505 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20506 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20507 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20508 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20509
20510 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20511 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20512 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20513 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20514 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20515 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20516 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20517 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20518 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20519 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20520 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20521 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20522
20523 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20524 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20525 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20526 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20527 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20528 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20529 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20530 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20531 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20532 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20533 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20534 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20535
20536 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20537 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20538 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20539 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20540 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20541 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20542 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20543 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20544 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20545 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20546 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20547 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20548
20549 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20550 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20551 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20552 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20553 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20554 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20555 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20556 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20557 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20558 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20559 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20560 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20561
20562 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20563 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20564 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20565 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20566 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20567 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20568 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20569 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20570 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20571 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20572 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20574
20575 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20576 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20577 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20578 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20579
20580 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20581 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20582 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20583 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20584 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20585 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20586 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20587 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20588 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20589 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20590 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20591 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20592
c19d1205
ZW
20593 /* The implementation of the FIX instruction is broken on some
20594 assemblers, in that it accepts a precision specifier as well as a
20595 rounding specifier, despite the fact that this is meaningless.
20596 To be more compatible, we accept it as well, though of course it
20597 does not set any bits. */
21d799b5
NC
20598 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20599 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20600 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20601 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20602 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20603 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20604 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20605 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20606 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20607 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20608 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20609 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20610 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20611
c19d1205 20612 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20613#undef ARM_VARIANT
20614#define ARM_VARIANT & fpu_fpa_ext_v2
20615
21d799b5
NC
20616 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20617 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20618 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20619 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20620 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20621 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20622
c921be7d
NC
20623#undef ARM_VARIANT
20624#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20625
c19d1205 20626 /* Moves and type conversions. */
21d799b5
NC
20627 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20628 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20629 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20630 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20631 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20632 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20633 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20634 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20635 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20636 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20637 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20638 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20639 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20640 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20641
20642 /* Memory operations. */
21d799b5
NC
20643 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20644 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20645 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20646 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20647 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20648 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20649 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20650 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20651 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20652 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20653 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20654 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20655 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20656 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20657 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20658 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20659 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20660 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20661
c19d1205 20662 /* Monadic operations. */
21d799b5
NC
20663 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20664 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20665 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20666
20667 /* Dyadic operations. */
21d799b5
NC
20668 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20669 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20670 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20671 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20672 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20673 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20674 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20675 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20676 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20677
c19d1205 20678 /* Comparisons. */
21d799b5
NC
20679 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20680 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20681 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20682 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20683
62f3b8c8
PB
20684 /* Double precision load/store are still present on single precision
20685 implementations. */
20686 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20687 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20688 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20689 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20690 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20691 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20692 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20693 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20694 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20695 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20696
c921be7d
NC
20697#undef ARM_VARIANT
20698#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20699
c19d1205 20700 /* Moves and type conversions. */
21d799b5
NC
20701 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20702 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20703 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20704 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20705 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20706 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20707 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20708 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20709 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20710 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20711 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20712 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20713 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20714
c19d1205 20715 /* Monadic operations. */
21d799b5
NC
20716 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20717 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20718 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20719
20720 /* Dyadic operations. */
21d799b5
NC
20721 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20722 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20723 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20724 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20725 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20726 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20727 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20728 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20729 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20730
c19d1205 20731 /* Comparisons. */
21d799b5
NC
20732 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20733 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20734 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20735 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20736
c921be7d
NC
20737#undef ARM_VARIANT
20738#define ARM_VARIANT & fpu_vfp_ext_v2
20739
21d799b5
NC
20740 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20741 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20742 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20743 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20744
037e8744
JB
20745/* Instructions which may belong to either the Neon or VFP instruction sets.
20746 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20747#undef ARM_VARIANT
20748#define ARM_VARIANT & fpu_vfp_ext_v1xd
20749#undef THUMB_VARIANT
20750#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20751
037e8744
JB
20752 /* These mnemonics are unique to VFP. */
20753 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20754 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20755 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20756 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20757 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20758 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20759 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20760 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20761 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20762 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20763
20764 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20765 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20766 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20767 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20768
21d799b5
NC
20769 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20770 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20771
20772 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20773 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20774
55881a11
MGD
20775 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20776 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20777 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20778 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20779 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20780 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20781 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20782 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20783
5f1af56b 20784 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20785 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20786 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20787 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20788
037e8744
JB
20789
20790 /* NOTE: All VMOV encoding is special-cased! */
20791 NCE(vmov, 0, 1, (VMOV), neon_mov),
20792 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20793
9db2f6b4
RL
20794#undef ARM_VARIANT
20795#define ARM_VARIANT & arm_ext_fp16
20796#undef THUMB_VARIANT
20797#define THUMB_VARIANT & arm_ext_fp16
20798 /* New instructions added from v8.2, allowing the extraction and insertion of
20799 the upper 16 bits of a 32-bit vector register. */
20800 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20801 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20802
dec41383
JW
20803 /* New backported fma/fms instructions optional in v8.2. */
20804 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20805 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20806
c921be7d
NC
20807#undef THUMB_VARIANT
20808#define THUMB_VARIANT & fpu_neon_ext_v1
20809#undef ARM_VARIANT
20810#define ARM_VARIANT & fpu_neon_ext_v1
20811
5287ad62
JB
20812 /* Data processing with three registers of the same length. */
20813 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20814 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20815 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20816 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20817 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20818 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20819 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20820 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20821 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20822 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20823 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20824 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20825 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20826 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20827 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20828 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20829 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20830 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20831 /* If not immediate, fall back to neon_dyadic_i64_su.
20832 shl_imm should accept I8 I16 I32 I64,
20833 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20834 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20835 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20836 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20837 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20838 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20839 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20840 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20841 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20842 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20843 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20844 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20845 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20846 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20847 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20848 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20849 /* Bitfield ops, untyped. */
20850 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20851 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20852 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20853 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20854 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20855 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20856 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20857 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20858 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20859 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20860 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20861 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20862 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20863 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20864 back to neon_dyadic_if_su. */
21d799b5
NC
20865 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20866 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20867 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20868 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20869 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20870 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20871 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20872 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20873 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20874 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20875 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20876 /* As above, D registers only. */
21d799b5
NC
20877 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20878 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20879 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20880 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20881 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20882 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20883 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20884 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20885 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20886 /* vtst takes sizes 8, 16, 32. */
20887 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20888 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20889 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20890 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20891 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20892 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20893 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20894 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20895 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20896 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20897 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20898 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20899 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20900 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20901 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20902 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20903 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20904 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20905 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20906 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20907 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20908 /* ARM v8.1 extension. */
643afb90
MW
20909 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20910 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20911 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20912 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20913
20914 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20915 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20916 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20917
20918 /* Data processing with two registers and a shift amount. */
20919 /* Right shifts, and variants with rounding.
20920 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20921 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20922 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20923 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20924 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20925 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20926 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20927 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20928 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20929 /* Shift and insert. Sizes accepted 8 16 32 64. */
20930 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20931 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20932 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20933 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20934 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20935 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20936 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20937 /* Right shift immediate, saturating & narrowing, with rounding variants.
20938 Types accepted S16 S32 S64 U16 U32 U64. */
20939 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20940 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20941 /* As above, unsigned. Types accepted S16 S32 S64. */
20942 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20943 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20944 /* Right shift narrowing. Types accepted I16 I32 I64. */
20945 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20946 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20947 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20948 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20949 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20950 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20951
4316f0d2
DG
20952 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20953 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20954
20955 /* Data processing, three registers of different lengths. */
20956 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20957 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20958 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20959 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20960 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20961 /* If not scalar, fall back to neon_dyadic_long.
20962 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20963 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20964 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20965 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20966 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20967 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20968 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20969 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20970 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20971 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20972 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20973 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20974 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20975 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20976 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20977 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20978 S16 S32 U16 U32. */
21d799b5 20979 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20980
20981 /* Extract. Size 8. */
3b8d421e
PB
20982 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20983 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20984
20985 /* Two registers, miscellaneous. */
20986 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20987 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20988 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20989 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20990 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20991 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20992 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20993 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20994 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20995 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20996 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20997 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20998 /* VMOVN. Types I16 I32 I64. */
21d799b5 20999 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 21000 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 21001 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 21002 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 21003 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
21004 /* VZIP / VUZP. Sizes 8 16 32. */
21005 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21006 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21007 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21008 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21009 /* VQABS / VQNEG. Types S8 S16 S32. */
21010 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21011 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21012 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21013 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21014 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21015 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21016 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21017 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21018 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 21019 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
21020 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21021 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21022 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21023 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21024 /* VCLS. Types S8 S16 S32. */
21025 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21026 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21027 /* VCLZ. Types I8 I16 I32. */
21028 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21029 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21030 /* VCNT. Size 8. */
21031 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21032 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21033 /* Two address, untyped. */
21034 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21035 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21036 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
21037 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21038 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
21039
21040 /* Table lookup. Size 8. */
21041 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21042 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21043
c921be7d
NC
21044#undef THUMB_VARIANT
21045#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21046#undef ARM_VARIANT
21047#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21048
5287ad62 21049 /* Neon element/structure load/store. */
21d799b5
NC
21050 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21051 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21052 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21053 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21054 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21055 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21056 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21057 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 21058
c921be7d 21059#undef THUMB_VARIANT
74db7efb
NC
21060#define THUMB_VARIANT & fpu_vfp_ext_v3xd
21061#undef ARM_VARIANT
21062#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
21063 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21064 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21065 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21066 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21067 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21068 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21069 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21070 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21071 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21072
74db7efb 21073#undef THUMB_VARIANT
c921be7d
NC
21074#define THUMB_VARIANT & fpu_vfp_ext_v3
21075#undef ARM_VARIANT
21076#define ARM_VARIANT & fpu_vfp_ext_v3
21077
21d799b5 21078 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 21079 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21080 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21081 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21082 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21083 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21084 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 21085 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 21086 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 21087
74db7efb
NC
21088#undef ARM_VARIANT
21089#define ARM_VARIANT & fpu_vfp_ext_fma
21090#undef THUMB_VARIANT
21091#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
21092 /* Mnemonics shared by Neon and VFP. These are included in the
21093 VFP FMA variant; NEON and VFP FMA always includes the NEON
21094 FMA instructions. */
21095 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21096 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21097 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21098 the v form should always be used. */
21099 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21100 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21101 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21102 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21103 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21104 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21105
5287ad62 21106#undef THUMB_VARIANT
c921be7d
NC
21107#undef ARM_VARIANT
21108#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21109
21d799b5
NC
21110 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21111 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21112 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21113 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21114 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21115 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21116 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21117 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 21118
c921be7d
NC
21119#undef ARM_VARIANT
21120#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21121
21d799b5
NC
21122 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21123 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21124 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21125 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21126 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21127 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21128 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21129 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21130 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
21131 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21132 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21133 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21134 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21135 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21136 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
21137 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21138 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21139 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21140 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21141 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21142 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21143 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21144 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21145 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21146 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21147 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
21148 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21149 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21150 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
21151 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21152 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21153 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21154 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21155 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21156 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21157 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21158 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21159 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21160 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21161 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21162 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21163 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21164 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21165 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21166 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21167 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21168 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
21169 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21170 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21171 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21172 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21173 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21174 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21175 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21176 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21177 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21178 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21179 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21180 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21181 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21182 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21183 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21184 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21185 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21186 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21187 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21188 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21189 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21190 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21191 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21192 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21193 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21194 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21195 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21196 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21197 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21198 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21199 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21200 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21201 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21202 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21203 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21204 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21205 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21206 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21207 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21208 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21209 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21210 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21211 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21212 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21213 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21214 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21215 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
21216 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21217 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21218 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21219 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21220 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21221 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
21222 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21223 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21224 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21225 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21226 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21227 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21228 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21229 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21230 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21231 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21232 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21233 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21234 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21235 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21236 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21237 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21238 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21239 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21240 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21241 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21242 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21243 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21244 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21245 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21246 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21247 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21248 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21249 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21250 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21251 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21252 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21253 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21254 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21255 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21256 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21257 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21258 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21259 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21260 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21261 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21262 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21263 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21264 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21265 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21266 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21267 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21268 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21269 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21270 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21271 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21272 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21273 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21274 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21275 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21276 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21277 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21278 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21279 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21280 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21281 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21282 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21283 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21284
c921be7d
NC
21285#undef ARM_VARIANT
21286#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21287
21d799b5
NC
21288 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21289 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21290 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21291 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21292 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21293 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21294 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21295 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21296 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21297 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21298 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21299 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21300 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21301 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21302 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21303 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21304 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21305 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21306 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21307 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21308 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21309 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21310 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21311 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21312 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21313 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21314 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21315 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21316 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21317 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21318 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21319 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21320 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21321 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21322 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21323 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21324 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21325 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21326 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21327 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21328 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21329 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21330 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21331 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21332 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21333 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21334 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21335 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21336 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21337 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21338 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21339 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21340 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21341 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21342 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21343 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21344 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21345
c921be7d
NC
21346#undef ARM_VARIANT
21347#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21348
21d799b5
NC
21349 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21350 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21351 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21352 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21353 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21354 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21355 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21356 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21357 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21358 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21359 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21360 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21361 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21362 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21363 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21364 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21365 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21366 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21367 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21368 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21369 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21370 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21371 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21372 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21373 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21374 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21375 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21376 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21377 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21378 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21379 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21380 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21381 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21382 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21383 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21384 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21385 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21386 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21387 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21388 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21389 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21390 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21391 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21392 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21393 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21394 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21395 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21396 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21397 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21398 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21399 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21400 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21401 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21402 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21403 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21404 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21405 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21406 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21407 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21408 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21409 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21410 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21411 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21412 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21413 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21414 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21415 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21416 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21417 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21418 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21419 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21420 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21421 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21422 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21423 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21424 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21425
16a1fa25 21426 /* ARMv8-M instructions. */
4ed7ed8d
TP
21427#undef ARM_VARIANT
21428#define ARM_VARIANT NULL
21429#undef THUMB_VARIANT
21430#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21431 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21432 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21433 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21434 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21435 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21436 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21437 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21438
21439 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21440 instructions behave as nop if no VFP is present. */
21441#undef THUMB_VARIANT
21442#define THUMB_VARIANT & arm_ext_v8m_main
21443 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21444 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21445};
21446#undef ARM_VARIANT
21447#undef THUMB_VARIANT
21448#undef TCE
c19d1205
ZW
21449#undef TUE
21450#undef TUF
21451#undef TCC
8f06b2d8 21452#undef cCE
e3cb604e
PB
21453#undef cCL
21454#undef C3E
c19d1205
ZW
21455#undef CE
21456#undef CM
21457#undef UE
21458#undef UF
21459#undef UT
5287ad62
JB
21460#undef NUF
21461#undef nUF
21462#undef NCE
21463#undef nCE
c19d1205
ZW
21464#undef OPS0
21465#undef OPS1
21466#undef OPS2
21467#undef OPS3
21468#undef OPS4
21469#undef OPS5
21470#undef OPS6
21471#undef do_0
21472\f
21473/* MD interface: bits in the object file. */
bfae80f2 21474
c19d1205
ZW
21475/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21476 for use in the a.out file, and stores them in the array pointed to by buf.
21477 This knows about the endian-ness of the target machine and does
21478 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21479 2 (short) and 4 (long) Floating numbers are put out as a series of
21480 LITTLENUMS (shorts, here at least). */
b99bd4ef 21481
c19d1205
ZW
21482void
21483md_number_to_chars (char * buf, valueT val, int n)
21484{
21485 if (target_big_endian)
21486 number_to_chars_bigendian (buf, val, n);
21487 else
21488 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21489}
21490
c19d1205
ZW
21491static valueT
21492md_chars_to_number (char * buf, int n)
bfae80f2 21493{
c19d1205
ZW
21494 valueT result = 0;
21495 unsigned char * where = (unsigned char *) buf;
bfae80f2 21496
c19d1205 21497 if (target_big_endian)
b99bd4ef 21498 {
c19d1205
ZW
21499 while (n--)
21500 {
21501 result <<= 8;
21502 result |= (*where++ & 255);
21503 }
b99bd4ef 21504 }
c19d1205 21505 else
b99bd4ef 21506 {
c19d1205
ZW
21507 while (n--)
21508 {
21509 result <<= 8;
21510 result |= (where[n] & 255);
21511 }
bfae80f2 21512 }
b99bd4ef 21513
c19d1205 21514 return result;
bfae80f2 21515}
b99bd4ef 21516
c19d1205 21517/* MD interface: Sections. */
b99bd4ef 21518
fa94de6b
RM
21519/* Calculate the maximum variable size (i.e., excluding fr_fix)
21520 that an rs_machine_dependent frag may reach. */
21521
21522unsigned int
21523arm_frag_max_var (fragS *fragp)
21524{
21525 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21526 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21527
21528 Note that we generate relaxable instructions even for cases that don't
21529 really need it, like an immediate that's a trivial constant. So we're
21530 overestimating the instruction size for some of those cases. Rather
21531 than putting more intelligence here, it would probably be better to
21532 avoid generating a relaxation frag in the first place when it can be
21533 determined up front that a short instruction will suffice. */
21534
21535 gas_assert (fragp->fr_type == rs_machine_dependent);
21536 return INSN_SIZE;
21537}
21538
0110f2b8
PB
21539/* Estimate the size of a frag before relaxing. Assume everything fits in
21540 2 bytes. */
21541
c19d1205 21542int
0110f2b8 21543md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21544 segT segtype ATTRIBUTE_UNUSED)
21545{
0110f2b8
PB
21546 fragp->fr_var = 2;
21547 return 2;
21548}
21549
21550/* Convert a machine dependent frag. */
21551
21552void
21553md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21554{
21555 unsigned long insn;
21556 unsigned long old_op;
21557 char *buf;
21558 expressionS exp;
21559 fixS *fixp;
21560 int reloc_type;
21561 int pc_rel;
21562 int opcode;
21563
21564 buf = fragp->fr_literal + fragp->fr_fix;
21565
21566 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21567 if (fragp->fr_symbol)
21568 {
0110f2b8
PB
21569 exp.X_op = O_symbol;
21570 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21571 }
21572 else
21573 {
0110f2b8 21574 exp.X_op = O_constant;
5f4273c7 21575 }
0110f2b8
PB
21576 exp.X_add_number = fragp->fr_offset;
21577 opcode = fragp->fr_subtype;
21578 switch (opcode)
21579 {
21580 case T_MNEM_ldr_pc:
21581 case T_MNEM_ldr_pc2:
21582 case T_MNEM_ldr_sp:
21583 case T_MNEM_str_sp:
21584 case T_MNEM_ldr:
21585 case T_MNEM_ldrb:
21586 case T_MNEM_ldrh:
21587 case T_MNEM_str:
21588 case T_MNEM_strb:
21589 case T_MNEM_strh:
21590 if (fragp->fr_var == 4)
21591 {
5f4273c7 21592 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21593 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21594 {
21595 insn |= (old_op & 0x700) << 4;
21596 }
21597 else
21598 {
21599 insn |= (old_op & 7) << 12;
21600 insn |= (old_op & 0x38) << 13;
21601 }
21602 insn |= 0x00000c00;
21603 put_thumb32_insn (buf, insn);
21604 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21605 }
21606 else
21607 {
21608 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21609 }
21610 pc_rel = (opcode == T_MNEM_ldr_pc2);
21611 break;
21612 case T_MNEM_adr:
21613 if (fragp->fr_var == 4)
21614 {
21615 insn = THUMB_OP32 (opcode);
21616 insn |= (old_op & 0xf0) << 4;
21617 put_thumb32_insn (buf, insn);
21618 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21619 }
21620 else
21621 {
21622 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21623 exp.X_add_number -= 4;
21624 }
21625 pc_rel = 1;
21626 break;
21627 case T_MNEM_mov:
21628 case T_MNEM_movs:
21629 case T_MNEM_cmp:
21630 case T_MNEM_cmn:
21631 if (fragp->fr_var == 4)
21632 {
21633 int r0off = (opcode == T_MNEM_mov
21634 || opcode == T_MNEM_movs) ? 0 : 8;
21635 insn = THUMB_OP32 (opcode);
21636 insn = (insn & 0xe1ffffff) | 0x10000000;
21637 insn |= (old_op & 0x700) << r0off;
21638 put_thumb32_insn (buf, insn);
21639 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21640 }
21641 else
21642 {
21643 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21644 }
21645 pc_rel = 0;
21646 break;
21647 case T_MNEM_b:
21648 if (fragp->fr_var == 4)
21649 {
21650 insn = THUMB_OP32(opcode);
21651 put_thumb32_insn (buf, insn);
21652 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21653 }
21654 else
21655 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21656 pc_rel = 1;
21657 break;
21658 case T_MNEM_bcond:
21659 if (fragp->fr_var == 4)
21660 {
21661 insn = THUMB_OP32(opcode);
21662 insn |= (old_op & 0xf00) << 14;
21663 put_thumb32_insn (buf, insn);
21664 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21665 }
21666 else
21667 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21668 pc_rel = 1;
21669 break;
21670 case T_MNEM_add_sp:
21671 case T_MNEM_add_pc:
21672 case T_MNEM_inc_sp:
21673 case T_MNEM_dec_sp:
21674 if (fragp->fr_var == 4)
21675 {
21676 /* ??? Choose between add and addw. */
21677 insn = THUMB_OP32 (opcode);
21678 insn |= (old_op & 0xf0) << 4;
21679 put_thumb32_insn (buf, insn);
16805f35
PB
21680 if (opcode == T_MNEM_add_pc)
21681 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21682 else
21683 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21684 }
21685 else
21686 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21687 pc_rel = 0;
21688 break;
21689
21690 case T_MNEM_addi:
21691 case T_MNEM_addis:
21692 case T_MNEM_subi:
21693 case T_MNEM_subis:
21694 if (fragp->fr_var == 4)
21695 {
21696 insn = THUMB_OP32 (opcode);
21697 insn |= (old_op & 0xf0) << 4;
21698 insn |= (old_op & 0xf) << 16;
21699 put_thumb32_insn (buf, insn);
16805f35
PB
21700 if (insn & (1 << 20))
21701 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21702 else
21703 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21704 }
21705 else
21706 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21707 pc_rel = 0;
21708 break;
21709 default:
5f4273c7 21710 abort ();
0110f2b8
PB
21711 }
21712 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21713 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21714 fixp->fx_file = fragp->fr_file;
21715 fixp->fx_line = fragp->fr_line;
21716 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21717
21718 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21719 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21720 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21721 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21722}
21723
21724/* Return the size of a relaxable immediate operand instruction.
21725 SHIFT and SIZE specify the form of the allowable immediate. */
21726static int
21727relax_immediate (fragS *fragp, int size, int shift)
21728{
21729 offsetT offset;
21730 offsetT mask;
21731 offsetT low;
21732
21733 /* ??? Should be able to do better than this. */
21734 if (fragp->fr_symbol)
21735 return 4;
21736
21737 low = (1 << shift) - 1;
21738 mask = (1 << (shift + size)) - (1 << shift);
21739 offset = fragp->fr_offset;
21740 /* Force misaligned offsets to 32-bit variant. */
21741 if (offset & low)
5e77afaa 21742 return 4;
0110f2b8
PB
21743 if (offset & ~mask)
21744 return 4;
21745 return 2;
21746}
21747
5e77afaa
PB
21748/* Get the address of a symbol during relaxation. */
21749static addressT
5f4273c7 21750relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21751{
21752 fragS *sym_frag;
21753 addressT addr;
21754 symbolS *sym;
21755
21756 sym = fragp->fr_symbol;
21757 sym_frag = symbol_get_frag (sym);
21758 know (S_GET_SEGMENT (sym) != absolute_section
21759 || sym_frag == &zero_address_frag);
21760 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21761
21762 /* If frag has yet to be reached on this pass, assume it will
21763 move by STRETCH just as we did. If this is not so, it will
21764 be because some frag between grows, and that will force
21765 another pass. */
21766
21767 if (stretch != 0
21768 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21769 {
21770 fragS *f;
21771
21772 /* Adjust stretch for any alignment frag. Note that if have
21773 been expanding the earlier code, the symbol may be
21774 defined in what appears to be an earlier frag. FIXME:
21775 This doesn't handle the fr_subtype field, which specifies
21776 a maximum number of bytes to skip when doing an
21777 alignment. */
21778 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21779 {
21780 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21781 {
21782 if (stretch < 0)
21783 stretch = - ((- stretch)
21784 & ~ ((1 << (int) f->fr_offset) - 1));
21785 else
21786 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21787 if (stretch == 0)
21788 break;
21789 }
21790 }
21791 if (f != NULL)
21792 addr += stretch;
21793 }
5e77afaa
PB
21794
21795 return addr;
21796}
21797
0110f2b8
PB
21798/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21799 load. */
21800static int
5e77afaa 21801relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21802{
21803 addressT addr;
21804 offsetT val;
21805
21806 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21807 if (fragp->fr_symbol == NULL
21808 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21809 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21810 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21811 return 4;
21812
5f4273c7 21813 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21814 addr = fragp->fr_address + fragp->fr_fix;
21815 addr = (addr + 4) & ~3;
5e77afaa 21816 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21817 if (val & 3)
5e77afaa 21818 return 4;
0110f2b8
PB
21819 val -= addr;
21820 if (val < 0 || val > 1020)
21821 return 4;
21822 return 2;
21823}
21824
21825/* Return the size of a relaxable add/sub immediate instruction. */
21826static int
21827relax_addsub (fragS *fragp, asection *sec)
21828{
21829 char *buf;
21830 int op;
21831
21832 buf = fragp->fr_literal + fragp->fr_fix;
21833 op = bfd_get_16(sec->owner, buf);
21834 if ((op & 0xf) == ((op >> 4) & 0xf))
21835 return relax_immediate (fragp, 8, 0);
21836 else
21837 return relax_immediate (fragp, 3, 0);
21838}
21839
e83a675f
RE
21840/* Return TRUE iff the definition of symbol S could be pre-empted
21841 (overridden) at link or load time. */
21842static bfd_boolean
21843symbol_preemptible (symbolS *s)
21844{
21845 /* Weak symbols can always be pre-empted. */
21846 if (S_IS_WEAK (s))
21847 return TRUE;
21848
21849 /* Non-global symbols cannot be pre-empted. */
21850 if (! S_IS_EXTERNAL (s))
21851 return FALSE;
21852
21853#ifdef OBJ_ELF
21854 /* In ELF, a global symbol can be marked protected, or private. In that
21855 case it can't be pre-empted (other definitions in the same link unit
21856 would violate the ODR). */
21857 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21858 return FALSE;
21859#endif
21860
21861 /* Other global symbols might be pre-empted. */
21862 return TRUE;
21863}
0110f2b8
PB
21864
21865/* Return the size of a relaxable branch instruction. BITS is the
21866 size of the offset field in the narrow instruction. */
21867
21868static int
5e77afaa 21869relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21870{
21871 addressT addr;
21872 offsetT val;
21873 offsetT limit;
21874
21875 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21876 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21877 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21878 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21879 return 4;
21880
267bf995 21881#ifdef OBJ_ELF
e83a675f 21882 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21883 if (S_IS_DEFINED (fragp->fr_symbol)
21884 && ARM_IS_FUNC (fragp->fr_symbol))
21885 return 4;
e83a675f 21886#endif
0d9b4b55 21887
e83a675f 21888 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21889 return 4;
267bf995 21890
5f4273c7 21891 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21892 addr = fragp->fr_address + fragp->fr_fix + 4;
21893 val -= addr;
21894
21895 /* Offset is a signed value *2 */
21896 limit = 1 << bits;
21897 if (val >= limit || val < -limit)
21898 return 4;
21899 return 2;
21900}
21901
21902
21903/* Relax a machine dependent frag. This returns the amount by which
21904 the current size of the frag should change. */
21905
21906int
5e77afaa 21907arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21908{
21909 int oldsize;
21910 int newsize;
21911
21912 oldsize = fragp->fr_var;
21913 switch (fragp->fr_subtype)
21914 {
21915 case T_MNEM_ldr_pc2:
5f4273c7 21916 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21917 break;
21918 case T_MNEM_ldr_pc:
21919 case T_MNEM_ldr_sp:
21920 case T_MNEM_str_sp:
5f4273c7 21921 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21922 break;
21923 case T_MNEM_ldr:
21924 case T_MNEM_str:
5f4273c7 21925 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21926 break;
21927 case T_MNEM_ldrh:
21928 case T_MNEM_strh:
5f4273c7 21929 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21930 break;
21931 case T_MNEM_ldrb:
21932 case T_MNEM_strb:
5f4273c7 21933 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21934 break;
21935 case T_MNEM_adr:
5f4273c7 21936 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21937 break;
21938 case T_MNEM_mov:
21939 case T_MNEM_movs:
21940 case T_MNEM_cmp:
21941 case T_MNEM_cmn:
5f4273c7 21942 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21943 break;
21944 case T_MNEM_b:
5f4273c7 21945 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21946 break;
21947 case T_MNEM_bcond:
5f4273c7 21948 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21949 break;
21950 case T_MNEM_add_sp:
21951 case T_MNEM_add_pc:
21952 newsize = relax_immediate (fragp, 8, 2);
21953 break;
21954 case T_MNEM_inc_sp:
21955 case T_MNEM_dec_sp:
21956 newsize = relax_immediate (fragp, 7, 2);
21957 break;
21958 case T_MNEM_addi:
21959 case T_MNEM_addis:
21960 case T_MNEM_subi:
21961 case T_MNEM_subis:
21962 newsize = relax_addsub (fragp, sec);
21963 break;
21964 default:
5f4273c7 21965 abort ();
0110f2b8 21966 }
5e77afaa
PB
21967
21968 fragp->fr_var = newsize;
21969 /* Freeze wide instructions that are at or before the same location as
21970 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21971 Don't freeze them unconditionally because targets may be artificially
21972 misaligned by the expansion of preceding frags. */
5e77afaa 21973 if (stretch <= 0 && newsize > 2)
0110f2b8 21974 {
0110f2b8 21975 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21976 frag_wane (fragp);
0110f2b8 21977 }
5e77afaa 21978
0110f2b8 21979 return newsize - oldsize;
c19d1205 21980}
b99bd4ef 21981
c19d1205 21982/* Round up a section size to the appropriate boundary. */
b99bd4ef 21983
c19d1205
ZW
21984valueT
21985md_section_align (segT segment ATTRIBUTE_UNUSED,
21986 valueT size)
21987{
f0927246
NC
21988#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21989 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21990 {
21991 /* For a.out, force the section size to be aligned. If we don't do
21992 this, BFD will align it for us, but it will not write out the
21993 final bytes of the section. This may be a bug in BFD, but it is
21994 easier to fix it here since that is how the other a.out targets
21995 work. */
21996 int align;
21997
21998 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21999 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 22000 }
c19d1205 22001#endif
f0927246 22002
6844c0cc 22003 return size;
bfae80f2 22004}
b99bd4ef 22005
c19d1205
ZW
22006/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22007 of an rs_align_code fragment. */
22008
22009void
22010arm_handle_align (fragS * fragP)
bfae80f2 22011{
d9235011 22012 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
22013 {
22014 { /* ARMv1 */
22015 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22016 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22017 },
22018 { /* ARMv6k */
22019 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22020 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22021 },
22022 };
d9235011 22023 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
22024 {
22025 { /* Thumb-1 */
22026 {0xc0, 0x46}, /* LE */
22027 {0x46, 0xc0}, /* BE */
22028 },
22029 { /* Thumb-2 */
22030 {0x00, 0xbf}, /* LE */
22031 {0xbf, 0x00} /* BE */
22032 }
22033 };
d9235011 22034 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
22035 { /* Wide Thumb-2 */
22036 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22037 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22038 };
c921be7d 22039
e7495e45 22040 unsigned bytes, fix, noop_size;
c19d1205 22041 char * p;
d9235011
TS
22042 const unsigned char * noop;
22043 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
22044#ifdef OBJ_ELF
22045 enum mstate state;
22046#endif
bfae80f2 22047
c19d1205 22048 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
22049 return;
22050
c19d1205
ZW
22051 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22052 p = fragP->fr_literal + fragP->fr_fix;
22053 fix = 0;
bfae80f2 22054
c19d1205
ZW
22055 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22056 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 22057
cd000bff 22058 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 22059
cd000bff 22060 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 22061 {
7f78eb34
JW
22062 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22063 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
22064 {
22065 narrow_noop = thumb_noop[1][target_big_endian];
22066 noop = wide_thumb_noop[target_big_endian];
22067 }
c19d1205 22068 else
e7495e45
NS
22069 noop = thumb_noop[0][target_big_endian];
22070 noop_size = 2;
cd000bff
DJ
22071#ifdef OBJ_ELF
22072 state = MAP_THUMB;
22073#endif
7ed4c4c5
NC
22074 }
22075 else
22076 {
7f78eb34
JW
22077 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22078 ? selected_cpu : arm_arch_none,
22079 arm_ext_v6k) != 0]
e7495e45
NS
22080 [target_big_endian];
22081 noop_size = 4;
cd000bff
DJ
22082#ifdef OBJ_ELF
22083 state = MAP_ARM;
22084#endif
7ed4c4c5 22085 }
c921be7d 22086
e7495e45 22087 fragP->fr_var = noop_size;
c921be7d 22088
c19d1205 22089 if (bytes & (noop_size - 1))
7ed4c4c5 22090 {
c19d1205 22091 fix = bytes & (noop_size - 1);
cd000bff
DJ
22092#ifdef OBJ_ELF
22093 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22094#endif
c19d1205
ZW
22095 memset (p, 0, fix);
22096 p += fix;
22097 bytes -= fix;
a737bd4d 22098 }
a737bd4d 22099
e7495e45
NS
22100 if (narrow_noop)
22101 {
22102 if (bytes & noop_size)
22103 {
22104 /* Insert a narrow noop. */
22105 memcpy (p, narrow_noop, noop_size);
22106 p += noop_size;
22107 bytes -= noop_size;
22108 fix += noop_size;
22109 }
22110
22111 /* Use wide noops for the remainder */
22112 noop_size = 4;
22113 }
22114
c19d1205 22115 while (bytes >= noop_size)
a737bd4d 22116 {
c19d1205
ZW
22117 memcpy (p, noop, noop_size);
22118 p += noop_size;
22119 bytes -= noop_size;
22120 fix += noop_size;
a737bd4d
NC
22121 }
22122
c19d1205 22123 fragP->fr_fix += fix;
a737bd4d
NC
22124}
22125
c19d1205
ZW
22126/* Called from md_do_align. Used to create an alignment
22127 frag in a code section. */
22128
22129void
22130arm_frag_align_code (int n, int max)
bfae80f2 22131{
c19d1205 22132 char * p;
7ed4c4c5 22133
c19d1205 22134 /* We assume that there will never be a requirement
6ec8e702 22135 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 22136 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
22137 {
22138 char err_msg[128];
22139
fa94de6b 22140 sprintf (err_msg,
477330fc
RM
22141 _("alignments greater than %d bytes not supported in .text sections."),
22142 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 22143 as_fatal ("%s", err_msg);
6ec8e702 22144 }
bfae80f2 22145
c19d1205
ZW
22146 p = frag_var (rs_align_code,
22147 MAX_MEM_FOR_RS_ALIGN_CODE,
22148 1,
22149 (relax_substateT) max,
22150 (symbolS *) NULL,
22151 (offsetT) n,
22152 (char *) NULL);
22153 *p = 0;
22154}
bfae80f2 22155
8dc2430f
NC
22156/* Perform target specific initialisation of a frag.
22157 Note - despite the name this initialisation is not done when the frag
22158 is created, but only when its type is assigned. A frag can be created
22159 and used a long time before its type is set, so beware of assuming that
33eaf5de 22160 this initialisation is performed first. */
bfae80f2 22161
cd000bff
DJ
22162#ifndef OBJ_ELF
22163void
22164arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22165{
22166 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 22167 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
22168}
22169
22170#else /* OBJ_ELF is defined. */
c19d1205 22171void
cd000bff 22172arm_init_frag (fragS * fragP, int max_chars)
c19d1205 22173{
e8d84ca1 22174 bfd_boolean frag_thumb_mode;
b968d18a 22175
8dc2430f
NC
22176 /* If the current ARM vs THUMB mode has not already
22177 been recorded into this frag then do so now. */
cd000bff 22178 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
22179 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22180
e8d84ca1
NC
22181 /* PR 21809: Do not set a mapping state for debug sections
22182 - it just confuses other tools. */
22183 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22184 return;
22185
b968d18a 22186 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 22187
f9c1b181
RL
22188 /* Record a mapping symbol for alignment frags. We will delete this
22189 later if the alignment ends up empty. */
22190 switch (fragP->fr_type)
22191 {
22192 case rs_align:
22193 case rs_align_test:
22194 case rs_fill:
22195 mapping_state_2 (MAP_DATA, max_chars);
22196 break;
22197 case rs_align_code:
b968d18a 22198 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
22199 break;
22200 default:
22201 break;
cd000bff 22202 }
bfae80f2
RE
22203}
22204
c19d1205
ZW
22205/* When we change sections we need to issue a new mapping symbol. */
22206
22207void
22208arm_elf_change_section (void)
bfae80f2 22209{
c19d1205
ZW
22210 /* Link an unlinked unwind index table section to the .text section. */
22211 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22212 && elf_linked_to_section (now_seg) == NULL)
22213 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
22214}
22215
c19d1205
ZW
22216int
22217arm_elf_section_type (const char * str, size_t len)
e45d0630 22218{
c19d1205
ZW
22219 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22220 return SHT_ARM_EXIDX;
e45d0630 22221
c19d1205
ZW
22222 return -1;
22223}
22224\f
22225/* Code to deal with unwinding tables. */
e45d0630 22226
c19d1205 22227static void add_unwind_adjustsp (offsetT);
e45d0630 22228
5f4273c7 22229/* Generate any deferred unwind frame offset. */
e45d0630 22230
bfae80f2 22231static void
c19d1205 22232flush_pending_unwind (void)
bfae80f2 22233{
c19d1205 22234 offsetT offset;
bfae80f2 22235
c19d1205
ZW
22236 offset = unwind.pending_offset;
22237 unwind.pending_offset = 0;
22238 if (offset != 0)
22239 add_unwind_adjustsp (offset);
bfae80f2
RE
22240}
22241
c19d1205
ZW
22242/* Add an opcode to this list for this function. Two-byte opcodes should
22243 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22244 order. */
22245
bfae80f2 22246static void
c19d1205 22247add_unwind_opcode (valueT op, int length)
bfae80f2 22248{
c19d1205
ZW
22249 /* Add any deferred stack adjustment. */
22250 if (unwind.pending_offset)
22251 flush_pending_unwind ();
bfae80f2 22252
c19d1205 22253 unwind.sp_restored = 0;
bfae80f2 22254
c19d1205 22255 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 22256 {
c19d1205
ZW
22257 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22258 if (unwind.opcodes)
325801bd
TS
22259 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22260 unwind.opcode_alloc);
c19d1205 22261 else
325801bd 22262 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 22263 }
c19d1205 22264 while (length > 0)
bfae80f2 22265 {
c19d1205
ZW
22266 length--;
22267 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22268 op >>= 8;
22269 unwind.opcode_count++;
bfae80f2 22270 }
bfae80f2
RE
22271}
22272
c19d1205
ZW
22273/* Add unwind opcodes to adjust the stack pointer. */
22274
bfae80f2 22275static void
c19d1205 22276add_unwind_adjustsp (offsetT offset)
bfae80f2 22277{
c19d1205 22278 valueT op;
bfae80f2 22279
c19d1205 22280 if (offset > 0x200)
bfae80f2 22281 {
c19d1205
ZW
22282 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22283 char bytes[5];
22284 int n;
22285 valueT o;
bfae80f2 22286
c19d1205
ZW
22287 /* Long form: 0xb2, uleb128. */
22288 /* This might not fit in a word so add the individual bytes,
22289 remembering the list is built in reverse order. */
22290 o = (valueT) ((offset - 0x204) >> 2);
22291 if (o == 0)
22292 add_unwind_opcode (0, 1);
bfae80f2 22293
c19d1205
ZW
22294 /* Calculate the uleb128 encoding of the offset. */
22295 n = 0;
22296 while (o)
22297 {
22298 bytes[n] = o & 0x7f;
22299 o >>= 7;
22300 if (o)
22301 bytes[n] |= 0x80;
22302 n++;
22303 }
22304 /* Add the insn. */
22305 for (; n; n--)
22306 add_unwind_opcode (bytes[n - 1], 1);
22307 add_unwind_opcode (0xb2, 1);
22308 }
22309 else if (offset > 0x100)
bfae80f2 22310 {
c19d1205
ZW
22311 /* Two short opcodes. */
22312 add_unwind_opcode (0x3f, 1);
22313 op = (offset - 0x104) >> 2;
22314 add_unwind_opcode (op, 1);
bfae80f2 22315 }
c19d1205
ZW
22316 else if (offset > 0)
22317 {
22318 /* Short opcode. */
22319 op = (offset - 4) >> 2;
22320 add_unwind_opcode (op, 1);
22321 }
22322 else if (offset < 0)
bfae80f2 22323 {
c19d1205
ZW
22324 offset = -offset;
22325 while (offset > 0x100)
bfae80f2 22326 {
c19d1205
ZW
22327 add_unwind_opcode (0x7f, 1);
22328 offset -= 0x100;
bfae80f2 22329 }
c19d1205
ZW
22330 op = ((offset - 4) >> 2) | 0x40;
22331 add_unwind_opcode (op, 1);
bfae80f2 22332 }
bfae80f2
RE
22333}
22334
c19d1205 22335/* Finish the list of unwind opcodes for this function. */
0198d5e6 22336
c19d1205
ZW
22337static void
22338finish_unwind_opcodes (void)
bfae80f2 22339{
c19d1205 22340 valueT op;
bfae80f2 22341
c19d1205 22342 if (unwind.fp_used)
bfae80f2 22343 {
708587a4 22344 /* Adjust sp as necessary. */
c19d1205
ZW
22345 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22346 flush_pending_unwind ();
bfae80f2 22347
c19d1205
ZW
22348 /* After restoring sp from the frame pointer. */
22349 op = 0x90 | unwind.fp_reg;
22350 add_unwind_opcode (op, 1);
22351 }
22352 else
22353 flush_pending_unwind ();
bfae80f2
RE
22354}
22355
bfae80f2 22356
c19d1205
ZW
22357/* Start an exception table entry. If idx is nonzero this is an index table
22358 entry. */
bfae80f2
RE
22359
22360static void
c19d1205 22361start_unwind_section (const segT text_seg, int idx)
bfae80f2 22362{
c19d1205
ZW
22363 const char * text_name;
22364 const char * prefix;
22365 const char * prefix_once;
22366 const char * group_name;
c19d1205 22367 char * sec_name;
c19d1205
ZW
22368 int type;
22369 int flags;
22370 int linkonce;
bfae80f2 22371
c19d1205 22372 if (idx)
bfae80f2 22373 {
c19d1205
ZW
22374 prefix = ELF_STRING_ARM_unwind;
22375 prefix_once = ELF_STRING_ARM_unwind_once;
22376 type = SHT_ARM_EXIDX;
bfae80f2 22377 }
c19d1205 22378 else
bfae80f2 22379 {
c19d1205
ZW
22380 prefix = ELF_STRING_ARM_unwind_info;
22381 prefix_once = ELF_STRING_ARM_unwind_info_once;
22382 type = SHT_PROGBITS;
bfae80f2
RE
22383 }
22384
c19d1205
ZW
22385 text_name = segment_name (text_seg);
22386 if (streq (text_name, ".text"))
22387 text_name = "";
22388
22389 if (strncmp (text_name, ".gnu.linkonce.t.",
22390 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22391 {
c19d1205
ZW
22392 prefix = prefix_once;
22393 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22394 }
22395
29a2809e 22396 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22397
c19d1205
ZW
22398 flags = SHF_ALLOC;
22399 linkonce = 0;
22400 group_name = 0;
bfae80f2 22401
c19d1205
ZW
22402 /* Handle COMDAT group. */
22403 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22404 {
c19d1205
ZW
22405 group_name = elf_group_name (text_seg);
22406 if (group_name == NULL)
22407 {
bd3ba5d1 22408 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22409 segment_name (text_seg));
22410 ignore_rest_of_line ();
22411 return;
22412 }
22413 flags |= SHF_GROUP;
22414 linkonce = 1;
bfae80f2
RE
22415 }
22416
a91e1603
L
22417 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22418 linkonce, 0);
bfae80f2 22419
5f4273c7 22420 /* Set the section link for index tables. */
c19d1205
ZW
22421 if (idx)
22422 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22423}
22424
bfae80f2 22425
c19d1205
ZW
22426/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22427 personality routine data. Returns zero, or the index table value for
cad0da33 22428 an inline entry. */
c19d1205
ZW
22429
22430static valueT
22431create_unwind_entry (int have_data)
bfae80f2 22432{
c19d1205
ZW
22433 int size;
22434 addressT where;
22435 char *ptr;
22436 /* The current word of data. */
22437 valueT data;
22438 /* The number of bytes left in this word. */
22439 int n;
bfae80f2 22440
c19d1205 22441 finish_unwind_opcodes ();
bfae80f2 22442
c19d1205
ZW
22443 /* Remember the current text section. */
22444 unwind.saved_seg = now_seg;
22445 unwind.saved_subseg = now_subseg;
bfae80f2 22446
c19d1205 22447 start_unwind_section (now_seg, 0);
bfae80f2 22448
c19d1205 22449 if (unwind.personality_routine == NULL)
bfae80f2 22450 {
c19d1205
ZW
22451 if (unwind.personality_index == -2)
22452 {
22453 if (have_data)
5f4273c7 22454 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22455 return 1; /* EXIDX_CANTUNWIND. */
22456 }
bfae80f2 22457
c19d1205
ZW
22458 /* Use a default personality routine if none is specified. */
22459 if (unwind.personality_index == -1)
22460 {
22461 if (unwind.opcode_count > 3)
22462 unwind.personality_index = 1;
22463 else
22464 unwind.personality_index = 0;
22465 }
bfae80f2 22466
c19d1205
ZW
22467 /* Space for the personality routine entry. */
22468 if (unwind.personality_index == 0)
22469 {
22470 if (unwind.opcode_count > 3)
22471 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22472
c19d1205
ZW
22473 if (!have_data)
22474 {
22475 /* All the data is inline in the index table. */
22476 data = 0x80;
22477 n = 3;
22478 while (unwind.opcode_count > 0)
22479 {
22480 unwind.opcode_count--;
22481 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22482 n--;
22483 }
bfae80f2 22484
c19d1205
ZW
22485 /* Pad with "finish" opcodes. */
22486 while (n--)
22487 data = (data << 8) | 0xb0;
bfae80f2 22488
c19d1205
ZW
22489 return data;
22490 }
22491 size = 0;
22492 }
22493 else
22494 /* We get two opcodes "free" in the first word. */
22495 size = unwind.opcode_count - 2;
22496 }
22497 else
5011093d 22498 {
cad0da33
NC
22499 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22500 if (unwind.personality_index != -1)
22501 {
22502 as_bad (_("attempt to recreate an unwind entry"));
22503 return 1;
22504 }
5011093d
NC
22505
22506 /* An extra byte is required for the opcode count. */
22507 size = unwind.opcode_count + 1;
22508 }
bfae80f2 22509
c19d1205
ZW
22510 size = (size + 3) >> 2;
22511 if (size > 0xff)
22512 as_bad (_("too many unwind opcodes"));
bfae80f2 22513
c19d1205
ZW
22514 frag_align (2, 0, 0);
22515 record_alignment (now_seg, 2);
22516 unwind.table_entry = expr_build_dot ();
22517
22518 /* Allocate the table entry. */
22519 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22520 /* PR 13449: Zero the table entries in case some of them are not used. */
22521 memset (ptr, 0, (size << 2) + 4);
c19d1205 22522 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22523
c19d1205 22524 switch (unwind.personality_index)
bfae80f2 22525 {
c19d1205
ZW
22526 case -1:
22527 /* ??? Should this be a PLT generating relocation? */
22528 /* Custom personality routine. */
22529 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22530 BFD_RELOC_ARM_PREL31);
bfae80f2 22531
c19d1205
ZW
22532 where += 4;
22533 ptr += 4;
bfae80f2 22534
c19d1205 22535 /* Set the first byte to the number of additional words. */
5011093d 22536 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22537 n = 3;
22538 break;
bfae80f2 22539
c19d1205
ZW
22540 /* ABI defined personality routines. */
22541 case 0:
22542 /* Three opcodes bytes are packed into the first word. */
22543 data = 0x80;
22544 n = 3;
22545 break;
bfae80f2 22546
c19d1205
ZW
22547 case 1:
22548 case 2:
22549 /* The size and first two opcode bytes go in the first word. */
22550 data = ((0x80 + unwind.personality_index) << 8) | size;
22551 n = 2;
22552 break;
bfae80f2 22553
c19d1205
ZW
22554 default:
22555 /* Should never happen. */
22556 abort ();
22557 }
bfae80f2 22558
c19d1205
ZW
22559 /* Pack the opcodes into words (MSB first), reversing the list at the same
22560 time. */
22561 while (unwind.opcode_count > 0)
22562 {
22563 if (n == 0)
22564 {
22565 md_number_to_chars (ptr, data, 4);
22566 ptr += 4;
22567 n = 4;
22568 data = 0;
22569 }
22570 unwind.opcode_count--;
22571 n--;
22572 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22573 }
22574
22575 /* Finish off the last word. */
22576 if (n < 4)
22577 {
22578 /* Pad with "finish" opcodes. */
22579 while (n--)
22580 data = (data << 8) | 0xb0;
22581
22582 md_number_to_chars (ptr, data, 4);
22583 }
22584
22585 if (!have_data)
22586 {
22587 /* Add an empty descriptor if there is no user-specified data. */
22588 ptr = frag_more (4);
22589 md_number_to_chars (ptr, 0, 4);
22590 }
22591
22592 return 0;
bfae80f2
RE
22593}
22594
f0927246
NC
22595
22596/* Initialize the DWARF-2 unwind information for this procedure. */
22597
22598void
22599tc_arm_frame_initial_instructions (void)
22600{
22601 cfi_add_CFA_def_cfa (REG_SP, 0);
22602}
22603#endif /* OBJ_ELF */
22604
c19d1205
ZW
22605/* Convert REGNAME to a DWARF-2 register number. */
22606
22607int
1df69f4f 22608tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22609{
1df69f4f 22610 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22611 if (reg != FAIL)
22612 return reg;
c19d1205 22613
1f5afe1c
NC
22614 /* PR 16694: Allow VFP registers as well. */
22615 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22616 if (reg != FAIL)
22617 return 64 + reg;
c19d1205 22618
1f5afe1c
NC
22619 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22620 if (reg != FAIL)
22621 return reg + 256;
22622
0198d5e6 22623 return FAIL;
bfae80f2
RE
22624}
22625
f0927246 22626#ifdef TE_PE
c19d1205 22627void
f0927246 22628tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22629{
91d6fa6a 22630 expressionS exp;
bfae80f2 22631
91d6fa6a
NC
22632 exp.X_op = O_secrel;
22633 exp.X_add_symbol = symbol;
22634 exp.X_add_number = 0;
22635 emit_expr (&exp, size);
f0927246
NC
22636}
22637#endif
bfae80f2 22638
c19d1205 22639/* MD interface: Symbol and relocation handling. */
bfae80f2 22640
2fc8bdac
ZW
22641/* Return the address within the segment that a PC-relative fixup is
22642 relative to. For ARM, PC-relative fixups applied to instructions
22643 are generally relative to the location of the fixup plus 8 bytes.
22644 Thumb branches are offset by 4, and Thumb loads relative to PC
22645 require special handling. */
bfae80f2 22646
c19d1205 22647long
2fc8bdac 22648md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22649{
2fc8bdac
ZW
22650 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22651
22652 /* If this is pc-relative and we are going to emit a relocation
22653 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22654 will need. Otherwise we want to use the calculated base.
22655 For WinCE we skip the bias for externals as well, since this
22656 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22657 if (fixP->fx_pcrel
2fc8bdac 22658 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22659 || (arm_force_relocation (fixP)
22660#ifdef TE_WINCE
22661 && !S_IS_EXTERNAL (fixP->fx_addsy)
22662#endif
22663 )))
2fc8bdac 22664 base = 0;
bfae80f2 22665
267bf995 22666
c19d1205 22667 switch (fixP->fx_r_type)
bfae80f2 22668 {
2fc8bdac
ZW
22669 /* PC relative addressing on the Thumb is slightly odd as the
22670 bottom two bits of the PC are forced to zero for the
22671 calculation. This happens *after* application of the
22672 pipeline offset. However, Thumb adrl already adjusts for
22673 this, so we need not do it again. */
c19d1205 22674 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22675 return base & ~3;
c19d1205
ZW
22676
22677 case BFD_RELOC_ARM_THUMB_OFFSET:
22678 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22679 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22680 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22681 return (base + 4) & ~3;
c19d1205 22682
2fc8bdac
ZW
22683 /* Thumb branches are simply offset by +4. */
22684 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22685 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22686 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22687 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22688 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22689 return base + 4;
bfae80f2 22690
267bf995 22691 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22692 if (fixP->fx_addsy
22693 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22694 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22695 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22696 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22697 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22698 return base + 4;
22699
00adf2d4
JB
22700 /* BLX is like branches above, but forces the low two bits of PC to
22701 zero. */
486499d0
CL
22702 case BFD_RELOC_THUMB_PCREL_BLX:
22703 if (fixP->fx_addsy
22704 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22705 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22706 && THUMB_IS_FUNC (fixP->fx_addsy)
22707 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22708 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22709 return (base + 4) & ~3;
22710
2fc8bdac
ZW
22711 /* ARM mode branches are offset by +8. However, the Windows CE
22712 loader expects the relocation not to take this into account. */
267bf995 22713 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22714 if (fixP->fx_addsy
22715 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22716 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22717 && ARM_IS_FUNC (fixP->fx_addsy)
22718 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22719 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22720 return base + 8;
267bf995 22721
486499d0
CL
22722 case BFD_RELOC_ARM_PCREL_CALL:
22723 if (fixP->fx_addsy
22724 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22725 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22726 && THUMB_IS_FUNC (fixP->fx_addsy)
22727 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22728 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22729 return base + 8;
267bf995 22730
2fc8bdac 22731 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22732 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22733 case BFD_RELOC_ARM_PLT32:
c19d1205 22734#ifdef TE_WINCE
5f4273c7 22735 /* When handling fixups immediately, because we have already
477330fc 22736 discovered the value of a symbol, or the address of the frag involved
53baae48 22737 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22738 see fixup_segment() in write.c
22739 The S_IS_EXTERNAL test handles the case of global symbols.
22740 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22741 if (fixP->fx_pcrel
22742 && fixP->fx_addsy != NULL
22743 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22744 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22745 return base + 8;
2fc8bdac 22746 return base;
c19d1205 22747#else
2fc8bdac 22748 return base + 8;
c19d1205 22749#endif
2fc8bdac 22750
267bf995 22751
2fc8bdac
ZW
22752 /* ARM mode loads relative to PC are also offset by +8. Unlike
22753 branches, the Windows CE loader *does* expect the relocation
22754 to take this into account. */
22755 case BFD_RELOC_ARM_OFFSET_IMM:
22756 case BFD_RELOC_ARM_OFFSET_IMM8:
22757 case BFD_RELOC_ARM_HWLITERAL:
22758 case BFD_RELOC_ARM_LITERAL:
22759 case BFD_RELOC_ARM_CP_OFF_IMM:
22760 return base + 8;
22761
22762
22763 /* Other PC-relative relocations are un-offset. */
22764 default:
22765 return base;
22766 }
bfae80f2
RE
22767}
22768
8b2d793c
NC
22769static bfd_boolean flag_warn_syms = TRUE;
22770
ae8714c2
NC
22771bfd_boolean
22772arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22773{
8b2d793c
NC
22774 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22775 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22776 does mean that the resulting code might be very confusing to the reader.
22777 Also this warning can be triggered if the user omits an operand before
22778 an immediate address, eg:
22779
22780 LDR =foo
22781
22782 GAS treats this as an assignment of the value of the symbol foo to a
22783 symbol LDR, and so (without this code) it will not issue any kind of
22784 warning or error message.
22785
22786 Note - ARM instructions are case-insensitive but the strings in the hash
22787 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22788 lower case too. */
22789 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22790 {
22791 char * nbuf = strdup (name);
22792 char * p;
22793
22794 for (p = nbuf; *p; p++)
22795 *p = TOLOWER (*p);
22796 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22797 {
22798 static struct hash_control * already_warned = NULL;
22799
22800 if (already_warned == NULL)
22801 already_warned = hash_new ();
22802 /* Only warn about the symbol once. To keep the code
22803 simple we let hash_insert do the lookup for us. */
22804 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22805 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22806 }
22807 else
22808 free (nbuf);
22809 }
3739860c 22810
ae8714c2
NC
22811 return FALSE;
22812}
22813
22814/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22815 Otherwise we have no need to default values of symbols. */
22816
22817symbolS *
22818md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22819{
22820#ifdef OBJ_ELF
22821 if (name[0] == '_' && name[1] == 'G'
22822 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22823 {
22824 if (!GOT_symbol)
22825 {
22826 if (symbol_find (name))
22827 as_bad (_("GOT already in the symbol table"));
22828
22829 GOT_symbol = symbol_new (name, undefined_section,
22830 (valueT) 0, & zero_address_frag);
22831 }
22832
22833 return GOT_symbol;
22834 }
22835#endif
22836
c921be7d 22837 return NULL;
bfae80f2
RE
22838}
22839
55cf6793 22840/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22841 computed as two separate immediate values, added together. We
22842 already know that this value cannot be computed by just one ARM
22843 instruction. */
22844
22845static unsigned int
22846validate_immediate_twopart (unsigned int val,
22847 unsigned int * highpart)
bfae80f2 22848{
c19d1205
ZW
22849 unsigned int a;
22850 unsigned int i;
bfae80f2 22851
c19d1205
ZW
22852 for (i = 0; i < 32; i += 2)
22853 if (((a = rotate_left (val, i)) & 0xff) != 0)
22854 {
22855 if (a & 0xff00)
22856 {
22857 if (a & ~ 0xffff)
22858 continue;
22859 * highpart = (a >> 8) | ((i + 24) << 7);
22860 }
22861 else if (a & 0xff0000)
22862 {
22863 if (a & 0xff000000)
22864 continue;
22865 * highpart = (a >> 16) | ((i + 16) << 7);
22866 }
22867 else
22868 {
9c2799c2 22869 gas_assert (a & 0xff000000);
c19d1205
ZW
22870 * highpart = (a >> 24) | ((i + 8) << 7);
22871 }
bfae80f2 22872
c19d1205
ZW
22873 return (a & 0xff) | (i << 7);
22874 }
bfae80f2 22875
c19d1205 22876 return FAIL;
bfae80f2
RE
22877}
22878
c19d1205
ZW
22879static int
22880validate_offset_imm (unsigned int val, int hwse)
22881{
22882 if ((hwse && val > 255) || val > 4095)
22883 return FAIL;
22884 return val;
22885}
bfae80f2 22886
55cf6793 22887/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22888 negative immediate constant by altering the instruction. A bit of
22889 a hack really.
22890 MOV <-> MVN
22891 AND <-> BIC
22892 ADC <-> SBC
22893 by inverting the second operand, and
22894 ADD <-> SUB
22895 CMP <-> CMN
22896 by negating the second operand. */
bfae80f2 22897
c19d1205
ZW
22898static int
22899negate_data_op (unsigned long * instruction,
22900 unsigned long value)
bfae80f2 22901{
c19d1205
ZW
22902 int op, new_inst;
22903 unsigned long negated, inverted;
bfae80f2 22904
c19d1205
ZW
22905 negated = encode_arm_immediate (-value);
22906 inverted = encode_arm_immediate (~value);
bfae80f2 22907
c19d1205
ZW
22908 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22909 switch (op)
bfae80f2 22910 {
c19d1205
ZW
22911 /* First negates. */
22912 case OPCODE_SUB: /* ADD <-> SUB */
22913 new_inst = OPCODE_ADD;
22914 value = negated;
22915 break;
bfae80f2 22916
c19d1205
ZW
22917 case OPCODE_ADD:
22918 new_inst = OPCODE_SUB;
22919 value = negated;
22920 break;
bfae80f2 22921
c19d1205
ZW
22922 case OPCODE_CMP: /* CMP <-> CMN */
22923 new_inst = OPCODE_CMN;
22924 value = negated;
22925 break;
bfae80f2 22926
c19d1205
ZW
22927 case OPCODE_CMN:
22928 new_inst = OPCODE_CMP;
22929 value = negated;
22930 break;
bfae80f2 22931
c19d1205
ZW
22932 /* Now Inverted ops. */
22933 case OPCODE_MOV: /* MOV <-> MVN */
22934 new_inst = OPCODE_MVN;
22935 value = inverted;
22936 break;
bfae80f2 22937
c19d1205
ZW
22938 case OPCODE_MVN:
22939 new_inst = OPCODE_MOV;
22940 value = inverted;
22941 break;
bfae80f2 22942
c19d1205
ZW
22943 case OPCODE_AND: /* AND <-> BIC */
22944 new_inst = OPCODE_BIC;
22945 value = inverted;
22946 break;
bfae80f2 22947
c19d1205
ZW
22948 case OPCODE_BIC:
22949 new_inst = OPCODE_AND;
22950 value = inverted;
22951 break;
bfae80f2 22952
c19d1205
ZW
22953 case OPCODE_ADC: /* ADC <-> SBC */
22954 new_inst = OPCODE_SBC;
22955 value = inverted;
22956 break;
bfae80f2 22957
c19d1205
ZW
22958 case OPCODE_SBC:
22959 new_inst = OPCODE_ADC;
22960 value = inverted;
22961 break;
bfae80f2 22962
c19d1205
ZW
22963 /* We cannot do anything. */
22964 default:
22965 return FAIL;
b99bd4ef
NC
22966 }
22967
c19d1205
ZW
22968 if (value == (unsigned) FAIL)
22969 return FAIL;
22970
22971 *instruction &= OPCODE_MASK;
22972 *instruction |= new_inst << DATA_OP_SHIFT;
22973 return value;
b99bd4ef
NC
22974}
22975
ef8d22e6
PB
22976/* Like negate_data_op, but for Thumb-2. */
22977
22978static unsigned int
16dd5e42 22979thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22980{
22981 int op, new_inst;
22982 int rd;
16dd5e42 22983 unsigned int negated, inverted;
ef8d22e6
PB
22984
22985 negated = encode_thumb32_immediate (-value);
22986 inverted = encode_thumb32_immediate (~value);
22987
22988 rd = (*instruction >> 8) & 0xf;
22989 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22990 switch (op)
22991 {
22992 /* ADD <-> SUB. Includes CMP <-> CMN. */
22993 case T2_OPCODE_SUB:
22994 new_inst = T2_OPCODE_ADD;
22995 value = negated;
22996 break;
22997
22998 case T2_OPCODE_ADD:
22999 new_inst = T2_OPCODE_SUB;
23000 value = negated;
23001 break;
23002
23003 /* ORR <-> ORN. Includes MOV <-> MVN. */
23004 case T2_OPCODE_ORR:
23005 new_inst = T2_OPCODE_ORN;
23006 value = inverted;
23007 break;
23008
23009 case T2_OPCODE_ORN:
23010 new_inst = T2_OPCODE_ORR;
23011 value = inverted;
23012 break;
23013
23014 /* AND <-> BIC. TST has no inverted equivalent. */
23015 case T2_OPCODE_AND:
23016 new_inst = T2_OPCODE_BIC;
23017 if (rd == 15)
23018 value = FAIL;
23019 else
23020 value = inverted;
23021 break;
23022
23023 case T2_OPCODE_BIC:
23024 new_inst = T2_OPCODE_AND;
23025 value = inverted;
23026 break;
23027
23028 /* ADC <-> SBC */
23029 case T2_OPCODE_ADC:
23030 new_inst = T2_OPCODE_SBC;
23031 value = inverted;
23032 break;
23033
23034 case T2_OPCODE_SBC:
23035 new_inst = T2_OPCODE_ADC;
23036 value = inverted;
23037 break;
23038
23039 /* We cannot do anything. */
23040 default:
23041 return FAIL;
23042 }
23043
16dd5e42 23044 if (value == (unsigned int)FAIL)
ef8d22e6
PB
23045 return FAIL;
23046
23047 *instruction &= T2_OPCODE_MASK;
23048 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23049 return value;
23050}
23051
8f06b2d8 23052/* Read a 32-bit thumb instruction from buf. */
0198d5e6 23053
8f06b2d8
PB
23054static unsigned long
23055get_thumb32_insn (char * buf)
23056{
23057 unsigned long insn;
23058 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23059 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23060
23061 return insn;
23062}
23063
a8bc6c78
PB
23064/* We usually want to set the low bit on the address of thumb function
23065 symbols. In particular .word foo - . should have the low bit set.
23066 Generic code tries to fold the difference of two symbols to
23067 a constant. Prevent this and force a relocation when the first symbols
23068 is a thumb function. */
c921be7d
NC
23069
23070bfd_boolean
a8bc6c78
PB
23071arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23072{
23073 if (op == O_subtract
23074 && l->X_op == O_symbol
23075 && r->X_op == O_symbol
23076 && THUMB_IS_FUNC (l->X_add_symbol))
23077 {
23078 l->X_op = O_subtract;
23079 l->X_op_symbol = r->X_add_symbol;
23080 l->X_add_number -= r->X_add_number;
c921be7d 23081 return TRUE;
a8bc6c78 23082 }
c921be7d 23083
a8bc6c78 23084 /* Process as normal. */
c921be7d 23085 return FALSE;
a8bc6c78
PB
23086}
23087
4a42ebbc
RR
23088/* Encode Thumb2 unconditional branches and calls. The encoding
23089 for the 2 are identical for the immediate values. */
23090
23091static void
23092encode_thumb2_b_bl_offset (char * buf, offsetT value)
23093{
23094#define T2I1I2MASK ((1 << 13) | (1 << 11))
23095 offsetT newval;
23096 offsetT newval2;
23097 addressT S, I1, I2, lo, hi;
23098
23099 S = (value >> 24) & 0x01;
23100 I1 = (value >> 23) & 0x01;
23101 I2 = (value >> 22) & 0x01;
23102 hi = (value >> 12) & 0x3ff;
fa94de6b 23103 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
23104 newval = md_chars_to_number (buf, THUMB_SIZE);
23105 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23106 newval |= (S << 10) | hi;
23107 newval2 &= ~T2I1I2MASK;
23108 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23109 md_number_to_chars (buf, newval, THUMB_SIZE);
23110 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23111}
23112
c19d1205 23113void
55cf6793 23114md_apply_fix (fixS * fixP,
c19d1205
ZW
23115 valueT * valP,
23116 segT seg)
23117{
23118 offsetT value = * valP;
23119 offsetT newval;
23120 unsigned int newimm;
23121 unsigned long temp;
23122 int sign;
23123 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 23124
9c2799c2 23125 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 23126
c19d1205 23127 /* Note whether this will delete the relocation. */
4962c51a 23128
c19d1205
ZW
23129 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23130 fixP->fx_done = 1;
b99bd4ef 23131
adbaf948 23132 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 23133 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
23134 for emit_reloc. */
23135 value &= 0xffffffff;
23136 value ^= 0x80000000;
5f4273c7 23137 value -= 0x80000000;
adbaf948
ZW
23138
23139 *valP = value;
c19d1205 23140 fixP->fx_addnumber = value;
b99bd4ef 23141
adbaf948
ZW
23142 /* Same treatment for fixP->fx_offset. */
23143 fixP->fx_offset &= 0xffffffff;
23144 fixP->fx_offset ^= 0x80000000;
23145 fixP->fx_offset -= 0x80000000;
23146
c19d1205 23147 switch (fixP->fx_r_type)
b99bd4ef 23148 {
c19d1205
ZW
23149 case BFD_RELOC_NONE:
23150 /* This will need to go in the object file. */
23151 fixP->fx_done = 0;
23152 break;
b99bd4ef 23153
c19d1205
ZW
23154 case BFD_RELOC_ARM_IMMEDIATE:
23155 /* We claim that this fixup has been processed here,
23156 even if in fact we generate an error because we do
23157 not have a reloc for it, so tc_gen_reloc will reject it. */
23158 fixP->fx_done = 1;
b99bd4ef 23159
77db8e2e 23160 if (fixP->fx_addsy)
b99bd4ef 23161 {
77db8e2e 23162 const char *msg = 0;
b99bd4ef 23163
77db8e2e
NC
23164 if (! S_IS_DEFINED (fixP->fx_addsy))
23165 msg = _("undefined symbol %s used as an immediate value");
23166 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23167 msg = _("symbol %s is in a different section");
23168 else if (S_IS_WEAK (fixP->fx_addsy))
23169 msg = _("symbol %s is weak and may be overridden later");
23170
23171 if (msg)
23172 {
23173 as_bad_where (fixP->fx_file, fixP->fx_line,
23174 msg, S_GET_NAME (fixP->fx_addsy));
23175 break;
23176 }
42e5fcbf
AS
23177 }
23178
c19d1205
ZW
23179 temp = md_chars_to_number (buf, INSN_SIZE);
23180
5e73442d
SL
23181 /* If the offset is negative, we should use encoding A2 for ADR. */
23182 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23183 newimm = negate_data_op (&temp, value);
23184 else
23185 {
23186 newimm = encode_arm_immediate (value);
23187
23188 /* If the instruction will fail, see if we can fix things up by
23189 changing the opcode. */
23190 if (newimm == (unsigned int) FAIL)
23191 newimm = negate_data_op (&temp, value);
bada4342
JW
23192 /* MOV accepts both ARM modified immediate (A1 encoding) and
23193 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23194 When disassembling, MOV is preferred when there is no encoding
23195 overlap. */
23196 if (newimm == (unsigned int) FAIL
23197 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23198 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23199 && !((temp >> SBIT_SHIFT) & 0x1)
23200 && value >= 0 && value <= 0xffff)
23201 {
23202 /* Clear bits[23:20] to change encoding from A1 to A2. */
23203 temp &= 0xff0fffff;
23204 /* Encoding high 4bits imm. Code below will encode the remaining
23205 low 12bits. */
23206 temp |= (value & 0x0000f000) << 4;
23207 newimm = value & 0x00000fff;
23208 }
5e73442d
SL
23209 }
23210
23211 if (newimm == (unsigned int) FAIL)
b99bd4ef 23212 {
c19d1205
ZW
23213 as_bad_where (fixP->fx_file, fixP->fx_line,
23214 _("invalid constant (%lx) after fixup"),
23215 (unsigned long) value);
23216 break;
b99bd4ef 23217 }
b99bd4ef 23218
c19d1205
ZW
23219 newimm |= (temp & 0xfffff000);
23220 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23221 break;
b99bd4ef 23222
c19d1205
ZW
23223 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23224 {
23225 unsigned int highpart = 0;
23226 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 23227
77db8e2e 23228 if (fixP->fx_addsy)
42e5fcbf 23229 {
77db8e2e 23230 const char *msg = 0;
42e5fcbf 23231
77db8e2e
NC
23232 if (! S_IS_DEFINED (fixP->fx_addsy))
23233 msg = _("undefined symbol %s used as an immediate value");
23234 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23235 msg = _("symbol %s is in a different section");
23236 else if (S_IS_WEAK (fixP->fx_addsy))
23237 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 23238
77db8e2e
NC
23239 if (msg)
23240 {
23241 as_bad_where (fixP->fx_file, fixP->fx_line,
23242 msg, S_GET_NAME (fixP->fx_addsy));
23243 break;
23244 }
23245 }
fa94de6b 23246
c19d1205
ZW
23247 newimm = encode_arm_immediate (value);
23248 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 23249
c19d1205
ZW
23250 /* If the instruction will fail, see if we can fix things up by
23251 changing the opcode. */
23252 if (newimm == (unsigned int) FAIL
23253 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23254 {
23255 /* No ? OK - try using two ADD instructions to generate
23256 the value. */
23257 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 23258
c19d1205
ZW
23259 /* Yes - then make sure that the second instruction is
23260 also an add. */
23261 if (newimm != (unsigned int) FAIL)
23262 newinsn = temp;
23263 /* Still No ? Try using a negated value. */
23264 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23265 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23266 /* Otherwise - give up. */
23267 else
23268 {
23269 as_bad_where (fixP->fx_file, fixP->fx_line,
23270 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23271 (long) value);
23272 break;
23273 }
b99bd4ef 23274
c19d1205
ZW
23275 /* Replace the first operand in the 2nd instruction (which
23276 is the PC) with the destination register. We have
23277 already added in the PC in the first instruction and we
23278 do not want to do it again. */
23279 newinsn &= ~ 0xf0000;
23280 newinsn |= ((newinsn & 0x0f000) << 4);
23281 }
b99bd4ef 23282
c19d1205
ZW
23283 newimm |= (temp & 0xfffff000);
23284 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23285
c19d1205
ZW
23286 highpart |= (newinsn & 0xfffff000);
23287 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23288 }
23289 break;
b99bd4ef 23290
c19d1205 23291 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23292 if (!fixP->fx_done && seg->use_rela_p)
23293 value = 0;
1a0670f3 23294 /* Fall through. */
00a97672 23295
c19d1205 23296 case BFD_RELOC_ARM_LITERAL:
26d97720 23297 sign = value > 0;
b99bd4ef 23298
c19d1205
ZW
23299 if (value < 0)
23300 value = - value;
b99bd4ef 23301
c19d1205 23302 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23303 {
c19d1205
ZW
23304 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23305 as_bad_where (fixP->fx_file, fixP->fx_line,
23306 _("invalid literal constant: pool needs to be closer"));
23307 else
23308 as_bad_where (fixP->fx_file, fixP->fx_line,
23309 _("bad immediate value for offset (%ld)"),
23310 (long) value);
23311 break;
f03698e6
RE
23312 }
23313
c19d1205 23314 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23315 if (value == 0)
23316 newval &= 0xfffff000;
23317 else
23318 {
23319 newval &= 0xff7ff000;
23320 newval |= value | (sign ? INDEX_UP : 0);
23321 }
c19d1205
ZW
23322 md_number_to_chars (buf, newval, INSN_SIZE);
23323 break;
b99bd4ef 23324
c19d1205
ZW
23325 case BFD_RELOC_ARM_OFFSET_IMM8:
23326 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23327 sign = value > 0;
b99bd4ef 23328
c19d1205
ZW
23329 if (value < 0)
23330 value = - value;
b99bd4ef 23331
c19d1205 23332 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23333 {
c19d1205
ZW
23334 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23335 as_bad_where (fixP->fx_file, fixP->fx_line,
23336 _("invalid literal constant: pool needs to be closer"));
23337 else
427d0db6
RM
23338 as_bad_where (fixP->fx_file, fixP->fx_line,
23339 _("bad immediate value for 8-bit offset (%ld)"),
23340 (long) value);
c19d1205 23341 break;
b99bd4ef
NC
23342 }
23343
c19d1205 23344 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23345 if (value == 0)
23346 newval &= 0xfffff0f0;
23347 else
23348 {
23349 newval &= 0xff7ff0f0;
23350 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23351 }
c19d1205
ZW
23352 md_number_to_chars (buf, newval, INSN_SIZE);
23353 break;
b99bd4ef 23354
c19d1205
ZW
23355 case BFD_RELOC_ARM_T32_OFFSET_U8:
23356 if (value < 0 || value > 1020 || value % 4 != 0)
23357 as_bad_where (fixP->fx_file, fixP->fx_line,
23358 _("bad immediate value for offset (%ld)"), (long) value);
23359 value /= 4;
b99bd4ef 23360
c19d1205 23361 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23362 newval |= value;
23363 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23364 break;
b99bd4ef 23365
c19d1205
ZW
23366 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23367 /* This is a complicated relocation used for all varieties of Thumb32
23368 load/store instruction with immediate offset:
23369
23370 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23371 *4, optional writeback(W)
c19d1205
ZW
23372 (doubleword load/store)
23373
23374 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23375 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23376 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23377 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23378 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23379
23380 Uppercase letters indicate bits that are already encoded at
23381 this point. Lowercase letters are our problem. For the
23382 second block of instructions, the secondary opcode nybble
23383 (bits 8..11) is present, and bit 23 is zero, even if this is
23384 a PC-relative operation. */
23385 newval = md_chars_to_number (buf, THUMB_SIZE);
23386 newval <<= 16;
23387 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23388
c19d1205 23389 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23390 {
c19d1205
ZW
23391 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23392 if (value >= 0)
23393 newval |= (1 << 23);
23394 else
23395 value = -value;
23396 if (value % 4 != 0)
23397 {
23398 as_bad_where (fixP->fx_file, fixP->fx_line,
23399 _("offset not a multiple of 4"));
23400 break;
23401 }
23402 value /= 4;
216d22bc 23403 if (value > 0xff)
c19d1205
ZW
23404 {
23405 as_bad_where (fixP->fx_file, fixP->fx_line,
23406 _("offset out of range"));
23407 break;
23408 }
23409 newval &= ~0xff;
b99bd4ef 23410 }
c19d1205 23411 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23412 {
c19d1205
ZW
23413 /* PC-relative, 12-bit offset. */
23414 if (value >= 0)
23415 newval |= (1 << 23);
23416 else
23417 value = -value;
216d22bc 23418 if (value > 0xfff)
c19d1205
ZW
23419 {
23420 as_bad_where (fixP->fx_file, fixP->fx_line,
23421 _("offset out of range"));
23422 break;
23423 }
23424 newval &= ~0xfff;
b99bd4ef 23425 }
c19d1205 23426 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23427 {
c19d1205
ZW
23428 /* Writeback: 8-bit, +/- offset. */
23429 if (value >= 0)
23430 newval |= (1 << 9);
23431 else
23432 value = -value;
216d22bc 23433 if (value > 0xff)
c19d1205
ZW
23434 {
23435 as_bad_where (fixP->fx_file, fixP->fx_line,
23436 _("offset out of range"));
23437 break;
23438 }
23439 newval &= ~0xff;
b99bd4ef 23440 }
c19d1205 23441 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23442 {
c19d1205 23443 /* T-instruction: positive 8-bit offset. */
216d22bc 23444 if (value < 0 || value > 0xff)
b99bd4ef 23445 {
c19d1205
ZW
23446 as_bad_where (fixP->fx_file, fixP->fx_line,
23447 _("offset out of range"));
23448 break;
b99bd4ef 23449 }
c19d1205
ZW
23450 newval &= ~0xff;
23451 newval |= value;
b99bd4ef
NC
23452 }
23453 else
b99bd4ef 23454 {
c19d1205
ZW
23455 /* Positive 12-bit or negative 8-bit offset. */
23456 int limit;
23457 if (value >= 0)
b99bd4ef 23458 {
c19d1205
ZW
23459 newval |= (1 << 23);
23460 limit = 0xfff;
23461 }
23462 else
23463 {
23464 value = -value;
23465 limit = 0xff;
23466 }
23467 if (value > limit)
23468 {
23469 as_bad_where (fixP->fx_file, fixP->fx_line,
23470 _("offset out of range"));
23471 break;
b99bd4ef 23472 }
c19d1205 23473 newval &= ~limit;
b99bd4ef 23474 }
b99bd4ef 23475
c19d1205
ZW
23476 newval |= value;
23477 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23478 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23479 break;
404ff6b5 23480
c19d1205
ZW
23481 case BFD_RELOC_ARM_SHIFT_IMM:
23482 newval = md_chars_to_number (buf, INSN_SIZE);
23483 if (((unsigned long) value) > 32
23484 || (value == 32
23485 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23486 {
23487 as_bad_where (fixP->fx_file, fixP->fx_line,
23488 _("shift expression is too large"));
23489 break;
23490 }
404ff6b5 23491
c19d1205
ZW
23492 if (value == 0)
23493 /* Shifts of zero must be done as lsl. */
23494 newval &= ~0x60;
23495 else if (value == 32)
23496 value = 0;
23497 newval &= 0xfffff07f;
23498 newval |= (value & 0x1f) << 7;
23499 md_number_to_chars (buf, newval, INSN_SIZE);
23500 break;
404ff6b5 23501
c19d1205 23502 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23503 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23504 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23505 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23506 /* We claim that this fixup has been processed here,
23507 even if in fact we generate an error because we do
23508 not have a reloc for it, so tc_gen_reloc will reject it. */
23509 fixP->fx_done = 1;
404ff6b5 23510
c19d1205
ZW
23511 if (fixP->fx_addsy
23512 && ! S_IS_DEFINED (fixP->fx_addsy))
23513 {
23514 as_bad_where (fixP->fx_file, fixP->fx_line,
23515 _("undefined symbol %s used as an immediate value"),
23516 S_GET_NAME (fixP->fx_addsy));
23517 break;
23518 }
404ff6b5 23519
c19d1205
ZW
23520 newval = md_chars_to_number (buf, THUMB_SIZE);
23521 newval <<= 16;
23522 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23523
16805f35 23524 newimm = FAIL;
bada4342
JW
23525 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23526 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23527 Thumb2 modified immediate encoding (T2). */
23528 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23529 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23530 {
23531 newimm = encode_thumb32_immediate (value);
23532 if (newimm == (unsigned int) FAIL)
23533 newimm = thumb32_negate_data_op (&newval, value);
23534 }
bada4342 23535 if (newimm == (unsigned int) FAIL)
92e90b6e 23536 {
bada4342 23537 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23538 {
bada4342
JW
23539 /* Turn add/sum into addw/subw. */
23540 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23541 newval = (newval & 0xfeffffff) | 0x02000000;
23542 /* No flat 12-bit imm encoding for addsw/subsw. */
23543 if ((newval & 0x00100000) == 0)
40f246e3 23544 {
bada4342
JW
23545 /* 12 bit immediate for addw/subw. */
23546 if (value < 0)
23547 {
23548 value = -value;
23549 newval ^= 0x00a00000;
23550 }
23551 if (value > 0xfff)
23552 newimm = (unsigned int) FAIL;
23553 else
23554 newimm = value;
23555 }
23556 }
23557 else
23558 {
23559 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23560 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23561 disassembling, MOV is preferred when there is no encoding
23562 overlap.
23563 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23564 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23565 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23566 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23567 && value >= 0 && value <=0xffff)
23568 {
23569 /* Toggle bit[25] to change encoding from T2 to T3. */
23570 newval ^= 1 << 25;
23571 /* Clear bits[19:16]. */
23572 newval &= 0xfff0ffff;
23573 /* Encoding high 4bits imm. Code below will encode the
23574 remaining low 12bits. */
23575 newval |= (value & 0x0000f000) << 4;
23576 newimm = value & 0x00000fff;
40f246e3 23577 }
e9f89963 23578 }
92e90b6e 23579 }
cc8a6dd0 23580
c19d1205 23581 if (newimm == (unsigned int)FAIL)
3631a3c8 23582 {
c19d1205
ZW
23583 as_bad_where (fixP->fx_file, fixP->fx_line,
23584 _("invalid constant (%lx) after fixup"),
23585 (unsigned long) value);
23586 break;
3631a3c8
NC
23587 }
23588
c19d1205
ZW
23589 newval |= (newimm & 0x800) << 15;
23590 newval |= (newimm & 0x700) << 4;
23591 newval |= (newimm & 0x0ff);
cc8a6dd0 23592
c19d1205
ZW
23593 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23594 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23595 break;
a737bd4d 23596
3eb17e6b 23597 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23598 if (((unsigned long) value) > 0xffff)
23599 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23600 _("invalid smc expression"));
2fc8bdac 23601 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23602 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23603 md_number_to_chars (buf, newval, INSN_SIZE);
23604 break;
a737bd4d 23605
90ec0d68
MGD
23606 case BFD_RELOC_ARM_HVC:
23607 if (((unsigned long) value) > 0xffff)
23608 as_bad_where (fixP->fx_file, fixP->fx_line,
23609 _("invalid hvc expression"));
23610 newval = md_chars_to_number (buf, INSN_SIZE);
23611 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23612 md_number_to_chars (buf, newval, INSN_SIZE);
23613 break;
23614
c19d1205 23615 case BFD_RELOC_ARM_SWI:
adbaf948 23616 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23617 {
23618 if (((unsigned long) value) > 0xff)
23619 as_bad_where (fixP->fx_file, fixP->fx_line,
23620 _("invalid swi expression"));
2fc8bdac 23621 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23622 newval |= value;
23623 md_number_to_chars (buf, newval, THUMB_SIZE);
23624 }
23625 else
23626 {
23627 if (((unsigned long) value) > 0x00ffffff)
23628 as_bad_where (fixP->fx_file, fixP->fx_line,
23629 _("invalid swi expression"));
2fc8bdac 23630 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23631 newval |= value;
23632 md_number_to_chars (buf, newval, INSN_SIZE);
23633 }
23634 break;
a737bd4d 23635
c19d1205
ZW
23636 case BFD_RELOC_ARM_MULTI:
23637 if (((unsigned long) value) > 0xffff)
23638 as_bad_where (fixP->fx_file, fixP->fx_line,
23639 _("invalid expression in load/store multiple"));
23640 newval = value | md_chars_to_number (buf, INSN_SIZE);
23641 md_number_to_chars (buf, newval, INSN_SIZE);
23642 break;
a737bd4d 23643
c19d1205 23644#ifdef OBJ_ELF
39b41c9c 23645 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23646
23647 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23648 && fixP->fx_addsy
34e77a92 23649 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23650 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23651 && THUMB_IS_FUNC (fixP->fx_addsy))
23652 /* Flip the bl to blx. This is a simple flip
23653 bit here because we generate PCREL_CALL for
23654 unconditional bls. */
23655 {
23656 newval = md_chars_to_number (buf, INSN_SIZE);
23657 newval = newval | 0x10000000;
23658 md_number_to_chars (buf, newval, INSN_SIZE);
23659 temp = 1;
23660 fixP->fx_done = 1;
23661 }
39b41c9c
PB
23662 else
23663 temp = 3;
23664 goto arm_branch_common;
23665
23666 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23667 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23668 && fixP->fx_addsy
34e77a92 23669 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23670 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23671 && THUMB_IS_FUNC (fixP->fx_addsy))
23672 {
23673 /* This would map to a bl<cond>, b<cond>,
23674 b<always> to a Thumb function. We
23675 need to force a relocation for this particular
23676 case. */
23677 newval = md_chars_to_number (buf, INSN_SIZE);
23678 fixP->fx_done = 0;
23679 }
1a0670f3 23680 /* Fall through. */
267bf995 23681
2fc8bdac 23682 case BFD_RELOC_ARM_PLT32:
c19d1205 23683#endif
39b41c9c
PB
23684 case BFD_RELOC_ARM_PCREL_BRANCH:
23685 temp = 3;
23686 goto arm_branch_common;
a737bd4d 23687
39b41c9c 23688 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23689
39b41c9c 23690 temp = 1;
267bf995
RR
23691 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23692 && fixP->fx_addsy
34e77a92 23693 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23694 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23695 && ARM_IS_FUNC (fixP->fx_addsy))
23696 {
23697 /* Flip the blx to a bl and warn. */
23698 const char *name = S_GET_NAME (fixP->fx_addsy);
23699 newval = 0xeb000000;
23700 as_warn_where (fixP->fx_file, fixP->fx_line,
23701 _("blx to '%s' an ARM ISA state function changed to bl"),
23702 name);
23703 md_number_to_chars (buf, newval, INSN_SIZE);
23704 temp = 3;
23705 fixP->fx_done = 1;
23706 }
23707
23708#ifdef OBJ_ELF
23709 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23710 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23711#endif
23712
39b41c9c 23713 arm_branch_common:
c19d1205 23714 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23715 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23716 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
de194d85 23717 also be clear. */
39b41c9c 23718 if (value & temp)
c19d1205 23719 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23720 _("misaligned branch destination"));
23721 if ((value & (offsetT)0xfe000000) != (offsetT)0
23722 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23723 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23724
2fc8bdac 23725 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23726 {
2fc8bdac
ZW
23727 newval = md_chars_to_number (buf, INSN_SIZE);
23728 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23729 /* Set the H bit on BLX instructions. */
23730 if (temp == 1)
23731 {
23732 if (value & 2)
23733 newval |= 0x01000000;
23734 else
23735 newval &= ~0x01000000;
23736 }
2fc8bdac 23737 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23738 }
c19d1205 23739 break;
a737bd4d 23740
25fe350b
MS
23741 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23742 /* CBZ can only branch forward. */
a737bd4d 23743
738755b0 23744 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23745 (which, strictly speaking, are prohibited) will be turned into
23746 no-ops.
738755b0
MS
23747
23748 FIXME: It may be better to remove the instruction completely and
23749 perform relaxation. */
23750 if (value == -2)
2fc8bdac
ZW
23751 {
23752 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23753 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23754 md_number_to_chars (buf, newval, THUMB_SIZE);
23755 }
738755b0
MS
23756 else
23757 {
23758 if (value & ~0x7e)
08f10d51 23759 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23760
477330fc 23761 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23762 {
23763 newval = md_chars_to_number (buf, THUMB_SIZE);
23764 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23765 md_number_to_chars (buf, newval, THUMB_SIZE);
23766 }
23767 }
c19d1205 23768 break;
a737bd4d 23769
c19d1205 23770 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23771 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23772 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23773
2fc8bdac
ZW
23774 if (fixP->fx_done || !seg->use_rela_p)
23775 {
23776 newval = md_chars_to_number (buf, THUMB_SIZE);
23777 newval |= (value & 0x1ff) >> 1;
23778 md_number_to_chars (buf, newval, THUMB_SIZE);
23779 }
c19d1205 23780 break;
a737bd4d 23781
c19d1205 23782 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23783 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23784 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23785
2fc8bdac
ZW
23786 if (fixP->fx_done || !seg->use_rela_p)
23787 {
23788 newval = md_chars_to_number (buf, THUMB_SIZE);
23789 newval |= (value & 0xfff) >> 1;
23790 md_number_to_chars (buf, newval, THUMB_SIZE);
23791 }
c19d1205 23792 break;
a737bd4d 23793
c19d1205 23794 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23795 if (fixP->fx_addsy
23796 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23797 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23798 && ARM_IS_FUNC (fixP->fx_addsy)
23799 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23800 {
23801 /* Force a relocation for a branch 20 bits wide. */
23802 fixP->fx_done = 0;
23803 }
08f10d51 23804 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23805 as_bad_where (fixP->fx_file, fixP->fx_line,
23806 _("conditional branch out of range"));
404ff6b5 23807
2fc8bdac
ZW
23808 if (fixP->fx_done || !seg->use_rela_p)
23809 {
23810 offsetT newval2;
23811 addressT S, J1, J2, lo, hi;
404ff6b5 23812
2fc8bdac
ZW
23813 S = (value & 0x00100000) >> 20;
23814 J2 = (value & 0x00080000) >> 19;
23815 J1 = (value & 0x00040000) >> 18;
23816 hi = (value & 0x0003f000) >> 12;
23817 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23818
2fc8bdac
ZW
23819 newval = md_chars_to_number (buf, THUMB_SIZE);
23820 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23821 newval |= (S << 10) | hi;
23822 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23823 md_number_to_chars (buf, newval, THUMB_SIZE);
23824 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23825 }
c19d1205 23826 break;
6c43fab6 23827
c19d1205 23828 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23829 /* If there is a blx from a thumb state function to
23830 another thumb function flip this to a bl and warn
23831 about it. */
23832
23833 if (fixP->fx_addsy
34e77a92 23834 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23835 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23836 && THUMB_IS_FUNC (fixP->fx_addsy))
23837 {
23838 const char *name = S_GET_NAME (fixP->fx_addsy);
23839 as_warn_where (fixP->fx_file, fixP->fx_line,
23840 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23841 name);
23842 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23843 newval = newval | 0x1000;
23844 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23845 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23846 fixP->fx_done = 1;
23847 }
23848
23849
23850 goto thumb_bl_common;
23851
c19d1205 23852 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23853 /* A bl from Thumb state ISA to an internal ARM state function
23854 is converted to a blx. */
23855 if (fixP->fx_addsy
23856 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23857 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23858 && ARM_IS_FUNC (fixP->fx_addsy)
23859 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23860 {
23861 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23862 newval = newval & ~0x1000;
23863 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23864 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23865 fixP->fx_done = 1;
23866 }
23867
23868 thumb_bl_common:
23869
2fc8bdac
ZW
23870 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23871 /* For a BLX instruction, make sure that the relocation is rounded up
23872 to a word boundary. This follows the semantics of the instruction
23873 which specifies that bit 1 of the target address will come from bit
23874 1 of the base address. */
d406f3e4
JB
23875 value = (value + 3) & ~ 3;
23876
23877#ifdef OBJ_ELF
23878 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23879 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23880 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23881#endif
404ff6b5 23882
2b2f5df9
NC
23883 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23884 {
fc289b0a 23885 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23886 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23887 else if ((value & ~0x1ffffff)
23888 && ((value & ~0x1ffffff) != ~0x1ffffff))
23889 as_bad_where (fixP->fx_file, fixP->fx_line,
23890 _("Thumb2 branch out of range"));
23891 }
4a42ebbc
RR
23892
23893 if (fixP->fx_done || !seg->use_rela_p)
23894 encode_thumb2_b_bl_offset (buf, value);
23895
c19d1205 23896 break;
404ff6b5 23897
c19d1205 23898 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23899 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23900 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23901
2fc8bdac 23902 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23903 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23904
2fc8bdac 23905 break;
a737bd4d 23906
2fc8bdac
ZW
23907 case BFD_RELOC_8:
23908 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23909 *buf = value;
c19d1205 23910 break;
a737bd4d 23911
c19d1205 23912 case BFD_RELOC_16:
2fc8bdac 23913 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23914 md_number_to_chars (buf, value, 2);
c19d1205 23915 break;
a737bd4d 23916
c19d1205 23917#ifdef OBJ_ELF
0855e32b
NS
23918 case BFD_RELOC_ARM_TLS_CALL:
23919 case BFD_RELOC_ARM_THM_TLS_CALL:
23920 case BFD_RELOC_ARM_TLS_DESCSEQ:
23921 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23922 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23923 case BFD_RELOC_ARM_TLS_GD32:
23924 case BFD_RELOC_ARM_TLS_LE32:
23925 case BFD_RELOC_ARM_TLS_IE32:
23926 case BFD_RELOC_ARM_TLS_LDM32:
23927 case BFD_RELOC_ARM_TLS_LDO32:
23928 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23929 break;
6c43fab6 23930
c19d1205
ZW
23931 case BFD_RELOC_ARM_GOT32:
23932 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23933 break;
b43420e6
NC
23934
23935 case BFD_RELOC_ARM_GOT_PREL:
23936 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23937 md_number_to_chars (buf, value, 4);
b43420e6
NC
23938 break;
23939
9a6f4e97
NS
23940 case BFD_RELOC_ARM_TARGET2:
23941 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23942 addend here for REL targets, because it won't be written out
23943 during reloc processing later. */
9a6f4e97
NS
23944 if (fixP->fx_done || !seg->use_rela_p)
23945 md_number_to_chars (buf, fixP->fx_offset, 4);
23946 break;
c19d1205 23947#endif
6c43fab6 23948
c19d1205
ZW
23949 case BFD_RELOC_RVA:
23950 case BFD_RELOC_32:
23951 case BFD_RELOC_ARM_TARGET1:
23952 case BFD_RELOC_ARM_ROSEGREL32:
23953 case BFD_RELOC_ARM_SBREL32:
23954 case BFD_RELOC_32_PCREL:
f0927246
NC
23955#ifdef TE_PE
23956 case BFD_RELOC_32_SECREL:
23957#endif
2fc8bdac 23958 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23959#ifdef TE_WINCE
23960 /* For WinCE we only do this for pcrel fixups. */
23961 if (fixP->fx_done || fixP->fx_pcrel)
23962#endif
23963 md_number_to_chars (buf, value, 4);
c19d1205 23964 break;
6c43fab6 23965
c19d1205
ZW
23966#ifdef OBJ_ELF
23967 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23968 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23969 {
23970 newval = md_chars_to_number (buf, 4) & 0x80000000;
23971 if ((value ^ (value >> 1)) & 0x40000000)
23972 {
23973 as_bad_where (fixP->fx_file, fixP->fx_line,
23974 _("rel31 relocation overflow"));
23975 }
23976 newval |= value & 0x7fffffff;
23977 md_number_to_chars (buf, newval, 4);
23978 }
23979 break;
c19d1205 23980#endif
a737bd4d 23981
c19d1205 23982 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23983 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23984 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23985 newval = md_chars_to_number (buf, INSN_SIZE);
23986 else
23987 newval = get_thumb32_insn (buf);
23988 if ((newval & 0x0f200f00) == 0x0d000900)
23989 {
23990 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23991 has permitted values that are multiples of 2, in the range 0
23992 to 510. */
23993 if (value < -510 || value > 510 || (value & 1))
23994 as_bad_where (fixP->fx_file, fixP->fx_line,
23995 _("co-processor offset out of range"));
23996 }
23997 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23998 as_bad_where (fixP->fx_file, fixP->fx_line,
23999 _("co-processor offset out of range"));
24000 cp_off_common:
26d97720 24001 sign = value > 0;
c19d1205
ZW
24002 if (value < 0)
24003 value = -value;
8f06b2d8
PB
24004 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24005 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24006 newval = md_chars_to_number (buf, INSN_SIZE);
24007 else
24008 newval = get_thumb32_insn (buf);
26d97720
NS
24009 if (value == 0)
24010 newval &= 0xffffff00;
24011 else
24012 {
24013 newval &= 0xff7fff00;
9db2f6b4
RL
24014 if ((newval & 0x0f200f00) == 0x0d000900)
24015 {
24016 /* This is a fp16 vstr/vldr.
24017
24018 It requires the immediate offset in the instruction is shifted
24019 left by 1 to be a half-word offset.
24020
24021 Here, left shift by 1 first, and later right shift by 2
24022 should get the right offset. */
24023 value <<= 1;
24024 }
26d97720
NS
24025 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24026 }
8f06b2d8
PB
24027 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24028 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24029 md_number_to_chars (buf, newval, INSN_SIZE);
24030 else
24031 put_thumb32_insn (buf, newval);
c19d1205 24032 break;
a737bd4d 24033
c19d1205 24034 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 24035 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
24036 if (value < -255 || value > 255)
24037 as_bad_where (fixP->fx_file, fixP->fx_line,
24038 _("co-processor offset out of range"));
df7849c5 24039 value *= 4;
c19d1205 24040 goto cp_off_common;
6c43fab6 24041
c19d1205
ZW
24042 case BFD_RELOC_ARM_THUMB_OFFSET:
24043 newval = md_chars_to_number (buf, THUMB_SIZE);
24044 /* Exactly what ranges, and where the offset is inserted depends
24045 on the type of instruction, we can establish this from the
24046 top 4 bits. */
24047 switch (newval >> 12)
24048 {
24049 case 4: /* PC load. */
24050 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24051 forced to zero for these loads; md_pcrel_from has already
24052 compensated for this. */
24053 if (value & 3)
24054 as_bad_where (fixP->fx_file, fixP->fx_line,
24055 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
24056 (((unsigned long) fixP->fx_frag->fr_address
24057 + (unsigned long) fixP->fx_where) & ~3)
24058 + (unsigned long) value);
a737bd4d 24059
c19d1205
ZW
24060 if (value & ~0x3fc)
24061 as_bad_where (fixP->fx_file, fixP->fx_line,
24062 _("invalid offset, value too big (0x%08lX)"),
24063 (long) value);
a737bd4d 24064
c19d1205
ZW
24065 newval |= value >> 2;
24066 break;
a737bd4d 24067
c19d1205
ZW
24068 case 9: /* SP load/store. */
24069 if (value & ~0x3fc)
24070 as_bad_where (fixP->fx_file, fixP->fx_line,
24071 _("invalid offset, value too big (0x%08lX)"),
24072 (long) value);
24073 newval |= value >> 2;
24074 break;
6c43fab6 24075
c19d1205
ZW
24076 case 6: /* Word load/store. */
24077 if (value & ~0x7c)
24078 as_bad_where (fixP->fx_file, fixP->fx_line,
24079 _("invalid offset, value too big (0x%08lX)"),
24080 (long) value);
24081 newval |= value << 4; /* 6 - 2. */
24082 break;
a737bd4d 24083
c19d1205
ZW
24084 case 7: /* Byte load/store. */
24085 if (value & ~0x1f)
24086 as_bad_where (fixP->fx_file, fixP->fx_line,
24087 _("invalid offset, value too big (0x%08lX)"),
24088 (long) value);
24089 newval |= value << 6;
24090 break;
a737bd4d 24091
c19d1205
ZW
24092 case 8: /* Halfword load/store. */
24093 if (value & ~0x3e)
24094 as_bad_where (fixP->fx_file, fixP->fx_line,
24095 _("invalid offset, value too big (0x%08lX)"),
24096 (long) value);
24097 newval |= value << 5; /* 6 - 1. */
24098 break;
a737bd4d 24099
c19d1205
ZW
24100 default:
24101 as_bad_where (fixP->fx_file, fixP->fx_line,
24102 "Unable to process relocation for thumb opcode: %lx",
24103 (unsigned long) newval);
24104 break;
24105 }
24106 md_number_to_chars (buf, newval, THUMB_SIZE);
24107 break;
a737bd4d 24108
c19d1205
ZW
24109 case BFD_RELOC_ARM_THUMB_ADD:
24110 /* This is a complicated relocation, since we use it for all of
24111 the following immediate relocations:
a737bd4d 24112
c19d1205
ZW
24113 3bit ADD/SUB
24114 8bit ADD/SUB
24115 9bit ADD/SUB SP word-aligned
24116 10bit ADD PC/SP word-aligned
a737bd4d 24117
c19d1205
ZW
24118 The type of instruction being processed is encoded in the
24119 instruction field:
a737bd4d 24120
c19d1205
ZW
24121 0x8000 SUB
24122 0x00F0 Rd
24123 0x000F Rs
24124 */
24125 newval = md_chars_to_number (buf, THUMB_SIZE);
24126 {
24127 int rd = (newval >> 4) & 0xf;
24128 int rs = newval & 0xf;
24129 int subtract = !!(newval & 0x8000);
a737bd4d 24130
c19d1205
ZW
24131 /* Check for HI regs, only very restricted cases allowed:
24132 Adjusting SP, and using PC or SP to get an address. */
24133 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24134 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24135 as_bad_where (fixP->fx_file, fixP->fx_line,
24136 _("invalid Hi register with immediate"));
a737bd4d 24137
c19d1205
ZW
24138 /* If value is negative, choose the opposite instruction. */
24139 if (value < 0)
24140 {
24141 value = -value;
24142 subtract = !subtract;
24143 if (value < 0)
24144 as_bad_where (fixP->fx_file, fixP->fx_line,
24145 _("immediate value out of range"));
24146 }
a737bd4d 24147
c19d1205
ZW
24148 if (rd == REG_SP)
24149 {
75c11999 24150 if (value & ~0x1fc)
c19d1205
ZW
24151 as_bad_where (fixP->fx_file, fixP->fx_line,
24152 _("invalid immediate for stack address calculation"));
24153 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24154 newval |= value >> 2;
24155 }
24156 else if (rs == REG_PC || rs == REG_SP)
24157 {
c12d2c9d
NC
24158 /* PR gas/18541. If the addition is for a defined symbol
24159 within range of an ADR instruction then accept it. */
24160 if (subtract
24161 && value == 4
24162 && fixP->fx_addsy != NULL)
24163 {
24164 subtract = 0;
24165
24166 if (! S_IS_DEFINED (fixP->fx_addsy)
24167 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24168 || S_IS_WEAK (fixP->fx_addsy))
24169 {
24170 as_bad_where (fixP->fx_file, fixP->fx_line,
24171 _("address calculation needs a strongly defined nearby symbol"));
24172 }
24173 else
24174 {
24175 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24176
24177 /* Round up to the next 4-byte boundary. */
24178 if (v & 3)
24179 v = (v + 3) & ~ 3;
24180 else
24181 v += 4;
24182 v = S_GET_VALUE (fixP->fx_addsy) - v;
24183
24184 if (v & ~0x3fc)
24185 {
24186 as_bad_where (fixP->fx_file, fixP->fx_line,
24187 _("symbol too far away"));
24188 }
24189 else
24190 {
24191 fixP->fx_done = 1;
24192 value = v;
24193 }
24194 }
24195 }
24196
c19d1205
ZW
24197 if (subtract || value & ~0x3fc)
24198 as_bad_where (fixP->fx_file, fixP->fx_line,
24199 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 24200 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
24201 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24202 newval |= rd << 8;
24203 newval |= value >> 2;
24204 }
24205 else if (rs == rd)
24206 {
24207 if (value & ~0xff)
24208 as_bad_where (fixP->fx_file, fixP->fx_line,
24209 _("immediate value out of range"));
24210 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24211 newval |= (rd << 8) | value;
24212 }
24213 else
24214 {
24215 if (value & ~0x7)
24216 as_bad_where (fixP->fx_file, fixP->fx_line,
24217 _("immediate value out of range"));
24218 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24219 newval |= rd | (rs << 3) | (value << 6);
24220 }
24221 }
24222 md_number_to_chars (buf, newval, THUMB_SIZE);
24223 break;
a737bd4d 24224
c19d1205
ZW
24225 case BFD_RELOC_ARM_THUMB_IMM:
24226 newval = md_chars_to_number (buf, THUMB_SIZE);
24227 if (value < 0 || value > 255)
24228 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 24229 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
24230 (long) value);
24231 newval |= value;
24232 md_number_to_chars (buf, newval, THUMB_SIZE);
24233 break;
a737bd4d 24234
c19d1205
ZW
24235 case BFD_RELOC_ARM_THUMB_SHIFT:
24236 /* 5bit shift value (0..32). LSL cannot take 32. */
24237 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24238 temp = newval & 0xf800;
24239 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24240 as_bad_where (fixP->fx_file, fixP->fx_line,
24241 _("invalid shift value: %ld"), (long) value);
24242 /* Shifts of zero must be encoded as LSL. */
24243 if (value == 0)
24244 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24245 /* Shifts of 32 are encoded as zero. */
24246 else if (value == 32)
24247 value = 0;
24248 newval |= value << 6;
24249 md_number_to_chars (buf, newval, THUMB_SIZE);
24250 break;
a737bd4d 24251
c19d1205
ZW
24252 case BFD_RELOC_VTABLE_INHERIT:
24253 case BFD_RELOC_VTABLE_ENTRY:
24254 fixP->fx_done = 0;
24255 return;
6c43fab6 24256
b6895b4f
PB
24257 case BFD_RELOC_ARM_MOVW:
24258 case BFD_RELOC_ARM_MOVT:
24259 case BFD_RELOC_ARM_THUMB_MOVW:
24260 case BFD_RELOC_ARM_THUMB_MOVT:
24261 if (fixP->fx_done || !seg->use_rela_p)
24262 {
24263 /* REL format relocations are limited to a 16-bit addend. */
24264 if (!fixP->fx_done)
24265 {
39623e12 24266 if (value < -0x8000 || value > 0x7fff)
b6895b4f 24267 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 24268 _("offset out of range"));
b6895b4f
PB
24269 }
24270 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24271 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24272 {
24273 value >>= 16;
24274 }
24275
24276 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24277 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24278 {
24279 newval = get_thumb32_insn (buf);
24280 newval &= 0xfbf08f00;
24281 newval |= (value & 0xf000) << 4;
24282 newval |= (value & 0x0800) << 15;
24283 newval |= (value & 0x0700) << 4;
24284 newval |= (value & 0x00ff);
24285 put_thumb32_insn (buf, newval);
24286 }
24287 else
24288 {
24289 newval = md_chars_to_number (buf, 4);
24290 newval &= 0xfff0f000;
24291 newval |= value & 0x0fff;
24292 newval |= (value & 0xf000) << 4;
24293 md_number_to_chars (buf, newval, 4);
24294 }
24295 }
24296 return;
24297
72d98d16
MG
24298 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24299 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24300 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24301 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24302 gas_assert (!fixP->fx_done);
24303 {
24304 bfd_vma insn;
24305 bfd_boolean is_mov;
24306 bfd_vma encoded_addend = value;
24307
24308 /* Check that addend can be encoded in instruction. */
24309 if (!seg->use_rela_p && (value < 0 || value > 255))
24310 as_bad_where (fixP->fx_file, fixP->fx_line,
24311 _("the offset 0x%08lX is not representable"),
24312 (unsigned long) encoded_addend);
24313
24314 /* Extract the instruction. */
24315 insn = md_chars_to_number (buf, THUMB_SIZE);
24316 is_mov = (insn & 0xf800) == 0x2000;
24317
24318 /* Encode insn. */
24319 if (is_mov)
24320 {
24321 if (!seg->use_rela_p)
24322 insn |= encoded_addend;
24323 }
24324 else
24325 {
24326 int rd, rs;
24327
24328 /* Extract the instruction. */
24329 /* Encoding is the following
24330 0x8000 SUB
24331 0x00F0 Rd
24332 0x000F Rs
24333 */
24334 /* The following conditions must be true :
24335 - ADD
24336 - Rd == Rs
24337 - Rd <= 7
24338 */
24339 rd = (insn >> 4) & 0xf;
24340 rs = insn & 0xf;
24341 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24342 as_bad_where (fixP->fx_file, fixP->fx_line,
24343 _("Unable to process relocation for thumb opcode: %lx"),
24344 (unsigned long) insn);
24345
24346 /* Encode as ADD immediate8 thumb 1 code. */
24347 insn = 0x3000 | (rd << 8);
24348
24349 /* Place the encoded addend into the first 8 bits of the
24350 instruction. */
24351 if (!seg->use_rela_p)
24352 insn |= encoded_addend;
24353 }
24354
24355 /* Update the instruction. */
24356 md_number_to_chars (buf, insn, THUMB_SIZE);
24357 }
24358 break;
24359
4962c51a
MS
24360 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24361 case BFD_RELOC_ARM_ALU_PC_G0:
24362 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24363 case BFD_RELOC_ARM_ALU_PC_G1:
24364 case BFD_RELOC_ARM_ALU_PC_G2:
24365 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24366 case BFD_RELOC_ARM_ALU_SB_G0:
24367 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24368 case BFD_RELOC_ARM_ALU_SB_G1:
24369 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24370 gas_assert (!fixP->fx_done);
4962c51a
MS
24371 if (!seg->use_rela_p)
24372 {
477330fc
RM
24373 bfd_vma insn;
24374 bfd_vma encoded_addend;
24375 bfd_vma addend_abs = abs (value);
24376
24377 /* Check that the absolute value of the addend can be
24378 expressed as an 8-bit constant plus a rotation. */
24379 encoded_addend = encode_arm_immediate (addend_abs);
24380 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24381 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24382 _("the offset 0x%08lX is not representable"),
24383 (unsigned long) addend_abs);
24384
24385 /* Extract the instruction. */
24386 insn = md_chars_to_number (buf, INSN_SIZE);
24387
24388 /* If the addend is positive, use an ADD instruction.
24389 Otherwise use a SUB. Take care not to destroy the S bit. */
24390 insn &= 0xff1fffff;
24391 if (value < 0)
24392 insn |= 1 << 22;
24393 else
24394 insn |= 1 << 23;
24395
24396 /* Place the encoded addend into the first 12 bits of the
24397 instruction. */
24398 insn &= 0xfffff000;
24399 insn |= encoded_addend;
24400
24401 /* Update the instruction. */
24402 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24403 }
24404 break;
24405
24406 case BFD_RELOC_ARM_LDR_PC_G0:
24407 case BFD_RELOC_ARM_LDR_PC_G1:
24408 case BFD_RELOC_ARM_LDR_PC_G2:
24409 case BFD_RELOC_ARM_LDR_SB_G0:
24410 case BFD_RELOC_ARM_LDR_SB_G1:
24411 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24412 gas_assert (!fixP->fx_done);
4962c51a 24413 if (!seg->use_rela_p)
477330fc
RM
24414 {
24415 bfd_vma insn;
24416 bfd_vma addend_abs = abs (value);
4962c51a 24417
477330fc
RM
24418 /* Check that the absolute value of the addend can be
24419 encoded in 12 bits. */
24420 if (addend_abs >= 0x1000)
4962c51a 24421 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24422 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24423 (unsigned long) addend_abs);
24424
24425 /* Extract the instruction. */
24426 insn = md_chars_to_number (buf, INSN_SIZE);
24427
24428 /* If the addend is negative, clear bit 23 of the instruction.
24429 Otherwise set it. */
24430 if (value < 0)
24431 insn &= ~(1 << 23);
24432 else
24433 insn |= 1 << 23;
24434
24435 /* Place the absolute value of the addend into the first 12 bits
24436 of the instruction. */
24437 insn &= 0xfffff000;
24438 insn |= addend_abs;
24439
24440 /* Update the instruction. */
24441 md_number_to_chars (buf, insn, INSN_SIZE);
24442 }
4962c51a
MS
24443 break;
24444
24445 case BFD_RELOC_ARM_LDRS_PC_G0:
24446 case BFD_RELOC_ARM_LDRS_PC_G1:
24447 case BFD_RELOC_ARM_LDRS_PC_G2:
24448 case BFD_RELOC_ARM_LDRS_SB_G0:
24449 case BFD_RELOC_ARM_LDRS_SB_G1:
24450 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24451 gas_assert (!fixP->fx_done);
4962c51a 24452 if (!seg->use_rela_p)
477330fc
RM
24453 {
24454 bfd_vma insn;
24455 bfd_vma addend_abs = abs (value);
4962c51a 24456
477330fc
RM
24457 /* Check that the absolute value of the addend can be
24458 encoded in 8 bits. */
24459 if (addend_abs >= 0x100)
4962c51a 24460 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24461 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24462 (unsigned long) addend_abs);
24463
24464 /* Extract the instruction. */
24465 insn = md_chars_to_number (buf, INSN_SIZE);
24466
24467 /* If the addend is negative, clear bit 23 of the instruction.
24468 Otherwise set it. */
24469 if (value < 0)
24470 insn &= ~(1 << 23);
24471 else
24472 insn |= 1 << 23;
24473
24474 /* Place the first four bits of the absolute value of the addend
24475 into the first 4 bits of the instruction, and the remaining
24476 four into bits 8 .. 11. */
24477 insn &= 0xfffff0f0;
24478 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24479
24480 /* Update the instruction. */
24481 md_number_to_chars (buf, insn, INSN_SIZE);
24482 }
4962c51a
MS
24483 break;
24484
24485 case BFD_RELOC_ARM_LDC_PC_G0:
24486 case BFD_RELOC_ARM_LDC_PC_G1:
24487 case BFD_RELOC_ARM_LDC_PC_G2:
24488 case BFD_RELOC_ARM_LDC_SB_G0:
24489 case BFD_RELOC_ARM_LDC_SB_G1:
24490 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24491 gas_assert (!fixP->fx_done);
4962c51a 24492 if (!seg->use_rela_p)
477330fc
RM
24493 {
24494 bfd_vma insn;
24495 bfd_vma addend_abs = abs (value);
4962c51a 24496
477330fc
RM
24497 /* Check that the absolute value of the addend is a multiple of
24498 four and, when divided by four, fits in 8 bits. */
24499 if (addend_abs & 0x3)
4962c51a 24500 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24501 _("bad offset 0x%08lX (must be word-aligned)"),
24502 (unsigned long) addend_abs);
4962c51a 24503
477330fc 24504 if ((addend_abs >> 2) > 0xff)
4962c51a 24505 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24506 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24507 (unsigned long) addend_abs);
24508
24509 /* Extract the instruction. */
24510 insn = md_chars_to_number (buf, INSN_SIZE);
24511
24512 /* If the addend is negative, clear bit 23 of the instruction.
24513 Otherwise set it. */
24514 if (value < 0)
24515 insn &= ~(1 << 23);
24516 else
24517 insn |= 1 << 23;
24518
24519 /* Place the addend (divided by four) into the first eight
24520 bits of the instruction. */
24521 insn &= 0xfffffff0;
24522 insn |= addend_abs >> 2;
24523
24524 /* Update the instruction. */
24525 md_number_to_chars (buf, insn, INSN_SIZE);
24526 }
4962c51a
MS
24527 break;
24528
845b51d6
PB
24529 case BFD_RELOC_ARM_V4BX:
24530 /* This will need to go in the object file. */
24531 fixP->fx_done = 0;
24532 break;
24533
c19d1205
ZW
24534 case BFD_RELOC_UNUSED:
24535 default:
24536 as_bad_where (fixP->fx_file, fixP->fx_line,
24537 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24538 }
6c43fab6
RE
24539}
24540
c19d1205
ZW
24541/* Translate internal representation of relocation info to BFD target
24542 format. */
a737bd4d 24543
c19d1205 24544arelent *
00a97672 24545tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24546{
c19d1205
ZW
24547 arelent * reloc;
24548 bfd_reloc_code_real_type code;
a737bd4d 24549
325801bd 24550 reloc = XNEW (arelent);
a737bd4d 24551
325801bd 24552 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24553 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24554 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24555
2fc8bdac 24556 if (fixp->fx_pcrel)
00a97672
RS
24557 {
24558 if (section->use_rela_p)
24559 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24560 else
24561 fixp->fx_offset = reloc->address;
24562 }
c19d1205 24563 reloc->addend = fixp->fx_offset;
a737bd4d 24564
c19d1205 24565 switch (fixp->fx_r_type)
a737bd4d 24566 {
c19d1205
ZW
24567 case BFD_RELOC_8:
24568 if (fixp->fx_pcrel)
24569 {
24570 code = BFD_RELOC_8_PCREL;
24571 break;
24572 }
1a0670f3 24573 /* Fall through. */
a737bd4d 24574
c19d1205
ZW
24575 case BFD_RELOC_16:
24576 if (fixp->fx_pcrel)
24577 {
24578 code = BFD_RELOC_16_PCREL;
24579 break;
24580 }
1a0670f3 24581 /* Fall through. */
6c43fab6 24582
c19d1205
ZW
24583 case BFD_RELOC_32:
24584 if (fixp->fx_pcrel)
24585 {
24586 code = BFD_RELOC_32_PCREL;
24587 break;
24588 }
1a0670f3 24589 /* Fall through. */
a737bd4d 24590
b6895b4f
PB
24591 case BFD_RELOC_ARM_MOVW:
24592 if (fixp->fx_pcrel)
24593 {
24594 code = BFD_RELOC_ARM_MOVW_PCREL;
24595 break;
24596 }
1a0670f3 24597 /* Fall through. */
b6895b4f
PB
24598
24599 case BFD_RELOC_ARM_MOVT:
24600 if (fixp->fx_pcrel)
24601 {
24602 code = BFD_RELOC_ARM_MOVT_PCREL;
24603 break;
24604 }
1a0670f3 24605 /* Fall through. */
b6895b4f
PB
24606
24607 case BFD_RELOC_ARM_THUMB_MOVW:
24608 if (fixp->fx_pcrel)
24609 {
24610 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24611 break;
24612 }
1a0670f3 24613 /* Fall through. */
b6895b4f
PB
24614
24615 case BFD_RELOC_ARM_THUMB_MOVT:
24616 if (fixp->fx_pcrel)
24617 {
24618 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24619 break;
24620 }
1a0670f3 24621 /* Fall through. */
b6895b4f 24622
c19d1205
ZW
24623 case BFD_RELOC_NONE:
24624 case BFD_RELOC_ARM_PCREL_BRANCH:
24625 case BFD_RELOC_ARM_PCREL_BLX:
24626 case BFD_RELOC_RVA:
24627 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24628 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24629 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24630 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24631 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24632 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24633 case BFD_RELOC_VTABLE_ENTRY:
24634 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24635#ifdef TE_PE
24636 case BFD_RELOC_32_SECREL:
24637#endif
c19d1205
ZW
24638 code = fixp->fx_r_type;
24639 break;
a737bd4d 24640
00adf2d4
JB
24641 case BFD_RELOC_THUMB_PCREL_BLX:
24642#ifdef OBJ_ELF
24643 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24644 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24645 else
24646#endif
24647 code = BFD_RELOC_THUMB_PCREL_BLX;
24648 break;
24649
c19d1205
ZW
24650 case BFD_RELOC_ARM_LITERAL:
24651 case BFD_RELOC_ARM_HWLITERAL:
24652 /* If this is called then the a literal has
24653 been referenced across a section boundary. */
24654 as_bad_where (fixp->fx_file, fixp->fx_line,
24655 _("literal referenced across section boundary"));
24656 return NULL;
a737bd4d 24657
c19d1205 24658#ifdef OBJ_ELF
0855e32b
NS
24659 case BFD_RELOC_ARM_TLS_CALL:
24660 case BFD_RELOC_ARM_THM_TLS_CALL:
24661 case BFD_RELOC_ARM_TLS_DESCSEQ:
24662 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24663 case BFD_RELOC_ARM_GOT32:
24664 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24665 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24666 case BFD_RELOC_ARM_PLT32:
24667 case BFD_RELOC_ARM_TARGET1:
24668 case BFD_RELOC_ARM_ROSEGREL32:
24669 case BFD_RELOC_ARM_SBREL32:
24670 case BFD_RELOC_ARM_PREL31:
24671 case BFD_RELOC_ARM_TARGET2:
c19d1205 24672 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24673 case BFD_RELOC_ARM_PCREL_CALL:
24674 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24675 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24676 case BFD_RELOC_ARM_ALU_PC_G0:
24677 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24678 case BFD_RELOC_ARM_ALU_PC_G1:
24679 case BFD_RELOC_ARM_ALU_PC_G2:
24680 case BFD_RELOC_ARM_LDR_PC_G0:
24681 case BFD_RELOC_ARM_LDR_PC_G1:
24682 case BFD_RELOC_ARM_LDR_PC_G2:
24683 case BFD_RELOC_ARM_LDRS_PC_G0:
24684 case BFD_RELOC_ARM_LDRS_PC_G1:
24685 case BFD_RELOC_ARM_LDRS_PC_G2:
24686 case BFD_RELOC_ARM_LDC_PC_G0:
24687 case BFD_RELOC_ARM_LDC_PC_G1:
24688 case BFD_RELOC_ARM_LDC_PC_G2:
24689 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24690 case BFD_RELOC_ARM_ALU_SB_G0:
24691 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24692 case BFD_RELOC_ARM_ALU_SB_G1:
24693 case BFD_RELOC_ARM_ALU_SB_G2:
24694 case BFD_RELOC_ARM_LDR_SB_G0:
24695 case BFD_RELOC_ARM_LDR_SB_G1:
24696 case BFD_RELOC_ARM_LDR_SB_G2:
24697 case BFD_RELOC_ARM_LDRS_SB_G0:
24698 case BFD_RELOC_ARM_LDRS_SB_G1:
24699 case BFD_RELOC_ARM_LDRS_SB_G2:
24700 case BFD_RELOC_ARM_LDC_SB_G0:
24701 case BFD_RELOC_ARM_LDC_SB_G1:
24702 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24703 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24704 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24705 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24706 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24707 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24708 code = fixp->fx_r_type;
24709 break;
a737bd4d 24710
0855e32b 24711 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24712 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24713 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24714 case BFD_RELOC_ARM_TLS_IE32:
24715 case BFD_RELOC_ARM_TLS_LDM32:
24716 /* BFD will include the symbol's address in the addend.
24717 But we don't want that, so subtract it out again here. */
24718 if (!S_IS_COMMON (fixp->fx_addsy))
24719 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24720 code = fixp->fx_r_type;
24721 break;
24722#endif
a737bd4d 24723
c19d1205
ZW
24724 case BFD_RELOC_ARM_IMMEDIATE:
24725 as_bad_where (fixp->fx_file, fixp->fx_line,
24726 _("internal relocation (type: IMMEDIATE) not fixed up"));
24727 return NULL;
a737bd4d 24728
c19d1205
ZW
24729 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24730 as_bad_where (fixp->fx_file, fixp->fx_line,
24731 _("ADRL used for a symbol not defined in the same file"));
24732 return NULL;
a737bd4d 24733
c19d1205 24734 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24735 if (section->use_rela_p)
24736 {
24737 code = fixp->fx_r_type;
24738 break;
24739 }
24740
c19d1205
ZW
24741 if (fixp->fx_addsy != NULL
24742 && !S_IS_DEFINED (fixp->fx_addsy)
24743 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24744 {
c19d1205
ZW
24745 as_bad_where (fixp->fx_file, fixp->fx_line,
24746 _("undefined local label `%s'"),
24747 S_GET_NAME (fixp->fx_addsy));
24748 return NULL;
a737bd4d
NC
24749 }
24750
c19d1205
ZW
24751 as_bad_where (fixp->fx_file, fixp->fx_line,
24752 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24753 return NULL;
a737bd4d 24754
c19d1205
ZW
24755 default:
24756 {
e0471c16 24757 const char * type;
6c43fab6 24758
c19d1205
ZW
24759 switch (fixp->fx_r_type)
24760 {
24761 case BFD_RELOC_NONE: type = "NONE"; break;
24762 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24763 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24764 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24765 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24766 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24767 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24768 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24769 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24770 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24771 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24772 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24773 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24774 default: type = _("<unknown>"); break;
24775 }
24776 as_bad_where (fixp->fx_file, fixp->fx_line,
24777 _("cannot represent %s relocation in this object file format"),
24778 type);
24779 return NULL;
24780 }
a737bd4d 24781 }
6c43fab6 24782
c19d1205
ZW
24783#ifdef OBJ_ELF
24784 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24785 && GOT_symbol
24786 && fixp->fx_addsy == GOT_symbol)
24787 {
24788 code = BFD_RELOC_ARM_GOTPC;
24789 reloc->addend = fixp->fx_offset = reloc->address;
24790 }
24791#endif
6c43fab6 24792
c19d1205 24793 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24794
c19d1205
ZW
24795 if (reloc->howto == NULL)
24796 {
24797 as_bad_where (fixp->fx_file, fixp->fx_line,
24798 _("cannot represent %s relocation in this object file format"),
24799 bfd_get_reloc_code_name (code));
24800 return NULL;
24801 }
6c43fab6 24802
c19d1205
ZW
24803 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24804 vtable entry to be used in the relocation's section offset. */
24805 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24806 reloc->address = fixp->fx_offset;
6c43fab6 24807
c19d1205 24808 return reloc;
6c43fab6
RE
24809}
24810
c19d1205 24811/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24812
c19d1205
ZW
24813void
24814cons_fix_new_arm (fragS * frag,
24815 int where,
24816 int size,
62ebcb5c
AM
24817 expressionS * exp,
24818 bfd_reloc_code_real_type reloc)
6c43fab6 24819{
c19d1205 24820 int pcrel = 0;
6c43fab6 24821
c19d1205
ZW
24822 /* Pick a reloc.
24823 FIXME: @@ Should look at CPU word size. */
24824 switch (size)
24825 {
24826 case 1:
62ebcb5c 24827 reloc = BFD_RELOC_8;
c19d1205
ZW
24828 break;
24829 case 2:
62ebcb5c 24830 reloc = BFD_RELOC_16;
c19d1205
ZW
24831 break;
24832 case 4:
24833 default:
62ebcb5c 24834 reloc = BFD_RELOC_32;
c19d1205
ZW
24835 break;
24836 case 8:
62ebcb5c 24837 reloc = BFD_RELOC_64;
c19d1205
ZW
24838 break;
24839 }
6c43fab6 24840
f0927246
NC
24841#ifdef TE_PE
24842 if (exp->X_op == O_secrel)
24843 {
24844 exp->X_op = O_symbol;
62ebcb5c 24845 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24846 }
24847#endif
24848
62ebcb5c 24849 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24850}
6c43fab6 24851
4343666d 24852#if defined (OBJ_COFF)
c19d1205
ZW
24853void
24854arm_validate_fix (fixS * fixP)
6c43fab6 24855{
c19d1205
ZW
24856 /* If the destination of the branch is a defined symbol which does not have
24857 the THUMB_FUNC attribute, then we must be calling a function which has
24858 the (interfacearm) attribute. We look for the Thumb entry point to that
24859 function and change the branch to refer to that function instead. */
24860 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24861 && fixP->fx_addsy != NULL
24862 && S_IS_DEFINED (fixP->fx_addsy)
24863 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24864 {
c19d1205 24865 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24866 }
c19d1205
ZW
24867}
24868#endif
6c43fab6 24869
267bf995 24870
c19d1205
ZW
24871int
24872arm_force_relocation (struct fix * fixp)
24873{
24874#if defined (OBJ_COFF) && defined (TE_PE)
24875 if (fixp->fx_r_type == BFD_RELOC_RVA)
24876 return 1;
24877#endif
6c43fab6 24878
267bf995
RR
24879 /* In case we have a call or a branch to a function in ARM ISA mode from
24880 a thumb function or vice-versa force the relocation. These relocations
24881 are cleared off for some cores that might have blx and simple transformations
24882 are possible. */
24883
24884#ifdef OBJ_ELF
24885 switch (fixp->fx_r_type)
24886 {
24887 case BFD_RELOC_ARM_PCREL_JUMP:
24888 case BFD_RELOC_ARM_PCREL_CALL:
24889 case BFD_RELOC_THUMB_PCREL_BLX:
24890 if (THUMB_IS_FUNC (fixp->fx_addsy))
24891 return 1;
24892 break;
24893
24894 case BFD_RELOC_ARM_PCREL_BLX:
24895 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24896 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24897 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24898 if (ARM_IS_FUNC (fixp->fx_addsy))
24899 return 1;
24900 break;
24901
24902 default:
24903 break;
24904 }
24905#endif
24906
b5884301
PB
24907 /* Resolve these relocations even if the symbol is extern or weak.
24908 Technically this is probably wrong due to symbol preemption.
24909 In practice these relocations do not have enough range to be useful
24910 at dynamic link time, and some code (e.g. in the Linux kernel)
24911 expects these references to be resolved. */
c19d1205
ZW
24912 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24913 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24914 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24915 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24916 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24917 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24918 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24919 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24920 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24921 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24922 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24923 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24924 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24925 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24926 return 0;
a737bd4d 24927
4962c51a
MS
24928 /* Always leave these relocations for the linker. */
24929 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24930 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24931 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24932 return 1;
24933
f0291e4c
PB
24934 /* Always generate relocations against function symbols. */
24935 if (fixp->fx_r_type == BFD_RELOC_32
24936 && fixp->fx_addsy
24937 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24938 return 1;
24939
c19d1205 24940 return generic_force_reloc (fixp);
404ff6b5
AH
24941}
24942
0ffdc86c 24943#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24944/* Relocations against function names must be left unadjusted,
24945 so that the linker can use this information to generate interworking
24946 stubs. The MIPS version of this function
c19d1205
ZW
24947 also prevents relocations that are mips-16 specific, but I do not
24948 know why it does this.
404ff6b5 24949
c19d1205
ZW
24950 FIXME:
24951 There is one other problem that ought to be addressed here, but
24952 which currently is not: Taking the address of a label (rather
24953 than a function) and then later jumping to that address. Such
24954 addresses also ought to have their bottom bit set (assuming that
24955 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24956
c19d1205
ZW
24957bfd_boolean
24958arm_fix_adjustable (fixS * fixP)
404ff6b5 24959{
c19d1205
ZW
24960 if (fixP->fx_addsy == NULL)
24961 return 1;
404ff6b5 24962
e28387c3
PB
24963 /* Preserve relocations against symbols with function type. */
24964 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24965 return FALSE;
e28387c3 24966
c19d1205
ZW
24967 if (THUMB_IS_FUNC (fixP->fx_addsy)
24968 && fixP->fx_subsy == NULL)
c921be7d 24969 return FALSE;
a737bd4d 24970
c19d1205
ZW
24971 /* We need the symbol name for the VTABLE entries. */
24972 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24973 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24974 return FALSE;
404ff6b5 24975
c19d1205
ZW
24976 /* Don't allow symbols to be discarded on GOT related relocs. */
24977 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24978 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24979 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24980 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24981 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24982 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24983 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24984 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24985 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24986 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24987 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24988 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24989 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24990 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24991 return FALSE;
a737bd4d 24992
4962c51a
MS
24993 /* Similarly for group relocations. */
24994 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24995 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24996 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24997 return FALSE;
4962c51a 24998
79947c54
CD
24999 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25000 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25001 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25002 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25003 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25004 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25005 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25006 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25007 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 25008 return FALSE;
79947c54 25009
72d98d16
MG
25010 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25011 offsets, so keep these symbols. */
25012 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25013 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25014 return FALSE;
25015
c921be7d 25016 return TRUE;
a737bd4d 25017}
0ffdc86c
NC
25018#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25019
25020#ifdef OBJ_ELF
c19d1205
ZW
25021const char *
25022elf32_arm_target_format (void)
404ff6b5 25023{
c19d1205
ZW
25024#ifdef TE_SYMBIAN
25025 return (target_big_endian
25026 ? "elf32-bigarm-symbian"
25027 : "elf32-littlearm-symbian");
25028#elif defined (TE_VXWORKS)
25029 return (target_big_endian
25030 ? "elf32-bigarm-vxworks"
25031 : "elf32-littlearm-vxworks");
b38cadfb
NC
25032#elif defined (TE_NACL)
25033 return (target_big_endian
25034 ? "elf32-bigarm-nacl"
25035 : "elf32-littlearm-nacl");
c19d1205
ZW
25036#else
25037 if (target_big_endian)
25038 return "elf32-bigarm";
25039 else
25040 return "elf32-littlearm";
25041#endif
404ff6b5
AH
25042}
25043
c19d1205
ZW
25044void
25045armelf_frob_symbol (symbolS * symp,
25046 int * puntp)
404ff6b5 25047{
c19d1205
ZW
25048 elf_frob_symbol (symp, puntp);
25049}
25050#endif
404ff6b5 25051
c19d1205 25052/* MD interface: Finalization. */
a737bd4d 25053
c19d1205
ZW
25054void
25055arm_cleanup (void)
25056{
25057 literal_pool * pool;
a737bd4d 25058
e07e6e58
NC
25059 /* Ensure that all the IT blocks are properly closed. */
25060 check_it_blocks_finished ();
25061
c19d1205
ZW
25062 for (pool = list_of_pools; pool; pool = pool->next)
25063 {
5f4273c7 25064 /* Put it at the end of the relevant section. */
c19d1205
ZW
25065 subseg_set (pool->section, pool->sub_section);
25066#ifdef OBJ_ELF
25067 arm_elf_change_section ();
25068#endif
25069 s_ltorg (0);
25070 }
404ff6b5
AH
25071}
25072
cd000bff
DJ
25073#ifdef OBJ_ELF
25074/* Remove any excess mapping symbols generated for alignment frags in
25075 SEC. We may have created a mapping symbol before a zero byte
25076 alignment; remove it if there's a mapping symbol after the
25077 alignment. */
25078static void
25079check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25080 void *dummy ATTRIBUTE_UNUSED)
25081{
25082 segment_info_type *seginfo = seg_info (sec);
25083 fragS *fragp;
25084
25085 if (seginfo == NULL || seginfo->frchainP == NULL)
25086 return;
25087
25088 for (fragp = seginfo->frchainP->frch_root;
25089 fragp != NULL;
25090 fragp = fragp->fr_next)
25091 {
25092 symbolS *sym = fragp->tc_frag_data.last_map;
25093 fragS *next = fragp->fr_next;
25094
25095 /* Variable-sized frags have been converted to fixed size by
25096 this point. But if this was variable-sized to start with,
25097 there will be a fixed-size frag after it. So don't handle
25098 next == NULL. */
25099 if (sym == NULL || next == NULL)
25100 continue;
25101
25102 if (S_GET_VALUE (sym) < next->fr_address)
25103 /* Not at the end of this frag. */
25104 continue;
25105 know (S_GET_VALUE (sym) == next->fr_address);
25106
25107 do
25108 {
25109 if (next->tc_frag_data.first_map != NULL)
25110 {
25111 /* Next frag starts with a mapping symbol. Discard this
25112 one. */
25113 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25114 break;
25115 }
25116
25117 if (next->fr_next == NULL)
25118 {
25119 /* This mapping symbol is at the end of the section. Discard
25120 it. */
25121 know (next->fr_fix == 0 && next->fr_var == 0);
25122 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25123 break;
25124 }
25125
25126 /* As long as we have empty frags without any mapping symbols,
25127 keep looking. */
25128 /* If the next frag is non-empty and does not start with a
25129 mapping symbol, then this mapping symbol is required. */
25130 if (next->fr_address != next->fr_next->fr_address)
25131 break;
25132
25133 next = next->fr_next;
25134 }
25135 while (next != NULL);
25136 }
25137}
25138#endif
25139
c19d1205
ZW
25140/* Adjust the symbol table. This marks Thumb symbols as distinct from
25141 ARM ones. */
404ff6b5 25142
c19d1205
ZW
25143void
25144arm_adjust_symtab (void)
404ff6b5 25145{
c19d1205
ZW
25146#ifdef OBJ_COFF
25147 symbolS * sym;
404ff6b5 25148
c19d1205
ZW
25149 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25150 {
25151 if (ARM_IS_THUMB (sym))
25152 {
25153 if (THUMB_IS_FUNC (sym))
25154 {
25155 /* Mark the symbol as a Thumb function. */
25156 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25157 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25158 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 25159
c19d1205
ZW
25160 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25161 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25162 else
25163 as_bad (_("%s: unexpected function type: %d"),
25164 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25165 }
25166 else switch (S_GET_STORAGE_CLASS (sym))
25167 {
25168 case C_EXT:
25169 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25170 break;
25171 case C_STAT:
25172 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25173 break;
25174 case C_LABEL:
25175 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25176 break;
25177 default:
25178 /* Do nothing. */
25179 break;
25180 }
25181 }
a737bd4d 25182
c19d1205
ZW
25183 if (ARM_IS_INTERWORK (sym))
25184 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 25185 }
c19d1205
ZW
25186#endif
25187#ifdef OBJ_ELF
25188 symbolS * sym;
25189 char bind;
404ff6b5 25190
c19d1205 25191 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 25192 {
c19d1205
ZW
25193 if (ARM_IS_THUMB (sym))
25194 {
25195 elf_symbol_type * elf_sym;
404ff6b5 25196
c19d1205
ZW
25197 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25198 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 25199
b0796911
PB
25200 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25201 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
25202 {
25203 /* If it's a .thumb_func, declare it as so,
25204 otherwise tag label as .code 16. */
25205 if (THUMB_IS_FUNC (sym))
39d911fc
TP
25206 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25207 ST_BRANCH_TO_THUMB);
3ba67470 25208 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
25209 elf_sym->internal_elf_sym.st_info =
25210 ELF_ST_INFO (bind, STT_ARM_16BIT);
25211 }
25212 }
25213 }
cd000bff
DJ
25214
25215 /* Remove any overlapping mapping symbols generated by alignment frags. */
25216 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
25217 /* Now do generic ELF adjustments. */
25218 elf_adjust_symtab ();
c19d1205 25219#endif
404ff6b5
AH
25220}
25221
c19d1205 25222/* MD interface: Initialization. */
404ff6b5 25223
a737bd4d 25224static void
c19d1205 25225set_constant_flonums (void)
a737bd4d 25226{
c19d1205 25227 int i;
404ff6b5 25228
c19d1205
ZW
25229 for (i = 0; i < NUM_FLOAT_VALS; i++)
25230 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25231 abort ();
a737bd4d 25232}
404ff6b5 25233
3e9e4fcf
JB
25234/* Auto-select Thumb mode if it's the only available instruction set for the
25235 given architecture. */
25236
25237static void
25238autoselect_thumb_from_cpu_variant (void)
25239{
25240 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25241 opcode_select (16);
25242}
25243
c19d1205
ZW
25244void
25245md_begin (void)
a737bd4d 25246{
c19d1205
ZW
25247 unsigned mach;
25248 unsigned int i;
404ff6b5 25249
c19d1205
ZW
25250 if ( (arm_ops_hsh = hash_new ()) == NULL
25251 || (arm_cond_hsh = hash_new ()) == NULL
25252 || (arm_shift_hsh = hash_new ()) == NULL
25253 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 25254 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 25255 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
25256 || (arm_reloc_hsh = hash_new ()) == NULL
25257 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
25258 as_fatal (_("virtual memory exhausted"));
25259
25260 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 25261 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 25262 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 25263 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 25264 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 25265 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 25266 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25267 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 25268 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25269 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25270 (void *) (v7m_psrs + i));
c19d1205 25271 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25272 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25273 for (i = 0;
25274 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25275 i++)
d3ce72d0 25276 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25277 (void *) (barrier_opt_names + i));
c19d1205 25278#ifdef OBJ_ELF
3da1d841
NC
25279 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25280 {
25281 struct reloc_entry * entry = reloc_names + i;
25282
25283 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25284 /* This makes encode_branch() use the EABI versions of this relocation. */
25285 entry->reloc = BFD_RELOC_UNUSED;
25286
25287 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25288 }
c19d1205
ZW
25289#endif
25290
25291 set_constant_flonums ();
404ff6b5 25292
c19d1205
ZW
25293 /* Set the cpu variant based on the command-line options. We prefer
25294 -mcpu= over -march= if both are set (as for GCC); and we prefer
25295 -mfpu= over any other way of setting the floating point unit.
25296 Use of legacy options with new options are faulted. */
e74cfd16 25297 if (legacy_cpu)
404ff6b5 25298 {
e74cfd16 25299 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25300 as_bad (_("use of old and new-style options to set CPU type"));
25301
25302 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25303 }
e74cfd16 25304 else if (!mcpu_cpu_opt)
c168ce07
TP
25305 {
25306 mcpu_cpu_opt = march_cpu_opt;
25307 dyn_mcpu_ext_opt = dyn_march_ext_opt;
25308 /* Avoid double free in arm_md_end. */
25309 dyn_march_ext_opt = NULL;
25310 }
404ff6b5 25311
e74cfd16 25312 if (legacy_fpu)
c19d1205 25313 {
e74cfd16 25314 if (mfpu_opt)
c19d1205 25315 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25316
25317 mfpu_opt = legacy_fpu;
25318 }
e74cfd16 25319 else if (!mfpu_opt)
03b1477f 25320 {
45eb4c1b
NS
25321#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25322 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25323 /* Some environments specify a default FPU. If they don't, infer it
25324 from the processor. */
e74cfd16 25325 if (mcpu_fpu_opt)
03b1477f
RE
25326 mfpu_opt = mcpu_fpu_opt;
25327 else
25328 mfpu_opt = march_fpu_opt;
39c2da32 25329#else
e74cfd16 25330 mfpu_opt = &fpu_default;
39c2da32 25331#endif
03b1477f
RE
25332 }
25333
e74cfd16 25334 if (!mfpu_opt)
03b1477f 25335 {
493cb6ef 25336 if (mcpu_cpu_opt != NULL)
e74cfd16 25337 mfpu_opt = &fpu_default;
493cb6ef 25338 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25339 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25340 else
e74cfd16 25341 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25342 }
25343
ee065d83 25344#ifdef CPU_DEFAULT
e74cfd16 25345 if (!mcpu_cpu_opt)
ee065d83 25346 {
e74cfd16
PB
25347 mcpu_cpu_opt = &cpu_default;
25348 selected_cpu = cpu_default;
ee065d83 25349 }
c168ce07
TP
25350 else if (dyn_mcpu_ext_opt)
25351 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
62785b09
TP
25352 else
25353 selected_cpu = *mcpu_cpu_opt;
e74cfd16 25354#else
c168ce07
TP
25355 if (mcpu_cpu_opt && dyn_mcpu_ext_opt)
25356 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
25357 else if (mcpu_cpu_opt)
e74cfd16 25358 selected_cpu = *mcpu_cpu_opt;
ee065d83 25359 else
e74cfd16 25360 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25361#endif
03b1477f 25362
e74cfd16 25363 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
25364 if (dyn_mcpu_ext_opt)
25365 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
03b1477f 25366
3e9e4fcf
JB
25367 autoselect_thumb_from_cpu_variant ();
25368
e74cfd16 25369 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25370
f17c130b 25371#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25372 {
7cc69913
NC
25373 unsigned int flags = 0;
25374
25375#if defined OBJ_ELF
25376 flags = meabi_flags;
d507cf36
PB
25377
25378 switch (meabi_flags)
33a392fb 25379 {
d507cf36 25380 case EF_ARM_EABI_UNKNOWN:
7cc69913 25381#endif
d507cf36
PB
25382 /* Set the flags in the private structure. */
25383 if (uses_apcs_26) flags |= F_APCS26;
25384 if (support_interwork) flags |= F_INTERWORK;
25385 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25386 if (pic_code) flags |= F_PIC;
e74cfd16 25387 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25388 flags |= F_SOFT_FLOAT;
25389
d507cf36
PB
25390 switch (mfloat_abi_opt)
25391 {
25392 case ARM_FLOAT_ABI_SOFT:
25393 case ARM_FLOAT_ABI_SOFTFP:
25394 flags |= F_SOFT_FLOAT;
25395 break;
33a392fb 25396
d507cf36
PB
25397 case ARM_FLOAT_ABI_HARD:
25398 if (flags & F_SOFT_FLOAT)
25399 as_bad (_("hard-float conflicts with specified fpu"));
25400 break;
25401 }
03b1477f 25402
e74cfd16
PB
25403 /* Using pure-endian doubles (even if soft-float). */
25404 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25405 flags |= F_VFP_FLOAT;
f17c130b 25406
fde78edd 25407#if defined OBJ_ELF
e74cfd16 25408 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25409 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25410 break;
25411
8cb51566 25412 case EF_ARM_EABI_VER4:
3a4a14e9 25413 case EF_ARM_EABI_VER5:
c19d1205 25414 /* No additional flags to set. */
d507cf36
PB
25415 break;
25416
25417 default:
25418 abort ();
25419 }
7cc69913 25420#endif
b99bd4ef
NC
25421 bfd_set_private_flags (stdoutput, flags);
25422
25423 /* We have run out flags in the COFF header to encode the
25424 status of ATPCS support, so instead we create a dummy,
c19d1205 25425 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25426 if (atpcs)
25427 {
25428 asection * sec;
25429
25430 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25431
25432 if (sec != NULL)
25433 {
25434 bfd_set_section_flags
25435 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25436 bfd_set_section_size (stdoutput, sec, 0);
25437 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25438 }
25439 }
7cc69913 25440 }
f17c130b 25441#endif
b99bd4ef
NC
25442
25443 /* Record the CPU type as well. */
2d447fca
JM
25444 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25445 mach = bfd_mach_arm_iWMMXt2;
25446 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25447 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25448 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25449 mach = bfd_mach_arm_XScale;
e74cfd16 25450 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25451 mach = bfd_mach_arm_ep9312;
e74cfd16 25452 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25453 mach = bfd_mach_arm_5TE;
e74cfd16 25454 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25455 {
e74cfd16 25456 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25457 mach = bfd_mach_arm_5T;
25458 else
25459 mach = bfd_mach_arm_5;
25460 }
e74cfd16 25461 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25462 {
e74cfd16 25463 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25464 mach = bfd_mach_arm_4T;
25465 else
25466 mach = bfd_mach_arm_4;
25467 }
e74cfd16 25468 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25469 mach = bfd_mach_arm_3M;
e74cfd16
PB
25470 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25471 mach = bfd_mach_arm_3;
25472 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25473 mach = bfd_mach_arm_2a;
25474 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25475 mach = bfd_mach_arm_2;
25476 else
25477 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25478
25479 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25480}
25481
c19d1205 25482/* Command line processing. */
b99bd4ef 25483
c19d1205
ZW
25484/* md_parse_option
25485 Invocation line includes a switch not recognized by the base assembler.
25486 See if it's a processor-specific option.
b99bd4ef 25487
c19d1205
ZW
25488 This routine is somewhat complicated by the need for backwards
25489 compatibility (since older releases of gcc can't be changed).
25490 The new options try to make the interface as compatible as
25491 possible with GCC.
b99bd4ef 25492
c19d1205 25493 New options (supported) are:
b99bd4ef 25494
c19d1205
ZW
25495 -mcpu=<cpu name> Assemble for selected processor
25496 -march=<architecture name> Assemble for selected architecture
25497 -mfpu=<fpu architecture> Assemble for selected FPU.
25498 -EB/-mbig-endian Big-endian
25499 -EL/-mlittle-endian Little-endian
25500 -k Generate PIC code
25501 -mthumb Start in Thumb mode
25502 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25503
278df34e 25504 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25505 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25506
c19d1205 25507 For now we will also provide support for:
b99bd4ef 25508
c19d1205
ZW
25509 -mapcs-32 32-bit Program counter
25510 -mapcs-26 26-bit Program counter
25511 -macps-float Floats passed in FP registers
25512 -mapcs-reentrant Reentrant code
25513 -matpcs
25514 (sometime these will probably be replaced with -mapcs=<list of options>
25515 and -matpcs=<list of options>)
b99bd4ef 25516
c19d1205
ZW
25517 The remaining options are only supported for back-wards compatibility.
25518 Cpu variants, the arm part is optional:
25519 -m[arm]1 Currently not supported.
25520 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25521 -m[arm]3 Arm 3 processor
25522 -m[arm]6[xx], Arm 6 processors
25523 -m[arm]7[xx][t][[d]m] Arm 7 processors
25524 -m[arm]8[10] Arm 8 processors
25525 -m[arm]9[20][tdmi] Arm 9 processors
25526 -mstrongarm[110[0]] StrongARM processors
25527 -mxscale XScale processors
25528 -m[arm]v[2345[t[e]]] Arm architectures
25529 -mall All (except the ARM1)
25530 FP variants:
25531 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25532 -mfpe-old (No float load/store multiples)
25533 -mvfpxd VFP Single precision
25534 -mvfp All VFP
25535 -mno-fpu Disable all floating point instructions
b99bd4ef 25536
c19d1205
ZW
25537 The following CPU names are recognized:
25538 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25539 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25540 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25541 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25542 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25543 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25544 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25545
c19d1205 25546 */
b99bd4ef 25547
c19d1205 25548const char * md_shortopts = "m:k";
b99bd4ef 25549
c19d1205
ZW
25550#ifdef ARM_BI_ENDIAN
25551#define OPTION_EB (OPTION_MD_BASE + 0)
25552#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25553#else
c19d1205
ZW
25554#if TARGET_BYTES_BIG_ENDIAN
25555#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25556#else
c19d1205
ZW
25557#define OPTION_EL (OPTION_MD_BASE + 1)
25558#endif
b99bd4ef 25559#endif
845b51d6 25560#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25561
c19d1205 25562struct option md_longopts[] =
b99bd4ef 25563{
c19d1205
ZW
25564#ifdef OPTION_EB
25565 {"EB", no_argument, NULL, OPTION_EB},
25566#endif
25567#ifdef OPTION_EL
25568 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25569#endif
845b51d6 25570 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25571 {NULL, no_argument, NULL, 0}
25572};
b99bd4ef 25573
c19d1205 25574size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25575
c19d1205 25576struct arm_option_table
b99bd4ef 25577{
0198d5e6
TC
25578 const char * option; /* Option name to match. */
25579 const char * help; /* Help information. */
25580 int * var; /* Variable to change. */
25581 int value; /* What to change it to. */
25582 const char * deprecated; /* If non-null, print this message. */
c19d1205 25583};
b99bd4ef 25584
c19d1205
ZW
25585struct arm_option_table arm_opts[] =
25586{
25587 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25588 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25589 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25590 &support_interwork, 1, NULL},
25591 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25592 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25593 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25594 1, NULL},
25595 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25596 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25597 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25598 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25599 NULL},
b99bd4ef 25600
c19d1205
ZW
25601 /* These are recognized by the assembler, but have no affect on code. */
25602 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25603 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25604
25605 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25606 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25607 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25608 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25609 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25610 {NULL, NULL, NULL, 0, NULL}
25611};
25612
25613struct arm_legacy_option_table
25614{
0198d5e6
TC
25615 const char * option; /* Option name to match. */
25616 const arm_feature_set ** var; /* Variable to change. */
25617 const arm_feature_set value; /* What to change it to. */
25618 const char * deprecated; /* If non-null, print this message. */
e74cfd16 25619};
b99bd4ef 25620
e74cfd16
PB
25621const struct arm_legacy_option_table arm_legacy_opts[] =
25622{
c19d1205
ZW
25623 /* DON'T add any new processors to this list -- we want the whole list
25624 to go away... Add them to the processors table instead. */
e74cfd16
PB
25625 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25626 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25627 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25628 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25629 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25630 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25631 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25632 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25633 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25634 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25635 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25636 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25637 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25638 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25639 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25640 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25641 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25642 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25643 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25644 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25645 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25646 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25647 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25648 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25649 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25650 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25651 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25652 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25653 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25654 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25655 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25656 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25657 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25658 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25659 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25660 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25661 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25662 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25663 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25664 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25665 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25666 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25667 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25668 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25669 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25670 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25671 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25672 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25673 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25674 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25675 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25676 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25677 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25678 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25679 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25680 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25681 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25682 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25683 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25684 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25685 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25686 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25687 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25688 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25689 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25690 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25691 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25692 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25693 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25694 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25695 N_("use -mcpu=strongarm110")},
e74cfd16 25696 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25697 N_("use -mcpu=strongarm1100")},
e74cfd16 25698 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25699 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25700 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25701 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25702 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25703
c19d1205 25704 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25705 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25706 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25707 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25708 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25709 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25710 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25711 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25712 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25713 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25714 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25715 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25716 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25717 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25718 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25719 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25720 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25721 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25722 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25723
c19d1205 25724 /* Floating point variants -- don't add any more to this list either. */
0198d5e6
TC
25725 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25726 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25727 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25728 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25729 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25730
e74cfd16 25731 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25732};
7ed4c4c5 25733
c19d1205 25734struct arm_cpu_option_table
7ed4c4c5 25735{
0198d5e6
TC
25736 const char * name;
25737 size_t name_len;
25738 const arm_feature_set value;
25739 const arm_feature_set ext;
c19d1205
ZW
25740 /* For some CPUs we assume an FPU unless the user explicitly sets
25741 -mfpu=... */
0198d5e6 25742 const arm_feature_set default_fpu;
ee065d83
PB
25743 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25744 case. */
0198d5e6 25745 const char * canonical_name;
c19d1205 25746};
7ed4c4c5 25747
c19d1205
ZW
25748/* This list should, at a minimum, contain all the cpu names
25749 recognized by GCC. */
996b5569 25750#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
0198d5e6 25751
e74cfd16 25752static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25753{
996b5569
TP
25754 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25755 ARM_ARCH_NONE,
25756 FPU_ARCH_FPA),
25757 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25758 ARM_ARCH_NONE,
25759 FPU_ARCH_FPA),
25760 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25761 ARM_ARCH_NONE,
25762 FPU_ARCH_FPA),
25763 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25764 ARM_ARCH_NONE,
25765 FPU_ARCH_FPA),
25766 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25767 ARM_ARCH_NONE,
25768 FPU_ARCH_FPA),
25769 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25770 ARM_ARCH_NONE,
25771 FPU_ARCH_FPA),
25772 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25773 ARM_ARCH_NONE,
25774 FPU_ARCH_FPA),
25775 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25776 ARM_ARCH_NONE,
25777 FPU_ARCH_FPA),
25778 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25779 ARM_ARCH_NONE,
25780 FPU_ARCH_FPA),
25781 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25782 ARM_ARCH_NONE,
25783 FPU_ARCH_FPA),
25784 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25785 ARM_ARCH_NONE,
25786 FPU_ARCH_FPA),
25787 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25788 ARM_ARCH_NONE,
25789 FPU_ARCH_FPA),
25790 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25791 ARM_ARCH_NONE,
25792 FPU_ARCH_FPA),
25793 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25794 ARM_ARCH_NONE,
25795 FPU_ARCH_FPA),
25796 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25797 ARM_ARCH_NONE,
25798 FPU_ARCH_FPA),
25799 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25800 ARM_ARCH_NONE,
25801 FPU_ARCH_FPA),
25802 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25803 ARM_ARCH_NONE,
25804 FPU_ARCH_FPA),
25805 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25806 ARM_ARCH_NONE,
25807 FPU_ARCH_FPA),
25808 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25809 ARM_ARCH_NONE,
25810 FPU_ARCH_FPA),
25811 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25812 ARM_ARCH_NONE,
25813 FPU_ARCH_FPA),
25814 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25815 ARM_ARCH_NONE,
25816 FPU_ARCH_FPA),
25817 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25818 ARM_ARCH_NONE,
25819 FPU_ARCH_FPA),
25820 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25821 ARM_ARCH_NONE,
25822 FPU_ARCH_FPA),
25823 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25824 ARM_ARCH_NONE,
25825 FPU_ARCH_FPA),
25826 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25827 ARM_ARCH_NONE,
25828 FPU_ARCH_FPA),
25829 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25830 ARM_ARCH_NONE,
25831 FPU_ARCH_FPA),
25832 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25833 ARM_ARCH_NONE,
25834 FPU_ARCH_FPA),
25835 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25836 ARM_ARCH_NONE,
25837 FPU_ARCH_FPA),
25838 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25839 ARM_ARCH_NONE,
25840 FPU_ARCH_FPA),
25841 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25842 ARM_ARCH_NONE,
25843 FPU_ARCH_FPA),
25844 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25845 ARM_ARCH_NONE,
25846 FPU_ARCH_FPA),
25847 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25848 ARM_ARCH_NONE,
25849 FPU_ARCH_FPA),
25850 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25851 ARM_ARCH_NONE,
25852 FPU_ARCH_FPA),
25853 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25854 ARM_ARCH_NONE,
25855 FPU_ARCH_FPA),
25856 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25857 ARM_ARCH_NONE,
25858 FPU_ARCH_FPA),
25859 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25860 ARM_ARCH_NONE,
25861 FPU_ARCH_FPA),
25862 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25863 ARM_ARCH_NONE,
25864 FPU_ARCH_FPA),
25865 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25866 ARM_ARCH_NONE,
25867 FPU_ARCH_FPA),
25868 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25869 ARM_ARCH_NONE,
25870 FPU_ARCH_FPA),
25871 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25872 ARM_ARCH_NONE,
25873 FPU_ARCH_FPA),
25874 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25875 ARM_ARCH_NONE,
25876 FPU_ARCH_FPA),
25877 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25878 ARM_ARCH_NONE,
25879 FPU_ARCH_FPA),
25880 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25881 ARM_ARCH_NONE,
25882 FPU_ARCH_FPA),
25883 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25884 ARM_ARCH_NONE,
25885 FPU_ARCH_FPA),
25886 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25887 ARM_ARCH_NONE,
25888 FPU_ARCH_FPA),
25889 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25890 ARM_ARCH_NONE,
25891 FPU_ARCH_FPA),
25892
c19d1205
ZW
25893 /* For V5 or later processors we default to using VFP; but the user
25894 should really set the FPU type explicitly. */
996b5569
TP
25895 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25896 ARM_ARCH_NONE,
25897 FPU_ARCH_VFP_V2),
25898 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25899 ARM_ARCH_NONE,
25900 FPU_ARCH_VFP_V2),
25901 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25902 ARM_ARCH_NONE,
25903 FPU_ARCH_VFP_V2),
25904 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25905 ARM_ARCH_NONE,
25906 FPU_ARCH_VFP_V2),
25907 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25908 ARM_ARCH_NONE,
25909 FPU_ARCH_VFP_V2),
25910 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25911 ARM_ARCH_NONE,
25912 FPU_ARCH_VFP_V2),
25913 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25914 ARM_ARCH_NONE,
25915 FPU_ARCH_VFP_V2),
25916 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25917 ARM_ARCH_NONE,
25918 FPU_ARCH_VFP_V2),
25919 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25920 ARM_ARCH_NONE,
25921 FPU_ARCH_VFP_V2),
25922 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25923 ARM_ARCH_NONE,
25924 FPU_ARCH_VFP_V2),
25925 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
25926 ARM_ARCH_NONE,
25927 FPU_ARCH_VFP_V2),
25928 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
25929 ARM_ARCH_NONE,
25930 FPU_ARCH_VFP_V2),
25931 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
25932 ARM_ARCH_NONE,
25933 FPU_ARCH_VFP_V1),
25934 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
25935 ARM_ARCH_NONE,
25936 FPU_ARCH_VFP_V1),
25937 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
25938 ARM_ARCH_NONE,
25939 FPU_ARCH_VFP_V2),
25940 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
25941 ARM_ARCH_NONE,
25942 FPU_ARCH_VFP_V2),
25943 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
25944 ARM_ARCH_NONE,
25945 FPU_ARCH_VFP_V1),
25946 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
25947 ARM_ARCH_NONE,
25948 FPU_ARCH_VFP_V2),
25949 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
25950 ARM_ARCH_NONE,
25951 FPU_ARCH_VFP_V2),
25952 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
25953 ARM_ARCH_NONE,
25954 FPU_ARCH_VFP_V2),
25955 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
25956 ARM_ARCH_NONE,
25957 FPU_ARCH_VFP_V2),
25958 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
25959 ARM_ARCH_NONE,
25960 FPU_ARCH_VFP_V2),
25961 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
25962 ARM_ARCH_NONE,
25963 FPU_ARCH_VFP_V2),
25964 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
25965 ARM_ARCH_NONE,
25966 FPU_ARCH_VFP_V2),
25967 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
25968 ARM_ARCH_NONE,
25969 FPU_ARCH_VFP_V2),
25970 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
25971 ARM_ARCH_NONE,
25972 FPU_ARCH_VFP_V2),
25973 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
25974 ARM_ARCH_NONE,
25975 FPU_NONE),
25976 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
25977 ARM_ARCH_NONE,
25978 FPU_NONE),
25979 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
25980 ARM_ARCH_NONE,
25981 FPU_ARCH_VFP_V2),
25982 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
25983 ARM_ARCH_NONE,
25984 FPU_ARCH_VFP_V2),
25985 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
25986 ARM_ARCH_NONE,
25987 FPU_ARCH_VFP_V2),
25988 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
25989 ARM_ARCH_NONE,
25990 FPU_NONE),
25991 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
25992 ARM_ARCH_NONE,
25993 FPU_NONE),
25994 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
25995 ARM_ARCH_NONE,
25996 FPU_ARCH_VFP_V2),
25997 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
25998 ARM_ARCH_NONE,
25999 FPU_NONE),
26000 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26001 ARM_ARCH_NONE,
26002 FPU_ARCH_VFP_V2),
26003 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26004 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26005 FPU_NONE),
26006 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26007 ARM_ARCH_NONE,
26008 FPU_ARCH_NEON_VFP_V4),
26009 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26010 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26011 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26012 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26013 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26014 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26015 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26016 ARM_ARCH_NONE,
26017 FPU_ARCH_NEON_VFP_V4),
26018 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26019 ARM_ARCH_NONE,
26020 FPU_ARCH_NEON_VFP_V4),
26021 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26022 ARM_ARCH_NONE,
26023 FPU_ARCH_NEON_VFP_V4),
26024 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26025 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26026 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26027 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26028 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26029 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26030 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26031 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26032 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26033 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26034 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26035 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26036 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26037 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26038 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26039 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26040 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26041 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26042 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26043 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26044 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
15a7695f
JG
26045 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26046 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
0198d5e6 26047 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
996b5569
TP
26048 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26049 ARM_ARCH_NONE,
26050 FPU_NONE),
26051 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26052 ARM_ARCH_NONE,
26053 FPU_ARCH_VFP_V3D16),
26054 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26055 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26056 FPU_NONE),
26057 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26058 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26059 FPU_ARCH_VFP_V3D16),
26060 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26061 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26062 FPU_ARCH_VFP_V3D16),
0cda1e19
TP
26063 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26064 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26065 FPU_ARCH_NEON_VFP_ARMV8),
996b5569
TP
26066 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26067 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26068 FPU_NONE),
26069 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26070 ARM_ARCH_NONE,
26071 FPU_NONE),
26072 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26073 ARM_ARCH_NONE,
26074 FPU_NONE),
26075 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26076 ARM_ARCH_NONE,
26077 FPU_NONE),
26078 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26079 ARM_ARCH_NONE,
26080 FPU_NONE),
26081 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26082 ARM_ARCH_NONE,
26083 FPU_NONE),
26084 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26085 ARM_ARCH_NONE,
26086 FPU_NONE),
26087 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26088 ARM_ARCH_NONE,
26089 FPU_NONE),
26090 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26091 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26092 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 26093
c19d1205 26094 /* ??? XSCALE is really an architecture. */
996b5569
TP
26095 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26096 ARM_ARCH_NONE,
26097 FPU_ARCH_VFP_V2),
26098
c19d1205 26099 /* ??? iwmmxt is not a processor. */
996b5569
TP
26100 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26101 ARM_ARCH_NONE,
26102 FPU_ARCH_VFP_V2),
26103 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26104 ARM_ARCH_NONE,
26105 FPU_ARCH_VFP_V2),
26106 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26107 ARM_ARCH_NONE,
26108 FPU_ARCH_VFP_V2),
26109
0198d5e6 26110 /* Maverick. */
996b5569
TP
26111 ARM_CPU_OPT ("ep9312", "ARM920T",
26112 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26113 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26114
da4339ed 26115 /* Marvell processors. */
996b5569
TP
26116 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26117 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26118 FPU_ARCH_VFP_V3D16),
26119 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26120 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26121 FPU_ARCH_NEON_VFP_V4),
da4339ed 26122
996b5569
TP
26123 /* APM X-Gene family. */
26124 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26125 ARM_ARCH_NONE,
26126 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26127 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26128 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26129 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26130
26131 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 26132};
f3bad469 26133#undef ARM_CPU_OPT
7ed4c4c5 26134
c19d1205 26135struct arm_arch_option_table
7ed4c4c5 26136{
0198d5e6
TC
26137 const char * name;
26138 size_t name_len;
26139 const arm_feature_set value;
26140 const arm_feature_set default_fpu;
c19d1205 26141};
7ed4c4c5 26142
c19d1205
ZW
26143/* This list should, at a minimum, contain all the architecture names
26144 recognized by GCC. */
f3bad469 26145#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
0198d5e6 26146
e74cfd16 26147static const struct arm_arch_option_table arm_archs[] =
c19d1205 26148{
f3bad469
MGD
26149 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26150 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26151 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26152 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26153 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26154 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26155 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26156 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26157 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26158 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26159 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26160 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26161 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26162 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26163 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26164 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26165 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26166 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26167 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26168 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26169 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
26170 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26171 kept to preserve existing behaviour. */
26172 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26173 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
26174 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26175 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26176 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
26177 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26178 kept to preserve existing behaviour. */
26179 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26180 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
26181 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26182 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26183 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
26184 /* The official spelling of the ARMv7 profile variants is the dashed form.
26185 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 26186 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 26187 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
26188 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26189 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26190 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26191 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26192 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26193 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 26194 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 26195 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 26196 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 26197 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 26198 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 26199 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
ced40572 26200 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
dec41383 26201 ARM_ARCH_OPT ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP),
f3bad469
MGD
26202 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26203 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26204 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26205 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 26206};
f3bad469 26207#undef ARM_ARCH_OPT
7ed4c4c5 26208
69133863 26209/* ISA extensions in the co-processor and main instruction set space. */
0198d5e6 26210
69133863 26211struct arm_option_extension_value_table
c19d1205 26212{
0198d5e6
TC
26213 const char * name;
26214 size_t name_len;
26215 const arm_feature_set merge_value;
26216 const arm_feature_set clear_value;
d942732e
TP
26217 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26218 indicates that an extension is available for all architectures while
26219 ARM_ANY marks an empty entry. */
0198d5e6 26220 const arm_feature_set allowed_archs[2];
c19d1205 26221};
7ed4c4c5 26222
0198d5e6
TC
26223/* The following table must be in alphabetical order with a NULL last entry. */
26224
d942732e
TP
26225#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26226#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
0198d5e6 26227
69133863 26228static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 26229{
823d2571
TG
26230 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26231 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 26232 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
26233 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26234 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
c604a79a
JW
26235 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26236 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26237 ARM_ARCH_V8_2A),
15afaa63
TP
26238 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26239 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26240 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
26241 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26242 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
26243 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26245 ARM_ARCH_V8_2A),
d942732e 26246 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 26247 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
26248 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26249 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
3d030cdb
TP
26250 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26251 Thumb divide instruction. Due to this having the same name as the
26252 previous entry, this will be ignored when doing command-line parsing and
26253 only considered by build attribute selection code. */
26254 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26255 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26256 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
823d2571 26257 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 26258 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 26259 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 26260 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 26261 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
26262 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26263 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 26264 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
26265 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26266 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
26267 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26268 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26269 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
26270 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26271 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
ced40572 26272 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
4d1464f2
MW
26273 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26274 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
ced40572 26275 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
643afb90
MW
26276 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26277 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
ced40572 26278 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
d942732e 26279 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 26280 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
26281 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26282 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
26283 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26284 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26285 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
26286 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26287 | ARM_EXT_DIV),
26288 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26289 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26290 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
26291 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26292 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 26293};
f3bad469 26294#undef ARM_EXT_OPT
69133863
MGD
26295
26296/* ISA floating-point and Advanced SIMD extensions. */
26297struct arm_option_fpu_value_table
26298{
0198d5e6
TC
26299 const char * name;
26300 const arm_feature_set value;
c19d1205 26301};
7ed4c4c5 26302
c19d1205
ZW
26303/* This list should, at a minimum, contain all the fpu names
26304 recognized by GCC. */
69133863 26305static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26306{
26307 {"softfpa", FPU_NONE},
26308 {"fpe", FPU_ARCH_FPE},
26309 {"fpe2", FPU_ARCH_FPE},
26310 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26311 {"fpa", FPU_ARCH_FPA},
26312 {"fpa10", FPU_ARCH_FPA},
26313 {"fpa11", FPU_ARCH_FPA},
26314 {"arm7500fe", FPU_ARCH_FPA},
26315 {"softvfp", FPU_ARCH_VFP},
26316 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26317 {"vfp", FPU_ARCH_VFP_V2},
26318 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26319 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26320 {"vfp10", FPU_ARCH_VFP_V2},
26321 {"vfp10-r0", FPU_ARCH_VFP_V1},
26322 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26323 {"vfpv2", FPU_ARCH_VFP_V2},
26324 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26325 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26326 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26327 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26328 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26329 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26330 {"arm1020t", FPU_ARCH_VFP_V1},
26331 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26332 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26333 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26334 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26335 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26336 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26337 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26338 {"vfpv4", FPU_ARCH_VFP_V4},
26339 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26340 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26341 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26342 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26343 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26344 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26345 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26346 {"crypto-neon-fp-armv8",
26347 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26348 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26349 {"crypto-neon-fp-armv8.1",
26350 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26351 {NULL, ARM_ARCH_NONE}
26352};
26353
26354struct arm_option_value_table
26355{
e0471c16 26356 const char *name;
e74cfd16 26357 long value;
c19d1205 26358};
7ed4c4c5 26359
e74cfd16 26360static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26361{
26362 {"hard", ARM_FLOAT_ABI_HARD},
26363 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26364 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26365 {NULL, 0}
c19d1205 26366};
7ed4c4c5 26367
c19d1205 26368#ifdef OBJ_ELF
3a4a14e9 26369/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26370static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26371{
26372 {"gnu", EF_ARM_EABI_UNKNOWN},
26373 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26374 {"5", EF_ARM_EABI_VER5},
e74cfd16 26375 {NULL, 0}
c19d1205
ZW
26376};
26377#endif
7ed4c4c5 26378
c19d1205
ZW
26379struct arm_long_option_table
26380{
0198d5e6 26381 const char * option; /* Substring to match. */
e0471c16 26382 const char * help; /* Help information. */
17b9d67d 26383 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26384 const char * deprecated; /* If non-null, print this message. */
c19d1205 26385};
7ed4c4c5 26386
c921be7d 26387static bfd_boolean
c168ce07
TP
26388arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26389 arm_feature_set **ext_set_p)
7ed4c4c5 26390{
69133863 26391 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26392 extensions being added before being removed. We achieve this by having
26393 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26394 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26395 or removing it (0) and only allowing it to change in the order
69133863
MGD
26396 -1 -> 1 -> 0. */
26397 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26398 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26399 int adding_value = -1;
26400
c168ce07
TP
26401 if (!*ext_set_p)
26402 {
26403 *ext_set_p = XNEW (arm_feature_set);
26404 **ext_set_p = arm_arch_none;
26405 }
e74cfd16 26406
c19d1205 26407 while (str != NULL && *str != 0)
7ed4c4c5 26408 {
82b8a785 26409 const char *ext;
f3bad469 26410 size_t len;
7ed4c4c5 26411
c19d1205
ZW
26412 if (*str != '+')
26413 {
26414 as_bad (_("invalid architectural extension"));
c921be7d 26415 return FALSE;
c19d1205 26416 }
7ed4c4c5 26417
c19d1205
ZW
26418 str++;
26419 ext = strchr (str, '+');
7ed4c4c5 26420
c19d1205 26421 if (ext != NULL)
f3bad469 26422 len = ext - str;
c19d1205 26423 else
f3bad469 26424 len = strlen (str);
7ed4c4c5 26425
f3bad469 26426 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26427 {
26428 if (adding_value != 0)
26429 {
26430 adding_value = 0;
26431 opt = arm_extensions;
26432 }
26433
f3bad469 26434 len -= 2;
69133863
MGD
26435 str += 2;
26436 }
f3bad469 26437 else if (len > 0)
69133863
MGD
26438 {
26439 if (adding_value == -1)
26440 {
26441 adding_value = 1;
26442 opt = arm_extensions;
26443 }
26444 else if (adding_value != 1)
26445 {
26446 as_bad (_("must specify extensions to add before specifying "
26447 "those to remove"));
26448 return FALSE;
26449 }
26450 }
26451
f3bad469 26452 if (len == 0)
c19d1205
ZW
26453 {
26454 as_bad (_("missing architectural extension"));
c921be7d 26455 return FALSE;
c19d1205 26456 }
7ed4c4c5 26457
69133863
MGD
26458 gas_assert (adding_value != -1);
26459 gas_assert (opt != NULL);
26460
26461 /* Scan over the options table trying to find an exact match. */
26462 for (; opt->name != NULL; opt++)
f3bad469 26463 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26464 {
d942732e
TP
26465 int i, nb_allowed_archs =
26466 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26467 /* Check we can apply the extension to this architecture. */
d942732e
TP
26468 for (i = 0; i < nb_allowed_archs; i++)
26469 {
26470 /* Empty entry. */
26471 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26472 continue;
c168ce07 26473 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
d942732e
TP
26474 break;
26475 }
26476 if (i == nb_allowed_archs)
69133863
MGD
26477 {
26478 as_bad (_("extension does not apply to the base architecture"));
26479 return FALSE;
26480 }
26481
26482 /* Add or remove the extension. */
26483 if (adding_value)
c168ce07
TP
26484 ARM_MERGE_FEATURE_SETS (**ext_set_p, **ext_set_p,
26485 opt->merge_value);
69133863 26486 else
c168ce07 26487 ARM_CLEAR_FEATURE (**ext_set_p, **ext_set_p, opt->clear_value);
69133863 26488
3d030cdb
TP
26489 /* Allowing Thumb division instructions for ARMv7 in autodetection
26490 rely on this break so that duplicate extensions (extensions
26491 with the same name as a previous extension in the list) are not
26492 considered for command-line parsing. */
c19d1205
ZW
26493 break;
26494 }
7ed4c4c5 26495
c19d1205
ZW
26496 if (opt->name == NULL)
26497 {
69133863
MGD
26498 /* Did we fail to find an extension because it wasn't specified in
26499 alphabetical order, or because it does not exist? */
26500
26501 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26502 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26503 break;
26504
26505 if (opt->name == NULL)
26506 as_bad (_("unknown architectural extension `%s'"), str);
26507 else
26508 as_bad (_("architectural extensions must be specified in "
26509 "alphabetical order"));
26510
c921be7d 26511 return FALSE;
c19d1205 26512 }
69133863
MGD
26513 else
26514 {
26515 /* We should skip the extension we've just matched the next time
26516 round. */
26517 opt++;
26518 }
7ed4c4c5 26519
c19d1205
ZW
26520 str = ext;
26521 };
7ed4c4c5 26522
c921be7d 26523 return TRUE;
c19d1205 26524}
7ed4c4c5 26525
c921be7d 26526static bfd_boolean
17b9d67d 26527arm_parse_cpu (const char *str)
7ed4c4c5 26528{
f3bad469 26529 const struct arm_cpu_option_table *opt;
82b8a785 26530 const char *ext = strchr (str, '+');
f3bad469 26531 size_t len;
7ed4c4c5 26532
c19d1205 26533 if (ext != NULL)
f3bad469 26534 len = ext - str;
7ed4c4c5 26535 else
f3bad469 26536 len = strlen (str);
7ed4c4c5 26537
f3bad469 26538 if (len == 0)
7ed4c4c5 26539 {
c19d1205 26540 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26541 return FALSE;
7ed4c4c5
NC
26542 }
26543
c19d1205 26544 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26545 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26546 {
c168ce07
TP
26547 mcpu_cpu_opt = &opt->value;
26548 if (!dyn_mcpu_ext_opt)
26549 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
26550 *dyn_mcpu_ext_opt = opt->ext;
e74cfd16 26551 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26552 if (opt->canonical_name)
ef8e6722
JW
26553 {
26554 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26555 strcpy (selected_cpu_name, opt->canonical_name);
26556 }
ee065d83
PB
26557 else
26558 {
f3bad469 26559 size_t i;
c921be7d 26560
ef8e6722
JW
26561 if (len >= sizeof selected_cpu_name)
26562 len = (sizeof selected_cpu_name) - 1;
26563
f3bad469 26564 for (i = 0; i < len; i++)
ee065d83
PB
26565 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26566 selected_cpu_name[i] = 0;
26567 }
7ed4c4c5 26568
c19d1205 26569 if (ext != NULL)
c168ce07 26570 return arm_parse_extension (ext, mcpu_cpu_opt, &dyn_mcpu_ext_opt);
7ed4c4c5 26571
c921be7d 26572 return TRUE;
c19d1205 26573 }
7ed4c4c5 26574
c19d1205 26575 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26576 return FALSE;
7ed4c4c5
NC
26577}
26578
c921be7d 26579static bfd_boolean
17b9d67d 26580arm_parse_arch (const char *str)
7ed4c4c5 26581{
e74cfd16 26582 const struct arm_arch_option_table *opt;
82b8a785 26583 const char *ext = strchr (str, '+');
f3bad469 26584 size_t len;
7ed4c4c5 26585
c19d1205 26586 if (ext != NULL)
f3bad469 26587 len = ext - str;
7ed4c4c5 26588 else
f3bad469 26589 len = strlen (str);
7ed4c4c5 26590
f3bad469 26591 if (len == 0)
7ed4c4c5 26592 {
c19d1205 26593 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26594 return FALSE;
7ed4c4c5
NC
26595 }
26596
c19d1205 26597 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26598 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26599 {
e74cfd16
PB
26600 march_cpu_opt = &opt->value;
26601 march_fpu_opt = &opt->default_fpu;
5f4273c7 26602 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26603
c19d1205 26604 if (ext != NULL)
c168ce07 26605 return arm_parse_extension (ext, march_cpu_opt, &dyn_march_ext_opt);
7ed4c4c5 26606
c921be7d 26607 return TRUE;
c19d1205
ZW
26608 }
26609
26610 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26611 return FALSE;
7ed4c4c5 26612}
eb043451 26613
c921be7d 26614static bfd_boolean
17b9d67d 26615arm_parse_fpu (const char * str)
c19d1205 26616{
69133863 26617 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26618
c19d1205
ZW
26619 for (opt = arm_fpus; opt->name != NULL; opt++)
26620 if (streq (opt->name, str))
26621 {
e74cfd16 26622 mfpu_opt = &opt->value;
c921be7d 26623 return TRUE;
c19d1205 26624 }
b99bd4ef 26625
c19d1205 26626 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26627 return FALSE;
c19d1205
ZW
26628}
26629
c921be7d 26630static bfd_boolean
17b9d67d 26631arm_parse_float_abi (const char * str)
b99bd4ef 26632{
e74cfd16 26633 const struct arm_option_value_table * opt;
b99bd4ef 26634
c19d1205
ZW
26635 for (opt = arm_float_abis; opt->name != NULL; opt++)
26636 if (streq (opt->name, str))
26637 {
26638 mfloat_abi_opt = opt->value;
c921be7d 26639 return TRUE;
c19d1205 26640 }
cc8a6dd0 26641
c19d1205 26642 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26643 return FALSE;
c19d1205 26644}
b99bd4ef 26645
c19d1205 26646#ifdef OBJ_ELF
c921be7d 26647static bfd_boolean
17b9d67d 26648arm_parse_eabi (const char * str)
c19d1205 26649{
e74cfd16 26650 const struct arm_option_value_table *opt;
cc8a6dd0 26651
c19d1205
ZW
26652 for (opt = arm_eabis; opt->name != NULL; opt++)
26653 if (streq (opt->name, str))
26654 {
26655 meabi_flags = opt->value;
c921be7d 26656 return TRUE;
c19d1205
ZW
26657 }
26658 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26659 return FALSE;
c19d1205
ZW
26660}
26661#endif
cc8a6dd0 26662
c921be7d 26663static bfd_boolean
17b9d67d 26664arm_parse_it_mode (const char * str)
e07e6e58 26665{
c921be7d 26666 bfd_boolean ret = TRUE;
e07e6e58
NC
26667
26668 if (streq ("arm", str))
26669 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26670 else if (streq ("thumb", str))
26671 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26672 else if (streq ("always", str))
26673 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26674 else if (streq ("never", str))
26675 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26676 else
26677 {
26678 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26679 "arm, thumb, always, or never."), str);
c921be7d 26680 ret = FALSE;
e07e6e58
NC
26681 }
26682
26683 return ret;
26684}
26685
2e6976a8 26686static bfd_boolean
17b9d67d 26687arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26688{
26689 codecomposer_syntax = TRUE;
26690 arm_comment_chars[0] = ';';
26691 arm_line_separator_chars[0] = 0;
26692 return TRUE;
26693}
26694
c19d1205
ZW
26695struct arm_long_option_table arm_long_opts[] =
26696{
26697 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26698 arm_parse_cpu, NULL},
26699 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26700 arm_parse_arch, NULL},
26701 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26702 arm_parse_fpu, NULL},
26703 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26704 arm_parse_float_abi, NULL},
26705#ifdef OBJ_ELF
7fac0536 26706 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26707 arm_parse_eabi, NULL},
26708#endif
e07e6e58
NC
26709 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26710 arm_parse_it_mode, NULL},
2e6976a8
DG
26711 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26712 arm_ccs_mode, NULL},
c19d1205
ZW
26713 {NULL, NULL, 0, NULL}
26714};
cc8a6dd0 26715
c19d1205 26716int
17b9d67d 26717md_parse_option (int c, const char * arg)
c19d1205
ZW
26718{
26719 struct arm_option_table *opt;
e74cfd16 26720 const struct arm_legacy_option_table *fopt;
c19d1205 26721 struct arm_long_option_table *lopt;
b99bd4ef 26722
c19d1205 26723 switch (c)
b99bd4ef 26724 {
c19d1205
ZW
26725#ifdef OPTION_EB
26726 case OPTION_EB:
26727 target_big_endian = 1;
26728 break;
26729#endif
cc8a6dd0 26730
c19d1205
ZW
26731#ifdef OPTION_EL
26732 case OPTION_EL:
26733 target_big_endian = 0;
26734 break;
26735#endif
b99bd4ef 26736
845b51d6
PB
26737 case OPTION_FIX_V4BX:
26738 fix_v4bx = TRUE;
26739 break;
26740
c19d1205
ZW
26741 case 'a':
26742 /* Listing option. Just ignore these, we don't support additional
26743 ones. */
26744 return 0;
b99bd4ef 26745
c19d1205
ZW
26746 default:
26747 for (opt = arm_opts; opt->option != NULL; opt++)
26748 {
26749 if (c == opt->option[0]
26750 && ((arg == NULL && opt->option[1] == 0)
26751 || streq (arg, opt->option + 1)))
26752 {
c19d1205 26753 /* If the option is deprecated, tell the user. */
278df34e 26754 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26755 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26756 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26757
c19d1205
ZW
26758 if (opt->var != NULL)
26759 *opt->var = opt->value;
cc8a6dd0 26760
c19d1205
ZW
26761 return 1;
26762 }
26763 }
b99bd4ef 26764
e74cfd16
PB
26765 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26766 {
26767 if (c == fopt->option[0]
26768 && ((arg == NULL && fopt->option[1] == 0)
26769 || streq (arg, fopt->option + 1)))
26770 {
e74cfd16 26771 /* If the option is deprecated, tell the user. */
278df34e 26772 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26773 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26774 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26775
26776 if (fopt->var != NULL)
26777 *fopt->var = &fopt->value;
26778
26779 return 1;
26780 }
26781 }
26782
c19d1205
ZW
26783 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26784 {
26785 /* These options are expected to have an argument. */
26786 if (c == lopt->option[0]
26787 && arg != NULL
26788 && strncmp (arg, lopt->option + 1,
26789 strlen (lopt->option + 1)) == 0)
26790 {
c19d1205 26791 /* If the option is deprecated, tell the user. */
278df34e 26792 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26793 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26794 _(lopt->deprecated));
b99bd4ef 26795
c19d1205
ZW
26796 /* Call the sup-option parser. */
26797 return lopt->func (arg + strlen (lopt->option) - 1);
26798 }
26799 }
a737bd4d 26800
c19d1205
ZW
26801 return 0;
26802 }
a394c00f 26803
c19d1205
ZW
26804 return 1;
26805}
a394c00f 26806
c19d1205
ZW
26807void
26808md_show_usage (FILE * fp)
a394c00f 26809{
c19d1205
ZW
26810 struct arm_option_table *opt;
26811 struct arm_long_option_table *lopt;
a394c00f 26812
c19d1205 26813 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26814
c19d1205
ZW
26815 for (opt = arm_opts; opt->option != NULL; opt++)
26816 if (opt->help != NULL)
26817 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26818
c19d1205
ZW
26819 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26820 if (lopt->help != NULL)
26821 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26822
c19d1205
ZW
26823#ifdef OPTION_EB
26824 fprintf (fp, _("\
26825 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26826#endif
26827
c19d1205
ZW
26828#ifdef OPTION_EL
26829 fprintf (fp, _("\
26830 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26831#endif
845b51d6
PB
26832
26833 fprintf (fp, _("\
26834 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26835}
ee065d83 26836
ee065d83 26837#ifdef OBJ_ELF
0198d5e6 26838
62b3e311
PB
26839typedef struct
26840{
26841 int val;
26842 arm_feature_set flags;
26843} cpu_arch_ver_table;
26844
2c6b98ea
TP
26845/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26846 chronologically for architectures, with an exception for ARMv6-M and
26847 ARMv6S-M due to legacy reasons. No new architecture should have a
26848 special case. This allows for build attribute selection results to be
26849 stable when new architectures are added. */
62b3e311
PB
26850static const cpu_arch_ver_table cpu_arch_ver[] =
26851{
2c6b98ea
TP
26852 {0, ARM_ARCH_V1},
26853 {0, ARM_ARCH_V2},
26854 {0, ARM_ARCH_V2S},
26855 {0, ARM_ARCH_V3},
26856 {0, ARM_ARCH_V3M},
26857 {1, ARM_ARCH_V4xM},
62b3e311 26858 {1, ARM_ARCH_V4},
2c6b98ea 26859 {2, ARM_ARCH_V4TxM},
62b3e311 26860 {2, ARM_ARCH_V4T},
2c6b98ea 26861 {3, ARM_ARCH_V5xM},
62b3e311 26862 {3, ARM_ARCH_V5},
2c6b98ea 26863 {3, ARM_ARCH_V5TxM},
ee3c0378 26864 {3, ARM_ARCH_V5T},
2c6b98ea 26865 {4, ARM_ARCH_V5TExP},
62b3e311
PB
26866 {4, ARM_ARCH_V5TE},
26867 {5, ARM_ARCH_V5TEJ},
26868 {6, ARM_ARCH_V6},
f4c65163 26869 {7, ARM_ARCH_V6Z},
2c6b98ea
TP
26870 {7, ARM_ARCH_V6KZ},
26871 {9, ARM_ARCH_V6K},
26872 {8, ARM_ARCH_V6T2},
26873 {8, ARM_ARCH_V6KT2},
26874 {8, ARM_ARCH_V6ZT2},
26875 {8, ARM_ARCH_V6KZT2},
26876
26877 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
26878 always selected build attributes to match those of ARMv6-M
26879 (resp. ARMv6S-M). However, due to these architectures being a strict
26880 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
26881 would be selected when fully respecting chronology of architectures.
26882 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
26883 move them before ARMv7 architectures. */
91e22acd 26884 {11, ARM_ARCH_V6M},
b2a5fbdc 26885 {12, ARM_ARCH_V6SM},
2c6b98ea
TP
26886
26887 {10, ARM_ARCH_V7},
26888 {10, ARM_ARCH_V7A},
62b3e311
PB
26889 {10, ARM_ARCH_V7R},
26890 {10, ARM_ARCH_V7M},
2c6b98ea
TP
26891 {10, ARM_ARCH_V7VE},
26892 {13, ARM_ARCH_V7EM},
bca38921 26893 {14, ARM_ARCH_V8A},
2c6b98ea
TP
26894 {14, ARM_ARCH_V8_1A},
26895 {14, ARM_ARCH_V8_2A},
26896 {14, ARM_ARCH_V8_3A},
ff8646ee 26897 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26898 {17, ARM_ARCH_V8M_MAIN},
ced40572 26899 {15, ARM_ARCH_V8R},
dec41383 26900 {16, ARM_ARCH_V8_4A},
2c6b98ea 26901 {-1, ARM_ARCH_NONE}
62b3e311
PB
26902};
26903
ee3c0378 26904/* Set an attribute if it has not already been set by the user. */
0198d5e6 26905
ee3c0378
AS
26906static void
26907aeabi_set_attribute_int (int tag, int value)
26908{
26909 if (tag < 1
26910 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26911 || !attributes_set_explicitly[tag])
26912 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26913}
26914
26915static void
26916aeabi_set_attribute_string (int tag, const char *value)
26917{
26918 if (tag < 1
26919 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26920 || !attributes_set_explicitly[tag])
26921 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26922}
26923
2c6b98ea
TP
26924/* Return whether features in the *NEEDED feature set are available via
26925 extensions for the architecture whose feature set is *ARCH_FSET. */
0198d5e6 26926
2c6b98ea
TP
26927static bfd_boolean
26928have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
26929 const arm_feature_set *needed)
26930{
26931 int i, nb_allowed_archs;
26932 arm_feature_set ext_fset;
26933 const struct arm_option_extension_value_table *opt;
26934
26935 ext_fset = arm_arch_none;
26936 for (opt = arm_extensions; opt->name != NULL; opt++)
26937 {
26938 /* Extension does not provide any feature we need. */
26939 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
26940 continue;
26941
26942 nb_allowed_archs =
26943 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
26944 for (i = 0; i < nb_allowed_archs; i++)
26945 {
26946 /* Empty entry. */
26947 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
26948 break;
26949
26950 /* Extension is available, add it. */
26951 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
26952 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
26953 }
26954 }
26955
26956 /* Can we enable all features in *needed? */
26957 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
26958}
26959
26960/* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
26961 a given architecture feature set *ARCH_EXT_FSET including extension feature
26962 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
26963 - if true, check for an exact match of the architecture modulo extensions;
26964 - otherwise, select build attribute value of the first superset
26965 architecture released so that results remains stable when new architectures
26966 are added.
26967 For -march/-mcpu=all the build attribute value of the most featureful
26968 architecture is returned. Tag_CPU_arch_profile result is returned in
26969 PROFILE. */
0198d5e6 26970
2c6b98ea
TP
26971static int
26972get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
26973 const arm_feature_set *ext_fset,
26974 char *profile, int exact_match)
26975{
26976 arm_feature_set arch_fset;
26977 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
26978
26979 /* Select most featureful architecture with all its extensions if building
26980 for -march=all as the feature sets used to set build attributes. */
26981 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
26982 {
26983 /* Force revisiting of decision for each new architecture. */
26984 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
26985 *profile = 'A';
26986 return TAG_CPU_ARCH_V8;
26987 }
26988
26989 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
26990
26991 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
26992 {
26993 arm_feature_set known_arch_fset;
26994
26995 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
26996 if (exact_match)
26997 {
26998 /* Base architecture match user-specified architecture and
26999 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27000 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27001 {
27002 p_ver_ret = p_ver;
27003 goto found;
27004 }
27005 /* Base architecture match user-specified architecture only
27006 (eg. ARMv6-M in the same case as above). Record it in case we
27007 find a match with above condition. */
27008 else if (p_ver_ret == NULL
27009 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27010 p_ver_ret = p_ver;
27011 }
27012 else
27013 {
27014
27015 /* Architecture has all features wanted. */
27016 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27017 {
27018 arm_feature_set added_fset;
27019
27020 /* Compute features added by this architecture over the one
27021 recorded in p_ver_ret. */
27022 if (p_ver_ret != NULL)
27023 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27024 p_ver_ret->flags);
27025 /* First architecture that match incl. with extensions, or the
27026 only difference in features over the recorded match is
27027 features that were optional and are now mandatory. */
27028 if (p_ver_ret == NULL
27029 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27030 {
27031 p_ver_ret = p_ver;
27032 goto found;
27033 }
27034 }
27035 else if (p_ver_ret == NULL)
27036 {
27037 arm_feature_set needed_ext_fset;
27038
27039 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27040
27041 /* Architecture has all features needed when using some
27042 extensions. Record it and continue searching in case there
27043 exist an architecture providing all needed features without
27044 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27045 OS extension). */
27046 if (have_ext_for_needed_feat_p (&known_arch_fset,
27047 &needed_ext_fset))
27048 p_ver_ret = p_ver;
27049 }
27050 }
27051 }
27052
27053 if (p_ver_ret == NULL)
27054 return -1;
27055
27056found:
27057 /* Tag_CPU_arch_profile. */
27058 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27059 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27060 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27061 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27062 *profile = 'A';
27063 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27064 *profile = 'R';
27065 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27066 *profile = 'M';
27067 else
27068 *profile = '\0';
27069 return p_ver_ret->val;
27070}
27071
ee065d83 27072/* Set the public EABI object attributes. */
0198d5e6 27073
c168ce07 27074static void
ee065d83
PB
27075aeabi_set_public_attributes (void)
27076{
69239280 27077 char profile;
2c6b98ea 27078 int arch = -1;
90ec0d68 27079 int virt_sec = 0;
bca38921 27080 int fp16_optional = 0;
2c6b98ea
TP
27081 int skip_exact_match = 0;
27082 arm_feature_set flags, flags_arch, flags_ext;
ee065d83 27083
54bab281
TP
27084 /* Autodetection mode, choose the architecture based the instructions
27085 actually used. */
27086 if (no_cpu_selected ())
27087 {
27088 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
ddd7f988 27089
54bab281
TP
27090 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27091 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
ddd7f988 27092
54bab281
TP
27093 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27094 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
ddd7f988 27095
54bab281
TP
27096 /* Code run during relaxation relies on selected_cpu being set. */
27097 selected_cpu = flags;
27098 }
27099 /* Otherwise, choose the architecture based on the capabilities of the
27100 requested cpu. */
27101 else
27102 flags = selected_cpu;
27103 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
7f78eb34 27104
ddd7f988 27105 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
27106 if (object_arch)
27107 {
2c6b98ea
TP
27108 ARM_CLEAR_FEATURE (flags_arch, *object_arch, fpu_any);
27109 flags_ext = arm_arch_none;
7a1d4c38 27110 }
2c6b98ea 27111 else
62b3e311 27112 {
2c6b98ea
TP
27113 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27114 flags_ext = dyn_mcpu_ext_opt ? *dyn_mcpu_ext_opt : arm_arch_none;
27115 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
27116 }
27117
27118 /* When this function is run again after relaxation has happened there is no
27119 way to determine whether an architecture or CPU was specified by the user:
27120 - selected_cpu is set above for relaxation to work;
27121 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27122 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27123 Therefore, if not in -march=all case we first try an exact match and fall
27124 back to autodetection. */
27125 if (!skip_exact_match)
27126 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27127 if (arch == -1)
27128 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27129 if (arch == -1)
27130 as_bad (_("no architecture contains all the instructions used\n"));
9e3c6df6 27131
ee065d83
PB
27132 /* Tag_CPU_name. */
27133 if (selected_cpu_name[0])
27134 {
91d6fa6a 27135 char *q;
ee065d83 27136
91d6fa6a
NC
27137 q = selected_cpu_name;
27138 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
27139 {
27140 int i;
5f4273c7 27141
91d6fa6a
NC
27142 q += 4;
27143 for (i = 0; q[i]; i++)
27144 q[i] = TOUPPER (q[i]);
ee065d83 27145 }
91d6fa6a 27146 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 27147 }
62f3b8c8 27148
ee065d83 27149 /* Tag_CPU_arch. */
ee3c0378 27150 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 27151
62b3e311 27152 /* Tag_CPU_arch_profile. */
69239280
MGD
27153 if (profile != '\0')
27154 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 27155
15afaa63 27156 /* Tag_DSP_extension. */
6c290d53
TP
27157 if (dyn_mcpu_ext_opt && ARM_CPU_HAS_FEATURE (*dyn_mcpu_ext_opt, arm_ext_dsp))
27158 aeabi_set_attribute_int (Tag_DSP_extension, 1);
15afaa63 27159
2c6b98ea 27160 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
ee065d83 27161 /* Tag_ARM_ISA_use. */
ee3c0378 27162 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
2c6b98ea 27163 || ARM_FEATURE_ZERO (flags_arch))
ee3c0378 27164 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 27165
ee065d83 27166 /* Tag_THUMB_ISA_use. */
ee3c0378 27167 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
2c6b98ea 27168 || ARM_FEATURE_ZERO (flags_arch))
4ed7ed8d
TP
27169 {
27170 int thumb_isa_use;
27171
27172 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 27173 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
27174 thumb_isa_use = 3;
27175 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27176 thumb_isa_use = 2;
27177 else
27178 thumb_isa_use = 1;
27179 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27180 }
62f3b8c8 27181
ee065d83 27182 /* Tag_VFP_arch. */
a715796b
TG
27183 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27184 aeabi_set_attribute_int (Tag_VFP_arch,
27185 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27186 ? 7 : 8);
bca38921 27187 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
27188 aeabi_set_attribute_int (Tag_VFP_arch,
27189 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27190 ? 5 : 6);
27191 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
27192 {
27193 fp16_optional = 1;
27194 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27195 }
ada65aa3 27196 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
27197 {
27198 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27199 fp16_optional = 1;
27200 }
ee3c0378
AS
27201 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27202 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27203 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 27204 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 27205 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 27206
4547cb56
NC
27207 /* Tag_ABI_HardFP_use. */
27208 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27209 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27210 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27211
ee065d83 27212 /* Tag_WMMX_arch. */
ee3c0378
AS
27213 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27214 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27215 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27216 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 27217
ee3c0378 27218 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
27219 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27220 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27221 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
27222 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27223 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27224 {
27225 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27226 {
27227 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27228 }
27229 else
27230 {
27231 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27232 fp16_optional = 1;
27233 }
27234 }
fa94de6b 27235
ee3c0378 27236 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 27237 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 27238 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 27239
69239280
MGD
27240 /* Tag_DIV_use.
27241
27242 We set Tag_DIV_use to two when integer divide instructions have been used
27243 in ARM state, or when Thumb integer divide instructions have been used,
27244 but we have no architecture profile set, nor have we any ARM instructions.
27245
4ed7ed8d
TP
27246 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27247 by the base architecture.
bca38921 27248
69239280 27249 For new architectures we will have to check these tests. */
ced40572 27250 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
4ed7ed8d
TP
27251 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27252 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
27253 aeabi_set_attribute_int (Tag_DIV_use, 0);
27254 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27255 || (profile == '\0'
27256 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27257 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 27258 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
27259
27260 /* Tag_MP_extension_use. */
27261 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27262 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
27263
27264 /* Tag Virtualization_use. */
27265 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
27266 virt_sec |= 1;
27267 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27268 virt_sec |= 2;
27269 if (virt_sec != 0)
27270 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
27271}
27272
c168ce07
TP
27273/* Post relaxation hook. Recompute ARM attributes now that relaxation is
27274 finished and free extension feature bits which will not be used anymore. */
0198d5e6 27275
c168ce07
TP
27276void
27277arm_md_post_relax (void)
27278{
27279 aeabi_set_public_attributes ();
27280 XDELETE (dyn_mcpu_ext_opt);
27281 dyn_mcpu_ext_opt = NULL;
27282 XDELETE (dyn_march_ext_opt);
27283 dyn_march_ext_opt = NULL;
27284}
27285
104d59d1 27286/* Add the default contents for the .ARM.attributes section. */
0198d5e6 27287
ee065d83
PB
27288void
27289arm_md_end (void)
27290{
ee065d83
PB
27291 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27292 return;
27293
27294 aeabi_set_public_attributes ();
ee065d83 27295}
8463be01 27296#endif /* OBJ_ELF */
ee065d83 27297
ee065d83
PB
27298/* Parse a .cpu directive. */
27299
27300static void
27301s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27302{
e74cfd16 27303 const struct arm_cpu_option_table *opt;
ee065d83
PB
27304 char *name;
27305 char saved_char;
27306
27307 name = input_line_pointer;
5f4273c7 27308 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27309 input_line_pointer++;
27310 saved_char = *input_line_pointer;
27311 *input_line_pointer = 0;
27312
27313 /* Skip the first "all" entry. */
27314 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27315 if (streq (opt->name, name))
27316 {
c168ce07
TP
27317 mcpu_cpu_opt = &opt->value;
27318 if (!dyn_mcpu_ext_opt)
27319 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27320 *dyn_mcpu_ext_opt = opt->ext;
27321 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
ee065d83 27322 if (opt->canonical_name)
5f4273c7 27323 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
27324 else
27325 {
27326 int i;
27327 for (i = 0; opt->name[i]; i++)
27328 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 27329
ee065d83
PB
27330 selected_cpu_name[i] = 0;
27331 }
e74cfd16 27332 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27333 if (dyn_mcpu_ext_opt)
27334 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27335 *input_line_pointer = saved_char;
27336 demand_empty_rest_of_line ();
27337 return;
27338 }
27339 as_bad (_("unknown cpu `%s'"), name);
27340 *input_line_pointer = saved_char;
27341 ignore_rest_of_line ();
27342}
27343
ee065d83
PB
27344/* Parse a .arch directive. */
27345
27346static void
27347s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27348{
e74cfd16 27349 const struct arm_arch_option_table *opt;
ee065d83
PB
27350 char saved_char;
27351 char *name;
27352
27353 name = input_line_pointer;
5f4273c7 27354 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27355 input_line_pointer++;
27356 saved_char = *input_line_pointer;
27357 *input_line_pointer = 0;
27358
27359 /* Skip the first "all" entry. */
27360 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27361 if (streq (opt->name, name))
27362 {
e74cfd16 27363 mcpu_cpu_opt = &opt->value;
c168ce07
TP
27364 XDELETE (dyn_mcpu_ext_opt);
27365 dyn_mcpu_ext_opt = NULL;
27366 selected_cpu = *mcpu_cpu_opt;
5f4273c7 27367 strcpy (selected_cpu_name, opt->name);
c168ce07 27368 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
ee065d83
PB
27369 *input_line_pointer = saved_char;
27370 demand_empty_rest_of_line ();
27371 return;
27372 }
27373
27374 as_bad (_("unknown architecture `%s'\n"), name);
27375 *input_line_pointer = saved_char;
27376 ignore_rest_of_line ();
27377}
27378
7a1d4c38
PB
27379/* Parse a .object_arch directive. */
27380
27381static void
27382s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27383{
27384 const struct arm_arch_option_table *opt;
27385 char saved_char;
27386 char *name;
27387
27388 name = input_line_pointer;
5f4273c7 27389 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
27390 input_line_pointer++;
27391 saved_char = *input_line_pointer;
27392 *input_line_pointer = 0;
27393
27394 /* Skip the first "all" entry. */
27395 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27396 if (streq (opt->name, name))
27397 {
27398 object_arch = &opt->value;
27399 *input_line_pointer = saved_char;
27400 demand_empty_rest_of_line ();
27401 return;
27402 }
27403
27404 as_bad (_("unknown architecture `%s'\n"), name);
27405 *input_line_pointer = saved_char;
27406 ignore_rest_of_line ();
27407}
27408
69133863
MGD
27409/* Parse a .arch_extension directive. */
27410
27411static void
27412s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27413{
27414 const struct arm_option_extension_value_table *opt;
d942732e 27415 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
27416 char saved_char;
27417 char *name;
27418 int adding_value = 1;
27419
27420 name = input_line_pointer;
27421 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27422 input_line_pointer++;
27423 saved_char = *input_line_pointer;
27424 *input_line_pointer = 0;
27425
27426 if (strlen (name) >= 2
27427 && strncmp (name, "no", 2) == 0)
27428 {
27429 adding_value = 0;
27430 name += 2;
27431 }
27432
27433 for (opt = arm_extensions; opt->name != NULL; opt++)
27434 if (streq (opt->name, name))
27435 {
d942732e
TP
27436 int i, nb_allowed_archs =
27437 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27438 for (i = 0; i < nb_allowed_archs; i++)
27439 {
27440 /* Empty entry. */
27441 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27442 continue;
27443 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
27444 break;
27445 }
27446
27447 if (i == nb_allowed_archs)
69133863
MGD
27448 {
27449 as_bad (_("architectural extension `%s' is not allowed for the "
27450 "current base architecture"), name);
27451 break;
27452 }
27453
c168ce07
TP
27454 if (!dyn_mcpu_ext_opt)
27455 {
27456 dyn_mcpu_ext_opt = XNEW (arm_feature_set);
27457 *dyn_mcpu_ext_opt = arm_arch_none;
27458 }
69133863 27459 if (adding_value)
c168ce07 27460 ARM_MERGE_FEATURE_SETS (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
5a70a223 27461 opt->merge_value);
69133863 27462 else
c168ce07
TP
27463 ARM_CLEAR_FEATURE (*dyn_mcpu_ext_opt, *dyn_mcpu_ext_opt,
27464 opt->clear_value);
69133863 27465
c168ce07
TP
27466 ARM_MERGE_FEATURE_SETS (selected_cpu, *mcpu_cpu_opt, *dyn_mcpu_ext_opt);
27467 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, *mfpu_opt);
69133863
MGD
27468 *input_line_pointer = saved_char;
27469 demand_empty_rest_of_line ();
3d030cdb
TP
27470 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27471 on this return so that duplicate extensions (extensions with the
27472 same name as a previous extension in the list) are not considered
27473 for command-line parsing. */
69133863
MGD
27474 return;
27475 }
27476
27477 if (opt->name == NULL)
e673710a 27478 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27479
27480 *input_line_pointer = saved_char;
27481 ignore_rest_of_line ();
27482}
27483
ee065d83
PB
27484/* Parse a .fpu directive. */
27485
27486static void
27487s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27488{
69133863 27489 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27490 char saved_char;
27491 char *name;
27492
27493 name = input_line_pointer;
5f4273c7 27494 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27495 input_line_pointer++;
27496 saved_char = *input_line_pointer;
27497 *input_line_pointer = 0;
5f4273c7 27498
ee065d83
PB
27499 for (opt = arm_fpus; opt->name != NULL; opt++)
27500 if (streq (opt->name, name))
27501 {
e74cfd16
PB
27502 mfpu_opt = &opt->value;
27503 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
c168ce07
TP
27504 if (dyn_mcpu_ext_opt)
27505 ARM_MERGE_FEATURE_SETS (cpu_variant, cpu_variant, *dyn_mcpu_ext_opt);
ee065d83
PB
27506 *input_line_pointer = saved_char;
27507 demand_empty_rest_of_line ();
27508 return;
27509 }
27510
27511 as_bad (_("unknown floating point format `%s'\n"), name);
27512 *input_line_pointer = saved_char;
27513 ignore_rest_of_line ();
27514}
ee065d83 27515
794ba86a 27516/* Copy symbol information. */
f31fef98 27517
794ba86a
DJ
27518void
27519arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27520{
27521 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27522}
e04befd0 27523
f31fef98 27524#ifdef OBJ_ELF
e04befd0
AS
27525/* Given a symbolic attribute NAME, return the proper integer value.
27526 Returns -1 if the attribute is not known. */
f31fef98 27527
e04befd0
AS
27528int
27529arm_convert_symbolic_attribute (const char *name)
27530{
f31fef98
NC
27531 static const struct
27532 {
27533 const char * name;
27534 const int tag;
27535 }
27536 attribute_table[] =
27537 {
27538 /* When you modify this table you should
27539 also modify the list in doc/c-arm.texi. */
e04befd0 27540#define T(tag) {#tag, tag}
f31fef98
NC
27541 T (Tag_CPU_raw_name),
27542 T (Tag_CPU_name),
27543 T (Tag_CPU_arch),
27544 T (Tag_CPU_arch_profile),
27545 T (Tag_ARM_ISA_use),
27546 T (Tag_THUMB_ISA_use),
75375b3e 27547 T (Tag_FP_arch),
f31fef98
NC
27548 T (Tag_VFP_arch),
27549 T (Tag_WMMX_arch),
27550 T (Tag_Advanced_SIMD_arch),
27551 T (Tag_PCS_config),
27552 T (Tag_ABI_PCS_R9_use),
27553 T (Tag_ABI_PCS_RW_data),
27554 T (Tag_ABI_PCS_RO_data),
27555 T (Tag_ABI_PCS_GOT_use),
27556 T (Tag_ABI_PCS_wchar_t),
27557 T (Tag_ABI_FP_rounding),
27558 T (Tag_ABI_FP_denormal),
27559 T (Tag_ABI_FP_exceptions),
27560 T (Tag_ABI_FP_user_exceptions),
27561 T (Tag_ABI_FP_number_model),
75375b3e 27562 T (Tag_ABI_align_needed),
f31fef98 27563 T (Tag_ABI_align8_needed),
75375b3e 27564 T (Tag_ABI_align_preserved),
f31fef98
NC
27565 T (Tag_ABI_align8_preserved),
27566 T (Tag_ABI_enum_size),
27567 T (Tag_ABI_HardFP_use),
27568 T (Tag_ABI_VFP_args),
27569 T (Tag_ABI_WMMX_args),
27570 T (Tag_ABI_optimization_goals),
27571 T (Tag_ABI_FP_optimization_goals),
27572 T (Tag_compatibility),
27573 T (Tag_CPU_unaligned_access),
75375b3e 27574 T (Tag_FP_HP_extension),
f31fef98
NC
27575 T (Tag_VFP_HP_extension),
27576 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27577 T (Tag_MPextension_use),
27578 T (Tag_DIV_use),
f31fef98
NC
27579 T (Tag_nodefaults),
27580 T (Tag_also_compatible_with),
27581 T (Tag_conformance),
27582 T (Tag_T2EE_use),
27583 T (Tag_Virtualization_use),
15afaa63 27584 T (Tag_DSP_extension),
cd21e546 27585 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27586#undef T
f31fef98 27587 };
e04befd0
AS
27588 unsigned int i;
27589
27590 if (name == NULL)
27591 return -1;
27592
f31fef98 27593 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27594 if (streq (name, attribute_table[i].name))
e04befd0
AS
27595 return attribute_table[i].tag;
27596
27597 return -1;
27598}
267bf995 27599
93ef582d
NC
27600/* Apply sym value for relocations only in the case that they are for
27601 local symbols in the same segment as the fixup and you have the
27602 respective architectural feature for blx and simple switches. */
0198d5e6 27603
267bf995 27604int
93ef582d 27605arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27606{
27607 if (fixP->fx_addsy
27608 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27609 /* PR 17444: If the local symbol is in a different section then a reloc
27610 will always be generated for it, so applying the symbol value now
27611 will result in a double offset being stored in the relocation. */
27612 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27613 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27614 {
27615 switch (fixP->fx_r_type)
27616 {
27617 case BFD_RELOC_ARM_PCREL_BLX:
27618 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27619 if (ARM_IS_FUNC (fixP->fx_addsy))
27620 return 1;
27621 break;
27622
27623 case BFD_RELOC_ARM_PCREL_CALL:
27624 case BFD_RELOC_THUMB_PCREL_BLX:
27625 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27626 return 1;
267bf995
RR
27627 break;
27628
27629 default:
27630 break;
27631 }
27632
27633 }
27634 return 0;
27635}
f31fef98 27636#endif /* OBJ_ELF */