]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Initialize variables in i386_linux_handle_segmentation_fault
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
6f2750fe 2 Copyright (C) 1994-2016 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
823d2571
TG
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 179static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
180 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
188static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
189static const arm_feature_set arm_ext_v6_notm =
190 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
191static const arm_feature_set arm_ext_v6_dsp =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
193static const arm_feature_set arm_ext_barrier =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
195static const arm_feature_set arm_ext_msr =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
197static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
198static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
199static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
200static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
201static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
202static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 203static const arm_feature_set arm_ext_m =
4ed7ed8d 204 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, ARM_EXT2_V8M);
823d2571
TG
205static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
206static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
207static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
208static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
209static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 210static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 211static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
ff8646ee
TP
212static const arm_feature_set arm_ext_v6t2_v8m =
213 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
214/* Instructions shared between ARMv8-A and ARMv8-M. */
215static const arm_feature_set arm_ext_atomics =
216 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
105bde57
MW
217static const arm_feature_set arm_ext_v8_2 =
218 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
b8ec4e87
JW
219/* FP16 instructions. */
220static const arm_feature_set arm_ext_fp16 =
221 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
e74cfd16
PB
222
223static const arm_feature_set arm_arch_any = ARM_ANY;
823d2571 224static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
225static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
226static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 227static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 228
2d447fca 229static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 230 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 231static const arm_feature_set arm_cext_iwmmxt =
823d2571 232 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 233static const arm_feature_set arm_cext_xscale =
823d2571 234 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 235static const arm_feature_set arm_cext_maverick =
823d2571
TG
236 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
237static const arm_feature_set fpu_fpa_ext_v1 =
238 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
239static const arm_feature_set fpu_fpa_ext_v2 =
240 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 241static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
242 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
243static const arm_feature_set fpu_vfp_ext_v1 =
244 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
245static const arm_feature_set fpu_vfp_ext_v2 =
246 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
247static const arm_feature_set fpu_vfp_ext_v3xd =
248 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
249static const arm_feature_set fpu_vfp_ext_v3 =
250 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 251static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
252 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
253static const arm_feature_set fpu_neon_ext_v1 =
254 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 255static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571
TG
256 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
257static const arm_feature_set fpu_vfp_fp16 =
258 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
259static const arm_feature_set fpu_neon_ext_fma =
260 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
261static const arm_feature_set fpu_vfp_ext_fma =
262 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 263static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 264 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 265static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 266 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 267static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 268 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 269static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 270 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 271static const arm_feature_set crc_ext_armv8 =
823d2571 272 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e
MW
273static const arm_feature_set fpu_neon_ext_v8_1 =
274 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8 | FPU_NEON_EXT_RDMA);
e74cfd16 275
33a392fb 276static int mfloat_abi_opt = -1;
e74cfd16
PB
277/* Record user cpu selection for object attributes. */
278static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 279/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 280static char selected_cpu_name[20];
8d67f500 281
aacf0b33
KT
282extern FLONUM_TYPE generic_floating_point_number;
283
8d67f500
NC
284/* Return if no cpu was selected on command-line. */
285static bfd_boolean
286no_cpu_selected (void)
287{
823d2571 288 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
289}
290
7cc69913 291#ifdef OBJ_ELF
deeaaff8
DJ
292# ifdef EABI_DEFAULT
293static int meabi_flags = EABI_DEFAULT;
294# else
d507cf36 295static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 296# endif
e1da3f5b 297
ee3c0378
AS
298static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
299
e1da3f5b 300bfd_boolean
5f4273c7 301arm_is_eabi (void)
e1da3f5b
PB
302{
303 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
304}
7cc69913 305#endif
b99bd4ef 306
b99bd4ef 307#ifdef OBJ_ELF
c19d1205 308/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
309symbolS * GOT_symbol;
310#endif
311
b99bd4ef
NC
312/* 0: assemble for ARM,
313 1: assemble for Thumb,
314 2: assemble for Thumb even though target CPU does not support thumb
315 instructions. */
316static int thumb_mode = 0;
8dc2430f
NC
317/* A value distinct from the possible values for thumb_mode that we
318 can use to record whether thumb_mode has been copied into the
319 tc_frag_data field of a frag. */
320#define MODE_RECORDED (1 << 4)
b99bd4ef 321
e07e6e58
NC
322/* Specifies the intrinsic IT insn behavior mode. */
323enum implicit_it_mode
324{
325 IMPLICIT_IT_MODE_NEVER = 0x00,
326 IMPLICIT_IT_MODE_ARM = 0x01,
327 IMPLICIT_IT_MODE_THUMB = 0x02,
328 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
329};
330static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
331
c19d1205
ZW
332/* If unified_syntax is true, we are processing the new unified
333 ARM/Thumb syntax. Important differences from the old ARM mode:
334
335 - Immediate operands do not require a # prefix.
336 - Conditional affixes always appear at the end of the
337 instruction. (For backward compatibility, those instructions
338 that formerly had them in the middle, continue to accept them
339 there.)
340 - The IT instruction may appear, and if it does is validated
341 against subsequent conditional affixes. It does not generate
342 machine code.
343
344 Important differences from the old Thumb mode:
345
346 - Immediate operands do not require a # prefix.
347 - Most of the V6T2 instructions are only available in unified mode.
348 - The .N and .W suffixes are recognized and honored (it is an error
349 if they cannot be honored).
350 - All instructions set the flags if and only if they have an 's' affix.
351 - Conditional affixes may be used. They are validated against
352 preceding IT instructions. Unlike ARM mode, you cannot use a
353 conditional affix except in the scope of an IT instruction. */
354
355static bfd_boolean unified_syntax = FALSE;
b99bd4ef 356
bacebabc
RM
357/* An immediate operand can start with #, and ld*, st*, pld operands
358 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
359 before a [, which can appear as the first operand for pld.
360 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
361const char arm_symbol_chars[] = "#[]{}";
bacebabc 362
5287ad62
JB
363enum neon_el_type
364{
dcbf9037 365 NT_invtype,
5287ad62
JB
366 NT_untyped,
367 NT_integer,
368 NT_float,
369 NT_poly,
370 NT_signed,
dcbf9037 371 NT_unsigned
5287ad62
JB
372};
373
374struct neon_type_el
375{
376 enum neon_el_type type;
377 unsigned size;
378};
379
380#define NEON_MAX_TYPE_ELS 4
381
382struct neon_type
383{
384 struct neon_type_el el[NEON_MAX_TYPE_ELS];
385 unsigned elems;
386};
387
e07e6e58
NC
388enum it_instruction_type
389{
390 OUTSIDE_IT_INSN,
391 INSIDE_IT_INSN,
392 INSIDE_IT_LAST_INSN,
393 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 394 if inside, should be the last one. */
e07e6e58 395 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 396 i.e. BKPT and NOP. */
e07e6e58
NC
397 IT_INSN /* The IT insn has been parsed. */
398};
399
ad6cec43
MGD
400/* The maximum number of operands we need. */
401#define ARM_IT_MAX_OPERANDS 6
402
b99bd4ef
NC
403struct arm_it
404{
c19d1205 405 const char * error;
b99bd4ef 406 unsigned long instruction;
c19d1205
ZW
407 int size;
408 int size_req;
409 int cond;
037e8744
JB
410 /* "uncond_value" is set to the value in place of the conditional field in
411 unconditional versions of the instruction, or -1 if nothing is
412 appropriate. */
413 int uncond_value;
5287ad62 414 struct neon_type vectype;
88714cb8
DG
415 /* This does not indicate an actual NEON instruction, only that
416 the mnemonic accepts neon-style type suffixes. */
417 int is_neon;
0110f2b8
PB
418 /* Set to the opcode if the instruction needs relaxation.
419 Zero if the instruction is not relaxed. */
420 unsigned long relax;
b99bd4ef
NC
421 struct
422 {
423 bfd_reloc_code_real_type type;
c19d1205
ZW
424 expressionS exp;
425 int pc_rel;
b99bd4ef 426 } reloc;
b99bd4ef 427
e07e6e58
NC
428 enum it_instruction_type it_insn_type;
429
c19d1205
ZW
430 struct
431 {
432 unsigned reg;
ca3f61f7 433 signed int imm;
dcbf9037 434 struct neon_type_el vectype;
ca3f61f7
NC
435 unsigned present : 1; /* Operand present. */
436 unsigned isreg : 1; /* Operand was a register. */
437 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
438 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
439 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 440 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
441 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
442 instructions. This allows us to disambiguate ARM <-> vector insns. */
443 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 444 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 445 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 446 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
447 unsigned hasreloc : 1; /* Operand has relocation suffix. */
448 unsigned writeback : 1; /* Operand has trailing ! */
449 unsigned preind : 1; /* Preindexed address. */
450 unsigned postind : 1; /* Postindexed address. */
451 unsigned negative : 1; /* Index register was negated. */
452 unsigned shifted : 1; /* Shift applied to operation. */
453 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 454 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
455};
456
c19d1205 457static struct arm_it inst;
b99bd4ef
NC
458
459#define NUM_FLOAT_VALS 8
460
05d2d07e 461const char * fp_const[] =
b99bd4ef
NC
462{
463 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
464};
465
c19d1205 466/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
467#define MAX_LITTLENUMS 6
468
469LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
470
471#define FAIL (-1)
472#define SUCCESS (0)
473
474#define SUFF_S 1
475#define SUFF_D 2
476#define SUFF_E 3
477#define SUFF_P 4
478
c19d1205
ZW
479#define CP_T_X 0x00008000
480#define CP_T_Y 0x00400000
b99bd4ef 481
c19d1205
ZW
482#define CONDS_BIT 0x00100000
483#define LOAD_BIT 0x00100000
b99bd4ef
NC
484
485#define DOUBLE_LOAD_FLAG 0x00000001
486
487struct asm_cond
488{
d3ce72d0 489 const char * template_name;
c921be7d 490 unsigned long value;
b99bd4ef
NC
491};
492
c19d1205 493#define COND_ALWAYS 0xE
b99bd4ef 494
b99bd4ef
NC
495struct asm_psr
496{
d3ce72d0 497 const char * template_name;
c921be7d 498 unsigned long field;
b99bd4ef
NC
499};
500
62b3e311
PB
501struct asm_barrier_opt
502{
e797f7e0
MGD
503 const char * template_name;
504 unsigned long value;
505 const arm_feature_set arch;
62b3e311
PB
506};
507
2d2255b5 508/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
509#define SPSR_BIT (1 << 22)
510
c19d1205
ZW
511/* The individual PSR flag bits. */
512#define PSR_c (1 << 16)
513#define PSR_x (1 << 17)
514#define PSR_s (1 << 18)
515#define PSR_f (1 << 19)
b99bd4ef 516
c19d1205 517struct reloc_entry
bfae80f2 518{
c921be7d
NC
519 char * name;
520 bfd_reloc_code_real_type reloc;
bfae80f2
RE
521};
522
5287ad62 523enum vfp_reg_pos
bfae80f2 524{
5287ad62
JB
525 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
526 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
527};
528
529enum vfp_ldstm_type
530{
531 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
532};
533
dcbf9037
JB
534/* Bits for DEFINED field in neon_typed_alias. */
535#define NTA_HASTYPE 1
536#define NTA_HASINDEX 2
537
538struct neon_typed_alias
539{
c921be7d
NC
540 unsigned char defined;
541 unsigned char index;
542 struct neon_type_el eltype;
dcbf9037
JB
543};
544
c19d1205
ZW
545/* ARM register categories. This includes coprocessor numbers and various
546 architecture extensions' registers. */
547enum arm_reg_type
bfae80f2 548{
c19d1205
ZW
549 REG_TYPE_RN,
550 REG_TYPE_CP,
551 REG_TYPE_CN,
552 REG_TYPE_FN,
553 REG_TYPE_VFS,
554 REG_TYPE_VFD,
5287ad62 555 REG_TYPE_NQ,
037e8744 556 REG_TYPE_VFSD,
5287ad62 557 REG_TYPE_NDQ,
037e8744 558 REG_TYPE_NSDQ,
c19d1205
ZW
559 REG_TYPE_VFC,
560 REG_TYPE_MVF,
561 REG_TYPE_MVD,
562 REG_TYPE_MVFX,
563 REG_TYPE_MVDX,
564 REG_TYPE_MVAX,
565 REG_TYPE_DSPSC,
566 REG_TYPE_MMXWR,
567 REG_TYPE_MMXWC,
568 REG_TYPE_MMXWCG,
569 REG_TYPE_XSCALE,
90ec0d68 570 REG_TYPE_RNB
bfae80f2
RE
571};
572
dcbf9037
JB
573/* Structure for a hash table entry for a register.
574 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
575 information which states whether a vector type or index is specified (for a
576 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
577struct reg_entry
578{
c921be7d 579 const char * name;
90ec0d68 580 unsigned int number;
c921be7d
NC
581 unsigned char type;
582 unsigned char builtin;
583 struct neon_typed_alias * neon;
6c43fab6
RE
584};
585
c19d1205 586/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 587const char * const reg_expected_msgs[] =
c19d1205
ZW
588{
589 N_("ARM register expected"),
590 N_("bad or missing co-processor number"),
591 N_("co-processor register expected"),
592 N_("FPA register expected"),
593 N_("VFP single precision register expected"),
5287ad62
JB
594 N_("VFP/Neon double precision register expected"),
595 N_("Neon quad precision register expected"),
037e8744 596 N_("VFP single or double precision register expected"),
5287ad62 597 N_("Neon double or quad precision register expected"),
037e8744 598 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
599 N_("VFP system register expected"),
600 N_("Maverick MVF register expected"),
601 N_("Maverick MVD register expected"),
602 N_("Maverick MVFX register expected"),
603 N_("Maverick MVDX register expected"),
604 N_("Maverick MVAX register expected"),
605 N_("Maverick DSPSC register expected"),
606 N_("iWMMXt data register expected"),
607 N_("iWMMXt control register expected"),
608 N_("iWMMXt scalar register expected"),
609 N_("XScale accumulator register expected"),
6c43fab6
RE
610};
611
c19d1205 612/* Some well known registers that we refer to directly elsewhere. */
bd340a04 613#define REG_R12 12
c19d1205
ZW
614#define REG_SP 13
615#define REG_LR 14
616#define REG_PC 15
404ff6b5 617
b99bd4ef
NC
618/* ARM instructions take 4bytes in the object file, Thumb instructions
619 take 2: */
c19d1205 620#define INSN_SIZE 4
b99bd4ef
NC
621
622struct asm_opcode
623{
624 /* Basic string to match. */
d3ce72d0 625 const char * template_name;
c19d1205
ZW
626
627 /* Parameters to instruction. */
5be8be5d 628 unsigned int operands[8];
c19d1205
ZW
629
630 /* Conditional tag - see opcode_lookup. */
631 unsigned int tag : 4;
b99bd4ef
NC
632
633 /* Basic instruction code. */
c19d1205 634 unsigned int avalue : 28;
b99bd4ef 635
c19d1205
ZW
636 /* Thumb-format instruction code. */
637 unsigned int tvalue;
b99bd4ef 638
90e4755a 639 /* Which architecture variant provides this instruction. */
c921be7d
NC
640 const arm_feature_set * avariant;
641 const arm_feature_set * tvariant;
c19d1205
ZW
642
643 /* Function to call to encode instruction in ARM format. */
644 void (* aencode) (void);
b99bd4ef 645
c19d1205
ZW
646 /* Function to call to encode instruction in Thumb format. */
647 void (* tencode) (void);
b99bd4ef
NC
648};
649
a737bd4d
NC
650/* Defines for various bits that we will want to toggle. */
651#define INST_IMMEDIATE 0x02000000
652#define OFFSET_REG 0x02000000
c19d1205 653#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
654#define SHIFT_BY_REG 0x00000010
655#define PRE_INDEX 0x01000000
656#define INDEX_UP 0x00800000
657#define WRITE_BACK 0x00200000
658#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 659#define CPSI_MMOD 0x00020000
90e4755a 660
a737bd4d
NC
661#define LITERAL_MASK 0xf000f000
662#define OPCODE_MASK 0xfe1fffff
663#define V4_STR_BIT 0x00000020
8335d6aa 664#define VLDR_VMOV_SAME 0x0040f000
90e4755a 665
efd81785
PB
666#define T2_SUBS_PC_LR 0xf3de8f00
667
a737bd4d 668#define DATA_OP_SHIFT 21
90e4755a 669
ef8d22e6
PB
670#define T2_OPCODE_MASK 0xfe1fffff
671#define T2_DATA_OP_SHIFT 21
672
6530b175
NC
673#define A_COND_MASK 0xf0000000
674#define A_PUSH_POP_OP_MASK 0x0fff0000
675
676/* Opcodes for pushing/poping registers to/from the stack. */
677#define A1_OPCODE_PUSH 0x092d0000
678#define A2_OPCODE_PUSH 0x052d0004
679#define A2_OPCODE_POP 0x049d0004
680
a737bd4d
NC
681/* Codes to distinguish the arithmetic instructions. */
682#define OPCODE_AND 0
683#define OPCODE_EOR 1
684#define OPCODE_SUB 2
685#define OPCODE_RSB 3
686#define OPCODE_ADD 4
687#define OPCODE_ADC 5
688#define OPCODE_SBC 6
689#define OPCODE_RSC 7
690#define OPCODE_TST 8
691#define OPCODE_TEQ 9
692#define OPCODE_CMP 10
693#define OPCODE_CMN 11
694#define OPCODE_ORR 12
695#define OPCODE_MOV 13
696#define OPCODE_BIC 14
697#define OPCODE_MVN 15
90e4755a 698
ef8d22e6
PB
699#define T2_OPCODE_AND 0
700#define T2_OPCODE_BIC 1
701#define T2_OPCODE_ORR 2
702#define T2_OPCODE_ORN 3
703#define T2_OPCODE_EOR 4
704#define T2_OPCODE_ADD 8
705#define T2_OPCODE_ADC 10
706#define T2_OPCODE_SBC 11
707#define T2_OPCODE_SUB 13
708#define T2_OPCODE_RSB 14
709
a737bd4d
NC
710#define T_OPCODE_MUL 0x4340
711#define T_OPCODE_TST 0x4200
712#define T_OPCODE_CMN 0x42c0
713#define T_OPCODE_NEG 0x4240
714#define T_OPCODE_MVN 0x43c0
90e4755a 715
a737bd4d
NC
716#define T_OPCODE_ADD_R3 0x1800
717#define T_OPCODE_SUB_R3 0x1a00
718#define T_OPCODE_ADD_HI 0x4400
719#define T_OPCODE_ADD_ST 0xb000
720#define T_OPCODE_SUB_ST 0xb080
721#define T_OPCODE_ADD_SP 0xa800
722#define T_OPCODE_ADD_PC 0xa000
723#define T_OPCODE_ADD_I8 0x3000
724#define T_OPCODE_SUB_I8 0x3800
725#define T_OPCODE_ADD_I3 0x1c00
726#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 727
a737bd4d
NC
728#define T_OPCODE_ASR_R 0x4100
729#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
730#define T_OPCODE_LSR_R 0x40c0
731#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
732#define T_OPCODE_ASR_I 0x1000
733#define T_OPCODE_LSL_I 0x0000
734#define T_OPCODE_LSR_I 0x0800
b99bd4ef 735
a737bd4d
NC
736#define T_OPCODE_MOV_I8 0x2000
737#define T_OPCODE_CMP_I8 0x2800
738#define T_OPCODE_CMP_LR 0x4280
739#define T_OPCODE_MOV_HR 0x4600
740#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 741
a737bd4d
NC
742#define T_OPCODE_LDR_PC 0x4800
743#define T_OPCODE_LDR_SP 0x9800
744#define T_OPCODE_STR_SP 0x9000
745#define T_OPCODE_LDR_IW 0x6800
746#define T_OPCODE_STR_IW 0x6000
747#define T_OPCODE_LDR_IH 0x8800
748#define T_OPCODE_STR_IH 0x8000
749#define T_OPCODE_LDR_IB 0x7800
750#define T_OPCODE_STR_IB 0x7000
751#define T_OPCODE_LDR_RW 0x5800
752#define T_OPCODE_STR_RW 0x5000
753#define T_OPCODE_LDR_RH 0x5a00
754#define T_OPCODE_STR_RH 0x5200
755#define T_OPCODE_LDR_RB 0x5c00
756#define T_OPCODE_STR_RB 0x5400
c9b604bd 757
a737bd4d
NC
758#define T_OPCODE_PUSH 0xb400
759#define T_OPCODE_POP 0xbc00
b99bd4ef 760
2fc8bdac 761#define T_OPCODE_BRANCH 0xe000
b99bd4ef 762
a737bd4d 763#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 764#define THUMB_PP_PC_LR 0x0100
c19d1205 765#define THUMB_LOAD_BIT 0x0800
53365c0d 766#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
767
768#define BAD_ARGS _("bad arguments to instruction")
fdfde340 769#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
770#define BAD_PC _("r15 not allowed here")
771#define BAD_COND _("instruction cannot be conditional")
772#define BAD_OVERLAP _("registers may not be the same")
773#define BAD_HIREG _("lo register required")
774#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 775#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
776#define BAD_BRANCH _("branch must be last instruction in IT block")
777#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 778#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
779#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
780#define BAD_IT_COND _("incorrect condition in IT block")
781#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 782#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
783#define BAD_PC_ADDRESSING \
784 _("cannot use register index with PC-relative addressing")
785#define BAD_PC_WRITEBACK \
786 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
787#define BAD_RANGE _("branch out of range")
788#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 789#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
c19d1205 790
c921be7d
NC
791static struct hash_control * arm_ops_hsh;
792static struct hash_control * arm_cond_hsh;
793static struct hash_control * arm_shift_hsh;
794static struct hash_control * arm_psr_hsh;
795static struct hash_control * arm_v7m_psr_hsh;
796static struct hash_control * arm_reg_hsh;
797static struct hash_control * arm_reloc_hsh;
798static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 799
b99bd4ef
NC
800/* Stuff needed to resolve the label ambiguity
801 As:
802 ...
803 label: <insn>
804 may differ from:
805 ...
806 label:
5f4273c7 807 <insn> */
b99bd4ef
NC
808
809symbolS * last_label_seen;
b34976b6 810static int label_is_thumb_function_name = FALSE;
e07e6e58 811
3d0c9500
NC
812/* Literal pool structure. Held on a per-section
813 and per-sub-section basis. */
a737bd4d 814
c19d1205 815#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 816typedef struct literal_pool
b99bd4ef 817{
c921be7d
NC
818 expressionS literals [MAX_LITERAL_POOL_SIZE];
819 unsigned int next_free_entry;
820 unsigned int id;
821 symbolS * symbol;
822 segT section;
823 subsegT sub_section;
a8040cf2
NC
824#ifdef OBJ_ELF
825 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
826#endif
c921be7d 827 struct literal_pool * next;
8335d6aa 828 unsigned int alignment;
3d0c9500 829} literal_pool;
b99bd4ef 830
3d0c9500
NC
831/* Pointer to a linked list of literal pools. */
832literal_pool * list_of_pools = NULL;
e27ec89e 833
2e6976a8
DG
834typedef enum asmfunc_states
835{
836 OUTSIDE_ASMFUNC,
837 WAITING_ASMFUNC_NAME,
838 WAITING_ENDASMFUNC
839} asmfunc_states;
840
841static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
842
e07e6e58
NC
843#ifdef OBJ_ELF
844# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
845#else
846static struct current_it now_it;
847#endif
848
849static inline int
850now_it_compatible (int cond)
851{
852 return (cond & ~1) == (now_it.cc & ~1);
853}
854
855static inline int
856conditional_insn (void)
857{
858 return inst.cond != COND_ALWAYS;
859}
860
861static int in_it_block (void);
862
863static int handle_it_state (void);
864
865static void force_automatic_it_block_close (void);
866
c921be7d
NC
867static void it_fsm_post_encode (void);
868
e07e6e58
NC
869#define set_it_insn_type(type) \
870 do \
871 { \
872 inst.it_insn_type = type; \
873 if (handle_it_state () == FAIL) \
477330fc 874 return; \
e07e6e58
NC
875 } \
876 while (0)
877
c921be7d
NC
878#define set_it_insn_type_nonvoid(type, failret) \
879 do \
880 { \
881 inst.it_insn_type = type; \
882 if (handle_it_state () == FAIL) \
477330fc 883 return failret; \
c921be7d
NC
884 } \
885 while(0)
886
e07e6e58
NC
887#define set_it_insn_type_last() \
888 do \
889 { \
890 if (inst.cond == COND_ALWAYS) \
477330fc 891 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 892 else \
477330fc 893 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
894 } \
895 while (0)
896
c19d1205 897/* Pure syntax. */
b99bd4ef 898
c19d1205
ZW
899/* This array holds the chars that always start a comment. If the
900 pre-processor is disabled, these aren't very useful. */
2e6976a8 901char arm_comment_chars[] = "@";
3d0c9500 902
c19d1205
ZW
903/* This array holds the chars that only start a comment at the beginning of
904 a line. If the line seems to have the form '# 123 filename'
905 .line and .file directives will appear in the pre-processed output. */
906/* Note that input_file.c hand checks for '#' at the beginning of the
907 first line of the input file. This is because the compiler outputs
908 #NO_APP at the beginning of its output. */
909/* Also note that comments like this one will always work. */
910const char line_comment_chars[] = "#";
3d0c9500 911
2e6976a8 912char arm_line_separator_chars[] = ";";
b99bd4ef 913
c19d1205
ZW
914/* Chars that can be used to separate mant
915 from exp in floating point numbers. */
916const char EXP_CHARS[] = "eE";
3d0c9500 917
c19d1205
ZW
918/* Chars that mean this number is a floating point constant. */
919/* As in 0f12.456 */
920/* or 0d1.2345e12 */
b99bd4ef 921
c19d1205 922const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 923
c19d1205
ZW
924/* Prefix characters that indicate the start of an immediate
925 value. */
926#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 927
c19d1205
ZW
928/* Separator character handling. */
929
930#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
931
932static inline int
933skip_past_char (char ** str, char c)
934{
8ab8155f
NC
935 /* PR gas/14987: Allow for whitespace before the expected character. */
936 skip_whitespace (*str);
427d0db6 937
c19d1205
ZW
938 if (**str == c)
939 {
940 (*str)++;
941 return SUCCESS;
3d0c9500 942 }
c19d1205
ZW
943 else
944 return FAIL;
945}
c921be7d 946
c19d1205 947#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 948
c19d1205
ZW
949/* Arithmetic expressions (possibly involving symbols). */
950
951/* Return TRUE if anything in the expression is a bignum. */
952
953static int
954walk_no_bignums (symbolS * sp)
955{
956 if (symbol_get_value_expression (sp)->X_op == O_big)
957 return 1;
958
959 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 960 {
c19d1205
ZW
961 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
962 || (symbol_get_value_expression (sp)->X_op_symbol
963 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
964 }
965
c19d1205 966 return 0;
3d0c9500
NC
967}
968
c19d1205
ZW
969static int in_my_get_expression = 0;
970
971/* Third argument to my_get_expression. */
972#define GE_NO_PREFIX 0
973#define GE_IMM_PREFIX 1
974#define GE_OPT_PREFIX 2
5287ad62
JB
975/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
976 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
977#define GE_OPT_PREFIX_BIG 3
a737bd4d 978
b99bd4ef 979static int
c19d1205 980my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 981{
c19d1205
ZW
982 char * save_in;
983 segT seg;
b99bd4ef 984
c19d1205
ZW
985 /* In unified syntax, all prefixes are optional. */
986 if (unified_syntax)
5287ad62 987 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 988 : GE_OPT_PREFIX;
b99bd4ef 989
c19d1205 990 switch (prefix_mode)
b99bd4ef 991 {
c19d1205
ZW
992 case GE_NO_PREFIX: break;
993 case GE_IMM_PREFIX:
994 if (!is_immediate_prefix (**str))
995 {
996 inst.error = _("immediate expression requires a # prefix");
997 return FAIL;
998 }
999 (*str)++;
1000 break;
1001 case GE_OPT_PREFIX:
5287ad62 1002 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1003 if (is_immediate_prefix (**str))
1004 (*str)++;
1005 break;
1006 default: abort ();
1007 }
b99bd4ef 1008
c19d1205 1009 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1010
c19d1205
ZW
1011 save_in = input_line_pointer;
1012 input_line_pointer = *str;
1013 in_my_get_expression = 1;
1014 seg = expression (ep);
1015 in_my_get_expression = 0;
1016
f86adc07 1017 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1018 {
f86adc07 1019 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1020 *str = input_line_pointer;
1021 input_line_pointer = save_in;
1022 if (inst.error == NULL)
f86adc07
NS
1023 inst.error = (ep->X_op == O_absent
1024 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1025 return 1;
1026 }
b99bd4ef 1027
c19d1205
ZW
1028#ifdef OBJ_AOUT
1029 if (seg != absolute_section
1030 && seg != text_section
1031 && seg != data_section
1032 && seg != bss_section
1033 && seg != undefined_section)
1034 {
1035 inst.error = _("bad segment");
1036 *str = input_line_pointer;
1037 input_line_pointer = save_in;
1038 return 1;
b99bd4ef 1039 }
87975d2a
AM
1040#else
1041 (void) seg;
c19d1205 1042#endif
b99bd4ef 1043
c19d1205
ZW
1044 /* Get rid of any bignums now, so that we don't generate an error for which
1045 we can't establish a line number later on. Big numbers are never valid
1046 in instructions, which is where this routine is always called. */
5287ad62
JB
1047 if (prefix_mode != GE_OPT_PREFIX_BIG
1048 && (ep->X_op == O_big
477330fc 1049 || (ep->X_add_symbol
5287ad62 1050 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1051 || (ep->X_op_symbol
5287ad62 1052 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1053 {
1054 inst.error = _("invalid constant");
1055 *str = input_line_pointer;
1056 input_line_pointer = save_in;
1057 return 1;
1058 }
b99bd4ef 1059
c19d1205
ZW
1060 *str = input_line_pointer;
1061 input_line_pointer = save_in;
1062 return 0;
b99bd4ef
NC
1063}
1064
c19d1205
ZW
1065/* Turn a string in input_line_pointer into a floating point constant
1066 of type TYPE, and store the appropriate bytes in *LITP. The number
1067 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1068 returned, or NULL on OK.
b99bd4ef 1069
c19d1205
ZW
1070 Note that fp constants aren't represent in the normal way on the ARM.
1071 In big endian mode, things are as expected. However, in little endian
1072 mode fp constants are big-endian word-wise, and little-endian byte-wise
1073 within the words. For example, (double) 1.1 in big endian mode is
1074 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1075 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1076
c19d1205 1077 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1078
c19d1205
ZW
1079char *
1080md_atof (int type, char * litP, int * sizeP)
1081{
1082 int prec;
1083 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1084 char *t;
1085 int i;
b99bd4ef 1086
c19d1205
ZW
1087 switch (type)
1088 {
1089 case 'f':
1090 case 'F':
1091 case 's':
1092 case 'S':
1093 prec = 2;
1094 break;
b99bd4ef 1095
c19d1205
ZW
1096 case 'd':
1097 case 'D':
1098 case 'r':
1099 case 'R':
1100 prec = 4;
1101 break;
b99bd4ef 1102
c19d1205
ZW
1103 case 'x':
1104 case 'X':
499ac353 1105 prec = 5;
c19d1205 1106 break;
b99bd4ef 1107
c19d1205
ZW
1108 case 'p':
1109 case 'P':
499ac353 1110 prec = 5;
c19d1205 1111 break;
a737bd4d 1112
c19d1205
ZW
1113 default:
1114 *sizeP = 0;
499ac353 1115 return _("Unrecognized or unsupported floating point constant");
c19d1205 1116 }
b99bd4ef 1117
c19d1205
ZW
1118 t = atof_ieee (input_line_pointer, type, words);
1119 if (t)
1120 input_line_pointer = t;
499ac353 1121 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1122
c19d1205
ZW
1123 if (target_big_endian)
1124 {
1125 for (i = 0; i < prec; i++)
1126 {
499ac353
NC
1127 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1128 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1129 }
1130 }
1131 else
1132 {
e74cfd16 1133 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1134 for (i = prec - 1; i >= 0; i--)
1135 {
499ac353
NC
1136 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1137 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1138 }
1139 else
1140 /* For a 4 byte float the order of elements in `words' is 1 0.
1141 For an 8 byte float the order is 1 0 3 2. */
1142 for (i = 0; i < prec; i += 2)
1143 {
499ac353
NC
1144 md_number_to_chars (litP, (valueT) words[i + 1],
1145 sizeof (LITTLENUM_TYPE));
1146 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1147 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1148 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1149 }
1150 }
b99bd4ef 1151
499ac353 1152 return NULL;
c19d1205 1153}
b99bd4ef 1154
c19d1205
ZW
1155/* We handle all bad expressions here, so that we can report the faulty
1156 instruction in the error message. */
1157void
91d6fa6a 1158md_operand (expressionS * exp)
c19d1205
ZW
1159{
1160 if (in_my_get_expression)
91d6fa6a 1161 exp->X_op = O_illegal;
b99bd4ef
NC
1162}
1163
c19d1205 1164/* Immediate values. */
b99bd4ef 1165
c19d1205
ZW
1166/* Generic immediate-value read function for use in directives.
1167 Accepts anything that 'expression' can fold to a constant.
1168 *val receives the number. */
1169#ifdef OBJ_ELF
1170static int
1171immediate_for_directive (int *val)
b99bd4ef 1172{
c19d1205
ZW
1173 expressionS exp;
1174 exp.X_op = O_illegal;
b99bd4ef 1175
c19d1205
ZW
1176 if (is_immediate_prefix (*input_line_pointer))
1177 {
1178 input_line_pointer++;
1179 expression (&exp);
1180 }
b99bd4ef 1181
c19d1205
ZW
1182 if (exp.X_op != O_constant)
1183 {
1184 as_bad (_("expected #constant"));
1185 ignore_rest_of_line ();
1186 return FAIL;
1187 }
1188 *val = exp.X_add_number;
1189 return SUCCESS;
b99bd4ef 1190}
c19d1205 1191#endif
b99bd4ef 1192
c19d1205 1193/* Register parsing. */
b99bd4ef 1194
c19d1205
ZW
1195/* Generic register parser. CCP points to what should be the
1196 beginning of a register name. If it is indeed a valid register
1197 name, advance CCP over it and return the reg_entry structure;
1198 otherwise return NULL. Does not issue diagnostics. */
1199
1200static struct reg_entry *
1201arm_reg_parse_multi (char **ccp)
b99bd4ef 1202{
c19d1205
ZW
1203 char *start = *ccp;
1204 char *p;
1205 struct reg_entry *reg;
b99bd4ef 1206
477330fc
RM
1207 skip_whitespace (start);
1208
c19d1205
ZW
1209#ifdef REGISTER_PREFIX
1210 if (*start != REGISTER_PREFIX)
01cfc07f 1211 return NULL;
c19d1205
ZW
1212 start++;
1213#endif
1214#ifdef OPTIONAL_REGISTER_PREFIX
1215 if (*start == OPTIONAL_REGISTER_PREFIX)
1216 start++;
1217#endif
b99bd4ef 1218
c19d1205
ZW
1219 p = start;
1220 if (!ISALPHA (*p) || !is_name_beginner (*p))
1221 return NULL;
b99bd4ef 1222
c19d1205
ZW
1223 do
1224 p++;
1225 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1226
1227 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1228
1229 if (!reg)
1230 return NULL;
1231
1232 *ccp = p;
1233 return reg;
b99bd4ef
NC
1234}
1235
1236static int
dcbf9037 1237arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1238 enum arm_reg_type type)
b99bd4ef 1239{
c19d1205
ZW
1240 /* Alternative syntaxes are accepted for a few register classes. */
1241 switch (type)
1242 {
1243 case REG_TYPE_MVF:
1244 case REG_TYPE_MVD:
1245 case REG_TYPE_MVFX:
1246 case REG_TYPE_MVDX:
1247 /* Generic coprocessor register names are allowed for these. */
79134647 1248 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1249 return reg->number;
1250 break;
69b97547 1251
c19d1205
ZW
1252 case REG_TYPE_CP:
1253 /* For backward compatibility, a bare number is valid here. */
1254 {
1255 unsigned long processor = strtoul (start, ccp, 10);
1256 if (*ccp != start && processor <= 15)
1257 return processor;
1258 }
6057a28f 1259
c19d1205
ZW
1260 case REG_TYPE_MMXWC:
1261 /* WC includes WCG. ??? I'm not sure this is true for all
1262 instructions that take WC registers. */
79134647 1263 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1264 return reg->number;
6057a28f 1265 break;
c19d1205 1266
6057a28f 1267 default:
c19d1205 1268 break;
6057a28f
NC
1269 }
1270
dcbf9037
JB
1271 return FAIL;
1272}
1273
1274/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1275 return value is the register number or FAIL. */
1276
1277static int
1278arm_reg_parse (char **ccp, enum arm_reg_type type)
1279{
1280 char *start = *ccp;
1281 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1282 int ret;
1283
1284 /* Do not allow a scalar (reg+index) to parse as a register. */
1285 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1286 return FAIL;
1287
1288 if (reg && reg->type == type)
1289 return reg->number;
1290
1291 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1292 return ret;
1293
c19d1205
ZW
1294 *ccp = start;
1295 return FAIL;
1296}
69b97547 1297
dcbf9037
JB
1298/* Parse a Neon type specifier. *STR should point at the leading '.'
1299 character. Does no verification at this stage that the type fits the opcode
1300 properly. E.g.,
1301
1302 .i32.i32.s16
1303 .s32.f32
1304 .u16
1305
1306 Can all be legally parsed by this function.
1307
1308 Fills in neon_type struct pointer with parsed information, and updates STR
1309 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1310 type, FAIL if not. */
1311
1312static int
1313parse_neon_type (struct neon_type *type, char **str)
1314{
1315 char *ptr = *str;
1316
1317 if (type)
1318 type->elems = 0;
1319
1320 while (type->elems < NEON_MAX_TYPE_ELS)
1321 {
1322 enum neon_el_type thistype = NT_untyped;
1323 unsigned thissize = -1u;
1324
1325 if (*ptr != '.')
1326 break;
1327
1328 ptr++;
1329
1330 /* Just a size without an explicit type. */
1331 if (ISDIGIT (*ptr))
1332 goto parsesize;
1333
1334 switch (TOLOWER (*ptr))
1335 {
1336 case 'i': thistype = NT_integer; break;
1337 case 'f': thistype = NT_float; break;
1338 case 'p': thistype = NT_poly; break;
1339 case 's': thistype = NT_signed; break;
1340 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1341 case 'd':
1342 thistype = NT_float;
1343 thissize = 64;
1344 ptr++;
1345 goto done;
dcbf9037
JB
1346 default:
1347 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1348 return FAIL;
1349 }
1350
1351 ptr++;
1352
1353 /* .f is an abbreviation for .f32. */
1354 if (thistype == NT_float && !ISDIGIT (*ptr))
1355 thissize = 32;
1356 else
1357 {
1358 parsesize:
1359 thissize = strtoul (ptr, &ptr, 10);
1360
1361 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1362 && thissize != 64)
1363 {
1364 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1365 return FAIL;
1366 }
1367 }
1368
037e8744 1369 done:
dcbf9037 1370 if (type)
477330fc
RM
1371 {
1372 type->el[type->elems].type = thistype;
dcbf9037
JB
1373 type->el[type->elems].size = thissize;
1374 type->elems++;
1375 }
1376 }
1377
1378 /* Empty/missing type is not a successful parse. */
1379 if (type->elems == 0)
1380 return FAIL;
1381
1382 *str = ptr;
1383
1384 return SUCCESS;
1385}
1386
1387/* Errors may be set multiple times during parsing or bit encoding
1388 (particularly in the Neon bits), but usually the earliest error which is set
1389 will be the most meaningful. Avoid overwriting it with later (cascading)
1390 errors by calling this function. */
1391
1392static void
1393first_error (const char *err)
1394{
1395 if (!inst.error)
1396 inst.error = err;
1397}
1398
1399/* Parse a single type, e.g. ".s32", leading period included. */
1400static int
1401parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1402{
1403 char *str = *ccp;
1404 struct neon_type optype;
1405
1406 if (*str == '.')
1407 {
1408 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1409 {
1410 if (optype.elems == 1)
1411 *vectype = optype.el[0];
1412 else
1413 {
1414 first_error (_("only one type should be specified for operand"));
1415 return FAIL;
1416 }
1417 }
dcbf9037 1418 else
477330fc
RM
1419 {
1420 first_error (_("vector type expected"));
1421 return FAIL;
1422 }
dcbf9037
JB
1423 }
1424 else
1425 return FAIL;
5f4273c7 1426
dcbf9037 1427 *ccp = str;
5f4273c7 1428
dcbf9037
JB
1429 return SUCCESS;
1430}
1431
1432/* Special meanings for indices (which have a range of 0-7), which will fit into
1433 a 4-bit integer. */
1434
1435#define NEON_ALL_LANES 15
1436#define NEON_INTERLEAVE_LANES 14
1437
1438/* Parse either a register or a scalar, with an optional type. Return the
1439 register number, and optionally fill in the actual type of the register
1440 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1441 type/index information in *TYPEINFO. */
1442
1443static int
1444parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1445 enum arm_reg_type *rtype,
1446 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1447{
1448 char *str = *ccp;
1449 struct reg_entry *reg = arm_reg_parse_multi (&str);
1450 struct neon_typed_alias atype;
1451 struct neon_type_el parsetype;
1452
1453 atype.defined = 0;
1454 atype.index = -1;
1455 atype.eltype.type = NT_invtype;
1456 atype.eltype.size = -1;
1457
1458 /* Try alternate syntax for some types of register. Note these are mutually
1459 exclusive with the Neon syntax extensions. */
1460 if (reg == NULL)
1461 {
1462 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1463 if (altreg != FAIL)
477330fc 1464 *ccp = str;
dcbf9037 1465 if (typeinfo)
477330fc 1466 *typeinfo = atype;
dcbf9037
JB
1467 return altreg;
1468 }
1469
037e8744
JB
1470 /* Undo polymorphism when a set of register types may be accepted. */
1471 if ((type == REG_TYPE_NDQ
1472 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1473 || (type == REG_TYPE_VFSD
477330fc 1474 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1475 || (type == REG_TYPE_NSDQ
477330fc
RM
1476 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1477 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1478 || (type == REG_TYPE_MMXWC
1479 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1480 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1481
1482 if (type != reg->type)
1483 return FAIL;
1484
1485 if (reg->neon)
1486 atype = *reg->neon;
5f4273c7 1487
dcbf9037
JB
1488 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1489 {
1490 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1491 {
1492 first_error (_("can't redefine type for operand"));
1493 return FAIL;
1494 }
dcbf9037
JB
1495 atype.defined |= NTA_HASTYPE;
1496 atype.eltype = parsetype;
1497 }
5f4273c7 1498
dcbf9037
JB
1499 if (skip_past_char (&str, '[') == SUCCESS)
1500 {
1501 if (type != REG_TYPE_VFD)
477330fc
RM
1502 {
1503 first_error (_("only D registers may be indexed"));
1504 return FAIL;
1505 }
5f4273c7 1506
dcbf9037 1507 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1508 {
1509 first_error (_("can't change index for operand"));
1510 return FAIL;
1511 }
dcbf9037
JB
1512
1513 atype.defined |= NTA_HASINDEX;
1514
1515 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1516 atype.index = NEON_ALL_LANES;
dcbf9037 1517 else
477330fc
RM
1518 {
1519 expressionS exp;
dcbf9037 1520
477330fc 1521 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1522
477330fc
RM
1523 if (exp.X_op != O_constant)
1524 {
1525 first_error (_("constant expression required"));
1526 return FAIL;
1527 }
dcbf9037 1528
477330fc
RM
1529 if (skip_past_char (&str, ']') == FAIL)
1530 return FAIL;
dcbf9037 1531
477330fc
RM
1532 atype.index = exp.X_add_number;
1533 }
dcbf9037 1534 }
5f4273c7 1535
dcbf9037
JB
1536 if (typeinfo)
1537 *typeinfo = atype;
5f4273c7 1538
dcbf9037
JB
1539 if (rtype)
1540 *rtype = type;
5f4273c7 1541
dcbf9037 1542 *ccp = str;
5f4273c7 1543
dcbf9037
JB
1544 return reg->number;
1545}
1546
1547/* Like arm_reg_parse, but allow allow the following extra features:
1548 - If RTYPE is non-zero, return the (possibly restricted) type of the
1549 register (e.g. Neon double or quad reg when either has been requested).
1550 - If this is a Neon vector type with additional type information, fill
1551 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1552 This function will fault on encountering a scalar. */
dcbf9037
JB
1553
1554static int
1555arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1556 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1557{
1558 struct neon_typed_alias atype;
1559 char *str = *ccp;
1560 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1561
1562 if (reg == FAIL)
1563 return FAIL;
1564
0855e32b
NS
1565 /* Do not allow regname(... to parse as a register. */
1566 if (*str == '(')
1567 return FAIL;
1568
dcbf9037
JB
1569 /* Do not allow a scalar (reg+index) to parse as a register. */
1570 if ((atype.defined & NTA_HASINDEX) != 0)
1571 {
1572 first_error (_("register operand expected, but got scalar"));
1573 return FAIL;
1574 }
1575
1576 if (vectype)
1577 *vectype = atype.eltype;
1578
1579 *ccp = str;
1580
1581 return reg;
1582}
1583
1584#define NEON_SCALAR_REG(X) ((X) >> 4)
1585#define NEON_SCALAR_INDEX(X) ((X) & 15)
1586
5287ad62
JB
1587/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1588 have enough information to be able to do a good job bounds-checking. So, we
1589 just do easy checks here, and do further checks later. */
1590
1591static int
dcbf9037 1592parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1593{
dcbf9037 1594 int reg;
5287ad62 1595 char *str = *ccp;
dcbf9037 1596 struct neon_typed_alias atype;
5f4273c7 1597
dcbf9037 1598 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1599
dcbf9037 1600 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1601 return FAIL;
5f4273c7 1602
dcbf9037 1603 if (atype.index == NEON_ALL_LANES)
5287ad62 1604 {
dcbf9037 1605 first_error (_("scalar must have an index"));
5287ad62
JB
1606 return FAIL;
1607 }
dcbf9037 1608 else if (atype.index >= 64 / elsize)
5287ad62 1609 {
dcbf9037 1610 first_error (_("scalar index out of range"));
5287ad62
JB
1611 return FAIL;
1612 }
5f4273c7 1613
dcbf9037
JB
1614 if (type)
1615 *type = atype.eltype;
5f4273c7 1616
5287ad62 1617 *ccp = str;
5f4273c7 1618
dcbf9037 1619 return reg * 16 + atype.index;
5287ad62
JB
1620}
1621
c19d1205 1622/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1623
c19d1205
ZW
1624static long
1625parse_reg_list (char ** strp)
1626{
1627 char * str = * strp;
1628 long range = 0;
1629 int another_range;
a737bd4d 1630
c19d1205
ZW
1631 /* We come back here if we get ranges concatenated by '+' or '|'. */
1632 do
6057a28f 1633 {
477330fc
RM
1634 skip_whitespace (str);
1635
c19d1205 1636 another_range = 0;
a737bd4d 1637
c19d1205
ZW
1638 if (*str == '{')
1639 {
1640 int in_range = 0;
1641 int cur_reg = -1;
a737bd4d 1642
c19d1205
ZW
1643 str++;
1644 do
1645 {
1646 int reg;
6057a28f 1647
dcbf9037 1648 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1649 {
dcbf9037 1650 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1651 return FAIL;
1652 }
a737bd4d 1653
c19d1205
ZW
1654 if (in_range)
1655 {
1656 int i;
a737bd4d 1657
c19d1205
ZW
1658 if (reg <= cur_reg)
1659 {
dcbf9037 1660 first_error (_("bad range in register list"));
c19d1205
ZW
1661 return FAIL;
1662 }
40a18ebd 1663
c19d1205
ZW
1664 for (i = cur_reg + 1; i < reg; i++)
1665 {
1666 if (range & (1 << i))
1667 as_tsktsk
1668 (_("Warning: duplicated register (r%d) in register list"),
1669 i);
1670 else
1671 range |= 1 << i;
1672 }
1673 in_range = 0;
1674 }
a737bd4d 1675
c19d1205
ZW
1676 if (range & (1 << reg))
1677 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1678 reg);
1679 else if (reg <= cur_reg)
1680 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1681
c19d1205
ZW
1682 range |= 1 << reg;
1683 cur_reg = reg;
1684 }
1685 while (skip_past_comma (&str) != FAIL
1686 || (in_range = 1, *str++ == '-'));
1687 str--;
a737bd4d 1688
d996d970 1689 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1690 {
dcbf9037 1691 first_error (_("missing `}'"));
c19d1205
ZW
1692 return FAIL;
1693 }
1694 }
1695 else
1696 {
91d6fa6a 1697 expressionS exp;
40a18ebd 1698
91d6fa6a 1699 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1700 return FAIL;
40a18ebd 1701
91d6fa6a 1702 if (exp.X_op == O_constant)
c19d1205 1703 {
91d6fa6a
NC
1704 if (exp.X_add_number
1705 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1706 {
1707 inst.error = _("invalid register mask");
1708 return FAIL;
1709 }
a737bd4d 1710
91d6fa6a 1711 if ((range & exp.X_add_number) != 0)
c19d1205 1712 {
91d6fa6a 1713 int regno = range & exp.X_add_number;
a737bd4d 1714
c19d1205
ZW
1715 regno &= -regno;
1716 regno = (1 << regno) - 1;
1717 as_tsktsk
1718 (_("Warning: duplicated register (r%d) in register list"),
1719 regno);
1720 }
a737bd4d 1721
91d6fa6a 1722 range |= exp.X_add_number;
c19d1205
ZW
1723 }
1724 else
1725 {
1726 if (inst.reloc.type != 0)
1727 {
1728 inst.error = _("expression too complex");
1729 return FAIL;
1730 }
a737bd4d 1731
91d6fa6a 1732 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1733 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1734 inst.reloc.pc_rel = 0;
1735 }
1736 }
a737bd4d 1737
c19d1205
ZW
1738 if (*str == '|' || *str == '+')
1739 {
1740 str++;
1741 another_range = 1;
1742 }
a737bd4d 1743 }
c19d1205 1744 while (another_range);
a737bd4d 1745
c19d1205
ZW
1746 *strp = str;
1747 return range;
a737bd4d
NC
1748}
1749
5287ad62
JB
1750/* Types of registers in a list. */
1751
1752enum reg_list_els
1753{
1754 REGLIST_VFP_S,
1755 REGLIST_VFP_D,
1756 REGLIST_NEON_D
1757};
1758
c19d1205
ZW
1759/* Parse a VFP register list. If the string is invalid return FAIL.
1760 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1761 register. Parses registers of type ETYPE.
1762 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1763 - Q registers can be used to specify pairs of D registers
1764 - { } can be omitted from around a singleton register list
477330fc
RM
1765 FIXME: This is not implemented, as it would require backtracking in
1766 some cases, e.g.:
1767 vtbl.8 d3,d4,d5
1768 This could be done (the meaning isn't really ambiguous), but doesn't
1769 fit in well with the current parsing framework.
dcbf9037
JB
1770 - 32 D registers may be used (also true for VFPv3).
1771 FIXME: Types are ignored in these register lists, which is probably a
1772 bug. */
6057a28f 1773
c19d1205 1774static int
037e8744 1775parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1776{
037e8744 1777 char *str = *ccp;
c19d1205
ZW
1778 int base_reg;
1779 int new_base;
21d799b5 1780 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1781 int max_regs = 0;
c19d1205
ZW
1782 int count = 0;
1783 int warned = 0;
1784 unsigned long mask = 0;
a737bd4d 1785 int i;
6057a28f 1786
477330fc 1787 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1788 {
1789 inst.error = _("expecting {");
1790 return FAIL;
1791 }
6057a28f 1792
5287ad62 1793 switch (etype)
c19d1205 1794 {
5287ad62 1795 case REGLIST_VFP_S:
c19d1205
ZW
1796 regtype = REG_TYPE_VFS;
1797 max_regs = 32;
5287ad62 1798 break;
5f4273c7 1799
5287ad62
JB
1800 case REGLIST_VFP_D:
1801 regtype = REG_TYPE_VFD;
b7fc2769 1802 break;
5f4273c7 1803
b7fc2769
JB
1804 case REGLIST_NEON_D:
1805 regtype = REG_TYPE_NDQ;
1806 break;
1807 }
1808
1809 if (etype != REGLIST_VFP_S)
1810 {
b1cc4aeb
PB
1811 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1812 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1813 {
1814 max_regs = 32;
1815 if (thumb_mode)
1816 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1817 fpu_vfp_ext_d32);
1818 else
1819 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1820 fpu_vfp_ext_d32);
1821 }
5287ad62 1822 else
477330fc 1823 max_regs = 16;
c19d1205 1824 }
6057a28f 1825
c19d1205 1826 base_reg = max_regs;
a737bd4d 1827
c19d1205
ZW
1828 do
1829 {
5287ad62 1830 int setmask = 1, addregs = 1;
dcbf9037 1831
037e8744 1832 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1833
c19d1205 1834 if (new_base == FAIL)
a737bd4d 1835 {
dcbf9037 1836 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1837 return FAIL;
1838 }
5f4273c7 1839
b7fc2769 1840 if (new_base >= max_regs)
477330fc
RM
1841 {
1842 first_error (_("register out of range in list"));
1843 return FAIL;
1844 }
5f4273c7 1845
5287ad62
JB
1846 /* Note: a value of 2 * n is returned for the register Q<n>. */
1847 if (regtype == REG_TYPE_NQ)
477330fc
RM
1848 {
1849 setmask = 3;
1850 addregs = 2;
1851 }
5287ad62 1852
c19d1205
ZW
1853 if (new_base < base_reg)
1854 base_reg = new_base;
a737bd4d 1855
5287ad62 1856 if (mask & (setmask << new_base))
c19d1205 1857 {
dcbf9037 1858 first_error (_("invalid register list"));
c19d1205 1859 return FAIL;
a737bd4d 1860 }
a737bd4d 1861
c19d1205
ZW
1862 if ((mask >> new_base) != 0 && ! warned)
1863 {
1864 as_tsktsk (_("register list not in ascending order"));
1865 warned = 1;
1866 }
0bbf2aa4 1867
5287ad62
JB
1868 mask |= setmask << new_base;
1869 count += addregs;
0bbf2aa4 1870
037e8744 1871 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1872 {
1873 int high_range;
0bbf2aa4 1874
037e8744 1875 str++;
0bbf2aa4 1876
037e8744 1877 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1878 == FAIL)
c19d1205
ZW
1879 {
1880 inst.error = gettext (reg_expected_msgs[regtype]);
1881 return FAIL;
1882 }
0bbf2aa4 1883
477330fc
RM
1884 if (high_range >= max_regs)
1885 {
1886 first_error (_("register out of range in list"));
1887 return FAIL;
1888 }
b7fc2769 1889
477330fc
RM
1890 if (regtype == REG_TYPE_NQ)
1891 high_range = high_range + 1;
5287ad62 1892
c19d1205
ZW
1893 if (high_range <= new_base)
1894 {
1895 inst.error = _("register range not in ascending order");
1896 return FAIL;
1897 }
0bbf2aa4 1898
5287ad62 1899 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1900 {
5287ad62 1901 if (mask & (setmask << new_base))
0bbf2aa4 1902 {
c19d1205
ZW
1903 inst.error = _("invalid register list");
1904 return FAIL;
0bbf2aa4 1905 }
c19d1205 1906
5287ad62
JB
1907 mask |= setmask << new_base;
1908 count += addregs;
0bbf2aa4 1909 }
0bbf2aa4 1910 }
0bbf2aa4 1911 }
037e8744 1912 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1913
037e8744 1914 str++;
0bbf2aa4 1915
c19d1205
ZW
1916 /* Sanity check -- should have raised a parse error above. */
1917 if (count == 0 || count > max_regs)
1918 abort ();
1919
1920 *pbase = base_reg;
1921
1922 /* Final test -- the registers must be consecutive. */
1923 mask >>= base_reg;
1924 for (i = 0; i < count; i++)
1925 {
1926 if ((mask & (1u << i)) == 0)
1927 {
1928 inst.error = _("non-contiguous register range");
1929 return FAIL;
1930 }
1931 }
1932
037e8744
JB
1933 *ccp = str;
1934
c19d1205 1935 return count;
b99bd4ef
NC
1936}
1937
dcbf9037
JB
1938/* True if two alias types are the same. */
1939
c921be7d 1940static bfd_boolean
dcbf9037
JB
1941neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1942{
1943 if (!a && !b)
c921be7d 1944 return TRUE;
5f4273c7 1945
dcbf9037 1946 if (!a || !b)
c921be7d 1947 return FALSE;
dcbf9037
JB
1948
1949 if (a->defined != b->defined)
c921be7d 1950 return FALSE;
5f4273c7 1951
dcbf9037
JB
1952 if ((a->defined & NTA_HASTYPE) != 0
1953 && (a->eltype.type != b->eltype.type
477330fc 1954 || a->eltype.size != b->eltype.size))
c921be7d 1955 return FALSE;
dcbf9037
JB
1956
1957 if ((a->defined & NTA_HASINDEX) != 0
1958 && (a->index != b->index))
c921be7d 1959 return FALSE;
5f4273c7 1960
c921be7d 1961 return TRUE;
dcbf9037
JB
1962}
1963
5287ad62
JB
1964/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1965 The base register is put in *PBASE.
dcbf9037 1966 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1967 the return value.
1968 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1969 Bits [6:5] encode the list length (minus one).
1970 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1971
5287ad62 1972#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1973#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1974#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1975
1976static int
dcbf9037 1977parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1978 struct neon_type_el *eltype)
5287ad62
JB
1979{
1980 char *ptr = *str;
1981 int base_reg = -1;
1982 int reg_incr = -1;
1983 int count = 0;
1984 int lane = -1;
1985 int leading_brace = 0;
1986 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1987 const char *const incr_error = _("register stride must be 1 or 2");
1988 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1989 struct neon_typed_alias firsttype;
5f4273c7 1990
5287ad62
JB
1991 if (skip_past_char (&ptr, '{') == SUCCESS)
1992 leading_brace = 1;
5f4273c7 1993
5287ad62
JB
1994 do
1995 {
dcbf9037
JB
1996 struct neon_typed_alias atype;
1997 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1998
5287ad62 1999 if (getreg == FAIL)
477330fc
RM
2000 {
2001 first_error (_(reg_expected_msgs[rtype]));
2002 return FAIL;
2003 }
5f4273c7 2004
5287ad62 2005 if (base_reg == -1)
477330fc
RM
2006 {
2007 base_reg = getreg;
2008 if (rtype == REG_TYPE_NQ)
2009 {
2010 reg_incr = 1;
2011 }
2012 firsttype = atype;
2013 }
5287ad62 2014 else if (reg_incr == -1)
477330fc
RM
2015 {
2016 reg_incr = getreg - base_reg;
2017 if (reg_incr < 1 || reg_incr > 2)
2018 {
2019 first_error (_(incr_error));
2020 return FAIL;
2021 }
2022 }
5287ad62 2023 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2024 {
2025 first_error (_(incr_error));
2026 return FAIL;
2027 }
dcbf9037 2028
c921be7d 2029 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2030 {
2031 first_error (_(type_error));
2032 return FAIL;
2033 }
5f4273c7 2034
5287ad62 2035 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2036 modes. */
5287ad62 2037 if (ptr[0] == '-')
477330fc
RM
2038 {
2039 struct neon_typed_alias htype;
2040 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2041 if (lane == -1)
2042 lane = NEON_INTERLEAVE_LANES;
2043 else if (lane != NEON_INTERLEAVE_LANES)
2044 {
2045 first_error (_(type_error));
2046 return FAIL;
2047 }
2048 if (reg_incr == -1)
2049 reg_incr = 1;
2050 else if (reg_incr != 1)
2051 {
2052 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2053 return FAIL;
2054 }
2055 ptr++;
2056 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2057 if (hireg == FAIL)
2058 {
2059 first_error (_(reg_expected_msgs[rtype]));
2060 return FAIL;
2061 }
2062 if (! neon_alias_types_same (&htype, &firsttype))
2063 {
2064 first_error (_(type_error));
2065 return FAIL;
2066 }
2067 count += hireg + dregs - getreg;
2068 continue;
2069 }
5f4273c7 2070
5287ad62
JB
2071 /* If we're using Q registers, we can't use [] or [n] syntax. */
2072 if (rtype == REG_TYPE_NQ)
477330fc
RM
2073 {
2074 count += 2;
2075 continue;
2076 }
5f4273c7 2077
dcbf9037 2078 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2079 {
2080 if (lane == -1)
2081 lane = atype.index;
2082 else if (lane != atype.index)
2083 {
2084 first_error (_(type_error));
2085 return FAIL;
2086 }
2087 }
5287ad62 2088 else if (lane == -1)
477330fc 2089 lane = NEON_INTERLEAVE_LANES;
5287ad62 2090 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2091 {
2092 first_error (_(type_error));
2093 return FAIL;
2094 }
5287ad62
JB
2095 count++;
2096 }
2097 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2098
5287ad62
JB
2099 /* No lane set by [x]. We must be interleaving structures. */
2100 if (lane == -1)
2101 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2102
5287ad62
JB
2103 /* Sanity check. */
2104 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2105 || (count > 1 && reg_incr == -1))
2106 {
dcbf9037 2107 first_error (_("error parsing element/structure list"));
5287ad62
JB
2108 return FAIL;
2109 }
2110
2111 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2112 {
dcbf9037 2113 first_error (_("expected }"));
5287ad62
JB
2114 return FAIL;
2115 }
5f4273c7 2116
5287ad62
JB
2117 if (reg_incr == -1)
2118 reg_incr = 1;
2119
dcbf9037
JB
2120 if (eltype)
2121 *eltype = firsttype.eltype;
2122
5287ad62
JB
2123 *pbase = base_reg;
2124 *str = ptr;
5f4273c7 2125
5287ad62
JB
2126 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2127}
2128
c19d1205
ZW
2129/* Parse an explicit relocation suffix on an expression. This is
2130 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2131 arm_reloc_hsh contains no entries, so this function can only
2132 succeed if there is no () after the word. Returns -1 on error,
2133 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2134
c19d1205
ZW
2135static int
2136parse_reloc (char **str)
b99bd4ef 2137{
c19d1205
ZW
2138 struct reloc_entry *r;
2139 char *p, *q;
b99bd4ef 2140
c19d1205
ZW
2141 if (**str != '(')
2142 return BFD_RELOC_UNUSED;
b99bd4ef 2143
c19d1205
ZW
2144 p = *str + 1;
2145 q = p;
2146
2147 while (*q && *q != ')' && *q != ',')
2148 q++;
2149 if (*q != ')')
2150 return -1;
2151
21d799b5
NC
2152 if ((r = (struct reloc_entry *)
2153 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2154 return -1;
2155
2156 *str = q + 1;
2157 return r->reloc;
b99bd4ef
NC
2158}
2159
c19d1205
ZW
2160/* Directives: register aliases. */
2161
dcbf9037 2162static struct reg_entry *
90ec0d68 2163insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2164{
d3ce72d0 2165 struct reg_entry *new_reg;
c19d1205 2166 const char *name;
b99bd4ef 2167
d3ce72d0 2168 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2169 {
d3ce72d0 2170 if (new_reg->builtin)
c19d1205 2171 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2172
c19d1205
ZW
2173 /* Only warn about a redefinition if it's not defined as the
2174 same register. */
d3ce72d0 2175 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2176 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2177
d929913e 2178 return NULL;
c19d1205 2179 }
b99bd4ef 2180
c19d1205 2181 name = xstrdup (str);
d3ce72d0 2182 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2183
d3ce72d0
NC
2184 new_reg->name = name;
2185 new_reg->number = number;
2186 new_reg->type = type;
2187 new_reg->builtin = FALSE;
2188 new_reg->neon = NULL;
b99bd4ef 2189
d3ce72d0 2190 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2191 abort ();
5f4273c7 2192
d3ce72d0 2193 return new_reg;
dcbf9037
JB
2194}
2195
2196static void
2197insert_neon_reg_alias (char *str, int number, int type,
477330fc 2198 struct neon_typed_alias *atype)
dcbf9037
JB
2199{
2200 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2201
dcbf9037
JB
2202 if (!reg)
2203 {
2204 first_error (_("attempt to redefine typed alias"));
2205 return;
2206 }
5f4273c7 2207
dcbf9037
JB
2208 if (atype)
2209 {
21d799b5 2210 reg->neon = (struct neon_typed_alias *)
477330fc 2211 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2212 *reg->neon = *atype;
2213 }
c19d1205 2214}
b99bd4ef 2215
c19d1205 2216/* Look for the .req directive. This is of the form:
b99bd4ef 2217
c19d1205 2218 new_register_name .req existing_register_name
b99bd4ef 2219
c19d1205 2220 If we find one, or if it looks sufficiently like one that we want to
d929913e 2221 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2222
d929913e 2223static bfd_boolean
c19d1205
ZW
2224create_register_alias (char * newname, char *p)
2225{
2226 struct reg_entry *old;
2227 char *oldname, *nbuf;
2228 size_t nlen;
b99bd4ef 2229
c19d1205
ZW
2230 /* The input scrubber ensures that whitespace after the mnemonic is
2231 collapsed to single spaces. */
2232 oldname = p;
2233 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2234 return FALSE;
b99bd4ef 2235
c19d1205
ZW
2236 oldname += 6;
2237 if (*oldname == '\0')
d929913e 2238 return FALSE;
b99bd4ef 2239
21d799b5 2240 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2241 if (!old)
b99bd4ef 2242 {
c19d1205 2243 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2244 return TRUE;
b99bd4ef
NC
2245 }
2246
c19d1205
ZW
2247 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2248 the desired alias name, and p points to its end. If not, then
2249 the desired alias name is in the global original_case_string. */
2250#ifdef TC_CASE_SENSITIVE
2251 nlen = p - newname;
2252#else
2253 newname = original_case_string;
2254 nlen = strlen (newname);
2255#endif
b99bd4ef 2256
21d799b5 2257 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2258 memcpy (nbuf, newname, nlen);
2259 nbuf[nlen] = '\0';
b99bd4ef 2260
c19d1205
ZW
2261 /* Create aliases under the new name as stated; an all-lowercase
2262 version of the new name; and an all-uppercase version of the new
2263 name. */
d929913e
NC
2264 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2265 {
2266 for (p = nbuf; *p; p++)
2267 *p = TOUPPER (*p);
c19d1205 2268
d929913e
NC
2269 if (strncmp (nbuf, newname, nlen))
2270 {
2271 /* If this attempt to create an additional alias fails, do not bother
2272 trying to create the all-lower case alias. We will fail and issue
2273 a second, duplicate error message. This situation arises when the
2274 programmer does something like:
2275 foo .req r0
2276 Foo .req r1
2277 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2278 the artificial FOO alias because it has already been created by the
d929913e
NC
2279 first .req. */
2280 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2281 return TRUE;
2282 }
c19d1205 2283
d929913e
NC
2284 for (p = nbuf; *p; p++)
2285 *p = TOLOWER (*p);
c19d1205 2286
d929913e
NC
2287 if (strncmp (nbuf, newname, nlen))
2288 insert_reg_alias (nbuf, old->number, old->type);
2289 }
c19d1205 2290
d929913e 2291 return TRUE;
b99bd4ef
NC
2292}
2293
dcbf9037
JB
2294/* Create a Neon typed/indexed register alias using directives, e.g.:
2295 X .dn d5.s32[1]
2296 Y .qn 6.s16
2297 Z .dn d7
2298 T .dn Z[0]
2299 These typed registers can be used instead of the types specified after the
2300 Neon mnemonic, so long as all operands given have types. Types can also be
2301 specified directly, e.g.:
5f4273c7 2302 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2303
c921be7d 2304static bfd_boolean
dcbf9037
JB
2305create_neon_reg_alias (char *newname, char *p)
2306{
2307 enum arm_reg_type basetype;
2308 struct reg_entry *basereg;
2309 struct reg_entry mybasereg;
2310 struct neon_type ntype;
2311 struct neon_typed_alias typeinfo;
12d6b0b7 2312 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2313 int namelen;
5f4273c7 2314
dcbf9037
JB
2315 typeinfo.defined = 0;
2316 typeinfo.eltype.type = NT_invtype;
2317 typeinfo.eltype.size = -1;
2318 typeinfo.index = -1;
5f4273c7 2319
dcbf9037 2320 nameend = p;
5f4273c7 2321
dcbf9037
JB
2322 if (strncmp (p, " .dn ", 5) == 0)
2323 basetype = REG_TYPE_VFD;
2324 else if (strncmp (p, " .qn ", 5) == 0)
2325 basetype = REG_TYPE_NQ;
2326 else
c921be7d 2327 return FALSE;
5f4273c7 2328
dcbf9037 2329 p += 5;
5f4273c7 2330
dcbf9037 2331 if (*p == '\0')
c921be7d 2332 return FALSE;
5f4273c7 2333
dcbf9037
JB
2334 basereg = arm_reg_parse_multi (&p);
2335
2336 if (basereg && basereg->type != basetype)
2337 {
2338 as_bad (_("bad type for register"));
c921be7d 2339 return FALSE;
dcbf9037
JB
2340 }
2341
2342 if (basereg == NULL)
2343 {
2344 expressionS exp;
2345 /* Try parsing as an integer. */
2346 my_get_expression (&exp, &p, GE_NO_PREFIX);
2347 if (exp.X_op != O_constant)
477330fc
RM
2348 {
2349 as_bad (_("expression must be constant"));
2350 return FALSE;
2351 }
dcbf9037
JB
2352 basereg = &mybasereg;
2353 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2354 : exp.X_add_number;
dcbf9037
JB
2355 basereg->neon = 0;
2356 }
2357
2358 if (basereg->neon)
2359 typeinfo = *basereg->neon;
2360
2361 if (parse_neon_type (&ntype, &p) == SUCCESS)
2362 {
2363 /* We got a type. */
2364 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2365 {
2366 as_bad (_("can't redefine the type of a register alias"));
2367 return FALSE;
2368 }
5f4273c7 2369
dcbf9037
JB
2370 typeinfo.defined |= NTA_HASTYPE;
2371 if (ntype.elems != 1)
477330fc
RM
2372 {
2373 as_bad (_("you must specify a single type only"));
2374 return FALSE;
2375 }
dcbf9037
JB
2376 typeinfo.eltype = ntype.el[0];
2377 }
5f4273c7 2378
dcbf9037
JB
2379 if (skip_past_char (&p, '[') == SUCCESS)
2380 {
2381 expressionS exp;
2382 /* We got a scalar index. */
5f4273c7 2383
dcbf9037 2384 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2385 {
2386 as_bad (_("can't redefine the index of a scalar alias"));
2387 return FALSE;
2388 }
5f4273c7 2389
dcbf9037 2390 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2391
dcbf9037 2392 if (exp.X_op != O_constant)
477330fc
RM
2393 {
2394 as_bad (_("scalar index must be constant"));
2395 return FALSE;
2396 }
5f4273c7 2397
dcbf9037
JB
2398 typeinfo.defined |= NTA_HASINDEX;
2399 typeinfo.index = exp.X_add_number;
5f4273c7 2400
dcbf9037 2401 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2402 {
2403 as_bad (_("expecting ]"));
2404 return FALSE;
2405 }
dcbf9037
JB
2406 }
2407
15735687
NS
2408 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2409 the desired alias name, and p points to its end. If not, then
2410 the desired alias name is in the global original_case_string. */
2411#ifdef TC_CASE_SENSITIVE
dcbf9037 2412 namelen = nameend - newname;
15735687
NS
2413#else
2414 newname = original_case_string;
2415 namelen = strlen (newname);
2416#endif
2417
21d799b5 2418 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2419 strncpy (namebuf, newname, namelen);
2420 namebuf[namelen] = '\0';
5f4273c7 2421
dcbf9037 2422 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2423 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2424
dcbf9037
JB
2425 /* Insert name in all uppercase. */
2426 for (p = namebuf; *p; p++)
2427 *p = TOUPPER (*p);
5f4273c7 2428
dcbf9037
JB
2429 if (strncmp (namebuf, newname, namelen))
2430 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2431 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2432
dcbf9037
JB
2433 /* Insert name in all lowercase. */
2434 for (p = namebuf; *p; p++)
2435 *p = TOLOWER (*p);
5f4273c7 2436
dcbf9037
JB
2437 if (strncmp (namebuf, newname, namelen))
2438 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2439 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2440
c921be7d 2441 return TRUE;
dcbf9037
JB
2442}
2443
c19d1205
ZW
2444/* Should never be called, as .req goes between the alias and the
2445 register name, not at the beginning of the line. */
c921be7d 2446
b99bd4ef 2447static void
c19d1205 2448s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2449{
c19d1205
ZW
2450 as_bad (_("invalid syntax for .req directive"));
2451}
b99bd4ef 2452
dcbf9037
JB
2453static void
2454s_dn (int a ATTRIBUTE_UNUSED)
2455{
2456 as_bad (_("invalid syntax for .dn directive"));
2457}
2458
2459static void
2460s_qn (int a ATTRIBUTE_UNUSED)
2461{
2462 as_bad (_("invalid syntax for .qn directive"));
2463}
2464
c19d1205
ZW
2465/* The .unreq directive deletes an alias which was previously defined
2466 by .req. For example:
b99bd4ef 2467
c19d1205
ZW
2468 my_alias .req r11
2469 .unreq my_alias */
b99bd4ef
NC
2470
2471static void
c19d1205 2472s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2473{
c19d1205
ZW
2474 char * name;
2475 char saved_char;
b99bd4ef 2476
c19d1205
ZW
2477 name = input_line_pointer;
2478
2479 while (*input_line_pointer != 0
2480 && *input_line_pointer != ' '
2481 && *input_line_pointer != '\n')
2482 ++input_line_pointer;
2483
2484 saved_char = *input_line_pointer;
2485 *input_line_pointer = 0;
2486
2487 if (!*name)
2488 as_bad (_("invalid syntax for .unreq directive"));
2489 else
2490 {
21d799b5 2491 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2492 name);
c19d1205
ZW
2493
2494 if (!reg)
2495 as_bad (_("unknown register alias '%s'"), name);
2496 else if (reg->builtin)
a1727c1a 2497 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2498 name);
2499 else
2500 {
d929913e
NC
2501 char * p;
2502 char * nbuf;
2503
db0bc284 2504 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2505 free ((char *) reg->name);
477330fc
RM
2506 if (reg->neon)
2507 free (reg->neon);
c19d1205 2508 free (reg);
d929913e
NC
2509
2510 /* Also locate the all upper case and all lower case versions.
2511 Do not complain if we cannot find one or the other as it
2512 was probably deleted above. */
5f4273c7 2513
d929913e
NC
2514 nbuf = strdup (name);
2515 for (p = nbuf; *p; p++)
2516 *p = TOUPPER (*p);
21d799b5 2517 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2518 if (reg)
2519 {
db0bc284 2520 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2521 free ((char *) reg->name);
2522 if (reg->neon)
2523 free (reg->neon);
2524 free (reg);
2525 }
2526
2527 for (p = nbuf; *p; p++)
2528 *p = TOLOWER (*p);
21d799b5 2529 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2530 if (reg)
2531 {
db0bc284 2532 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2533 free ((char *) reg->name);
2534 if (reg->neon)
2535 free (reg->neon);
2536 free (reg);
2537 }
2538
2539 free (nbuf);
c19d1205
ZW
2540 }
2541 }
b99bd4ef 2542
c19d1205 2543 *input_line_pointer = saved_char;
b99bd4ef
NC
2544 demand_empty_rest_of_line ();
2545}
2546
c19d1205
ZW
2547/* Directives: Instruction set selection. */
2548
2549#ifdef OBJ_ELF
2550/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2551 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2552 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2553 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2554
cd000bff
DJ
2555/* Create a new mapping symbol for the transition to STATE. */
2556
2557static void
2558make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2559{
a737bd4d 2560 symbolS * symbolP;
c19d1205
ZW
2561 const char * symname;
2562 int type;
b99bd4ef 2563
c19d1205 2564 switch (state)
b99bd4ef 2565 {
c19d1205
ZW
2566 case MAP_DATA:
2567 symname = "$d";
2568 type = BSF_NO_FLAGS;
2569 break;
2570 case MAP_ARM:
2571 symname = "$a";
2572 type = BSF_NO_FLAGS;
2573 break;
2574 case MAP_THUMB:
2575 symname = "$t";
2576 type = BSF_NO_FLAGS;
2577 break;
c19d1205
ZW
2578 default:
2579 abort ();
2580 }
2581
cd000bff 2582 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2583 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2584
2585 switch (state)
2586 {
2587 case MAP_ARM:
2588 THUMB_SET_FUNC (symbolP, 0);
2589 ARM_SET_THUMB (symbolP, 0);
2590 ARM_SET_INTERWORK (symbolP, support_interwork);
2591 break;
2592
2593 case MAP_THUMB:
2594 THUMB_SET_FUNC (symbolP, 1);
2595 ARM_SET_THUMB (symbolP, 1);
2596 ARM_SET_INTERWORK (symbolP, support_interwork);
2597 break;
2598
2599 case MAP_DATA:
2600 default:
cd000bff
DJ
2601 break;
2602 }
2603
2604 /* Save the mapping symbols for future reference. Also check that
2605 we do not place two mapping symbols at the same offset within a
2606 frag. We'll handle overlap between frags in
2de7820f
JZ
2607 check_mapping_symbols.
2608
2609 If .fill or other data filling directive generates zero sized data,
2610 the mapping symbol for the following code will have the same value
2611 as the one generated for the data filling directive. In this case,
2612 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2613 if (value == 0)
2614 {
2de7820f
JZ
2615 if (frag->tc_frag_data.first_map != NULL)
2616 {
2617 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2618 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2619 }
cd000bff
DJ
2620 frag->tc_frag_data.first_map = symbolP;
2621 }
2622 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2623 {
2624 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2625 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2626 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2627 }
cd000bff
DJ
2628 frag->tc_frag_data.last_map = symbolP;
2629}
2630
2631/* We must sometimes convert a region marked as code to data during
2632 code alignment, if an odd number of bytes have to be padded. The
2633 code mapping symbol is pushed to an aligned address. */
2634
2635static void
2636insert_data_mapping_symbol (enum mstate state,
2637 valueT value, fragS *frag, offsetT bytes)
2638{
2639 /* If there was already a mapping symbol, remove it. */
2640 if (frag->tc_frag_data.last_map != NULL
2641 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2642 {
2643 symbolS *symp = frag->tc_frag_data.last_map;
2644
2645 if (value == 0)
2646 {
2647 know (frag->tc_frag_data.first_map == symp);
2648 frag->tc_frag_data.first_map = NULL;
2649 }
2650 frag->tc_frag_data.last_map = NULL;
2651 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2652 }
cd000bff
DJ
2653
2654 make_mapping_symbol (MAP_DATA, value, frag);
2655 make_mapping_symbol (state, value + bytes, frag);
2656}
2657
2658static void mapping_state_2 (enum mstate state, int max_chars);
2659
2660/* Set the mapping state to STATE. Only call this when about to
2661 emit some STATE bytes to the file. */
2662
4e9aaefb 2663#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2664void
2665mapping_state (enum mstate state)
2666{
940b5ce0
DJ
2667 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2668
cd000bff
DJ
2669 if (mapstate == state)
2670 /* The mapping symbol has already been emitted.
2671 There is nothing else to do. */
2672 return;
49c62a33
NC
2673
2674 if (state == MAP_ARM || state == MAP_THUMB)
2675 /* PR gas/12931
2676 All ARM instructions require 4-byte alignment.
2677 (Almost) all Thumb instructions require 2-byte alignment.
2678
2679 When emitting instructions into any section, mark the section
2680 appropriately.
2681
2682 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2683 but themselves require 2-byte alignment; this applies to some
2684 PC- relative forms. However, these cases will invovle implicit
2685 literal pool generation or an explicit .align >=2, both of
2686 which will cause the section to me marked with sufficient
2687 alignment. Thus, we don't handle those cases here. */
2688 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2689
2690 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2691 /* This case will be evaluated later. */
cd000bff 2692 return;
cd000bff
DJ
2693
2694 mapping_state_2 (state, 0);
cd000bff
DJ
2695}
2696
2697/* Same as mapping_state, but MAX_CHARS bytes have already been
2698 allocated. Put the mapping symbol that far back. */
2699
2700static void
2701mapping_state_2 (enum mstate state, int max_chars)
2702{
940b5ce0
DJ
2703 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2704
2705 if (!SEG_NORMAL (now_seg))
2706 return;
2707
cd000bff
DJ
2708 if (mapstate == state)
2709 /* The mapping symbol has already been emitted.
2710 There is nothing else to do. */
2711 return;
2712
4e9aaefb
SA
2713 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2714 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2715 {
2716 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2717 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2718
2719 if (add_symbol)
2720 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2721 }
2722
cd000bff
DJ
2723 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2724 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2725}
4e9aaefb 2726#undef TRANSITION
c19d1205 2727#else
d3106081
NS
2728#define mapping_state(x) ((void)0)
2729#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2730#endif
2731
2732/* Find the real, Thumb encoded start of a Thumb function. */
2733
4343666d 2734#ifdef OBJ_COFF
c19d1205
ZW
2735static symbolS *
2736find_real_start (symbolS * symbolP)
2737{
2738 char * real_start;
2739 const char * name = S_GET_NAME (symbolP);
2740 symbolS * new_target;
2741
2742 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2743#define STUB_NAME ".real_start_of"
2744
2745 if (name == NULL)
2746 abort ();
2747
37f6032b
ZW
2748 /* The compiler may generate BL instructions to local labels because
2749 it needs to perform a branch to a far away location. These labels
2750 do not have a corresponding ".real_start_of" label. We check
2751 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2752 the ".real_start_of" convention for nonlocal branches. */
2753 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2754 return symbolP;
2755
37f6032b 2756 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2757 new_target = symbol_find (real_start);
2758
2759 if (new_target == NULL)
2760 {
bd3ba5d1 2761 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2762 new_target = symbolP;
2763 }
2764
c19d1205
ZW
2765 return new_target;
2766}
4343666d 2767#endif
c19d1205
ZW
2768
2769static void
2770opcode_select (int width)
2771{
2772 switch (width)
2773 {
2774 case 16:
2775 if (! thumb_mode)
2776 {
e74cfd16 2777 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2778 as_bad (_("selected processor does not support THUMB opcodes"));
2779
2780 thumb_mode = 1;
2781 /* No need to force the alignment, since we will have been
2782 coming from ARM mode, which is word-aligned. */
2783 record_alignment (now_seg, 1);
2784 }
c19d1205
ZW
2785 break;
2786
2787 case 32:
2788 if (thumb_mode)
2789 {
e74cfd16 2790 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2791 as_bad (_("selected processor does not support ARM opcodes"));
2792
2793 thumb_mode = 0;
2794
2795 if (!need_pass_2)
2796 frag_align (2, 0, 0);
2797
2798 record_alignment (now_seg, 1);
2799 }
c19d1205
ZW
2800 break;
2801
2802 default:
2803 as_bad (_("invalid instruction size selected (%d)"), width);
2804 }
2805}
2806
2807static void
2808s_arm (int ignore ATTRIBUTE_UNUSED)
2809{
2810 opcode_select (32);
2811 demand_empty_rest_of_line ();
2812}
2813
2814static void
2815s_thumb (int ignore ATTRIBUTE_UNUSED)
2816{
2817 opcode_select (16);
2818 demand_empty_rest_of_line ();
2819}
2820
2821static void
2822s_code (int unused ATTRIBUTE_UNUSED)
2823{
2824 int temp;
2825
2826 temp = get_absolute_expression ();
2827 switch (temp)
2828 {
2829 case 16:
2830 case 32:
2831 opcode_select (temp);
2832 break;
2833
2834 default:
2835 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2836 }
2837}
2838
2839static void
2840s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2841{
2842 /* If we are not already in thumb mode go into it, EVEN if
2843 the target processor does not support thumb instructions.
2844 This is used by gcc/config/arm/lib1funcs.asm for example
2845 to compile interworking support functions even if the
2846 target processor should not support interworking. */
2847 if (! thumb_mode)
2848 {
2849 thumb_mode = 2;
2850 record_alignment (now_seg, 1);
2851 }
2852
2853 demand_empty_rest_of_line ();
2854}
2855
2856static void
2857s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2858{
2859 s_thumb (0);
2860
2861 /* The following label is the name/address of the start of a Thumb function.
2862 We need to know this for the interworking support. */
2863 label_is_thumb_function_name = TRUE;
2864}
2865
2866/* Perform a .set directive, but also mark the alias as
2867 being a thumb function. */
2868
2869static void
2870s_thumb_set (int equiv)
2871{
2872 /* XXX the following is a duplicate of the code for s_set() in read.c
2873 We cannot just call that code as we need to get at the symbol that
2874 is created. */
2875 char * name;
2876 char delim;
2877 char * end_name;
2878 symbolS * symbolP;
2879
2880 /* Especial apologies for the random logic:
2881 This just grew, and could be parsed much more simply!
2882 Dean - in haste. */
d02603dc 2883 delim = get_symbol_name (& name);
c19d1205 2884 end_name = input_line_pointer;
d02603dc 2885 (void) restore_line_pointer (delim);
c19d1205
ZW
2886
2887 if (*input_line_pointer != ',')
2888 {
2889 *end_name = 0;
2890 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2891 *end_name = delim;
2892 ignore_rest_of_line ();
2893 return;
2894 }
2895
2896 input_line_pointer++;
2897 *end_name = 0;
2898
2899 if (name[0] == '.' && name[1] == '\0')
2900 {
2901 /* XXX - this should not happen to .thumb_set. */
2902 abort ();
2903 }
2904
2905 if ((symbolP = symbol_find (name)) == NULL
2906 && (symbolP = md_undefined_symbol (name)) == NULL)
2907 {
2908#ifndef NO_LISTING
2909 /* When doing symbol listings, play games with dummy fragments living
2910 outside the normal fragment chain to record the file and line info
c19d1205 2911 for this symbol. */
b99bd4ef
NC
2912 if (listing & LISTING_SYMBOLS)
2913 {
2914 extern struct list_info_struct * listing_tail;
21d799b5 2915 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2916
2917 memset (dummy_frag, 0, sizeof (fragS));
2918 dummy_frag->fr_type = rs_fill;
2919 dummy_frag->line = listing_tail;
2920 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2921 dummy_frag->fr_symbol = symbolP;
2922 }
2923 else
2924#endif
2925 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2926
2927#ifdef OBJ_COFF
2928 /* "set" symbols are local unless otherwise specified. */
2929 SF_SET_LOCAL (symbolP);
2930#endif /* OBJ_COFF */
2931 } /* Make a new symbol. */
2932
2933 symbol_table_insert (symbolP);
2934
2935 * end_name = delim;
2936
2937 if (equiv
2938 && S_IS_DEFINED (symbolP)
2939 && S_GET_SEGMENT (symbolP) != reg_section)
2940 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2941
2942 pseudo_set (symbolP);
2943
2944 demand_empty_rest_of_line ();
2945
c19d1205 2946 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2947
2948 THUMB_SET_FUNC (symbolP, 1);
2949 ARM_SET_THUMB (symbolP, 1);
2950#if defined OBJ_ELF || defined OBJ_COFF
2951 ARM_SET_INTERWORK (symbolP, support_interwork);
2952#endif
2953}
2954
c19d1205 2955/* Directives: Mode selection. */
b99bd4ef 2956
c19d1205
ZW
2957/* .syntax [unified|divided] - choose the new unified syntax
2958 (same for Arm and Thumb encoding, modulo slight differences in what
2959 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2960static void
c19d1205 2961s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2962{
c19d1205
ZW
2963 char *name, delim;
2964
d02603dc 2965 delim = get_symbol_name (& name);
c19d1205
ZW
2966
2967 if (!strcasecmp (name, "unified"))
2968 unified_syntax = TRUE;
2969 else if (!strcasecmp (name, "divided"))
2970 unified_syntax = FALSE;
2971 else
2972 {
2973 as_bad (_("unrecognized syntax mode \"%s\""), name);
2974 return;
2975 }
d02603dc 2976 (void) restore_line_pointer (delim);
b99bd4ef
NC
2977 demand_empty_rest_of_line ();
2978}
2979
c19d1205
ZW
2980/* Directives: sectioning and alignment. */
2981
c19d1205
ZW
2982static void
2983s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2984{
c19d1205
ZW
2985 /* We don't support putting frags in the BSS segment, we fake it by
2986 marking in_bss, then looking at s_skip for clues. */
2987 subseg_set (bss_section, 0);
2988 demand_empty_rest_of_line ();
cd000bff
DJ
2989
2990#ifdef md_elf_section_change_hook
2991 md_elf_section_change_hook ();
2992#endif
c19d1205 2993}
b99bd4ef 2994
c19d1205
ZW
2995static void
2996s_even (int ignore ATTRIBUTE_UNUSED)
2997{
2998 /* Never make frag if expect extra pass. */
2999 if (!need_pass_2)
3000 frag_align (1, 0, 0);
b99bd4ef 3001
c19d1205 3002 record_alignment (now_seg, 1);
b99bd4ef 3003
c19d1205 3004 demand_empty_rest_of_line ();
b99bd4ef
NC
3005}
3006
2e6976a8
DG
3007/* Directives: CodeComposer Studio. */
3008
3009/* .ref (for CodeComposer Studio syntax only). */
3010static void
3011s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3012{
3013 if (codecomposer_syntax)
3014 ignore_rest_of_line ();
3015 else
3016 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3017}
3018
3019/* If name is not NULL, then it is used for marking the beginning of a
3020 function, wherease if it is NULL then it means the function end. */
3021static void
3022asmfunc_debug (const char * name)
3023{
3024 static const char * last_name = NULL;
3025
3026 if (name != NULL)
3027 {
3028 gas_assert (last_name == NULL);
3029 last_name = name;
3030
3031 if (debug_type == DEBUG_STABS)
3032 stabs_generate_asm_func (name, name);
3033 }
3034 else
3035 {
3036 gas_assert (last_name != NULL);
3037
3038 if (debug_type == DEBUG_STABS)
3039 stabs_generate_asm_endfunc (last_name, last_name);
3040
3041 last_name = NULL;
3042 }
3043}
3044
3045static void
3046s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3047{
3048 if (codecomposer_syntax)
3049 {
3050 switch (asmfunc_state)
3051 {
3052 case OUTSIDE_ASMFUNC:
3053 asmfunc_state = WAITING_ASMFUNC_NAME;
3054 break;
3055
3056 case WAITING_ASMFUNC_NAME:
3057 as_bad (_(".asmfunc repeated."));
3058 break;
3059
3060 case WAITING_ENDASMFUNC:
3061 as_bad (_(".asmfunc without function."));
3062 break;
3063 }
3064 demand_empty_rest_of_line ();
3065 }
3066 else
3067 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3068}
3069
3070static void
3071s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3072{
3073 if (codecomposer_syntax)
3074 {
3075 switch (asmfunc_state)
3076 {
3077 case OUTSIDE_ASMFUNC:
3078 as_bad (_(".endasmfunc without a .asmfunc."));
3079 break;
3080
3081 case WAITING_ASMFUNC_NAME:
3082 as_bad (_(".endasmfunc without function."));
3083 break;
3084
3085 case WAITING_ENDASMFUNC:
3086 asmfunc_state = OUTSIDE_ASMFUNC;
3087 asmfunc_debug (NULL);
3088 break;
3089 }
3090 demand_empty_rest_of_line ();
3091 }
3092 else
3093 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3094}
3095
3096static void
3097s_ccs_def (int name)
3098{
3099 if (codecomposer_syntax)
3100 s_globl (name);
3101 else
3102 as_bad (_(".def pseudo-op only available with -mccs flag."));
3103}
3104
c19d1205 3105/* Directives: Literal pools. */
a737bd4d 3106
c19d1205
ZW
3107static literal_pool *
3108find_literal_pool (void)
a737bd4d 3109{
c19d1205 3110 literal_pool * pool;
a737bd4d 3111
c19d1205 3112 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3113 {
c19d1205
ZW
3114 if (pool->section == now_seg
3115 && pool->sub_section == now_subseg)
3116 break;
a737bd4d
NC
3117 }
3118
c19d1205 3119 return pool;
a737bd4d
NC
3120}
3121
c19d1205
ZW
3122static literal_pool *
3123find_or_make_literal_pool (void)
a737bd4d 3124{
c19d1205
ZW
3125 /* Next literal pool ID number. */
3126 static unsigned int latest_pool_num = 1;
3127 literal_pool * pool;
a737bd4d 3128
c19d1205 3129 pool = find_literal_pool ();
a737bd4d 3130
c19d1205 3131 if (pool == NULL)
a737bd4d 3132 {
c19d1205 3133 /* Create a new pool. */
21d799b5 3134 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3135 if (! pool)
3136 return NULL;
a737bd4d 3137
c19d1205
ZW
3138 pool->next_free_entry = 0;
3139 pool->section = now_seg;
3140 pool->sub_section = now_subseg;
3141 pool->next = list_of_pools;
3142 pool->symbol = NULL;
8335d6aa 3143 pool->alignment = 2;
c19d1205
ZW
3144
3145 /* Add it to the list. */
3146 list_of_pools = pool;
a737bd4d 3147 }
a737bd4d 3148
c19d1205
ZW
3149 /* New pools, and emptied pools, will have a NULL symbol. */
3150 if (pool->symbol == NULL)
a737bd4d 3151 {
c19d1205
ZW
3152 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3153 (valueT) 0, &zero_address_frag);
3154 pool->id = latest_pool_num ++;
a737bd4d
NC
3155 }
3156
c19d1205
ZW
3157 /* Done. */
3158 return pool;
a737bd4d
NC
3159}
3160
c19d1205 3161/* Add the literal in the global 'inst'
5f4273c7 3162 structure to the relevant literal pool. */
b99bd4ef
NC
3163
3164static int
8335d6aa 3165add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3166{
8335d6aa
JW
3167#define PADDING_SLOT 0x1
3168#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3169 literal_pool * pool;
8335d6aa
JW
3170 unsigned int entry, pool_size = 0;
3171 bfd_boolean padding_slot_p = FALSE;
e56c722b 3172 unsigned imm1 = 0;
8335d6aa
JW
3173 unsigned imm2 = 0;
3174
3175 if (nbytes == 8)
3176 {
3177 imm1 = inst.operands[1].imm;
3178 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3179 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3180 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3181 if (target_big_endian)
3182 {
3183 imm1 = imm2;
3184 imm2 = inst.operands[1].imm;
3185 }
3186 }
b99bd4ef 3187
c19d1205
ZW
3188 pool = find_or_make_literal_pool ();
3189
3190 /* Check if this literal value is already in the pool. */
3191 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3192 {
8335d6aa
JW
3193 if (nbytes == 4)
3194 {
3195 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3196 && (inst.reloc.exp.X_op == O_constant)
3197 && (pool->literals[entry].X_add_number
3198 == inst.reloc.exp.X_add_number)
3199 && (pool->literals[entry].X_md == nbytes)
3200 && (pool->literals[entry].X_unsigned
3201 == inst.reloc.exp.X_unsigned))
3202 break;
3203
3204 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3205 && (inst.reloc.exp.X_op == O_symbol)
3206 && (pool->literals[entry].X_add_number
3207 == inst.reloc.exp.X_add_number)
3208 && (pool->literals[entry].X_add_symbol
3209 == inst.reloc.exp.X_add_symbol)
3210 && (pool->literals[entry].X_op_symbol
3211 == inst.reloc.exp.X_op_symbol)
3212 && (pool->literals[entry].X_md == nbytes))
3213 break;
3214 }
3215 else if ((nbytes == 8)
3216 && !(pool_size & 0x7)
3217 && ((entry + 1) != pool->next_free_entry)
3218 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3219 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3220 && (pool->literals[entry].X_unsigned
3221 == inst.reloc.exp.X_unsigned)
3222 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3223 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3224 && (pool->literals[entry + 1].X_unsigned
3225 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3226 break;
3227
8335d6aa
JW
3228 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3229 if (padding_slot_p && (nbytes == 4))
c19d1205 3230 break;
8335d6aa
JW
3231
3232 pool_size += 4;
b99bd4ef
NC
3233 }
3234
c19d1205
ZW
3235 /* Do we need to create a new entry? */
3236 if (entry == pool->next_free_entry)
3237 {
3238 if (entry >= MAX_LITERAL_POOL_SIZE)
3239 {
3240 inst.error = _("literal pool overflow");
3241 return FAIL;
3242 }
3243
8335d6aa
JW
3244 if (nbytes == 8)
3245 {
3246 /* For 8-byte entries, we align to an 8-byte boundary,
3247 and split it into two 4-byte entries, because on 32-bit
3248 host, 8-byte constants are treated as big num, thus
3249 saved in "generic_bignum" which will be overwritten
3250 by later assignments.
3251
3252 We also need to make sure there is enough space for
3253 the split.
3254
3255 We also check to make sure the literal operand is a
3256 constant number. */
19f2f6a9
JW
3257 if (!(inst.reloc.exp.X_op == O_constant
3258 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3259 {
3260 inst.error = _("invalid type for literal pool");
3261 return FAIL;
3262 }
3263 else if (pool_size & 0x7)
3264 {
3265 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3266 {
3267 inst.error = _("literal pool overflow");
3268 return FAIL;
3269 }
3270
3271 pool->literals[entry] = inst.reloc.exp;
3272 pool->literals[entry].X_add_number = 0;
3273 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3274 pool->next_free_entry += 1;
3275 pool_size += 4;
3276 }
3277 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3278 {
3279 inst.error = _("literal pool overflow");
3280 return FAIL;
3281 }
3282
3283 pool->literals[entry] = inst.reloc.exp;
3284 pool->literals[entry].X_op = O_constant;
3285 pool->literals[entry].X_add_number = imm1;
3286 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3287 pool->literals[entry++].X_md = 4;
3288 pool->literals[entry] = inst.reloc.exp;
3289 pool->literals[entry].X_op = O_constant;
3290 pool->literals[entry].X_add_number = imm2;
3291 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3292 pool->literals[entry].X_md = 4;
3293 pool->alignment = 3;
3294 pool->next_free_entry += 1;
3295 }
3296 else
3297 {
3298 pool->literals[entry] = inst.reloc.exp;
3299 pool->literals[entry].X_md = 4;
3300 }
3301
a8040cf2
NC
3302#ifdef OBJ_ELF
3303 /* PR ld/12974: Record the location of the first source line to reference
3304 this entry in the literal pool. If it turns out during linking that the
3305 symbol does not exist we will be able to give an accurate line number for
3306 the (first use of the) missing reference. */
3307 if (debug_type == DEBUG_DWARF2)
3308 dwarf2_where (pool->locs + entry);
3309#endif
c19d1205
ZW
3310 pool->next_free_entry += 1;
3311 }
8335d6aa
JW
3312 else if (padding_slot_p)
3313 {
3314 pool->literals[entry] = inst.reloc.exp;
3315 pool->literals[entry].X_md = nbytes;
3316 }
b99bd4ef 3317
c19d1205 3318 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3319 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3320 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3321
c19d1205 3322 return SUCCESS;
b99bd4ef
NC
3323}
3324
2e6976a8 3325bfd_boolean
2e57ce7b 3326tc_start_label_without_colon (void)
2e6976a8
DG
3327{
3328 bfd_boolean ret = TRUE;
3329
3330 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3331 {
2e57ce7b 3332 const char *label = input_line_pointer;
2e6976a8
DG
3333
3334 while (!is_end_of_line[(int) label[-1]])
3335 --label;
3336
3337 if (*label == '.')
3338 {
3339 as_bad (_("Invalid label '%s'"), label);
3340 ret = FALSE;
3341 }
3342
3343 asmfunc_debug (label);
3344
3345 asmfunc_state = WAITING_ENDASMFUNC;
3346 }
3347
3348 return ret;
3349}
3350
c19d1205
ZW
3351/* Can't use symbol_new here, so have to create a symbol and then at
3352 a later date assign it a value. Thats what these functions do. */
e16bb312 3353
c19d1205
ZW
3354static void
3355symbol_locate (symbolS * symbolP,
3356 const char * name, /* It is copied, the caller can modify. */
3357 segT segment, /* Segment identifier (SEG_<something>). */
3358 valueT valu, /* Symbol value. */
3359 fragS * frag) /* Associated fragment. */
3360{
e57e6ddc 3361 size_t name_length;
c19d1205 3362 char * preserved_copy_of_name;
e16bb312 3363
c19d1205
ZW
3364 name_length = strlen (name) + 1; /* +1 for \0. */
3365 obstack_grow (&notes, name, name_length);
21d799b5 3366 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3367
c19d1205
ZW
3368#ifdef tc_canonicalize_symbol_name
3369 preserved_copy_of_name =
3370 tc_canonicalize_symbol_name (preserved_copy_of_name);
3371#endif
b99bd4ef 3372
c19d1205 3373 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3374
c19d1205
ZW
3375 S_SET_SEGMENT (symbolP, segment);
3376 S_SET_VALUE (symbolP, valu);
3377 symbol_clear_list_pointers (symbolP);
b99bd4ef 3378
c19d1205 3379 symbol_set_frag (symbolP, frag);
b99bd4ef 3380
c19d1205
ZW
3381 /* Link to end of symbol chain. */
3382 {
3383 extern int symbol_table_frozen;
b99bd4ef 3384
c19d1205
ZW
3385 if (symbol_table_frozen)
3386 abort ();
3387 }
b99bd4ef 3388
c19d1205 3389 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3390
c19d1205 3391 obj_symbol_new_hook (symbolP);
b99bd4ef 3392
c19d1205
ZW
3393#ifdef tc_symbol_new_hook
3394 tc_symbol_new_hook (symbolP);
3395#endif
3396
3397#ifdef DEBUG_SYMS
3398 verify_symbol_chain (symbol_rootP, symbol_lastP);
3399#endif /* DEBUG_SYMS */
b99bd4ef
NC
3400}
3401
c19d1205
ZW
3402static void
3403s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3404{
c19d1205
ZW
3405 unsigned int entry;
3406 literal_pool * pool;
3407 char sym_name[20];
b99bd4ef 3408
c19d1205
ZW
3409 pool = find_literal_pool ();
3410 if (pool == NULL
3411 || pool->symbol == NULL
3412 || pool->next_free_entry == 0)
3413 return;
b99bd4ef 3414
c19d1205
ZW
3415 /* Align pool as you have word accesses.
3416 Only make a frag if we have to. */
3417 if (!need_pass_2)
8335d6aa 3418 frag_align (pool->alignment, 0, 0);
b99bd4ef 3419
c19d1205 3420 record_alignment (now_seg, 2);
b99bd4ef 3421
aaca88ef 3422#ifdef OBJ_ELF
47fc6e36
WN
3423 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3424 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3425#endif
c19d1205 3426 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3427
c19d1205
ZW
3428 symbol_locate (pool->symbol, sym_name, now_seg,
3429 (valueT) frag_now_fix (), frag_now);
3430 symbol_table_insert (pool->symbol);
b99bd4ef 3431
c19d1205 3432 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3433
c19d1205
ZW
3434#if defined OBJ_COFF || defined OBJ_ELF
3435 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3436#endif
6c43fab6 3437
c19d1205 3438 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3439 {
3440#ifdef OBJ_ELF
3441 if (debug_type == DEBUG_DWARF2)
3442 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3443#endif
3444 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3445 emit_expr (&(pool->literals[entry]),
3446 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3447 }
b99bd4ef 3448
c19d1205
ZW
3449 /* Mark the pool as empty. */
3450 pool->next_free_entry = 0;
3451 pool->symbol = NULL;
b99bd4ef
NC
3452}
3453
c19d1205
ZW
3454#ifdef OBJ_ELF
3455/* Forward declarations for functions below, in the MD interface
3456 section. */
3457static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3458static valueT create_unwind_entry (int);
3459static void start_unwind_section (const segT, int);
3460static void add_unwind_opcode (valueT, int);
3461static void flush_pending_unwind (void);
b99bd4ef 3462
c19d1205 3463/* Directives: Data. */
b99bd4ef 3464
c19d1205
ZW
3465static void
3466s_arm_elf_cons (int nbytes)
3467{
3468 expressionS exp;
b99bd4ef 3469
c19d1205
ZW
3470#ifdef md_flush_pending_output
3471 md_flush_pending_output ();
3472#endif
b99bd4ef 3473
c19d1205 3474 if (is_it_end_of_statement ())
b99bd4ef 3475 {
c19d1205
ZW
3476 demand_empty_rest_of_line ();
3477 return;
b99bd4ef
NC
3478 }
3479
c19d1205
ZW
3480#ifdef md_cons_align
3481 md_cons_align (nbytes);
3482#endif
b99bd4ef 3483
c19d1205
ZW
3484 mapping_state (MAP_DATA);
3485 do
b99bd4ef 3486 {
c19d1205
ZW
3487 int reloc;
3488 char *base = input_line_pointer;
b99bd4ef 3489
c19d1205 3490 expression (& exp);
b99bd4ef 3491
c19d1205
ZW
3492 if (exp.X_op != O_symbol)
3493 emit_expr (&exp, (unsigned int) nbytes);
3494 else
3495 {
3496 char *before_reloc = input_line_pointer;
3497 reloc = parse_reloc (&input_line_pointer);
3498 if (reloc == -1)
3499 {
3500 as_bad (_("unrecognized relocation suffix"));
3501 ignore_rest_of_line ();
3502 return;
3503 }
3504 else if (reloc == BFD_RELOC_UNUSED)
3505 emit_expr (&exp, (unsigned int) nbytes);
3506 else
3507 {
21d799b5 3508 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3509 bfd_reloc_type_lookup (stdoutput,
3510 (bfd_reloc_code_real_type) reloc);
c19d1205 3511 int size = bfd_get_reloc_size (howto);
b99bd4ef 3512
2fc8bdac
ZW
3513 if (reloc == BFD_RELOC_ARM_PLT32)
3514 {
3515 as_bad (_("(plt) is only valid on branch targets"));
3516 reloc = BFD_RELOC_UNUSED;
3517 size = 0;
3518 }
3519
c19d1205 3520 if (size > nbytes)
2fc8bdac 3521 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3522 howto->name, nbytes);
3523 else
3524 {
3525 /* We've parsed an expression stopping at O_symbol.
3526 But there may be more expression left now that we
3527 have parsed the relocation marker. Parse it again.
3528 XXX Surely there is a cleaner way to do this. */
3529 char *p = input_line_pointer;
3530 int offset;
21d799b5 3531 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3532 memcpy (save_buf, base, input_line_pointer - base);
3533 memmove (base + (input_line_pointer - before_reloc),
3534 base, before_reloc - base);
3535
3536 input_line_pointer = base + (input_line_pointer-before_reloc);
3537 expression (&exp);
3538 memcpy (base, save_buf, p - base);
3539
3540 offset = nbytes - size;
4b1a927e
AM
3541 p = frag_more (nbytes);
3542 memset (p, 0, nbytes);
c19d1205 3543 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3544 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3545 }
3546 }
3547 }
b99bd4ef 3548 }
c19d1205 3549 while (*input_line_pointer++ == ',');
b99bd4ef 3550
c19d1205
ZW
3551 /* Put terminator back into stream. */
3552 input_line_pointer --;
3553 demand_empty_rest_of_line ();
b99bd4ef
NC
3554}
3555
c921be7d
NC
3556/* Emit an expression containing a 32-bit thumb instruction.
3557 Implementation based on put_thumb32_insn. */
3558
3559static void
3560emit_thumb32_expr (expressionS * exp)
3561{
3562 expressionS exp_high = *exp;
3563
3564 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3565 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3566 exp->X_add_number &= 0xffff;
3567 emit_expr (exp, (unsigned int) THUMB_SIZE);
3568}
3569
3570/* Guess the instruction size based on the opcode. */
3571
3572static int
3573thumb_insn_size (int opcode)
3574{
3575 if ((unsigned int) opcode < 0xe800u)
3576 return 2;
3577 else if ((unsigned int) opcode >= 0xe8000000u)
3578 return 4;
3579 else
3580 return 0;
3581}
3582
3583static bfd_boolean
3584emit_insn (expressionS *exp, int nbytes)
3585{
3586 int size = 0;
3587
3588 if (exp->X_op == O_constant)
3589 {
3590 size = nbytes;
3591
3592 if (size == 0)
3593 size = thumb_insn_size (exp->X_add_number);
3594
3595 if (size != 0)
3596 {
3597 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3598 {
3599 as_bad (_(".inst.n operand too big. "\
3600 "Use .inst.w instead"));
3601 size = 0;
3602 }
3603 else
3604 {
3605 if (now_it.state == AUTOMATIC_IT_BLOCK)
3606 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3607 else
3608 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3609
3610 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3611 emit_thumb32_expr (exp);
3612 else
3613 emit_expr (exp, (unsigned int) size);
3614
3615 it_fsm_post_encode ();
3616 }
3617 }
3618 else
3619 as_bad (_("cannot determine Thumb instruction size. " \
3620 "Use .inst.n/.inst.w instead"));
3621 }
3622 else
3623 as_bad (_("constant expression required"));
3624
3625 return (size != 0);
3626}
3627
3628/* Like s_arm_elf_cons but do not use md_cons_align and
3629 set the mapping state to MAP_ARM/MAP_THUMB. */
3630
3631static void
3632s_arm_elf_inst (int nbytes)
3633{
3634 if (is_it_end_of_statement ())
3635 {
3636 demand_empty_rest_of_line ();
3637 return;
3638 }
3639
3640 /* Calling mapping_state () here will not change ARM/THUMB,
3641 but will ensure not to be in DATA state. */
3642
3643 if (thumb_mode)
3644 mapping_state (MAP_THUMB);
3645 else
3646 {
3647 if (nbytes != 0)
3648 {
3649 as_bad (_("width suffixes are invalid in ARM mode"));
3650 ignore_rest_of_line ();
3651 return;
3652 }
3653
3654 nbytes = 4;
3655
3656 mapping_state (MAP_ARM);
3657 }
3658
3659 do
3660 {
3661 expressionS exp;
3662
3663 expression (& exp);
3664
3665 if (! emit_insn (& exp, nbytes))
3666 {
3667 ignore_rest_of_line ();
3668 return;
3669 }
3670 }
3671 while (*input_line_pointer++ == ',');
3672
3673 /* Put terminator back into stream. */
3674 input_line_pointer --;
3675 demand_empty_rest_of_line ();
3676}
b99bd4ef 3677
c19d1205 3678/* Parse a .rel31 directive. */
b99bd4ef 3679
c19d1205
ZW
3680static void
3681s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3682{
3683 expressionS exp;
3684 char *p;
3685 valueT highbit;
b99bd4ef 3686
c19d1205
ZW
3687 highbit = 0;
3688 if (*input_line_pointer == '1')
3689 highbit = 0x80000000;
3690 else if (*input_line_pointer != '0')
3691 as_bad (_("expected 0 or 1"));
b99bd4ef 3692
c19d1205
ZW
3693 input_line_pointer++;
3694 if (*input_line_pointer != ',')
3695 as_bad (_("missing comma"));
3696 input_line_pointer++;
b99bd4ef 3697
c19d1205
ZW
3698#ifdef md_flush_pending_output
3699 md_flush_pending_output ();
3700#endif
b99bd4ef 3701
c19d1205
ZW
3702#ifdef md_cons_align
3703 md_cons_align (4);
3704#endif
b99bd4ef 3705
c19d1205 3706 mapping_state (MAP_DATA);
b99bd4ef 3707
c19d1205 3708 expression (&exp);
b99bd4ef 3709
c19d1205
ZW
3710 p = frag_more (4);
3711 md_number_to_chars (p, highbit, 4);
3712 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3713 BFD_RELOC_ARM_PREL31);
b99bd4ef 3714
c19d1205 3715 demand_empty_rest_of_line ();
b99bd4ef
NC
3716}
3717
c19d1205 3718/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3719
c19d1205 3720/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3721
c19d1205
ZW
3722static void
3723s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3724{
3725 demand_empty_rest_of_line ();
921e5f0a
PB
3726 if (unwind.proc_start)
3727 {
c921be7d 3728 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3729 return;
3730 }
3731
c19d1205
ZW
3732 /* Mark the start of the function. */
3733 unwind.proc_start = expr_build_dot ();
b99bd4ef 3734
c19d1205
ZW
3735 /* Reset the rest of the unwind info. */
3736 unwind.opcode_count = 0;
3737 unwind.table_entry = NULL;
3738 unwind.personality_routine = NULL;
3739 unwind.personality_index = -1;
3740 unwind.frame_size = 0;
3741 unwind.fp_offset = 0;
fdfde340 3742 unwind.fp_reg = REG_SP;
c19d1205
ZW
3743 unwind.fp_used = 0;
3744 unwind.sp_restored = 0;
3745}
b99bd4ef 3746
b99bd4ef 3747
c19d1205
ZW
3748/* Parse a handlerdata directive. Creates the exception handling table entry
3749 for the function. */
b99bd4ef 3750
c19d1205
ZW
3751static void
3752s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3753{
3754 demand_empty_rest_of_line ();
921e5f0a 3755 if (!unwind.proc_start)
c921be7d 3756 as_bad (MISSING_FNSTART);
921e5f0a 3757
c19d1205 3758 if (unwind.table_entry)
6decc662 3759 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3760
c19d1205
ZW
3761 create_unwind_entry (1);
3762}
a737bd4d 3763
c19d1205 3764/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3765
c19d1205
ZW
3766static void
3767s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3768{
3769 long where;
3770 char *ptr;
3771 valueT val;
940b5ce0 3772 unsigned int marked_pr_dependency;
f02232aa 3773
c19d1205 3774 demand_empty_rest_of_line ();
f02232aa 3775
921e5f0a
PB
3776 if (!unwind.proc_start)
3777 {
c921be7d 3778 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3779 return;
3780 }
3781
c19d1205
ZW
3782 /* Add eh table entry. */
3783 if (unwind.table_entry == NULL)
3784 val = create_unwind_entry (0);
3785 else
3786 val = 0;
f02232aa 3787
c19d1205
ZW
3788 /* Add index table entry. This is two words. */
3789 start_unwind_section (unwind.saved_seg, 1);
3790 frag_align (2, 0, 0);
3791 record_alignment (now_seg, 2);
b99bd4ef 3792
c19d1205 3793 ptr = frag_more (8);
5011093d 3794 memset (ptr, 0, 8);
c19d1205 3795 where = frag_now_fix () - 8;
f02232aa 3796
c19d1205
ZW
3797 /* Self relative offset of the function start. */
3798 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3799 BFD_RELOC_ARM_PREL31);
f02232aa 3800
c19d1205
ZW
3801 /* Indicate dependency on EHABI-defined personality routines to the
3802 linker, if it hasn't been done already. */
940b5ce0
DJ
3803 marked_pr_dependency
3804 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3805 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3806 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3807 {
5f4273c7
NC
3808 static const char *const name[] =
3809 {
3810 "__aeabi_unwind_cpp_pr0",
3811 "__aeabi_unwind_cpp_pr1",
3812 "__aeabi_unwind_cpp_pr2"
3813 };
c19d1205
ZW
3814 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3815 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3816 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3817 |= 1 << unwind.personality_index;
c19d1205 3818 }
f02232aa 3819
c19d1205
ZW
3820 if (val)
3821 /* Inline exception table entry. */
3822 md_number_to_chars (ptr + 4, val, 4);
3823 else
3824 /* Self relative offset of the table entry. */
3825 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3826 BFD_RELOC_ARM_PREL31);
f02232aa 3827
c19d1205
ZW
3828 /* Restore the original section. */
3829 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3830
3831 unwind.proc_start = NULL;
c19d1205 3832}
f02232aa 3833
f02232aa 3834
c19d1205 3835/* Parse an unwind_cantunwind directive. */
b99bd4ef 3836
c19d1205
ZW
3837static void
3838s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3839{
3840 demand_empty_rest_of_line ();
921e5f0a 3841 if (!unwind.proc_start)
c921be7d 3842 as_bad (MISSING_FNSTART);
921e5f0a 3843
c19d1205
ZW
3844 if (unwind.personality_routine || unwind.personality_index != -1)
3845 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3846
c19d1205
ZW
3847 unwind.personality_index = -2;
3848}
b99bd4ef 3849
b99bd4ef 3850
c19d1205 3851/* Parse a personalityindex directive. */
b99bd4ef 3852
c19d1205
ZW
3853static void
3854s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3855{
3856 expressionS exp;
b99bd4ef 3857
921e5f0a 3858 if (!unwind.proc_start)
c921be7d 3859 as_bad (MISSING_FNSTART);
921e5f0a 3860
c19d1205
ZW
3861 if (unwind.personality_routine || unwind.personality_index != -1)
3862 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3863
c19d1205 3864 expression (&exp);
b99bd4ef 3865
c19d1205
ZW
3866 if (exp.X_op != O_constant
3867 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3868 {
c19d1205
ZW
3869 as_bad (_("bad personality routine number"));
3870 ignore_rest_of_line ();
3871 return;
b99bd4ef
NC
3872 }
3873
c19d1205 3874 unwind.personality_index = exp.X_add_number;
b99bd4ef 3875
c19d1205
ZW
3876 demand_empty_rest_of_line ();
3877}
e16bb312 3878
e16bb312 3879
c19d1205 3880/* Parse a personality directive. */
e16bb312 3881
c19d1205
ZW
3882static void
3883s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3884{
3885 char *name, *p, c;
a737bd4d 3886
921e5f0a 3887 if (!unwind.proc_start)
c921be7d 3888 as_bad (MISSING_FNSTART);
921e5f0a 3889
c19d1205
ZW
3890 if (unwind.personality_routine || unwind.personality_index != -1)
3891 as_bad (_("duplicate .personality directive"));
a737bd4d 3892
d02603dc 3893 c = get_symbol_name (& name);
c19d1205 3894 p = input_line_pointer;
d02603dc
NC
3895 if (c == '"')
3896 ++ input_line_pointer;
c19d1205
ZW
3897 unwind.personality_routine = symbol_find_or_make (name);
3898 *p = c;
3899 demand_empty_rest_of_line ();
3900}
e16bb312 3901
e16bb312 3902
c19d1205 3903/* Parse a directive saving core registers. */
e16bb312 3904
c19d1205
ZW
3905static void
3906s_arm_unwind_save_core (void)
e16bb312 3907{
c19d1205
ZW
3908 valueT op;
3909 long range;
3910 int n;
e16bb312 3911
c19d1205
ZW
3912 range = parse_reg_list (&input_line_pointer);
3913 if (range == FAIL)
e16bb312 3914 {
c19d1205
ZW
3915 as_bad (_("expected register list"));
3916 ignore_rest_of_line ();
3917 return;
3918 }
e16bb312 3919
c19d1205 3920 demand_empty_rest_of_line ();
e16bb312 3921
c19d1205
ZW
3922 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3923 into .unwind_save {..., sp...}. We aren't bothered about the value of
3924 ip because it is clobbered by calls. */
3925 if (unwind.sp_restored && unwind.fp_reg == 12
3926 && (range & 0x3000) == 0x1000)
3927 {
3928 unwind.opcode_count--;
3929 unwind.sp_restored = 0;
3930 range = (range | 0x2000) & ~0x1000;
3931 unwind.pending_offset = 0;
3932 }
e16bb312 3933
01ae4198
DJ
3934 /* Pop r4-r15. */
3935 if (range & 0xfff0)
c19d1205 3936 {
01ae4198
DJ
3937 /* See if we can use the short opcodes. These pop a block of up to 8
3938 registers starting with r4, plus maybe r14. */
3939 for (n = 0; n < 8; n++)
3940 {
3941 /* Break at the first non-saved register. */
3942 if ((range & (1 << (n + 4))) == 0)
3943 break;
3944 }
3945 /* See if there are any other bits set. */
3946 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3947 {
3948 /* Use the long form. */
3949 op = 0x8000 | ((range >> 4) & 0xfff);
3950 add_unwind_opcode (op, 2);
3951 }
0dd132b6 3952 else
01ae4198
DJ
3953 {
3954 /* Use the short form. */
3955 if (range & 0x4000)
3956 op = 0xa8; /* Pop r14. */
3957 else
3958 op = 0xa0; /* Do not pop r14. */
3959 op |= (n - 1);
3960 add_unwind_opcode (op, 1);
3961 }
c19d1205 3962 }
0dd132b6 3963
c19d1205
ZW
3964 /* Pop r0-r3. */
3965 if (range & 0xf)
3966 {
3967 op = 0xb100 | (range & 0xf);
3968 add_unwind_opcode (op, 2);
0dd132b6
NC
3969 }
3970
c19d1205
ZW
3971 /* Record the number of bytes pushed. */
3972 for (n = 0; n < 16; n++)
3973 {
3974 if (range & (1 << n))
3975 unwind.frame_size += 4;
3976 }
0dd132b6
NC
3977}
3978
c19d1205
ZW
3979
3980/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3981
3982static void
c19d1205 3983s_arm_unwind_save_fpa (int reg)
b99bd4ef 3984{
c19d1205
ZW
3985 expressionS exp;
3986 int num_regs;
3987 valueT op;
b99bd4ef 3988
c19d1205
ZW
3989 /* Get Number of registers to transfer. */
3990 if (skip_past_comma (&input_line_pointer) != FAIL)
3991 expression (&exp);
3992 else
3993 exp.X_op = O_illegal;
b99bd4ef 3994
c19d1205 3995 if (exp.X_op != O_constant)
b99bd4ef 3996 {
c19d1205
ZW
3997 as_bad (_("expected , <constant>"));
3998 ignore_rest_of_line ();
b99bd4ef
NC
3999 return;
4000 }
4001
c19d1205
ZW
4002 num_regs = exp.X_add_number;
4003
4004 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4005 {
c19d1205
ZW
4006 as_bad (_("number of registers must be in the range [1:4]"));
4007 ignore_rest_of_line ();
b99bd4ef
NC
4008 return;
4009 }
4010
c19d1205 4011 demand_empty_rest_of_line ();
b99bd4ef 4012
c19d1205
ZW
4013 if (reg == 4)
4014 {
4015 /* Short form. */
4016 op = 0xb4 | (num_regs - 1);
4017 add_unwind_opcode (op, 1);
4018 }
b99bd4ef
NC
4019 else
4020 {
c19d1205
ZW
4021 /* Long form. */
4022 op = 0xc800 | (reg << 4) | (num_regs - 1);
4023 add_unwind_opcode (op, 2);
b99bd4ef 4024 }
c19d1205 4025 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4026}
4027
c19d1205 4028
fa073d69
MS
4029/* Parse a directive saving VFP registers for ARMv6 and above. */
4030
4031static void
4032s_arm_unwind_save_vfp_armv6 (void)
4033{
4034 int count;
4035 unsigned int start;
4036 valueT op;
4037 int num_vfpv3_regs = 0;
4038 int num_regs_below_16;
4039
4040 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4041 if (count == FAIL)
4042 {
4043 as_bad (_("expected register list"));
4044 ignore_rest_of_line ();
4045 return;
4046 }
4047
4048 demand_empty_rest_of_line ();
4049
4050 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4051 than FSTMX/FLDMX-style ones). */
4052
4053 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4054 if (start >= 16)
4055 num_vfpv3_regs = count;
4056 else if (start + count > 16)
4057 num_vfpv3_regs = start + count - 16;
4058
4059 if (num_vfpv3_regs > 0)
4060 {
4061 int start_offset = start > 16 ? start - 16 : 0;
4062 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4063 add_unwind_opcode (op, 2);
4064 }
4065
4066 /* Generate opcode for registers numbered in the range 0 .. 15. */
4067 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4068 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4069 if (num_regs_below_16 > 0)
4070 {
4071 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4072 add_unwind_opcode (op, 2);
4073 }
4074
4075 unwind.frame_size += count * 8;
4076}
4077
4078
4079/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4080
4081static void
c19d1205 4082s_arm_unwind_save_vfp (void)
b99bd4ef 4083{
c19d1205 4084 int count;
ca3f61f7 4085 unsigned int reg;
c19d1205 4086 valueT op;
b99bd4ef 4087
5287ad62 4088 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4089 if (count == FAIL)
b99bd4ef 4090 {
c19d1205
ZW
4091 as_bad (_("expected register list"));
4092 ignore_rest_of_line ();
b99bd4ef
NC
4093 return;
4094 }
4095
c19d1205 4096 demand_empty_rest_of_line ();
b99bd4ef 4097
c19d1205 4098 if (reg == 8)
b99bd4ef 4099 {
c19d1205
ZW
4100 /* Short form. */
4101 op = 0xb8 | (count - 1);
4102 add_unwind_opcode (op, 1);
b99bd4ef 4103 }
c19d1205 4104 else
b99bd4ef 4105 {
c19d1205
ZW
4106 /* Long form. */
4107 op = 0xb300 | (reg << 4) | (count - 1);
4108 add_unwind_opcode (op, 2);
b99bd4ef 4109 }
c19d1205
ZW
4110 unwind.frame_size += count * 8 + 4;
4111}
b99bd4ef 4112
b99bd4ef 4113
c19d1205
ZW
4114/* Parse a directive saving iWMMXt data registers. */
4115
4116static void
4117s_arm_unwind_save_mmxwr (void)
4118{
4119 int reg;
4120 int hi_reg;
4121 int i;
4122 unsigned mask = 0;
4123 valueT op;
b99bd4ef 4124
c19d1205
ZW
4125 if (*input_line_pointer == '{')
4126 input_line_pointer++;
b99bd4ef 4127
c19d1205 4128 do
b99bd4ef 4129 {
dcbf9037 4130 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4131
c19d1205 4132 if (reg == FAIL)
b99bd4ef 4133 {
9b7132d3 4134 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4135 goto error;
b99bd4ef
NC
4136 }
4137
c19d1205
ZW
4138 if (mask >> reg)
4139 as_tsktsk (_("register list not in ascending order"));
4140 mask |= 1 << reg;
b99bd4ef 4141
c19d1205
ZW
4142 if (*input_line_pointer == '-')
4143 {
4144 input_line_pointer++;
dcbf9037 4145 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4146 if (hi_reg == FAIL)
4147 {
9b7132d3 4148 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4149 goto error;
4150 }
4151 else if (reg >= hi_reg)
4152 {
4153 as_bad (_("bad register range"));
4154 goto error;
4155 }
4156 for (; reg < hi_reg; reg++)
4157 mask |= 1 << reg;
4158 }
4159 }
4160 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4161
d996d970 4162 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4163
c19d1205 4164 demand_empty_rest_of_line ();
b99bd4ef 4165
708587a4 4166 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4167 the list. */
4168 flush_pending_unwind ();
b99bd4ef 4169
c19d1205 4170 for (i = 0; i < 16; i++)
b99bd4ef 4171 {
c19d1205
ZW
4172 if (mask & (1 << i))
4173 unwind.frame_size += 8;
b99bd4ef
NC
4174 }
4175
c19d1205
ZW
4176 /* Attempt to combine with a previous opcode. We do this because gcc
4177 likes to output separate unwind directives for a single block of
4178 registers. */
4179 if (unwind.opcode_count > 0)
b99bd4ef 4180 {
c19d1205
ZW
4181 i = unwind.opcodes[unwind.opcode_count - 1];
4182 if ((i & 0xf8) == 0xc0)
4183 {
4184 i &= 7;
4185 /* Only merge if the blocks are contiguous. */
4186 if (i < 6)
4187 {
4188 if ((mask & 0xfe00) == (1 << 9))
4189 {
4190 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4191 unwind.opcode_count--;
4192 }
4193 }
4194 else if (i == 6 && unwind.opcode_count >= 2)
4195 {
4196 i = unwind.opcodes[unwind.opcode_count - 2];
4197 reg = i >> 4;
4198 i &= 0xf;
b99bd4ef 4199
c19d1205
ZW
4200 op = 0xffff << (reg - 1);
4201 if (reg > 0
87a1fd79 4202 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4203 {
4204 op = (1 << (reg + i + 1)) - 1;
4205 op &= ~((1 << reg) - 1);
4206 mask |= op;
4207 unwind.opcode_count -= 2;
4208 }
4209 }
4210 }
b99bd4ef
NC
4211 }
4212
c19d1205
ZW
4213 hi_reg = 15;
4214 /* We want to generate opcodes in the order the registers have been
4215 saved, ie. descending order. */
4216 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4217 {
c19d1205
ZW
4218 /* Save registers in blocks. */
4219 if (reg < 0
4220 || !(mask & (1 << reg)))
4221 {
4222 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4223 preceding block. */
c19d1205
ZW
4224 if (reg != hi_reg)
4225 {
4226 if (reg == 9)
4227 {
4228 /* Short form. */
4229 op = 0xc0 | (hi_reg - 10);
4230 add_unwind_opcode (op, 1);
4231 }
4232 else
4233 {
4234 /* Long form. */
4235 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4236 add_unwind_opcode (op, 2);
4237 }
4238 }
4239 hi_reg = reg - 1;
4240 }
b99bd4ef
NC
4241 }
4242
c19d1205
ZW
4243 return;
4244error:
4245 ignore_rest_of_line ();
b99bd4ef
NC
4246}
4247
4248static void
c19d1205 4249s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4250{
c19d1205
ZW
4251 int reg;
4252 int hi_reg;
4253 unsigned mask = 0;
4254 valueT op;
b99bd4ef 4255
c19d1205
ZW
4256 if (*input_line_pointer == '{')
4257 input_line_pointer++;
b99bd4ef 4258
477330fc
RM
4259 skip_whitespace (input_line_pointer);
4260
c19d1205 4261 do
b99bd4ef 4262 {
dcbf9037 4263 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4264
c19d1205
ZW
4265 if (reg == FAIL)
4266 {
9b7132d3 4267 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4268 goto error;
4269 }
b99bd4ef 4270
c19d1205
ZW
4271 reg -= 8;
4272 if (mask >> reg)
4273 as_tsktsk (_("register list not in ascending order"));
4274 mask |= 1 << reg;
b99bd4ef 4275
c19d1205
ZW
4276 if (*input_line_pointer == '-')
4277 {
4278 input_line_pointer++;
dcbf9037 4279 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4280 if (hi_reg == FAIL)
4281 {
9b7132d3 4282 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4283 goto error;
4284 }
4285 else if (reg >= hi_reg)
4286 {
4287 as_bad (_("bad register range"));
4288 goto error;
4289 }
4290 for (; reg < hi_reg; reg++)
4291 mask |= 1 << reg;
4292 }
b99bd4ef 4293 }
c19d1205 4294 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4295
d996d970 4296 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4297
c19d1205
ZW
4298 demand_empty_rest_of_line ();
4299
708587a4 4300 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4301 the list. */
4302 flush_pending_unwind ();
b99bd4ef 4303
c19d1205 4304 for (reg = 0; reg < 16; reg++)
b99bd4ef 4305 {
c19d1205
ZW
4306 if (mask & (1 << reg))
4307 unwind.frame_size += 4;
b99bd4ef 4308 }
c19d1205
ZW
4309 op = 0xc700 | mask;
4310 add_unwind_opcode (op, 2);
4311 return;
4312error:
4313 ignore_rest_of_line ();
b99bd4ef
NC
4314}
4315
c19d1205 4316
fa073d69
MS
4317/* Parse an unwind_save directive.
4318 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4319
b99bd4ef 4320static void
fa073d69 4321s_arm_unwind_save (int arch_v6)
b99bd4ef 4322{
c19d1205
ZW
4323 char *peek;
4324 struct reg_entry *reg;
4325 bfd_boolean had_brace = FALSE;
b99bd4ef 4326
921e5f0a 4327 if (!unwind.proc_start)
c921be7d 4328 as_bad (MISSING_FNSTART);
921e5f0a 4329
c19d1205
ZW
4330 /* Figure out what sort of save we have. */
4331 peek = input_line_pointer;
b99bd4ef 4332
c19d1205 4333 if (*peek == '{')
b99bd4ef 4334 {
c19d1205
ZW
4335 had_brace = TRUE;
4336 peek++;
b99bd4ef
NC
4337 }
4338
c19d1205 4339 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4340
c19d1205 4341 if (!reg)
b99bd4ef 4342 {
c19d1205
ZW
4343 as_bad (_("register expected"));
4344 ignore_rest_of_line ();
b99bd4ef
NC
4345 return;
4346 }
4347
c19d1205 4348 switch (reg->type)
b99bd4ef 4349 {
c19d1205
ZW
4350 case REG_TYPE_FN:
4351 if (had_brace)
4352 {
4353 as_bad (_("FPA .unwind_save does not take a register list"));
4354 ignore_rest_of_line ();
4355 return;
4356 }
93ac2687 4357 input_line_pointer = peek;
c19d1205 4358 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4359 return;
c19d1205 4360
1f5afe1c
NC
4361 case REG_TYPE_RN:
4362 s_arm_unwind_save_core ();
4363 return;
4364
fa073d69
MS
4365 case REG_TYPE_VFD:
4366 if (arch_v6)
477330fc 4367 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4368 else
477330fc 4369 s_arm_unwind_save_vfp ();
fa073d69 4370 return;
1f5afe1c
NC
4371
4372 case REG_TYPE_MMXWR:
4373 s_arm_unwind_save_mmxwr ();
4374 return;
4375
4376 case REG_TYPE_MMXWCG:
4377 s_arm_unwind_save_mmxwcg ();
4378 return;
c19d1205
ZW
4379
4380 default:
4381 as_bad (_(".unwind_save does not support this kind of register"));
4382 ignore_rest_of_line ();
b99bd4ef 4383 }
c19d1205 4384}
b99bd4ef 4385
b99bd4ef 4386
c19d1205
ZW
4387/* Parse an unwind_movsp directive. */
4388
4389static void
4390s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4391{
4392 int reg;
4393 valueT op;
4fa3602b 4394 int offset;
c19d1205 4395
921e5f0a 4396 if (!unwind.proc_start)
c921be7d 4397 as_bad (MISSING_FNSTART);
921e5f0a 4398
dcbf9037 4399 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4400 if (reg == FAIL)
b99bd4ef 4401 {
9b7132d3 4402 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4403 ignore_rest_of_line ();
b99bd4ef
NC
4404 return;
4405 }
4fa3602b
PB
4406
4407 /* Optional constant. */
4408 if (skip_past_comma (&input_line_pointer) != FAIL)
4409 {
4410 if (immediate_for_directive (&offset) == FAIL)
4411 return;
4412 }
4413 else
4414 offset = 0;
4415
c19d1205 4416 demand_empty_rest_of_line ();
b99bd4ef 4417
c19d1205 4418 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4419 {
c19d1205 4420 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4421 return;
4422 }
4423
c19d1205
ZW
4424 if (unwind.fp_reg != REG_SP)
4425 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4426
c19d1205
ZW
4427 /* Generate opcode to restore the value. */
4428 op = 0x90 | reg;
4429 add_unwind_opcode (op, 1);
4430
4431 /* Record the information for later. */
4432 unwind.fp_reg = reg;
4fa3602b 4433 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4434 unwind.sp_restored = 1;
b05fe5cf
ZW
4435}
4436
c19d1205
ZW
4437/* Parse an unwind_pad directive. */
4438
b05fe5cf 4439static void
c19d1205 4440s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4441{
c19d1205 4442 int offset;
b05fe5cf 4443
921e5f0a 4444 if (!unwind.proc_start)
c921be7d 4445 as_bad (MISSING_FNSTART);
921e5f0a 4446
c19d1205
ZW
4447 if (immediate_for_directive (&offset) == FAIL)
4448 return;
b99bd4ef 4449
c19d1205
ZW
4450 if (offset & 3)
4451 {
4452 as_bad (_("stack increment must be multiple of 4"));
4453 ignore_rest_of_line ();
4454 return;
4455 }
b99bd4ef 4456
c19d1205
ZW
4457 /* Don't generate any opcodes, just record the details for later. */
4458 unwind.frame_size += offset;
4459 unwind.pending_offset += offset;
4460
4461 demand_empty_rest_of_line ();
4462}
4463
4464/* Parse an unwind_setfp directive. */
4465
4466static void
4467s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4468{
c19d1205
ZW
4469 int sp_reg;
4470 int fp_reg;
4471 int offset;
4472
921e5f0a 4473 if (!unwind.proc_start)
c921be7d 4474 as_bad (MISSING_FNSTART);
921e5f0a 4475
dcbf9037 4476 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4477 if (skip_past_comma (&input_line_pointer) == FAIL)
4478 sp_reg = FAIL;
4479 else
dcbf9037 4480 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4481
c19d1205
ZW
4482 if (fp_reg == FAIL || sp_reg == FAIL)
4483 {
4484 as_bad (_("expected <reg>, <reg>"));
4485 ignore_rest_of_line ();
4486 return;
4487 }
b99bd4ef 4488
c19d1205
ZW
4489 /* Optional constant. */
4490 if (skip_past_comma (&input_line_pointer) != FAIL)
4491 {
4492 if (immediate_for_directive (&offset) == FAIL)
4493 return;
4494 }
4495 else
4496 offset = 0;
a737bd4d 4497
c19d1205 4498 demand_empty_rest_of_line ();
a737bd4d 4499
fdfde340 4500 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4501 {
c19d1205
ZW
4502 as_bad (_("register must be either sp or set by a previous"
4503 "unwind_movsp directive"));
4504 return;
a737bd4d
NC
4505 }
4506
c19d1205
ZW
4507 /* Don't generate any opcodes, just record the information for later. */
4508 unwind.fp_reg = fp_reg;
4509 unwind.fp_used = 1;
fdfde340 4510 if (sp_reg == REG_SP)
c19d1205
ZW
4511 unwind.fp_offset = unwind.frame_size - offset;
4512 else
4513 unwind.fp_offset -= offset;
a737bd4d
NC
4514}
4515
c19d1205
ZW
4516/* Parse an unwind_raw directive. */
4517
4518static void
4519s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4520{
c19d1205 4521 expressionS exp;
708587a4 4522 /* This is an arbitrary limit. */
c19d1205
ZW
4523 unsigned char op[16];
4524 int count;
a737bd4d 4525
921e5f0a 4526 if (!unwind.proc_start)
c921be7d 4527 as_bad (MISSING_FNSTART);
921e5f0a 4528
c19d1205
ZW
4529 expression (&exp);
4530 if (exp.X_op == O_constant
4531 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4532 {
c19d1205
ZW
4533 unwind.frame_size += exp.X_add_number;
4534 expression (&exp);
4535 }
4536 else
4537 exp.X_op = O_illegal;
a737bd4d 4538
c19d1205
ZW
4539 if (exp.X_op != O_constant)
4540 {
4541 as_bad (_("expected <offset>, <opcode>"));
4542 ignore_rest_of_line ();
4543 return;
4544 }
a737bd4d 4545
c19d1205 4546 count = 0;
a737bd4d 4547
c19d1205
ZW
4548 /* Parse the opcode. */
4549 for (;;)
4550 {
4551 if (count >= 16)
4552 {
4553 as_bad (_("unwind opcode too long"));
4554 ignore_rest_of_line ();
a737bd4d 4555 }
c19d1205 4556 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4557 {
c19d1205
ZW
4558 as_bad (_("invalid unwind opcode"));
4559 ignore_rest_of_line ();
4560 return;
a737bd4d 4561 }
c19d1205 4562 op[count++] = exp.X_add_number;
a737bd4d 4563
c19d1205
ZW
4564 /* Parse the next byte. */
4565 if (skip_past_comma (&input_line_pointer) == FAIL)
4566 break;
a737bd4d 4567
c19d1205
ZW
4568 expression (&exp);
4569 }
b99bd4ef 4570
c19d1205
ZW
4571 /* Add the opcode bytes in reverse order. */
4572 while (count--)
4573 add_unwind_opcode (op[count], 1);
b99bd4ef 4574
c19d1205 4575 demand_empty_rest_of_line ();
b99bd4ef 4576}
ee065d83
PB
4577
4578
4579/* Parse a .eabi_attribute directive. */
4580
4581static void
4582s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4583{
0420f52b 4584 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4585
4586 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4587 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4588}
4589
0855e32b
NS
4590/* Emit a tls fix for the symbol. */
4591
4592static void
4593s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4594{
4595 char *p;
4596 expressionS exp;
4597#ifdef md_flush_pending_output
4598 md_flush_pending_output ();
4599#endif
4600
4601#ifdef md_cons_align
4602 md_cons_align (4);
4603#endif
4604
4605 /* Since we're just labelling the code, there's no need to define a
4606 mapping symbol. */
4607 expression (&exp);
4608 p = obstack_next_free (&frchain_now->frch_obstack);
4609 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4610 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4611 : BFD_RELOC_ARM_TLS_DESCSEQ);
4612}
cdf9ccec 4613#endif /* OBJ_ELF */
0855e32b 4614
ee065d83 4615static void s_arm_arch (int);
7a1d4c38 4616static void s_arm_object_arch (int);
ee065d83
PB
4617static void s_arm_cpu (int);
4618static void s_arm_fpu (int);
69133863 4619static void s_arm_arch_extension (int);
b99bd4ef 4620
f0927246
NC
4621#ifdef TE_PE
4622
4623static void
5f4273c7 4624pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4625{
4626 expressionS exp;
4627
4628 do
4629 {
4630 expression (&exp);
4631 if (exp.X_op == O_symbol)
4632 exp.X_op = O_secrel;
4633
4634 emit_expr (&exp, 4);
4635 }
4636 while (*input_line_pointer++ == ',');
4637
4638 input_line_pointer--;
4639 demand_empty_rest_of_line ();
4640}
4641#endif /* TE_PE */
4642
c19d1205
ZW
4643/* This table describes all the machine specific pseudo-ops the assembler
4644 has to support. The fields are:
4645 pseudo-op name without dot
4646 function to call to execute this pseudo-op
4647 Integer arg to pass to the function. */
b99bd4ef 4648
c19d1205 4649const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4650{
c19d1205
ZW
4651 /* Never called because '.req' does not start a line. */
4652 { "req", s_req, 0 },
dcbf9037
JB
4653 /* Following two are likewise never called. */
4654 { "dn", s_dn, 0 },
4655 { "qn", s_qn, 0 },
c19d1205
ZW
4656 { "unreq", s_unreq, 0 },
4657 { "bss", s_bss, 0 },
db2ed2e0 4658 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4659 { "arm", s_arm, 0 },
4660 { "thumb", s_thumb, 0 },
4661 { "code", s_code, 0 },
4662 { "force_thumb", s_force_thumb, 0 },
4663 { "thumb_func", s_thumb_func, 0 },
4664 { "thumb_set", s_thumb_set, 0 },
4665 { "even", s_even, 0 },
4666 { "ltorg", s_ltorg, 0 },
4667 { "pool", s_ltorg, 0 },
4668 { "syntax", s_syntax, 0 },
8463be01
PB
4669 { "cpu", s_arm_cpu, 0 },
4670 { "arch", s_arm_arch, 0 },
7a1d4c38 4671 { "object_arch", s_arm_object_arch, 0 },
8463be01 4672 { "fpu", s_arm_fpu, 0 },
69133863 4673 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4674#ifdef OBJ_ELF
c921be7d
NC
4675 { "word", s_arm_elf_cons, 4 },
4676 { "long", s_arm_elf_cons, 4 },
4677 { "inst.n", s_arm_elf_inst, 2 },
4678 { "inst.w", s_arm_elf_inst, 4 },
4679 { "inst", s_arm_elf_inst, 0 },
4680 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4681 { "fnstart", s_arm_unwind_fnstart, 0 },
4682 { "fnend", s_arm_unwind_fnend, 0 },
4683 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4684 { "personality", s_arm_unwind_personality, 0 },
4685 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4686 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4687 { "save", s_arm_unwind_save, 0 },
fa073d69 4688 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4689 { "movsp", s_arm_unwind_movsp, 0 },
4690 { "pad", s_arm_unwind_pad, 0 },
4691 { "setfp", s_arm_unwind_setfp, 0 },
4692 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4693 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4694 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4695#else
4696 { "word", cons, 4},
f0927246
NC
4697
4698 /* These are used for dwarf. */
4699 {"2byte", cons, 2},
4700 {"4byte", cons, 4},
4701 {"8byte", cons, 8},
4702 /* These are used for dwarf2. */
4703 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4704 { "loc", dwarf2_directive_loc, 0 },
4705 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4706#endif
4707 { "extend", float_cons, 'x' },
4708 { "ldouble", float_cons, 'x' },
4709 { "packed", float_cons, 'p' },
f0927246
NC
4710#ifdef TE_PE
4711 {"secrel32", pe_directive_secrel, 0},
4712#endif
2e6976a8
DG
4713
4714 /* These are for compatibility with CodeComposer Studio. */
4715 {"ref", s_ccs_ref, 0},
4716 {"def", s_ccs_def, 0},
4717 {"asmfunc", s_ccs_asmfunc, 0},
4718 {"endasmfunc", s_ccs_endasmfunc, 0},
4719
c19d1205
ZW
4720 { 0, 0, 0 }
4721};
4722\f
4723/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4724
c19d1205
ZW
4725/* Generic immediate-value read function for use in insn parsing.
4726 STR points to the beginning of the immediate (the leading #);
4727 VAL receives the value; if the value is outside [MIN, MAX]
4728 issue an error. PREFIX_OPT is true if the immediate prefix is
4729 optional. */
b99bd4ef 4730
c19d1205
ZW
4731static int
4732parse_immediate (char **str, int *val, int min, int max,
4733 bfd_boolean prefix_opt)
4734{
4735 expressionS exp;
4736 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4737 if (exp.X_op != O_constant)
b99bd4ef 4738 {
c19d1205
ZW
4739 inst.error = _("constant expression required");
4740 return FAIL;
4741 }
b99bd4ef 4742
c19d1205
ZW
4743 if (exp.X_add_number < min || exp.X_add_number > max)
4744 {
4745 inst.error = _("immediate value out of range");
4746 return FAIL;
4747 }
b99bd4ef 4748
c19d1205
ZW
4749 *val = exp.X_add_number;
4750 return SUCCESS;
4751}
b99bd4ef 4752
5287ad62 4753/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4754 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4755 instructions. Puts the result directly in inst.operands[i]. */
4756
4757static int
8335d6aa
JW
4758parse_big_immediate (char **str, int i, expressionS *in_exp,
4759 bfd_boolean allow_symbol_p)
5287ad62
JB
4760{
4761 expressionS exp;
8335d6aa 4762 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4763 char *ptr = *str;
4764
8335d6aa 4765 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4766
8335d6aa 4767 if (exp_p->X_op == O_constant)
036dc3f7 4768 {
8335d6aa 4769 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4770 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4771 O_constant. We have to be careful not to break compilation for
4772 32-bit X_add_number, though. */
8335d6aa 4773 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4774 {
8335d6aa
JW
4775 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4776 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4777 & 0xffffffff);
036dc3f7
PB
4778 inst.operands[i].regisimm = 1;
4779 }
4780 }
8335d6aa
JW
4781 else if (exp_p->X_op == O_big
4782 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4783 {
4784 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4785
5287ad62 4786 /* Bignums have their least significant bits in
477330fc
RM
4787 generic_bignum[0]. Make sure we put 32 bits in imm and
4788 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4789 gas_assert (parts != 0);
95b75c01
NC
4790
4791 /* Make sure that the number is not too big.
4792 PR 11972: Bignums can now be sign-extended to the
4793 size of a .octa so check that the out of range bits
4794 are all zero or all one. */
8335d6aa 4795 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4796 {
4797 LITTLENUM_TYPE m = -1;
4798
4799 if (generic_bignum[parts * 2] != 0
4800 && generic_bignum[parts * 2] != m)
4801 return FAIL;
4802
8335d6aa 4803 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4804 if (generic_bignum[j] != generic_bignum[j-1])
4805 return FAIL;
4806 }
4807
5287ad62
JB
4808 inst.operands[i].imm = 0;
4809 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4810 inst.operands[i].imm |= generic_bignum[idx]
4811 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4812 inst.operands[i].reg = 0;
4813 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4814 inst.operands[i].reg |= generic_bignum[idx]
4815 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4816 inst.operands[i].regisimm = 1;
4817 }
8335d6aa 4818 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4819 return FAIL;
5f4273c7 4820
5287ad62
JB
4821 *str = ptr;
4822
4823 return SUCCESS;
4824}
4825
c19d1205
ZW
4826/* Returns the pseudo-register number of an FPA immediate constant,
4827 or FAIL if there isn't a valid constant here. */
b99bd4ef 4828
c19d1205
ZW
4829static int
4830parse_fpa_immediate (char ** str)
4831{
4832 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4833 char * save_in;
4834 expressionS exp;
4835 int i;
4836 int j;
b99bd4ef 4837
c19d1205
ZW
4838 /* First try and match exact strings, this is to guarantee
4839 that some formats will work even for cross assembly. */
b99bd4ef 4840
c19d1205
ZW
4841 for (i = 0; fp_const[i]; i++)
4842 {
4843 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4844 {
c19d1205 4845 char *start = *str;
b99bd4ef 4846
c19d1205
ZW
4847 *str += strlen (fp_const[i]);
4848 if (is_end_of_line[(unsigned char) **str])
4849 return i + 8;
4850 *str = start;
4851 }
4852 }
b99bd4ef 4853
c19d1205
ZW
4854 /* Just because we didn't get a match doesn't mean that the constant
4855 isn't valid, just that it is in a format that we don't
4856 automatically recognize. Try parsing it with the standard
4857 expression routines. */
b99bd4ef 4858
c19d1205 4859 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4860
c19d1205
ZW
4861 /* Look for a raw floating point number. */
4862 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4863 && is_end_of_line[(unsigned char) *save_in])
4864 {
4865 for (i = 0; i < NUM_FLOAT_VALS; i++)
4866 {
4867 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4868 {
c19d1205
ZW
4869 if (words[j] != fp_values[i][j])
4870 break;
b99bd4ef
NC
4871 }
4872
c19d1205 4873 if (j == MAX_LITTLENUMS)
b99bd4ef 4874 {
c19d1205
ZW
4875 *str = save_in;
4876 return i + 8;
b99bd4ef
NC
4877 }
4878 }
4879 }
b99bd4ef 4880
c19d1205
ZW
4881 /* Try and parse a more complex expression, this will probably fail
4882 unless the code uses a floating point prefix (eg "0f"). */
4883 save_in = input_line_pointer;
4884 input_line_pointer = *str;
4885 if (expression (&exp) == absolute_section
4886 && exp.X_op == O_big
4887 && exp.X_add_number < 0)
4888 {
4889 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4890 Ditto for 15. */
ba592044
AM
4891#define X_PRECISION 5
4892#define E_PRECISION 15L
4893 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4894 {
4895 for (i = 0; i < NUM_FLOAT_VALS; i++)
4896 {
4897 for (j = 0; j < MAX_LITTLENUMS; j++)
4898 {
4899 if (words[j] != fp_values[i][j])
4900 break;
4901 }
b99bd4ef 4902
c19d1205
ZW
4903 if (j == MAX_LITTLENUMS)
4904 {
4905 *str = input_line_pointer;
4906 input_line_pointer = save_in;
4907 return i + 8;
4908 }
4909 }
4910 }
b99bd4ef
NC
4911 }
4912
c19d1205
ZW
4913 *str = input_line_pointer;
4914 input_line_pointer = save_in;
4915 inst.error = _("invalid FPA immediate expression");
4916 return FAIL;
b99bd4ef
NC
4917}
4918
136da414
JB
4919/* Returns 1 if a number has "quarter-precision" float format
4920 0baBbbbbbc defgh000 00000000 00000000. */
4921
4922static int
4923is_quarter_float (unsigned imm)
4924{
4925 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4926 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4927}
4928
aacf0b33
KT
4929
4930/* Detect the presence of a floating point or integer zero constant,
4931 i.e. #0.0 or #0. */
4932
4933static bfd_boolean
4934parse_ifimm_zero (char **in)
4935{
4936 int error_code;
4937
4938 if (!is_immediate_prefix (**in))
4939 return FALSE;
4940
4941 ++*in;
0900a05b
JW
4942
4943 /* Accept #0x0 as a synonym for #0. */
4944 if (strncmp (*in, "0x", 2) == 0)
4945 {
4946 int val;
4947 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4948 return FALSE;
4949 return TRUE;
4950 }
4951
aacf0b33
KT
4952 error_code = atof_generic (in, ".", EXP_CHARS,
4953 &generic_floating_point_number);
4954
4955 if (!error_code
4956 && generic_floating_point_number.sign == '+'
4957 && (generic_floating_point_number.low
4958 > generic_floating_point_number.leader))
4959 return TRUE;
4960
4961 return FALSE;
4962}
4963
136da414
JB
4964/* Parse an 8-bit "quarter-precision" floating point number of the form:
4965 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4966 The zero and minus-zero cases need special handling, since they can't be
4967 encoded in the "quarter-precision" float format, but can nonetheless be
4968 loaded as integer constants. */
136da414
JB
4969
4970static unsigned
4971parse_qfloat_immediate (char **ccp, int *immed)
4972{
4973 char *str = *ccp;
c96612cc 4974 char *fpnum;
136da414 4975 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4976 int found_fpchar = 0;
5f4273c7 4977
136da414 4978 skip_past_char (&str, '#');
5f4273c7 4979
c96612cc
JB
4980 /* We must not accidentally parse an integer as a floating-point number. Make
4981 sure that the value we parse is not an integer by checking for special
4982 characters '.' or 'e'.
4983 FIXME: This is a horrible hack, but doing better is tricky because type
4984 information isn't in a very usable state at parse time. */
4985 fpnum = str;
4986 skip_whitespace (fpnum);
4987
4988 if (strncmp (fpnum, "0x", 2) == 0)
4989 return FAIL;
4990 else
4991 {
4992 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
4993 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4994 {
4995 found_fpchar = 1;
4996 break;
4997 }
c96612cc
JB
4998
4999 if (!found_fpchar)
477330fc 5000 return FAIL;
c96612cc 5001 }
5f4273c7 5002
136da414
JB
5003 if ((str = atof_ieee (str, 's', words)) != NULL)
5004 {
5005 unsigned fpword = 0;
5006 int i;
5f4273c7 5007
136da414
JB
5008 /* Our FP word must be 32 bits (single-precision FP). */
5009 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5010 {
5011 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5012 fpword |= words[i];
5013 }
5f4273c7 5014
c96612cc 5015 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5016 *immed = fpword;
136da414 5017 else
477330fc 5018 return FAIL;
136da414
JB
5019
5020 *ccp = str;
5f4273c7 5021
136da414
JB
5022 return SUCCESS;
5023 }
5f4273c7 5024
136da414
JB
5025 return FAIL;
5026}
5027
c19d1205
ZW
5028/* Shift operands. */
5029enum shift_kind
b99bd4ef 5030{
c19d1205
ZW
5031 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5032};
b99bd4ef 5033
c19d1205
ZW
5034struct asm_shift_name
5035{
5036 const char *name;
5037 enum shift_kind kind;
5038};
b99bd4ef 5039
c19d1205
ZW
5040/* Third argument to parse_shift. */
5041enum parse_shift_mode
5042{
5043 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5044 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5045 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5046 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5047 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5048};
b99bd4ef 5049
c19d1205
ZW
5050/* Parse a <shift> specifier on an ARM data processing instruction.
5051 This has three forms:
b99bd4ef 5052
c19d1205
ZW
5053 (LSL|LSR|ASL|ASR|ROR) Rs
5054 (LSL|LSR|ASL|ASR|ROR) #imm
5055 RRX
b99bd4ef 5056
c19d1205
ZW
5057 Note that ASL is assimilated to LSL in the instruction encoding, and
5058 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5059
c19d1205
ZW
5060static int
5061parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5062{
c19d1205
ZW
5063 const struct asm_shift_name *shift_name;
5064 enum shift_kind shift;
5065 char *s = *str;
5066 char *p = s;
5067 int reg;
b99bd4ef 5068
c19d1205
ZW
5069 for (p = *str; ISALPHA (*p); p++)
5070 ;
b99bd4ef 5071
c19d1205 5072 if (p == *str)
b99bd4ef 5073 {
c19d1205
ZW
5074 inst.error = _("shift expression expected");
5075 return FAIL;
b99bd4ef
NC
5076 }
5077
21d799b5 5078 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5079 p - *str);
c19d1205
ZW
5080
5081 if (shift_name == NULL)
b99bd4ef 5082 {
c19d1205
ZW
5083 inst.error = _("shift expression expected");
5084 return FAIL;
b99bd4ef
NC
5085 }
5086
c19d1205 5087 shift = shift_name->kind;
b99bd4ef 5088
c19d1205
ZW
5089 switch (mode)
5090 {
5091 case NO_SHIFT_RESTRICT:
5092 case SHIFT_IMMEDIATE: break;
b99bd4ef 5093
c19d1205
ZW
5094 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5095 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5096 {
5097 inst.error = _("'LSL' or 'ASR' required");
5098 return FAIL;
5099 }
5100 break;
b99bd4ef 5101
c19d1205
ZW
5102 case SHIFT_LSL_IMMEDIATE:
5103 if (shift != SHIFT_LSL)
5104 {
5105 inst.error = _("'LSL' required");
5106 return FAIL;
5107 }
5108 break;
b99bd4ef 5109
c19d1205
ZW
5110 case SHIFT_ASR_IMMEDIATE:
5111 if (shift != SHIFT_ASR)
5112 {
5113 inst.error = _("'ASR' required");
5114 return FAIL;
5115 }
5116 break;
b99bd4ef 5117
c19d1205
ZW
5118 default: abort ();
5119 }
b99bd4ef 5120
c19d1205
ZW
5121 if (shift != SHIFT_RRX)
5122 {
5123 /* Whitespace can appear here if the next thing is a bare digit. */
5124 skip_whitespace (p);
b99bd4ef 5125
c19d1205 5126 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5127 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5128 {
5129 inst.operands[i].imm = reg;
5130 inst.operands[i].immisreg = 1;
5131 }
5132 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5133 return FAIL;
5134 }
5135 inst.operands[i].shift_kind = shift;
5136 inst.operands[i].shifted = 1;
5137 *str = p;
5138 return SUCCESS;
b99bd4ef
NC
5139}
5140
c19d1205 5141/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5142
c19d1205
ZW
5143 #<immediate>
5144 #<immediate>, <rotate>
5145 <Rm>
5146 <Rm>, <shift>
b99bd4ef 5147
c19d1205
ZW
5148 where <shift> is defined by parse_shift above, and <rotate> is a
5149 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5150 is deferred to md_apply_fix. */
b99bd4ef 5151
c19d1205
ZW
5152static int
5153parse_shifter_operand (char **str, int i)
5154{
5155 int value;
91d6fa6a 5156 expressionS exp;
b99bd4ef 5157
dcbf9037 5158 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5159 {
5160 inst.operands[i].reg = value;
5161 inst.operands[i].isreg = 1;
b99bd4ef 5162
c19d1205
ZW
5163 /* parse_shift will override this if appropriate */
5164 inst.reloc.exp.X_op = O_constant;
5165 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5166
c19d1205
ZW
5167 if (skip_past_comma (str) == FAIL)
5168 return SUCCESS;
b99bd4ef 5169
c19d1205
ZW
5170 /* Shift operation on register. */
5171 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5172 }
5173
c19d1205
ZW
5174 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5175 return FAIL;
b99bd4ef 5176
c19d1205 5177 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5178 {
c19d1205 5179 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5180 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5181 return FAIL;
b99bd4ef 5182
91d6fa6a 5183 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5184 {
5185 inst.error = _("constant expression expected");
5186 return FAIL;
5187 }
b99bd4ef 5188
91d6fa6a 5189 value = exp.X_add_number;
c19d1205
ZW
5190 if (value < 0 || value > 30 || value % 2 != 0)
5191 {
5192 inst.error = _("invalid rotation");
5193 return FAIL;
5194 }
5195 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5196 {
5197 inst.error = _("invalid constant");
5198 return FAIL;
5199 }
09d92015 5200
a415b1cd
JB
5201 /* Encode as specified. */
5202 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5203 return SUCCESS;
09d92015
MM
5204 }
5205
c19d1205
ZW
5206 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5207 inst.reloc.pc_rel = 0;
5208 return SUCCESS;
09d92015
MM
5209}
5210
4962c51a
MS
5211/* Group relocation information. Each entry in the table contains the
5212 textual name of the relocation as may appear in assembler source
5213 and must end with a colon.
5214 Along with this textual name are the relocation codes to be used if
5215 the corresponding instruction is an ALU instruction (ADD or SUB only),
5216 an LDR, an LDRS, or an LDC. */
5217
5218struct group_reloc_table_entry
5219{
5220 const char *name;
5221 int alu_code;
5222 int ldr_code;
5223 int ldrs_code;
5224 int ldc_code;
5225};
5226
5227typedef enum
5228{
5229 /* Varieties of non-ALU group relocation. */
5230
5231 GROUP_LDR,
5232 GROUP_LDRS,
5233 GROUP_LDC
5234} group_reloc_type;
5235
5236static struct group_reloc_table_entry group_reloc_table[] =
5237 { /* Program counter relative: */
5238 { "pc_g0_nc",
5239 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5240 0, /* LDR */
5241 0, /* LDRS */
5242 0 }, /* LDC */
5243 { "pc_g0",
5244 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5245 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5246 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5247 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5248 { "pc_g1_nc",
5249 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5250 0, /* LDR */
5251 0, /* LDRS */
5252 0 }, /* LDC */
5253 { "pc_g1",
5254 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5255 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5256 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5257 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5258 { "pc_g2",
5259 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5260 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5261 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5262 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5263 /* Section base relative */
5264 { "sb_g0_nc",
5265 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5266 0, /* LDR */
5267 0, /* LDRS */
5268 0 }, /* LDC */
5269 { "sb_g0",
5270 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5271 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5272 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5273 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5274 { "sb_g1_nc",
5275 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5276 0, /* LDR */
5277 0, /* LDRS */
5278 0 }, /* LDC */
5279 { "sb_g1",
5280 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5281 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5282 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5283 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5284 { "sb_g2",
5285 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5286 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5287 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5288 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5289 /* Absolute thumb alu relocations. */
5290 { "lower0_7",
5291 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5292 0, /* LDR. */
5293 0, /* LDRS. */
5294 0 }, /* LDC. */
5295 { "lower8_15",
5296 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5297 0, /* LDR. */
5298 0, /* LDRS. */
5299 0 }, /* LDC. */
5300 { "upper0_7",
5301 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5302 0, /* LDR. */
5303 0, /* LDRS. */
5304 0 }, /* LDC. */
5305 { "upper8_15",
5306 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5307 0, /* LDR. */
5308 0, /* LDRS. */
5309 0 } }; /* LDC. */
4962c51a
MS
5310
5311/* Given the address of a pointer pointing to the textual name of a group
5312 relocation as may appear in assembler source, attempt to find its details
5313 in group_reloc_table. The pointer will be updated to the character after
5314 the trailing colon. On failure, FAIL will be returned; SUCCESS
5315 otherwise. On success, *entry will be updated to point at the relevant
5316 group_reloc_table entry. */
5317
5318static int
5319find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5320{
5321 unsigned int i;
5322 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5323 {
5324 int length = strlen (group_reloc_table[i].name);
5325
5f4273c7
NC
5326 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5327 && (*str)[length] == ':')
477330fc
RM
5328 {
5329 *out = &group_reloc_table[i];
5330 *str += (length + 1);
5331 return SUCCESS;
5332 }
4962c51a
MS
5333 }
5334
5335 return FAIL;
5336}
5337
5338/* Parse a <shifter_operand> for an ARM data processing instruction
5339 (as for parse_shifter_operand) where group relocations are allowed:
5340
5341 #<immediate>
5342 #<immediate>, <rotate>
5343 #:<group_reloc>:<expression>
5344 <Rm>
5345 <Rm>, <shift>
5346
5347 where <group_reloc> is one of the strings defined in group_reloc_table.
5348 The hashes are optional.
5349
5350 Everything else is as for parse_shifter_operand. */
5351
5352static parse_operand_result
5353parse_shifter_operand_group_reloc (char **str, int i)
5354{
5355 /* Determine if we have the sequence of characters #: or just :
5356 coming next. If we do, then we check for a group relocation.
5357 If we don't, punt the whole lot to parse_shifter_operand. */
5358
5359 if (((*str)[0] == '#' && (*str)[1] == ':')
5360 || (*str)[0] == ':')
5361 {
5362 struct group_reloc_table_entry *entry;
5363
5364 if ((*str)[0] == '#')
477330fc 5365 (*str) += 2;
4962c51a 5366 else
477330fc 5367 (*str)++;
4962c51a
MS
5368
5369 /* Try to parse a group relocation. Anything else is an error. */
5370 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5371 {
5372 inst.error = _("unknown group relocation");
5373 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5374 }
4962c51a
MS
5375
5376 /* We now have the group relocation table entry corresponding to
477330fc 5377 the name in the assembler source. Next, we parse the expression. */
4962c51a 5378 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5379 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5380
5381 /* Record the relocation type (always the ALU variant here). */
21d799b5 5382 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5383 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5384
5385 return PARSE_OPERAND_SUCCESS;
5386 }
5387 else
5388 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5389 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5390
5391 /* Never reached. */
5392}
5393
8e560766
MGD
5394/* Parse a Neon alignment expression. Information is written to
5395 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5396
8e560766
MGD
5397 align .imm = align << 8, .immisalign=1, .preind=0 */
5398static parse_operand_result
5399parse_neon_alignment (char **str, int i)
5400{
5401 char *p = *str;
5402 expressionS exp;
5403
5404 my_get_expression (&exp, &p, GE_NO_PREFIX);
5405
5406 if (exp.X_op != O_constant)
5407 {
5408 inst.error = _("alignment must be constant");
5409 return PARSE_OPERAND_FAIL;
5410 }
5411
5412 inst.operands[i].imm = exp.X_add_number << 8;
5413 inst.operands[i].immisalign = 1;
5414 /* Alignments are not pre-indexes. */
5415 inst.operands[i].preind = 0;
5416
5417 *str = p;
5418 return PARSE_OPERAND_SUCCESS;
5419}
5420
c19d1205
ZW
5421/* Parse all forms of an ARM address expression. Information is written
5422 to inst.operands[i] and/or inst.reloc.
09d92015 5423
c19d1205 5424 Preindexed addressing (.preind=1):
09d92015 5425
c19d1205
ZW
5426 [Rn, #offset] .reg=Rn .reloc.exp=offset
5427 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5428 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5429 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5430
c19d1205 5431 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5432
c19d1205 5433 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5434
c19d1205
ZW
5435 [Rn], #offset .reg=Rn .reloc.exp=offset
5436 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5437 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5438 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5439
c19d1205 5440 Unindexed addressing (.preind=0, .postind=0):
09d92015 5441
c19d1205 5442 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5443
c19d1205 5444 Other:
09d92015 5445
c19d1205
ZW
5446 [Rn]{!} shorthand for [Rn,#0]{!}
5447 =immediate .isreg=0 .reloc.exp=immediate
5448 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5449
c19d1205
ZW
5450 It is the caller's responsibility to check for addressing modes not
5451 supported by the instruction, and to set inst.reloc.type. */
5452
4962c51a
MS
5453static parse_operand_result
5454parse_address_main (char **str, int i, int group_relocations,
477330fc 5455 group_reloc_type group_type)
09d92015 5456{
c19d1205
ZW
5457 char *p = *str;
5458 int reg;
09d92015 5459
c19d1205 5460 if (skip_past_char (&p, '[') == FAIL)
09d92015 5461 {
c19d1205
ZW
5462 if (skip_past_char (&p, '=') == FAIL)
5463 {
974da60d 5464 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5465 inst.reloc.pc_rel = 1;
5466 inst.operands[i].reg = REG_PC;
5467 inst.operands[i].isreg = 1;
5468 inst.operands[i].preind = 1;
09d92015 5469
8335d6aa
JW
5470 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5471 return PARSE_OPERAND_FAIL;
5472 }
5473 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5474 /*allow_symbol_p=*/TRUE))
4962c51a 5475 return PARSE_OPERAND_FAIL;
09d92015 5476
c19d1205 5477 *str = p;
4962c51a 5478 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5479 }
5480
8ab8155f
NC
5481 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5482 skip_whitespace (p);
5483
dcbf9037 5484 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5485 {
c19d1205 5486 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5487 return PARSE_OPERAND_FAIL;
09d92015 5488 }
c19d1205
ZW
5489 inst.operands[i].reg = reg;
5490 inst.operands[i].isreg = 1;
09d92015 5491
c19d1205 5492 if (skip_past_comma (&p) == SUCCESS)
09d92015 5493 {
c19d1205 5494 inst.operands[i].preind = 1;
09d92015 5495
c19d1205
ZW
5496 if (*p == '+') p++;
5497 else if (*p == '-') p++, inst.operands[i].negative = 1;
5498
dcbf9037 5499 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5500 {
c19d1205
ZW
5501 inst.operands[i].imm = reg;
5502 inst.operands[i].immisreg = 1;
5503
5504 if (skip_past_comma (&p) == SUCCESS)
5505 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5506 return PARSE_OPERAND_FAIL;
c19d1205 5507 }
5287ad62 5508 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5509 {
5510 /* FIXME: '@' should be used here, but it's filtered out by generic
5511 code before we get to see it here. This may be subject to
5512 change. */
5513 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5514
8e560766
MGD
5515 if (result != PARSE_OPERAND_SUCCESS)
5516 return result;
5517 }
c19d1205
ZW
5518 else
5519 {
5520 if (inst.operands[i].negative)
5521 {
5522 inst.operands[i].negative = 0;
5523 p--;
5524 }
4962c51a 5525
5f4273c7
NC
5526 if (group_relocations
5527 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5528 {
5529 struct group_reloc_table_entry *entry;
5530
477330fc
RM
5531 /* Skip over the #: or : sequence. */
5532 if (*p == '#')
5533 p += 2;
5534 else
5535 p++;
4962c51a
MS
5536
5537 /* Try to parse a group relocation. Anything else is an
477330fc 5538 error. */
4962c51a
MS
5539 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5540 {
5541 inst.error = _("unknown group relocation");
5542 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5543 }
5544
5545 /* We now have the group relocation table entry corresponding to
5546 the name in the assembler source. Next, we parse the
477330fc 5547 expression. */
4962c51a
MS
5548 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5549 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5550
5551 /* Record the relocation type. */
477330fc
RM
5552 switch (group_type)
5553 {
5554 case GROUP_LDR:
5555 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5556 break;
4962c51a 5557
477330fc
RM
5558 case GROUP_LDRS:
5559 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5560 break;
4962c51a 5561
477330fc
RM
5562 case GROUP_LDC:
5563 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5564 break;
4962c51a 5565
477330fc
RM
5566 default:
5567 gas_assert (0);
5568 }
4962c51a 5569
477330fc 5570 if (inst.reloc.type == 0)
4962c51a
MS
5571 {
5572 inst.error = _("this group relocation is not allowed on this instruction");
5573 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5574 }
477330fc
RM
5575 }
5576 else
26d97720
NS
5577 {
5578 char *q = p;
5579 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5580 return PARSE_OPERAND_FAIL;
5581 /* If the offset is 0, find out if it's a +0 or -0. */
5582 if (inst.reloc.exp.X_op == O_constant
5583 && inst.reloc.exp.X_add_number == 0)
5584 {
5585 skip_whitespace (q);
5586 if (*q == '#')
5587 {
5588 q++;
5589 skip_whitespace (q);
5590 }
5591 if (*q == '-')
5592 inst.operands[i].negative = 1;
5593 }
5594 }
09d92015
MM
5595 }
5596 }
8e560766
MGD
5597 else if (skip_past_char (&p, ':') == SUCCESS)
5598 {
5599 /* FIXME: '@' should be used here, but it's filtered out by generic code
5600 before we get to see it here. This may be subject to change. */
5601 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5602
8e560766
MGD
5603 if (result != PARSE_OPERAND_SUCCESS)
5604 return result;
5605 }
09d92015 5606
c19d1205 5607 if (skip_past_char (&p, ']') == FAIL)
09d92015 5608 {
c19d1205 5609 inst.error = _("']' expected");
4962c51a 5610 return PARSE_OPERAND_FAIL;
09d92015
MM
5611 }
5612
c19d1205
ZW
5613 if (skip_past_char (&p, '!') == SUCCESS)
5614 inst.operands[i].writeback = 1;
09d92015 5615
c19d1205 5616 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5617 {
c19d1205
ZW
5618 if (skip_past_char (&p, '{') == SUCCESS)
5619 {
5620 /* [Rn], {expr} - unindexed, with option */
5621 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5622 0, 255, TRUE) == FAIL)
4962c51a 5623 return PARSE_OPERAND_FAIL;
09d92015 5624
c19d1205
ZW
5625 if (skip_past_char (&p, '}') == FAIL)
5626 {
5627 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5628 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5629 }
5630 if (inst.operands[i].preind)
5631 {
5632 inst.error = _("cannot combine index with option");
4962c51a 5633 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5634 }
5635 *str = p;
4962c51a 5636 return PARSE_OPERAND_SUCCESS;
09d92015 5637 }
c19d1205
ZW
5638 else
5639 {
5640 inst.operands[i].postind = 1;
5641 inst.operands[i].writeback = 1;
09d92015 5642
c19d1205
ZW
5643 if (inst.operands[i].preind)
5644 {
5645 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5646 return PARSE_OPERAND_FAIL;
c19d1205 5647 }
09d92015 5648
c19d1205
ZW
5649 if (*p == '+') p++;
5650 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5651
dcbf9037 5652 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5653 {
477330fc
RM
5654 /* We might be using the immediate for alignment already. If we
5655 are, OR the register number into the low-order bits. */
5656 if (inst.operands[i].immisalign)
5657 inst.operands[i].imm |= reg;
5658 else
5659 inst.operands[i].imm = reg;
c19d1205 5660 inst.operands[i].immisreg = 1;
a737bd4d 5661
c19d1205
ZW
5662 if (skip_past_comma (&p) == SUCCESS)
5663 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5664 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5665 }
5666 else
5667 {
26d97720 5668 char *q = p;
c19d1205
ZW
5669 if (inst.operands[i].negative)
5670 {
5671 inst.operands[i].negative = 0;
5672 p--;
5673 }
5674 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5675 return PARSE_OPERAND_FAIL;
26d97720
NS
5676 /* If the offset is 0, find out if it's a +0 or -0. */
5677 if (inst.reloc.exp.X_op == O_constant
5678 && inst.reloc.exp.X_add_number == 0)
5679 {
5680 skip_whitespace (q);
5681 if (*q == '#')
5682 {
5683 q++;
5684 skip_whitespace (q);
5685 }
5686 if (*q == '-')
5687 inst.operands[i].negative = 1;
5688 }
c19d1205
ZW
5689 }
5690 }
a737bd4d
NC
5691 }
5692
c19d1205
ZW
5693 /* If at this point neither .preind nor .postind is set, we have a
5694 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5695 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5696 {
5697 inst.operands[i].preind = 1;
5698 inst.reloc.exp.X_op = O_constant;
5699 inst.reloc.exp.X_add_number = 0;
5700 }
5701 *str = p;
4962c51a
MS
5702 return PARSE_OPERAND_SUCCESS;
5703}
5704
5705static int
5706parse_address (char **str, int i)
5707{
21d799b5 5708 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5709 ? SUCCESS : FAIL;
4962c51a
MS
5710}
5711
5712static parse_operand_result
5713parse_address_group_reloc (char **str, int i, group_reloc_type type)
5714{
5715 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5716}
5717
b6895b4f
PB
5718/* Parse an operand for a MOVW or MOVT instruction. */
5719static int
5720parse_half (char **str)
5721{
5722 char * p;
5f4273c7 5723
b6895b4f
PB
5724 p = *str;
5725 skip_past_char (&p, '#');
5f4273c7 5726 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5727 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5728 else if (strncasecmp (p, ":upper16:", 9) == 0)
5729 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5730
5731 if (inst.reloc.type != BFD_RELOC_UNUSED)
5732 {
5733 p += 9;
5f4273c7 5734 skip_whitespace (p);
b6895b4f
PB
5735 }
5736
5737 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5738 return FAIL;
5739
5740 if (inst.reloc.type == BFD_RELOC_UNUSED)
5741 {
5742 if (inst.reloc.exp.X_op != O_constant)
5743 {
5744 inst.error = _("constant expression expected");
5745 return FAIL;
5746 }
5747 if (inst.reloc.exp.X_add_number < 0
5748 || inst.reloc.exp.X_add_number > 0xffff)
5749 {
5750 inst.error = _("immediate value out of range");
5751 return FAIL;
5752 }
5753 }
5754 *str = p;
5755 return SUCCESS;
5756}
5757
c19d1205 5758/* Miscellaneous. */
a737bd4d 5759
c19d1205
ZW
5760/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5761 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5762static int
d2cd1205 5763parse_psr (char **str, bfd_boolean lhs)
09d92015 5764{
c19d1205
ZW
5765 char *p;
5766 unsigned long psr_field;
62b3e311
PB
5767 const struct asm_psr *psr;
5768 char *start;
d2cd1205 5769 bfd_boolean is_apsr = FALSE;
ac7f631b 5770 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5771
a4482bb6
NC
5772 /* PR gas/12698: If the user has specified -march=all then m_profile will
5773 be TRUE, but we want to ignore it in this case as we are building for any
5774 CPU type, including non-m variants. */
823d2571 5775 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5776 m_profile = FALSE;
5777
c19d1205
ZW
5778 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5779 feature for ease of use and backwards compatibility. */
5780 p = *str;
62b3e311 5781 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5782 {
5783 if (m_profile)
5784 goto unsupported_psr;
fa94de6b 5785
d2cd1205
JB
5786 psr_field = SPSR_BIT;
5787 }
5788 else if (strncasecmp (p, "CPSR", 4) == 0)
5789 {
5790 if (m_profile)
5791 goto unsupported_psr;
5792
5793 psr_field = 0;
5794 }
5795 else if (strncasecmp (p, "APSR", 4) == 0)
5796 {
5797 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5798 and ARMv7-R architecture CPUs. */
5799 is_apsr = TRUE;
5800 psr_field = 0;
5801 }
5802 else if (m_profile)
62b3e311
PB
5803 {
5804 start = p;
5805 do
5806 p++;
5807 while (ISALNUM (*p) || *p == '_');
5808
d2cd1205
JB
5809 if (strncasecmp (start, "iapsr", 5) == 0
5810 || strncasecmp (start, "eapsr", 5) == 0
5811 || strncasecmp (start, "xpsr", 4) == 0
5812 || strncasecmp (start, "psr", 3) == 0)
5813 p = start + strcspn (start, "rR") + 1;
5814
21d799b5 5815 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5816 p - start);
d2cd1205 5817
62b3e311
PB
5818 if (!psr)
5819 return FAIL;
09d92015 5820
d2cd1205
JB
5821 /* If APSR is being written, a bitfield may be specified. Note that
5822 APSR itself is handled above. */
5823 if (psr->field <= 3)
5824 {
5825 psr_field = psr->field;
5826 is_apsr = TRUE;
5827 goto check_suffix;
5828 }
5829
62b3e311 5830 *str = p;
d2cd1205
JB
5831 /* M-profile MSR instructions have the mask field set to "10", except
5832 *PSR variants which modify APSR, which may use a different mask (and
5833 have been handled already). Do that by setting the PSR_f field
5834 here. */
5835 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5836 }
d2cd1205
JB
5837 else
5838 goto unsupported_psr;
09d92015 5839
62b3e311 5840 p += 4;
d2cd1205 5841check_suffix:
c19d1205
ZW
5842 if (*p == '_')
5843 {
5844 /* A suffix follows. */
c19d1205
ZW
5845 p++;
5846 start = p;
a737bd4d 5847
c19d1205
ZW
5848 do
5849 p++;
5850 while (ISALNUM (*p) || *p == '_');
a737bd4d 5851
d2cd1205
JB
5852 if (is_apsr)
5853 {
5854 /* APSR uses a notation for bits, rather than fields. */
5855 unsigned int nzcvq_bits = 0;
5856 unsigned int g_bit = 0;
5857 char *bit;
fa94de6b 5858
d2cd1205
JB
5859 for (bit = start; bit != p; bit++)
5860 {
5861 switch (TOLOWER (*bit))
477330fc 5862 {
d2cd1205
JB
5863 case 'n':
5864 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5865 break;
5866
5867 case 'z':
5868 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5869 break;
5870
5871 case 'c':
5872 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5873 break;
5874
5875 case 'v':
5876 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5877 break;
fa94de6b 5878
d2cd1205
JB
5879 case 'q':
5880 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5881 break;
fa94de6b 5882
d2cd1205
JB
5883 case 'g':
5884 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5885 break;
fa94de6b 5886
d2cd1205
JB
5887 default:
5888 inst.error = _("unexpected bit specified after APSR");
5889 return FAIL;
5890 }
5891 }
fa94de6b 5892
d2cd1205
JB
5893 if (nzcvq_bits == 0x1f)
5894 psr_field |= PSR_f;
fa94de6b 5895
d2cd1205
JB
5896 if (g_bit == 0x1)
5897 {
5898 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5899 {
d2cd1205
JB
5900 inst.error = _("selected processor does not "
5901 "support DSP extension");
5902 return FAIL;
5903 }
5904
5905 psr_field |= PSR_s;
5906 }
fa94de6b 5907
d2cd1205
JB
5908 if ((nzcvq_bits & 0x20) != 0
5909 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5910 || (g_bit & 0x2) != 0)
5911 {
5912 inst.error = _("bad bitmask specified after APSR");
5913 return FAIL;
5914 }
5915 }
5916 else
477330fc 5917 {
d2cd1205 5918 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5919 p - start);
d2cd1205 5920 if (!psr)
477330fc 5921 goto error;
a737bd4d 5922
d2cd1205
JB
5923 psr_field |= psr->field;
5924 }
a737bd4d 5925 }
c19d1205 5926 else
a737bd4d 5927 {
c19d1205
ZW
5928 if (ISALNUM (*p))
5929 goto error; /* Garbage after "[CS]PSR". */
5930
d2cd1205 5931 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5932 is deprecated, but allow it anyway. */
d2cd1205
JB
5933 if (is_apsr && lhs)
5934 {
5935 psr_field |= PSR_f;
5936 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5937 "deprecated"));
5938 }
5939 else if (!m_profile)
5940 /* These bits are never right for M-profile devices: don't set them
5941 (only code paths which read/write APSR reach here). */
5942 psr_field |= (PSR_c | PSR_f);
a737bd4d 5943 }
c19d1205
ZW
5944 *str = p;
5945 return psr_field;
a737bd4d 5946
d2cd1205
JB
5947 unsupported_psr:
5948 inst.error = _("selected processor does not support requested special "
5949 "purpose register");
5950 return FAIL;
5951
c19d1205
ZW
5952 error:
5953 inst.error = _("flag for {c}psr instruction expected");
5954 return FAIL;
a737bd4d
NC
5955}
5956
c19d1205
ZW
5957/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5958 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5959
c19d1205
ZW
5960static int
5961parse_cps_flags (char **str)
a737bd4d 5962{
c19d1205
ZW
5963 int val = 0;
5964 int saw_a_flag = 0;
5965 char *s = *str;
a737bd4d 5966
c19d1205
ZW
5967 for (;;)
5968 switch (*s++)
5969 {
5970 case '\0': case ',':
5971 goto done;
a737bd4d 5972
c19d1205
ZW
5973 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5974 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5975 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5976
c19d1205
ZW
5977 default:
5978 inst.error = _("unrecognized CPS flag");
5979 return FAIL;
5980 }
a737bd4d 5981
c19d1205
ZW
5982 done:
5983 if (saw_a_flag == 0)
a737bd4d 5984 {
c19d1205
ZW
5985 inst.error = _("missing CPS flags");
5986 return FAIL;
a737bd4d 5987 }
a737bd4d 5988
c19d1205
ZW
5989 *str = s - 1;
5990 return val;
a737bd4d
NC
5991}
5992
c19d1205
ZW
5993/* Parse an endian specifier ("BE" or "LE", case insensitive);
5994 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5995
5996static int
c19d1205 5997parse_endian_specifier (char **str)
a737bd4d 5998{
c19d1205
ZW
5999 int little_endian;
6000 char *s = *str;
a737bd4d 6001
c19d1205
ZW
6002 if (strncasecmp (s, "BE", 2))
6003 little_endian = 0;
6004 else if (strncasecmp (s, "LE", 2))
6005 little_endian = 1;
6006 else
a737bd4d 6007 {
c19d1205 6008 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6009 return FAIL;
6010 }
6011
c19d1205 6012 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6013 {
c19d1205 6014 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6015 return FAIL;
6016 }
6017
c19d1205
ZW
6018 *str = s + 2;
6019 return little_endian;
6020}
a737bd4d 6021
c19d1205
ZW
6022/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6023 value suitable for poking into the rotate field of an sxt or sxta
6024 instruction, or FAIL on error. */
6025
6026static int
6027parse_ror (char **str)
6028{
6029 int rot;
6030 char *s = *str;
6031
6032 if (strncasecmp (s, "ROR", 3) == 0)
6033 s += 3;
6034 else
a737bd4d 6035 {
c19d1205 6036 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6037 return FAIL;
6038 }
c19d1205
ZW
6039
6040 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6041 return FAIL;
6042
6043 switch (rot)
a737bd4d 6044 {
c19d1205
ZW
6045 case 0: *str = s; return 0x0;
6046 case 8: *str = s; return 0x1;
6047 case 16: *str = s; return 0x2;
6048 case 24: *str = s; return 0x3;
6049
6050 default:
6051 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6052 return FAIL;
6053 }
c19d1205 6054}
a737bd4d 6055
c19d1205
ZW
6056/* Parse a conditional code (from conds[] below). The value returned is in the
6057 range 0 .. 14, or FAIL. */
6058static int
6059parse_cond (char **str)
6060{
c462b453 6061 char *q;
c19d1205 6062 const struct asm_cond *c;
c462b453
PB
6063 int n;
6064 /* Condition codes are always 2 characters, so matching up to
6065 3 characters is sufficient. */
6066 char cond[3];
a737bd4d 6067
c462b453
PB
6068 q = *str;
6069 n = 0;
6070 while (ISALPHA (*q) && n < 3)
6071 {
e07e6e58 6072 cond[n] = TOLOWER (*q);
c462b453
PB
6073 q++;
6074 n++;
6075 }
a737bd4d 6076
21d799b5 6077 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6078 if (!c)
a737bd4d 6079 {
c19d1205 6080 inst.error = _("condition required");
a737bd4d
NC
6081 return FAIL;
6082 }
6083
c19d1205
ZW
6084 *str = q;
6085 return c->value;
6086}
6087
e797f7e0
MGD
6088/* If the given feature available in the selected CPU, mark it as used.
6089 Returns TRUE iff feature is available. */
6090static bfd_boolean
6091mark_feature_used (const arm_feature_set *feature)
6092{
6093 /* Ensure the option is valid on the current architecture. */
6094 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6095 return FALSE;
6096
6097 /* Add the appropriate architecture feature for the barrier option used.
6098 */
6099 if (thumb_mode)
6100 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6101 else
6102 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6103
6104 return TRUE;
6105}
6106
62b3e311
PB
6107/* Parse an option for a barrier instruction. Returns the encoding for the
6108 option, or FAIL. */
6109static int
6110parse_barrier (char **str)
6111{
6112 char *p, *q;
6113 const struct asm_barrier_opt *o;
6114
6115 p = q = *str;
6116 while (ISALPHA (*q))
6117 q++;
6118
21d799b5 6119 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6120 q - p);
62b3e311
PB
6121 if (!o)
6122 return FAIL;
6123
e797f7e0
MGD
6124 if (!mark_feature_used (&o->arch))
6125 return FAIL;
6126
62b3e311
PB
6127 *str = q;
6128 return o->value;
6129}
6130
92e90b6e
PB
6131/* Parse the operands of a table branch instruction. Similar to a memory
6132 operand. */
6133static int
6134parse_tb (char **str)
6135{
6136 char * p = *str;
6137 int reg;
6138
6139 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6140 {
6141 inst.error = _("'[' expected");
6142 return FAIL;
6143 }
92e90b6e 6144
dcbf9037 6145 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6146 {
6147 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6148 return FAIL;
6149 }
6150 inst.operands[0].reg = reg;
6151
6152 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6153 {
6154 inst.error = _("',' expected");
6155 return FAIL;
6156 }
5f4273c7 6157
dcbf9037 6158 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6159 {
6160 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6161 return FAIL;
6162 }
6163 inst.operands[0].imm = reg;
6164
6165 if (skip_past_comma (&p) == SUCCESS)
6166 {
6167 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6168 return FAIL;
6169 if (inst.reloc.exp.X_add_number != 1)
6170 {
6171 inst.error = _("invalid shift");
6172 return FAIL;
6173 }
6174 inst.operands[0].shifted = 1;
6175 }
6176
6177 if (skip_past_char (&p, ']') == FAIL)
6178 {
6179 inst.error = _("']' expected");
6180 return FAIL;
6181 }
6182 *str = p;
6183 return SUCCESS;
6184}
6185
5287ad62
JB
6186/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6187 information on the types the operands can take and how they are encoded.
037e8744
JB
6188 Up to four operands may be read; this function handles setting the
6189 ".present" field for each read operand itself.
5287ad62
JB
6190 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6191 else returns FAIL. */
6192
6193static int
6194parse_neon_mov (char **str, int *which_operand)
6195{
6196 int i = *which_operand, val;
6197 enum arm_reg_type rtype;
6198 char *ptr = *str;
dcbf9037 6199 struct neon_type_el optype;
5f4273c7 6200
dcbf9037 6201 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6202 {
6203 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6204 inst.operands[i].reg = val;
6205 inst.operands[i].isscalar = 1;
dcbf9037 6206 inst.operands[i].vectype = optype;
5287ad62
JB
6207 inst.operands[i++].present = 1;
6208
6209 if (skip_past_comma (&ptr) == FAIL)
477330fc 6210 goto wanted_comma;
5f4273c7 6211
dcbf9037 6212 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6213 goto wanted_arm;
5f4273c7 6214
5287ad62
JB
6215 inst.operands[i].reg = val;
6216 inst.operands[i].isreg = 1;
6217 inst.operands[i].present = 1;
6218 }
037e8744 6219 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6220 != FAIL)
5287ad62
JB
6221 {
6222 /* Cases 0, 1, 2, 3, 5 (D only). */
6223 if (skip_past_comma (&ptr) == FAIL)
477330fc 6224 goto wanted_comma;
5f4273c7 6225
5287ad62
JB
6226 inst.operands[i].reg = val;
6227 inst.operands[i].isreg = 1;
6228 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6229 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6230 inst.operands[i].isvec = 1;
dcbf9037 6231 inst.operands[i].vectype = optype;
5287ad62
JB
6232 inst.operands[i++].present = 1;
6233
dcbf9037 6234 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6235 {
6236 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6237 Case 13: VMOV <Sd>, <Rm> */
6238 inst.operands[i].reg = val;
6239 inst.operands[i].isreg = 1;
6240 inst.operands[i].present = 1;
6241
6242 if (rtype == REG_TYPE_NQ)
6243 {
6244 first_error (_("can't use Neon quad register here"));
6245 return FAIL;
6246 }
6247 else if (rtype != REG_TYPE_VFS)
6248 {
6249 i++;
6250 if (skip_past_comma (&ptr) == FAIL)
6251 goto wanted_comma;
6252 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6253 goto wanted_arm;
6254 inst.operands[i].reg = val;
6255 inst.operands[i].isreg = 1;
6256 inst.operands[i].present = 1;
6257 }
6258 }
037e8744 6259 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6260 &optype)) != FAIL)
6261 {
6262 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6263 Case 1: VMOV<c><q> <Dd>, <Dm>
6264 Case 8: VMOV.F32 <Sd>, <Sm>
6265 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6266
6267 inst.operands[i].reg = val;
6268 inst.operands[i].isreg = 1;
6269 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6270 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6271 inst.operands[i].isvec = 1;
6272 inst.operands[i].vectype = optype;
6273 inst.operands[i].present = 1;
6274
6275 if (skip_past_comma (&ptr) == SUCCESS)
6276 {
6277 /* Case 15. */
6278 i++;
6279
6280 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6281 goto wanted_arm;
6282
6283 inst.operands[i].reg = val;
6284 inst.operands[i].isreg = 1;
6285 inst.operands[i++].present = 1;
6286
6287 if (skip_past_comma (&ptr) == FAIL)
6288 goto wanted_comma;
6289
6290 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6291 goto wanted_arm;
6292
6293 inst.operands[i].reg = val;
6294 inst.operands[i].isreg = 1;
6295 inst.operands[i].present = 1;
6296 }
6297 }
4641781c 6298 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6299 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6300 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6301 Case 10: VMOV.F32 <Sd>, #<imm>
6302 Case 11: VMOV.F64 <Dd>, #<imm> */
6303 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6304 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6305 == SUCCESS)
477330fc
RM
6306 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6307 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6308 ;
5287ad62 6309 else
477330fc
RM
6310 {
6311 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6312 return FAIL;
6313 }
5287ad62 6314 }
dcbf9037 6315 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6316 {
6317 /* Cases 6, 7. */
6318 inst.operands[i].reg = val;
6319 inst.operands[i].isreg = 1;
6320 inst.operands[i++].present = 1;
5f4273c7 6321
5287ad62 6322 if (skip_past_comma (&ptr) == FAIL)
477330fc 6323 goto wanted_comma;
5f4273c7 6324
dcbf9037 6325 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6326 {
6327 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6328 inst.operands[i].reg = val;
6329 inst.operands[i].isscalar = 1;
6330 inst.operands[i].present = 1;
6331 inst.operands[i].vectype = optype;
6332 }
dcbf9037 6333 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6334 {
6335 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6336 inst.operands[i].reg = val;
6337 inst.operands[i].isreg = 1;
6338 inst.operands[i++].present = 1;
6339
6340 if (skip_past_comma (&ptr) == FAIL)
6341 goto wanted_comma;
6342
6343 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6344 == FAIL)
6345 {
6346 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6347 return FAIL;
6348 }
6349
6350 inst.operands[i].reg = val;
6351 inst.operands[i].isreg = 1;
6352 inst.operands[i].isvec = 1;
6353 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6354 inst.operands[i].vectype = optype;
6355 inst.operands[i].present = 1;
6356
6357 if (rtype == REG_TYPE_VFS)
6358 {
6359 /* Case 14. */
6360 i++;
6361 if (skip_past_comma (&ptr) == FAIL)
6362 goto wanted_comma;
6363 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6364 &optype)) == FAIL)
6365 {
6366 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6367 return FAIL;
6368 }
6369 inst.operands[i].reg = val;
6370 inst.operands[i].isreg = 1;
6371 inst.operands[i].isvec = 1;
6372 inst.operands[i].issingle = 1;
6373 inst.operands[i].vectype = optype;
6374 inst.operands[i].present = 1;
6375 }
6376 }
037e8744 6377 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6378 != FAIL)
6379 {
6380 /* Case 13. */
6381 inst.operands[i].reg = val;
6382 inst.operands[i].isreg = 1;
6383 inst.operands[i].isvec = 1;
6384 inst.operands[i].issingle = 1;
6385 inst.operands[i].vectype = optype;
6386 inst.operands[i].present = 1;
6387 }
5287ad62
JB
6388 }
6389 else
6390 {
dcbf9037 6391 first_error (_("parse error"));
5287ad62
JB
6392 return FAIL;
6393 }
6394
6395 /* Successfully parsed the operands. Update args. */
6396 *which_operand = i;
6397 *str = ptr;
6398 return SUCCESS;
6399
5f4273c7 6400 wanted_comma:
dcbf9037 6401 first_error (_("expected comma"));
5287ad62 6402 return FAIL;
5f4273c7
NC
6403
6404 wanted_arm:
dcbf9037 6405 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6406 return FAIL;
5287ad62
JB
6407}
6408
5be8be5d
DG
6409/* Use this macro when the operand constraints are different
6410 for ARM and THUMB (e.g. ldrd). */
6411#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6412 ((arm_operand) | ((thumb_operand) << 16))
6413
c19d1205
ZW
6414/* Matcher codes for parse_operands. */
6415enum operand_parse_code
6416{
6417 OP_stop, /* end of line */
6418
6419 OP_RR, /* ARM register */
6420 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6421 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6422 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6423 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6424 optional trailing ! */
c19d1205
ZW
6425 OP_RRw, /* ARM register, not r15, optional trailing ! */
6426 OP_RCP, /* Coprocessor number */
6427 OP_RCN, /* Coprocessor register */
6428 OP_RF, /* FPA register */
6429 OP_RVS, /* VFP single precision register */
5287ad62
JB
6430 OP_RVD, /* VFP double precision register (0..15) */
6431 OP_RND, /* Neon double precision register (0..31) */
6432 OP_RNQ, /* Neon quad precision register */
037e8744 6433 OP_RVSD, /* VFP single or double precision register */
5287ad62 6434 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6435 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6436 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6437 OP_RVC, /* VFP control register */
6438 OP_RMF, /* Maverick F register */
6439 OP_RMD, /* Maverick D register */
6440 OP_RMFX, /* Maverick FX register */
6441 OP_RMDX, /* Maverick DX register */
6442 OP_RMAX, /* Maverick AX register */
6443 OP_RMDS, /* Maverick DSPSC register */
6444 OP_RIWR, /* iWMMXt wR register */
6445 OP_RIWC, /* iWMMXt wC register */
6446 OP_RIWG, /* iWMMXt wCG register */
6447 OP_RXA, /* XScale accumulator register */
6448
6449 OP_REGLST, /* ARM register list */
6450 OP_VRSLST, /* VFP single-precision register list */
6451 OP_VRDLST, /* VFP double-precision register list */
037e8744 6452 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6453 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6454 OP_NSTRLST, /* Neon element/structure list */
6455
5287ad62 6456 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6457 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6458 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6459 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6460 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6461 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6462 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6463 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6464 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6465 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6466 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6467
6468 OP_I0, /* immediate zero */
c19d1205
ZW
6469 OP_I7, /* immediate value 0 .. 7 */
6470 OP_I15, /* 0 .. 15 */
6471 OP_I16, /* 1 .. 16 */
5287ad62 6472 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6473 OP_I31, /* 0 .. 31 */
6474 OP_I31w, /* 0 .. 31, optional trailing ! */
6475 OP_I32, /* 1 .. 32 */
5287ad62
JB
6476 OP_I32z, /* 0 .. 32 */
6477 OP_I63, /* 0 .. 63 */
c19d1205 6478 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6479 OP_I64, /* 1 .. 64 */
6480 OP_I64z, /* 0 .. 64 */
c19d1205 6481 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6482
6483 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6484 OP_I7b, /* 0 .. 7 */
6485 OP_I15b, /* 0 .. 15 */
6486 OP_I31b, /* 0 .. 31 */
6487
6488 OP_SH, /* shifter operand */
4962c51a 6489 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6490 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6491 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6492 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6493 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6494 OP_EXP, /* arbitrary expression */
6495 OP_EXPi, /* same, with optional immediate prefix */
6496 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6497 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6498
6499 OP_CPSF, /* CPS flags */
6500 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6501 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6502 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6503 OP_COND, /* conditional code */
92e90b6e 6504 OP_TB, /* Table branch. */
c19d1205 6505
037e8744
JB
6506 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6507
c19d1205
ZW
6508 OP_RRnpc_I0, /* ARM register or literal 0 */
6509 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6510 OP_RR_EXi, /* ARM register or expression with imm prefix */
6511 OP_RF_IF, /* FPA register or immediate */
6512 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6513 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6514
6515 /* Optional operands. */
6516 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6517 OP_oI31b, /* 0 .. 31 */
5287ad62 6518 OP_oI32b, /* 1 .. 32 */
5f1af56b 6519 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6520 OP_oIffffb, /* 0 .. 65535 */
6521 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6522
6523 OP_oRR, /* ARM register */
6524 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6525 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6526 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6527 OP_oRND, /* Optional Neon double precision register */
6528 OP_oRNQ, /* Optional Neon quad precision register */
6529 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6530 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6531 OP_oSHll, /* LSL immediate */
6532 OP_oSHar, /* ASR immediate */
6533 OP_oSHllar, /* LSL or ASR immediate */
6534 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6535 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6536
5be8be5d
DG
6537 /* Some pre-defined mixed (ARM/THUMB) operands. */
6538 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6539 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6540 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6541
c19d1205
ZW
6542 OP_FIRST_OPTIONAL = OP_oI7b
6543};
a737bd4d 6544
c19d1205
ZW
6545/* Generic instruction operand parser. This does no encoding and no
6546 semantic validation; it merely squirrels values away in the inst
6547 structure. Returns SUCCESS or FAIL depending on whether the
6548 specified grammar matched. */
6549static int
5be8be5d 6550parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6551{
5be8be5d 6552 unsigned const int *upat = pattern;
c19d1205
ZW
6553 char *backtrack_pos = 0;
6554 const char *backtrack_error = 0;
99aad254 6555 int i, val = 0, backtrack_index = 0;
5287ad62 6556 enum arm_reg_type rtype;
4962c51a 6557 parse_operand_result result;
5be8be5d 6558 unsigned int op_parse_code;
c19d1205 6559
e07e6e58
NC
6560#define po_char_or_fail(chr) \
6561 do \
6562 { \
6563 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6564 goto bad_args; \
e07e6e58
NC
6565 } \
6566 while (0)
c19d1205 6567
e07e6e58
NC
6568#define po_reg_or_fail(regtype) \
6569 do \
dcbf9037 6570 { \
e07e6e58 6571 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6572 & inst.operands[i].vectype); \
e07e6e58 6573 if (val == FAIL) \
477330fc
RM
6574 { \
6575 first_error (_(reg_expected_msgs[regtype])); \
6576 goto failure; \
6577 } \
e07e6e58
NC
6578 inst.operands[i].reg = val; \
6579 inst.operands[i].isreg = 1; \
6580 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6581 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6582 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6583 || rtype == REG_TYPE_VFD \
6584 || rtype == REG_TYPE_NQ); \
dcbf9037 6585 } \
e07e6e58
NC
6586 while (0)
6587
6588#define po_reg_or_goto(regtype, label) \
6589 do \
6590 { \
6591 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6592 & inst.operands[i].vectype); \
6593 if (val == FAIL) \
6594 goto label; \
dcbf9037 6595 \
e07e6e58
NC
6596 inst.operands[i].reg = val; \
6597 inst.operands[i].isreg = 1; \
6598 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6599 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6600 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6601 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6602 || rtype == REG_TYPE_NQ); \
6603 } \
6604 while (0)
6605
6606#define po_imm_or_fail(min, max, popt) \
6607 do \
6608 { \
6609 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6610 goto failure; \
6611 inst.operands[i].imm = val; \
6612 } \
6613 while (0)
6614
6615#define po_scalar_or_goto(elsz, label) \
6616 do \
6617 { \
6618 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6619 if (val == FAIL) \
6620 goto label; \
6621 inst.operands[i].reg = val; \
6622 inst.operands[i].isscalar = 1; \
6623 } \
6624 while (0)
6625
6626#define po_misc_or_fail(expr) \
6627 do \
6628 { \
6629 if (expr) \
6630 goto failure; \
6631 } \
6632 while (0)
6633
6634#define po_misc_or_fail_no_backtrack(expr) \
6635 do \
6636 { \
6637 result = expr; \
6638 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6639 backtrack_pos = 0; \
6640 if (result != PARSE_OPERAND_SUCCESS) \
6641 goto failure; \
6642 } \
6643 while (0)
4962c51a 6644
52e7f43d
RE
6645#define po_barrier_or_imm(str) \
6646 do \
6647 { \
6648 val = parse_barrier (&str); \
ccb84d65
JB
6649 if (val == FAIL && ! ISALPHA (*str)) \
6650 goto immediate; \
6651 if (val == FAIL \
6652 /* ISB can only take SY as an option. */ \
6653 || ((inst.instruction & 0xf0) == 0x60 \
6654 && val != 0xf)) \
52e7f43d 6655 { \
ccb84d65
JB
6656 inst.error = _("invalid barrier type"); \
6657 backtrack_pos = 0; \
6658 goto failure; \
52e7f43d
RE
6659 } \
6660 } \
6661 while (0)
6662
c19d1205
ZW
6663 skip_whitespace (str);
6664
6665 for (i = 0; upat[i] != OP_stop; i++)
6666 {
5be8be5d
DG
6667 op_parse_code = upat[i];
6668 if (op_parse_code >= 1<<16)
6669 op_parse_code = thumb ? (op_parse_code >> 16)
6670 : (op_parse_code & ((1<<16)-1));
6671
6672 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6673 {
6674 /* Remember where we are in case we need to backtrack. */
9c2799c2 6675 gas_assert (!backtrack_pos);
c19d1205
ZW
6676 backtrack_pos = str;
6677 backtrack_error = inst.error;
6678 backtrack_index = i;
6679 }
6680
b6702015 6681 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6682 po_char_or_fail (',');
6683
5be8be5d 6684 switch (op_parse_code)
c19d1205
ZW
6685 {
6686 /* Registers */
6687 case OP_oRRnpc:
5be8be5d 6688 case OP_oRRnpcsp:
c19d1205 6689 case OP_RRnpc:
5be8be5d 6690 case OP_RRnpcsp:
c19d1205
ZW
6691 case OP_oRR:
6692 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6693 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6694 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6695 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6696 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6697 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6698 case OP_oRND:
5287ad62 6699 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6700 case OP_RVC:
6701 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6702 break;
6703 /* Also accept generic coprocessor regs for unknown registers. */
6704 coproc_reg:
6705 po_reg_or_fail (REG_TYPE_CN);
6706 break;
c19d1205
ZW
6707 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6708 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6709 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6710 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6711 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6712 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6713 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6714 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6715 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6716 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6717 case OP_oRNQ:
5287ad62 6718 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6719 case OP_oRNDQ:
5287ad62 6720 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6721 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6722 case OP_oRNSDQ:
6723 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6724
6725 /* Neon scalar. Using an element size of 8 means that some invalid
6726 scalars are accepted here, so deal with those in later code. */
6727 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6728
6729 case OP_RNDQ_I0:
6730 {
6731 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6732 break;
6733 try_imm0:
6734 po_imm_or_fail (0, 0, TRUE);
6735 }
6736 break;
6737
6738 case OP_RVSD_I0:
6739 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6740 break;
6741
aacf0b33
KT
6742 case OP_RSVD_FI0:
6743 {
6744 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6745 break;
6746 try_ifimm0:
6747 if (parse_ifimm_zero (&str))
6748 inst.operands[i].imm = 0;
6749 else
6750 {
6751 inst.error
6752 = _("only floating point zero is allowed as immediate value");
6753 goto failure;
6754 }
6755 }
6756 break;
6757
477330fc
RM
6758 case OP_RR_RNSC:
6759 {
6760 po_scalar_or_goto (8, try_rr);
6761 break;
6762 try_rr:
6763 po_reg_or_fail (REG_TYPE_RN);
6764 }
6765 break;
6766
6767 case OP_RNSDQ_RNSC:
6768 {
6769 po_scalar_or_goto (8, try_nsdq);
6770 break;
6771 try_nsdq:
6772 po_reg_or_fail (REG_TYPE_NSDQ);
6773 }
6774 break;
6775
6776 case OP_RNDQ_RNSC:
6777 {
6778 po_scalar_or_goto (8, try_ndq);
6779 break;
6780 try_ndq:
6781 po_reg_or_fail (REG_TYPE_NDQ);
6782 }
6783 break;
6784
6785 case OP_RND_RNSC:
6786 {
6787 po_scalar_or_goto (8, try_vfd);
6788 break;
6789 try_vfd:
6790 po_reg_or_fail (REG_TYPE_VFD);
6791 }
6792 break;
6793
6794 case OP_VMOV:
6795 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6796 not careful then bad things might happen. */
6797 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6798 break;
6799
6800 case OP_RNDQ_Ibig:
6801 {
6802 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6803 break;
6804 try_immbig:
6805 /* There's a possibility of getting a 64-bit immediate here, so
6806 we need special handling. */
8335d6aa
JW
6807 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6808 == FAIL)
477330fc
RM
6809 {
6810 inst.error = _("immediate value is out of range");
6811 goto failure;
6812 }
6813 }
6814 break;
6815
6816 case OP_RNDQ_I63b:
6817 {
6818 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6819 break;
6820 try_shimm:
6821 po_imm_or_fail (0, 63, TRUE);
6822 }
6823 break;
c19d1205
ZW
6824
6825 case OP_RRnpcb:
6826 po_char_or_fail ('[');
6827 po_reg_or_fail (REG_TYPE_RN);
6828 po_char_or_fail (']');
6829 break;
a737bd4d 6830
55881a11 6831 case OP_RRnpctw:
c19d1205 6832 case OP_RRw:
b6702015 6833 case OP_oRRw:
c19d1205
ZW
6834 po_reg_or_fail (REG_TYPE_RN);
6835 if (skip_past_char (&str, '!') == SUCCESS)
6836 inst.operands[i].writeback = 1;
6837 break;
6838
6839 /* Immediates */
6840 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6841 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6842 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6843 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6844 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6845 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6846 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6847 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6848 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6849 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6850 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6851 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6852
6853 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6854 case OP_oI7b:
6855 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6856 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6857 case OP_oI31b:
6858 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6859 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6860 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6861 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6862
6863 /* Immediate variants */
6864 case OP_oI255c:
6865 po_char_or_fail ('{');
6866 po_imm_or_fail (0, 255, TRUE);
6867 po_char_or_fail ('}');
6868 break;
6869
6870 case OP_I31w:
6871 /* The expression parser chokes on a trailing !, so we have
6872 to find it first and zap it. */
6873 {
6874 char *s = str;
6875 while (*s && *s != ',')
6876 s++;
6877 if (s[-1] == '!')
6878 {
6879 s[-1] = '\0';
6880 inst.operands[i].writeback = 1;
6881 }
6882 po_imm_or_fail (0, 31, TRUE);
6883 if (str == s - 1)
6884 str = s;
6885 }
6886 break;
6887
6888 /* Expressions */
6889 case OP_EXPi: EXPi:
6890 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6891 GE_OPT_PREFIX));
6892 break;
6893
6894 case OP_EXP:
6895 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6896 GE_NO_PREFIX));
6897 break;
6898
6899 case OP_EXPr: EXPr:
6900 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6901 GE_NO_PREFIX));
6902 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6903 {
c19d1205
ZW
6904 val = parse_reloc (&str);
6905 if (val == -1)
6906 {
6907 inst.error = _("unrecognized relocation suffix");
6908 goto failure;
6909 }
6910 else if (val != BFD_RELOC_UNUSED)
6911 {
6912 inst.operands[i].imm = val;
6913 inst.operands[i].hasreloc = 1;
6914 }
a737bd4d 6915 }
c19d1205 6916 break;
a737bd4d 6917
b6895b4f
PB
6918 /* Operand for MOVW or MOVT. */
6919 case OP_HALF:
6920 po_misc_or_fail (parse_half (&str));
6921 break;
6922
e07e6e58 6923 /* Register or expression. */
c19d1205
ZW
6924 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6925 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6926
e07e6e58 6927 /* Register or immediate. */
c19d1205
ZW
6928 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6929 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6930
c19d1205
ZW
6931 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6932 IF:
6933 if (!is_immediate_prefix (*str))
6934 goto bad_args;
6935 str++;
6936 val = parse_fpa_immediate (&str);
6937 if (val == FAIL)
6938 goto failure;
6939 /* FPA immediates are encoded as registers 8-15.
6940 parse_fpa_immediate has already applied the offset. */
6941 inst.operands[i].reg = val;
6942 inst.operands[i].isreg = 1;
6943 break;
09d92015 6944
2d447fca
JM
6945 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6946 I32z: po_imm_or_fail (0, 32, FALSE); break;
6947
e07e6e58 6948 /* Two kinds of register. */
c19d1205
ZW
6949 case OP_RIWR_RIWC:
6950 {
6951 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6952 if (!rege
6953 || (rege->type != REG_TYPE_MMXWR
6954 && rege->type != REG_TYPE_MMXWC
6955 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6956 {
6957 inst.error = _("iWMMXt data or control register expected");
6958 goto failure;
6959 }
6960 inst.operands[i].reg = rege->number;
6961 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6962 }
6963 break;
09d92015 6964
41adaa5c
JM
6965 case OP_RIWC_RIWG:
6966 {
6967 struct reg_entry *rege = arm_reg_parse_multi (&str);
6968 if (!rege
6969 || (rege->type != REG_TYPE_MMXWC
6970 && rege->type != REG_TYPE_MMXWCG))
6971 {
6972 inst.error = _("iWMMXt control register expected");
6973 goto failure;
6974 }
6975 inst.operands[i].reg = rege->number;
6976 inst.operands[i].isreg = 1;
6977 }
6978 break;
6979
c19d1205
ZW
6980 /* Misc */
6981 case OP_CPSF: val = parse_cps_flags (&str); break;
6982 case OP_ENDI: val = parse_endian_specifier (&str); break;
6983 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6984 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6985 case OP_oBARRIER_I15:
6986 po_barrier_or_imm (str); break;
6987 immediate:
6988 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 6989 goto failure;
52e7f43d 6990 break;
c19d1205 6991
fa94de6b 6992 case OP_wPSR:
d2cd1205 6993 case OP_rPSR:
90ec0d68
MGD
6994 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6995 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6996 {
6997 inst.error = _("Banked registers are not available with this "
6998 "architecture.");
6999 goto failure;
7000 }
7001 break;
d2cd1205
JB
7002 try_psr:
7003 val = parse_psr (&str, op_parse_code == OP_wPSR);
7004 break;
037e8744 7005
477330fc
RM
7006 case OP_APSR_RR:
7007 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7008 break;
7009 try_apsr:
7010 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7011 instruction). */
7012 if (strncasecmp (str, "APSR_", 5) == 0)
7013 {
7014 unsigned found = 0;
7015 str += 5;
7016 while (found < 15)
7017 switch (*str++)
7018 {
7019 case 'c': found = (found & 1) ? 16 : found | 1; break;
7020 case 'n': found = (found & 2) ? 16 : found | 2; break;
7021 case 'z': found = (found & 4) ? 16 : found | 4; break;
7022 case 'v': found = (found & 8) ? 16 : found | 8; break;
7023 default: found = 16;
7024 }
7025 if (found != 15)
7026 goto failure;
7027 inst.operands[i].isvec = 1;
f7c21dc7
NC
7028 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7029 inst.operands[i].reg = REG_PC;
477330fc
RM
7030 }
7031 else
7032 goto failure;
7033 break;
037e8744 7034
92e90b6e
PB
7035 case OP_TB:
7036 po_misc_or_fail (parse_tb (&str));
7037 break;
7038
e07e6e58 7039 /* Register lists. */
c19d1205
ZW
7040 case OP_REGLST:
7041 val = parse_reg_list (&str);
7042 if (*str == '^')
7043 {
5e0d7f77 7044 inst.operands[i].writeback = 1;
c19d1205
ZW
7045 str++;
7046 }
7047 break;
09d92015 7048
c19d1205 7049 case OP_VRSLST:
5287ad62 7050 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7051 break;
09d92015 7052
c19d1205 7053 case OP_VRDLST:
5287ad62 7054 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7055 break;
a737bd4d 7056
477330fc
RM
7057 case OP_VRSDLST:
7058 /* Allow Q registers too. */
7059 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7060 REGLIST_NEON_D);
7061 if (val == FAIL)
7062 {
7063 inst.error = NULL;
7064 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7065 REGLIST_VFP_S);
7066 inst.operands[i].issingle = 1;
7067 }
7068 break;
7069
7070 case OP_NRDLST:
7071 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7072 REGLIST_NEON_D);
7073 break;
5287ad62
JB
7074
7075 case OP_NSTRLST:
477330fc
RM
7076 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7077 &inst.operands[i].vectype);
7078 break;
5287ad62 7079
c19d1205
ZW
7080 /* Addressing modes */
7081 case OP_ADDR:
7082 po_misc_or_fail (parse_address (&str, i));
7083 break;
09d92015 7084
4962c51a
MS
7085 case OP_ADDRGLDR:
7086 po_misc_or_fail_no_backtrack (
477330fc 7087 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7088 break;
7089
7090 case OP_ADDRGLDRS:
7091 po_misc_or_fail_no_backtrack (
477330fc 7092 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7093 break;
7094
7095 case OP_ADDRGLDC:
7096 po_misc_or_fail_no_backtrack (
477330fc 7097 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7098 break;
7099
c19d1205
ZW
7100 case OP_SH:
7101 po_misc_or_fail (parse_shifter_operand (&str, i));
7102 break;
09d92015 7103
4962c51a
MS
7104 case OP_SHG:
7105 po_misc_or_fail_no_backtrack (
477330fc 7106 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7107 break;
7108
c19d1205
ZW
7109 case OP_oSHll:
7110 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7111 break;
09d92015 7112
c19d1205
ZW
7113 case OP_oSHar:
7114 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7115 break;
09d92015 7116
c19d1205
ZW
7117 case OP_oSHllar:
7118 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7119 break;
09d92015 7120
c19d1205 7121 default:
5be8be5d 7122 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7123 }
09d92015 7124
c19d1205
ZW
7125 /* Various value-based sanity checks and shared operations. We
7126 do not signal immediate failures for the register constraints;
7127 this allows a syntax error to take precedence. */
5be8be5d 7128 switch (op_parse_code)
c19d1205
ZW
7129 {
7130 case OP_oRRnpc:
7131 case OP_RRnpc:
7132 case OP_RRnpcb:
7133 case OP_RRw:
b6702015 7134 case OP_oRRw:
c19d1205
ZW
7135 case OP_RRnpc_I0:
7136 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7137 inst.error = BAD_PC;
7138 break;
09d92015 7139
5be8be5d
DG
7140 case OP_oRRnpcsp:
7141 case OP_RRnpcsp:
7142 if (inst.operands[i].isreg)
7143 {
7144 if (inst.operands[i].reg == REG_PC)
7145 inst.error = BAD_PC;
7146 else if (inst.operands[i].reg == REG_SP)
7147 inst.error = BAD_SP;
7148 }
7149 break;
7150
55881a11 7151 case OP_RRnpctw:
fa94de6b
RM
7152 if (inst.operands[i].isreg
7153 && inst.operands[i].reg == REG_PC
55881a11
MGD
7154 && (inst.operands[i].writeback || thumb))
7155 inst.error = BAD_PC;
7156 break;
7157
c19d1205
ZW
7158 case OP_CPSF:
7159 case OP_ENDI:
7160 case OP_oROR:
d2cd1205
JB
7161 case OP_wPSR:
7162 case OP_rPSR:
c19d1205 7163 case OP_COND:
52e7f43d 7164 case OP_oBARRIER_I15:
c19d1205
ZW
7165 case OP_REGLST:
7166 case OP_VRSLST:
7167 case OP_VRDLST:
477330fc
RM
7168 case OP_VRSDLST:
7169 case OP_NRDLST:
7170 case OP_NSTRLST:
c19d1205
ZW
7171 if (val == FAIL)
7172 goto failure;
7173 inst.operands[i].imm = val;
7174 break;
a737bd4d 7175
c19d1205
ZW
7176 default:
7177 break;
7178 }
09d92015 7179
c19d1205
ZW
7180 /* If we get here, this operand was successfully parsed. */
7181 inst.operands[i].present = 1;
7182 continue;
09d92015 7183
c19d1205 7184 bad_args:
09d92015 7185 inst.error = BAD_ARGS;
c19d1205
ZW
7186
7187 failure:
7188 if (!backtrack_pos)
d252fdde
PB
7189 {
7190 /* The parse routine should already have set inst.error, but set a
5f4273c7 7191 default here just in case. */
d252fdde
PB
7192 if (!inst.error)
7193 inst.error = _("syntax error");
7194 return FAIL;
7195 }
c19d1205
ZW
7196
7197 /* Do not backtrack over a trailing optional argument that
7198 absorbed some text. We will only fail again, with the
7199 'garbage following instruction' error message, which is
7200 probably less helpful than the current one. */
7201 if (backtrack_index == i && backtrack_pos != str
7202 && upat[i+1] == OP_stop)
d252fdde
PB
7203 {
7204 if (!inst.error)
7205 inst.error = _("syntax error");
7206 return FAIL;
7207 }
c19d1205
ZW
7208
7209 /* Try again, skipping the optional argument at backtrack_pos. */
7210 str = backtrack_pos;
7211 inst.error = backtrack_error;
7212 inst.operands[backtrack_index].present = 0;
7213 i = backtrack_index;
7214 backtrack_pos = 0;
09d92015 7215 }
09d92015 7216
c19d1205
ZW
7217 /* Check that we have parsed all the arguments. */
7218 if (*str != '\0' && !inst.error)
7219 inst.error = _("garbage following instruction");
09d92015 7220
c19d1205 7221 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7222}
7223
c19d1205
ZW
7224#undef po_char_or_fail
7225#undef po_reg_or_fail
7226#undef po_reg_or_goto
7227#undef po_imm_or_fail
5287ad62 7228#undef po_scalar_or_fail
52e7f43d 7229#undef po_barrier_or_imm
e07e6e58 7230
c19d1205 7231/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7232#define constraint(expr, err) \
7233 do \
c19d1205 7234 { \
e07e6e58
NC
7235 if (expr) \
7236 { \
7237 inst.error = err; \
7238 return; \
7239 } \
c19d1205 7240 } \
e07e6e58 7241 while (0)
c19d1205 7242
fdfde340
JM
7243/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7244 instructions are unpredictable if these registers are used. This
7245 is the BadReg predicate in ARM's Thumb-2 documentation. */
7246#define reject_bad_reg(reg) \
7247 do \
7248 if (reg == REG_SP || reg == REG_PC) \
7249 { \
7250 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7251 return; \
7252 } \
7253 while (0)
7254
94206790
MM
7255/* If REG is R13 (the stack pointer), warn that its use is
7256 deprecated. */
7257#define warn_deprecated_sp(reg) \
7258 do \
7259 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7260 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7261 while (0)
7262
c19d1205
ZW
7263/* Functions for operand encoding. ARM, then Thumb. */
7264
d840c081 7265#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7266
9db2f6b4
RL
7267/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7268
7269 The only binary encoding difference is the Coprocessor number. Coprocessor
7270 9 is used for half-precision calculations or conversions. The format of the
7271 instruction is the same as the equivalent Coprocessor 10 instuction that
7272 exists for Single-Precision operation. */
7273
7274static void
7275do_scalar_fp16_v82_encode (void)
7276{
7277 if (inst.cond != COND_ALWAYS)
7278 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7279 " the behaviour is UNPREDICTABLE"));
7280 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7281 _(BAD_FP16));
7282
7283 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7284 mark_feature_used (&arm_ext_fp16);
7285}
7286
c19d1205
ZW
7287/* If VAL can be encoded in the immediate field of an ARM instruction,
7288 return the encoded form. Otherwise, return FAIL. */
7289
7290static unsigned int
7291encode_arm_immediate (unsigned int val)
09d92015 7292{
c19d1205
ZW
7293 unsigned int a, i;
7294
4f1d6205
L
7295 if (val <= 0xff)
7296 return val;
7297
7298 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7299 if ((a = rotate_left (val, i)) <= 0xff)
7300 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7301
7302 return FAIL;
09d92015
MM
7303}
7304
c19d1205
ZW
7305/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7306 return the encoded form. Otherwise, return FAIL. */
7307static unsigned int
7308encode_thumb32_immediate (unsigned int val)
09d92015 7309{
c19d1205 7310 unsigned int a, i;
09d92015 7311
9c3c69f2 7312 if (val <= 0xff)
c19d1205 7313 return val;
a737bd4d 7314
9c3c69f2 7315 for (i = 1; i <= 24; i++)
09d92015 7316 {
9c3c69f2
PB
7317 a = val >> i;
7318 if ((val & ~(0xff << i)) == 0)
7319 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7320 }
a737bd4d 7321
c19d1205
ZW
7322 a = val & 0xff;
7323 if (val == ((a << 16) | a))
7324 return 0x100 | a;
7325 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7326 return 0x300 | a;
09d92015 7327
c19d1205
ZW
7328 a = val & 0xff00;
7329 if (val == ((a << 16) | a))
7330 return 0x200 | (a >> 8);
a737bd4d 7331
c19d1205 7332 return FAIL;
09d92015 7333}
5287ad62 7334/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7335
7336static void
5287ad62
JB
7337encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7338{
7339 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7340 && reg > 15)
7341 {
b1cc4aeb 7342 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7343 {
7344 if (thumb_mode)
7345 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7346 fpu_vfp_ext_d32);
7347 else
7348 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7349 fpu_vfp_ext_d32);
7350 }
5287ad62 7351 else
477330fc
RM
7352 {
7353 first_error (_("D register out of range for selected VFP version"));
7354 return;
7355 }
5287ad62
JB
7356 }
7357
c19d1205 7358 switch (pos)
09d92015 7359 {
c19d1205
ZW
7360 case VFP_REG_Sd:
7361 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7362 break;
7363
7364 case VFP_REG_Sn:
7365 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7366 break;
7367
7368 case VFP_REG_Sm:
7369 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7370 break;
7371
5287ad62
JB
7372 case VFP_REG_Dd:
7373 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7374 break;
5f4273c7 7375
5287ad62
JB
7376 case VFP_REG_Dn:
7377 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7378 break;
5f4273c7 7379
5287ad62
JB
7380 case VFP_REG_Dm:
7381 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7382 break;
7383
c19d1205
ZW
7384 default:
7385 abort ();
09d92015 7386 }
09d92015
MM
7387}
7388
c19d1205 7389/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7390 if any, is handled by md_apply_fix. */
09d92015 7391static void
c19d1205 7392encode_arm_shift (int i)
09d92015 7393{
c19d1205
ZW
7394 if (inst.operands[i].shift_kind == SHIFT_RRX)
7395 inst.instruction |= SHIFT_ROR << 5;
7396 else
09d92015 7397 {
c19d1205
ZW
7398 inst.instruction |= inst.operands[i].shift_kind << 5;
7399 if (inst.operands[i].immisreg)
7400 {
7401 inst.instruction |= SHIFT_BY_REG;
7402 inst.instruction |= inst.operands[i].imm << 8;
7403 }
7404 else
7405 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7406 }
c19d1205 7407}
09d92015 7408
c19d1205
ZW
7409static void
7410encode_arm_shifter_operand (int i)
7411{
7412 if (inst.operands[i].isreg)
09d92015 7413 {
c19d1205
ZW
7414 inst.instruction |= inst.operands[i].reg;
7415 encode_arm_shift (i);
09d92015 7416 }
c19d1205 7417 else
a415b1cd
JB
7418 {
7419 inst.instruction |= INST_IMMEDIATE;
7420 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7421 inst.instruction |= inst.operands[i].imm;
7422 }
09d92015
MM
7423}
7424
c19d1205 7425/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7426static void
c19d1205 7427encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7428{
2b2f5df9
NC
7429 /* PR 14260:
7430 Generate an error if the operand is not a register. */
7431 constraint (!inst.operands[i].isreg,
7432 _("Instruction does not support =N addresses"));
7433
c19d1205 7434 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7435
c19d1205 7436 if (inst.operands[i].preind)
09d92015 7437 {
c19d1205
ZW
7438 if (is_t)
7439 {
7440 inst.error = _("instruction does not accept preindexed addressing");
7441 return;
7442 }
7443 inst.instruction |= PRE_INDEX;
7444 if (inst.operands[i].writeback)
7445 inst.instruction |= WRITE_BACK;
09d92015 7446
c19d1205
ZW
7447 }
7448 else if (inst.operands[i].postind)
7449 {
9c2799c2 7450 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7451 if (is_t)
7452 inst.instruction |= WRITE_BACK;
7453 }
7454 else /* unindexed - only for coprocessor */
09d92015 7455 {
c19d1205 7456 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7457 return;
7458 }
7459
c19d1205
ZW
7460 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7461 && (((inst.instruction & 0x000f0000) >> 16)
7462 == ((inst.instruction & 0x0000f000) >> 12)))
7463 as_warn ((inst.instruction & LOAD_BIT)
7464 ? _("destination register same as write-back base")
7465 : _("source register same as write-back base"));
09d92015
MM
7466}
7467
c19d1205
ZW
7468/* inst.operands[i] was set up by parse_address. Encode it into an
7469 ARM-format mode 2 load or store instruction. If is_t is true,
7470 reject forms that cannot be used with a T instruction (i.e. not
7471 post-indexed). */
a737bd4d 7472static void
c19d1205 7473encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7474{
5be8be5d
DG
7475 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7476
c19d1205 7477 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7478
c19d1205 7479 if (inst.operands[i].immisreg)
09d92015 7480 {
5be8be5d
DG
7481 constraint ((inst.operands[i].imm == REG_PC
7482 || (is_pc && inst.operands[i].writeback)),
7483 BAD_PC_ADDRESSING);
c19d1205
ZW
7484 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7485 inst.instruction |= inst.operands[i].imm;
7486 if (!inst.operands[i].negative)
7487 inst.instruction |= INDEX_UP;
7488 if (inst.operands[i].shifted)
7489 {
7490 if (inst.operands[i].shift_kind == SHIFT_RRX)
7491 inst.instruction |= SHIFT_ROR << 5;
7492 else
7493 {
7494 inst.instruction |= inst.operands[i].shift_kind << 5;
7495 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7496 }
7497 }
09d92015 7498 }
c19d1205 7499 else /* immediate offset in inst.reloc */
09d92015 7500 {
5be8be5d
DG
7501 if (is_pc && !inst.reloc.pc_rel)
7502 {
7503 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7504
7505 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7506 cannot use PC in addressing.
7507 PC cannot be used in writeback addressing, either. */
7508 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7509 BAD_PC_ADDRESSING);
23a10334 7510
dc5ec521 7511 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7512 if (warn_on_deprecated
7513 && !is_load
7514 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7515 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7516 }
7517
c19d1205 7518 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7519 {
7520 /* Prefer + for zero encoded value. */
7521 if (!inst.operands[i].negative)
7522 inst.instruction |= INDEX_UP;
7523 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7524 }
09d92015 7525 }
09d92015
MM
7526}
7527
c19d1205
ZW
7528/* inst.operands[i] was set up by parse_address. Encode it into an
7529 ARM-format mode 3 load or store instruction. Reject forms that
7530 cannot be used with such instructions. If is_t is true, reject
7531 forms that cannot be used with a T instruction (i.e. not
7532 post-indexed). */
7533static void
7534encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7535{
c19d1205 7536 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7537 {
c19d1205
ZW
7538 inst.error = _("instruction does not accept scaled register index");
7539 return;
09d92015 7540 }
a737bd4d 7541
c19d1205 7542 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7543
c19d1205
ZW
7544 if (inst.operands[i].immisreg)
7545 {
5be8be5d 7546 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7547 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7548 BAD_PC_ADDRESSING);
eb9f3f00
JB
7549 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7550 BAD_PC_WRITEBACK);
c19d1205
ZW
7551 inst.instruction |= inst.operands[i].imm;
7552 if (!inst.operands[i].negative)
7553 inst.instruction |= INDEX_UP;
7554 }
7555 else /* immediate offset in inst.reloc */
7556 {
5be8be5d
DG
7557 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7558 && inst.operands[i].writeback),
7559 BAD_PC_WRITEBACK);
c19d1205
ZW
7560 inst.instruction |= HWOFFSET_IMM;
7561 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7562 {
7563 /* Prefer + for zero encoded value. */
7564 if (!inst.operands[i].negative)
7565 inst.instruction |= INDEX_UP;
7566
7567 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7568 }
c19d1205 7569 }
a737bd4d
NC
7570}
7571
8335d6aa
JW
7572/* Write immediate bits [7:0] to the following locations:
7573
7574 |28/24|23 19|18 16|15 4|3 0|
7575 | 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|
7576
7577 This function is used by VMOV/VMVN/VORR/VBIC. */
7578
7579static void
7580neon_write_immbits (unsigned immbits)
7581{
7582 inst.instruction |= immbits & 0xf;
7583 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7584 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7585}
7586
7587/* Invert low-order SIZE bits of XHI:XLO. */
7588
7589static void
7590neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7591{
7592 unsigned immlo = xlo ? *xlo : 0;
7593 unsigned immhi = xhi ? *xhi : 0;
7594
7595 switch (size)
7596 {
7597 case 8:
7598 immlo = (~immlo) & 0xff;
7599 break;
7600
7601 case 16:
7602 immlo = (~immlo) & 0xffff;
7603 break;
7604
7605 case 64:
7606 immhi = (~immhi) & 0xffffffff;
7607 /* fall through. */
7608
7609 case 32:
7610 immlo = (~immlo) & 0xffffffff;
7611 break;
7612
7613 default:
7614 abort ();
7615 }
7616
7617 if (xlo)
7618 *xlo = immlo;
7619
7620 if (xhi)
7621 *xhi = immhi;
7622}
7623
7624/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7625 A, B, C, D. */
09d92015 7626
c19d1205 7627static int
8335d6aa 7628neon_bits_same_in_bytes (unsigned imm)
09d92015 7629{
8335d6aa
JW
7630 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7631 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7632 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7633 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7634}
a737bd4d 7635
8335d6aa 7636/* For immediate of above form, return 0bABCD. */
09d92015 7637
8335d6aa
JW
7638static unsigned
7639neon_squash_bits (unsigned imm)
7640{
7641 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7642 | ((imm & 0x01000000) >> 21);
7643}
7644
7645/* Compress quarter-float representation to 0b...000 abcdefgh. */
7646
7647static unsigned
7648neon_qfloat_bits (unsigned imm)
7649{
7650 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7651}
7652
7653/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7654 the instruction. *OP is passed as the initial value of the op field, and
7655 may be set to a different value depending on the constant (i.e.
7656 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7657 MVN). If the immediate looks like a repeated pattern then also
7658 try smaller element sizes. */
7659
7660static int
7661neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7662 unsigned *immbits, int *op, int size,
7663 enum neon_el_type type)
7664{
7665 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7666 float. */
7667 if (type == NT_float && !float_p)
7668 return FAIL;
7669
7670 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7671 {
8335d6aa
JW
7672 if (size != 32 || *op == 1)
7673 return FAIL;
7674 *immbits = neon_qfloat_bits (immlo);
7675 return 0xf;
7676 }
7677
7678 if (size == 64)
7679 {
7680 if (neon_bits_same_in_bytes (immhi)
7681 && neon_bits_same_in_bytes (immlo))
c19d1205 7682 {
8335d6aa
JW
7683 if (*op == 1)
7684 return FAIL;
7685 *immbits = (neon_squash_bits (immhi) << 4)
7686 | neon_squash_bits (immlo);
7687 *op = 1;
7688 return 0xe;
c19d1205 7689 }
a737bd4d 7690
8335d6aa
JW
7691 if (immhi != immlo)
7692 return FAIL;
7693 }
a737bd4d 7694
8335d6aa 7695 if (size >= 32)
09d92015 7696 {
8335d6aa 7697 if (immlo == (immlo & 0x000000ff))
c19d1205 7698 {
8335d6aa
JW
7699 *immbits = immlo;
7700 return 0x0;
c19d1205 7701 }
8335d6aa 7702 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7703 {
8335d6aa
JW
7704 *immbits = immlo >> 8;
7705 return 0x2;
c19d1205 7706 }
8335d6aa
JW
7707 else if (immlo == (immlo & 0x00ff0000))
7708 {
7709 *immbits = immlo >> 16;
7710 return 0x4;
7711 }
7712 else if (immlo == (immlo & 0xff000000))
7713 {
7714 *immbits = immlo >> 24;
7715 return 0x6;
7716 }
7717 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7718 {
7719 *immbits = (immlo >> 8) & 0xff;
7720 return 0xc;
7721 }
7722 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7723 {
7724 *immbits = (immlo >> 16) & 0xff;
7725 return 0xd;
7726 }
7727
7728 if ((immlo & 0xffff) != (immlo >> 16))
7729 return FAIL;
7730 immlo &= 0xffff;
09d92015 7731 }
a737bd4d 7732
8335d6aa 7733 if (size >= 16)
4962c51a 7734 {
8335d6aa
JW
7735 if (immlo == (immlo & 0x000000ff))
7736 {
7737 *immbits = immlo;
7738 return 0x8;
7739 }
7740 else if (immlo == (immlo & 0x0000ff00))
7741 {
7742 *immbits = immlo >> 8;
7743 return 0xa;
7744 }
7745
7746 if ((immlo & 0xff) != (immlo >> 8))
7747 return FAIL;
7748 immlo &= 0xff;
4962c51a
MS
7749 }
7750
8335d6aa
JW
7751 if (immlo == (immlo & 0x000000ff))
7752 {
7753 /* Don't allow MVN with 8-bit immediate. */
7754 if (*op == 1)
7755 return FAIL;
7756 *immbits = immlo;
7757 return 0xe;
7758 }
26d97720 7759
8335d6aa 7760 return FAIL;
c19d1205 7761}
a737bd4d 7762
5fc177c8 7763#if defined BFD_HOST_64_BIT
ba592044
AM
7764/* Returns TRUE if double precision value V may be cast
7765 to single precision without loss of accuracy. */
7766
7767static bfd_boolean
5fc177c8 7768is_double_a_single (bfd_int64_t v)
ba592044 7769{
5fc177c8 7770 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7771 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7772
7773 return (exp == 0 || exp == 0x7FF
7774 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7775 && (mantissa & 0x1FFFFFFFl) == 0;
7776}
7777
3739860c 7778/* Returns a double precision value casted to single precision
ba592044
AM
7779 (ignoring the least significant bits in exponent and mantissa). */
7780
7781static int
5fc177c8 7782double_to_single (bfd_int64_t v)
ba592044
AM
7783{
7784 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7785 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7786 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7787
7788 if (exp == 0x7FF)
7789 exp = 0xFF;
7790 else
7791 {
7792 exp = exp - 1023 + 127;
7793 if (exp >= 0xFF)
7794 {
7795 /* Infinity. */
7796 exp = 0x7F;
7797 mantissa = 0;
7798 }
7799 else if (exp < 0)
7800 {
7801 /* No denormalized numbers. */
7802 exp = 0;
7803 mantissa = 0;
7804 }
7805 }
7806 mantissa >>= 29;
7807 return (sign << 31) | (exp << 23) | mantissa;
7808}
5fc177c8 7809#endif /* BFD_HOST_64_BIT */
ba592044 7810
8335d6aa
JW
7811enum lit_type
7812{
7813 CONST_THUMB,
7814 CONST_ARM,
7815 CONST_VEC
7816};
7817
ba592044
AM
7818static void do_vfp_nsyn_opcode (const char *);
7819
c19d1205
ZW
7820/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7821 Determine whether it can be performed with a move instruction; if
7822 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7823 return TRUE; if it can't, convert inst.instruction to a literal-pool
7824 load and return FALSE. If this is not a valid thing to do in the
7825 current context, set inst.error and return TRUE.
a737bd4d 7826
c19d1205
ZW
7827 inst.operands[i] describes the destination register. */
7828
c921be7d 7829static bfd_boolean
8335d6aa 7830move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7831{
53365c0d 7832 unsigned long tbit;
8335d6aa
JW
7833 bfd_boolean thumb_p = (t == CONST_THUMB);
7834 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7835
7836 if (thumb_p)
7837 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7838 else
7839 tbit = LOAD_BIT;
7840
7841 if ((inst.instruction & tbit) == 0)
09d92015 7842 {
c19d1205 7843 inst.error = _("invalid pseudo operation");
c921be7d 7844 return TRUE;
09d92015 7845 }
ba592044 7846
8335d6aa
JW
7847 if (inst.reloc.exp.X_op != O_constant
7848 && inst.reloc.exp.X_op != O_symbol
7849 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7850 {
7851 inst.error = _("constant expression expected");
c921be7d 7852 return TRUE;
09d92015 7853 }
ba592044
AM
7854
7855 if (inst.reloc.exp.X_op == O_constant
7856 || inst.reloc.exp.X_op == O_big)
8335d6aa 7857 {
5fc177c8
NC
7858#if defined BFD_HOST_64_BIT
7859 bfd_int64_t v;
7860#else
ba592044 7861 offsetT v;
5fc177c8 7862#endif
ba592044 7863 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7864 {
ba592044
AM
7865 LITTLENUM_TYPE w[X_PRECISION];
7866 LITTLENUM_TYPE * l;
7867
7868 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7869 {
ba592044
AM
7870 gen_to_words (w, X_PRECISION, E_PRECISION);
7871 l = w;
7872 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7873 }
ba592044
AM
7874 else
7875 l = generic_bignum;
3739860c 7876
5fc177c8
NC
7877#if defined BFD_HOST_64_BIT
7878 v =
7879 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7880 << LITTLENUM_NUMBER_OF_BITS)
7881 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7882 << LITTLENUM_NUMBER_OF_BITS)
7883 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7884 << LITTLENUM_NUMBER_OF_BITS)
7885 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7886#else
ba592044
AM
7887 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7888 | (l[0] & LITTLENUM_MASK);
5fc177c8 7889#endif
8335d6aa 7890 }
ba592044
AM
7891 else
7892 v = inst.reloc.exp.X_add_number;
7893
7894 if (!inst.operands[i].issingle)
8335d6aa 7895 {
12569877 7896 if (thumb_p)
8335d6aa 7897 {
2c32be70
CM
7898 /* This can be encoded only for a low register. */
7899 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7900 {
7901 /* This can be done with a mov(1) instruction. */
7902 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7903 inst.instruction |= v;
7904 return TRUE;
7905 }
12569877 7906
ff8646ee
TP
7907 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7908 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7909 {
fc289b0a
TP
7910 /* Check if on thumb2 it can be done with a mov.w, mvn or
7911 movw instruction. */
12569877
AM
7912 unsigned int newimm;
7913 bfd_boolean isNegated;
7914
7915 newimm = encode_thumb32_immediate (v);
7916 if (newimm != (unsigned int) FAIL)
7917 isNegated = FALSE;
7918 else
7919 {
582cfe03 7920 newimm = encode_thumb32_immediate (~v);
12569877
AM
7921 if (newimm != (unsigned int) FAIL)
7922 isNegated = TRUE;
7923 }
7924
fc289b0a
TP
7925 /* The number can be loaded with a mov.w or mvn
7926 instruction. */
ff8646ee
TP
7927 if (newimm != (unsigned int) FAIL
7928 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7929 {
fc289b0a 7930 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7931 | (inst.operands[i].reg << 8));
fc289b0a 7932 /* Change to MOVN. */
582cfe03 7933 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7934 inst.instruction |= (newimm & 0x800) << 15;
7935 inst.instruction |= (newimm & 0x700) << 4;
7936 inst.instruction |= (newimm & 0x0ff);
7937 return TRUE;
7938 }
fc289b0a 7939 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
7940 else if ((v & ~0xFFFF) == 0
7941 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 7942 {
582cfe03 7943 int imm = v & 0xFFFF;
12569877 7944
582cfe03 7945 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7946 inst.instruction |= (inst.operands[i].reg << 8);
7947 inst.instruction |= (imm & 0xf000) << 4;
7948 inst.instruction |= (imm & 0x0800) << 15;
7949 inst.instruction |= (imm & 0x0700) << 4;
7950 inst.instruction |= (imm & 0x00ff);
7951 return TRUE;
7952 }
7953 }
8335d6aa 7954 }
12569877 7955 else if (arm_p)
ba592044
AM
7956 {
7957 int value = encode_arm_immediate (v);
12569877 7958
ba592044
AM
7959 if (value != FAIL)
7960 {
7961 /* This can be done with a mov instruction. */
7962 inst.instruction &= LITERAL_MASK;
7963 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7964 inst.instruction |= value & 0xfff;
7965 return TRUE;
7966 }
8335d6aa 7967
ba592044
AM
7968 value = encode_arm_immediate (~ v);
7969 if (value != FAIL)
7970 {
7971 /* This can be done with a mvn instruction. */
7972 inst.instruction &= LITERAL_MASK;
7973 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7974 inst.instruction |= value & 0xfff;
7975 return TRUE;
7976 }
7977 }
7978 else if (t == CONST_VEC)
8335d6aa 7979 {
ba592044
AM
7980 int op = 0;
7981 unsigned immbits = 0;
7982 unsigned immlo = inst.operands[1].imm;
7983 unsigned immhi = inst.operands[1].regisimm
7984 ? inst.operands[1].reg
7985 : inst.reloc.exp.X_unsigned
7986 ? 0
7987 : ((bfd_int64_t)((int) immlo)) >> 32;
7988 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7989 &op, 64, NT_invtype);
7990
7991 if (cmode == FAIL)
7992 {
7993 neon_invert_size (&immlo, &immhi, 64);
7994 op = !op;
7995 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7996 &op, 64, NT_invtype);
7997 }
7998
7999 if (cmode != FAIL)
8000 {
8001 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8002 | (1 << 23)
8003 | (cmode << 8)
8004 | (op << 5)
8005 | (1 << 4);
8006
8007 /* Fill other bits in vmov encoding for both thumb and arm. */
8008 if (thumb_mode)
eff0bc54 8009 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8010 else
eff0bc54 8011 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8012 neon_write_immbits (immbits);
8013 return TRUE;
8014 }
8335d6aa
JW
8015 }
8016 }
8335d6aa 8017
ba592044
AM
8018 if (t == CONST_VEC)
8019 {
8020 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8021 if (inst.operands[i].issingle
8022 && is_quarter_float (inst.operands[1].imm)
8023 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8024 {
ba592044
AM
8025 inst.operands[1].imm =
8026 neon_qfloat_bits (v);
8027 do_vfp_nsyn_opcode ("fconsts");
8028 return TRUE;
8335d6aa 8029 }
5fc177c8
NC
8030
8031 /* If our host does not support a 64-bit type then we cannot perform
8032 the following optimization. This mean that there will be a
8033 discrepancy between the output produced by an assembler built for
8034 a 32-bit-only host and the output produced from a 64-bit host, but
8035 this cannot be helped. */
8036#if defined BFD_HOST_64_BIT
ba592044
AM
8037 else if (!inst.operands[1].issingle
8038 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8039 {
ba592044
AM
8040 if (is_double_a_single (v)
8041 && is_quarter_float (double_to_single (v)))
8042 {
8043 inst.operands[1].imm =
8044 neon_qfloat_bits (double_to_single (v));
8045 do_vfp_nsyn_opcode ("fconstd");
8046 return TRUE;
8047 }
8335d6aa 8048 }
5fc177c8 8049#endif
8335d6aa
JW
8050 }
8051 }
8052
8053 if (add_to_lit_pool ((!inst.operands[i].isvec
8054 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8055 return TRUE;
8056
8057 inst.operands[1].reg = REG_PC;
8058 inst.operands[1].isreg = 1;
8059 inst.operands[1].preind = 1;
8060 inst.reloc.pc_rel = 1;
8061 inst.reloc.type = (thumb_p
8062 ? BFD_RELOC_ARM_THUMB_OFFSET
8063 : (mode_3
8064 ? BFD_RELOC_ARM_HWLITERAL
8065 : BFD_RELOC_ARM_LITERAL));
8066 return FALSE;
8067}
8068
8069/* inst.operands[i] was set up by parse_address. Encode it into an
8070 ARM-format instruction. Reject all forms which cannot be encoded
8071 into a coprocessor load/store instruction. If wb_ok is false,
8072 reject use of writeback; if unind_ok is false, reject use of
8073 unindexed addressing. If reloc_override is not 0, use it instead
8074 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8075 (in which case it is preserved). */
8076
8077static int
8078encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8079{
8080 if (!inst.operands[i].isreg)
8081 {
99b2a2dd
NC
8082 /* PR 18256 */
8083 if (! inst.operands[0].isvec)
8084 {
8085 inst.error = _("invalid co-processor operand");
8086 return FAIL;
8087 }
8335d6aa
JW
8088 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8089 return SUCCESS;
8090 }
8091
8092 inst.instruction |= inst.operands[i].reg << 16;
8093
8094 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8095
8096 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8097 {
8098 gas_assert (!inst.operands[i].writeback);
8099 if (!unind_ok)
8100 {
8101 inst.error = _("instruction does not support unindexed addressing");
8102 return FAIL;
8103 }
8104 inst.instruction |= inst.operands[i].imm;
8105 inst.instruction |= INDEX_UP;
8106 return SUCCESS;
8107 }
8108
8109 if (inst.operands[i].preind)
8110 inst.instruction |= PRE_INDEX;
8111
8112 if (inst.operands[i].writeback)
09d92015 8113 {
8335d6aa 8114 if (inst.operands[i].reg == REG_PC)
c19d1205 8115 {
8335d6aa
JW
8116 inst.error = _("pc may not be used with write-back");
8117 return FAIL;
c19d1205 8118 }
8335d6aa 8119 if (!wb_ok)
c19d1205 8120 {
8335d6aa
JW
8121 inst.error = _("instruction does not support writeback");
8122 return FAIL;
c19d1205 8123 }
8335d6aa 8124 inst.instruction |= WRITE_BACK;
09d92015
MM
8125 }
8126
8335d6aa
JW
8127 if (reloc_override)
8128 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8129 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8130 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8131 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8132 {
8335d6aa
JW
8133 if (thumb_mode)
8134 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8135 else
8136 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8137 }
8335d6aa
JW
8138
8139 /* Prefer + for zero encoded value. */
8140 if (!inst.operands[i].negative)
8141 inst.instruction |= INDEX_UP;
8142
8143 return SUCCESS;
09d92015
MM
8144}
8145
5f4273c7 8146/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8147 First some generics; their names are taken from the conventional
8148 bit positions for register arguments in ARM format instructions. */
09d92015 8149
a737bd4d 8150static void
c19d1205 8151do_noargs (void)
09d92015 8152{
c19d1205 8153}
a737bd4d 8154
c19d1205
ZW
8155static void
8156do_rd (void)
8157{
8158 inst.instruction |= inst.operands[0].reg << 12;
8159}
a737bd4d 8160
c19d1205
ZW
8161static void
8162do_rd_rm (void)
8163{
8164 inst.instruction |= inst.operands[0].reg << 12;
8165 inst.instruction |= inst.operands[1].reg;
8166}
09d92015 8167
9eb6c0f1
MGD
8168static void
8169do_rm_rn (void)
8170{
8171 inst.instruction |= inst.operands[0].reg;
8172 inst.instruction |= inst.operands[1].reg << 16;
8173}
8174
c19d1205
ZW
8175static void
8176do_rd_rn (void)
8177{
8178 inst.instruction |= inst.operands[0].reg << 12;
8179 inst.instruction |= inst.operands[1].reg << 16;
8180}
a737bd4d 8181
c19d1205
ZW
8182static void
8183do_rn_rd (void)
8184{
8185 inst.instruction |= inst.operands[0].reg << 16;
8186 inst.instruction |= inst.operands[1].reg << 12;
8187}
09d92015 8188
4ed7ed8d
TP
8189static void
8190do_tt (void)
8191{
8192 inst.instruction |= inst.operands[0].reg << 8;
8193 inst.instruction |= inst.operands[1].reg << 16;
8194}
8195
59d09be6
MGD
8196static bfd_boolean
8197check_obsolete (const arm_feature_set *feature, const char *msg)
8198{
8199 if (ARM_CPU_IS_ANY (cpu_variant))
8200 {
5c3696f8 8201 as_tsktsk ("%s", msg);
59d09be6
MGD
8202 return TRUE;
8203 }
8204 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8205 {
8206 as_bad ("%s", msg);
8207 return TRUE;
8208 }
8209
8210 return FALSE;
8211}
8212
c19d1205
ZW
8213static void
8214do_rd_rm_rn (void)
8215{
9a64e435 8216 unsigned Rn = inst.operands[2].reg;
708587a4 8217 /* Enforce restrictions on SWP instruction. */
9a64e435 8218 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8219 {
8220 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8221 _("Rn must not overlap other operands"));
8222
59d09be6
MGD
8223 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8224 */
8225 if (!check_obsolete (&arm_ext_v8,
8226 _("swp{b} use is obsoleted for ARMv8 and later"))
8227 && warn_on_deprecated
8228 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8229 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8230 }
59d09be6 8231
c19d1205
ZW
8232 inst.instruction |= inst.operands[0].reg << 12;
8233 inst.instruction |= inst.operands[1].reg;
9a64e435 8234 inst.instruction |= Rn << 16;
c19d1205 8235}
09d92015 8236
c19d1205
ZW
8237static void
8238do_rd_rn_rm (void)
8239{
8240 inst.instruction |= inst.operands[0].reg << 12;
8241 inst.instruction |= inst.operands[1].reg << 16;
8242 inst.instruction |= inst.operands[2].reg;
8243}
a737bd4d 8244
c19d1205
ZW
8245static void
8246do_rm_rd_rn (void)
8247{
5be8be5d
DG
8248 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8249 constraint (((inst.reloc.exp.X_op != O_constant
8250 && inst.reloc.exp.X_op != O_illegal)
8251 || inst.reloc.exp.X_add_number != 0),
8252 BAD_ADDR_MODE);
c19d1205
ZW
8253 inst.instruction |= inst.operands[0].reg;
8254 inst.instruction |= inst.operands[1].reg << 12;
8255 inst.instruction |= inst.operands[2].reg << 16;
8256}
09d92015 8257
c19d1205
ZW
8258static void
8259do_imm0 (void)
8260{
8261 inst.instruction |= inst.operands[0].imm;
8262}
09d92015 8263
c19d1205
ZW
8264static void
8265do_rd_cpaddr (void)
8266{
8267 inst.instruction |= inst.operands[0].reg << 12;
8268 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8269}
a737bd4d 8270
c19d1205
ZW
8271/* ARM instructions, in alphabetical order by function name (except
8272 that wrapper functions appear immediately after the function they
8273 wrap). */
09d92015 8274
c19d1205
ZW
8275/* This is a pseudo-op of the form "adr rd, label" to be converted
8276 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8277
8278static void
c19d1205 8279do_adr (void)
09d92015 8280{
c19d1205 8281 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8282
c19d1205
ZW
8283 /* Frag hacking will turn this into a sub instruction if the offset turns
8284 out to be negative. */
8285 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8286 inst.reloc.pc_rel = 1;
2fc8bdac 8287 inst.reloc.exp.X_add_number -= 8;
c19d1205 8288}
b99bd4ef 8289
c19d1205
ZW
8290/* This is a pseudo-op of the form "adrl rd, label" to be converted
8291 into a relative address of the form:
8292 add rd, pc, #low(label-.-8)"
8293 add rd, rd, #high(label-.-8)" */
b99bd4ef 8294
c19d1205
ZW
8295static void
8296do_adrl (void)
8297{
8298 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8299
c19d1205
ZW
8300 /* Frag hacking will turn this into a sub instruction if the offset turns
8301 out to be negative. */
8302 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8303 inst.reloc.pc_rel = 1;
8304 inst.size = INSN_SIZE * 2;
2fc8bdac 8305 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8306}
8307
b99bd4ef 8308static void
c19d1205 8309do_arit (void)
b99bd4ef 8310{
c19d1205
ZW
8311 if (!inst.operands[1].present)
8312 inst.operands[1].reg = inst.operands[0].reg;
8313 inst.instruction |= inst.operands[0].reg << 12;
8314 inst.instruction |= inst.operands[1].reg << 16;
8315 encode_arm_shifter_operand (2);
8316}
b99bd4ef 8317
62b3e311
PB
8318static void
8319do_barrier (void)
8320{
8321 if (inst.operands[0].present)
ccb84d65 8322 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8323 else
8324 inst.instruction |= 0xf;
8325}
8326
c19d1205
ZW
8327static void
8328do_bfc (void)
8329{
8330 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8331 constraint (msb > 32, _("bit-field extends past end of register"));
8332 /* The instruction encoding stores the LSB and MSB,
8333 not the LSB and width. */
8334 inst.instruction |= inst.operands[0].reg << 12;
8335 inst.instruction |= inst.operands[1].imm << 7;
8336 inst.instruction |= (msb - 1) << 16;
8337}
b99bd4ef 8338
c19d1205
ZW
8339static void
8340do_bfi (void)
8341{
8342 unsigned int msb;
b99bd4ef 8343
c19d1205
ZW
8344 /* #0 in second position is alternative syntax for bfc, which is
8345 the same instruction but with REG_PC in the Rm field. */
8346 if (!inst.operands[1].isreg)
8347 inst.operands[1].reg = REG_PC;
b99bd4ef 8348
c19d1205
ZW
8349 msb = inst.operands[2].imm + inst.operands[3].imm;
8350 constraint (msb > 32, _("bit-field extends past end of register"));
8351 /* The instruction encoding stores the LSB and MSB,
8352 not the LSB and width. */
8353 inst.instruction |= inst.operands[0].reg << 12;
8354 inst.instruction |= inst.operands[1].reg;
8355 inst.instruction |= inst.operands[2].imm << 7;
8356 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8357}
8358
b99bd4ef 8359static void
c19d1205 8360do_bfx (void)
b99bd4ef 8361{
c19d1205
ZW
8362 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8363 _("bit-field extends past end of register"));
8364 inst.instruction |= inst.operands[0].reg << 12;
8365 inst.instruction |= inst.operands[1].reg;
8366 inst.instruction |= inst.operands[2].imm << 7;
8367 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8368}
09d92015 8369
c19d1205
ZW
8370/* ARM V5 breakpoint instruction (argument parse)
8371 BKPT <16 bit unsigned immediate>
8372 Instruction is not conditional.
8373 The bit pattern given in insns[] has the COND_ALWAYS condition,
8374 and it is an error if the caller tried to override that. */
b99bd4ef 8375
c19d1205
ZW
8376static void
8377do_bkpt (void)
8378{
8379 /* Top 12 of 16 bits to bits 19:8. */
8380 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8381
c19d1205
ZW
8382 /* Bottom 4 of 16 bits to bits 3:0. */
8383 inst.instruction |= inst.operands[0].imm & 0xf;
8384}
09d92015 8385
c19d1205
ZW
8386static void
8387encode_branch (int default_reloc)
8388{
8389 if (inst.operands[0].hasreloc)
8390 {
0855e32b
NS
8391 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8392 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8393 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8394 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8395 ? BFD_RELOC_ARM_PLT32
8396 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8397 }
b99bd4ef 8398 else
9ae92b05 8399 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8400 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8401}
8402
b99bd4ef 8403static void
c19d1205 8404do_branch (void)
b99bd4ef 8405{
39b41c9c
PB
8406#ifdef OBJ_ELF
8407 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8408 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8409 else
8410#endif
8411 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8412}
8413
8414static void
8415do_bl (void)
8416{
8417#ifdef OBJ_ELF
8418 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8419 {
8420 if (inst.cond == COND_ALWAYS)
8421 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8422 else
8423 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8424 }
8425 else
8426#endif
8427 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8428}
b99bd4ef 8429
c19d1205
ZW
8430/* ARM V5 branch-link-exchange instruction (argument parse)
8431 BLX <target_addr> ie BLX(1)
8432 BLX{<condition>} <Rm> ie BLX(2)
8433 Unfortunately, there are two different opcodes for this mnemonic.
8434 So, the insns[].value is not used, and the code here zaps values
8435 into inst.instruction.
8436 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8437
c19d1205
ZW
8438static void
8439do_blx (void)
8440{
8441 if (inst.operands[0].isreg)
b99bd4ef 8442 {
c19d1205
ZW
8443 /* Arg is a register; the opcode provided by insns[] is correct.
8444 It is not illegal to do "blx pc", just useless. */
8445 if (inst.operands[0].reg == REG_PC)
8446 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8447
c19d1205
ZW
8448 inst.instruction |= inst.operands[0].reg;
8449 }
8450 else
b99bd4ef 8451 {
c19d1205 8452 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8453 conditionally, and the opcode must be adjusted.
8454 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8455 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8456 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8457 inst.instruction = 0xfa000000;
267bf995 8458 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8459 }
c19d1205
ZW
8460}
8461
8462static void
8463do_bx (void)
8464{
845b51d6
PB
8465 bfd_boolean want_reloc;
8466
c19d1205
ZW
8467 if (inst.operands[0].reg == REG_PC)
8468 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8469
c19d1205 8470 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8471 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8472 it is for ARMv4t or earlier. */
8473 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8474 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8475 want_reloc = TRUE;
8476
5ad34203 8477#ifdef OBJ_ELF
845b51d6 8478 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8479#endif
584206db 8480 want_reloc = FALSE;
845b51d6
PB
8481
8482 if (want_reloc)
8483 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8484}
8485
c19d1205
ZW
8486
8487/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8488
8489static void
c19d1205 8490do_bxj (void)
a737bd4d 8491{
c19d1205
ZW
8492 if (inst.operands[0].reg == REG_PC)
8493 as_tsktsk (_("use of r15 in bxj is not really useful"));
8494
8495 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8496}
8497
c19d1205
ZW
8498/* Co-processor data operation:
8499 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8500 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8501static void
8502do_cdp (void)
8503{
8504 inst.instruction |= inst.operands[0].reg << 8;
8505 inst.instruction |= inst.operands[1].imm << 20;
8506 inst.instruction |= inst.operands[2].reg << 12;
8507 inst.instruction |= inst.operands[3].reg << 16;
8508 inst.instruction |= inst.operands[4].reg;
8509 inst.instruction |= inst.operands[5].imm << 5;
8510}
a737bd4d
NC
8511
8512static void
c19d1205 8513do_cmp (void)
a737bd4d 8514{
c19d1205
ZW
8515 inst.instruction |= inst.operands[0].reg << 16;
8516 encode_arm_shifter_operand (1);
a737bd4d
NC
8517}
8518
c19d1205
ZW
8519/* Transfer between coprocessor and ARM registers.
8520 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8521 MRC2
8522 MCR{cond}
8523 MCR2
8524
8525 No special properties. */
09d92015 8526
dcbd0d71
MGD
8527struct deprecated_coproc_regs_s
8528{
8529 unsigned cp;
8530 int opc1;
8531 unsigned crn;
8532 unsigned crm;
8533 int opc2;
8534 arm_feature_set deprecated;
8535 arm_feature_set obsoleted;
8536 const char *dep_msg;
8537 const char *obs_msg;
8538};
8539
8540#define DEPR_ACCESS_V8 \
8541 N_("This coprocessor register access is deprecated in ARMv8")
8542
8543/* Table of all deprecated coprocessor registers. */
8544static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8545{
8546 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8547 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8548 DEPR_ACCESS_V8, NULL},
8549 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8550 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8551 DEPR_ACCESS_V8, NULL},
8552 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8553 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8554 DEPR_ACCESS_V8, NULL},
8555 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8556 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8557 DEPR_ACCESS_V8, NULL},
8558 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8559 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8560 DEPR_ACCESS_V8, NULL},
8561};
8562
8563#undef DEPR_ACCESS_V8
8564
8565static const size_t deprecated_coproc_reg_count =
8566 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8567
09d92015 8568static void
c19d1205 8569do_co_reg (void)
09d92015 8570{
fdfde340 8571 unsigned Rd;
dcbd0d71 8572 size_t i;
fdfde340
JM
8573
8574 Rd = inst.operands[2].reg;
8575 if (thumb_mode)
8576 {
8577 if (inst.instruction == 0xee000010
8578 || inst.instruction == 0xfe000010)
8579 /* MCR, MCR2 */
8580 reject_bad_reg (Rd);
8581 else
8582 /* MRC, MRC2 */
8583 constraint (Rd == REG_SP, BAD_SP);
8584 }
8585 else
8586 {
8587 /* MCR */
8588 if (inst.instruction == 0xe000010)
8589 constraint (Rd == REG_PC, BAD_PC);
8590 }
8591
dcbd0d71
MGD
8592 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8593 {
8594 const struct deprecated_coproc_regs_s *r =
8595 deprecated_coproc_regs + i;
8596
8597 if (inst.operands[0].reg == r->cp
8598 && inst.operands[1].imm == r->opc1
8599 && inst.operands[3].reg == r->crn
8600 && inst.operands[4].reg == r->crm
8601 && inst.operands[5].imm == r->opc2)
8602 {
b10bf8c5 8603 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8604 && warn_on_deprecated
dcbd0d71 8605 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8606 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8607 }
8608 }
fdfde340 8609
c19d1205
ZW
8610 inst.instruction |= inst.operands[0].reg << 8;
8611 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8612 inst.instruction |= Rd << 12;
c19d1205
ZW
8613 inst.instruction |= inst.operands[3].reg << 16;
8614 inst.instruction |= inst.operands[4].reg;
8615 inst.instruction |= inst.operands[5].imm << 5;
8616}
09d92015 8617
c19d1205
ZW
8618/* Transfer between coprocessor register and pair of ARM registers.
8619 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8620 MCRR2
8621 MRRC{cond}
8622 MRRC2
b99bd4ef 8623
c19d1205 8624 Two XScale instructions are special cases of these:
09d92015 8625
c19d1205
ZW
8626 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8627 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8628
5f4273c7 8629 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8630
c19d1205
ZW
8631static void
8632do_co_reg2c (void)
8633{
fdfde340
JM
8634 unsigned Rd, Rn;
8635
8636 Rd = inst.operands[2].reg;
8637 Rn = inst.operands[3].reg;
8638
8639 if (thumb_mode)
8640 {
8641 reject_bad_reg (Rd);
8642 reject_bad_reg (Rn);
8643 }
8644 else
8645 {
8646 constraint (Rd == REG_PC, BAD_PC);
8647 constraint (Rn == REG_PC, BAD_PC);
8648 }
8649
c19d1205
ZW
8650 inst.instruction |= inst.operands[0].reg << 8;
8651 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8652 inst.instruction |= Rd << 12;
8653 inst.instruction |= Rn << 16;
c19d1205 8654 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8655}
8656
c19d1205
ZW
8657static void
8658do_cpsi (void)
8659{
8660 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8661 if (inst.operands[1].present)
8662 {
8663 inst.instruction |= CPSI_MMOD;
8664 inst.instruction |= inst.operands[1].imm;
8665 }
c19d1205 8666}
b99bd4ef 8667
62b3e311
PB
8668static void
8669do_dbg (void)
8670{
8671 inst.instruction |= inst.operands[0].imm;
8672}
8673
eea54501
MGD
8674static void
8675do_div (void)
8676{
8677 unsigned Rd, Rn, Rm;
8678
8679 Rd = inst.operands[0].reg;
8680 Rn = (inst.operands[1].present
8681 ? inst.operands[1].reg : Rd);
8682 Rm = inst.operands[2].reg;
8683
8684 constraint ((Rd == REG_PC), BAD_PC);
8685 constraint ((Rn == REG_PC), BAD_PC);
8686 constraint ((Rm == REG_PC), BAD_PC);
8687
8688 inst.instruction |= Rd << 16;
8689 inst.instruction |= Rn << 0;
8690 inst.instruction |= Rm << 8;
8691}
8692
b99bd4ef 8693static void
c19d1205 8694do_it (void)
b99bd4ef 8695{
c19d1205 8696 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8697 process it to do the validation as if in
8698 thumb mode, just in case the code gets
8699 assembled for thumb using the unified syntax. */
8700
c19d1205 8701 inst.size = 0;
e07e6e58
NC
8702 if (unified_syntax)
8703 {
8704 set_it_insn_type (IT_INSN);
8705 now_it.mask = (inst.instruction & 0xf) | 0x10;
8706 now_it.cc = inst.operands[0].imm;
8707 }
09d92015 8708}
b99bd4ef 8709
6530b175
NC
8710/* If there is only one register in the register list,
8711 then return its register number. Otherwise return -1. */
8712static int
8713only_one_reg_in_list (int range)
8714{
8715 int i = ffs (range) - 1;
8716 return (i > 15 || range != (1 << i)) ? -1 : i;
8717}
8718
09d92015 8719static void
6530b175 8720encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8721{
c19d1205
ZW
8722 int base_reg = inst.operands[0].reg;
8723 int range = inst.operands[1].imm;
6530b175 8724 int one_reg;
ea6ef066 8725
c19d1205
ZW
8726 inst.instruction |= base_reg << 16;
8727 inst.instruction |= range;
ea6ef066 8728
c19d1205
ZW
8729 if (inst.operands[1].writeback)
8730 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8731
c19d1205 8732 if (inst.operands[0].writeback)
ea6ef066 8733 {
c19d1205
ZW
8734 inst.instruction |= WRITE_BACK;
8735 /* Check for unpredictable uses of writeback. */
8736 if (inst.instruction & LOAD_BIT)
09d92015 8737 {
c19d1205
ZW
8738 /* Not allowed in LDM type 2. */
8739 if ((inst.instruction & LDM_TYPE_2_OR_3)
8740 && ((range & (1 << REG_PC)) == 0))
8741 as_warn (_("writeback of base register is UNPREDICTABLE"));
8742 /* Only allowed if base reg not in list for other types. */
8743 else if (range & (1 << base_reg))
8744 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8745 }
8746 else /* STM. */
8747 {
8748 /* Not allowed for type 2. */
8749 if (inst.instruction & LDM_TYPE_2_OR_3)
8750 as_warn (_("writeback of base register is UNPREDICTABLE"));
8751 /* Only allowed if base reg not in list, or first in list. */
8752 else if ((range & (1 << base_reg))
8753 && (range & ((1 << base_reg) - 1)))
8754 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8755 }
ea6ef066 8756 }
6530b175
NC
8757
8758 /* If PUSH/POP has only one register, then use the A2 encoding. */
8759 one_reg = only_one_reg_in_list (range);
8760 if (from_push_pop_mnem && one_reg >= 0)
8761 {
8762 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8763
8764 inst.instruction &= A_COND_MASK;
8765 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8766 inst.instruction |= one_reg << 12;
8767 }
8768}
8769
8770static void
8771do_ldmstm (void)
8772{
8773 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8774}
8775
c19d1205
ZW
8776/* ARMv5TE load-consecutive (argument parse)
8777 Mode is like LDRH.
8778
8779 LDRccD R, mode
8780 STRccD R, mode. */
8781
a737bd4d 8782static void
c19d1205 8783do_ldrd (void)
a737bd4d 8784{
c19d1205 8785 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8786 _("first transfer register must be even"));
c19d1205
ZW
8787 constraint (inst.operands[1].present
8788 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8789 _("can only transfer two consecutive registers"));
c19d1205
ZW
8790 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8791 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8792
c19d1205
ZW
8793 if (!inst.operands[1].present)
8794 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8795
c56791bb
RE
8796 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8797 register and the first register written; we have to diagnose
8798 overlap between the base and the second register written here. */
ea6ef066 8799
c56791bb
RE
8800 if (inst.operands[2].reg == inst.operands[1].reg
8801 && (inst.operands[2].writeback || inst.operands[2].postind))
8802 as_warn (_("base register written back, and overlaps "
8803 "second transfer register"));
b05fe5cf 8804
c56791bb
RE
8805 if (!(inst.instruction & V4_STR_BIT))
8806 {
c19d1205 8807 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8808 destination (even if not write-back). */
8809 if (inst.operands[2].immisreg
8810 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8811 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8812 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8813 }
c19d1205
ZW
8814 inst.instruction |= inst.operands[0].reg << 12;
8815 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8816}
8817
8818static void
c19d1205 8819do_ldrex (void)
b05fe5cf 8820{
c19d1205
ZW
8821 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8822 || inst.operands[1].postind || inst.operands[1].writeback
8823 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8824 || inst.operands[1].negative
8825 /* This can arise if the programmer has written
8826 strex rN, rM, foo
8827 or if they have mistakenly used a register name as the last
8828 operand, eg:
8829 strex rN, rM, rX
8830 It is very difficult to distinguish between these two cases
8831 because "rX" might actually be a label. ie the register
8832 name has been occluded by a symbol of the same name. So we
8833 just generate a general 'bad addressing mode' type error
8834 message and leave it up to the programmer to discover the
8835 true cause and fix their mistake. */
8836 || (inst.operands[1].reg == REG_PC),
8837 BAD_ADDR_MODE);
b05fe5cf 8838
c19d1205
ZW
8839 constraint (inst.reloc.exp.X_op != O_constant
8840 || inst.reloc.exp.X_add_number != 0,
8841 _("offset must be zero in ARM encoding"));
b05fe5cf 8842
5be8be5d
DG
8843 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8844
c19d1205
ZW
8845 inst.instruction |= inst.operands[0].reg << 12;
8846 inst.instruction |= inst.operands[1].reg << 16;
8847 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8848}
8849
8850static void
c19d1205 8851do_ldrexd (void)
b05fe5cf 8852{
c19d1205
ZW
8853 constraint (inst.operands[0].reg % 2 != 0,
8854 _("even register required"));
8855 constraint (inst.operands[1].present
8856 && inst.operands[1].reg != inst.operands[0].reg + 1,
8857 _("can only load two consecutive registers"));
8858 /* If op 1 were present and equal to PC, this function wouldn't
8859 have been called in the first place. */
8860 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8861
c19d1205
ZW
8862 inst.instruction |= inst.operands[0].reg << 12;
8863 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8864}
8865
1be5fd2e
NC
8866/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8867 which is not a multiple of four is UNPREDICTABLE. */
8868static void
8869check_ldr_r15_aligned (void)
8870{
8871 constraint (!(inst.operands[1].immisreg)
8872 && (inst.operands[0].reg == REG_PC
8873 && inst.operands[1].reg == REG_PC
8874 && (inst.reloc.exp.X_add_number & 0x3)),
8875 _("ldr to register 15 must be 4-byte alligned"));
8876}
8877
b05fe5cf 8878static void
c19d1205 8879do_ldst (void)
b05fe5cf 8880{
c19d1205
ZW
8881 inst.instruction |= inst.operands[0].reg << 12;
8882 if (!inst.operands[1].isreg)
8335d6aa 8883 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8884 return;
c19d1205 8885 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8886 check_ldr_r15_aligned ();
b05fe5cf
ZW
8887}
8888
8889static void
c19d1205 8890do_ldstt (void)
b05fe5cf 8891{
c19d1205
ZW
8892 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8893 reject [Rn,...]. */
8894 if (inst.operands[1].preind)
b05fe5cf 8895 {
bd3ba5d1
NC
8896 constraint (inst.reloc.exp.X_op != O_constant
8897 || inst.reloc.exp.X_add_number != 0,
c19d1205 8898 _("this instruction requires a post-indexed address"));
b05fe5cf 8899
c19d1205
ZW
8900 inst.operands[1].preind = 0;
8901 inst.operands[1].postind = 1;
8902 inst.operands[1].writeback = 1;
b05fe5cf 8903 }
c19d1205
ZW
8904 inst.instruction |= inst.operands[0].reg << 12;
8905 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8906}
b05fe5cf 8907
c19d1205 8908/* Halfword and signed-byte load/store operations. */
b05fe5cf 8909
c19d1205
ZW
8910static void
8911do_ldstv4 (void)
8912{
ff4a8d2b 8913 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8914 inst.instruction |= inst.operands[0].reg << 12;
8915 if (!inst.operands[1].isreg)
8335d6aa 8916 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8917 return;
c19d1205 8918 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8919}
8920
8921static void
c19d1205 8922do_ldsttv4 (void)
b05fe5cf 8923{
c19d1205
ZW
8924 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8925 reject [Rn,...]. */
8926 if (inst.operands[1].preind)
b05fe5cf 8927 {
bd3ba5d1
NC
8928 constraint (inst.reloc.exp.X_op != O_constant
8929 || inst.reloc.exp.X_add_number != 0,
c19d1205 8930 _("this instruction requires a post-indexed address"));
b05fe5cf 8931
c19d1205
ZW
8932 inst.operands[1].preind = 0;
8933 inst.operands[1].postind = 1;
8934 inst.operands[1].writeback = 1;
b05fe5cf 8935 }
c19d1205
ZW
8936 inst.instruction |= inst.operands[0].reg << 12;
8937 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8938}
b05fe5cf 8939
c19d1205
ZW
8940/* Co-processor register load/store.
8941 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8942static void
8943do_lstc (void)
8944{
8945 inst.instruction |= inst.operands[0].reg << 8;
8946 inst.instruction |= inst.operands[1].reg << 12;
8947 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8948}
8949
b05fe5cf 8950static void
c19d1205 8951do_mlas (void)
b05fe5cf 8952{
8fb9d7b9 8953 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8954 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8955 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8956 && !(inst.instruction & 0x00400000))
8fb9d7b9 8957 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8958
c19d1205
ZW
8959 inst.instruction |= inst.operands[0].reg << 16;
8960 inst.instruction |= inst.operands[1].reg;
8961 inst.instruction |= inst.operands[2].reg << 8;
8962 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8963}
b05fe5cf 8964
c19d1205
ZW
8965static void
8966do_mov (void)
8967{
8968 inst.instruction |= inst.operands[0].reg << 12;
8969 encode_arm_shifter_operand (1);
8970}
b05fe5cf 8971
c19d1205
ZW
8972/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8973static void
8974do_mov16 (void)
8975{
b6895b4f
PB
8976 bfd_vma imm;
8977 bfd_boolean top;
8978
8979 top = (inst.instruction & 0x00400000) != 0;
8980 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8981 _(":lower16: not allowed this instruction"));
8982 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8983 _(":upper16: not allowed instruction"));
c19d1205 8984 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8985 if (inst.reloc.type == BFD_RELOC_UNUSED)
8986 {
8987 imm = inst.reloc.exp.X_add_number;
8988 /* The value is in two pieces: 0:11, 16:19. */
8989 inst.instruction |= (imm & 0x00000fff);
8990 inst.instruction |= (imm & 0x0000f000) << 4;
8991 }
b05fe5cf 8992}
b99bd4ef 8993
037e8744
JB
8994static int
8995do_vfp_nsyn_mrs (void)
8996{
8997 if (inst.operands[0].isvec)
8998 {
8999 if (inst.operands[1].reg != 1)
477330fc 9000 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9001 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9002 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9003 do_vfp_nsyn_opcode ("fmstat");
9004 }
9005 else if (inst.operands[1].isvec)
9006 do_vfp_nsyn_opcode ("fmrx");
9007 else
9008 return FAIL;
5f4273c7 9009
037e8744
JB
9010 return SUCCESS;
9011}
9012
9013static int
9014do_vfp_nsyn_msr (void)
9015{
9016 if (inst.operands[0].isvec)
9017 do_vfp_nsyn_opcode ("fmxr");
9018 else
9019 return FAIL;
9020
9021 return SUCCESS;
9022}
9023
f7c21dc7
NC
9024static void
9025do_vmrs (void)
9026{
9027 unsigned Rt = inst.operands[0].reg;
fa94de6b 9028
16d02dc9 9029 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9030 {
9031 inst.error = BAD_SP;
9032 return;
9033 }
9034
9035 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9036 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9037 {
9038 inst.error = BAD_PC;
9039 return;
9040 }
9041
16d02dc9
JB
9042 /* If we get through parsing the register name, we just insert the number
9043 generated into the instruction without further validation. */
9044 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9045 inst.instruction |= (Rt << 12);
9046}
9047
9048static void
9049do_vmsr (void)
9050{
9051 unsigned Rt = inst.operands[1].reg;
fa94de6b 9052
f7c21dc7
NC
9053 if (thumb_mode)
9054 reject_bad_reg (Rt);
9055 else if (Rt == REG_PC)
9056 {
9057 inst.error = BAD_PC;
9058 return;
9059 }
9060
16d02dc9
JB
9061 /* If we get through parsing the register name, we just insert the number
9062 generated into the instruction without further validation. */
9063 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9064 inst.instruction |= (Rt << 12);
9065}
9066
b99bd4ef 9067static void
c19d1205 9068do_mrs (void)
b99bd4ef 9069{
90ec0d68
MGD
9070 unsigned br;
9071
037e8744
JB
9072 if (do_vfp_nsyn_mrs () == SUCCESS)
9073 return;
9074
ff4a8d2b 9075 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9076 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9077
9078 if (inst.operands[1].isreg)
9079 {
9080 br = inst.operands[1].reg;
9081 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9082 as_bad (_("bad register for mrs"));
9083 }
9084 else
9085 {
9086 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9087 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9088 != (PSR_c|PSR_f),
d2cd1205 9089 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9090 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9091 }
9092
9093 inst.instruction |= br;
c19d1205 9094}
b99bd4ef 9095
c19d1205
ZW
9096/* Two possible forms:
9097 "{C|S}PSR_<field>, Rm",
9098 "{C|S}PSR_f, #expression". */
b99bd4ef 9099
c19d1205
ZW
9100static void
9101do_msr (void)
9102{
037e8744
JB
9103 if (do_vfp_nsyn_msr () == SUCCESS)
9104 return;
9105
c19d1205
ZW
9106 inst.instruction |= inst.operands[0].imm;
9107 if (inst.operands[1].isreg)
9108 inst.instruction |= inst.operands[1].reg;
9109 else
b99bd4ef 9110 {
c19d1205
ZW
9111 inst.instruction |= INST_IMMEDIATE;
9112 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9113 inst.reloc.pc_rel = 0;
b99bd4ef 9114 }
b99bd4ef
NC
9115}
9116
c19d1205
ZW
9117static void
9118do_mul (void)
a737bd4d 9119{
ff4a8d2b
NC
9120 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9121
c19d1205
ZW
9122 if (!inst.operands[2].present)
9123 inst.operands[2].reg = inst.operands[0].reg;
9124 inst.instruction |= inst.operands[0].reg << 16;
9125 inst.instruction |= inst.operands[1].reg;
9126 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9127
8fb9d7b9
MS
9128 if (inst.operands[0].reg == inst.operands[1].reg
9129 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9130 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9131}
9132
c19d1205
ZW
9133/* Long Multiply Parser
9134 UMULL RdLo, RdHi, Rm, Rs
9135 SMULL RdLo, RdHi, Rm, Rs
9136 UMLAL RdLo, RdHi, Rm, Rs
9137 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9138
9139static void
c19d1205 9140do_mull (void)
b99bd4ef 9141{
c19d1205
ZW
9142 inst.instruction |= inst.operands[0].reg << 12;
9143 inst.instruction |= inst.operands[1].reg << 16;
9144 inst.instruction |= inst.operands[2].reg;
9145 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9146
682b27ad
PB
9147 /* rdhi and rdlo must be different. */
9148 if (inst.operands[0].reg == inst.operands[1].reg)
9149 as_tsktsk (_("rdhi and rdlo must be different"));
9150
9151 /* rdhi, rdlo and rm must all be different before armv6. */
9152 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9153 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9154 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9155 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9156}
b99bd4ef 9157
c19d1205
ZW
9158static void
9159do_nop (void)
9160{
e7495e45
NS
9161 if (inst.operands[0].present
9162 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9163 {
9164 /* Architectural NOP hints are CPSR sets with no bits selected. */
9165 inst.instruction &= 0xf0000000;
e7495e45
NS
9166 inst.instruction |= 0x0320f000;
9167 if (inst.operands[0].present)
9168 inst.instruction |= inst.operands[0].imm;
c19d1205 9169 }
b99bd4ef
NC
9170}
9171
c19d1205
ZW
9172/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9173 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9174 Condition defaults to COND_ALWAYS.
9175 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9176
9177static void
c19d1205 9178do_pkhbt (void)
b99bd4ef 9179{
c19d1205
ZW
9180 inst.instruction |= inst.operands[0].reg << 12;
9181 inst.instruction |= inst.operands[1].reg << 16;
9182 inst.instruction |= inst.operands[2].reg;
9183 if (inst.operands[3].present)
9184 encode_arm_shift (3);
9185}
b99bd4ef 9186
c19d1205 9187/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9188
c19d1205
ZW
9189static void
9190do_pkhtb (void)
9191{
9192 if (!inst.operands[3].present)
b99bd4ef 9193 {
c19d1205
ZW
9194 /* If the shift specifier is omitted, turn the instruction
9195 into pkhbt rd, rm, rn. */
9196 inst.instruction &= 0xfff00010;
9197 inst.instruction |= inst.operands[0].reg << 12;
9198 inst.instruction |= inst.operands[1].reg;
9199 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9200 }
9201 else
9202 {
c19d1205
ZW
9203 inst.instruction |= inst.operands[0].reg << 12;
9204 inst.instruction |= inst.operands[1].reg << 16;
9205 inst.instruction |= inst.operands[2].reg;
9206 encode_arm_shift (3);
b99bd4ef
NC
9207 }
9208}
9209
c19d1205 9210/* ARMv5TE: Preload-Cache
60e5ef9f 9211 MP Extensions: Preload for write
c19d1205 9212
60e5ef9f 9213 PLD(W) <addr_mode>
c19d1205
ZW
9214
9215 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9216
9217static void
c19d1205 9218do_pld (void)
b99bd4ef 9219{
c19d1205
ZW
9220 constraint (!inst.operands[0].isreg,
9221 _("'[' expected after PLD mnemonic"));
9222 constraint (inst.operands[0].postind,
9223 _("post-indexed expression used in preload instruction"));
9224 constraint (inst.operands[0].writeback,
9225 _("writeback used in preload instruction"));
9226 constraint (!inst.operands[0].preind,
9227 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9228 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9229}
b99bd4ef 9230
62b3e311
PB
9231/* ARMv7: PLI <addr_mode> */
9232static void
9233do_pli (void)
9234{
9235 constraint (!inst.operands[0].isreg,
9236 _("'[' expected after PLI mnemonic"));
9237 constraint (inst.operands[0].postind,
9238 _("post-indexed expression used in preload instruction"));
9239 constraint (inst.operands[0].writeback,
9240 _("writeback used in preload instruction"));
9241 constraint (!inst.operands[0].preind,
9242 _("unindexed addressing used in preload instruction"));
9243 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9244 inst.instruction &= ~PRE_INDEX;
9245}
9246
c19d1205
ZW
9247static void
9248do_push_pop (void)
9249{
5e0d7f77
MP
9250 constraint (inst.operands[0].writeback,
9251 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9252 inst.operands[1] = inst.operands[0];
9253 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9254 inst.operands[0].isreg = 1;
9255 inst.operands[0].writeback = 1;
9256 inst.operands[0].reg = REG_SP;
6530b175 9257 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9258}
b99bd4ef 9259
c19d1205
ZW
9260/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9261 word at the specified address and the following word
9262 respectively.
9263 Unconditionally executed.
9264 Error if Rn is R15. */
b99bd4ef 9265
c19d1205
ZW
9266static void
9267do_rfe (void)
9268{
9269 inst.instruction |= inst.operands[0].reg << 16;
9270 if (inst.operands[0].writeback)
9271 inst.instruction |= WRITE_BACK;
9272}
b99bd4ef 9273
c19d1205 9274/* ARM V6 ssat (argument parse). */
b99bd4ef 9275
c19d1205
ZW
9276static void
9277do_ssat (void)
9278{
9279 inst.instruction |= inst.operands[0].reg << 12;
9280 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9281 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9282
c19d1205
ZW
9283 if (inst.operands[3].present)
9284 encode_arm_shift (3);
b99bd4ef
NC
9285}
9286
c19d1205 9287/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9288
9289static void
c19d1205 9290do_usat (void)
b99bd4ef 9291{
c19d1205
ZW
9292 inst.instruction |= inst.operands[0].reg << 12;
9293 inst.instruction |= inst.operands[1].imm << 16;
9294 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9295
c19d1205
ZW
9296 if (inst.operands[3].present)
9297 encode_arm_shift (3);
b99bd4ef
NC
9298}
9299
c19d1205 9300/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9301
9302static void
c19d1205 9303do_ssat16 (void)
09d92015 9304{
c19d1205
ZW
9305 inst.instruction |= inst.operands[0].reg << 12;
9306 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9307 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9308}
9309
c19d1205
ZW
9310static void
9311do_usat16 (void)
a737bd4d 9312{
c19d1205
ZW
9313 inst.instruction |= inst.operands[0].reg << 12;
9314 inst.instruction |= inst.operands[1].imm << 16;
9315 inst.instruction |= inst.operands[2].reg;
9316}
a737bd4d 9317
c19d1205
ZW
9318/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9319 preserving the other bits.
a737bd4d 9320
c19d1205
ZW
9321 setend <endian_specifier>, where <endian_specifier> is either
9322 BE or LE. */
a737bd4d 9323
c19d1205
ZW
9324static void
9325do_setend (void)
9326{
12e37cbc
MGD
9327 if (warn_on_deprecated
9328 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9329 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9330
c19d1205
ZW
9331 if (inst.operands[0].imm)
9332 inst.instruction |= 0x200;
a737bd4d
NC
9333}
9334
9335static void
c19d1205 9336do_shift (void)
a737bd4d 9337{
c19d1205
ZW
9338 unsigned int Rm = (inst.operands[1].present
9339 ? inst.operands[1].reg
9340 : inst.operands[0].reg);
a737bd4d 9341
c19d1205
ZW
9342 inst.instruction |= inst.operands[0].reg << 12;
9343 inst.instruction |= Rm;
9344 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9345 {
c19d1205
ZW
9346 inst.instruction |= inst.operands[2].reg << 8;
9347 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9348 /* PR 12854: Error on extraneous shifts. */
9349 constraint (inst.operands[2].shifted,
9350 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9351 }
9352 else
c19d1205 9353 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9354}
9355
09d92015 9356static void
3eb17e6b 9357do_smc (void)
09d92015 9358{
3eb17e6b 9359 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9360 inst.reloc.pc_rel = 0;
09d92015
MM
9361}
9362
90ec0d68
MGD
9363static void
9364do_hvc (void)
9365{
9366 inst.reloc.type = BFD_RELOC_ARM_HVC;
9367 inst.reloc.pc_rel = 0;
9368}
9369
09d92015 9370static void
c19d1205 9371do_swi (void)
09d92015 9372{
c19d1205
ZW
9373 inst.reloc.type = BFD_RELOC_ARM_SWI;
9374 inst.reloc.pc_rel = 0;
09d92015
MM
9375}
9376
ddfded2f
MW
9377static void
9378do_setpan (void)
9379{
9380 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9381 _("selected processor does not support SETPAN instruction"));
9382
9383 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9384}
9385
9386static void
9387do_t_setpan (void)
9388{
9389 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9390 _("selected processor does not support SETPAN instruction"));
9391
9392 inst.instruction |= (inst.operands[0].imm << 3);
9393}
9394
c19d1205
ZW
9395/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9396 SMLAxy{cond} Rd,Rm,Rs,Rn
9397 SMLAWy{cond} Rd,Rm,Rs,Rn
9398 Error if any register is R15. */
e16bb312 9399
c19d1205
ZW
9400static void
9401do_smla (void)
e16bb312 9402{
c19d1205
ZW
9403 inst.instruction |= inst.operands[0].reg << 16;
9404 inst.instruction |= inst.operands[1].reg;
9405 inst.instruction |= inst.operands[2].reg << 8;
9406 inst.instruction |= inst.operands[3].reg << 12;
9407}
a737bd4d 9408
c19d1205
ZW
9409/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9410 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9411 Error if any register is R15.
9412 Warning if Rdlo == Rdhi. */
a737bd4d 9413
c19d1205
ZW
9414static void
9415do_smlal (void)
9416{
9417 inst.instruction |= inst.operands[0].reg << 12;
9418 inst.instruction |= inst.operands[1].reg << 16;
9419 inst.instruction |= inst.operands[2].reg;
9420 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9421
c19d1205
ZW
9422 if (inst.operands[0].reg == inst.operands[1].reg)
9423 as_tsktsk (_("rdhi and rdlo must be different"));
9424}
a737bd4d 9425
c19d1205
ZW
9426/* ARM V5E (El Segundo) signed-multiply (argument parse)
9427 SMULxy{cond} Rd,Rm,Rs
9428 Error if any register is R15. */
a737bd4d 9429
c19d1205
ZW
9430static void
9431do_smul (void)
9432{
9433 inst.instruction |= inst.operands[0].reg << 16;
9434 inst.instruction |= inst.operands[1].reg;
9435 inst.instruction |= inst.operands[2].reg << 8;
9436}
a737bd4d 9437
b6702015
PB
9438/* ARM V6 srs (argument parse). The variable fields in the encoding are
9439 the same for both ARM and Thumb-2. */
a737bd4d 9440
c19d1205
ZW
9441static void
9442do_srs (void)
9443{
b6702015
PB
9444 int reg;
9445
9446 if (inst.operands[0].present)
9447 {
9448 reg = inst.operands[0].reg;
fdfde340 9449 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9450 }
9451 else
fdfde340 9452 reg = REG_SP;
b6702015
PB
9453
9454 inst.instruction |= reg << 16;
9455 inst.instruction |= inst.operands[1].imm;
9456 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9457 inst.instruction |= WRITE_BACK;
9458}
a737bd4d 9459
c19d1205 9460/* ARM V6 strex (argument parse). */
a737bd4d 9461
c19d1205
ZW
9462static void
9463do_strex (void)
9464{
9465 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9466 || inst.operands[2].postind || inst.operands[2].writeback
9467 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9468 || inst.operands[2].negative
9469 /* See comment in do_ldrex(). */
9470 || (inst.operands[2].reg == REG_PC),
9471 BAD_ADDR_MODE);
a737bd4d 9472
c19d1205
ZW
9473 constraint (inst.operands[0].reg == inst.operands[1].reg
9474 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9475
c19d1205
ZW
9476 constraint (inst.reloc.exp.X_op != O_constant
9477 || inst.reloc.exp.X_add_number != 0,
9478 _("offset must be zero in ARM encoding"));
a737bd4d 9479
c19d1205
ZW
9480 inst.instruction |= inst.operands[0].reg << 12;
9481 inst.instruction |= inst.operands[1].reg;
9482 inst.instruction |= inst.operands[2].reg << 16;
9483 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9484}
9485
877807f8
NC
9486static void
9487do_t_strexbh (void)
9488{
9489 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9490 || inst.operands[2].postind || inst.operands[2].writeback
9491 || inst.operands[2].immisreg || inst.operands[2].shifted
9492 || inst.operands[2].negative,
9493 BAD_ADDR_MODE);
9494
9495 constraint (inst.operands[0].reg == inst.operands[1].reg
9496 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9497
9498 do_rm_rd_rn ();
9499}
9500
e16bb312 9501static void
c19d1205 9502do_strexd (void)
e16bb312 9503{
c19d1205
ZW
9504 constraint (inst.operands[1].reg % 2 != 0,
9505 _("even register required"));
9506 constraint (inst.operands[2].present
9507 && inst.operands[2].reg != inst.operands[1].reg + 1,
9508 _("can only store two consecutive registers"));
9509 /* If op 2 were present and equal to PC, this function wouldn't
9510 have been called in the first place. */
9511 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9512
c19d1205
ZW
9513 constraint (inst.operands[0].reg == inst.operands[1].reg
9514 || inst.operands[0].reg == inst.operands[1].reg + 1
9515 || inst.operands[0].reg == inst.operands[3].reg,
9516 BAD_OVERLAP);
e16bb312 9517
c19d1205
ZW
9518 inst.instruction |= inst.operands[0].reg << 12;
9519 inst.instruction |= inst.operands[1].reg;
9520 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9521}
9522
9eb6c0f1
MGD
9523/* ARM V8 STRL. */
9524static void
4b8c8c02 9525do_stlex (void)
9eb6c0f1
MGD
9526{
9527 constraint (inst.operands[0].reg == inst.operands[1].reg
9528 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9529
9530 do_rd_rm_rn ();
9531}
9532
9533static void
4b8c8c02 9534do_t_stlex (void)
9eb6c0f1
MGD
9535{
9536 constraint (inst.operands[0].reg == inst.operands[1].reg
9537 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9538
9539 do_rm_rd_rn ();
9540}
9541
c19d1205
ZW
9542/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9543 extends it to 32-bits, and adds the result to a value in another
9544 register. You can specify a rotation by 0, 8, 16, or 24 bits
9545 before extracting the 16-bit value.
9546 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9547 Condition defaults to COND_ALWAYS.
9548 Error if any register uses R15. */
9549
e16bb312 9550static void
c19d1205 9551do_sxtah (void)
e16bb312 9552{
c19d1205
ZW
9553 inst.instruction |= inst.operands[0].reg << 12;
9554 inst.instruction |= inst.operands[1].reg << 16;
9555 inst.instruction |= inst.operands[2].reg;
9556 inst.instruction |= inst.operands[3].imm << 10;
9557}
e16bb312 9558
c19d1205 9559/* ARM V6 SXTH.
e16bb312 9560
c19d1205
ZW
9561 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9562 Condition defaults to COND_ALWAYS.
9563 Error if any register uses R15. */
e16bb312
NC
9564
9565static void
c19d1205 9566do_sxth (void)
e16bb312 9567{
c19d1205
ZW
9568 inst.instruction |= inst.operands[0].reg << 12;
9569 inst.instruction |= inst.operands[1].reg;
9570 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9571}
c19d1205
ZW
9572\f
9573/* VFP instructions. In a logical order: SP variant first, monad
9574 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9575
9576static void
c19d1205 9577do_vfp_sp_monadic (void)
e16bb312 9578{
5287ad62
JB
9579 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9580 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9581}
9582
9583static void
c19d1205 9584do_vfp_sp_dyadic (void)
e16bb312 9585{
5287ad62
JB
9586 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9587 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9588 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9589}
9590
9591static void
c19d1205 9592do_vfp_sp_compare_z (void)
e16bb312 9593{
5287ad62 9594 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9595}
9596
9597static void
c19d1205 9598do_vfp_dp_sp_cvt (void)
e16bb312 9599{
5287ad62
JB
9600 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9601 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9602}
9603
9604static void
c19d1205 9605do_vfp_sp_dp_cvt (void)
e16bb312 9606{
5287ad62
JB
9607 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9608 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9609}
9610
9611static void
c19d1205 9612do_vfp_reg_from_sp (void)
e16bb312 9613{
c19d1205 9614 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9615 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9616}
9617
9618static void
c19d1205 9619do_vfp_reg2_from_sp2 (void)
e16bb312 9620{
c19d1205
ZW
9621 constraint (inst.operands[2].imm != 2,
9622 _("only two consecutive VFP SP registers allowed here"));
9623 inst.instruction |= inst.operands[0].reg << 12;
9624 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9625 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9626}
9627
9628static void
c19d1205 9629do_vfp_sp_from_reg (void)
e16bb312 9630{
5287ad62 9631 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9632 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9633}
9634
9635static void
c19d1205 9636do_vfp_sp2_from_reg2 (void)
e16bb312 9637{
c19d1205
ZW
9638 constraint (inst.operands[0].imm != 2,
9639 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9640 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9641 inst.instruction |= inst.operands[1].reg << 12;
9642 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9643}
9644
9645static void
c19d1205 9646do_vfp_sp_ldst (void)
e16bb312 9647{
5287ad62 9648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9649 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9650}
9651
9652static void
c19d1205 9653do_vfp_dp_ldst (void)
e16bb312 9654{
5287ad62 9655 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9656 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9657}
9658
c19d1205 9659
e16bb312 9660static void
c19d1205 9661vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9662{
c19d1205
ZW
9663 if (inst.operands[0].writeback)
9664 inst.instruction |= WRITE_BACK;
9665 else
9666 constraint (ldstm_type != VFP_LDSTMIA,
9667 _("this addressing mode requires base-register writeback"));
9668 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9669 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9670 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9671}
9672
9673static void
c19d1205 9674vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9675{
c19d1205 9676 int count;
e16bb312 9677
c19d1205
ZW
9678 if (inst.operands[0].writeback)
9679 inst.instruction |= WRITE_BACK;
9680 else
9681 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9682 _("this addressing mode requires base-register writeback"));
e16bb312 9683
c19d1205 9684 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9685 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9686
c19d1205
ZW
9687 count = inst.operands[1].imm << 1;
9688 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9689 count += 1;
e16bb312 9690
c19d1205 9691 inst.instruction |= count;
e16bb312
NC
9692}
9693
9694static void
c19d1205 9695do_vfp_sp_ldstmia (void)
e16bb312 9696{
c19d1205 9697 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9698}
9699
9700static void
c19d1205 9701do_vfp_sp_ldstmdb (void)
e16bb312 9702{
c19d1205 9703 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9704}
9705
9706static void
c19d1205 9707do_vfp_dp_ldstmia (void)
e16bb312 9708{
c19d1205 9709 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9710}
9711
9712static void
c19d1205 9713do_vfp_dp_ldstmdb (void)
e16bb312 9714{
c19d1205 9715 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9716}
9717
9718static void
c19d1205 9719do_vfp_xp_ldstmia (void)
e16bb312 9720{
c19d1205
ZW
9721 vfp_dp_ldstm (VFP_LDSTMIAX);
9722}
e16bb312 9723
c19d1205
ZW
9724static void
9725do_vfp_xp_ldstmdb (void)
9726{
9727 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9728}
5287ad62
JB
9729
9730static void
9731do_vfp_dp_rd_rm (void)
9732{
9733 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9734 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9735}
9736
9737static void
9738do_vfp_dp_rn_rd (void)
9739{
9740 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9741 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9742}
9743
9744static void
9745do_vfp_dp_rd_rn (void)
9746{
9747 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9748 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9749}
9750
9751static void
9752do_vfp_dp_rd_rn_rm (void)
9753{
9754 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9755 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9756 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9757}
9758
9759static void
9760do_vfp_dp_rd (void)
9761{
9762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9763}
9764
9765static void
9766do_vfp_dp_rm_rd_rn (void)
9767{
9768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9769 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9770 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9771}
9772
9773/* VFPv3 instructions. */
9774static void
9775do_vfp_sp_const (void)
9776{
9777 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9778 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9779 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9780}
9781
9782static void
9783do_vfp_dp_const (void)
9784{
9785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9786 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9787 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9788}
9789
9790static void
9791vfp_conv (int srcsize)
9792{
5f1af56b
MGD
9793 int immbits = srcsize - inst.operands[1].imm;
9794
fa94de6b
RM
9795 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9796 {
5f1af56b 9797 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9798 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9799 inst.error = _("immediate value out of range, expected range [0, 16]");
9800 return;
9801 }
fa94de6b 9802 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9803 {
9804 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9805 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9806 inst.error = _("immediate value out of range, expected range [1, 32]");
9807 return;
9808 }
9809
5287ad62
JB
9810 inst.instruction |= (immbits & 1) << 5;
9811 inst.instruction |= (immbits >> 1);
9812}
9813
9814static void
9815do_vfp_sp_conv_16 (void)
9816{
9817 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9818 vfp_conv (16);
9819}
9820
9821static void
9822do_vfp_dp_conv_16 (void)
9823{
9824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9825 vfp_conv (16);
9826}
9827
9828static void
9829do_vfp_sp_conv_32 (void)
9830{
9831 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9832 vfp_conv (32);
9833}
9834
9835static void
9836do_vfp_dp_conv_32 (void)
9837{
9838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9839 vfp_conv (32);
9840}
c19d1205
ZW
9841\f
9842/* FPA instructions. Also in a logical order. */
e16bb312 9843
c19d1205
ZW
9844static void
9845do_fpa_cmp (void)
9846{
9847 inst.instruction |= inst.operands[0].reg << 16;
9848 inst.instruction |= inst.operands[1].reg;
9849}
b99bd4ef
NC
9850
9851static void
c19d1205 9852do_fpa_ldmstm (void)
b99bd4ef 9853{
c19d1205
ZW
9854 inst.instruction |= inst.operands[0].reg << 12;
9855 switch (inst.operands[1].imm)
9856 {
9857 case 1: inst.instruction |= CP_T_X; break;
9858 case 2: inst.instruction |= CP_T_Y; break;
9859 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9860 case 4: break;
9861 default: abort ();
9862 }
b99bd4ef 9863
c19d1205
ZW
9864 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9865 {
9866 /* The instruction specified "ea" or "fd", so we can only accept
9867 [Rn]{!}. The instruction does not really support stacking or
9868 unstacking, so we have to emulate these by setting appropriate
9869 bits and offsets. */
9870 constraint (inst.reloc.exp.X_op != O_constant
9871 || inst.reloc.exp.X_add_number != 0,
9872 _("this instruction does not support indexing"));
b99bd4ef 9873
c19d1205
ZW
9874 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9875 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9876
c19d1205
ZW
9877 if (!(inst.instruction & INDEX_UP))
9878 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9879
c19d1205
ZW
9880 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9881 {
9882 inst.operands[2].preind = 0;
9883 inst.operands[2].postind = 1;
9884 }
9885 }
b99bd4ef 9886
c19d1205 9887 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9888}
c19d1205
ZW
9889\f
9890/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9891
c19d1205
ZW
9892static void
9893do_iwmmxt_tandorc (void)
9894{
9895 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9896}
b99bd4ef 9897
c19d1205
ZW
9898static void
9899do_iwmmxt_textrc (void)
9900{
9901 inst.instruction |= inst.operands[0].reg << 12;
9902 inst.instruction |= inst.operands[1].imm;
9903}
b99bd4ef
NC
9904
9905static void
c19d1205 9906do_iwmmxt_textrm (void)
b99bd4ef 9907{
c19d1205
ZW
9908 inst.instruction |= inst.operands[0].reg << 12;
9909 inst.instruction |= inst.operands[1].reg << 16;
9910 inst.instruction |= inst.operands[2].imm;
9911}
b99bd4ef 9912
c19d1205
ZW
9913static void
9914do_iwmmxt_tinsr (void)
9915{
9916 inst.instruction |= inst.operands[0].reg << 16;
9917 inst.instruction |= inst.operands[1].reg << 12;
9918 inst.instruction |= inst.operands[2].imm;
9919}
b99bd4ef 9920
c19d1205
ZW
9921static void
9922do_iwmmxt_tmia (void)
9923{
9924 inst.instruction |= inst.operands[0].reg << 5;
9925 inst.instruction |= inst.operands[1].reg;
9926 inst.instruction |= inst.operands[2].reg << 12;
9927}
b99bd4ef 9928
c19d1205
ZW
9929static void
9930do_iwmmxt_waligni (void)
9931{
9932 inst.instruction |= inst.operands[0].reg << 12;
9933 inst.instruction |= inst.operands[1].reg << 16;
9934 inst.instruction |= inst.operands[2].reg;
9935 inst.instruction |= inst.operands[3].imm << 20;
9936}
b99bd4ef 9937
2d447fca
JM
9938static void
9939do_iwmmxt_wmerge (void)
9940{
9941 inst.instruction |= inst.operands[0].reg << 12;
9942 inst.instruction |= inst.operands[1].reg << 16;
9943 inst.instruction |= inst.operands[2].reg;
9944 inst.instruction |= inst.operands[3].imm << 21;
9945}
9946
c19d1205
ZW
9947static void
9948do_iwmmxt_wmov (void)
9949{
9950 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9951 inst.instruction |= inst.operands[0].reg << 12;
9952 inst.instruction |= inst.operands[1].reg << 16;
9953 inst.instruction |= inst.operands[1].reg;
9954}
b99bd4ef 9955
c19d1205
ZW
9956static void
9957do_iwmmxt_wldstbh (void)
9958{
8f06b2d8 9959 int reloc;
c19d1205 9960 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9961 if (thumb_mode)
9962 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9963 else
9964 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9965 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9966}
9967
c19d1205
ZW
9968static void
9969do_iwmmxt_wldstw (void)
9970{
9971 /* RIWR_RIWC clears .isreg for a control register. */
9972 if (!inst.operands[0].isreg)
9973 {
9974 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9975 inst.instruction |= 0xf0000000;
9976 }
b99bd4ef 9977
c19d1205
ZW
9978 inst.instruction |= inst.operands[0].reg << 12;
9979 encode_arm_cp_address (1, TRUE, TRUE, 0);
9980}
b99bd4ef
NC
9981
9982static void
c19d1205 9983do_iwmmxt_wldstd (void)
b99bd4ef 9984{
c19d1205 9985 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9986 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9987 && inst.operands[1].immisreg)
9988 {
9989 inst.instruction &= ~0x1a000ff;
eff0bc54 9990 inst.instruction |= (0xfU << 28);
2d447fca
JM
9991 if (inst.operands[1].preind)
9992 inst.instruction |= PRE_INDEX;
9993 if (!inst.operands[1].negative)
9994 inst.instruction |= INDEX_UP;
9995 if (inst.operands[1].writeback)
9996 inst.instruction |= WRITE_BACK;
9997 inst.instruction |= inst.operands[1].reg << 16;
9998 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9999 inst.instruction |= inst.operands[1].imm;
10000 }
10001 else
10002 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10003}
b99bd4ef 10004
c19d1205
ZW
10005static void
10006do_iwmmxt_wshufh (void)
10007{
10008 inst.instruction |= inst.operands[0].reg << 12;
10009 inst.instruction |= inst.operands[1].reg << 16;
10010 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10011 inst.instruction |= (inst.operands[2].imm & 0x0f);
10012}
b99bd4ef 10013
c19d1205
ZW
10014static void
10015do_iwmmxt_wzero (void)
10016{
10017 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10018 inst.instruction |= inst.operands[0].reg;
10019 inst.instruction |= inst.operands[0].reg << 12;
10020 inst.instruction |= inst.operands[0].reg << 16;
10021}
2d447fca
JM
10022
10023static void
10024do_iwmmxt_wrwrwr_or_imm5 (void)
10025{
10026 if (inst.operands[2].isreg)
10027 do_rd_rn_rm ();
10028 else {
10029 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10030 _("immediate operand requires iWMMXt2"));
10031 do_rd_rn ();
10032 if (inst.operands[2].imm == 0)
10033 {
10034 switch ((inst.instruction >> 20) & 0xf)
10035 {
10036 case 4:
10037 case 5:
10038 case 6:
5f4273c7 10039 case 7:
2d447fca
JM
10040 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10041 inst.operands[2].imm = 16;
10042 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10043 break;
10044 case 8:
10045 case 9:
10046 case 10:
10047 case 11:
10048 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10049 inst.operands[2].imm = 32;
10050 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10051 break;
10052 case 12:
10053 case 13:
10054 case 14:
10055 case 15:
10056 {
10057 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10058 unsigned long wrn;
10059 wrn = (inst.instruction >> 16) & 0xf;
10060 inst.instruction &= 0xff0fff0f;
10061 inst.instruction |= wrn;
10062 /* Bail out here; the instruction is now assembled. */
10063 return;
10064 }
10065 }
10066 }
10067 /* Map 32 -> 0, etc. */
10068 inst.operands[2].imm &= 0x1f;
eff0bc54 10069 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10070 }
10071}
c19d1205
ZW
10072\f
10073/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10074 operations first, then control, shift, and load/store. */
b99bd4ef 10075
c19d1205 10076/* Insns like "foo X,Y,Z". */
b99bd4ef 10077
c19d1205
ZW
10078static void
10079do_mav_triple (void)
10080{
10081 inst.instruction |= inst.operands[0].reg << 16;
10082 inst.instruction |= inst.operands[1].reg;
10083 inst.instruction |= inst.operands[2].reg << 12;
10084}
b99bd4ef 10085
c19d1205
ZW
10086/* Insns like "foo W,X,Y,Z".
10087 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10088
c19d1205
ZW
10089static void
10090do_mav_quad (void)
10091{
10092 inst.instruction |= inst.operands[0].reg << 5;
10093 inst.instruction |= inst.operands[1].reg << 12;
10094 inst.instruction |= inst.operands[2].reg << 16;
10095 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10096}
10097
c19d1205
ZW
10098/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10099static void
10100do_mav_dspsc (void)
a737bd4d 10101{
c19d1205
ZW
10102 inst.instruction |= inst.operands[1].reg << 12;
10103}
a737bd4d 10104
c19d1205
ZW
10105/* Maverick shift immediate instructions.
10106 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10107 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10108
c19d1205
ZW
10109static void
10110do_mav_shift (void)
10111{
10112 int imm = inst.operands[2].imm;
a737bd4d 10113
c19d1205
ZW
10114 inst.instruction |= inst.operands[0].reg << 12;
10115 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10116
c19d1205
ZW
10117 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10118 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10119 Bit 4 should be 0. */
10120 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10121
c19d1205
ZW
10122 inst.instruction |= imm;
10123}
10124\f
10125/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10126
c19d1205
ZW
10127/* Xscale multiply-accumulate (argument parse)
10128 MIAcc acc0,Rm,Rs
10129 MIAPHcc acc0,Rm,Rs
10130 MIAxycc acc0,Rm,Rs. */
a737bd4d 10131
c19d1205
ZW
10132static void
10133do_xsc_mia (void)
10134{
10135 inst.instruction |= inst.operands[1].reg;
10136 inst.instruction |= inst.operands[2].reg << 12;
10137}
a737bd4d 10138
c19d1205 10139/* Xscale move-accumulator-register (argument parse)
a737bd4d 10140
c19d1205 10141 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10142
c19d1205
ZW
10143static void
10144do_xsc_mar (void)
10145{
10146 inst.instruction |= inst.operands[1].reg << 12;
10147 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10148}
10149
c19d1205 10150/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10151
c19d1205 10152 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10153
10154static void
c19d1205 10155do_xsc_mra (void)
b99bd4ef 10156{
c19d1205
ZW
10157 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10158 inst.instruction |= inst.operands[0].reg << 12;
10159 inst.instruction |= inst.operands[1].reg << 16;
10160}
10161\f
10162/* Encoding functions relevant only to Thumb. */
b99bd4ef 10163
c19d1205
ZW
10164/* inst.operands[i] is a shifted-register operand; encode
10165 it into inst.instruction in the format used by Thumb32. */
10166
10167static void
10168encode_thumb32_shifted_operand (int i)
10169{
10170 unsigned int value = inst.reloc.exp.X_add_number;
10171 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10172
9c3c69f2
PB
10173 constraint (inst.operands[i].immisreg,
10174 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10175 inst.instruction |= inst.operands[i].reg;
10176 if (shift == SHIFT_RRX)
10177 inst.instruction |= SHIFT_ROR << 4;
10178 else
b99bd4ef 10179 {
c19d1205
ZW
10180 constraint (inst.reloc.exp.X_op != O_constant,
10181 _("expression too complex"));
10182
10183 constraint (value > 32
10184 || (value == 32 && (shift == SHIFT_LSL
10185 || shift == SHIFT_ROR)),
10186 _("shift expression is too large"));
10187
10188 if (value == 0)
10189 shift = SHIFT_LSL;
10190 else if (value == 32)
10191 value = 0;
10192
10193 inst.instruction |= shift << 4;
10194 inst.instruction |= (value & 0x1c) << 10;
10195 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10196 }
c19d1205 10197}
b99bd4ef 10198
b99bd4ef 10199
c19d1205
ZW
10200/* inst.operands[i] was set up by parse_address. Encode it into a
10201 Thumb32 format load or store instruction. Reject forms that cannot
10202 be used with such instructions. If is_t is true, reject forms that
10203 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10204 that cannot be used with a D instruction. If it is a store insn,
10205 reject PC in Rn. */
b99bd4ef 10206
c19d1205
ZW
10207static void
10208encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10209{
5be8be5d 10210 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10211
10212 constraint (!inst.operands[i].isreg,
53365c0d 10213 _("Instruction does not support =N addresses"));
b99bd4ef 10214
c19d1205
ZW
10215 inst.instruction |= inst.operands[i].reg << 16;
10216 if (inst.operands[i].immisreg)
b99bd4ef 10217 {
5be8be5d 10218 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10219 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10220 constraint (inst.operands[i].negative,
10221 _("Thumb does not support negative register indexing"));
10222 constraint (inst.operands[i].postind,
10223 _("Thumb does not support register post-indexing"));
10224 constraint (inst.operands[i].writeback,
10225 _("Thumb does not support register indexing with writeback"));
10226 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10227 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10228
f40d1643 10229 inst.instruction |= inst.operands[i].imm;
c19d1205 10230 if (inst.operands[i].shifted)
b99bd4ef 10231 {
c19d1205
ZW
10232 constraint (inst.reloc.exp.X_op != O_constant,
10233 _("expression too complex"));
9c3c69f2
PB
10234 constraint (inst.reloc.exp.X_add_number < 0
10235 || inst.reloc.exp.X_add_number > 3,
c19d1205 10236 _("shift out of range"));
9c3c69f2 10237 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10238 }
10239 inst.reloc.type = BFD_RELOC_UNUSED;
10240 }
10241 else if (inst.operands[i].preind)
10242 {
5be8be5d 10243 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10244 constraint (is_t && inst.operands[i].writeback,
c19d1205 10245 _("cannot use writeback with this instruction"));
4755303e
WN
10246 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10247 BAD_PC_ADDRESSING);
c19d1205
ZW
10248
10249 if (is_d)
10250 {
10251 inst.instruction |= 0x01000000;
10252 if (inst.operands[i].writeback)
10253 inst.instruction |= 0x00200000;
b99bd4ef 10254 }
c19d1205 10255 else
b99bd4ef 10256 {
c19d1205
ZW
10257 inst.instruction |= 0x00000c00;
10258 if (inst.operands[i].writeback)
10259 inst.instruction |= 0x00000100;
b99bd4ef 10260 }
c19d1205 10261 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10262 }
c19d1205 10263 else if (inst.operands[i].postind)
b99bd4ef 10264 {
9c2799c2 10265 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10266 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10267 constraint (is_t, _("cannot use post-indexing with this instruction"));
10268
10269 if (is_d)
10270 inst.instruction |= 0x00200000;
10271 else
10272 inst.instruction |= 0x00000900;
10273 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10274 }
10275 else /* unindexed - only for coprocessor */
10276 inst.error = _("instruction does not accept unindexed addressing");
10277}
10278
10279/* Table of Thumb instructions which exist in both 16- and 32-bit
10280 encodings (the latter only in post-V6T2 cores). The index is the
10281 value used in the insns table below. When there is more than one
10282 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10283 holds variant (1).
10284 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10285#define T16_32_TAB \
21d799b5
NC
10286 X(_adc, 4140, eb400000), \
10287 X(_adcs, 4140, eb500000), \
10288 X(_add, 1c00, eb000000), \
10289 X(_adds, 1c00, eb100000), \
10290 X(_addi, 0000, f1000000), \
10291 X(_addis, 0000, f1100000), \
10292 X(_add_pc,000f, f20f0000), \
10293 X(_add_sp,000d, f10d0000), \
10294 X(_adr, 000f, f20f0000), \
10295 X(_and, 4000, ea000000), \
10296 X(_ands, 4000, ea100000), \
10297 X(_asr, 1000, fa40f000), \
10298 X(_asrs, 1000, fa50f000), \
10299 X(_b, e000, f000b000), \
10300 X(_bcond, d000, f0008000), \
10301 X(_bic, 4380, ea200000), \
10302 X(_bics, 4380, ea300000), \
10303 X(_cmn, 42c0, eb100f00), \
10304 X(_cmp, 2800, ebb00f00), \
10305 X(_cpsie, b660, f3af8400), \
10306 X(_cpsid, b670, f3af8600), \
10307 X(_cpy, 4600, ea4f0000), \
10308 X(_dec_sp,80dd, f1ad0d00), \
10309 X(_eor, 4040, ea800000), \
10310 X(_eors, 4040, ea900000), \
10311 X(_inc_sp,00dd, f10d0d00), \
10312 X(_ldmia, c800, e8900000), \
10313 X(_ldr, 6800, f8500000), \
10314 X(_ldrb, 7800, f8100000), \
10315 X(_ldrh, 8800, f8300000), \
10316 X(_ldrsb, 5600, f9100000), \
10317 X(_ldrsh, 5e00, f9300000), \
10318 X(_ldr_pc,4800, f85f0000), \
10319 X(_ldr_pc2,4800, f85f0000), \
10320 X(_ldr_sp,9800, f85d0000), \
10321 X(_lsl, 0000, fa00f000), \
10322 X(_lsls, 0000, fa10f000), \
10323 X(_lsr, 0800, fa20f000), \
10324 X(_lsrs, 0800, fa30f000), \
10325 X(_mov, 2000, ea4f0000), \
10326 X(_movs, 2000, ea5f0000), \
10327 X(_mul, 4340, fb00f000), \
10328 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10329 X(_mvn, 43c0, ea6f0000), \
10330 X(_mvns, 43c0, ea7f0000), \
10331 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10332 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10333 X(_orr, 4300, ea400000), \
10334 X(_orrs, 4300, ea500000), \
10335 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10336 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10337 X(_rev, ba00, fa90f080), \
10338 X(_rev16, ba40, fa90f090), \
10339 X(_revsh, bac0, fa90f0b0), \
10340 X(_ror, 41c0, fa60f000), \
10341 X(_rors, 41c0, fa70f000), \
10342 X(_sbc, 4180, eb600000), \
10343 X(_sbcs, 4180, eb700000), \
10344 X(_stmia, c000, e8800000), \
10345 X(_str, 6000, f8400000), \
10346 X(_strb, 7000, f8000000), \
10347 X(_strh, 8000, f8200000), \
10348 X(_str_sp,9000, f84d0000), \
10349 X(_sub, 1e00, eba00000), \
10350 X(_subs, 1e00, ebb00000), \
10351 X(_subi, 8000, f1a00000), \
10352 X(_subis, 8000, f1b00000), \
10353 X(_sxtb, b240, fa4ff080), \
10354 X(_sxth, b200, fa0ff080), \
10355 X(_tst, 4200, ea100f00), \
10356 X(_uxtb, b2c0, fa5ff080), \
10357 X(_uxth, b280, fa1ff080), \
10358 X(_nop, bf00, f3af8000), \
10359 X(_yield, bf10, f3af8001), \
10360 X(_wfe, bf20, f3af8002), \
10361 X(_wfi, bf30, f3af8003), \
53c4b28b 10362 X(_sev, bf40, f3af8004), \
74db7efb
NC
10363 X(_sevl, bf50, f3af8005), \
10364 X(_udf, de00, f7f0a000)
c19d1205
ZW
10365
10366/* To catch errors in encoding functions, the codes are all offset by
10367 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10368 as 16-bit instructions. */
21d799b5 10369#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10370enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10371#undef X
10372
10373#define X(a,b,c) 0x##b
10374static const unsigned short thumb_op16[] = { T16_32_TAB };
10375#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10376#undef X
10377
10378#define X(a,b,c) 0x##c
10379static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10380#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10381#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10382#undef X
10383#undef T16_32_TAB
10384
10385/* Thumb instruction encoders, in alphabetical order. */
10386
92e90b6e 10387/* ADDW or SUBW. */
c921be7d 10388
92e90b6e
PB
10389static void
10390do_t_add_sub_w (void)
10391{
10392 int Rd, Rn;
10393
10394 Rd = inst.operands[0].reg;
10395 Rn = inst.operands[1].reg;
10396
539d4391
NC
10397 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10398 is the SP-{plus,minus}-immediate form of the instruction. */
10399 if (Rn == REG_SP)
10400 constraint (Rd == REG_PC, BAD_PC);
10401 else
10402 reject_bad_reg (Rd);
fdfde340 10403
92e90b6e
PB
10404 inst.instruction |= (Rn << 16) | (Rd << 8);
10405 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10406}
10407
c19d1205
ZW
10408/* Parse an add or subtract instruction. We get here with inst.instruction
10409 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10410
10411static void
10412do_t_add_sub (void)
10413{
10414 int Rd, Rs, Rn;
10415
10416 Rd = inst.operands[0].reg;
10417 Rs = (inst.operands[1].present
10418 ? inst.operands[1].reg /* Rd, Rs, foo */
10419 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10420
e07e6e58
NC
10421 if (Rd == REG_PC)
10422 set_it_insn_type_last ();
10423
c19d1205
ZW
10424 if (unified_syntax)
10425 {
0110f2b8
PB
10426 bfd_boolean flags;
10427 bfd_boolean narrow;
10428 int opcode;
10429
10430 flags = (inst.instruction == T_MNEM_adds
10431 || inst.instruction == T_MNEM_subs);
10432 if (flags)
e07e6e58 10433 narrow = !in_it_block ();
0110f2b8 10434 else
e07e6e58 10435 narrow = in_it_block ();
c19d1205 10436 if (!inst.operands[2].isreg)
b99bd4ef 10437 {
16805f35
PB
10438 int add;
10439
fdfde340
JM
10440 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10441
16805f35
PB
10442 add = (inst.instruction == T_MNEM_add
10443 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10444 opcode = 0;
10445 if (inst.size_req != 4)
10446 {
0110f2b8 10447 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10448 appropriate. */
0110f2b8
PB
10449 if (Rd == REG_SP && Rs == REG_SP && !flags)
10450 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10451 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10452 opcode = T_MNEM_add_sp;
10453 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10454 opcode = T_MNEM_add_pc;
10455 else if (Rd <= 7 && Rs <= 7 && narrow)
10456 {
10457 if (flags)
10458 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10459 else
10460 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10461 }
10462 if (opcode)
10463 {
10464 inst.instruction = THUMB_OP16(opcode);
10465 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10466 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10467 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
10468 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
0110f2b8
PB
10469 if (inst.size_req != 2)
10470 inst.relax = opcode;
10471 }
10472 else
10473 constraint (inst.size_req == 2, BAD_HIREG);
10474 }
10475 if (inst.size_req == 4
10476 || (inst.size_req != 2 && !opcode))
10477 {
efd81785
PB
10478 if (Rd == REG_PC)
10479 {
fdfde340 10480 constraint (add, BAD_PC);
efd81785
PB
10481 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10482 _("only SUBS PC, LR, #const allowed"));
10483 constraint (inst.reloc.exp.X_op != O_constant,
10484 _("expression too complex"));
10485 constraint (inst.reloc.exp.X_add_number < 0
10486 || inst.reloc.exp.X_add_number > 0xff,
10487 _("immediate value out of range"));
10488 inst.instruction = T2_SUBS_PC_LR
10489 | inst.reloc.exp.X_add_number;
10490 inst.reloc.type = BFD_RELOC_UNUSED;
10491 return;
10492 }
10493 else if (Rs == REG_PC)
16805f35
PB
10494 {
10495 /* Always use addw/subw. */
10496 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10497 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10498 }
10499 else
10500 {
10501 inst.instruction = THUMB_OP32 (inst.instruction);
10502 inst.instruction = (inst.instruction & 0xe1ffffff)
10503 | 0x10000000;
10504 if (flags)
10505 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10506 else
10507 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10508 }
dc4503c6
PB
10509 inst.instruction |= Rd << 8;
10510 inst.instruction |= Rs << 16;
0110f2b8 10511 }
b99bd4ef 10512 }
c19d1205
ZW
10513 else
10514 {
5f4cb198
NC
10515 unsigned int value = inst.reloc.exp.X_add_number;
10516 unsigned int shift = inst.operands[2].shift_kind;
10517
c19d1205
ZW
10518 Rn = inst.operands[2].reg;
10519 /* See if we can do this with a 16-bit instruction. */
10520 if (!inst.operands[2].shifted && inst.size_req != 4)
10521 {
e27ec89e
PB
10522 if (Rd > 7 || Rs > 7 || Rn > 7)
10523 narrow = FALSE;
10524
10525 if (narrow)
c19d1205 10526 {
e27ec89e
PB
10527 inst.instruction = ((inst.instruction == T_MNEM_adds
10528 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10529 ? T_OPCODE_ADD_R3
10530 : T_OPCODE_SUB_R3);
10531 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10532 return;
10533 }
b99bd4ef 10534
7e806470 10535 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10536 {
7e806470
PB
10537 /* Thumb-1 cores (except v6-M) require at least one high
10538 register in a narrow non flag setting add. */
10539 if (Rd > 7 || Rn > 7
10540 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10541 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10542 {
7e806470
PB
10543 if (Rd == Rn)
10544 {
10545 Rn = Rs;
10546 Rs = Rd;
10547 }
c19d1205
ZW
10548 inst.instruction = T_OPCODE_ADD_HI;
10549 inst.instruction |= (Rd & 8) << 4;
10550 inst.instruction |= (Rd & 7);
10551 inst.instruction |= Rn << 3;
10552 return;
10553 }
c19d1205
ZW
10554 }
10555 }
c921be7d 10556
fdfde340
JM
10557 constraint (Rd == REG_PC, BAD_PC);
10558 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10559 constraint (Rs == REG_PC, BAD_PC);
10560 reject_bad_reg (Rn);
10561
c19d1205
ZW
10562 /* If we get here, it can't be done in 16 bits. */
10563 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10564 _("shift must be constant"));
10565 inst.instruction = THUMB_OP32 (inst.instruction);
10566 inst.instruction |= Rd << 8;
10567 inst.instruction |= Rs << 16;
5f4cb198
NC
10568 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10569 _("shift value over 3 not allowed in thumb mode"));
10570 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10571 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10572 encode_thumb32_shifted_operand (2);
10573 }
10574 }
10575 else
10576 {
10577 constraint (inst.instruction == T_MNEM_adds
10578 || inst.instruction == T_MNEM_subs,
10579 BAD_THUMB32);
b99bd4ef 10580
c19d1205 10581 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10582 {
c19d1205
ZW
10583 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10584 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10585 BAD_HIREG);
10586
10587 inst.instruction = (inst.instruction == T_MNEM_add
10588 ? 0x0000 : 0x8000);
10589 inst.instruction |= (Rd << 4) | Rs;
10590 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10591 return;
10592 }
10593
c19d1205
ZW
10594 Rn = inst.operands[2].reg;
10595 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10596
c19d1205
ZW
10597 /* We now have Rd, Rs, and Rn set to registers. */
10598 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10599 {
c19d1205
ZW
10600 /* Can't do this for SUB. */
10601 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10602 inst.instruction = T_OPCODE_ADD_HI;
10603 inst.instruction |= (Rd & 8) << 4;
10604 inst.instruction |= (Rd & 7);
10605 if (Rs == Rd)
10606 inst.instruction |= Rn << 3;
10607 else if (Rn == Rd)
10608 inst.instruction |= Rs << 3;
10609 else
10610 constraint (1, _("dest must overlap one source register"));
10611 }
10612 else
10613 {
10614 inst.instruction = (inst.instruction == T_MNEM_add
10615 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10616 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10617 }
b99bd4ef 10618 }
b99bd4ef
NC
10619}
10620
c19d1205
ZW
10621static void
10622do_t_adr (void)
10623{
fdfde340
JM
10624 unsigned Rd;
10625
10626 Rd = inst.operands[0].reg;
10627 reject_bad_reg (Rd);
10628
10629 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10630 {
10631 /* Defer to section relaxation. */
10632 inst.relax = inst.instruction;
10633 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10634 inst.instruction |= Rd << 4;
0110f2b8
PB
10635 }
10636 else if (unified_syntax && inst.size_req != 2)
e9f89963 10637 {
0110f2b8 10638 /* Generate a 32-bit opcode. */
e9f89963 10639 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10640 inst.instruction |= Rd << 8;
e9f89963
PB
10641 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10642 inst.reloc.pc_rel = 1;
10643 }
10644 else
10645 {
0110f2b8 10646 /* Generate a 16-bit opcode. */
e9f89963
PB
10647 inst.instruction = THUMB_OP16 (inst.instruction);
10648 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10649 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10650 inst.reloc.pc_rel = 1;
b99bd4ef 10651
fdfde340 10652 inst.instruction |= Rd << 4;
e9f89963 10653 }
c19d1205 10654}
b99bd4ef 10655
c19d1205
ZW
10656/* Arithmetic instructions for which there is just one 16-bit
10657 instruction encoding, and it allows only two low registers.
10658 For maximal compatibility with ARM syntax, we allow three register
10659 operands even when Thumb-32 instructions are not available, as long
10660 as the first two are identical. For instance, both "sbc r0,r1" and
10661 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10662static void
c19d1205 10663do_t_arit3 (void)
b99bd4ef 10664{
c19d1205 10665 int Rd, Rs, Rn;
b99bd4ef 10666
c19d1205
ZW
10667 Rd = inst.operands[0].reg;
10668 Rs = (inst.operands[1].present
10669 ? inst.operands[1].reg /* Rd, Rs, foo */
10670 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10671 Rn = inst.operands[2].reg;
b99bd4ef 10672
fdfde340
JM
10673 reject_bad_reg (Rd);
10674 reject_bad_reg (Rs);
10675 if (inst.operands[2].isreg)
10676 reject_bad_reg (Rn);
10677
c19d1205 10678 if (unified_syntax)
b99bd4ef 10679 {
c19d1205
ZW
10680 if (!inst.operands[2].isreg)
10681 {
10682 /* For an immediate, we always generate a 32-bit opcode;
10683 section relaxation will shrink it later if possible. */
10684 inst.instruction = THUMB_OP32 (inst.instruction);
10685 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10686 inst.instruction |= Rd << 8;
10687 inst.instruction |= Rs << 16;
10688 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10689 }
10690 else
10691 {
e27ec89e
PB
10692 bfd_boolean narrow;
10693
c19d1205 10694 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10695 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10696 narrow = !in_it_block ();
e27ec89e 10697 else
e07e6e58 10698 narrow = in_it_block ();
e27ec89e
PB
10699
10700 if (Rd > 7 || Rn > 7 || Rs > 7)
10701 narrow = FALSE;
10702 if (inst.operands[2].shifted)
10703 narrow = FALSE;
10704 if (inst.size_req == 4)
10705 narrow = FALSE;
10706
10707 if (narrow
c19d1205
ZW
10708 && Rd == Rs)
10709 {
10710 inst.instruction = THUMB_OP16 (inst.instruction);
10711 inst.instruction |= Rd;
10712 inst.instruction |= Rn << 3;
10713 return;
10714 }
b99bd4ef 10715
c19d1205
ZW
10716 /* If we get here, it can't be done in 16 bits. */
10717 constraint (inst.operands[2].shifted
10718 && inst.operands[2].immisreg,
10719 _("shift must be constant"));
10720 inst.instruction = THUMB_OP32 (inst.instruction);
10721 inst.instruction |= Rd << 8;
10722 inst.instruction |= Rs << 16;
10723 encode_thumb32_shifted_operand (2);
10724 }
a737bd4d 10725 }
c19d1205 10726 else
b99bd4ef 10727 {
c19d1205
ZW
10728 /* On its face this is a lie - the instruction does set the
10729 flags. However, the only supported mnemonic in this mode
10730 says it doesn't. */
10731 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10732
c19d1205
ZW
10733 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10734 _("unshifted register required"));
10735 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10736 constraint (Rd != Rs,
10737 _("dest and source1 must be the same register"));
a737bd4d 10738
c19d1205
ZW
10739 inst.instruction = THUMB_OP16 (inst.instruction);
10740 inst.instruction |= Rd;
10741 inst.instruction |= Rn << 3;
b99bd4ef 10742 }
a737bd4d 10743}
b99bd4ef 10744
c19d1205
ZW
10745/* Similarly, but for instructions where the arithmetic operation is
10746 commutative, so we can allow either of them to be different from
10747 the destination operand in a 16-bit instruction. For instance, all
10748 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10749 accepted. */
10750static void
10751do_t_arit3c (void)
a737bd4d 10752{
c19d1205 10753 int Rd, Rs, Rn;
b99bd4ef 10754
c19d1205
ZW
10755 Rd = inst.operands[0].reg;
10756 Rs = (inst.operands[1].present
10757 ? inst.operands[1].reg /* Rd, Rs, foo */
10758 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10759 Rn = inst.operands[2].reg;
c921be7d 10760
fdfde340
JM
10761 reject_bad_reg (Rd);
10762 reject_bad_reg (Rs);
10763 if (inst.operands[2].isreg)
10764 reject_bad_reg (Rn);
a737bd4d 10765
c19d1205 10766 if (unified_syntax)
a737bd4d 10767 {
c19d1205 10768 if (!inst.operands[2].isreg)
b99bd4ef 10769 {
c19d1205
ZW
10770 /* For an immediate, we always generate a 32-bit opcode;
10771 section relaxation will shrink it later if possible. */
10772 inst.instruction = THUMB_OP32 (inst.instruction);
10773 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10774 inst.instruction |= Rd << 8;
10775 inst.instruction |= Rs << 16;
10776 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10777 }
c19d1205 10778 else
a737bd4d 10779 {
e27ec89e
PB
10780 bfd_boolean narrow;
10781
c19d1205 10782 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10783 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10784 narrow = !in_it_block ();
e27ec89e 10785 else
e07e6e58 10786 narrow = in_it_block ();
e27ec89e
PB
10787
10788 if (Rd > 7 || Rn > 7 || Rs > 7)
10789 narrow = FALSE;
10790 if (inst.operands[2].shifted)
10791 narrow = FALSE;
10792 if (inst.size_req == 4)
10793 narrow = FALSE;
10794
10795 if (narrow)
a737bd4d 10796 {
c19d1205 10797 if (Rd == Rs)
a737bd4d 10798 {
c19d1205
ZW
10799 inst.instruction = THUMB_OP16 (inst.instruction);
10800 inst.instruction |= Rd;
10801 inst.instruction |= Rn << 3;
10802 return;
a737bd4d 10803 }
c19d1205 10804 if (Rd == Rn)
a737bd4d 10805 {
c19d1205
ZW
10806 inst.instruction = THUMB_OP16 (inst.instruction);
10807 inst.instruction |= Rd;
10808 inst.instruction |= Rs << 3;
10809 return;
a737bd4d
NC
10810 }
10811 }
c19d1205
ZW
10812
10813 /* If we get here, it can't be done in 16 bits. */
10814 constraint (inst.operands[2].shifted
10815 && inst.operands[2].immisreg,
10816 _("shift must be constant"));
10817 inst.instruction = THUMB_OP32 (inst.instruction);
10818 inst.instruction |= Rd << 8;
10819 inst.instruction |= Rs << 16;
10820 encode_thumb32_shifted_operand (2);
a737bd4d 10821 }
b99bd4ef 10822 }
c19d1205
ZW
10823 else
10824 {
10825 /* On its face this is a lie - the instruction does set the
10826 flags. However, the only supported mnemonic in this mode
10827 says it doesn't. */
10828 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10829
c19d1205
ZW
10830 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10831 _("unshifted register required"));
10832 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10833
10834 inst.instruction = THUMB_OP16 (inst.instruction);
10835 inst.instruction |= Rd;
10836
10837 if (Rd == Rs)
10838 inst.instruction |= Rn << 3;
10839 else if (Rd == Rn)
10840 inst.instruction |= Rs << 3;
10841 else
10842 constraint (1, _("dest must overlap one source register"));
10843 }
a737bd4d
NC
10844}
10845
c19d1205
ZW
10846static void
10847do_t_bfc (void)
a737bd4d 10848{
fdfde340 10849 unsigned Rd;
c19d1205
ZW
10850 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10851 constraint (msb > 32, _("bit-field extends past end of register"));
10852 /* The instruction encoding stores the LSB and MSB,
10853 not the LSB and width. */
fdfde340
JM
10854 Rd = inst.operands[0].reg;
10855 reject_bad_reg (Rd);
10856 inst.instruction |= Rd << 8;
c19d1205
ZW
10857 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10858 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10859 inst.instruction |= msb - 1;
b99bd4ef
NC
10860}
10861
c19d1205
ZW
10862static void
10863do_t_bfi (void)
b99bd4ef 10864{
fdfde340 10865 int Rd, Rn;
c19d1205 10866 unsigned int msb;
b99bd4ef 10867
fdfde340
JM
10868 Rd = inst.operands[0].reg;
10869 reject_bad_reg (Rd);
10870
c19d1205
ZW
10871 /* #0 in second position is alternative syntax for bfc, which is
10872 the same instruction but with REG_PC in the Rm field. */
10873 if (!inst.operands[1].isreg)
fdfde340
JM
10874 Rn = REG_PC;
10875 else
10876 {
10877 Rn = inst.operands[1].reg;
10878 reject_bad_reg (Rn);
10879 }
b99bd4ef 10880
c19d1205
ZW
10881 msb = inst.operands[2].imm + inst.operands[3].imm;
10882 constraint (msb > 32, _("bit-field extends past end of register"));
10883 /* The instruction encoding stores the LSB and MSB,
10884 not the LSB and width. */
fdfde340
JM
10885 inst.instruction |= Rd << 8;
10886 inst.instruction |= Rn << 16;
c19d1205
ZW
10887 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10888 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10889 inst.instruction |= msb - 1;
b99bd4ef
NC
10890}
10891
c19d1205
ZW
10892static void
10893do_t_bfx (void)
b99bd4ef 10894{
fdfde340
JM
10895 unsigned Rd, Rn;
10896
10897 Rd = inst.operands[0].reg;
10898 Rn = inst.operands[1].reg;
10899
10900 reject_bad_reg (Rd);
10901 reject_bad_reg (Rn);
10902
c19d1205
ZW
10903 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10904 _("bit-field extends past end of register"));
fdfde340
JM
10905 inst.instruction |= Rd << 8;
10906 inst.instruction |= Rn << 16;
c19d1205
ZW
10907 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10908 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10909 inst.instruction |= inst.operands[3].imm - 1;
10910}
b99bd4ef 10911
c19d1205
ZW
10912/* ARM V5 Thumb BLX (argument parse)
10913 BLX <target_addr> which is BLX(1)
10914 BLX <Rm> which is BLX(2)
10915 Unfortunately, there are two different opcodes for this mnemonic.
10916 So, the insns[].value is not used, and the code here zaps values
10917 into inst.instruction.
b99bd4ef 10918
c19d1205
ZW
10919 ??? How to take advantage of the additional two bits of displacement
10920 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10921
c19d1205
ZW
10922static void
10923do_t_blx (void)
10924{
e07e6e58
NC
10925 set_it_insn_type_last ();
10926
c19d1205 10927 if (inst.operands[0].isreg)
fdfde340
JM
10928 {
10929 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10930 /* We have a register, so this is BLX(2). */
10931 inst.instruction |= inst.operands[0].reg << 3;
10932 }
b99bd4ef
NC
10933 else
10934 {
c19d1205 10935 /* No register. This must be BLX(1). */
2fc8bdac 10936 inst.instruction = 0xf000e800;
0855e32b 10937 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10938 }
10939}
10940
c19d1205
ZW
10941static void
10942do_t_branch (void)
b99bd4ef 10943{
0110f2b8 10944 int opcode;
dfa9f0d5 10945 int cond;
9ae92b05 10946 int reloc;
dfa9f0d5 10947
e07e6e58
NC
10948 cond = inst.cond;
10949 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10950
10951 if (in_it_block ())
dfa9f0d5
PB
10952 {
10953 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10954 branches. */
dfa9f0d5 10955 cond = COND_ALWAYS;
dfa9f0d5
PB
10956 }
10957 else
10958 cond = inst.cond;
10959
10960 if (cond != COND_ALWAYS)
0110f2b8
PB
10961 opcode = T_MNEM_bcond;
10962 else
10963 opcode = inst.instruction;
10964
12d6b0b7
RS
10965 if (unified_syntax
10966 && (inst.size_req == 4
10960bfb
PB
10967 || (inst.size_req != 2
10968 && (inst.operands[0].hasreloc
10969 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10970 {
0110f2b8 10971 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10972 if (cond == COND_ALWAYS)
9ae92b05 10973 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10974 else
10975 {
ff8646ee
TP
10976 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
10977 _("selected architecture does not support "
10978 "wide conditional branch instruction"));
10979
9c2799c2 10980 gas_assert (cond != 0xF);
dfa9f0d5 10981 inst.instruction |= cond << 22;
9ae92b05 10982 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10983 }
10984 }
b99bd4ef
NC
10985 else
10986 {
0110f2b8 10987 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10988 if (cond == COND_ALWAYS)
9ae92b05 10989 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10990 else
b99bd4ef 10991 {
dfa9f0d5 10992 inst.instruction |= cond << 8;
9ae92b05 10993 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10994 }
0110f2b8
PB
10995 /* Allow section relaxation. */
10996 if (unified_syntax && inst.size_req != 2)
10997 inst.relax = opcode;
b99bd4ef 10998 }
9ae92b05 10999 inst.reloc.type = reloc;
c19d1205 11000 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11001}
11002
8884b720 11003/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11004 between the two is the maximum immediate allowed - which is passed in
8884b720 11005 RANGE. */
b99bd4ef 11006static void
8884b720 11007do_t_bkpt_hlt1 (int range)
b99bd4ef 11008{
dfa9f0d5
PB
11009 constraint (inst.cond != COND_ALWAYS,
11010 _("instruction is always unconditional"));
c19d1205 11011 if (inst.operands[0].present)
b99bd4ef 11012 {
8884b720 11013 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11014 _("immediate value out of range"));
11015 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11016 }
8884b720
MGD
11017
11018 set_it_insn_type (NEUTRAL_IT_INSN);
11019}
11020
11021static void
11022do_t_hlt (void)
11023{
11024 do_t_bkpt_hlt1 (63);
11025}
11026
11027static void
11028do_t_bkpt (void)
11029{
11030 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11031}
11032
11033static void
c19d1205 11034do_t_branch23 (void)
b99bd4ef 11035{
e07e6e58 11036 set_it_insn_type_last ();
0855e32b 11037 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11038
0855e32b
NS
11039 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11040 this file. We used to simply ignore the PLT reloc type here --
11041 the branch encoding is now needed to deal with TLSCALL relocs.
11042 So if we see a PLT reloc now, put it back to how it used to be to
11043 keep the preexisting behaviour. */
11044 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11045 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11046
4343666d 11047#if defined(OBJ_COFF)
c19d1205
ZW
11048 /* If the destination of the branch is a defined symbol which does not have
11049 the THUMB_FUNC attribute, then we must be calling a function which has
11050 the (interfacearm) attribute. We look for the Thumb entry point to that
11051 function and change the branch to refer to that function instead. */
11052 if ( inst.reloc.exp.X_op == O_symbol
11053 && inst.reloc.exp.X_add_symbol != NULL
11054 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11055 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11056 inst.reloc.exp.X_add_symbol =
11057 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11058#endif
90e4755a
RE
11059}
11060
11061static void
c19d1205 11062do_t_bx (void)
90e4755a 11063{
e07e6e58 11064 set_it_insn_type_last ();
c19d1205
ZW
11065 inst.instruction |= inst.operands[0].reg << 3;
11066 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11067 should cause the alignment to be checked once it is known. This is
11068 because BX PC only works if the instruction is word aligned. */
11069}
90e4755a 11070
c19d1205
ZW
11071static void
11072do_t_bxj (void)
11073{
fdfde340 11074 int Rm;
90e4755a 11075
e07e6e58 11076 set_it_insn_type_last ();
fdfde340
JM
11077 Rm = inst.operands[0].reg;
11078 reject_bad_reg (Rm);
11079 inst.instruction |= Rm << 16;
90e4755a
RE
11080}
11081
11082static void
c19d1205 11083do_t_clz (void)
90e4755a 11084{
fdfde340
JM
11085 unsigned Rd;
11086 unsigned Rm;
11087
11088 Rd = inst.operands[0].reg;
11089 Rm = inst.operands[1].reg;
11090
11091 reject_bad_reg (Rd);
11092 reject_bad_reg (Rm);
11093
11094 inst.instruction |= Rd << 8;
11095 inst.instruction |= Rm << 16;
11096 inst.instruction |= Rm;
c19d1205 11097}
90e4755a 11098
dfa9f0d5
PB
11099static void
11100do_t_cps (void)
11101{
e07e6e58 11102 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11103 inst.instruction |= inst.operands[0].imm;
11104}
11105
c19d1205
ZW
11106static void
11107do_t_cpsi (void)
11108{
e07e6e58 11109 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11110 if (unified_syntax
62b3e311
PB
11111 && (inst.operands[1].present || inst.size_req == 4)
11112 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11113 {
c19d1205
ZW
11114 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11115 inst.instruction = 0xf3af8000;
11116 inst.instruction |= imod << 9;
11117 inst.instruction |= inst.operands[0].imm << 5;
11118 if (inst.operands[1].present)
11119 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11120 }
c19d1205 11121 else
90e4755a 11122 {
62b3e311
PB
11123 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11124 && (inst.operands[0].imm & 4),
11125 _("selected processor does not support 'A' form "
11126 "of this instruction"));
11127 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11128 _("Thumb does not support the 2-argument "
11129 "form of this instruction"));
11130 inst.instruction |= inst.operands[0].imm;
90e4755a 11131 }
90e4755a
RE
11132}
11133
c19d1205
ZW
11134/* THUMB CPY instruction (argument parse). */
11135
90e4755a 11136static void
c19d1205 11137do_t_cpy (void)
90e4755a 11138{
c19d1205 11139 if (inst.size_req == 4)
90e4755a 11140 {
c19d1205
ZW
11141 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11142 inst.instruction |= inst.operands[0].reg << 8;
11143 inst.instruction |= inst.operands[1].reg;
90e4755a 11144 }
c19d1205 11145 else
90e4755a 11146 {
c19d1205
ZW
11147 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11148 inst.instruction |= (inst.operands[0].reg & 0x7);
11149 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11150 }
90e4755a
RE
11151}
11152
90e4755a 11153static void
25fe350b 11154do_t_cbz (void)
90e4755a 11155{
e07e6e58 11156 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11157 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11158 inst.instruction |= inst.operands[0].reg;
11159 inst.reloc.pc_rel = 1;
11160 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11161}
90e4755a 11162
62b3e311
PB
11163static void
11164do_t_dbg (void)
11165{
11166 inst.instruction |= inst.operands[0].imm;
11167}
11168
11169static void
11170do_t_div (void)
11171{
fdfde340
JM
11172 unsigned Rd, Rn, Rm;
11173
11174 Rd = inst.operands[0].reg;
11175 Rn = (inst.operands[1].present
11176 ? inst.operands[1].reg : Rd);
11177 Rm = inst.operands[2].reg;
11178
11179 reject_bad_reg (Rd);
11180 reject_bad_reg (Rn);
11181 reject_bad_reg (Rm);
11182
11183 inst.instruction |= Rd << 8;
11184 inst.instruction |= Rn << 16;
11185 inst.instruction |= Rm;
62b3e311
PB
11186}
11187
c19d1205
ZW
11188static void
11189do_t_hint (void)
11190{
11191 if (unified_syntax && inst.size_req == 4)
11192 inst.instruction = THUMB_OP32 (inst.instruction);
11193 else
11194 inst.instruction = THUMB_OP16 (inst.instruction);
11195}
90e4755a 11196
c19d1205
ZW
11197static void
11198do_t_it (void)
11199{
11200 unsigned int cond = inst.operands[0].imm;
e27ec89e 11201
e07e6e58
NC
11202 set_it_insn_type (IT_INSN);
11203 now_it.mask = (inst.instruction & 0xf) | 0x10;
11204 now_it.cc = cond;
5a01bb1d 11205 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11206
11207 /* If the condition is a negative condition, invert the mask. */
c19d1205 11208 if ((cond & 0x1) == 0x0)
90e4755a 11209 {
c19d1205 11210 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11211
c19d1205 11212 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11213 {
11214 /* No conversion needed. */
11215 now_it.block_length = 1;
11216 }
c19d1205 11217 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11218 {
11219 mask ^= 0x8;
11220 now_it.block_length = 2;
11221 }
e27ec89e 11222 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11223 {
11224 mask ^= 0xC;
11225 now_it.block_length = 3;
11226 }
c19d1205 11227 else
5a01bb1d
MGD
11228 {
11229 mask ^= 0xE;
11230 now_it.block_length = 4;
11231 }
90e4755a 11232
e27ec89e
PB
11233 inst.instruction &= 0xfff0;
11234 inst.instruction |= mask;
c19d1205 11235 }
90e4755a 11236
c19d1205
ZW
11237 inst.instruction |= cond << 4;
11238}
90e4755a 11239
3c707909
PB
11240/* Helper function used for both push/pop and ldm/stm. */
11241static void
11242encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11243{
11244 bfd_boolean load;
11245
11246 load = (inst.instruction & (1 << 20)) != 0;
11247
11248 if (mask & (1 << 13))
11249 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11250
11251 if ((mask & (1 << base)) != 0
11252 && writeback)
11253 inst.error = _("having the base register in the register list when "
11254 "using write back is UNPREDICTABLE");
11255
3c707909
PB
11256 if (load)
11257 {
e07e6e58 11258 if (mask & (1 << 15))
477330fc
RM
11259 {
11260 if (mask & (1 << 14))
11261 inst.error = _("LR and PC should not both be in register list");
11262 else
11263 set_it_insn_type_last ();
11264 }
3c707909
PB
11265 }
11266 else
11267 {
11268 if (mask & (1 << 15))
11269 inst.error = _("PC not allowed in register list");
3c707909
PB
11270 }
11271
11272 if ((mask & (mask - 1)) == 0)
11273 {
11274 /* Single register transfers implemented as str/ldr. */
11275 if (writeback)
11276 {
11277 if (inst.instruction & (1 << 23))
11278 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11279 else
11280 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11281 }
11282 else
11283 {
11284 if (inst.instruction & (1 << 23))
11285 inst.instruction = 0x00800000; /* ia -> [base] */
11286 else
11287 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11288 }
11289
11290 inst.instruction |= 0xf8400000;
11291 if (load)
11292 inst.instruction |= 0x00100000;
11293
5f4273c7 11294 mask = ffs (mask) - 1;
3c707909
PB
11295 mask <<= 12;
11296 }
11297 else if (writeback)
11298 inst.instruction |= WRITE_BACK;
11299
11300 inst.instruction |= mask;
11301 inst.instruction |= base << 16;
11302}
11303
c19d1205
ZW
11304static void
11305do_t_ldmstm (void)
11306{
11307 /* This really doesn't seem worth it. */
11308 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11309 _("expression too complex"));
11310 constraint (inst.operands[1].writeback,
11311 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11312
c19d1205
ZW
11313 if (unified_syntax)
11314 {
3c707909
PB
11315 bfd_boolean narrow;
11316 unsigned mask;
11317
11318 narrow = FALSE;
c19d1205
ZW
11319 /* See if we can use a 16-bit instruction. */
11320 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11321 && inst.size_req != 4
3c707909 11322 && !(inst.operands[1].imm & ~0xff))
90e4755a 11323 {
3c707909 11324 mask = 1 << inst.operands[0].reg;
90e4755a 11325
eab4f823 11326 if (inst.operands[0].reg <= 7)
90e4755a 11327 {
3c707909 11328 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11329 ? inst.operands[0].writeback
11330 : (inst.operands[0].writeback
11331 == !(inst.operands[1].imm & mask)))
477330fc 11332 {
eab4f823
MGD
11333 if (inst.instruction == T_MNEM_stmia
11334 && (inst.operands[1].imm & mask)
11335 && (inst.operands[1].imm & (mask - 1)))
11336 as_warn (_("value stored for r%d is UNKNOWN"),
11337 inst.operands[0].reg);
3c707909 11338
eab4f823
MGD
11339 inst.instruction = THUMB_OP16 (inst.instruction);
11340 inst.instruction |= inst.operands[0].reg << 8;
11341 inst.instruction |= inst.operands[1].imm;
11342 narrow = TRUE;
11343 }
11344 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11345 {
11346 /* This means 1 register in reg list one of 3 situations:
11347 1. Instruction is stmia, but without writeback.
11348 2. lmdia without writeback, but with Rn not in
477330fc 11349 reglist.
eab4f823
MGD
11350 3. ldmia with writeback, but with Rn in reglist.
11351 Case 3 is UNPREDICTABLE behaviour, so we handle
11352 case 1 and 2 which can be converted into a 16-bit
11353 str or ldr. The SP cases are handled below. */
11354 unsigned long opcode;
11355 /* First, record an error for Case 3. */
11356 if (inst.operands[1].imm & mask
11357 && inst.operands[0].writeback)
fa94de6b 11358 inst.error =
eab4f823
MGD
11359 _("having the base register in the register list when "
11360 "using write back is UNPREDICTABLE");
fa94de6b
RM
11361
11362 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11363 : T_MNEM_ldr);
11364 inst.instruction = THUMB_OP16 (opcode);
11365 inst.instruction |= inst.operands[0].reg << 3;
11366 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11367 narrow = TRUE;
11368 }
90e4755a 11369 }
eab4f823 11370 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11371 {
eab4f823
MGD
11372 if (inst.operands[0].writeback)
11373 {
fa94de6b 11374 inst.instruction =
eab4f823 11375 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11376 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11377 inst.instruction |= inst.operands[1].imm;
477330fc 11378 narrow = TRUE;
eab4f823
MGD
11379 }
11380 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11381 {
fa94de6b 11382 inst.instruction =
eab4f823 11383 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11384 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11385 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11386 narrow = TRUE;
eab4f823 11387 }
90e4755a 11388 }
3c707909
PB
11389 }
11390
11391 if (!narrow)
11392 {
c19d1205
ZW
11393 if (inst.instruction < 0xffff)
11394 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11395
5f4273c7
NC
11396 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11397 inst.operands[0].writeback);
90e4755a
RE
11398 }
11399 }
c19d1205 11400 else
90e4755a 11401 {
c19d1205
ZW
11402 constraint (inst.operands[0].reg > 7
11403 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11404 constraint (inst.instruction != T_MNEM_ldmia
11405 && inst.instruction != T_MNEM_stmia,
11406 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11407 if (inst.instruction == T_MNEM_stmia)
f03698e6 11408 {
c19d1205
ZW
11409 if (!inst.operands[0].writeback)
11410 as_warn (_("this instruction will write back the base register"));
11411 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11412 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11413 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11414 inst.operands[0].reg);
f03698e6 11415 }
c19d1205 11416 else
90e4755a 11417 {
c19d1205
ZW
11418 if (!inst.operands[0].writeback
11419 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11420 as_warn (_("this instruction will write back the base register"));
11421 else if (inst.operands[0].writeback
11422 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11423 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11424 }
11425
c19d1205
ZW
11426 inst.instruction = THUMB_OP16 (inst.instruction);
11427 inst.instruction |= inst.operands[0].reg << 8;
11428 inst.instruction |= inst.operands[1].imm;
11429 }
11430}
e28cd48c 11431
c19d1205
ZW
11432static void
11433do_t_ldrex (void)
11434{
11435 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11436 || inst.operands[1].postind || inst.operands[1].writeback
11437 || inst.operands[1].immisreg || inst.operands[1].shifted
11438 || inst.operands[1].negative,
01cfc07f 11439 BAD_ADDR_MODE);
e28cd48c 11440
5be8be5d
DG
11441 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11442
c19d1205
ZW
11443 inst.instruction |= inst.operands[0].reg << 12;
11444 inst.instruction |= inst.operands[1].reg << 16;
11445 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11446}
e28cd48c 11447
c19d1205
ZW
11448static void
11449do_t_ldrexd (void)
11450{
11451 if (!inst.operands[1].present)
1cac9012 11452 {
c19d1205
ZW
11453 constraint (inst.operands[0].reg == REG_LR,
11454 _("r14 not allowed as first register "
11455 "when second register is omitted"));
11456 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11457 }
c19d1205
ZW
11458 constraint (inst.operands[0].reg == inst.operands[1].reg,
11459 BAD_OVERLAP);
b99bd4ef 11460
c19d1205
ZW
11461 inst.instruction |= inst.operands[0].reg << 12;
11462 inst.instruction |= inst.operands[1].reg << 8;
11463 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11464}
11465
11466static void
c19d1205 11467do_t_ldst (void)
b99bd4ef 11468{
0110f2b8
PB
11469 unsigned long opcode;
11470 int Rn;
11471
e07e6e58
NC
11472 if (inst.operands[0].isreg
11473 && !inst.operands[0].preind
11474 && inst.operands[0].reg == REG_PC)
11475 set_it_insn_type_last ();
11476
0110f2b8 11477 opcode = inst.instruction;
c19d1205 11478 if (unified_syntax)
b99bd4ef 11479 {
53365c0d
PB
11480 if (!inst.operands[1].isreg)
11481 {
11482 if (opcode <= 0xffff)
11483 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11484 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11485 return;
11486 }
0110f2b8
PB
11487 if (inst.operands[1].isreg
11488 && !inst.operands[1].writeback
c19d1205
ZW
11489 && !inst.operands[1].shifted && !inst.operands[1].postind
11490 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11491 && opcode <= 0xffff
11492 && inst.size_req != 4)
c19d1205 11493 {
0110f2b8
PB
11494 /* Insn may have a 16-bit form. */
11495 Rn = inst.operands[1].reg;
11496 if (inst.operands[1].immisreg)
11497 {
11498 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11499 /* [Rn, Rik] */
0110f2b8
PB
11500 if (Rn <= 7 && inst.operands[1].imm <= 7)
11501 goto op16;
5be8be5d
DG
11502 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11503 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11504 }
11505 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11506 && opcode != T_MNEM_ldrsb)
11507 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11508 || (Rn == REG_SP && opcode == T_MNEM_str))
11509 {
11510 /* [Rn, #const] */
11511 if (Rn > 7)
11512 {
11513 if (Rn == REG_PC)
11514 {
11515 if (inst.reloc.pc_rel)
11516 opcode = T_MNEM_ldr_pc2;
11517 else
11518 opcode = T_MNEM_ldr_pc;
11519 }
11520 else
11521 {
11522 if (opcode == T_MNEM_ldr)
11523 opcode = T_MNEM_ldr_sp;
11524 else
11525 opcode = T_MNEM_str_sp;
11526 }
11527 inst.instruction = inst.operands[0].reg << 8;
11528 }
11529 else
11530 {
11531 inst.instruction = inst.operands[0].reg;
11532 inst.instruction |= inst.operands[1].reg << 3;
11533 }
11534 inst.instruction |= THUMB_OP16 (opcode);
11535 if (inst.size_req == 2)
11536 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11537 else
11538 inst.relax = opcode;
11539 return;
11540 }
c19d1205 11541 }
0110f2b8 11542 /* Definitely a 32-bit variant. */
5be8be5d 11543
8d67f500
NC
11544 /* Warning for Erratum 752419. */
11545 if (opcode == T_MNEM_ldr
11546 && inst.operands[0].reg == REG_SP
11547 && inst.operands[1].writeback == 1
11548 && !inst.operands[1].immisreg)
11549 {
11550 if (no_cpu_selected ()
11551 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11552 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11553 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11554 as_warn (_("This instruction may be unpredictable "
11555 "if executed on M-profile cores "
11556 "with interrupts enabled."));
11557 }
11558
5be8be5d 11559 /* Do some validations regarding addressing modes. */
1be5fd2e 11560 if (inst.operands[1].immisreg)
5be8be5d
DG
11561 reject_bad_reg (inst.operands[1].imm);
11562
1be5fd2e
NC
11563 constraint (inst.operands[1].writeback == 1
11564 && inst.operands[0].reg == inst.operands[1].reg,
11565 BAD_OVERLAP);
11566
0110f2b8 11567 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11568 inst.instruction |= inst.operands[0].reg << 12;
11569 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11570 check_ldr_r15_aligned ();
b99bd4ef
NC
11571 return;
11572 }
11573
c19d1205
ZW
11574 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11575
11576 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11577 {
c19d1205
ZW
11578 /* Only [Rn,Rm] is acceptable. */
11579 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11580 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11581 || inst.operands[1].postind || inst.operands[1].shifted
11582 || inst.operands[1].negative,
11583 _("Thumb does not support this addressing mode"));
11584 inst.instruction = THUMB_OP16 (inst.instruction);
11585 goto op16;
b99bd4ef 11586 }
5f4273c7 11587
c19d1205
ZW
11588 inst.instruction = THUMB_OP16 (inst.instruction);
11589 if (!inst.operands[1].isreg)
8335d6aa 11590 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11591 return;
b99bd4ef 11592
c19d1205
ZW
11593 constraint (!inst.operands[1].preind
11594 || inst.operands[1].shifted
11595 || inst.operands[1].writeback,
11596 _("Thumb does not support this addressing mode"));
11597 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11598 {
c19d1205
ZW
11599 constraint (inst.instruction & 0x0600,
11600 _("byte or halfword not valid for base register"));
11601 constraint (inst.operands[1].reg == REG_PC
11602 && !(inst.instruction & THUMB_LOAD_BIT),
11603 _("r15 based store not allowed"));
11604 constraint (inst.operands[1].immisreg,
11605 _("invalid base register for register offset"));
b99bd4ef 11606
c19d1205
ZW
11607 if (inst.operands[1].reg == REG_PC)
11608 inst.instruction = T_OPCODE_LDR_PC;
11609 else if (inst.instruction & THUMB_LOAD_BIT)
11610 inst.instruction = T_OPCODE_LDR_SP;
11611 else
11612 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11613
c19d1205
ZW
11614 inst.instruction |= inst.operands[0].reg << 8;
11615 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11616 return;
11617 }
90e4755a 11618
c19d1205
ZW
11619 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11620 if (!inst.operands[1].immisreg)
11621 {
11622 /* Immediate offset. */
11623 inst.instruction |= inst.operands[0].reg;
11624 inst.instruction |= inst.operands[1].reg << 3;
11625 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11626 return;
11627 }
90e4755a 11628
c19d1205
ZW
11629 /* Register offset. */
11630 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11631 constraint (inst.operands[1].negative,
11632 _("Thumb does not support this addressing mode"));
90e4755a 11633
c19d1205
ZW
11634 op16:
11635 switch (inst.instruction)
11636 {
11637 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11638 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11639 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11640 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11641 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11642 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11643 case 0x5600 /* ldrsb */:
11644 case 0x5e00 /* ldrsh */: break;
11645 default: abort ();
11646 }
90e4755a 11647
c19d1205
ZW
11648 inst.instruction |= inst.operands[0].reg;
11649 inst.instruction |= inst.operands[1].reg << 3;
11650 inst.instruction |= inst.operands[1].imm << 6;
11651}
90e4755a 11652
c19d1205
ZW
11653static void
11654do_t_ldstd (void)
11655{
11656 if (!inst.operands[1].present)
b99bd4ef 11657 {
c19d1205
ZW
11658 inst.operands[1].reg = inst.operands[0].reg + 1;
11659 constraint (inst.operands[0].reg == REG_LR,
11660 _("r14 not allowed here"));
bd340a04 11661 constraint (inst.operands[0].reg == REG_R12,
477330fc 11662 _("r12 not allowed here"));
b99bd4ef 11663 }
bd340a04
MGD
11664
11665 if (inst.operands[2].writeback
11666 && (inst.operands[0].reg == inst.operands[2].reg
11667 || inst.operands[1].reg == inst.operands[2].reg))
11668 as_warn (_("base register written back, and overlaps "
477330fc 11669 "one of transfer registers"));
bd340a04 11670
c19d1205
ZW
11671 inst.instruction |= inst.operands[0].reg << 12;
11672 inst.instruction |= inst.operands[1].reg << 8;
11673 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11674}
11675
c19d1205
ZW
11676static void
11677do_t_ldstt (void)
11678{
11679 inst.instruction |= inst.operands[0].reg << 12;
11680 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11681}
a737bd4d 11682
b99bd4ef 11683static void
c19d1205 11684do_t_mla (void)
b99bd4ef 11685{
fdfde340 11686 unsigned Rd, Rn, Rm, Ra;
c921be7d 11687
fdfde340
JM
11688 Rd = inst.operands[0].reg;
11689 Rn = inst.operands[1].reg;
11690 Rm = inst.operands[2].reg;
11691 Ra = inst.operands[3].reg;
11692
11693 reject_bad_reg (Rd);
11694 reject_bad_reg (Rn);
11695 reject_bad_reg (Rm);
11696 reject_bad_reg (Ra);
11697
11698 inst.instruction |= Rd << 8;
11699 inst.instruction |= Rn << 16;
11700 inst.instruction |= Rm;
11701 inst.instruction |= Ra << 12;
c19d1205 11702}
b99bd4ef 11703
c19d1205
ZW
11704static void
11705do_t_mlal (void)
11706{
fdfde340
JM
11707 unsigned RdLo, RdHi, Rn, Rm;
11708
11709 RdLo = inst.operands[0].reg;
11710 RdHi = inst.operands[1].reg;
11711 Rn = inst.operands[2].reg;
11712 Rm = inst.operands[3].reg;
11713
11714 reject_bad_reg (RdLo);
11715 reject_bad_reg (RdHi);
11716 reject_bad_reg (Rn);
11717 reject_bad_reg (Rm);
11718
11719 inst.instruction |= RdLo << 12;
11720 inst.instruction |= RdHi << 8;
11721 inst.instruction |= Rn << 16;
11722 inst.instruction |= Rm;
c19d1205 11723}
b99bd4ef 11724
c19d1205
ZW
11725static void
11726do_t_mov_cmp (void)
11727{
fdfde340
JM
11728 unsigned Rn, Rm;
11729
11730 Rn = inst.operands[0].reg;
11731 Rm = inst.operands[1].reg;
11732
e07e6e58
NC
11733 if (Rn == REG_PC)
11734 set_it_insn_type_last ();
11735
c19d1205 11736 if (unified_syntax)
b99bd4ef 11737 {
c19d1205
ZW
11738 int r0off = (inst.instruction == T_MNEM_mov
11739 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11740 unsigned long opcode;
3d388997
PB
11741 bfd_boolean narrow;
11742 bfd_boolean low_regs;
11743
fdfde340 11744 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11745 opcode = inst.instruction;
e07e6e58 11746 if (in_it_block ())
0110f2b8 11747 narrow = opcode != T_MNEM_movs;
3d388997 11748 else
0110f2b8 11749 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11750 if (inst.size_req == 4
11751 || inst.operands[1].shifted)
11752 narrow = FALSE;
11753
efd81785
PB
11754 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11755 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11756 && !inst.operands[1].shifted
fdfde340
JM
11757 && Rn == REG_PC
11758 && Rm == REG_LR)
efd81785
PB
11759 {
11760 inst.instruction = T2_SUBS_PC_LR;
11761 return;
11762 }
11763
fdfde340
JM
11764 if (opcode == T_MNEM_cmp)
11765 {
11766 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11767 if (narrow)
11768 {
11769 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11770 but valid. */
11771 warn_deprecated_sp (Rm);
11772 /* R15 was documented as a valid choice for Rm in ARMv6,
11773 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11774 tools reject R15, so we do too. */
11775 constraint (Rm == REG_PC, BAD_PC);
11776 }
11777 else
11778 reject_bad_reg (Rm);
fdfde340
JM
11779 }
11780 else if (opcode == T_MNEM_mov
11781 || opcode == T_MNEM_movs)
11782 {
11783 if (inst.operands[1].isreg)
11784 {
11785 if (opcode == T_MNEM_movs)
11786 {
11787 reject_bad_reg (Rn);
11788 reject_bad_reg (Rm);
11789 }
76fa04a4
MGD
11790 else if (narrow)
11791 {
11792 /* This is mov.n. */
11793 if ((Rn == REG_SP || Rn == REG_PC)
11794 && (Rm == REG_SP || Rm == REG_PC))
11795 {
5c3696f8 11796 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11797 "deprecated when r%u is the destination "
11798 "register."), Rm, Rn);
11799 }
11800 }
11801 else
11802 {
11803 /* This is mov.w. */
11804 constraint (Rn == REG_PC, BAD_PC);
11805 constraint (Rm == REG_PC, BAD_PC);
11806 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11807 }
fdfde340
JM
11808 }
11809 else
11810 reject_bad_reg (Rn);
11811 }
11812
c19d1205
ZW
11813 if (!inst.operands[1].isreg)
11814 {
0110f2b8 11815 /* Immediate operand. */
e07e6e58 11816 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11817 narrow = 0;
11818 if (low_regs && narrow)
11819 {
11820 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11821 inst.instruction |= Rn << 8;
0110f2b8 11822 if (inst.size_req == 2)
72d98d16
MG
11823 {
11824 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11825 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
11826 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11827 }
0110f2b8 11828 else
72d98d16 11829 inst.relax = opcode;
0110f2b8
PB
11830 }
11831 else
11832 {
11833 inst.instruction = THUMB_OP32 (inst.instruction);
11834 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11835 inst.instruction |= Rn << r0off;
0110f2b8
PB
11836 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11837 }
c19d1205 11838 }
728ca7c9
PB
11839 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11840 && (inst.instruction == T_MNEM_mov
11841 || inst.instruction == T_MNEM_movs))
11842 {
11843 /* Register shifts are encoded as separate shift instructions. */
11844 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11845
e07e6e58 11846 if (in_it_block ())
728ca7c9
PB
11847 narrow = !flags;
11848 else
11849 narrow = flags;
11850
11851 if (inst.size_req == 4)
11852 narrow = FALSE;
11853
11854 if (!low_regs || inst.operands[1].imm > 7)
11855 narrow = FALSE;
11856
fdfde340 11857 if (Rn != Rm)
728ca7c9
PB
11858 narrow = FALSE;
11859
11860 switch (inst.operands[1].shift_kind)
11861 {
11862 case SHIFT_LSL:
11863 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11864 break;
11865 case SHIFT_ASR:
11866 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11867 break;
11868 case SHIFT_LSR:
11869 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11870 break;
11871 case SHIFT_ROR:
11872 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11873 break;
11874 default:
5f4273c7 11875 abort ();
728ca7c9
PB
11876 }
11877
11878 inst.instruction = opcode;
11879 if (narrow)
11880 {
fdfde340 11881 inst.instruction |= Rn;
728ca7c9
PB
11882 inst.instruction |= inst.operands[1].imm << 3;
11883 }
11884 else
11885 {
11886 if (flags)
11887 inst.instruction |= CONDS_BIT;
11888
fdfde340
JM
11889 inst.instruction |= Rn << 8;
11890 inst.instruction |= Rm << 16;
728ca7c9
PB
11891 inst.instruction |= inst.operands[1].imm;
11892 }
11893 }
3d388997 11894 else if (!narrow)
c19d1205 11895 {
728ca7c9
PB
11896 /* Some mov with immediate shift have narrow variants.
11897 Register shifts are handled above. */
11898 if (low_regs && inst.operands[1].shifted
11899 && (inst.instruction == T_MNEM_mov
11900 || inst.instruction == T_MNEM_movs))
11901 {
e07e6e58 11902 if (in_it_block ())
728ca7c9
PB
11903 narrow = (inst.instruction == T_MNEM_mov);
11904 else
11905 narrow = (inst.instruction == T_MNEM_movs);
11906 }
11907
11908 if (narrow)
11909 {
11910 switch (inst.operands[1].shift_kind)
11911 {
11912 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11913 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11914 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11915 default: narrow = FALSE; break;
11916 }
11917 }
11918
11919 if (narrow)
11920 {
fdfde340
JM
11921 inst.instruction |= Rn;
11922 inst.instruction |= Rm << 3;
728ca7c9
PB
11923 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11924 }
11925 else
11926 {
11927 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11928 inst.instruction |= Rn << r0off;
728ca7c9
PB
11929 encode_thumb32_shifted_operand (1);
11930 }
c19d1205
ZW
11931 }
11932 else
11933 switch (inst.instruction)
11934 {
11935 case T_MNEM_mov:
837b3435 11936 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11937 results. Don't allow this. */
11938 if (low_regs)
11939 {
11940 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11941 "MOV Rd, Rs with two low registers is not "
11942 "permitted on this architecture");
fa94de6b 11943 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11944 arm_ext_v6);
11945 }
11946
c19d1205 11947 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11948 inst.instruction |= (Rn & 0x8) << 4;
11949 inst.instruction |= (Rn & 0x7);
11950 inst.instruction |= Rm << 3;
c19d1205 11951 break;
b99bd4ef 11952
c19d1205
ZW
11953 case T_MNEM_movs:
11954 /* We know we have low registers at this point.
941a8a52
MGD
11955 Generate LSLS Rd, Rs, #0. */
11956 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11957 inst.instruction |= Rn;
11958 inst.instruction |= Rm << 3;
c19d1205
ZW
11959 break;
11960
11961 case T_MNEM_cmp:
3d388997 11962 if (low_regs)
c19d1205
ZW
11963 {
11964 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11965 inst.instruction |= Rn;
11966 inst.instruction |= Rm << 3;
c19d1205
ZW
11967 }
11968 else
11969 {
11970 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11971 inst.instruction |= (Rn & 0x8) << 4;
11972 inst.instruction |= (Rn & 0x7);
11973 inst.instruction |= Rm << 3;
c19d1205
ZW
11974 }
11975 break;
11976 }
b99bd4ef
NC
11977 return;
11978 }
11979
c19d1205 11980 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11981
11982 /* PR 10443: Do not silently ignore shifted operands. */
11983 constraint (inst.operands[1].shifted,
11984 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11985
c19d1205 11986 if (inst.operands[1].isreg)
b99bd4ef 11987 {
fdfde340 11988 if (Rn < 8 && Rm < 8)
b99bd4ef 11989 {
c19d1205
ZW
11990 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11991 since a MOV instruction produces unpredictable results. */
11992 if (inst.instruction == T_OPCODE_MOV_I8)
11993 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11994 else
c19d1205 11995 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11996
fdfde340
JM
11997 inst.instruction |= Rn;
11998 inst.instruction |= Rm << 3;
b99bd4ef
NC
11999 }
12000 else
12001 {
c19d1205
ZW
12002 if (inst.instruction == T_OPCODE_MOV_I8)
12003 inst.instruction = T_OPCODE_MOV_HR;
12004 else
12005 inst.instruction = T_OPCODE_CMP_HR;
12006 do_t_cpy ();
b99bd4ef
NC
12007 }
12008 }
c19d1205 12009 else
b99bd4ef 12010 {
fdfde340 12011 constraint (Rn > 7,
c19d1205 12012 _("only lo regs allowed with immediate"));
fdfde340 12013 inst.instruction |= Rn << 8;
c19d1205
ZW
12014 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12015 }
12016}
b99bd4ef 12017
c19d1205
ZW
12018static void
12019do_t_mov16 (void)
12020{
fdfde340 12021 unsigned Rd;
b6895b4f
PB
12022 bfd_vma imm;
12023 bfd_boolean top;
12024
12025 top = (inst.instruction & 0x00800000) != 0;
12026 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12027 {
12028 constraint (top, _(":lower16: not allowed this instruction"));
12029 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12030 }
12031 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12032 {
12033 constraint (!top, _(":upper16: not allowed this instruction"));
12034 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12035 }
12036
fdfde340
JM
12037 Rd = inst.operands[0].reg;
12038 reject_bad_reg (Rd);
12039
12040 inst.instruction |= Rd << 8;
b6895b4f
PB
12041 if (inst.reloc.type == BFD_RELOC_UNUSED)
12042 {
12043 imm = inst.reloc.exp.X_add_number;
12044 inst.instruction |= (imm & 0xf000) << 4;
12045 inst.instruction |= (imm & 0x0800) << 15;
12046 inst.instruction |= (imm & 0x0700) << 4;
12047 inst.instruction |= (imm & 0x00ff);
12048 }
c19d1205 12049}
b99bd4ef 12050
c19d1205
ZW
12051static void
12052do_t_mvn_tst (void)
12053{
fdfde340 12054 unsigned Rn, Rm;
c921be7d 12055
fdfde340
JM
12056 Rn = inst.operands[0].reg;
12057 Rm = inst.operands[1].reg;
12058
12059 if (inst.instruction == T_MNEM_cmp
12060 || inst.instruction == T_MNEM_cmn)
12061 constraint (Rn == REG_PC, BAD_PC);
12062 else
12063 reject_bad_reg (Rn);
12064 reject_bad_reg (Rm);
12065
c19d1205
ZW
12066 if (unified_syntax)
12067 {
12068 int r0off = (inst.instruction == T_MNEM_mvn
12069 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12070 bfd_boolean narrow;
12071
12072 if (inst.size_req == 4
12073 || inst.instruction > 0xffff
12074 || inst.operands[1].shifted
fdfde340 12075 || Rn > 7 || Rm > 7)
3d388997 12076 narrow = FALSE;
fe8b4cc3
KT
12077 else if (inst.instruction == T_MNEM_cmn
12078 || inst.instruction == T_MNEM_tst)
3d388997
PB
12079 narrow = TRUE;
12080 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12081 narrow = !in_it_block ();
3d388997 12082 else
e07e6e58 12083 narrow = in_it_block ();
3d388997 12084
c19d1205 12085 if (!inst.operands[1].isreg)
b99bd4ef 12086 {
c19d1205
ZW
12087 /* For an immediate, we always generate a 32-bit opcode;
12088 section relaxation will shrink it later if possible. */
12089 if (inst.instruction < 0xffff)
12090 inst.instruction = THUMB_OP32 (inst.instruction);
12091 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12092 inst.instruction |= Rn << r0off;
c19d1205 12093 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12094 }
c19d1205 12095 else
b99bd4ef 12096 {
c19d1205 12097 /* See if we can do this with a 16-bit instruction. */
3d388997 12098 if (narrow)
b99bd4ef 12099 {
c19d1205 12100 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12101 inst.instruction |= Rn;
12102 inst.instruction |= Rm << 3;
b99bd4ef 12103 }
c19d1205 12104 else
b99bd4ef 12105 {
c19d1205
ZW
12106 constraint (inst.operands[1].shifted
12107 && inst.operands[1].immisreg,
12108 _("shift must be constant"));
12109 if (inst.instruction < 0xffff)
12110 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12111 inst.instruction |= Rn << r0off;
c19d1205 12112 encode_thumb32_shifted_operand (1);
b99bd4ef 12113 }
b99bd4ef
NC
12114 }
12115 }
12116 else
12117 {
c19d1205
ZW
12118 constraint (inst.instruction > 0xffff
12119 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12120 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12121 _("unshifted register required"));
fdfde340 12122 constraint (Rn > 7 || Rm > 7,
c19d1205 12123 BAD_HIREG);
b99bd4ef 12124
c19d1205 12125 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12126 inst.instruction |= Rn;
12127 inst.instruction |= Rm << 3;
b99bd4ef 12128 }
b99bd4ef
NC
12129}
12130
b05fe5cf 12131static void
c19d1205 12132do_t_mrs (void)
b05fe5cf 12133{
fdfde340 12134 unsigned Rd;
037e8744
JB
12135
12136 if (do_vfp_nsyn_mrs () == SUCCESS)
12137 return;
12138
90ec0d68
MGD
12139 Rd = inst.operands[0].reg;
12140 reject_bad_reg (Rd);
12141 inst.instruction |= Rd << 8;
12142
12143 if (inst.operands[1].isreg)
62b3e311 12144 {
90ec0d68
MGD
12145 unsigned br = inst.operands[1].reg;
12146 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12147 as_bad (_("bad register for mrs"));
12148
12149 inst.instruction |= br & (0xf << 16);
12150 inst.instruction |= (br & 0x300) >> 4;
12151 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12152 }
12153 else
12154 {
90ec0d68 12155 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12156
d2cd1205 12157 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12158 {
12159 /* PR gas/12698: The constraint is only applied for m_profile.
12160 If the user has specified -march=all, we want to ignore it as
12161 we are building for any CPU type, including non-m variants. */
823d2571
TG
12162 bfd_boolean m_profile =
12163 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12164 constraint ((flags != 0) && m_profile, _("selected processor does "
12165 "not support requested special purpose register"));
12166 }
90ec0d68 12167 else
d2cd1205
JB
12168 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12169 devices). */
12170 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12171 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12172
90ec0d68
MGD
12173 inst.instruction |= (flags & SPSR_BIT) >> 2;
12174 inst.instruction |= inst.operands[1].imm & 0xff;
12175 inst.instruction |= 0xf0000;
12176 }
c19d1205 12177}
b05fe5cf 12178
c19d1205
ZW
12179static void
12180do_t_msr (void)
12181{
62b3e311 12182 int flags;
fdfde340 12183 unsigned Rn;
62b3e311 12184
037e8744
JB
12185 if (do_vfp_nsyn_msr () == SUCCESS)
12186 return;
12187
c19d1205
ZW
12188 constraint (!inst.operands[1].isreg,
12189 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12190
12191 if (inst.operands[0].isreg)
12192 flags = (int)(inst.operands[0].reg);
12193 else
12194 flags = inst.operands[0].imm;
12195
d2cd1205 12196 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12197 {
d2cd1205
JB
12198 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12199
1a43faaf 12200 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12201 If the user has specified -march=all, we want to ignore it as
12202 we are building for any CPU type, including non-m variants. */
823d2571
TG
12203 bfd_boolean m_profile =
12204 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12205 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12206 && (bits & ~(PSR_s | PSR_f)) != 0)
12207 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12208 && bits != PSR_f)) && m_profile,
12209 _("selected processor does not support requested special "
12210 "purpose register"));
62b3e311
PB
12211 }
12212 else
d2cd1205
JB
12213 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12214 "requested special purpose register"));
c921be7d 12215
fdfde340
JM
12216 Rn = inst.operands[1].reg;
12217 reject_bad_reg (Rn);
12218
62b3e311 12219 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12220 inst.instruction |= (flags & 0xf0000) >> 8;
12221 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12222 inst.instruction |= (flags & 0xff);
fdfde340 12223 inst.instruction |= Rn << 16;
c19d1205 12224}
b05fe5cf 12225
c19d1205
ZW
12226static void
12227do_t_mul (void)
12228{
17828f45 12229 bfd_boolean narrow;
fdfde340 12230 unsigned Rd, Rn, Rm;
17828f45 12231
c19d1205
ZW
12232 if (!inst.operands[2].present)
12233 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12234
fdfde340
JM
12235 Rd = inst.operands[0].reg;
12236 Rn = inst.operands[1].reg;
12237 Rm = inst.operands[2].reg;
12238
17828f45 12239 if (unified_syntax)
b05fe5cf 12240 {
17828f45 12241 if (inst.size_req == 4
fdfde340
JM
12242 || (Rd != Rn
12243 && Rd != Rm)
12244 || Rn > 7
12245 || Rm > 7)
17828f45
JM
12246 narrow = FALSE;
12247 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12248 narrow = !in_it_block ();
17828f45 12249 else
e07e6e58 12250 narrow = in_it_block ();
b05fe5cf 12251 }
c19d1205 12252 else
b05fe5cf 12253 {
17828f45 12254 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12255 constraint (Rn > 7 || Rm > 7,
c19d1205 12256 BAD_HIREG);
17828f45
JM
12257 narrow = TRUE;
12258 }
b05fe5cf 12259
17828f45
JM
12260 if (narrow)
12261 {
12262 /* 16-bit MULS/Conditional MUL. */
c19d1205 12263 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12264 inst.instruction |= Rd;
b05fe5cf 12265
fdfde340
JM
12266 if (Rd == Rn)
12267 inst.instruction |= Rm << 3;
12268 else if (Rd == Rm)
12269 inst.instruction |= Rn << 3;
c19d1205
ZW
12270 else
12271 constraint (1, _("dest must overlap one source register"));
12272 }
17828f45
JM
12273 else
12274 {
e07e6e58
NC
12275 constraint (inst.instruction != T_MNEM_mul,
12276 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12277 /* 32-bit MUL. */
12278 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12279 inst.instruction |= Rd << 8;
12280 inst.instruction |= Rn << 16;
12281 inst.instruction |= Rm << 0;
12282
12283 reject_bad_reg (Rd);
12284 reject_bad_reg (Rn);
12285 reject_bad_reg (Rm);
17828f45 12286 }
c19d1205 12287}
b05fe5cf 12288
c19d1205
ZW
12289static void
12290do_t_mull (void)
12291{
fdfde340 12292 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12293
fdfde340
JM
12294 RdLo = inst.operands[0].reg;
12295 RdHi = inst.operands[1].reg;
12296 Rn = inst.operands[2].reg;
12297 Rm = inst.operands[3].reg;
12298
12299 reject_bad_reg (RdLo);
12300 reject_bad_reg (RdHi);
12301 reject_bad_reg (Rn);
12302 reject_bad_reg (Rm);
12303
12304 inst.instruction |= RdLo << 12;
12305 inst.instruction |= RdHi << 8;
12306 inst.instruction |= Rn << 16;
12307 inst.instruction |= Rm;
12308
12309 if (RdLo == RdHi)
c19d1205
ZW
12310 as_tsktsk (_("rdhi and rdlo must be different"));
12311}
b05fe5cf 12312
c19d1205
ZW
12313static void
12314do_t_nop (void)
12315{
e07e6e58
NC
12316 set_it_insn_type (NEUTRAL_IT_INSN);
12317
c19d1205
ZW
12318 if (unified_syntax)
12319 {
12320 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12321 {
c19d1205
ZW
12322 inst.instruction = THUMB_OP32 (inst.instruction);
12323 inst.instruction |= inst.operands[0].imm;
12324 }
12325 else
12326 {
bc2d1808
NC
12327 /* PR9722: Check for Thumb2 availability before
12328 generating a thumb2 nop instruction. */
afa62d5e 12329 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12330 {
12331 inst.instruction = THUMB_OP16 (inst.instruction);
12332 inst.instruction |= inst.operands[0].imm << 4;
12333 }
12334 else
12335 inst.instruction = 0x46c0;
c19d1205
ZW
12336 }
12337 }
12338 else
12339 {
12340 constraint (inst.operands[0].present,
12341 _("Thumb does not support NOP with hints"));
12342 inst.instruction = 0x46c0;
12343 }
12344}
b05fe5cf 12345
c19d1205
ZW
12346static void
12347do_t_neg (void)
12348{
12349 if (unified_syntax)
12350 {
3d388997
PB
12351 bfd_boolean narrow;
12352
12353 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12354 narrow = !in_it_block ();
3d388997 12355 else
e07e6e58 12356 narrow = in_it_block ();
3d388997
PB
12357 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12358 narrow = FALSE;
12359 if (inst.size_req == 4)
12360 narrow = FALSE;
12361
12362 if (!narrow)
c19d1205
ZW
12363 {
12364 inst.instruction = THUMB_OP32 (inst.instruction);
12365 inst.instruction |= inst.operands[0].reg << 8;
12366 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12367 }
12368 else
12369 {
c19d1205
ZW
12370 inst.instruction = THUMB_OP16 (inst.instruction);
12371 inst.instruction |= inst.operands[0].reg;
12372 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12373 }
12374 }
12375 else
12376 {
c19d1205
ZW
12377 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12378 BAD_HIREG);
12379 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12380
12381 inst.instruction = THUMB_OP16 (inst.instruction);
12382 inst.instruction |= inst.operands[0].reg;
12383 inst.instruction |= inst.operands[1].reg << 3;
12384 }
12385}
12386
1c444d06
JM
12387static void
12388do_t_orn (void)
12389{
12390 unsigned Rd, Rn;
12391
12392 Rd = inst.operands[0].reg;
12393 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12394
fdfde340
JM
12395 reject_bad_reg (Rd);
12396 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12397 reject_bad_reg (Rn);
12398
1c444d06
JM
12399 inst.instruction |= Rd << 8;
12400 inst.instruction |= Rn << 16;
12401
12402 if (!inst.operands[2].isreg)
12403 {
12404 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12405 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12406 }
12407 else
12408 {
12409 unsigned Rm;
12410
12411 Rm = inst.operands[2].reg;
fdfde340 12412 reject_bad_reg (Rm);
1c444d06
JM
12413
12414 constraint (inst.operands[2].shifted
12415 && inst.operands[2].immisreg,
12416 _("shift must be constant"));
12417 encode_thumb32_shifted_operand (2);
12418 }
12419}
12420
c19d1205
ZW
12421static void
12422do_t_pkhbt (void)
12423{
fdfde340
JM
12424 unsigned Rd, Rn, Rm;
12425
12426 Rd = inst.operands[0].reg;
12427 Rn = inst.operands[1].reg;
12428 Rm = inst.operands[2].reg;
12429
12430 reject_bad_reg (Rd);
12431 reject_bad_reg (Rn);
12432 reject_bad_reg (Rm);
12433
12434 inst.instruction |= Rd << 8;
12435 inst.instruction |= Rn << 16;
12436 inst.instruction |= Rm;
c19d1205
ZW
12437 if (inst.operands[3].present)
12438 {
12439 unsigned int val = inst.reloc.exp.X_add_number;
12440 constraint (inst.reloc.exp.X_op != O_constant,
12441 _("expression too complex"));
12442 inst.instruction |= (val & 0x1c) << 10;
12443 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12444 }
c19d1205 12445}
b05fe5cf 12446
c19d1205
ZW
12447static void
12448do_t_pkhtb (void)
12449{
12450 if (!inst.operands[3].present)
1ef52f49
NC
12451 {
12452 unsigned Rtmp;
12453
12454 inst.instruction &= ~0x00000020;
12455
12456 /* PR 10168. Swap the Rm and Rn registers. */
12457 Rtmp = inst.operands[1].reg;
12458 inst.operands[1].reg = inst.operands[2].reg;
12459 inst.operands[2].reg = Rtmp;
12460 }
c19d1205 12461 do_t_pkhbt ();
b05fe5cf
ZW
12462}
12463
c19d1205
ZW
12464static void
12465do_t_pld (void)
12466{
fdfde340
JM
12467 if (inst.operands[0].immisreg)
12468 reject_bad_reg (inst.operands[0].imm);
12469
c19d1205
ZW
12470 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12471}
b05fe5cf 12472
c19d1205
ZW
12473static void
12474do_t_push_pop (void)
b99bd4ef 12475{
e9f89963 12476 unsigned mask;
5f4273c7 12477
c19d1205
ZW
12478 constraint (inst.operands[0].writeback,
12479 _("push/pop do not support {reglist}^"));
12480 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12481 _("expression too complex"));
b99bd4ef 12482
e9f89963 12483 mask = inst.operands[0].imm;
d3bfe16e 12484 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12485 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
12486 else if (inst.size_req != 4
12487 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12488 ? REG_LR : REG_PC)))
b99bd4ef 12489 {
c19d1205
ZW
12490 inst.instruction = THUMB_OP16 (inst.instruction);
12491 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12492 inst.instruction |= mask & 0xff;
c19d1205
ZW
12493 }
12494 else if (unified_syntax)
12495 {
3c707909 12496 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12497 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12498 }
12499 else
12500 {
12501 inst.error = _("invalid register list to push/pop instruction");
12502 return;
12503 }
c19d1205 12504}
b99bd4ef 12505
c19d1205
ZW
12506static void
12507do_t_rbit (void)
12508{
fdfde340
JM
12509 unsigned Rd, Rm;
12510
12511 Rd = inst.operands[0].reg;
12512 Rm = inst.operands[1].reg;
12513
12514 reject_bad_reg (Rd);
12515 reject_bad_reg (Rm);
12516
12517 inst.instruction |= Rd << 8;
12518 inst.instruction |= Rm << 16;
12519 inst.instruction |= Rm;
c19d1205 12520}
b99bd4ef 12521
c19d1205
ZW
12522static void
12523do_t_rev (void)
12524{
fdfde340
JM
12525 unsigned Rd, Rm;
12526
12527 Rd = inst.operands[0].reg;
12528 Rm = inst.operands[1].reg;
12529
12530 reject_bad_reg (Rd);
12531 reject_bad_reg (Rm);
12532
12533 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12534 && inst.size_req != 4)
12535 {
12536 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12537 inst.instruction |= Rd;
12538 inst.instruction |= Rm << 3;
c19d1205
ZW
12539 }
12540 else if (unified_syntax)
12541 {
12542 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12543 inst.instruction |= Rd << 8;
12544 inst.instruction |= Rm << 16;
12545 inst.instruction |= Rm;
c19d1205
ZW
12546 }
12547 else
12548 inst.error = BAD_HIREG;
12549}
b99bd4ef 12550
1c444d06
JM
12551static void
12552do_t_rrx (void)
12553{
12554 unsigned Rd, Rm;
12555
12556 Rd = inst.operands[0].reg;
12557 Rm = inst.operands[1].reg;
12558
fdfde340
JM
12559 reject_bad_reg (Rd);
12560 reject_bad_reg (Rm);
c921be7d 12561
1c444d06
JM
12562 inst.instruction |= Rd << 8;
12563 inst.instruction |= Rm;
12564}
12565
c19d1205
ZW
12566static void
12567do_t_rsb (void)
12568{
fdfde340 12569 unsigned Rd, Rs;
b99bd4ef 12570
c19d1205
ZW
12571 Rd = inst.operands[0].reg;
12572 Rs = (inst.operands[1].present
12573 ? inst.operands[1].reg /* Rd, Rs, foo */
12574 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12575
fdfde340
JM
12576 reject_bad_reg (Rd);
12577 reject_bad_reg (Rs);
12578 if (inst.operands[2].isreg)
12579 reject_bad_reg (inst.operands[2].reg);
12580
c19d1205
ZW
12581 inst.instruction |= Rd << 8;
12582 inst.instruction |= Rs << 16;
12583 if (!inst.operands[2].isreg)
12584 {
026d3abb
PB
12585 bfd_boolean narrow;
12586
12587 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12588 narrow = !in_it_block ();
026d3abb 12589 else
e07e6e58 12590 narrow = in_it_block ();
026d3abb
PB
12591
12592 if (Rd > 7 || Rs > 7)
12593 narrow = FALSE;
12594
12595 if (inst.size_req == 4 || !unified_syntax)
12596 narrow = FALSE;
12597
12598 if (inst.reloc.exp.X_op != O_constant
12599 || inst.reloc.exp.X_add_number != 0)
12600 narrow = FALSE;
12601
12602 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12603 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12604 if (narrow)
12605 {
12606 inst.reloc.type = BFD_RELOC_UNUSED;
12607 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12608 inst.instruction |= Rs << 3;
12609 inst.instruction |= Rd;
12610 }
12611 else
12612 {
12613 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12614 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12615 }
c19d1205
ZW
12616 }
12617 else
12618 encode_thumb32_shifted_operand (2);
12619}
b99bd4ef 12620
c19d1205
ZW
12621static void
12622do_t_setend (void)
12623{
12e37cbc
MGD
12624 if (warn_on_deprecated
12625 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12626 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12627
e07e6e58 12628 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12629 if (inst.operands[0].imm)
12630 inst.instruction |= 0x8;
12631}
b99bd4ef 12632
c19d1205
ZW
12633static void
12634do_t_shift (void)
12635{
12636 if (!inst.operands[1].present)
12637 inst.operands[1].reg = inst.operands[0].reg;
12638
12639 if (unified_syntax)
12640 {
3d388997
PB
12641 bfd_boolean narrow;
12642 int shift_kind;
12643
12644 switch (inst.instruction)
12645 {
12646 case T_MNEM_asr:
12647 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12648 case T_MNEM_lsl:
12649 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12650 case T_MNEM_lsr:
12651 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12652 case T_MNEM_ror:
12653 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12654 default: abort ();
12655 }
12656
12657 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12658 narrow = !in_it_block ();
3d388997 12659 else
e07e6e58 12660 narrow = in_it_block ();
3d388997
PB
12661 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12662 narrow = FALSE;
12663 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12664 narrow = FALSE;
12665 if (inst.operands[2].isreg
12666 && (inst.operands[1].reg != inst.operands[0].reg
12667 || inst.operands[2].reg > 7))
12668 narrow = FALSE;
12669 if (inst.size_req == 4)
12670 narrow = FALSE;
12671
fdfde340
JM
12672 reject_bad_reg (inst.operands[0].reg);
12673 reject_bad_reg (inst.operands[1].reg);
c921be7d 12674
3d388997 12675 if (!narrow)
c19d1205
ZW
12676 {
12677 if (inst.operands[2].isreg)
b99bd4ef 12678 {
fdfde340 12679 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12680 inst.instruction = THUMB_OP32 (inst.instruction);
12681 inst.instruction |= inst.operands[0].reg << 8;
12682 inst.instruction |= inst.operands[1].reg << 16;
12683 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12684
12685 /* PR 12854: Error on extraneous shifts. */
12686 constraint (inst.operands[2].shifted,
12687 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12688 }
12689 else
12690 {
12691 inst.operands[1].shifted = 1;
3d388997 12692 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12693 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12694 ? T_MNEM_movs : T_MNEM_mov);
12695 inst.instruction |= inst.operands[0].reg << 8;
12696 encode_thumb32_shifted_operand (1);
12697 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12698 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12699 }
12700 }
12701 else
12702 {
c19d1205 12703 if (inst.operands[2].isreg)
b99bd4ef 12704 {
3d388997 12705 switch (shift_kind)
b99bd4ef 12706 {
3d388997
PB
12707 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12708 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12709 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12710 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12711 default: abort ();
b99bd4ef 12712 }
5f4273c7 12713
c19d1205
ZW
12714 inst.instruction |= inst.operands[0].reg;
12715 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12716
12717 /* PR 12854: Error on extraneous shifts. */
12718 constraint (inst.operands[2].shifted,
12719 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12720 }
12721 else
12722 {
3d388997 12723 switch (shift_kind)
b99bd4ef 12724 {
3d388997
PB
12725 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12726 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12727 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12728 default: abort ();
b99bd4ef 12729 }
c19d1205
ZW
12730 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12731 inst.instruction |= inst.operands[0].reg;
12732 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12733 }
12734 }
c19d1205
ZW
12735 }
12736 else
12737 {
12738 constraint (inst.operands[0].reg > 7
12739 || inst.operands[1].reg > 7, BAD_HIREG);
12740 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12741
c19d1205
ZW
12742 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12743 {
12744 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12745 constraint (inst.operands[0].reg != inst.operands[1].reg,
12746 _("source1 and dest must be same register"));
b99bd4ef 12747
c19d1205
ZW
12748 switch (inst.instruction)
12749 {
12750 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12751 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12752 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12753 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12754 default: abort ();
12755 }
5f4273c7 12756
c19d1205
ZW
12757 inst.instruction |= inst.operands[0].reg;
12758 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12759
12760 /* PR 12854: Error on extraneous shifts. */
12761 constraint (inst.operands[2].shifted,
12762 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12763 }
12764 else
b99bd4ef 12765 {
c19d1205
ZW
12766 switch (inst.instruction)
12767 {
12768 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12769 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12770 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12771 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12772 default: abort ();
12773 }
12774 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12775 inst.instruction |= inst.operands[0].reg;
12776 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12777 }
12778 }
b99bd4ef
NC
12779}
12780
12781static void
c19d1205 12782do_t_simd (void)
b99bd4ef 12783{
fdfde340
JM
12784 unsigned Rd, Rn, Rm;
12785
12786 Rd = inst.operands[0].reg;
12787 Rn = inst.operands[1].reg;
12788 Rm = inst.operands[2].reg;
12789
12790 reject_bad_reg (Rd);
12791 reject_bad_reg (Rn);
12792 reject_bad_reg (Rm);
12793
12794 inst.instruction |= Rd << 8;
12795 inst.instruction |= Rn << 16;
12796 inst.instruction |= Rm;
c19d1205 12797}
b99bd4ef 12798
03ee1b7f
NC
12799static void
12800do_t_simd2 (void)
12801{
12802 unsigned Rd, Rn, Rm;
12803
12804 Rd = inst.operands[0].reg;
12805 Rm = inst.operands[1].reg;
12806 Rn = inst.operands[2].reg;
12807
12808 reject_bad_reg (Rd);
12809 reject_bad_reg (Rn);
12810 reject_bad_reg (Rm);
12811
12812 inst.instruction |= Rd << 8;
12813 inst.instruction |= Rn << 16;
12814 inst.instruction |= Rm;
12815}
12816
c19d1205 12817static void
3eb17e6b 12818do_t_smc (void)
c19d1205
ZW
12819{
12820 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12821 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12822 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12823 constraint (inst.reloc.exp.X_op != O_constant,
12824 _("expression too complex"));
12825 inst.reloc.type = BFD_RELOC_UNUSED;
12826 inst.instruction |= (value & 0xf000) >> 12;
12827 inst.instruction |= (value & 0x0ff0);
12828 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12829 /* PR gas/15623: SMC instructions must be last in an IT block. */
12830 set_it_insn_type_last ();
c19d1205 12831}
b99bd4ef 12832
90ec0d68
MGD
12833static void
12834do_t_hvc (void)
12835{
12836 unsigned int value = inst.reloc.exp.X_add_number;
12837
12838 inst.reloc.type = BFD_RELOC_UNUSED;
12839 inst.instruction |= (value & 0x0fff);
12840 inst.instruction |= (value & 0xf000) << 4;
12841}
12842
c19d1205 12843static void
3a21c15a 12844do_t_ssat_usat (int bias)
c19d1205 12845{
fdfde340
JM
12846 unsigned Rd, Rn;
12847
12848 Rd = inst.operands[0].reg;
12849 Rn = inst.operands[2].reg;
12850
12851 reject_bad_reg (Rd);
12852 reject_bad_reg (Rn);
12853
12854 inst.instruction |= Rd << 8;
3a21c15a 12855 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12856 inst.instruction |= Rn << 16;
b99bd4ef 12857
c19d1205 12858 if (inst.operands[3].present)
b99bd4ef 12859 {
3a21c15a
NC
12860 offsetT shift_amount = inst.reloc.exp.X_add_number;
12861
12862 inst.reloc.type = BFD_RELOC_UNUSED;
12863
c19d1205
ZW
12864 constraint (inst.reloc.exp.X_op != O_constant,
12865 _("expression too complex"));
b99bd4ef 12866
3a21c15a 12867 if (shift_amount != 0)
6189168b 12868 {
3a21c15a
NC
12869 constraint (shift_amount > 31,
12870 _("shift expression is too large"));
12871
c19d1205 12872 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12873 inst.instruction |= 0x00200000; /* sh bit. */
12874
12875 inst.instruction |= (shift_amount & 0x1c) << 10;
12876 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12877 }
12878 }
b99bd4ef 12879}
c921be7d 12880
3a21c15a
NC
12881static void
12882do_t_ssat (void)
12883{
12884 do_t_ssat_usat (1);
12885}
b99bd4ef 12886
0dd132b6 12887static void
c19d1205 12888do_t_ssat16 (void)
0dd132b6 12889{
fdfde340
JM
12890 unsigned Rd, Rn;
12891
12892 Rd = inst.operands[0].reg;
12893 Rn = inst.operands[2].reg;
12894
12895 reject_bad_reg (Rd);
12896 reject_bad_reg (Rn);
12897
12898 inst.instruction |= Rd << 8;
c19d1205 12899 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12900 inst.instruction |= Rn << 16;
c19d1205 12901}
0dd132b6 12902
c19d1205
ZW
12903static void
12904do_t_strex (void)
12905{
12906 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12907 || inst.operands[2].postind || inst.operands[2].writeback
12908 || inst.operands[2].immisreg || inst.operands[2].shifted
12909 || inst.operands[2].negative,
01cfc07f 12910 BAD_ADDR_MODE);
0dd132b6 12911
5be8be5d
DG
12912 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12913
c19d1205
ZW
12914 inst.instruction |= inst.operands[0].reg << 8;
12915 inst.instruction |= inst.operands[1].reg << 12;
12916 inst.instruction |= inst.operands[2].reg << 16;
12917 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12918}
12919
b99bd4ef 12920static void
c19d1205 12921do_t_strexd (void)
b99bd4ef 12922{
c19d1205
ZW
12923 if (!inst.operands[2].present)
12924 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12925
c19d1205
ZW
12926 constraint (inst.operands[0].reg == inst.operands[1].reg
12927 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12928 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12929 BAD_OVERLAP);
b99bd4ef 12930
c19d1205
ZW
12931 inst.instruction |= inst.operands[0].reg;
12932 inst.instruction |= inst.operands[1].reg << 12;
12933 inst.instruction |= inst.operands[2].reg << 8;
12934 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12935}
12936
12937static void
c19d1205 12938do_t_sxtah (void)
b99bd4ef 12939{
fdfde340
JM
12940 unsigned Rd, Rn, Rm;
12941
12942 Rd = inst.operands[0].reg;
12943 Rn = inst.operands[1].reg;
12944 Rm = inst.operands[2].reg;
12945
12946 reject_bad_reg (Rd);
12947 reject_bad_reg (Rn);
12948 reject_bad_reg (Rm);
12949
12950 inst.instruction |= Rd << 8;
12951 inst.instruction |= Rn << 16;
12952 inst.instruction |= Rm;
c19d1205
ZW
12953 inst.instruction |= inst.operands[3].imm << 4;
12954}
b99bd4ef 12955
c19d1205
ZW
12956static void
12957do_t_sxth (void)
12958{
fdfde340
JM
12959 unsigned Rd, Rm;
12960
12961 Rd = inst.operands[0].reg;
12962 Rm = inst.operands[1].reg;
12963
12964 reject_bad_reg (Rd);
12965 reject_bad_reg (Rm);
c921be7d
NC
12966
12967 if (inst.instruction <= 0xffff
12968 && inst.size_req != 4
fdfde340 12969 && Rd <= 7 && Rm <= 7
c19d1205 12970 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12971 {
c19d1205 12972 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12973 inst.instruction |= Rd;
12974 inst.instruction |= Rm << 3;
b99bd4ef 12975 }
c19d1205 12976 else if (unified_syntax)
b99bd4ef 12977 {
c19d1205
ZW
12978 if (inst.instruction <= 0xffff)
12979 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12980 inst.instruction |= Rd << 8;
12981 inst.instruction |= Rm;
c19d1205 12982 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12983 }
c19d1205 12984 else
b99bd4ef 12985 {
c19d1205
ZW
12986 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12987 _("Thumb encoding does not support rotation"));
12988 constraint (1, BAD_HIREG);
b99bd4ef 12989 }
c19d1205 12990}
b99bd4ef 12991
c19d1205
ZW
12992static void
12993do_t_swi (void)
12994{
b2a5fbdc
MGD
12995 /* We have to do the following check manually as ARM_EXT_OS only applies
12996 to ARM_EXT_V6M. */
12997 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12998 {
ac7f631b
NC
12999 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
13000 /* This only applies to the v6m howver, not later architectures. */
13001 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13002 as_bad (_("SVC is not permitted on this architecture"));
13003 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13004 }
13005
c19d1205
ZW
13006 inst.reloc.type = BFD_RELOC_ARM_SWI;
13007}
b99bd4ef 13008
92e90b6e
PB
13009static void
13010do_t_tb (void)
13011{
fdfde340 13012 unsigned Rn, Rm;
92e90b6e
PB
13013 int half;
13014
13015 half = (inst.instruction & 0x10) != 0;
e07e6e58 13016 set_it_insn_type_last ();
dfa9f0d5
PB
13017 constraint (inst.operands[0].immisreg,
13018 _("instruction requires register index"));
fdfde340
JM
13019
13020 Rn = inst.operands[0].reg;
13021 Rm = inst.operands[0].imm;
c921be7d 13022
fdfde340
JM
13023 constraint (Rn == REG_SP, BAD_SP);
13024 reject_bad_reg (Rm);
13025
92e90b6e
PB
13026 constraint (!half && inst.operands[0].shifted,
13027 _("instruction does not allow shifted index"));
fdfde340 13028 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13029}
13030
74db7efb
NC
13031static void
13032do_t_udf (void)
13033{
13034 if (!inst.operands[0].present)
13035 inst.operands[0].imm = 0;
13036
13037 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13038 {
13039 constraint (inst.size_req == 2,
13040 _("immediate value out of range"));
13041 inst.instruction = THUMB_OP32 (inst.instruction);
13042 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13043 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13044 }
13045 else
13046 {
13047 inst.instruction = THUMB_OP16 (inst.instruction);
13048 inst.instruction |= inst.operands[0].imm;
13049 }
13050
13051 set_it_insn_type (NEUTRAL_IT_INSN);
13052}
13053
13054
c19d1205
ZW
13055static void
13056do_t_usat (void)
13057{
3a21c15a 13058 do_t_ssat_usat (0);
b99bd4ef
NC
13059}
13060
13061static void
c19d1205 13062do_t_usat16 (void)
b99bd4ef 13063{
fdfde340
JM
13064 unsigned Rd, Rn;
13065
13066 Rd = inst.operands[0].reg;
13067 Rn = inst.operands[2].reg;
13068
13069 reject_bad_reg (Rd);
13070 reject_bad_reg (Rn);
13071
13072 inst.instruction |= Rd << 8;
c19d1205 13073 inst.instruction |= inst.operands[1].imm;
fdfde340 13074 inst.instruction |= Rn << 16;
b99bd4ef 13075}
c19d1205 13076
5287ad62 13077/* Neon instruction encoder helpers. */
5f4273c7 13078
5287ad62 13079/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13080
5287ad62
JB
13081/* An "invalid" code for the following tables. */
13082#define N_INV -1u
13083
13084struct neon_tab_entry
b99bd4ef 13085{
5287ad62
JB
13086 unsigned integer;
13087 unsigned float_or_poly;
13088 unsigned scalar_or_imm;
13089};
5f4273c7 13090
5287ad62
JB
13091/* Map overloaded Neon opcodes to their respective encodings. */
13092#define NEON_ENC_TAB \
13093 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13094 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13095 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13096 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13097 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13098 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13099 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13100 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13101 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13102 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13103 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13104 /* Register variants of the following two instructions are encoded as
e07e6e58 13105 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13106 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13107 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13108 X(vfma, N_INV, 0x0000c10, N_INV), \
13109 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13110 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13111 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13112 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13113 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13114 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13115 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13116 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13117 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13118 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13119 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13120 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13121 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13122 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13123 X(vshl, 0x0000400, N_INV, 0x0800510), \
13124 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13125 X(vand, 0x0000110, N_INV, 0x0800030), \
13126 X(vbic, 0x0100110, N_INV, 0x0800030), \
13127 X(veor, 0x1000110, N_INV, N_INV), \
13128 X(vorn, 0x0300110, N_INV, 0x0800010), \
13129 X(vorr, 0x0200110, N_INV, 0x0800010), \
13130 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13131 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13132 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13133 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13134 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13135 X(vst1, 0x0000000, 0x0800000, N_INV), \
13136 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13137 X(vst2, 0x0000100, 0x0800100, N_INV), \
13138 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13139 X(vst3, 0x0000200, 0x0800200, N_INV), \
13140 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13141 X(vst4, 0x0000300, 0x0800300, N_INV), \
13142 X(vmovn, 0x1b20200, N_INV, N_INV), \
13143 X(vtrn, 0x1b20080, N_INV, N_INV), \
13144 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13145 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13146 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13147 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13148 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13149 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13150 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13151 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13152 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13153 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13154 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13155 X(vseleq, 0xe000a00, N_INV, N_INV), \
13156 X(vselvs, 0xe100a00, N_INV, N_INV), \
13157 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13158 X(vselgt, 0xe300a00, N_INV, N_INV), \
13159 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13160 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13161 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13162 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13163 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13164 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13165 X(sha3op, 0x2000c00, N_INV, N_INV), \
13166 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13167 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13168
13169enum neon_opc
13170{
13171#define X(OPC,I,F,S) N_MNEM_##OPC
13172NEON_ENC_TAB
13173#undef X
13174};
b99bd4ef 13175
5287ad62
JB
13176static const struct neon_tab_entry neon_enc_tab[] =
13177{
13178#define X(OPC,I,F,S) { (I), (F), (S) }
13179NEON_ENC_TAB
13180#undef X
13181};
b99bd4ef 13182
88714cb8
DG
13183/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13184#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13185#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13186#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13187#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13188#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13189#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13190#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13191#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13192#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13193#define NEON_ENC_SINGLE_(X) \
037e8744 13194 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13195#define NEON_ENC_DOUBLE_(X) \
037e8744 13196 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13197#define NEON_ENC_FPV8_(X) \
13198 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13199
88714cb8
DG
13200#define NEON_ENCODE(type, inst) \
13201 do \
13202 { \
13203 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13204 inst.is_neon = 1; \
13205 } \
13206 while (0)
13207
13208#define check_neon_suffixes \
13209 do \
13210 { \
13211 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13212 { \
13213 as_bad (_("invalid neon suffix for non neon instruction")); \
13214 return; \
13215 } \
13216 } \
13217 while (0)
13218
037e8744
JB
13219/* Define shapes for instruction operands. The following mnemonic characters
13220 are used in this table:
5287ad62 13221
037e8744 13222 F - VFP S<n> register
5287ad62
JB
13223 D - Neon D<n> register
13224 Q - Neon Q<n> register
13225 I - Immediate
13226 S - Scalar
13227 R - ARM register
13228 L - D<n> register list
5f4273c7 13229
037e8744
JB
13230 This table is used to generate various data:
13231 - enumerations of the form NS_DDR to be used as arguments to
13232 neon_select_shape.
13233 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13234 - a table used to drive neon_select_shape. */
b99bd4ef 13235
037e8744
JB
13236#define NEON_SHAPE_DEF \
13237 X(3, (D, D, D), DOUBLE), \
13238 X(3, (Q, Q, Q), QUAD), \
13239 X(3, (D, D, I), DOUBLE), \
13240 X(3, (Q, Q, I), QUAD), \
13241 X(3, (D, D, S), DOUBLE), \
13242 X(3, (Q, Q, S), QUAD), \
13243 X(2, (D, D), DOUBLE), \
13244 X(2, (Q, Q), QUAD), \
13245 X(2, (D, S), DOUBLE), \
13246 X(2, (Q, S), QUAD), \
13247 X(2, (D, R), DOUBLE), \
13248 X(2, (Q, R), QUAD), \
13249 X(2, (D, I), DOUBLE), \
13250 X(2, (Q, I), QUAD), \
13251 X(3, (D, L, D), DOUBLE), \
13252 X(2, (D, Q), MIXED), \
13253 X(2, (Q, D), MIXED), \
13254 X(3, (D, Q, I), MIXED), \
13255 X(3, (Q, D, I), MIXED), \
13256 X(3, (Q, D, D), MIXED), \
13257 X(3, (D, Q, Q), MIXED), \
13258 X(3, (Q, Q, D), MIXED), \
13259 X(3, (Q, D, S), MIXED), \
13260 X(3, (D, Q, S), MIXED), \
13261 X(4, (D, D, D, I), DOUBLE), \
13262 X(4, (Q, Q, Q, I), QUAD), \
13263 X(2, (F, F), SINGLE), \
13264 X(3, (F, F, F), SINGLE), \
13265 X(2, (F, I), SINGLE), \
13266 X(2, (F, D), MIXED), \
13267 X(2, (D, F), MIXED), \
13268 X(3, (F, F, I), MIXED), \
13269 X(4, (R, R, F, F), SINGLE), \
13270 X(4, (F, F, R, R), SINGLE), \
13271 X(3, (D, R, R), DOUBLE), \
13272 X(3, (R, R, D), DOUBLE), \
13273 X(2, (S, R), SINGLE), \
13274 X(2, (R, S), SINGLE), \
13275 X(2, (F, R), SINGLE), \
d54af2d0
RL
13276 X(2, (R, F), SINGLE), \
13277/* Half float shape supported so far. */\
13278 X (2, (H, D), MIXED), \
13279 X (2, (D, H), MIXED), \
13280 X (2, (H, F), MIXED), \
13281 X (2, (F, H), MIXED), \
13282 X (2, (H, H), HALF), \
13283 X (2, (H, R), HALF), \
13284 X (2, (R, H), HALF), \
13285 X (2, (H, I), HALF), \
13286 X (3, (H, H, H), HALF), \
13287 X (3, (H, F, I), MIXED), \
13288 X (3, (F, H, I), MIXED)
037e8744
JB
13289
13290#define S2(A,B) NS_##A##B
13291#define S3(A,B,C) NS_##A##B##C
13292#define S4(A,B,C,D) NS_##A##B##C##D
13293
13294#define X(N, L, C) S##N L
13295
5287ad62
JB
13296enum neon_shape
13297{
037e8744
JB
13298 NEON_SHAPE_DEF,
13299 NS_NULL
5287ad62 13300};
b99bd4ef 13301
037e8744
JB
13302#undef X
13303#undef S2
13304#undef S3
13305#undef S4
13306
13307enum neon_shape_class
13308{
d54af2d0 13309 SC_HALF,
037e8744
JB
13310 SC_SINGLE,
13311 SC_DOUBLE,
13312 SC_QUAD,
13313 SC_MIXED
13314};
13315
13316#define X(N, L, C) SC_##C
13317
13318static enum neon_shape_class neon_shape_class[] =
13319{
13320 NEON_SHAPE_DEF
13321};
13322
13323#undef X
13324
13325enum neon_shape_el
13326{
d54af2d0 13327 SE_H,
037e8744
JB
13328 SE_F,
13329 SE_D,
13330 SE_Q,
13331 SE_I,
13332 SE_S,
13333 SE_R,
13334 SE_L
13335};
13336
13337/* Register widths of above. */
13338static unsigned neon_shape_el_size[] =
13339{
d54af2d0 13340 16,
037e8744
JB
13341 32,
13342 64,
13343 128,
13344 0,
13345 32,
13346 32,
13347 0
13348};
13349
13350struct neon_shape_info
13351{
13352 unsigned els;
13353 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13354};
13355
13356#define S2(A,B) { SE_##A, SE_##B }
13357#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13358#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13359
13360#define X(N, L, C) { N, S##N L }
13361
13362static struct neon_shape_info neon_shape_tab[] =
13363{
13364 NEON_SHAPE_DEF
13365};
13366
13367#undef X
13368#undef S2
13369#undef S3
13370#undef S4
13371
5287ad62
JB
13372/* Bit masks used in type checking given instructions.
13373 'N_EQK' means the type must be the same as (or based on in some way) the key
13374 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13375 set, various other bits can be set as well in order to modify the meaning of
13376 the type constraint. */
13377
13378enum neon_type_mask
13379{
8e79c3df
CM
13380 N_S8 = 0x0000001,
13381 N_S16 = 0x0000002,
13382 N_S32 = 0x0000004,
13383 N_S64 = 0x0000008,
13384 N_U8 = 0x0000010,
13385 N_U16 = 0x0000020,
13386 N_U32 = 0x0000040,
13387 N_U64 = 0x0000080,
13388 N_I8 = 0x0000100,
13389 N_I16 = 0x0000200,
13390 N_I32 = 0x0000400,
13391 N_I64 = 0x0000800,
13392 N_8 = 0x0001000,
13393 N_16 = 0x0002000,
13394 N_32 = 0x0004000,
13395 N_64 = 0x0008000,
13396 N_P8 = 0x0010000,
13397 N_P16 = 0x0020000,
13398 N_F16 = 0x0040000,
13399 N_F32 = 0x0080000,
13400 N_F64 = 0x0100000,
4f51b4bd 13401 N_P64 = 0x0200000,
c921be7d
NC
13402 N_KEY = 0x1000000, /* Key element (main type specifier). */
13403 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13404 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13405 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13406 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13407 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13408 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13409 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13410 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13411 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13412 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13413 N_UTYP = 0,
4f51b4bd 13414 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13415};
13416
dcbf9037
JB
13417#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13418
5287ad62
JB
13419#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13420#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13421#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13422#define N_SUF_32 (N_SU_32 | N_F32)
13423#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13424#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
d54af2d0 13425#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13426
13427/* Pass this as the first type argument to neon_check_type to ignore types
13428 altogether. */
13429#define N_IGNORE_TYPE (N_KEY | N_EQK)
13430
037e8744
JB
13431/* Select a "shape" for the current instruction (describing register types or
13432 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13433 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13434 function of operand parsing, so this function doesn't need to be called.
13435 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13436
13437static enum neon_shape
037e8744 13438neon_select_shape (enum neon_shape shape, ...)
5287ad62 13439{
037e8744
JB
13440 va_list ap;
13441 enum neon_shape first_shape = shape;
5287ad62
JB
13442
13443 /* Fix missing optional operands. FIXME: we don't know at this point how
13444 many arguments we should have, so this makes the assumption that we have
13445 > 1. This is true of all current Neon opcodes, I think, but may not be
13446 true in the future. */
13447 if (!inst.operands[1].present)
13448 inst.operands[1] = inst.operands[0];
13449
037e8744 13450 va_start (ap, shape);
5f4273c7 13451
21d799b5 13452 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13453 {
13454 unsigned j;
13455 int matches = 1;
13456
13457 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13458 {
13459 if (!inst.operands[j].present)
13460 {
13461 matches = 0;
13462 break;
13463 }
13464
13465 switch (neon_shape_tab[shape].el[j])
13466 {
d54af2d0
RL
13467 /* If a .f16, .16, .u16, .s16 type specifier is given over
13468 a VFP single precision register operand, it's essentially
13469 means only half of the register is used.
13470
13471 If the type specifier is given after the mnemonics, the
13472 information is stored in inst.vectype. If the type specifier
13473 is given after register operand, the information is stored
13474 in inst.operands[].vectype.
13475
13476 When there is only one type specifier, and all the register
13477 operands are the same type of hardware register, the type
13478 specifier applies to all register operands.
13479
13480 If no type specifier is given, the shape is inferred from
13481 operand information.
13482
13483 for example:
13484 vadd.f16 s0, s1, s2: NS_HHH
13485 vabs.f16 s0, s1: NS_HH
13486 vmov.f16 s0, r1: NS_HR
13487 vmov.f16 r0, s1: NS_RH
13488 vcvt.f16 r0, s1: NS_RH
13489 vcvt.f16.s32 s2, s2, #29: NS_HFI
13490 vcvt.f16.s32 s2, s2: NS_HF
13491 */
13492 case SE_H:
13493 if (!(inst.operands[j].isreg
13494 && inst.operands[j].isvec
13495 && inst.operands[j].issingle
13496 && !inst.operands[j].isquad
13497 && ((inst.vectype.elems == 1
13498 && inst.vectype.el[0].size == 16)
13499 || (inst.vectype.elems > 1
13500 && inst.vectype.el[j].size == 16)
13501 || (inst.vectype.elems == 0
13502 && inst.operands[j].vectype.type != NT_invtype
13503 && inst.operands[j].vectype.size == 16))))
13504 matches = 0;
13505 break;
13506
477330fc
RM
13507 case SE_F:
13508 if (!(inst.operands[j].isreg
13509 && inst.operands[j].isvec
13510 && inst.operands[j].issingle
d54af2d0
RL
13511 && !inst.operands[j].isquad
13512 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13513 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13514 || (inst.vectype.elems == 0
13515 && (inst.operands[j].vectype.size == 32
13516 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13517 matches = 0;
13518 break;
13519
13520 case SE_D:
13521 if (!(inst.operands[j].isreg
13522 && inst.operands[j].isvec
13523 && !inst.operands[j].isquad
13524 && !inst.operands[j].issingle))
13525 matches = 0;
13526 break;
13527
13528 case SE_R:
13529 if (!(inst.operands[j].isreg
13530 && !inst.operands[j].isvec))
13531 matches = 0;
13532 break;
13533
13534 case SE_Q:
13535 if (!(inst.operands[j].isreg
13536 && inst.operands[j].isvec
13537 && inst.operands[j].isquad
13538 && !inst.operands[j].issingle))
13539 matches = 0;
13540 break;
13541
13542 case SE_I:
13543 if (!(!inst.operands[j].isreg
13544 && !inst.operands[j].isscalar))
13545 matches = 0;
13546 break;
13547
13548 case SE_S:
13549 if (!(!inst.operands[j].isreg
13550 && inst.operands[j].isscalar))
13551 matches = 0;
13552 break;
13553
13554 case SE_L:
13555 break;
13556 }
3fde54a2
JZ
13557 if (!matches)
13558 break;
477330fc 13559 }
ad6cec43
MGD
13560 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13561 /* We've matched all the entries in the shape table, and we don't
13562 have any left over operands which have not been matched. */
477330fc 13563 break;
037e8744 13564 }
5f4273c7 13565
037e8744 13566 va_end (ap);
5287ad62 13567
037e8744
JB
13568 if (shape == NS_NULL && first_shape != NS_NULL)
13569 first_error (_("invalid instruction shape"));
5287ad62 13570
037e8744
JB
13571 return shape;
13572}
5287ad62 13573
037e8744
JB
13574/* True if SHAPE is predominantly a quadword operation (most of the time, this
13575 means the Q bit should be set). */
13576
13577static int
13578neon_quad (enum neon_shape shape)
13579{
13580 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13581}
037e8744 13582
5287ad62
JB
13583static void
13584neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13585 unsigned *g_size)
5287ad62
JB
13586{
13587 /* Allow modification to be made to types which are constrained to be
13588 based on the key element, based on bits set alongside N_EQK. */
13589 if ((typebits & N_EQK) != 0)
13590 {
13591 if ((typebits & N_HLF) != 0)
13592 *g_size /= 2;
13593 else if ((typebits & N_DBL) != 0)
13594 *g_size *= 2;
13595 if ((typebits & N_SGN) != 0)
13596 *g_type = NT_signed;
13597 else if ((typebits & N_UNS) != 0)
477330fc 13598 *g_type = NT_unsigned;
5287ad62 13599 else if ((typebits & N_INT) != 0)
477330fc 13600 *g_type = NT_integer;
5287ad62 13601 else if ((typebits & N_FLT) != 0)
477330fc 13602 *g_type = NT_float;
dcbf9037 13603 else if ((typebits & N_SIZ) != 0)
477330fc 13604 *g_type = NT_untyped;
5287ad62
JB
13605 }
13606}
5f4273c7 13607
5287ad62
JB
13608/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13609 operand type, i.e. the single type specified in a Neon instruction when it
13610 is the only one given. */
13611
13612static struct neon_type_el
13613neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13614{
13615 struct neon_type_el dest = *key;
5f4273c7 13616
9c2799c2 13617 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13618
5287ad62
JB
13619 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13620
13621 return dest;
13622}
13623
13624/* Convert Neon type and size into compact bitmask representation. */
13625
13626static enum neon_type_mask
13627type_chk_of_el_type (enum neon_el_type type, unsigned size)
13628{
13629 switch (type)
13630 {
13631 case NT_untyped:
13632 switch (size)
477330fc
RM
13633 {
13634 case 8: return N_8;
13635 case 16: return N_16;
13636 case 32: return N_32;
13637 case 64: return N_64;
13638 default: ;
13639 }
5287ad62
JB
13640 break;
13641
13642 case NT_integer:
13643 switch (size)
477330fc
RM
13644 {
13645 case 8: return N_I8;
13646 case 16: return N_I16;
13647 case 32: return N_I32;
13648 case 64: return N_I64;
13649 default: ;
13650 }
5287ad62
JB
13651 break;
13652
13653 case NT_float:
037e8744 13654 switch (size)
477330fc 13655 {
8e79c3df 13656 case 16: return N_F16;
477330fc
RM
13657 case 32: return N_F32;
13658 case 64: return N_F64;
13659 default: ;
13660 }
5287ad62
JB
13661 break;
13662
13663 case NT_poly:
13664 switch (size)
477330fc
RM
13665 {
13666 case 8: return N_P8;
13667 case 16: return N_P16;
4f51b4bd 13668 case 64: return N_P64;
477330fc
RM
13669 default: ;
13670 }
5287ad62
JB
13671 break;
13672
13673 case NT_signed:
13674 switch (size)
477330fc
RM
13675 {
13676 case 8: return N_S8;
13677 case 16: return N_S16;
13678 case 32: return N_S32;
13679 case 64: return N_S64;
13680 default: ;
13681 }
5287ad62
JB
13682 break;
13683
13684 case NT_unsigned:
13685 switch (size)
477330fc
RM
13686 {
13687 case 8: return N_U8;
13688 case 16: return N_U16;
13689 case 32: return N_U32;
13690 case 64: return N_U64;
13691 default: ;
13692 }
5287ad62
JB
13693 break;
13694
13695 default: ;
13696 }
5f4273c7 13697
5287ad62
JB
13698 return N_UTYP;
13699}
13700
13701/* Convert compact Neon bitmask type representation to a type and size. Only
13702 handles the case where a single bit is set in the mask. */
13703
dcbf9037 13704static int
5287ad62 13705el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13706 enum neon_type_mask mask)
5287ad62 13707{
dcbf9037
JB
13708 if ((mask & N_EQK) != 0)
13709 return FAIL;
13710
5287ad62
JB
13711 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13712 *size = 8;
c70a8987 13713 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13714 *size = 16;
dcbf9037 13715 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13716 *size = 32;
4f51b4bd 13717 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13718 *size = 64;
dcbf9037
JB
13719 else
13720 return FAIL;
13721
5287ad62
JB
13722 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13723 *type = NT_signed;
dcbf9037 13724 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13725 *type = NT_unsigned;
dcbf9037 13726 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13727 *type = NT_integer;
dcbf9037 13728 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13729 *type = NT_untyped;
4f51b4bd 13730 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13731 *type = NT_poly;
d54af2d0 13732 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13733 *type = NT_float;
dcbf9037
JB
13734 else
13735 return FAIL;
5f4273c7 13736
dcbf9037 13737 return SUCCESS;
5287ad62
JB
13738}
13739
13740/* Modify a bitmask of allowed types. This is only needed for type
13741 relaxation. */
13742
13743static unsigned
13744modify_types_allowed (unsigned allowed, unsigned mods)
13745{
13746 unsigned size;
13747 enum neon_el_type type;
13748 unsigned destmask;
13749 int i;
5f4273c7 13750
5287ad62 13751 destmask = 0;
5f4273c7 13752
5287ad62
JB
13753 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13754 {
21d799b5 13755 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13756 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13757 {
13758 neon_modify_type_size (mods, &type, &size);
13759 destmask |= type_chk_of_el_type (type, size);
13760 }
5287ad62 13761 }
5f4273c7 13762
5287ad62
JB
13763 return destmask;
13764}
13765
13766/* Check type and return type classification.
13767 The manual states (paraphrase): If one datatype is given, it indicates the
13768 type given in:
13769 - the second operand, if there is one
13770 - the operand, if there is no second operand
13771 - the result, if there are no operands.
13772 This isn't quite good enough though, so we use a concept of a "key" datatype
13773 which is set on a per-instruction basis, which is the one which matters when
13774 only one data type is written.
13775 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13776 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13777
13778static struct neon_type_el
13779neon_check_type (unsigned els, enum neon_shape ns, ...)
13780{
13781 va_list ap;
13782 unsigned i, pass, key_el = 0;
13783 unsigned types[NEON_MAX_TYPE_ELS];
13784 enum neon_el_type k_type = NT_invtype;
13785 unsigned k_size = -1u;
13786 struct neon_type_el badtype = {NT_invtype, -1};
13787 unsigned key_allowed = 0;
13788
13789 /* Optional registers in Neon instructions are always (not) in operand 1.
13790 Fill in the missing operand here, if it was omitted. */
13791 if (els > 1 && !inst.operands[1].present)
13792 inst.operands[1] = inst.operands[0];
13793
13794 /* Suck up all the varargs. */
13795 va_start (ap, ns);
13796 for (i = 0; i < els; i++)
13797 {
13798 unsigned thisarg = va_arg (ap, unsigned);
13799 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13800 {
13801 va_end (ap);
13802 return badtype;
13803 }
5287ad62
JB
13804 types[i] = thisarg;
13805 if ((thisarg & N_KEY) != 0)
477330fc 13806 key_el = i;
5287ad62
JB
13807 }
13808 va_end (ap);
13809
dcbf9037
JB
13810 if (inst.vectype.elems > 0)
13811 for (i = 0; i < els; i++)
13812 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13813 {
13814 first_error (_("types specified in both the mnemonic and operands"));
13815 return badtype;
13816 }
dcbf9037 13817
5287ad62
JB
13818 /* Duplicate inst.vectype elements here as necessary.
13819 FIXME: No idea if this is exactly the same as the ARM assembler,
13820 particularly when an insn takes one register and one non-register
13821 operand. */
13822 if (inst.vectype.elems == 1 && els > 1)
13823 {
13824 unsigned j;
13825 inst.vectype.elems = els;
13826 inst.vectype.el[key_el] = inst.vectype.el[0];
13827 for (j = 0; j < els; j++)
477330fc
RM
13828 if (j != key_el)
13829 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13830 types[j]);
dcbf9037
JB
13831 }
13832 else if (inst.vectype.elems == 0 && els > 0)
13833 {
13834 unsigned j;
13835 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13836 after each operand. We allow some flexibility here; as long as the
13837 "key" operand has a type, we can infer the others. */
dcbf9037 13838 for (j = 0; j < els; j++)
477330fc
RM
13839 if (inst.operands[j].vectype.type != NT_invtype)
13840 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13841
13842 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13843 {
13844 for (j = 0; j < els; j++)
13845 if (inst.operands[j].vectype.type == NT_invtype)
13846 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13847 types[j]);
13848 }
dcbf9037 13849 else
477330fc
RM
13850 {
13851 first_error (_("operand types can't be inferred"));
13852 return badtype;
13853 }
5287ad62
JB
13854 }
13855 else if (inst.vectype.elems != els)
13856 {
dcbf9037 13857 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13858 return badtype;
13859 }
13860
13861 for (pass = 0; pass < 2; pass++)
13862 {
13863 for (i = 0; i < els; i++)
477330fc
RM
13864 {
13865 unsigned thisarg = types[i];
13866 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13867 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13868 enum neon_el_type g_type = inst.vectype.el[i].type;
13869 unsigned g_size = inst.vectype.el[i].size;
13870
13871 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13872 integer types if sign-specific variants are unavailable. */
477330fc 13873 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13874 && (types_allowed & N_SU_ALL) == 0)
13875 g_type = NT_integer;
13876
477330fc 13877 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13878 them. Some instructions only care about signs for some element
13879 sizes, so handle that properly. */
477330fc 13880 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13881 && ((g_size == 8 && (types_allowed & N_8) != 0)
13882 || (g_size == 16 && (types_allowed & N_16) != 0)
13883 || (g_size == 32 && (types_allowed & N_32) != 0)
13884 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13885 g_type = NT_untyped;
13886
477330fc
RM
13887 if (pass == 0)
13888 {
13889 if ((thisarg & N_KEY) != 0)
13890 {
13891 k_type = g_type;
13892 k_size = g_size;
13893 key_allowed = thisarg & ~N_KEY;
13894 }
13895 }
13896 else
13897 {
13898 if ((thisarg & N_VFP) != 0)
13899 {
13900 enum neon_shape_el regshape;
13901 unsigned regwidth, match;
99b253c5
NC
13902
13903 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13904 if (ns == NS_NULL)
13905 {
13906 first_error (_("invalid instruction shape"));
13907 return badtype;
13908 }
477330fc
RM
13909 regshape = neon_shape_tab[ns].el[i];
13910 regwidth = neon_shape_el_size[regshape];
13911
13912 /* In VFP mode, operands must match register widths. If we
13913 have a key operand, use its width, else use the width of
13914 the current operand. */
13915 if (k_size != -1u)
13916 match = k_size;
13917 else
13918 match = g_size;
13919
9db2f6b4
RL
13920 /* FP16 will use a single precision register. */
13921 if (regwidth == 32 && match == 16)
13922 {
13923 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13924 match = regwidth;
13925 else
13926 {
13927 inst.error = _(BAD_FP16);
13928 return badtype;
13929 }
13930 }
13931
477330fc
RM
13932 if (regwidth != match)
13933 {
13934 first_error (_("operand size must match register width"));
13935 return badtype;
13936 }
13937 }
13938
13939 if ((thisarg & N_EQK) == 0)
13940 {
13941 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13942
13943 if ((given_type & types_allowed) == 0)
13944 {
13945 first_error (_("bad type in Neon instruction"));
13946 return badtype;
13947 }
13948 }
13949 else
13950 {
13951 enum neon_el_type mod_k_type = k_type;
13952 unsigned mod_k_size = k_size;
13953 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13954 if (g_type != mod_k_type || g_size != mod_k_size)
13955 {
13956 first_error (_("inconsistent types in Neon instruction"));
13957 return badtype;
13958 }
13959 }
13960 }
13961 }
5287ad62
JB
13962 }
13963
13964 return inst.vectype.el[key_el];
13965}
13966
037e8744 13967/* Neon-style VFP instruction forwarding. */
5287ad62 13968
037e8744
JB
13969/* Thumb VFP instructions have 0xE in the condition field. */
13970
13971static void
13972do_vfp_cond_or_thumb (void)
5287ad62 13973{
88714cb8
DG
13974 inst.is_neon = 1;
13975
5287ad62 13976 if (thumb_mode)
037e8744 13977 inst.instruction |= 0xe0000000;
5287ad62 13978 else
037e8744 13979 inst.instruction |= inst.cond << 28;
5287ad62
JB
13980}
13981
037e8744
JB
13982/* Look up and encode a simple mnemonic, for use as a helper function for the
13983 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13984 etc. It is assumed that operand parsing has already been done, and that the
13985 operands are in the form expected by the given opcode (this isn't necessarily
13986 the same as the form in which they were parsed, hence some massaging must
13987 take place before this function is called).
13988 Checks current arch version against that in the looked-up opcode. */
5287ad62 13989
037e8744
JB
13990static void
13991do_vfp_nsyn_opcode (const char *opname)
5287ad62 13992{
037e8744 13993 const struct asm_opcode *opcode;
5f4273c7 13994
21d799b5 13995 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13996
037e8744
JB
13997 if (!opcode)
13998 abort ();
5287ad62 13999
037e8744 14000 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14001 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14002 _(BAD_FPU));
5287ad62 14003
88714cb8
DG
14004 inst.is_neon = 1;
14005
037e8744
JB
14006 if (thumb_mode)
14007 {
14008 inst.instruction = opcode->tvalue;
14009 opcode->tencode ();
14010 }
14011 else
14012 {
14013 inst.instruction = (inst.cond << 28) | opcode->avalue;
14014 opcode->aencode ();
14015 }
14016}
5287ad62
JB
14017
14018static void
037e8744 14019do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14020{
037e8744
JB
14021 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14022
9db2f6b4 14023 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14024 {
14025 if (is_add)
477330fc 14026 do_vfp_nsyn_opcode ("fadds");
037e8744 14027 else
477330fc 14028 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14029
14030 /* ARMv8.2 fp16 instruction. */
14031 if (rs == NS_HHH)
14032 do_scalar_fp16_v82_encode ();
037e8744
JB
14033 }
14034 else
14035 {
14036 if (is_add)
477330fc 14037 do_vfp_nsyn_opcode ("faddd");
037e8744 14038 else
477330fc 14039 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14040 }
14041}
14042
14043/* Check operand types to see if this is a VFP instruction, and if so call
14044 PFN (). */
14045
14046static int
14047try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14048{
14049 enum neon_shape rs;
14050 struct neon_type_el et;
14051
14052 switch (args)
14053 {
14054 case 2:
9db2f6b4
RL
14055 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14056 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14057 break;
5f4273c7 14058
037e8744 14059 case 3:
9db2f6b4
RL
14060 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14061 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14062 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14063 break;
14064
14065 default:
14066 abort ();
14067 }
14068
14069 if (et.type != NT_invtype)
14070 {
14071 pfn (rs);
14072 return SUCCESS;
14073 }
037e8744 14074
99b253c5 14075 inst.error = NULL;
037e8744
JB
14076 return FAIL;
14077}
14078
14079static void
14080do_vfp_nsyn_mla_mls (enum neon_shape rs)
14081{
14082 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14083
9db2f6b4 14084 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14085 {
14086 if (is_mla)
477330fc 14087 do_vfp_nsyn_opcode ("fmacs");
037e8744 14088 else
477330fc 14089 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14090
14091 /* ARMv8.2 fp16 instruction. */
14092 if (rs == NS_HHH)
14093 do_scalar_fp16_v82_encode ();
037e8744
JB
14094 }
14095 else
14096 {
14097 if (is_mla)
477330fc 14098 do_vfp_nsyn_opcode ("fmacd");
037e8744 14099 else
477330fc 14100 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14101 }
14102}
14103
62f3b8c8
PB
14104static void
14105do_vfp_nsyn_fma_fms (enum neon_shape rs)
14106{
14107 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14108
9db2f6b4 14109 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14110 {
14111 if (is_fma)
477330fc 14112 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14113 else
477330fc 14114 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14115
14116 /* ARMv8.2 fp16 instruction. */
14117 if (rs == NS_HHH)
14118 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14119 }
14120 else
14121 {
14122 if (is_fma)
477330fc 14123 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14124 else
477330fc 14125 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14126 }
14127}
14128
037e8744
JB
14129static void
14130do_vfp_nsyn_mul (enum neon_shape rs)
14131{
9db2f6b4
RL
14132 if (rs == NS_FFF || rs == NS_HHH)
14133 {
14134 do_vfp_nsyn_opcode ("fmuls");
14135
14136 /* ARMv8.2 fp16 instruction. */
14137 if (rs == NS_HHH)
14138 do_scalar_fp16_v82_encode ();
14139 }
037e8744
JB
14140 else
14141 do_vfp_nsyn_opcode ("fmuld");
14142}
14143
14144static void
14145do_vfp_nsyn_abs_neg (enum neon_shape rs)
14146{
14147 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14148 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14149
9db2f6b4 14150 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14151 {
14152 if (is_neg)
477330fc 14153 do_vfp_nsyn_opcode ("fnegs");
037e8744 14154 else
477330fc 14155 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14156
14157 /* ARMv8.2 fp16 instruction. */
14158 if (rs == NS_HH)
14159 do_scalar_fp16_v82_encode ();
037e8744
JB
14160 }
14161 else
14162 {
14163 if (is_neg)
477330fc 14164 do_vfp_nsyn_opcode ("fnegd");
037e8744 14165 else
477330fc 14166 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14167 }
14168}
14169
14170/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14171 insns belong to Neon, and are handled elsewhere. */
14172
14173static void
14174do_vfp_nsyn_ldm_stm (int is_dbmode)
14175{
14176 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14177 if (is_ldm)
14178 {
14179 if (is_dbmode)
477330fc 14180 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14181 else
477330fc 14182 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14183 }
14184 else
14185 {
14186 if (is_dbmode)
477330fc 14187 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14188 else
477330fc 14189 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14190 }
14191}
14192
037e8744
JB
14193static void
14194do_vfp_nsyn_sqrt (void)
14195{
9db2f6b4
RL
14196 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14197 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14198
9db2f6b4
RL
14199 if (rs == NS_FF || rs == NS_HH)
14200 {
14201 do_vfp_nsyn_opcode ("fsqrts");
14202
14203 /* ARMv8.2 fp16 instruction. */
14204 if (rs == NS_HH)
14205 do_scalar_fp16_v82_encode ();
14206 }
037e8744
JB
14207 else
14208 do_vfp_nsyn_opcode ("fsqrtd");
14209}
14210
14211static void
14212do_vfp_nsyn_div (void)
14213{
9db2f6b4 14214 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14215 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14216 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14217
9db2f6b4
RL
14218 if (rs == NS_FFF || rs == NS_HHH)
14219 {
14220 do_vfp_nsyn_opcode ("fdivs");
14221
14222 /* ARMv8.2 fp16 instruction. */
14223 if (rs == NS_HHH)
14224 do_scalar_fp16_v82_encode ();
14225 }
037e8744
JB
14226 else
14227 do_vfp_nsyn_opcode ("fdivd");
14228}
14229
14230static void
14231do_vfp_nsyn_nmul (void)
14232{
9db2f6b4 14233 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14234 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14235 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14236
9db2f6b4 14237 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14238 {
88714cb8 14239 NEON_ENCODE (SINGLE, inst);
037e8744 14240 do_vfp_sp_dyadic ();
9db2f6b4
RL
14241
14242 /* ARMv8.2 fp16 instruction. */
14243 if (rs == NS_HHH)
14244 do_scalar_fp16_v82_encode ();
037e8744
JB
14245 }
14246 else
14247 {
88714cb8 14248 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14249 do_vfp_dp_rd_rn_rm ();
14250 }
14251 do_vfp_cond_or_thumb ();
9db2f6b4 14252
037e8744
JB
14253}
14254
14255static void
14256do_vfp_nsyn_cmp (void)
14257{
9db2f6b4 14258 enum neon_shape rs;
037e8744
JB
14259 if (inst.operands[1].isreg)
14260 {
9db2f6b4
RL
14261 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14262 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14263
9db2f6b4 14264 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14265 {
14266 NEON_ENCODE (SINGLE, inst);
14267 do_vfp_sp_monadic ();
14268 }
037e8744 14269 else
477330fc
RM
14270 {
14271 NEON_ENCODE (DOUBLE, inst);
14272 do_vfp_dp_rd_rm ();
14273 }
037e8744
JB
14274 }
14275 else
14276 {
9db2f6b4
RL
14277 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14278 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14279
14280 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14281 {
14282 case N_MNEM_vcmp:
14283 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14284 break;
14285 case N_MNEM_vcmpe:
14286 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14287 break;
14288 default:
14289 abort ();
14290 }
5f4273c7 14291
9db2f6b4 14292 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14293 {
14294 NEON_ENCODE (SINGLE, inst);
14295 do_vfp_sp_compare_z ();
14296 }
037e8744 14297 else
477330fc
RM
14298 {
14299 NEON_ENCODE (DOUBLE, inst);
14300 do_vfp_dp_rd ();
14301 }
037e8744
JB
14302 }
14303 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14304
14305 /* ARMv8.2 fp16 instruction. */
14306 if (rs == NS_HI || rs == NS_HH)
14307 do_scalar_fp16_v82_encode ();
037e8744
JB
14308}
14309
14310static void
14311nsyn_insert_sp (void)
14312{
14313 inst.operands[1] = inst.operands[0];
14314 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14315 inst.operands[0].reg = REG_SP;
037e8744
JB
14316 inst.operands[0].isreg = 1;
14317 inst.operands[0].writeback = 1;
14318 inst.operands[0].present = 1;
14319}
14320
14321static void
14322do_vfp_nsyn_push (void)
14323{
14324 nsyn_insert_sp ();
14325 if (inst.operands[1].issingle)
14326 do_vfp_nsyn_opcode ("fstmdbs");
14327 else
14328 do_vfp_nsyn_opcode ("fstmdbd");
14329}
14330
14331static void
14332do_vfp_nsyn_pop (void)
14333{
14334 nsyn_insert_sp ();
14335 if (inst.operands[1].issingle)
22b5b651 14336 do_vfp_nsyn_opcode ("fldmias");
037e8744 14337 else
22b5b651 14338 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14339}
14340
14341/* Fix up Neon data-processing instructions, ORing in the correct bits for
14342 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14343
88714cb8
DG
14344static void
14345neon_dp_fixup (struct arm_it* insn)
037e8744 14346{
88714cb8
DG
14347 unsigned int i = insn->instruction;
14348 insn->is_neon = 1;
14349
037e8744
JB
14350 if (thumb_mode)
14351 {
14352 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14353 if (i & (1 << 24))
477330fc 14354 i |= 1 << 28;
5f4273c7 14355
037e8744 14356 i &= ~(1 << 24);
5f4273c7 14357
037e8744
JB
14358 i |= 0xef000000;
14359 }
14360 else
14361 i |= 0xf2000000;
5f4273c7 14362
88714cb8 14363 insn->instruction = i;
037e8744
JB
14364}
14365
14366/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14367 (0, 1, 2, 3). */
14368
14369static unsigned
14370neon_logbits (unsigned x)
14371{
14372 return ffs (x) - 4;
14373}
14374
14375#define LOW4(R) ((R) & 0xf)
14376#define HI1(R) (((R) >> 4) & 1)
14377
14378/* Encode insns with bit pattern:
14379
14380 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14381 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14382
037e8744
JB
14383 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14384 different meaning for some instruction. */
14385
14386static void
14387neon_three_same (int isquad, int ubit, int size)
14388{
14389 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14390 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14391 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14392 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14393 inst.instruction |= LOW4 (inst.operands[2].reg);
14394 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14395 inst.instruction |= (isquad != 0) << 6;
14396 inst.instruction |= (ubit != 0) << 24;
14397 if (size != -1)
14398 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14399
88714cb8 14400 neon_dp_fixup (&inst);
037e8744
JB
14401}
14402
14403/* Encode instructions of the form:
14404
14405 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14406 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14407
14408 Don't write size if SIZE == -1. */
14409
14410static void
14411neon_two_same (int qbit, int ubit, int size)
14412{
14413 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14414 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14415 inst.instruction |= LOW4 (inst.operands[1].reg);
14416 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14417 inst.instruction |= (qbit != 0) << 6;
14418 inst.instruction |= (ubit != 0) << 24;
14419
14420 if (size != -1)
14421 inst.instruction |= neon_logbits (size) << 18;
14422
88714cb8 14423 neon_dp_fixup (&inst);
5287ad62
JB
14424}
14425
14426/* Neon instruction encoders, in approximate order of appearance. */
14427
14428static void
14429do_neon_dyadic_i_su (void)
14430{
037e8744 14431 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14432 struct neon_type_el et = neon_check_type (3, rs,
14433 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14434 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14435}
14436
14437static void
14438do_neon_dyadic_i64_su (void)
14439{
037e8744 14440 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14441 struct neon_type_el et = neon_check_type (3, rs,
14442 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14443 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14444}
14445
14446static void
14447neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14448 unsigned immbits)
5287ad62
JB
14449{
14450 unsigned size = et.size >> 3;
14451 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14452 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14453 inst.instruction |= LOW4 (inst.operands[1].reg);
14454 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14455 inst.instruction |= (isquad != 0) << 6;
14456 inst.instruction |= immbits << 16;
14457 inst.instruction |= (size >> 3) << 7;
14458 inst.instruction |= (size & 0x7) << 19;
14459 if (write_ubit)
14460 inst.instruction |= (uval != 0) << 24;
14461
88714cb8 14462 neon_dp_fixup (&inst);
5287ad62
JB
14463}
14464
14465static void
14466do_neon_shl_imm (void)
14467{
14468 if (!inst.operands[2].isreg)
14469 {
037e8744 14470 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14471 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14472 int imm = inst.operands[2].imm;
14473
14474 constraint (imm < 0 || (unsigned)imm >= et.size,
14475 _("immediate out of range for shift"));
88714cb8 14476 NEON_ENCODE (IMMED, inst);
cb3b1e65 14477 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14478 }
14479 else
14480 {
037e8744 14481 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14482 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14483 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14484 unsigned int tmp;
14485
14486 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14487 vshl.xx Dd, Dm, Dn
14488 whereas other 3-register operations encoded by neon_three_same have
14489 syntax like:
14490 vadd.xx Dd, Dn, Dm
14491 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14492 here. */
627907b7
JB
14493 tmp = inst.operands[2].reg;
14494 inst.operands[2].reg = inst.operands[1].reg;
14495 inst.operands[1].reg = tmp;
88714cb8 14496 NEON_ENCODE (INTEGER, inst);
037e8744 14497 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14498 }
14499}
14500
14501static void
14502do_neon_qshl_imm (void)
14503{
14504 if (!inst.operands[2].isreg)
14505 {
037e8744 14506 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14507 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14508 int imm = inst.operands[2].imm;
627907b7 14509
cb3b1e65
JB
14510 constraint (imm < 0 || (unsigned)imm >= et.size,
14511 _("immediate out of range for shift"));
88714cb8 14512 NEON_ENCODE (IMMED, inst);
cb3b1e65 14513 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14514 }
14515 else
14516 {
037e8744 14517 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14518 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14519 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14520 unsigned int tmp;
14521
14522 /* See note in do_neon_shl_imm. */
14523 tmp = inst.operands[2].reg;
14524 inst.operands[2].reg = inst.operands[1].reg;
14525 inst.operands[1].reg = tmp;
88714cb8 14526 NEON_ENCODE (INTEGER, inst);
037e8744 14527 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14528 }
14529}
14530
627907b7
JB
14531static void
14532do_neon_rshl (void)
14533{
14534 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14535 struct neon_type_el et = neon_check_type (3, rs,
14536 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14537 unsigned int tmp;
14538
14539 tmp = inst.operands[2].reg;
14540 inst.operands[2].reg = inst.operands[1].reg;
14541 inst.operands[1].reg = tmp;
14542 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14543}
14544
5287ad62
JB
14545static int
14546neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14547{
036dc3f7
PB
14548 /* Handle .I8 pseudo-instructions. */
14549 if (size == 8)
5287ad62 14550 {
5287ad62 14551 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14552 FIXME is this the intended semantics? There doesn't seem much point in
14553 accepting .I8 if so. */
5287ad62
JB
14554 immediate |= immediate << 8;
14555 size = 16;
036dc3f7
PB
14556 }
14557
14558 if (size >= 32)
14559 {
14560 if (immediate == (immediate & 0x000000ff))
14561 {
14562 *immbits = immediate;
14563 return 0x1;
14564 }
14565 else if (immediate == (immediate & 0x0000ff00))
14566 {
14567 *immbits = immediate >> 8;
14568 return 0x3;
14569 }
14570 else if (immediate == (immediate & 0x00ff0000))
14571 {
14572 *immbits = immediate >> 16;
14573 return 0x5;
14574 }
14575 else if (immediate == (immediate & 0xff000000))
14576 {
14577 *immbits = immediate >> 24;
14578 return 0x7;
14579 }
14580 if ((immediate & 0xffff) != (immediate >> 16))
14581 goto bad_immediate;
14582 immediate &= 0xffff;
5287ad62
JB
14583 }
14584
14585 if (immediate == (immediate & 0x000000ff))
14586 {
14587 *immbits = immediate;
036dc3f7 14588 return 0x9;
5287ad62
JB
14589 }
14590 else if (immediate == (immediate & 0x0000ff00))
14591 {
14592 *immbits = immediate >> 8;
036dc3f7 14593 return 0xb;
5287ad62
JB
14594 }
14595
14596 bad_immediate:
dcbf9037 14597 first_error (_("immediate value out of range"));
5287ad62
JB
14598 return FAIL;
14599}
14600
5287ad62
JB
14601static void
14602do_neon_logic (void)
14603{
14604 if (inst.operands[2].present && inst.operands[2].isreg)
14605 {
037e8744 14606 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14607 neon_check_type (3, rs, N_IGNORE_TYPE);
14608 /* U bit and size field were set as part of the bitmask. */
88714cb8 14609 NEON_ENCODE (INTEGER, inst);
037e8744 14610 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14611 }
14612 else
14613 {
4316f0d2
DG
14614 const int three_ops_form = (inst.operands[2].present
14615 && !inst.operands[2].isreg);
14616 const int immoperand = (three_ops_form ? 2 : 1);
14617 enum neon_shape rs = (three_ops_form
14618 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14619 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14620 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14621 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14622 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14623 unsigned immbits;
14624 int cmode;
5f4273c7 14625
5287ad62 14626 if (et.type == NT_invtype)
477330fc 14627 return;
5f4273c7 14628
4316f0d2
DG
14629 if (three_ops_form)
14630 constraint (inst.operands[0].reg != inst.operands[1].reg,
14631 _("first and second operands shall be the same register"));
14632
88714cb8 14633 NEON_ENCODE (IMMED, inst);
5287ad62 14634
4316f0d2 14635 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14636 if (et.size == 64)
14637 {
14638 /* .i64 is a pseudo-op, so the immediate must be a repeating
14639 pattern. */
4316f0d2
DG
14640 if (immbits != (inst.operands[immoperand].regisimm ?
14641 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14642 {
14643 /* Set immbits to an invalid constant. */
14644 immbits = 0xdeadbeef;
14645 }
14646 }
14647
5287ad62 14648 switch (opcode)
477330fc
RM
14649 {
14650 case N_MNEM_vbic:
14651 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14652 break;
14653
14654 case N_MNEM_vorr:
14655 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14656 break;
14657
14658 case N_MNEM_vand:
14659 /* Pseudo-instruction for VBIC. */
14660 neon_invert_size (&immbits, 0, et.size);
14661 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14662 break;
14663
14664 case N_MNEM_vorn:
14665 /* Pseudo-instruction for VORR. */
14666 neon_invert_size (&immbits, 0, et.size);
14667 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14668 break;
14669
14670 default:
14671 abort ();
14672 }
5287ad62
JB
14673
14674 if (cmode == FAIL)
477330fc 14675 return;
5287ad62 14676
037e8744 14677 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14678 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14679 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14680 inst.instruction |= cmode << 8;
14681 neon_write_immbits (immbits);
5f4273c7 14682
88714cb8 14683 neon_dp_fixup (&inst);
5287ad62
JB
14684 }
14685}
14686
14687static void
14688do_neon_bitfield (void)
14689{
037e8744 14690 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14691 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14692 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14693}
14694
14695static void
dcbf9037 14696neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14697 unsigned destbits)
5287ad62 14698{
037e8744 14699 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14700 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14701 types | N_KEY);
5287ad62
JB
14702 if (et.type == NT_float)
14703 {
88714cb8 14704 NEON_ENCODE (FLOAT, inst);
037e8744 14705 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14706 }
14707 else
14708 {
88714cb8 14709 NEON_ENCODE (INTEGER, inst);
037e8744 14710 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14711 }
14712}
14713
14714static void
14715do_neon_dyadic_if_su (void)
14716{
dcbf9037 14717 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14718}
14719
14720static void
14721do_neon_dyadic_if_su_d (void)
14722{
14723 /* This version only allow D registers, but that constraint is enforced during
14724 operand parsing so we don't need to do anything extra here. */
dcbf9037 14725 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14726}
14727
5287ad62
JB
14728static void
14729do_neon_dyadic_if_i_d (void)
14730{
428e3f1f
PB
14731 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14732 affected if we specify unsigned args. */
14733 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14734}
14735
037e8744
JB
14736enum vfp_or_neon_is_neon_bits
14737{
14738 NEON_CHECK_CC = 1,
73924fbc
MGD
14739 NEON_CHECK_ARCH = 2,
14740 NEON_CHECK_ARCH8 = 4
037e8744
JB
14741};
14742
14743/* Call this function if an instruction which may have belonged to the VFP or
14744 Neon instruction sets, but turned out to be a Neon instruction (due to the
14745 operand types involved, etc.). We have to check and/or fix-up a couple of
14746 things:
14747
14748 - Make sure the user hasn't attempted to make a Neon instruction
14749 conditional.
14750 - Alter the value in the condition code field if necessary.
14751 - Make sure that the arch supports Neon instructions.
14752
14753 Which of these operations take place depends on bits from enum
14754 vfp_or_neon_is_neon_bits.
14755
14756 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14757 current instruction's condition is COND_ALWAYS, the condition field is
14758 changed to inst.uncond_value. This is necessary because instructions shared
14759 between VFP and Neon may be conditional for the VFP variants only, and the
14760 unconditional Neon version must have, e.g., 0xF in the condition field. */
14761
14762static int
14763vfp_or_neon_is_neon (unsigned check)
14764{
14765 /* Conditions are always legal in Thumb mode (IT blocks). */
14766 if (!thumb_mode && (check & NEON_CHECK_CC))
14767 {
14768 if (inst.cond != COND_ALWAYS)
477330fc
RM
14769 {
14770 first_error (_(BAD_COND));
14771 return FAIL;
14772 }
037e8744 14773 if (inst.uncond_value != -1)
477330fc 14774 inst.instruction |= inst.uncond_value << 28;
037e8744 14775 }
5f4273c7 14776
037e8744 14777 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14778 && !mark_feature_used (&fpu_neon_ext_v1))
14779 {
14780 first_error (_(BAD_FPU));
14781 return FAIL;
14782 }
14783
14784 if ((check & NEON_CHECK_ARCH8)
14785 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14786 {
14787 first_error (_(BAD_FPU));
14788 return FAIL;
14789 }
5f4273c7 14790
037e8744
JB
14791 return SUCCESS;
14792}
14793
5287ad62
JB
14794static void
14795do_neon_addsub_if_i (void)
14796{
037e8744
JB
14797 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14798 return;
14799
14800 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14801 return;
14802
5287ad62
JB
14803 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14804 affected if we specify unsigned args. */
dcbf9037 14805 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14806}
14807
14808/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14809 result to be:
14810 V<op> A,B (A is operand 0, B is operand 2)
14811 to mean:
14812 V<op> A,B,A
14813 not:
14814 V<op> A,B,B
14815 so handle that case specially. */
14816
14817static void
14818neon_exchange_operands (void)
14819{
14820 void *scratch = alloca (sizeof (inst.operands[0]));
14821 if (inst.operands[1].present)
14822 {
14823 /* Swap operands[1] and operands[2]. */
14824 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14825 inst.operands[1] = inst.operands[2];
14826 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14827 }
14828 else
14829 {
14830 inst.operands[1] = inst.operands[2];
14831 inst.operands[2] = inst.operands[0];
14832 }
14833}
14834
14835static void
14836neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14837{
14838 if (inst.operands[2].isreg)
14839 {
14840 if (invert)
477330fc 14841 neon_exchange_operands ();
dcbf9037 14842 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14843 }
14844 else
14845 {
037e8744 14846 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14847 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14848 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14849
88714cb8 14850 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14851 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14852 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14853 inst.instruction |= LOW4 (inst.operands[1].reg);
14854 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14855 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14856 inst.instruction |= (et.type == NT_float) << 10;
14857 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14858
88714cb8 14859 neon_dp_fixup (&inst);
5287ad62
JB
14860 }
14861}
14862
14863static void
14864do_neon_cmp (void)
14865{
14866 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14867}
14868
14869static void
14870do_neon_cmp_inv (void)
14871{
14872 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14873}
14874
14875static void
14876do_neon_ceq (void)
14877{
14878 neon_compare (N_IF_32, N_IF_32, FALSE);
14879}
14880
14881/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14882 scalars, which are encoded in 5 bits, M : Rm.
14883 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14884 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14885 index in M. */
14886
14887static unsigned
14888neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14889{
dcbf9037
JB
14890 unsigned regno = NEON_SCALAR_REG (scalar);
14891 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14892
14893 switch (elsize)
14894 {
14895 case 16:
14896 if (regno > 7 || elno > 3)
477330fc 14897 goto bad_scalar;
5287ad62 14898 return regno | (elno << 3);
5f4273c7 14899
5287ad62
JB
14900 case 32:
14901 if (regno > 15 || elno > 1)
477330fc 14902 goto bad_scalar;
5287ad62
JB
14903 return regno | (elno << 4);
14904
14905 default:
14906 bad_scalar:
dcbf9037 14907 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14908 }
14909
14910 return 0;
14911}
14912
14913/* Encode multiply / multiply-accumulate scalar instructions. */
14914
14915static void
14916neon_mul_mac (struct neon_type_el et, int ubit)
14917{
dcbf9037
JB
14918 unsigned scalar;
14919
14920 /* Give a more helpful error message if we have an invalid type. */
14921 if (et.type == NT_invtype)
14922 return;
5f4273c7 14923
dcbf9037 14924 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14925 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14926 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14927 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14928 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14929 inst.instruction |= LOW4 (scalar);
14930 inst.instruction |= HI1 (scalar) << 5;
14931 inst.instruction |= (et.type == NT_float) << 8;
14932 inst.instruction |= neon_logbits (et.size) << 20;
14933 inst.instruction |= (ubit != 0) << 24;
14934
88714cb8 14935 neon_dp_fixup (&inst);
5287ad62
JB
14936}
14937
14938static void
14939do_neon_mac_maybe_scalar (void)
14940{
037e8744
JB
14941 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14942 return;
14943
14944 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14945 return;
14946
5287ad62
JB
14947 if (inst.operands[2].isscalar)
14948 {
037e8744 14949 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14950 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14951 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14952 NEON_ENCODE (SCALAR, inst);
037e8744 14953 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14954 }
14955 else
428e3f1f
PB
14956 {
14957 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14958 affected if we specify unsigned args. */
14959 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14960 }
5287ad62
JB
14961}
14962
62f3b8c8
PB
14963static void
14964do_neon_fmac (void)
14965{
14966 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14967 return;
14968
14969 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14970 return;
14971
14972 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14973}
14974
5287ad62
JB
14975static void
14976do_neon_tst (void)
14977{
037e8744 14978 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14979 struct neon_type_el et = neon_check_type (3, rs,
14980 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14981 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14982}
14983
14984/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14985 same types as the MAC equivalents. The polynomial type for this instruction
14986 is encoded the same as the integer type. */
14987
14988static void
14989do_neon_mul (void)
14990{
037e8744
JB
14991 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14992 return;
14993
14994 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14995 return;
14996
5287ad62
JB
14997 if (inst.operands[2].isscalar)
14998 do_neon_mac_maybe_scalar ();
14999 else
dcbf9037 15000 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
15001}
15002
15003static void
15004do_neon_qdmulh (void)
15005{
15006 if (inst.operands[2].isscalar)
15007 {
037e8744 15008 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15009 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15010 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15011 NEON_ENCODE (SCALAR, inst);
037e8744 15012 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15013 }
15014 else
15015 {
037e8744 15016 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15017 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15018 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15019 NEON_ENCODE (INTEGER, inst);
5287ad62 15020 /* The U bit (rounding) comes from bit mask. */
037e8744 15021 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15022 }
15023}
15024
15025static void
15026do_neon_fcmp_absolute (void)
15027{
037e8744 15028 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15029 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
15030 /* Size field comes from bit mask. */
037e8744 15031 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
15032}
15033
15034static void
15035do_neon_fcmp_absolute_inv (void)
15036{
15037 neon_exchange_operands ();
15038 do_neon_fcmp_absolute ();
15039}
15040
15041static void
15042do_neon_step (void)
15043{
037e8744 15044 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15045 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 15046 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15047}
15048
15049static void
15050do_neon_abs_neg (void)
15051{
037e8744
JB
15052 enum neon_shape rs;
15053 struct neon_type_el et;
5f4273c7 15054
037e8744
JB
15055 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15056 return;
15057
15058 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15059 return;
15060
15061 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15062 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 15063
5287ad62
JB
15064 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15065 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15066 inst.instruction |= LOW4 (inst.operands[1].reg);
15067 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15068 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15069 inst.instruction |= (et.type == NT_float) << 10;
15070 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15071
88714cb8 15072 neon_dp_fixup (&inst);
5287ad62
JB
15073}
15074
15075static void
15076do_neon_sli (void)
15077{
037e8744 15078 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15079 struct neon_type_el et = neon_check_type (2, rs,
15080 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15081 int imm = inst.operands[2].imm;
15082 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15083 _("immediate out of range for insert"));
037e8744 15084 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15085}
15086
15087static void
15088do_neon_sri (void)
15089{
037e8744 15090 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15091 struct neon_type_el et = neon_check_type (2, rs,
15092 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15093 int imm = inst.operands[2].imm;
15094 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15095 _("immediate out of range for insert"));
037e8744 15096 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15097}
15098
15099static void
15100do_neon_qshlu_imm (void)
15101{
037e8744 15102 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15103 struct neon_type_el et = neon_check_type (2, rs,
15104 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15105 int imm = inst.operands[2].imm;
15106 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15107 _("immediate out of range for shift"));
5287ad62
JB
15108 /* Only encodes the 'U present' variant of the instruction.
15109 In this case, signed types have OP (bit 8) set to 0.
15110 Unsigned types have OP set to 1. */
15111 inst.instruction |= (et.type == NT_unsigned) << 8;
15112 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15113 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15114}
15115
15116static void
15117do_neon_qmovn (void)
15118{
15119 struct neon_type_el et = neon_check_type (2, NS_DQ,
15120 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15121 /* Saturating move where operands can be signed or unsigned, and the
15122 destination has the same signedness. */
88714cb8 15123 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15124 if (et.type == NT_unsigned)
15125 inst.instruction |= 0xc0;
15126 else
15127 inst.instruction |= 0x80;
15128 neon_two_same (0, 1, et.size / 2);
15129}
15130
15131static void
15132do_neon_qmovun (void)
15133{
15134 struct neon_type_el et = neon_check_type (2, NS_DQ,
15135 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15136 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15137 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15138 neon_two_same (0, 1, et.size / 2);
15139}
15140
15141static void
15142do_neon_rshift_sat_narrow (void)
15143{
15144 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15145 or unsigned. If operands are unsigned, results must also be unsigned. */
15146 struct neon_type_el et = neon_check_type (2, NS_DQI,
15147 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15148 int imm = inst.operands[2].imm;
15149 /* This gets the bounds check, size encoding and immediate bits calculation
15150 right. */
15151 et.size /= 2;
5f4273c7 15152
5287ad62
JB
15153 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15154 VQMOVN.I<size> <Dd>, <Qm>. */
15155 if (imm == 0)
15156 {
15157 inst.operands[2].present = 0;
15158 inst.instruction = N_MNEM_vqmovn;
15159 do_neon_qmovn ();
15160 return;
15161 }
5f4273c7 15162
5287ad62 15163 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15164 _("immediate out of range"));
5287ad62
JB
15165 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15166}
15167
15168static void
15169do_neon_rshift_sat_narrow_u (void)
15170{
15171 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15172 or unsigned. If operands are unsigned, results must also be unsigned. */
15173 struct neon_type_el et = neon_check_type (2, NS_DQI,
15174 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15175 int imm = inst.operands[2].imm;
15176 /* This gets the bounds check, size encoding and immediate bits calculation
15177 right. */
15178 et.size /= 2;
15179
15180 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15181 VQMOVUN.I<size> <Dd>, <Qm>. */
15182 if (imm == 0)
15183 {
15184 inst.operands[2].present = 0;
15185 inst.instruction = N_MNEM_vqmovun;
15186 do_neon_qmovun ();
15187 return;
15188 }
15189
15190 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15191 _("immediate out of range"));
5287ad62
JB
15192 /* FIXME: The manual is kind of unclear about what value U should have in
15193 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15194 must be 1. */
15195 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15196}
15197
15198static void
15199do_neon_movn (void)
15200{
15201 struct neon_type_el et = neon_check_type (2, NS_DQ,
15202 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15203 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15204 neon_two_same (0, 1, et.size / 2);
15205}
15206
15207static void
15208do_neon_rshift_narrow (void)
15209{
15210 struct neon_type_el et = neon_check_type (2, NS_DQI,
15211 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15212 int imm = inst.operands[2].imm;
15213 /* This gets the bounds check, size encoding and immediate bits calculation
15214 right. */
15215 et.size /= 2;
5f4273c7 15216
5287ad62
JB
15217 /* If immediate is zero then we are a pseudo-instruction for
15218 VMOVN.I<size> <Dd>, <Qm> */
15219 if (imm == 0)
15220 {
15221 inst.operands[2].present = 0;
15222 inst.instruction = N_MNEM_vmovn;
15223 do_neon_movn ();
15224 return;
15225 }
5f4273c7 15226
5287ad62 15227 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15228 _("immediate out of range for narrowing operation"));
5287ad62
JB
15229 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15230}
15231
15232static void
15233do_neon_shll (void)
15234{
15235 /* FIXME: Type checking when lengthening. */
15236 struct neon_type_el et = neon_check_type (2, NS_QDI,
15237 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15238 unsigned imm = inst.operands[2].imm;
15239
15240 if (imm == et.size)
15241 {
15242 /* Maximum shift variant. */
88714cb8 15243 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15244 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15245 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15246 inst.instruction |= LOW4 (inst.operands[1].reg);
15247 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15248 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15249
88714cb8 15250 neon_dp_fixup (&inst);
5287ad62
JB
15251 }
15252 else
15253 {
15254 /* A more-specific type check for non-max versions. */
15255 et = neon_check_type (2, NS_QDI,
477330fc 15256 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15257 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15258 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15259 }
15260}
15261
037e8744 15262/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15263 the current instruction is. */
15264
6b9a8b67
MGD
15265#define CVT_FLAVOUR_VAR \
15266 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15267 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15268 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15269 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15270 /* Half-precision conversions. */ \
15271 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15272 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15273 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15274 Compared with single/double precision variants, only the co-processor \
15275 field is different, so the encoding flow is reused here. */ \
15276 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15277 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15278 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15279 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15280 /* VFP instructions. */ \
15281 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15282 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15283 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15284 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15285 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15286 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15287 /* VFP instructions with bitshift. */ \
15288 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15289 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15290 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15291 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15292 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15293 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15294 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15295 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15296
15297#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15298 neon_cvt_flavour_##C,
15299
15300/* The different types of conversions we can do. */
15301enum neon_cvt_flavour
15302{
15303 CVT_FLAVOUR_VAR
15304 neon_cvt_flavour_invalid,
15305 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15306};
15307
15308#undef CVT_VAR
15309
15310static enum neon_cvt_flavour
15311get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15312{
6b9a8b67
MGD
15313#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15314 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15315 if (et.type != NT_invtype) \
15316 { \
15317 inst.error = NULL; \
15318 return (neon_cvt_flavour_##C); \
5287ad62 15319 }
6b9a8b67 15320
5287ad62 15321 struct neon_type_el et;
037e8744 15322 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15323 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15324 /* The instruction versions which take an immediate take one register
15325 argument, which is extended to the width of the full register. Thus the
15326 "source" and "destination" registers must have the same width. Hack that
15327 here by making the size equal to the key (wider, in this case) operand. */
15328 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15329
6b9a8b67
MGD
15330 CVT_FLAVOUR_VAR;
15331
15332 return neon_cvt_flavour_invalid;
5287ad62
JB
15333#undef CVT_VAR
15334}
15335
7e8e6784
MGD
15336enum neon_cvt_mode
15337{
15338 neon_cvt_mode_a,
15339 neon_cvt_mode_n,
15340 neon_cvt_mode_p,
15341 neon_cvt_mode_m,
15342 neon_cvt_mode_z,
30bdf752
MGD
15343 neon_cvt_mode_x,
15344 neon_cvt_mode_r
7e8e6784
MGD
15345};
15346
037e8744
JB
15347/* Neon-syntax VFP conversions. */
15348
5287ad62 15349static void
6b9a8b67 15350do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15351{
037e8744 15352 const char *opname = 0;
5f4273c7 15353
d54af2d0
RL
15354 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15355 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15356 {
037e8744
JB
15357 /* Conversions with immediate bitshift. */
15358 const char *enc[] =
477330fc 15359 {
6b9a8b67
MGD
15360#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15361 CVT_FLAVOUR_VAR
15362 NULL
15363#undef CVT_VAR
477330fc 15364 };
037e8744 15365
6b9a8b67 15366 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15367 {
15368 opname = enc[flavour];
15369 constraint (inst.operands[0].reg != inst.operands[1].reg,
15370 _("operands 0 and 1 must be the same register"));
15371 inst.operands[1] = inst.operands[2];
15372 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15373 }
5287ad62
JB
15374 }
15375 else
15376 {
037e8744
JB
15377 /* Conversions without bitshift. */
15378 const char *enc[] =
477330fc 15379 {
6b9a8b67
MGD
15380#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15381 CVT_FLAVOUR_VAR
15382 NULL
15383#undef CVT_VAR
477330fc 15384 };
037e8744 15385
6b9a8b67 15386 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15387 opname = enc[flavour];
037e8744
JB
15388 }
15389
15390 if (opname)
15391 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15392
15393 /* ARMv8.2 fp16 VCVT instruction. */
15394 if (flavour == neon_cvt_flavour_s32_f16
15395 || flavour == neon_cvt_flavour_u32_f16
15396 || flavour == neon_cvt_flavour_f16_u32
15397 || flavour == neon_cvt_flavour_f16_s32)
15398 do_scalar_fp16_v82_encode ();
037e8744
JB
15399}
15400
15401static void
15402do_vfp_nsyn_cvtz (void)
15403{
d54af2d0 15404 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15405 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15406 const char *enc[] =
15407 {
6b9a8b67
MGD
15408#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15409 CVT_FLAVOUR_VAR
15410 NULL
15411#undef CVT_VAR
037e8744
JB
15412 };
15413
6b9a8b67 15414 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15415 do_vfp_nsyn_opcode (enc[flavour]);
15416}
f31fef98 15417
037e8744 15418static void
bacebabc 15419do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15420 enum neon_cvt_mode mode)
15421{
15422 int sz, op;
15423 int rm;
15424
a715796b
TG
15425 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15426 D register operands. */
15427 if (flavour == neon_cvt_flavour_s32_f64
15428 || flavour == neon_cvt_flavour_u32_f64)
15429 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15430 _(BAD_FPU));
15431
9db2f6b4
RL
15432 if (flavour == neon_cvt_flavour_s32_f16
15433 || flavour == neon_cvt_flavour_u32_f16)
15434 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15435 _(BAD_FP16));
15436
7e8e6784
MGD
15437 set_it_insn_type (OUTSIDE_IT_INSN);
15438
15439 switch (flavour)
15440 {
15441 case neon_cvt_flavour_s32_f64:
15442 sz = 1;
827f64ff 15443 op = 1;
7e8e6784
MGD
15444 break;
15445 case neon_cvt_flavour_s32_f32:
15446 sz = 0;
15447 op = 1;
15448 break;
9db2f6b4
RL
15449 case neon_cvt_flavour_s32_f16:
15450 sz = 0;
15451 op = 1;
15452 break;
7e8e6784
MGD
15453 case neon_cvt_flavour_u32_f64:
15454 sz = 1;
15455 op = 0;
15456 break;
15457 case neon_cvt_flavour_u32_f32:
15458 sz = 0;
15459 op = 0;
15460 break;
9db2f6b4
RL
15461 case neon_cvt_flavour_u32_f16:
15462 sz = 0;
15463 op = 0;
15464 break;
7e8e6784
MGD
15465 default:
15466 first_error (_("invalid instruction shape"));
15467 return;
15468 }
15469
15470 switch (mode)
15471 {
15472 case neon_cvt_mode_a: rm = 0; break;
15473 case neon_cvt_mode_n: rm = 1; break;
15474 case neon_cvt_mode_p: rm = 2; break;
15475 case neon_cvt_mode_m: rm = 3; break;
15476 default: first_error (_("invalid rounding mode")); return;
15477 }
15478
15479 NEON_ENCODE (FPV8, inst);
15480 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15481 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15482 inst.instruction |= sz << 8;
9db2f6b4
RL
15483
15484 /* ARMv8.2 fp16 VCVT instruction. */
15485 if (flavour == neon_cvt_flavour_s32_f16
15486 ||flavour == neon_cvt_flavour_u32_f16)
15487 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15488 inst.instruction |= op << 7;
15489 inst.instruction |= rm << 16;
15490 inst.instruction |= 0xf0000000;
15491 inst.is_neon = TRUE;
15492}
15493
15494static void
15495do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15496{
15497 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15498 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15499 NS_FH, NS_HF, NS_FHI, NS_HFI,
15500 NS_NULL);
6b9a8b67 15501 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15502
e3e535bc 15503 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15504 if (mode == neon_cvt_mode_z
e3e535bc 15505 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
15506 && (flavour == neon_cvt_flavour_s32_f32
15507 || flavour == neon_cvt_flavour_u32_f32
15508 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15509 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15510 && (rs == NS_FD || rs == NS_FF))
15511 {
15512 do_vfp_nsyn_cvtz ();
15513 return;
15514 }
15515
9db2f6b4
RL
15516 /* ARMv8.2 fp16 VCVT conversions. */
15517 if (mode == neon_cvt_mode_z
15518 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15519 && (flavour == neon_cvt_flavour_s32_f16
15520 || flavour == neon_cvt_flavour_u32_f16)
15521 && (rs == NS_FH))
15522 {
15523 do_vfp_nsyn_cvtz ();
15524 do_scalar_fp16_v82_encode ();
15525 return;
15526 }
15527
037e8744 15528 /* VFP rather than Neon conversions. */
6b9a8b67 15529 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15530 {
7e8e6784
MGD
15531 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15532 do_vfp_nsyn_cvt (rs, flavour);
15533 else
15534 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15535
037e8744
JB
15536 return;
15537 }
15538
15539 switch (rs)
15540 {
15541 case NS_DDI:
15542 case NS_QQI:
15543 {
477330fc
RM
15544 unsigned immbits;
15545 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 15546
477330fc
RM
15547 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15548 return;
037e8744 15549
477330fc
RM
15550 /* Fixed-point conversion with #0 immediate is encoded as an
15551 integer conversion. */
15552 if (inst.operands[2].present && inst.operands[2].imm == 0)
15553 goto int_encode;
35997600 15554 immbits = 32 - inst.operands[2].imm;
477330fc
RM
15555 NEON_ENCODE (IMMED, inst);
15556 if (flavour != neon_cvt_flavour_invalid)
15557 inst.instruction |= enctab[flavour];
15558 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15559 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15560 inst.instruction |= LOW4 (inst.operands[1].reg);
15561 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15562 inst.instruction |= neon_quad (rs) << 6;
15563 inst.instruction |= 1 << 21;
15564 inst.instruction |= immbits << 16;
15565
15566 neon_dp_fixup (&inst);
037e8744
JB
15567 }
15568 break;
15569
15570 case NS_DD:
15571 case NS_QQ:
7e8e6784
MGD
15572 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15573 {
15574 NEON_ENCODE (FLOAT, inst);
15575 set_it_insn_type (OUTSIDE_IT_INSN);
15576
15577 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15578 return;
15579
15580 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15581 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15582 inst.instruction |= LOW4 (inst.operands[1].reg);
15583 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15584 inst.instruction |= neon_quad (rs) << 6;
15585 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15586 inst.instruction |= mode << 8;
15587 if (thumb_mode)
15588 inst.instruction |= 0xfc000000;
15589 else
15590 inst.instruction |= 0xf0000000;
15591 }
15592 else
15593 {
037e8744 15594 int_encode:
7e8e6784
MGD
15595 {
15596 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 15597
7e8e6784 15598 NEON_ENCODE (INTEGER, inst);
037e8744 15599
7e8e6784
MGD
15600 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15601 return;
037e8744 15602
7e8e6784
MGD
15603 if (flavour != neon_cvt_flavour_invalid)
15604 inst.instruction |= enctab[flavour];
037e8744 15605
7e8e6784
MGD
15606 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15607 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15608 inst.instruction |= LOW4 (inst.operands[1].reg);
15609 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15610 inst.instruction |= neon_quad (rs) << 6;
15611 inst.instruction |= 2 << 18;
037e8744 15612
7e8e6784
MGD
15613 neon_dp_fixup (&inst);
15614 }
15615 }
15616 break;
037e8744 15617
8e79c3df
CM
15618 /* Half-precision conversions for Advanced SIMD -- neon. */
15619 case NS_QD:
15620 case NS_DQ:
15621
15622 if ((rs == NS_DQ)
15623 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15624 {
15625 as_bad (_("operand size must match register width"));
15626 break;
15627 }
15628
15629 if ((rs == NS_QD)
15630 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15631 {
15632 as_bad (_("operand size must match register width"));
15633 break;
15634 }
15635
15636 if (rs == NS_DQ)
477330fc 15637 inst.instruction = 0x3b60600;
8e79c3df
CM
15638 else
15639 inst.instruction = 0x3b60700;
15640
15641 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15642 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15643 inst.instruction |= LOW4 (inst.operands[1].reg);
15644 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15645 neon_dp_fixup (&inst);
8e79c3df
CM
15646 break;
15647
037e8744
JB
15648 default:
15649 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15650 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15651 do_vfp_nsyn_cvt (rs, flavour);
15652 else
15653 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15654 }
5287ad62
JB
15655}
15656
e3e535bc
NC
15657static void
15658do_neon_cvtr (void)
15659{
7e8e6784 15660 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15661}
15662
15663static void
15664do_neon_cvt (void)
15665{
7e8e6784
MGD
15666 do_neon_cvt_1 (neon_cvt_mode_z);
15667}
15668
15669static void
15670do_neon_cvta (void)
15671{
15672 do_neon_cvt_1 (neon_cvt_mode_a);
15673}
15674
15675static void
15676do_neon_cvtn (void)
15677{
15678 do_neon_cvt_1 (neon_cvt_mode_n);
15679}
15680
15681static void
15682do_neon_cvtp (void)
15683{
15684 do_neon_cvt_1 (neon_cvt_mode_p);
15685}
15686
15687static void
15688do_neon_cvtm (void)
15689{
15690 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15691}
15692
8e79c3df 15693static void
c70a8987 15694do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15695{
c70a8987
MGD
15696 if (is_double)
15697 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15698
c70a8987
MGD
15699 encode_arm_vfp_reg (inst.operands[0].reg,
15700 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15701 encode_arm_vfp_reg (inst.operands[1].reg,
15702 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15703 inst.instruction |= to ? 0x10000 : 0;
15704 inst.instruction |= t ? 0x80 : 0;
15705 inst.instruction |= is_double ? 0x100 : 0;
15706 do_vfp_cond_or_thumb ();
15707}
8e79c3df 15708
c70a8987
MGD
15709static void
15710do_neon_cvttb_1 (bfd_boolean t)
15711{
d54af2d0
RL
15712 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15713 NS_DF, NS_DH, NS_NULL);
8e79c3df 15714
c70a8987
MGD
15715 if (rs == NS_NULL)
15716 return;
15717 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15718 {
15719 inst.error = NULL;
15720 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15721 }
15722 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15723 {
15724 inst.error = NULL;
15725 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15726 }
15727 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15728 {
a715796b
TG
15729 /* The VCVTB and VCVTT instructions with D-register operands
15730 don't work for SP only targets. */
15731 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15732 _(BAD_FPU));
15733
c70a8987
MGD
15734 inst.error = NULL;
15735 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15736 }
15737 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15738 {
a715796b
TG
15739 /* The VCVTB and VCVTT instructions with D-register operands
15740 don't work for SP only targets. */
15741 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15742 _(BAD_FPU));
15743
c70a8987
MGD
15744 inst.error = NULL;
15745 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15746 }
15747 else
15748 return;
15749}
15750
15751static void
15752do_neon_cvtb (void)
15753{
15754 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15755}
15756
15757
15758static void
15759do_neon_cvtt (void)
15760{
c70a8987 15761 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15762}
15763
5287ad62
JB
15764static void
15765neon_move_immediate (void)
15766{
037e8744
JB
15767 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15768 struct neon_type_el et = neon_check_type (2, rs,
15769 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15770 unsigned immlo, immhi = 0, immbits;
c96612cc 15771 int op, cmode, float_p;
5287ad62 15772
037e8744 15773 constraint (et.type == NT_invtype,
477330fc 15774 _("operand size must be specified for immediate VMOV"));
037e8744 15775
5287ad62
JB
15776 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15777 op = (inst.instruction & (1 << 5)) != 0;
15778
15779 immlo = inst.operands[1].imm;
15780 if (inst.operands[1].regisimm)
15781 immhi = inst.operands[1].reg;
15782
15783 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15784 _("immediate has bits set outside the operand size"));
5287ad62 15785
c96612cc
JB
15786 float_p = inst.operands[1].immisfloat;
15787
15788 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15789 et.size, et.type)) == FAIL)
5287ad62
JB
15790 {
15791 /* Invert relevant bits only. */
15792 neon_invert_size (&immlo, &immhi, et.size);
15793 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15794 with one or the other; those cases are caught by
15795 neon_cmode_for_move_imm. */
5287ad62 15796 op = !op;
c96612cc
JB
15797 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15798 &op, et.size, et.type)) == FAIL)
477330fc
RM
15799 {
15800 first_error (_("immediate out of range"));
15801 return;
15802 }
5287ad62
JB
15803 }
15804
15805 inst.instruction &= ~(1 << 5);
15806 inst.instruction |= op << 5;
15807
15808 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15809 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15810 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15811 inst.instruction |= cmode << 8;
15812
15813 neon_write_immbits (immbits);
15814}
15815
15816static void
15817do_neon_mvn (void)
15818{
15819 if (inst.operands[1].isreg)
15820 {
037e8744 15821 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15822
88714cb8 15823 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15824 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15825 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15826 inst.instruction |= LOW4 (inst.operands[1].reg);
15827 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15828 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15829 }
15830 else
15831 {
88714cb8 15832 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15833 neon_move_immediate ();
15834 }
15835
88714cb8 15836 neon_dp_fixup (&inst);
5287ad62
JB
15837}
15838
15839/* Encode instructions of form:
15840
15841 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15842 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15843
15844static void
15845neon_mixed_length (struct neon_type_el et, unsigned size)
15846{
15847 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15848 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15849 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15850 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15851 inst.instruction |= LOW4 (inst.operands[2].reg);
15852 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15853 inst.instruction |= (et.type == NT_unsigned) << 24;
15854 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15855
88714cb8 15856 neon_dp_fixup (&inst);
5287ad62
JB
15857}
15858
15859static void
15860do_neon_dyadic_long (void)
15861{
15862 /* FIXME: Type checking for lengthening op. */
15863 struct neon_type_el et = neon_check_type (3, NS_QDD,
15864 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15865 neon_mixed_length (et, et.size);
15866}
15867
15868static void
15869do_neon_abal (void)
15870{
15871 struct neon_type_el et = neon_check_type (3, NS_QDD,
15872 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15873 neon_mixed_length (et, et.size);
15874}
15875
15876static void
15877neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15878{
15879 if (inst.operands[2].isscalar)
15880 {
dcbf9037 15881 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15882 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15883 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15884 neon_mul_mac (et, et.type == NT_unsigned);
15885 }
15886 else
15887 {
15888 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15889 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15890 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15891 neon_mixed_length (et, et.size);
15892 }
15893}
15894
15895static void
15896do_neon_mac_maybe_scalar_long (void)
15897{
15898 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15899}
15900
15901static void
15902do_neon_dyadic_wide (void)
15903{
15904 struct neon_type_el et = neon_check_type (3, NS_QQD,
15905 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15906 neon_mixed_length (et, et.size);
15907}
15908
15909static void
15910do_neon_dyadic_narrow (void)
15911{
15912 struct neon_type_el et = neon_check_type (3, NS_QDD,
15913 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15914 /* Operand sign is unimportant, and the U bit is part of the opcode,
15915 so force the operand type to integer. */
15916 et.type = NT_integer;
5287ad62
JB
15917 neon_mixed_length (et, et.size / 2);
15918}
15919
15920static void
15921do_neon_mul_sat_scalar_long (void)
15922{
15923 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15924}
15925
15926static void
15927do_neon_vmull (void)
15928{
15929 if (inst.operands[2].isscalar)
15930 do_neon_mac_maybe_scalar_long ();
15931 else
15932 {
15933 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15934 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15935
5287ad62 15936 if (et.type == NT_poly)
477330fc 15937 NEON_ENCODE (POLY, inst);
5287ad62 15938 else
477330fc 15939 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15940
15941 /* For polynomial encoding the U bit must be zero, and the size must
15942 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15943 obviously, as 0b10). */
15944 if (et.size == 64)
15945 {
15946 /* Check we're on the correct architecture. */
15947 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15948 inst.error =
15949 _("Instruction form not available on this architecture.");
15950
15951 et.size = 32;
15952 }
15953
5287ad62
JB
15954 neon_mixed_length (et, et.size);
15955 }
15956}
15957
15958static void
15959do_neon_ext (void)
15960{
037e8744 15961 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15962 struct neon_type_el et = neon_check_type (3, rs,
15963 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15964 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15965
15966 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15967 _("shift out of range"));
5287ad62
JB
15968 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15969 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15970 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15971 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15972 inst.instruction |= LOW4 (inst.operands[2].reg);
15973 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15974 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15975 inst.instruction |= imm << 8;
5f4273c7 15976
88714cb8 15977 neon_dp_fixup (&inst);
5287ad62
JB
15978}
15979
15980static void
15981do_neon_rev (void)
15982{
037e8744 15983 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15984 struct neon_type_el et = neon_check_type (2, rs,
15985 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15986 unsigned op = (inst.instruction >> 7) & 3;
15987 /* N (width of reversed regions) is encoded as part of the bitmask. We
15988 extract it here to check the elements to be reversed are smaller.
15989 Otherwise we'd get a reserved instruction. */
15990 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15991 gas_assert (elsize != 0);
5287ad62 15992 constraint (et.size >= elsize,
477330fc 15993 _("elements must be smaller than reversal region"));
037e8744 15994 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15995}
15996
15997static void
15998do_neon_dup (void)
15999{
16000 if (inst.operands[1].isscalar)
16001 {
037e8744 16002 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16003 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16004 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16005 unsigned sizebits = et.size >> 3;
dcbf9037 16006 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16007 int logsize = neon_logbits (et.size);
dcbf9037 16008 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16009
16010 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16011 return;
037e8744 16012
88714cb8 16013 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16014 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16015 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16016 inst.instruction |= LOW4 (dm);
16017 inst.instruction |= HI1 (dm) << 5;
037e8744 16018 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16019 inst.instruction |= x << 17;
16020 inst.instruction |= sizebits << 16;
5f4273c7 16021
88714cb8 16022 neon_dp_fixup (&inst);
5287ad62
JB
16023 }
16024 else
16025 {
037e8744
JB
16026 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16027 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16028 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16029 /* Duplicate ARM register to lanes of vector. */
88714cb8 16030 NEON_ENCODE (ARMREG, inst);
5287ad62 16031 switch (et.size)
477330fc
RM
16032 {
16033 case 8: inst.instruction |= 0x400000; break;
16034 case 16: inst.instruction |= 0x000020; break;
16035 case 32: inst.instruction |= 0x000000; break;
16036 default: break;
16037 }
5287ad62
JB
16038 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16039 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16040 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16041 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16042 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16043 variants, except for the condition field. */
037e8744 16044 do_vfp_cond_or_thumb ();
5287ad62
JB
16045 }
16046}
16047
16048/* VMOV has particularly many variations. It can be one of:
16049 0. VMOV<c><q> <Qd>, <Qm>
16050 1. VMOV<c><q> <Dd>, <Dm>
16051 (Register operations, which are VORR with Rm = Rn.)
16052 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16053 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16054 (Immediate loads.)
16055 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16056 (ARM register to scalar.)
16057 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16058 (Two ARM registers to vector.)
16059 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16060 (Scalar to ARM register.)
16061 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16062 (Vector to two ARM registers.)
037e8744
JB
16063 8. VMOV.F32 <Sd>, <Sm>
16064 9. VMOV.F64 <Dd>, <Dm>
16065 (VFP register moves.)
16066 10. VMOV.F32 <Sd>, #imm
16067 11. VMOV.F64 <Dd>, #imm
16068 (VFP float immediate load.)
16069 12. VMOV <Rd>, <Sm>
16070 (VFP single to ARM reg.)
16071 13. VMOV <Sd>, <Rm>
16072 (ARM reg to VFP single.)
16073 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16074 (Two ARM regs to two VFP singles.)
16075 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16076 (Two VFP singles to two ARM regs.)
5f4273c7 16077
037e8744
JB
16078 These cases can be disambiguated using neon_select_shape, except cases 1/9
16079 and 3/11 which depend on the operand type too.
5f4273c7 16080
5287ad62 16081 All the encoded bits are hardcoded by this function.
5f4273c7 16082
b7fc2769
JB
16083 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16084 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16085
5287ad62 16086 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16087 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16088
16089static void
16090do_neon_mov (void)
16091{
037e8744 16092 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16093 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16094 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16095 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16096 struct neon_type_el et;
16097 const char *ldconst = 0;
5287ad62 16098
037e8744 16099 switch (rs)
5287ad62 16100 {
037e8744
JB
16101 case NS_DD: /* case 1/9. */
16102 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16103 /* It is not an error here if no type is given. */
16104 inst.error = NULL;
16105 if (et.type == NT_float && et.size == 64)
477330fc
RM
16106 {
16107 do_vfp_nsyn_opcode ("fcpyd");
16108 break;
16109 }
037e8744 16110 /* fall through. */
5287ad62 16111
037e8744
JB
16112 case NS_QQ: /* case 0/1. */
16113 {
477330fc
RM
16114 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16115 return;
16116 /* The architecture manual I have doesn't explicitly state which
16117 value the U bit should have for register->register moves, but
16118 the equivalent VORR instruction has U = 0, so do that. */
16119 inst.instruction = 0x0200110;
16120 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16121 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16122 inst.instruction |= LOW4 (inst.operands[1].reg);
16123 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16124 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16125 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16126 inst.instruction |= neon_quad (rs) << 6;
16127
16128 neon_dp_fixup (&inst);
037e8744
JB
16129 }
16130 break;
5f4273c7 16131
037e8744
JB
16132 case NS_DI: /* case 3/11. */
16133 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16134 inst.error = NULL;
16135 if (et.type == NT_float && et.size == 64)
477330fc
RM
16136 {
16137 /* case 11 (fconstd). */
16138 ldconst = "fconstd";
16139 goto encode_fconstd;
16140 }
037e8744
JB
16141 /* fall through. */
16142
16143 case NS_QI: /* case 2/3. */
16144 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16145 return;
037e8744
JB
16146 inst.instruction = 0x0800010;
16147 neon_move_immediate ();
88714cb8 16148 neon_dp_fixup (&inst);
5287ad62 16149 break;
5f4273c7 16150
037e8744
JB
16151 case NS_SR: /* case 4. */
16152 {
477330fc
RM
16153 unsigned bcdebits = 0;
16154 int logsize;
16155 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16156 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16157
05ac0ffb
JB
16158 /* .<size> is optional here, defaulting to .32. */
16159 if (inst.vectype.elems == 0
16160 && inst.operands[0].vectype.type == NT_invtype
16161 && inst.operands[1].vectype.type == NT_invtype)
16162 {
16163 inst.vectype.el[0].type = NT_untyped;
16164 inst.vectype.el[0].size = 32;
16165 inst.vectype.elems = 1;
16166 }
16167
477330fc
RM
16168 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16169 logsize = neon_logbits (et.size);
16170
16171 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16172 _(BAD_FPU));
16173 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16174 && et.size != 32, _(BAD_FPU));
16175 constraint (et.type == NT_invtype, _("bad type for scalar"));
16176 constraint (x >= 64 / et.size, _("scalar index out of range"));
16177
16178 switch (et.size)
16179 {
16180 case 8: bcdebits = 0x8; break;
16181 case 16: bcdebits = 0x1; break;
16182 case 32: bcdebits = 0x0; break;
16183 default: ;
16184 }
16185
16186 bcdebits |= x << logsize;
16187
16188 inst.instruction = 0xe000b10;
16189 do_vfp_cond_or_thumb ();
16190 inst.instruction |= LOW4 (dn) << 16;
16191 inst.instruction |= HI1 (dn) << 7;
16192 inst.instruction |= inst.operands[1].reg << 12;
16193 inst.instruction |= (bcdebits & 3) << 5;
16194 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16195 }
16196 break;
5f4273c7 16197
037e8744 16198 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16199 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16200 _(BAD_FPU));
b7fc2769 16201
037e8744
JB
16202 inst.instruction = 0xc400b10;
16203 do_vfp_cond_or_thumb ();
16204 inst.instruction |= LOW4 (inst.operands[0].reg);
16205 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16206 inst.instruction |= inst.operands[1].reg << 12;
16207 inst.instruction |= inst.operands[2].reg << 16;
16208 break;
5f4273c7 16209
037e8744
JB
16210 case NS_RS: /* case 6. */
16211 {
477330fc
RM
16212 unsigned logsize;
16213 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16214 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16215 unsigned abcdebits = 0;
037e8744 16216
05ac0ffb
JB
16217 /* .<dt> is optional here, defaulting to .32. */
16218 if (inst.vectype.elems == 0
16219 && inst.operands[0].vectype.type == NT_invtype
16220 && inst.operands[1].vectype.type == NT_invtype)
16221 {
16222 inst.vectype.el[0].type = NT_untyped;
16223 inst.vectype.el[0].size = 32;
16224 inst.vectype.elems = 1;
16225 }
16226
91d6fa6a
NC
16227 et = neon_check_type (2, NS_NULL,
16228 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16229 logsize = neon_logbits (et.size);
16230
16231 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16232 _(BAD_FPU));
16233 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16234 && et.size != 32, _(BAD_FPU));
16235 constraint (et.type == NT_invtype, _("bad type for scalar"));
16236 constraint (x >= 64 / et.size, _("scalar index out of range"));
16237
16238 switch (et.size)
16239 {
16240 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16241 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16242 case 32: abcdebits = 0x00; break;
16243 default: ;
16244 }
16245
16246 abcdebits |= x << logsize;
16247 inst.instruction = 0xe100b10;
16248 do_vfp_cond_or_thumb ();
16249 inst.instruction |= LOW4 (dn) << 16;
16250 inst.instruction |= HI1 (dn) << 7;
16251 inst.instruction |= inst.operands[0].reg << 12;
16252 inst.instruction |= (abcdebits & 3) << 5;
16253 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16254 }
16255 break;
5f4273c7 16256
037e8744
JB
16257 case NS_RRD: /* case 7 (fmrrd). */
16258 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16259 _(BAD_FPU));
037e8744
JB
16260
16261 inst.instruction = 0xc500b10;
16262 do_vfp_cond_or_thumb ();
16263 inst.instruction |= inst.operands[0].reg << 12;
16264 inst.instruction |= inst.operands[1].reg << 16;
16265 inst.instruction |= LOW4 (inst.operands[2].reg);
16266 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16267 break;
5f4273c7 16268
037e8744
JB
16269 case NS_FF: /* case 8 (fcpys). */
16270 do_vfp_nsyn_opcode ("fcpys");
16271 break;
5f4273c7 16272
9db2f6b4 16273 case NS_HI:
037e8744
JB
16274 case NS_FI: /* case 10 (fconsts). */
16275 ldconst = "fconsts";
16276 encode_fconstd:
16277 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16278 {
16279 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16280 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16281
16282 /* ARMv8.2 fp16 vmov.f16 instruction. */
16283 if (rs == NS_HI)
16284 do_scalar_fp16_v82_encode ();
477330fc 16285 }
5287ad62 16286 else
477330fc 16287 first_error (_("immediate out of range"));
037e8744 16288 break;
5f4273c7 16289
9db2f6b4 16290 case NS_RH:
037e8744
JB
16291 case NS_RF: /* case 12 (fmrs). */
16292 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16293 /* ARMv8.2 fp16 vmov.f16 instruction. */
16294 if (rs == NS_RH)
16295 do_scalar_fp16_v82_encode ();
037e8744 16296 break;
5f4273c7 16297
9db2f6b4 16298 case NS_HR:
037e8744
JB
16299 case NS_FR: /* case 13 (fmsr). */
16300 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16301 /* ARMv8.2 fp16 vmov.f16 instruction. */
16302 if (rs == NS_HR)
16303 do_scalar_fp16_v82_encode ();
037e8744 16304 break;
5f4273c7 16305
037e8744
JB
16306 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16307 (one of which is a list), but we have parsed four. Do some fiddling to
16308 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16309 expect. */
16310 case NS_RRFF: /* case 14 (fmrrs). */
16311 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16312 _("VFP registers must be adjacent"));
037e8744
JB
16313 inst.operands[2].imm = 2;
16314 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16315 do_vfp_nsyn_opcode ("fmrrs");
16316 break;
5f4273c7 16317
037e8744
JB
16318 case NS_FFRR: /* case 15 (fmsrr). */
16319 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16320 _("VFP registers must be adjacent"));
037e8744
JB
16321 inst.operands[1] = inst.operands[2];
16322 inst.operands[2] = inst.operands[3];
16323 inst.operands[0].imm = 2;
16324 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16325 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16326 break;
5f4273c7 16327
4c261dff
NC
16328 case NS_NULL:
16329 /* neon_select_shape has determined that the instruction
16330 shape is wrong and has already set the error message. */
16331 break;
16332
5287ad62
JB
16333 default:
16334 abort ();
16335 }
16336}
16337
16338static void
16339do_neon_rshift_round_imm (void)
16340{
037e8744 16341 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16342 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16343 int imm = inst.operands[2].imm;
16344
16345 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16346 if (imm == 0)
16347 {
16348 inst.operands[2].present = 0;
16349 do_neon_mov ();
16350 return;
16351 }
16352
16353 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16354 _("immediate out of range for shift"));
037e8744 16355 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16356 et.size - imm);
5287ad62
JB
16357}
16358
9db2f6b4
RL
16359static void
16360do_neon_movhf (void)
16361{
16362 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16363 constraint (rs != NS_HH, _("invalid suffix"));
16364
16365 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16366 _(BAD_FPU));
16367
16368 do_vfp_sp_monadic ();
16369
16370 inst.is_neon = 1;
16371 inst.instruction |= 0xf0000000;
16372}
16373
5287ad62
JB
16374static void
16375do_neon_movl (void)
16376{
16377 struct neon_type_el et = neon_check_type (2, NS_QD,
16378 N_EQK | N_DBL, N_SU_32 | N_KEY);
16379 unsigned sizebits = et.size >> 3;
16380 inst.instruction |= sizebits << 19;
16381 neon_two_same (0, et.type == NT_unsigned, -1);
16382}
16383
16384static void
16385do_neon_trn (void)
16386{
037e8744 16387 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16388 struct neon_type_el et = neon_check_type (2, rs,
16389 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16390 NEON_ENCODE (INTEGER, inst);
037e8744 16391 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16392}
16393
16394static void
16395do_neon_zip_uzp (void)
16396{
037e8744 16397 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16398 struct neon_type_el et = neon_check_type (2, rs,
16399 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16400 if (rs == NS_DD && et.size == 32)
16401 {
16402 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16403 inst.instruction = N_MNEM_vtrn;
16404 do_neon_trn ();
16405 return;
16406 }
037e8744 16407 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16408}
16409
16410static void
16411do_neon_sat_abs_neg (void)
16412{
037e8744 16413 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16414 struct neon_type_el et = neon_check_type (2, rs,
16415 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16416 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16417}
16418
16419static void
16420do_neon_pair_long (void)
16421{
037e8744 16422 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16423 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16424 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16425 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16426 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16427}
16428
16429static void
16430do_neon_recip_est (void)
16431{
037e8744 16432 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16433 struct neon_type_el et = neon_check_type (2, rs,
16434 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16435 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16436 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16437}
16438
16439static void
16440do_neon_cls (void)
16441{
037e8744 16442 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16443 struct neon_type_el et = neon_check_type (2, rs,
16444 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16445 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16446}
16447
16448static void
16449do_neon_clz (void)
16450{
037e8744 16451 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16452 struct neon_type_el et = neon_check_type (2, rs,
16453 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16454 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16455}
16456
16457static void
16458do_neon_cnt (void)
16459{
037e8744 16460 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16461 struct neon_type_el et = neon_check_type (2, rs,
16462 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16463 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16464}
16465
16466static void
16467do_neon_swp (void)
16468{
037e8744
JB
16469 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16470 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16471}
16472
16473static void
16474do_neon_tbl_tbx (void)
16475{
16476 unsigned listlenbits;
dcbf9037 16477 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16478
5287ad62
JB
16479 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16480 {
dcbf9037 16481 first_error (_("bad list length for table lookup"));
5287ad62
JB
16482 return;
16483 }
5f4273c7 16484
5287ad62
JB
16485 listlenbits = inst.operands[1].imm - 1;
16486 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16487 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16488 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16489 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16490 inst.instruction |= LOW4 (inst.operands[2].reg);
16491 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16492 inst.instruction |= listlenbits << 8;
5f4273c7 16493
88714cb8 16494 neon_dp_fixup (&inst);
5287ad62
JB
16495}
16496
16497static void
16498do_neon_ldm_stm (void)
16499{
16500 /* P, U and L bits are part of bitmask. */
16501 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16502 unsigned offsetbits = inst.operands[1].imm * 2;
16503
037e8744
JB
16504 if (inst.operands[1].issingle)
16505 {
16506 do_vfp_nsyn_ldm_stm (is_dbmode);
16507 return;
16508 }
16509
5287ad62 16510 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16511 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16512
16513 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16514 _("register list must contain at least 1 and at most 16 "
16515 "registers"));
5287ad62
JB
16516
16517 inst.instruction |= inst.operands[0].reg << 16;
16518 inst.instruction |= inst.operands[0].writeback << 21;
16519 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16520 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16521
16522 inst.instruction |= offsetbits;
5f4273c7 16523
037e8744 16524 do_vfp_cond_or_thumb ();
5287ad62
JB
16525}
16526
16527static void
16528do_neon_ldr_str (void)
16529{
5287ad62 16530 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16531
6844b2c2
MGD
16532 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16533 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16534 if (!is_ldr
6844b2c2 16535 && inst.operands[1].reg == REG_PC
ba86b375 16536 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16537 {
94dcf8bf 16538 if (thumb_mode)
6844b2c2 16539 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16540 else if (warn_on_deprecated)
5c3696f8 16541 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16542 }
16543
037e8744
JB
16544 if (inst.operands[0].issingle)
16545 {
cd2f129f 16546 if (is_ldr)
477330fc 16547 do_vfp_nsyn_opcode ("flds");
cd2f129f 16548 else
477330fc 16549 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16550
16551 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16552 if (inst.vectype.el[0].size == 16)
16553 do_scalar_fp16_v82_encode ();
5287ad62
JB
16554 }
16555 else
5287ad62 16556 {
cd2f129f 16557 if (is_ldr)
477330fc 16558 do_vfp_nsyn_opcode ("fldd");
5287ad62 16559 else
477330fc 16560 do_vfp_nsyn_opcode ("fstd");
5287ad62 16561 }
5287ad62
JB
16562}
16563
16564/* "interleave" version also handles non-interleaving register VLD1/VST1
16565 instructions. */
16566
16567static void
16568do_neon_ld_st_interleave (void)
16569{
037e8744 16570 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16571 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16572 unsigned alignbits = 0;
16573 unsigned idx;
16574 /* The bits in this table go:
16575 0: register stride of one (0) or two (1)
16576 1,2: register list length, minus one (1, 2, 3, 4).
16577 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16578 We use -1 for invalid entries. */
16579 const int typetable[] =
16580 {
16581 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16582 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16583 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16584 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16585 };
16586 int typebits;
16587
dcbf9037
JB
16588 if (et.type == NT_invtype)
16589 return;
16590
5287ad62
JB
16591 if (inst.operands[1].immisalign)
16592 switch (inst.operands[1].imm >> 8)
16593 {
16594 case 64: alignbits = 1; break;
16595 case 128:
477330fc 16596 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16597 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16598 goto bad_alignment;
16599 alignbits = 2;
16600 break;
5287ad62 16601 case 256:
477330fc
RM
16602 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16603 goto bad_alignment;
16604 alignbits = 3;
16605 break;
5287ad62
JB
16606 default:
16607 bad_alignment:
477330fc
RM
16608 first_error (_("bad alignment"));
16609 return;
5287ad62
JB
16610 }
16611
16612 inst.instruction |= alignbits << 4;
16613 inst.instruction |= neon_logbits (et.size) << 6;
16614
16615 /* Bits [4:6] of the immediate in a list specifier encode register stride
16616 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16617 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16618 up the right value for "type" in a table based on this value and the given
16619 list style, then stick it back. */
16620 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16621 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16622
16623 typebits = typetable[idx];
5f4273c7 16624
5287ad62 16625 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16626 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16627 _("bad element type for instruction"));
5287ad62
JB
16628
16629 inst.instruction &= ~0xf00;
16630 inst.instruction |= typebits << 8;
16631}
16632
16633/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16634 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16635 otherwise. The variable arguments are a list of pairs of legal (size, align)
16636 values, terminated with -1. */
16637
16638static int
16639neon_alignment_bit (int size, int align, int *do_align, ...)
16640{
16641 va_list ap;
16642 int result = FAIL, thissize, thisalign;
5f4273c7 16643
5287ad62
JB
16644 if (!inst.operands[1].immisalign)
16645 {
16646 *do_align = 0;
16647 return SUCCESS;
16648 }
5f4273c7 16649
5287ad62
JB
16650 va_start (ap, do_align);
16651
16652 do
16653 {
16654 thissize = va_arg (ap, int);
16655 if (thissize == -1)
477330fc 16656 break;
5287ad62
JB
16657 thisalign = va_arg (ap, int);
16658
16659 if (size == thissize && align == thisalign)
477330fc 16660 result = SUCCESS;
5287ad62
JB
16661 }
16662 while (result != SUCCESS);
16663
16664 va_end (ap);
16665
16666 if (result == SUCCESS)
16667 *do_align = 1;
16668 else
dcbf9037 16669 first_error (_("unsupported alignment for instruction"));
5f4273c7 16670
5287ad62
JB
16671 return result;
16672}
16673
16674static void
16675do_neon_ld_st_lane (void)
16676{
037e8744 16677 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16678 int align_good, do_align = 0;
16679 int logsize = neon_logbits (et.size);
16680 int align = inst.operands[1].imm >> 8;
16681 int n = (inst.instruction >> 8) & 3;
16682 int max_el = 64 / et.size;
5f4273c7 16683
dcbf9037
JB
16684 if (et.type == NT_invtype)
16685 return;
5f4273c7 16686
5287ad62 16687 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16688 _("bad list length"));
5287ad62 16689 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16690 _("scalar index out of range"));
5287ad62 16691 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16692 && et.size == 8,
16693 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16694
5287ad62
JB
16695 switch (n)
16696 {
16697 case 0: /* VLD1 / VST1. */
16698 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
477330fc 16699 32, 32, -1);
5287ad62 16700 if (align_good == FAIL)
477330fc 16701 return;
5287ad62 16702 if (do_align)
477330fc
RM
16703 {
16704 unsigned alignbits = 0;
16705 switch (et.size)
16706 {
16707 case 16: alignbits = 0x1; break;
16708 case 32: alignbits = 0x3; break;
16709 default: ;
16710 }
16711 inst.instruction |= alignbits << 4;
16712 }
5287ad62
JB
16713 break;
16714
16715 case 1: /* VLD2 / VST2. */
16716 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
477330fc 16717 32, 64, -1);
5287ad62 16718 if (align_good == FAIL)
477330fc 16719 return;
5287ad62 16720 if (do_align)
477330fc 16721 inst.instruction |= 1 << 4;
5287ad62
JB
16722 break;
16723
16724 case 2: /* VLD3 / VST3. */
16725 constraint (inst.operands[1].immisalign,
477330fc 16726 _("can't use alignment with this instruction"));
5287ad62
JB
16727 break;
16728
16729 case 3: /* VLD4 / VST4. */
16730 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
477330fc 16731 16, 64, 32, 64, 32, 128, -1);
5287ad62 16732 if (align_good == FAIL)
477330fc 16733 return;
5287ad62 16734 if (do_align)
477330fc
RM
16735 {
16736 unsigned alignbits = 0;
16737 switch (et.size)
16738 {
16739 case 8: alignbits = 0x1; break;
16740 case 16: alignbits = 0x1; break;
16741 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16742 default: ;
16743 }
16744 inst.instruction |= alignbits << 4;
16745 }
5287ad62
JB
16746 break;
16747
16748 default: ;
16749 }
16750
16751 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16752 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16753 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16754
5287ad62
JB
16755 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16756 inst.instruction |= logsize << 10;
16757}
16758
16759/* Encode single n-element structure to all lanes VLD<n> instructions. */
16760
16761static void
16762do_neon_ld_dup (void)
16763{
037e8744 16764 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16765 int align_good, do_align = 0;
16766
dcbf9037
JB
16767 if (et.type == NT_invtype)
16768 return;
16769
5287ad62
JB
16770 switch ((inst.instruction >> 8) & 3)
16771 {
16772 case 0: /* VLD1. */
9c2799c2 16773 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16774 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16775 &do_align, 16, 16, 32, 32, -1);
5287ad62 16776 if (align_good == FAIL)
477330fc 16777 return;
5287ad62 16778 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16779 {
16780 case 1: break;
16781 case 2: inst.instruction |= 1 << 5; break;
16782 default: first_error (_("bad list length")); return;
16783 }
5287ad62
JB
16784 inst.instruction |= neon_logbits (et.size) << 6;
16785 break;
16786
16787 case 1: /* VLD2. */
16788 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16789 &do_align, 8, 16, 16, 32, 32, 64, -1);
5287ad62 16790 if (align_good == FAIL)
477330fc 16791 return;
5287ad62 16792 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16793 _("bad list length"));
5287ad62 16794 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16795 inst.instruction |= 1 << 5;
5287ad62
JB
16796 inst.instruction |= neon_logbits (et.size) << 6;
16797 break;
16798
16799 case 2: /* VLD3. */
16800 constraint (inst.operands[1].immisalign,
477330fc 16801 _("can't use alignment with this instruction"));
5287ad62 16802 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16803 _("bad list length"));
5287ad62 16804 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16805 inst.instruction |= 1 << 5;
5287ad62
JB
16806 inst.instruction |= neon_logbits (et.size) << 6;
16807 break;
16808
16809 case 3: /* VLD4. */
16810 {
477330fc
RM
16811 int align = inst.operands[1].imm >> 8;
16812 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16813 16, 64, 32, 64, 32, 128, -1);
16814 if (align_good == FAIL)
16815 return;
16816 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16817 _("bad list length"));
16818 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16819 inst.instruction |= 1 << 5;
16820 if (et.size == 32 && align == 128)
16821 inst.instruction |= 0x3 << 6;
16822 else
16823 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16824 }
16825 break;
16826
16827 default: ;
16828 }
16829
16830 inst.instruction |= do_align << 4;
16831}
16832
16833/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16834 apart from bits [11:4]. */
16835
16836static void
16837do_neon_ldx_stx (void)
16838{
b1a769ed
DG
16839 if (inst.operands[1].isreg)
16840 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16841
5287ad62
JB
16842 switch (NEON_LANE (inst.operands[0].imm))
16843 {
16844 case NEON_INTERLEAVE_LANES:
88714cb8 16845 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16846 do_neon_ld_st_interleave ();
16847 break;
5f4273c7 16848
5287ad62 16849 case NEON_ALL_LANES:
88714cb8 16850 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16851 if (inst.instruction == N_INV)
16852 {
16853 first_error ("only loads support such operands");
16854 break;
16855 }
5287ad62
JB
16856 do_neon_ld_dup ();
16857 break;
5f4273c7 16858
5287ad62 16859 default:
88714cb8 16860 NEON_ENCODE (LANE, inst);
5287ad62
JB
16861 do_neon_ld_st_lane ();
16862 }
16863
16864 /* L bit comes from bit mask. */
16865 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16866 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16867 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16868
5287ad62
JB
16869 if (inst.operands[1].postind)
16870 {
16871 int postreg = inst.operands[1].imm & 0xf;
16872 constraint (!inst.operands[1].immisreg,
477330fc 16873 _("post-index must be a register"));
5287ad62 16874 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16875 _("bad register for post-index"));
5287ad62
JB
16876 inst.instruction |= postreg;
16877 }
4f2374c7 16878 else
5287ad62 16879 {
4f2374c7
WN
16880 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16881 constraint (inst.reloc.exp.X_op != O_constant
16882 || inst.reloc.exp.X_add_number != 0,
16883 BAD_ADDR_MODE);
16884
16885 if (inst.operands[1].writeback)
16886 {
16887 inst.instruction |= 0xd;
16888 }
16889 else
16890 inst.instruction |= 0xf;
5287ad62 16891 }
5f4273c7 16892
5287ad62
JB
16893 if (thumb_mode)
16894 inst.instruction |= 0xf9000000;
16895 else
16896 inst.instruction |= 0xf4000000;
16897}
33399f07
MGD
16898
16899/* FP v8. */
16900static void
16901do_vfp_nsyn_fpv8 (enum neon_shape rs)
16902{
a715796b
TG
16903 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16904 D register operands. */
16905 if (neon_shape_class[rs] == SC_DOUBLE)
16906 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16907 _(BAD_FPU));
16908
33399f07
MGD
16909 NEON_ENCODE (FPV8, inst);
16910
9db2f6b4
RL
16911 if (rs == NS_FFF || rs == NS_HHH)
16912 {
16913 do_vfp_sp_dyadic ();
16914
16915 /* ARMv8.2 fp16 instruction. */
16916 if (rs == NS_HHH)
16917 do_scalar_fp16_v82_encode ();
16918 }
33399f07
MGD
16919 else
16920 do_vfp_dp_rd_rn_rm ();
16921
16922 if (rs == NS_DDD)
16923 inst.instruction |= 0x100;
16924
16925 inst.instruction |= 0xf0000000;
16926}
16927
16928static void
16929do_vsel (void)
16930{
16931 set_it_insn_type (OUTSIDE_IT_INSN);
16932
16933 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16934 first_error (_("invalid instruction shape"));
16935}
16936
73924fbc
MGD
16937static void
16938do_vmaxnm (void)
16939{
16940 set_it_insn_type (OUTSIDE_IT_INSN);
16941
16942 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16943 return;
16944
16945 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16946 return;
16947
16948 neon_dyadic_misc (NT_untyped, N_F32, 0);
16949}
16950
30bdf752
MGD
16951static void
16952do_vrint_1 (enum neon_cvt_mode mode)
16953{
9db2f6b4 16954 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
16955 struct neon_type_el et;
16956
16957 if (rs == NS_NULL)
16958 return;
16959
a715796b
TG
16960 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16961 D register operands. */
16962 if (neon_shape_class[rs] == SC_DOUBLE)
16963 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16964 _(BAD_FPU));
16965
9db2f6b4
RL
16966 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
16967 | N_VFP);
30bdf752
MGD
16968 if (et.type != NT_invtype)
16969 {
16970 /* VFP encodings. */
16971 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16972 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16973 set_it_insn_type (OUTSIDE_IT_INSN);
16974
16975 NEON_ENCODE (FPV8, inst);
9db2f6b4 16976 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
16977 do_vfp_sp_monadic ();
16978 else
16979 do_vfp_dp_rd_rm ();
16980
16981 switch (mode)
16982 {
16983 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16984 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16985 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16986 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16987 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16988 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16989 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16990 default: abort ();
16991 }
16992
16993 inst.instruction |= (rs == NS_DD) << 8;
16994 do_vfp_cond_or_thumb ();
9db2f6b4
RL
16995
16996 /* ARMv8.2 fp16 vrint instruction. */
16997 if (rs == NS_HH)
16998 do_scalar_fp16_v82_encode ();
30bdf752
MGD
16999 }
17000 else
17001 {
17002 /* Neon encodings (or something broken...). */
17003 inst.error = NULL;
17004 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
17005
17006 if (et.type == NT_invtype)
17007 return;
17008
17009 set_it_insn_type (OUTSIDE_IT_INSN);
17010 NEON_ENCODE (FLOAT, inst);
17011
17012 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17013 return;
17014
17015 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17016 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17017 inst.instruction |= LOW4 (inst.operands[1].reg);
17018 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17019 inst.instruction |= neon_quad (rs) << 6;
17020 switch (mode)
17021 {
17022 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17023 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17024 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17025 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17026 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17027 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17028 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17029 default: abort ();
17030 }
17031
17032 if (thumb_mode)
17033 inst.instruction |= 0xfc000000;
17034 else
17035 inst.instruction |= 0xf0000000;
17036 }
17037}
17038
17039static void
17040do_vrintx (void)
17041{
17042 do_vrint_1 (neon_cvt_mode_x);
17043}
17044
17045static void
17046do_vrintz (void)
17047{
17048 do_vrint_1 (neon_cvt_mode_z);
17049}
17050
17051static void
17052do_vrintr (void)
17053{
17054 do_vrint_1 (neon_cvt_mode_r);
17055}
17056
17057static void
17058do_vrinta (void)
17059{
17060 do_vrint_1 (neon_cvt_mode_a);
17061}
17062
17063static void
17064do_vrintn (void)
17065{
17066 do_vrint_1 (neon_cvt_mode_n);
17067}
17068
17069static void
17070do_vrintp (void)
17071{
17072 do_vrint_1 (neon_cvt_mode_p);
17073}
17074
17075static void
17076do_vrintm (void)
17077{
17078 do_vrint_1 (neon_cvt_mode_m);
17079}
17080
91ff7894
MGD
17081/* Crypto v1 instructions. */
17082static void
17083do_crypto_2op_1 (unsigned elttype, int op)
17084{
17085 set_it_insn_type (OUTSIDE_IT_INSN);
17086
17087 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17088 == NT_invtype)
17089 return;
17090
17091 inst.error = NULL;
17092
17093 NEON_ENCODE (INTEGER, inst);
17094 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17095 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17096 inst.instruction |= LOW4 (inst.operands[1].reg);
17097 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17098 if (op != -1)
17099 inst.instruction |= op << 6;
17100
17101 if (thumb_mode)
17102 inst.instruction |= 0xfc000000;
17103 else
17104 inst.instruction |= 0xf0000000;
17105}
17106
48adcd8e
MGD
17107static void
17108do_crypto_3op_1 (int u, int op)
17109{
17110 set_it_insn_type (OUTSIDE_IT_INSN);
17111
17112 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17113 N_32 | N_UNT | N_KEY).type == NT_invtype)
17114 return;
17115
17116 inst.error = NULL;
17117
17118 NEON_ENCODE (INTEGER, inst);
17119 neon_three_same (1, u, 8 << op);
17120}
17121
91ff7894
MGD
17122static void
17123do_aese (void)
17124{
17125 do_crypto_2op_1 (N_8, 0);
17126}
17127
17128static void
17129do_aesd (void)
17130{
17131 do_crypto_2op_1 (N_8, 1);
17132}
17133
17134static void
17135do_aesmc (void)
17136{
17137 do_crypto_2op_1 (N_8, 2);
17138}
17139
17140static void
17141do_aesimc (void)
17142{
17143 do_crypto_2op_1 (N_8, 3);
17144}
17145
48adcd8e
MGD
17146static void
17147do_sha1c (void)
17148{
17149 do_crypto_3op_1 (0, 0);
17150}
17151
17152static void
17153do_sha1p (void)
17154{
17155 do_crypto_3op_1 (0, 1);
17156}
17157
17158static void
17159do_sha1m (void)
17160{
17161 do_crypto_3op_1 (0, 2);
17162}
17163
17164static void
17165do_sha1su0 (void)
17166{
17167 do_crypto_3op_1 (0, 3);
17168}
91ff7894 17169
48adcd8e
MGD
17170static void
17171do_sha256h (void)
17172{
17173 do_crypto_3op_1 (1, 0);
17174}
17175
17176static void
17177do_sha256h2 (void)
17178{
17179 do_crypto_3op_1 (1, 1);
17180}
17181
17182static void
17183do_sha256su1 (void)
17184{
17185 do_crypto_3op_1 (1, 2);
17186}
3c9017d2
MGD
17187
17188static void
17189do_sha1h (void)
17190{
17191 do_crypto_2op_1 (N_32, -1);
17192}
17193
17194static void
17195do_sha1su1 (void)
17196{
17197 do_crypto_2op_1 (N_32, 0);
17198}
17199
17200static void
17201do_sha256su0 (void)
17202{
17203 do_crypto_2op_1 (N_32, 1);
17204}
dd5181d5
KT
17205
17206static void
17207do_crc32_1 (unsigned int poly, unsigned int sz)
17208{
17209 unsigned int Rd = inst.operands[0].reg;
17210 unsigned int Rn = inst.operands[1].reg;
17211 unsigned int Rm = inst.operands[2].reg;
17212
17213 set_it_insn_type (OUTSIDE_IT_INSN);
17214 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17215 inst.instruction |= LOW4 (Rn) << 16;
17216 inst.instruction |= LOW4 (Rm);
17217 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17218 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17219
17220 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17221 as_warn (UNPRED_REG ("r15"));
17222 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17223 as_warn (UNPRED_REG ("r13"));
17224}
17225
17226static void
17227do_crc32b (void)
17228{
17229 do_crc32_1 (0, 0);
17230}
17231
17232static void
17233do_crc32h (void)
17234{
17235 do_crc32_1 (0, 1);
17236}
17237
17238static void
17239do_crc32w (void)
17240{
17241 do_crc32_1 (0, 2);
17242}
17243
17244static void
17245do_crc32cb (void)
17246{
17247 do_crc32_1 (1, 0);
17248}
17249
17250static void
17251do_crc32ch (void)
17252{
17253 do_crc32_1 (1, 1);
17254}
17255
17256static void
17257do_crc32cw (void)
17258{
17259 do_crc32_1 (1, 2);
17260}
17261
5287ad62
JB
17262\f
17263/* Overall per-instruction processing. */
17264
17265/* We need to be able to fix up arbitrary expressions in some statements.
17266 This is so that we can handle symbols that are an arbitrary distance from
17267 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17268 which returns part of an address in a form which will be valid for
17269 a data instruction. We do this by pushing the expression into a symbol
17270 in the expr_section, and creating a fix for that. */
17271
17272static void
17273fix_new_arm (fragS * frag,
17274 int where,
17275 short int size,
17276 expressionS * exp,
17277 int pc_rel,
17278 int reloc)
17279{
17280 fixS * new_fix;
17281
17282 switch (exp->X_op)
17283 {
17284 case O_constant:
6e7ce2cd
PB
17285 if (pc_rel)
17286 {
17287 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17288 refer to in the object file. Unfortunately for us, gas's
17289 generic expression parsing will already have folded out
17290 any use of .set foo/.type foo %function that may have
17291 been used to set type information of the target location,
17292 that's being specified symbolically. We have to presume
17293 the user knows what they are doing. */
6e7ce2cd
PB
17294 char name[16 + 8];
17295 symbolS *symbol;
17296
17297 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17298
17299 symbol = symbol_find_or_make (name);
17300 S_SET_SEGMENT (symbol, absolute_section);
17301 symbol_set_frag (symbol, &zero_address_frag);
17302 S_SET_VALUE (symbol, exp->X_add_number);
17303 exp->X_op = O_symbol;
17304 exp->X_add_symbol = symbol;
17305 exp->X_add_number = 0;
17306 }
17307 /* FALLTHROUGH */
5287ad62
JB
17308 case O_symbol:
17309 case O_add:
17310 case O_subtract:
21d799b5 17311 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17312 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17313 break;
17314
17315 default:
21d799b5 17316 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17317 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17318 break;
17319 }
17320
17321 /* Mark whether the fix is to a THUMB instruction, or an ARM
17322 instruction. */
17323 new_fix->tc_fix_data = thumb_mode;
17324}
17325
17326/* Create a frg for an instruction requiring relaxation. */
17327static void
17328output_relax_insn (void)
17329{
17330 char * to;
17331 symbolS *sym;
0110f2b8
PB
17332 int offset;
17333
6e1cb1a6
PB
17334 /* The size of the instruction is unknown, so tie the debug info to the
17335 start of the instruction. */
17336 dwarf2_emit_insn (0);
6e1cb1a6 17337
0110f2b8
PB
17338 switch (inst.reloc.exp.X_op)
17339 {
17340 case O_symbol:
17341 sym = inst.reloc.exp.X_add_symbol;
17342 offset = inst.reloc.exp.X_add_number;
17343 break;
17344 case O_constant:
17345 sym = NULL;
17346 offset = inst.reloc.exp.X_add_number;
17347 break;
17348 default:
17349 sym = make_expr_symbol (&inst.reloc.exp);
17350 offset = 0;
17351 break;
17352 }
17353 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17354 inst.relax, sym, offset, NULL/*offset, opcode*/);
17355 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17356}
17357
17358/* Write a 32-bit thumb instruction to buf. */
17359static void
17360put_thumb32_insn (char * buf, unsigned long insn)
17361{
17362 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17363 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17364}
17365
b99bd4ef 17366static void
c19d1205 17367output_inst (const char * str)
b99bd4ef 17368{
c19d1205 17369 char * to = NULL;
b99bd4ef 17370
c19d1205 17371 if (inst.error)
b99bd4ef 17372 {
c19d1205 17373 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17374 return;
17375 }
5f4273c7
NC
17376 if (inst.relax)
17377 {
17378 output_relax_insn ();
0110f2b8 17379 return;
5f4273c7 17380 }
c19d1205
ZW
17381 if (inst.size == 0)
17382 return;
b99bd4ef 17383
c19d1205 17384 to = frag_more (inst.size);
8dc2430f
NC
17385 /* PR 9814: Record the thumb mode into the current frag so that we know
17386 what type of NOP padding to use, if necessary. We override any previous
17387 setting so that if the mode has changed then the NOPS that we use will
17388 match the encoding of the last instruction in the frag. */
cd000bff 17389 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17390
17391 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17392 {
9c2799c2 17393 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17394 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17395 }
c19d1205 17396 else if (inst.size > INSN_SIZE)
b99bd4ef 17397 {
9c2799c2 17398 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17399 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17400 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17401 }
c19d1205
ZW
17402 else
17403 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17404
c19d1205
ZW
17405 if (inst.reloc.type != BFD_RELOC_UNUSED)
17406 fix_new_arm (frag_now, to - frag_now->fr_literal,
17407 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17408 inst.reloc.type);
b99bd4ef 17409
c19d1205 17410 dwarf2_emit_insn (inst.size);
c19d1205 17411}
b99bd4ef 17412
e07e6e58
NC
17413static char *
17414output_it_inst (int cond, int mask, char * to)
17415{
17416 unsigned long instruction = 0xbf00;
17417
17418 mask &= 0xf;
17419 instruction |= mask;
17420 instruction |= cond << 4;
17421
17422 if (to == NULL)
17423 {
17424 to = frag_more (2);
17425#ifdef OBJ_ELF
17426 dwarf2_emit_insn (2);
17427#endif
17428 }
17429
17430 md_number_to_chars (to, instruction, 2);
17431
17432 return to;
17433}
17434
c19d1205
ZW
17435/* Tag values used in struct asm_opcode's tag field. */
17436enum opcode_tag
17437{
17438 OT_unconditional, /* Instruction cannot be conditionalized.
17439 The ARM condition field is still 0xE. */
17440 OT_unconditionalF, /* Instruction cannot be conditionalized
17441 and carries 0xF in its ARM condition field. */
17442 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17443 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17444 suffix, others place 0xF where the condition field
17445 would be. */
c19d1205
ZW
17446 OT_cinfix3, /* Instruction takes a conditional infix,
17447 beginning at character index 3. (In
17448 unified mode, it becomes a suffix.) */
088fa78e
KH
17449 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17450 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17451 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17452 character index 3, even in unified mode. Used for
17453 legacy instructions where suffix and infix forms
17454 may be ambiguous. */
c19d1205 17455 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17456 suffix or an infix at character index 3. */
c19d1205
ZW
17457 OT_odd_infix_unc, /* This is the unconditional variant of an
17458 instruction that takes a conditional infix
17459 at an unusual position. In unified mode,
17460 this variant will accept a suffix. */
17461 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17462 are the conditional variants of instructions that
17463 take conditional infixes in unusual positions.
17464 The infix appears at character index
17465 (tag - OT_odd_infix_0). These are not accepted
17466 in unified mode. */
17467};
b99bd4ef 17468
c19d1205
ZW
17469/* Subroutine of md_assemble, responsible for looking up the primary
17470 opcode from the mnemonic the user wrote. STR points to the
17471 beginning of the mnemonic.
17472
17473 This is not simply a hash table lookup, because of conditional
17474 variants. Most instructions have conditional variants, which are
17475 expressed with a _conditional affix_ to the mnemonic. If we were
17476 to encode each conditional variant as a literal string in the opcode
17477 table, it would have approximately 20,000 entries.
17478
17479 Most mnemonics take this affix as a suffix, and in unified syntax,
17480 'most' is upgraded to 'all'. However, in the divided syntax, some
17481 instructions take the affix as an infix, notably the s-variants of
17482 the arithmetic instructions. Of those instructions, all but six
17483 have the infix appear after the third character of the mnemonic.
17484
17485 Accordingly, the algorithm for looking up primary opcodes given
17486 an identifier is:
17487
17488 1. Look up the identifier in the opcode table.
17489 If we find a match, go to step U.
17490
17491 2. Look up the last two characters of the identifier in the
17492 conditions table. If we find a match, look up the first N-2
17493 characters of the identifier in the opcode table. If we
17494 find a match, go to step CE.
17495
17496 3. Look up the fourth and fifth characters of the identifier in
17497 the conditions table. If we find a match, extract those
17498 characters from the identifier, and look up the remaining
17499 characters in the opcode table. If we find a match, go
17500 to step CM.
17501
17502 4. Fail.
17503
17504 U. Examine the tag field of the opcode structure, in case this is
17505 one of the six instructions with its conditional infix in an
17506 unusual place. If it is, the tag tells us where to find the
17507 infix; look it up in the conditions table and set inst.cond
17508 accordingly. Otherwise, this is an unconditional instruction.
17509 Again set inst.cond accordingly. Return the opcode structure.
17510
17511 CE. Examine the tag field to make sure this is an instruction that
17512 should receive a conditional suffix. If it is not, fail.
17513 Otherwise, set inst.cond from the suffix we already looked up,
17514 and return the opcode structure.
17515
17516 CM. Examine the tag field to make sure this is an instruction that
17517 should receive a conditional infix after the third character.
17518 If it is not, fail. Otherwise, undo the edits to the current
17519 line of input and proceed as for case CE. */
17520
17521static const struct asm_opcode *
17522opcode_lookup (char **str)
17523{
17524 char *end, *base;
17525 char *affix;
17526 const struct asm_opcode *opcode;
17527 const struct asm_cond *cond;
e3cb604e 17528 char save[2];
c19d1205
ZW
17529
17530 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17531 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17532 for (base = end = *str; *end != '\0'; end++)
721a8186 17533 if (*end == ' ' || *end == '.')
c19d1205 17534 break;
b99bd4ef 17535
c19d1205 17536 if (end == base)
c921be7d 17537 return NULL;
b99bd4ef 17538
5287ad62 17539 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17540 if (end[0] == '.')
b99bd4ef 17541 {
5287ad62 17542 int offset = 2;
5f4273c7 17543
267d2029 17544 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17545 use. */
267d2029 17546 if (unified_syntax && end[1] == 'w')
c19d1205 17547 inst.size_req = 4;
267d2029 17548 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17549 inst.size_req = 2;
17550 else
477330fc 17551 offset = 0;
5287ad62
JB
17552
17553 inst.vectype.elems = 0;
17554
17555 *str = end + offset;
b99bd4ef 17556
5f4273c7 17557 if (end[offset] == '.')
5287ad62 17558 {
267d2029 17559 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17560 non-unified ARM syntax mode). */
17561 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17562 return NULL;
477330fc 17563 }
5287ad62 17564 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17565 return NULL;
b99bd4ef 17566 }
c19d1205
ZW
17567 else
17568 *str = end;
b99bd4ef 17569
c19d1205 17570 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17571 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17572 end - base);
c19d1205 17573 if (opcode)
b99bd4ef 17574 {
c19d1205
ZW
17575 /* step U */
17576 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17577 {
c19d1205
ZW
17578 inst.cond = COND_ALWAYS;
17579 return opcode;
b99bd4ef 17580 }
b99bd4ef 17581
278df34e 17582 if (warn_on_deprecated && unified_syntax)
5c3696f8 17583 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17584 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17585 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17586 gas_assert (cond);
b99bd4ef 17587
c19d1205
ZW
17588 inst.cond = cond->value;
17589 return opcode;
17590 }
b99bd4ef 17591
c19d1205
ZW
17592 /* Cannot have a conditional suffix on a mnemonic of less than two
17593 characters. */
17594 if (end - base < 3)
c921be7d 17595 return NULL;
b99bd4ef 17596
c19d1205
ZW
17597 /* Look for suffixed mnemonic. */
17598 affix = end - 2;
21d799b5
NC
17599 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17600 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17601 affix - base);
c19d1205
ZW
17602 if (opcode && cond)
17603 {
17604 /* step CE */
17605 switch (opcode->tag)
17606 {
e3cb604e
PB
17607 case OT_cinfix3_legacy:
17608 /* Ignore conditional suffixes matched on infix only mnemonics. */
17609 break;
17610
c19d1205 17611 case OT_cinfix3:
088fa78e 17612 case OT_cinfix3_deprecated:
c19d1205
ZW
17613 case OT_odd_infix_unc:
17614 if (!unified_syntax)
e3cb604e 17615 return 0;
c19d1205
ZW
17616 /* else fall through */
17617
17618 case OT_csuffix:
477330fc 17619 case OT_csuffixF:
c19d1205
ZW
17620 case OT_csuf_or_in3:
17621 inst.cond = cond->value;
17622 return opcode;
17623
17624 case OT_unconditional:
17625 case OT_unconditionalF:
dfa9f0d5 17626 if (thumb_mode)
c921be7d 17627 inst.cond = cond->value;
dfa9f0d5
PB
17628 else
17629 {
c921be7d 17630 /* Delayed diagnostic. */
dfa9f0d5
PB
17631 inst.error = BAD_COND;
17632 inst.cond = COND_ALWAYS;
17633 }
c19d1205 17634 return opcode;
b99bd4ef 17635
c19d1205 17636 default:
c921be7d 17637 return NULL;
c19d1205
ZW
17638 }
17639 }
b99bd4ef 17640
c19d1205
ZW
17641 /* Cannot have a usual-position infix on a mnemonic of less than
17642 six characters (five would be a suffix). */
17643 if (end - base < 6)
c921be7d 17644 return NULL;
b99bd4ef 17645
c19d1205
ZW
17646 /* Look for infixed mnemonic in the usual position. */
17647 affix = base + 3;
21d799b5 17648 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17649 if (!cond)
c921be7d 17650 return NULL;
e3cb604e
PB
17651
17652 memcpy (save, affix, 2);
17653 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17654 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17655 (end - base) - 2);
e3cb604e
PB
17656 memmove (affix + 2, affix, (end - affix) - 2);
17657 memcpy (affix, save, 2);
17658
088fa78e
KH
17659 if (opcode
17660 && (opcode->tag == OT_cinfix3
17661 || opcode->tag == OT_cinfix3_deprecated
17662 || opcode->tag == OT_csuf_or_in3
17663 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17664 {
c921be7d 17665 /* Step CM. */
278df34e 17666 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17667 && (opcode->tag == OT_cinfix3
17668 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17669 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17670
17671 inst.cond = cond->value;
17672 return opcode;
b99bd4ef
NC
17673 }
17674
c921be7d 17675 return NULL;
b99bd4ef
NC
17676}
17677
e07e6e58
NC
17678/* This function generates an initial IT instruction, leaving its block
17679 virtually open for the new instructions. Eventually,
17680 the mask will be updated by now_it_add_mask () each time
17681 a new instruction needs to be included in the IT block.
17682 Finally, the block is closed with close_automatic_it_block ().
17683 The block closure can be requested either from md_assemble (),
17684 a tencode (), or due to a label hook. */
17685
17686static void
17687new_automatic_it_block (int cond)
17688{
17689 now_it.state = AUTOMATIC_IT_BLOCK;
17690 now_it.mask = 0x18;
17691 now_it.cc = cond;
17692 now_it.block_length = 1;
cd000bff 17693 mapping_state (MAP_THUMB);
e07e6e58 17694 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17695 now_it.warn_deprecated = FALSE;
17696 now_it.insn_cond = TRUE;
e07e6e58
NC
17697}
17698
17699/* Close an automatic IT block.
17700 See comments in new_automatic_it_block (). */
17701
17702static void
17703close_automatic_it_block (void)
17704{
17705 now_it.mask = 0x10;
17706 now_it.block_length = 0;
17707}
17708
17709/* Update the mask of the current automatically-generated IT
17710 instruction. See comments in new_automatic_it_block (). */
17711
17712static void
17713now_it_add_mask (int cond)
17714{
17715#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17716#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17717 | ((bitvalue) << (nbit)))
e07e6e58 17718 const int resulting_bit = (cond & 1);
c921be7d 17719
e07e6e58
NC
17720 now_it.mask &= 0xf;
17721 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17722 resulting_bit,
17723 (5 - now_it.block_length));
e07e6e58 17724 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17725 1,
17726 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17727 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17728
17729#undef CLEAR_BIT
17730#undef SET_BIT_VALUE
e07e6e58
NC
17731}
17732
17733/* The IT blocks handling machinery is accessed through the these functions:
17734 it_fsm_pre_encode () from md_assemble ()
17735 set_it_insn_type () optional, from the tencode functions
17736 set_it_insn_type_last () ditto
17737 in_it_block () ditto
17738 it_fsm_post_encode () from md_assemble ()
17739 force_automatic_it_block_close () from label habdling functions
17740
17741 Rationale:
17742 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17743 initializing the IT insn type with a generic initial value depending
17744 on the inst.condition.
e07e6e58 17745 2) During the tencode function, two things may happen:
477330fc
RM
17746 a) The tencode function overrides the IT insn type by
17747 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17748 b) The tencode function queries the IT block state by
17749 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17750
17751 Both set_it_insn_type and in_it_block run the internal FSM state
17752 handling function (handle_it_state), because: a) setting the IT insn
17753 type may incur in an invalid state (exiting the function),
17754 and b) querying the state requires the FSM to be updated.
17755 Specifically we want to avoid creating an IT block for conditional
17756 branches, so it_fsm_pre_encode is actually a guess and we can't
17757 determine whether an IT block is required until the tencode () routine
17758 has decided what type of instruction this actually it.
17759 Because of this, if set_it_insn_type and in_it_block have to be used,
17760 set_it_insn_type has to be called first.
17761
17762 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17763 determines the insn IT type depending on the inst.cond code.
17764 When a tencode () routine encodes an instruction that can be
17765 either outside an IT block, or, in the case of being inside, has to be
17766 the last one, set_it_insn_type_last () will determine the proper
17767 IT instruction type based on the inst.cond code. Otherwise,
17768 set_it_insn_type can be called for overriding that logic or
17769 for covering other cases.
17770
17771 Calling handle_it_state () may not transition the IT block state to
17772 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17773 still queried. Instead, if the FSM determines that the state should
17774 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17775 after the tencode () function: that's what it_fsm_post_encode () does.
17776
17777 Since in_it_block () calls the state handling function to get an
17778 updated state, an error may occur (due to invalid insns combination).
17779 In that case, inst.error is set.
17780 Therefore, inst.error has to be checked after the execution of
17781 the tencode () routine.
e07e6e58
NC
17782
17783 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17784 any pending state change (if any) that didn't take place in
17785 handle_it_state () as explained above. */
e07e6e58
NC
17786
17787static void
17788it_fsm_pre_encode (void)
17789{
17790 if (inst.cond != COND_ALWAYS)
17791 inst.it_insn_type = INSIDE_IT_INSN;
17792 else
17793 inst.it_insn_type = OUTSIDE_IT_INSN;
17794
17795 now_it.state_handled = 0;
17796}
17797
17798/* IT state FSM handling function. */
17799
17800static int
17801handle_it_state (void)
17802{
17803 now_it.state_handled = 1;
5a01bb1d 17804 now_it.insn_cond = FALSE;
e07e6e58
NC
17805
17806 switch (now_it.state)
17807 {
17808 case OUTSIDE_IT_BLOCK:
17809 switch (inst.it_insn_type)
17810 {
17811 case OUTSIDE_IT_INSN:
17812 break;
17813
17814 case INSIDE_IT_INSN:
17815 case INSIDE_IT_LAST_INSN:
17816 if (thumb_mode == 0)
17817 {
c921be7d 17818 if (unified_syntax
e07e6e58
NC
17819 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17820 as_tsktsk (_("Warning: conditional outside an IT block"\
17821 " for Thumb."));
17822 }
17823 else
17824 {
17825 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 17826 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
17827 {
17828 /* Automatically generate the IT instruction. */
17829 new_automatic_it_block (inst.cond);
17830 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17831 close_automatic_it_block ();
17832 }
17833 else
17834 {
17835 inst.error = BAD_OUT_IT;
17836 return FAIL;
17837 }
17838 }
17839 break;
17840
17841 case IF_INSIDE_IT_LAST_INSN:
17842 case NEUTRAL_IT_INSN:
17843 break;
17844
17845 case IT_INSN:
17846 now_it.state = MANUAL_IT_BLOCK;
17847 now_it.block_length = 0;
17848 break;
17849 }
17850 break;
17851
17852 case AUTOMATIC_IT_BLOCK:
17853 /* Three things may happen now:
17854 a) We should increment current it block size;
17855 b) We should close current it block (closing insn or 4 insns);
17856 c) We should close current it block and start a new one (due
17857 to incompatible conditions or
17858 4 insns-length block reached). */
17859
17860 switch (inst.it_insn_type)
17861 {
17862 case OUTSIDE_IT_INSN:
17863 /* The closure of the block shall happen immediatelly,
17864 so any in_it_block () call reports the block as closed. */
17865 force_automatic_it_block_close ();
17866 break;
17867
17868 case INSIDE_IT_INSN:
17869 case INSIDE_IT_LAST_INSN:
17870 case IF_INSIDE_IT_LAST_INSN:
17871 now_it.block_length++;
17872
17873 if (now_it.block_length > 4
17874 || !now_it_compatible (inst.cond))
17875 {
17876 force_automatic_it_block_close ();
17877 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17878 new_automatic_it_block (inst.cond);
17879 }
17880 else
17881 {
5a01bb1d 17882 now_it.insn_cond = TRUE;
e07e6e58
NC
17883 now_it_add_mask (inst.cond);
17884 }
17885
17886 if (now_it.state == AUTOMATIC_IT_BLOCK
17887 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17888 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17889 close_automatic_it_block ();
17890 break;
17891
17892 case NEUTRAL_IT_INSN:
17893 now_it.block_length++;
5a01bb1d 17894 now_it.insn_cond = TRUE;
e07e6e58
NC
17895
17896 if (now_it.block_length > 4)
17897 force_automatic_it_block_close ();
17898 else
17899 now_it_add_mask (now_it.cc & 1);
17900 break;
17901
17902 case IT_INSN:
17903 close_automatic_it_block ();
17904 now_it.state = MANUAL_IT_BLOCK;
17905 break;
17906 }
17907 break;
17908
17909 case MANUAL_IT_BLOCK:
17910 {
17911 /* Check conditional suffixes. */
17912 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17913 int is_last;
17914 now_it.mask <<= 1;
17915 now_it.mask &= 0x1f;
17916 is_last = (now_it.mask == 0x10);
5a01bb1d 17917 now_it.insn_cond = TRUE;
e07e6e58
NC
17918
17919 switch (inst.it_insn_type)
17920 {
17921 case OUTSIDE_IT_INSN:
17922 inst.error = BAD_NOT_IT;
17923 return FAIL;
17924
17925 case INSIDE_IT_INSN:
17926 if (cond != inst.cond)
17927 {
17928 inst.error = BAD_IT_COND;
17929 return FAIL;
17930 }
17931 break;
17932
17933 case INSIDE_IT_LAST_INSN:
17934 case IF_INSIDE_IT_LAST_INSN:
17935 if (cond != inst.cond)
17936 {
17937 inst.error = BAD_IT_COND;
17938 return FAIL;
17939 }
17940 if (!is_last)
17941 {
17942 inst.error = BAD_BRANCH;
17943 return FAIL;
17944 }
17945 break;
17946
17947 case NEUTRAL_IT_INSN:
17948 /* The BKPT instruction is unconditional even in an IT block. */
17949 break;
17950
17951 case IT_INSN:
17952 inst.error = BAD_IT_IT;
17953 return FAIL;
17954 }
17955 }
17956 break;
17957 }
17958
17959 return SUCCESS;
17960}
17961
5a01bb1d
MGD
17962struct depr_insn_mask
17963{
17964 unsigned long pattern;
17965 unsigned long mask;
17966 const char* description;
17967};
17968
17969/* List of 16-bit instruction patterns deprecated in an IT block in
17970 ARMv8. */
17971static const struct depr_insn_mask depr_it_insns[] = {
17972 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17973 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17974 { 0xa000, 0xb800, N_("ADR") },
17975 { 0x4800, 0xf800, N_("Literal loads") },
17976 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17977 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
17978 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
17979 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
17980 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
17981 { 0, 0, NULL }
17982};
17983
e07e6e58
NC
17984static void
17985it_fsm_post_encode (void)
17986{
17987 int is_last;
17988
17989 if (!now_it.state_handled)
17990 handle_it_state ();
17991
5a01bb1d
MGD
17992 if (now_it.insn_cond
17993 && !now_it.warn_deprecated
17994 && warn_on_deprecated
17995 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17996 {
17997 if (inst.instruction >= 0x10000)
17998 {
5c3696f8 17999 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18000 "deprecated in ARMv8"));
18001 now_it.warn_deprecated = TRUE;
18002 }
18003 else
18004 {
18005 const struct depr_insn_mask *p = depr_it_insns;
18006
18007 while (p->mask != 0)
18008 {
18009 if ((inst.instruction & p->mask) == p->pattern)
18010 {
5c3696f8 18011 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18012 "of the following class are deprecated in ARMv8: "
18013 "%s"), p->description);
18014 now_it.warn_deprecated = TRUE;
18015 break;
18016 }
18017
18018 ++p;
18019 }
18020 }
18021
18022 if (now_it.block_length > 1)
18023 {
5c3696f8 18024 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18025 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18026 now_it.warn_deprecated = TRUE;
18027 }
18028 }
18029
e07e6e58
NC
18030 is_last = (now_it.mask == 0x10);
18031 if (is_last)
18032 {
18033 now_it.state = OUTSIDE_IT_BLOCK;
18034 now_it.mask = 0;
18035 }
18036}
18037
18038static void
18039force_automatic_it_block_close (void)
18040{
18041 if (now_it.state == AUTOMATIC_IT_BLOCK)
18042 {
18043 close_automatic_it_block ();
18044 now_it.state = OUTSIDE_IT_BLOCK;
18045 now_it.mask = 0;
18046 }
18047}
18048
18049static int
18050in_it_block (void)
18051{
18052 if (!now_it.state_handled)
18053 handle_it_state ();
18054
18055 return now_it.state != OUTSIDE_IT_BLOCK;
18056}
18057
ff8646ee
TP
18058/* Whether OPCODE only has T32 encoding. Since this function is only used by
18059 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18060 here, hence the "known" in the function name. */
fc289b0a
TP
18061
18062static bfd_boolean
ff8646ee 18063known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18064{
18065 /* Original Thumb-1 wide instruction. */
18066 if (opcode->tencode == do_t_blx
18067 || opcode->tencode == do_t_branch23
18068 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18069 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18070 return TRUE;
18071
ff8646ee
TP
18072 /* Wide-only instruction added to ARMv8-M. */
18073 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m)
18074 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18075 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18076 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18077 return TRUE;
18078
18079 return FALSE;
18080}
18081
18082/* Whether wide instruction variant can be used if available for a valid OPCODE
18083 in ARCH. */
18084
18085static bfd_boolean
18086t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18087{
18088 if (known_t32_only_insn (opcode))
18089 return TRUE;
18090
18091 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18092 of variant T3 of B.W is checked in do_t_branch. */
18093 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18094 && opcode->tencode == do_t_branch)
18095 return TRUE;
18096
18097 /* Wide instruction variants of all instructions with narrow *and* wide
18098 variants become available with ARMv6t2. Other opcodes are either
18099 narrow-only or wide-only and are thus available if OPCODE is valid. */
18100 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18101 return TRUE;
18102
18103 /* OPCODE with narrow only instruction variant or wide variant not
18104 available. */
fc289b0a
TP
18105 return FALSE;
18106}
18107
c19d1205
ZW
18108void
18109md_assemble (char *str)
b99bd4ef 18110{
c19d1205
ZW
18111 char *p = str;
18112 const struct asm_opcode * opcode;
b99bd4ef 18113
c19d1205
ZW
18114 /* Align the previous label if needed. */
18115 if (last_label_seen != NULL)
b99bd4ef 18116 {
c19d1205
ZW
18117 symbol_set_frag (last_label_seen, frag_now);
18118 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18119 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18120 }
18121
c19d1205
ZW
18122 memset (&inst, '\0', sizeof (inst));
18123 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18124
c19d1205
ZW
18125 opcode = opcode_lookup (&p);
18126 if (!opcode)
b99bd4ef 18127 {
c19d1205 18128 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18129 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18130 if (! create_register_alias (str, p)
477330fc 18131 && ! create_neon_reg_alias (str, p))
c19d1205 18132 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18133
b99bd4ef
NC
18134 return;
18135 }
18136
278df34e 18137 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18138 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18139
037e8744
JB
18140 /* The value which unconditional instructions should have in place of the
18141 condition field. */
18142 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18143
c19d1205 18144 if (thumb_mode)
b99bd4ef 18145 {
e74cfd16 18146 arm_feature_set variant;
8f06b2d8
PB
18147
18148 variant = cpu_variant;
18149 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18150 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18151 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18152 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18153 if (!opcode->tvariant
18154 || (thumb_mode == 1
18155 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18156 {
84b52b66 18157 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18158 return;
18159 }
c19d1205
ZW
18160 if (inst.cond != COND_ALWAYS && !unified_syntax
18161 && opcode->tencode != do_t_branch)
b99bd4ef 18162 {
c19d1205 18163 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18164 return;
18165 }
18166
fc289b0a
TP
18167 /* Two things are addressed here:
18168 1) Implicit require narrow instructions on Thumb-1.
18169 This avoids relaxation accidentally introducing Thumb-2
18170 instructions.
18171 2) Reject wide instructions in non Thumb-2 cores.
18172
18173 Only instructions with narrow and wide variants need to be handled
18174 but selecting all non wide-only instructions is easier. */
18175 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18176 && !t32_insn_ok (variant, opcode))
076d447c 18177 {
fc289b0a
TP
18178 if (inst.size_req == 0)
18179 inst.size_req = 2;
18180 else if (inst.size_req == 4)
752d5da4 18181 {
ff8646ee
TP
18182 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18183 as_bad (_("selected processor does not support 32bit wide "
18184 "variant of instruction `%s'"), str);
18185 else
18186 as_bad (_("selected processor does not support `%s' in "
18187 "Thumb-2 mode"), str);
fc289b0a 18188 return;
752d5da4 18189 }
076d447c
PB
18190 }
18191
c19d1205
ZW
18192 inst.instruction = opcode->tvalue;
18193
5be8be5d 18194 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18195 {
18196 /* Prepare the it_insn_type for those encodings that don't set
18197 it. */
18198 it_fsm_pre_encode ();
c19d1205 18199
477330fc 18200 opcode->tencode ();
e07e6e58 18201
477330fc
RM
18202 it_fsm_post_encode ();
18203 }
e27ec89e 18204
0110f2b8 18205 if (!(inst.error || inst.relax))
b99bd4ef 18206 {
9c2799c2 18207 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18208 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18209 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18210 {
c19d1205 18211 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18212 return;
18213 }
18214 }
076d447c
PB
18215
18216 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18217 instruction. */
9c2799c2 18218 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18219
e74cfd16
PB
18220 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18221 *opcode->tvariant);
ee065d83 18222 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18223 set those bits when Thumb-2 32-bit instructions are seen. The impact
18224 of relaxable instructions will be considered later after we finish all
18225 relaxation. */
ff8646ee
TP
18226 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18227 variant = arm_arch_none;
18228 else
18229 variant = cpu_variant;
18230 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18231 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18232 arm_ext_v6t2);
cd000bff 18233
88714cb8
DG
18234 check_neon_suffixes;
18235
cd000bff 18236 if (!inst.error)
c877a2f2
NC
18237 {
18238 mapping_state (MAP_THUMB);
18239 }
c19d1205 18240 }
3e9e4fcf 18241 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18242 {
845b51d6
PB
18243 bfd_boolean is_bx;
18244
18245 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18246 is_bx = (opcode->aencode == do_bx);
18247
c19d1205 18248 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18249 if (!(is_bx && fix_v4bx)
18250 && !(opcode->avariant &&
18251 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18252 {
84b52b66 18253 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18254 return;
b99bd4ef 18255 }
c19d1205 18256 if (inst.size_req)
b99bd4ef 18257 {
c19d1205
ZW
18258 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18259 return;
b99bd4ef
NC
18260 }
18261
c19d1205
ZW
18262 inst.instruction = opcode->avalue;
18263 if (opcode->tag == OT_unconditionalF)
eff0bc54 18264 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18265 else
18266 inst.instruction |= inst.cond << 28;
18267 inst.size = INSN_SIZE;
5be8be5d 18268 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18269 {
18270 it_fsm_pre_encode ();
18271 opcode->aencode ();
18272 it_fsm_post_encode ();
18273 }
ee065d83 18274 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18275 on a hypothetical non-thumb v5 core. */
845b51d6 18276 if (is_bx)
e74cfd16 18277 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18278 else
e74cfd16
PB
18279 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18280 *opcode->avariant);
88714cb8
DG
18281
18282 check_neon_suffixes;
18283
cd000bff 18284 if (!inst.error)
c877a2f2
NC
18285 {
18286 mapping_state (MAP_ARM);
18287 }
b99bd4ef 18288 }
3e9e4fcf
JB
18289 else
18290 {
18291 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18292 "-- `%s'"), str);
18293 return;
18294 }
c19d1205
ZW
18295 output_inst (str);
18296}
b99bd4ef 18297
e07e6e58
NC
18298static void
18299check_it_blocks_finished (void)
18300{
18301#ifdef OBJ_ELF
18302 asection *sect;
18303
18304 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18305 if (seg_info (sect)->tc_segment_info_data.current_it.state
18306 == MANUAL_IT_BLOCK)
18307 {
18308 as_warn (_("section '%s' finished with an open IT block."),
18309 sect->name);
18310 }
18311#else
18312 if (now_it.state == MANUAL_IT_BLOCK)
18313 as_warn (_("file finished with an open IT block."));
18314#endif
18315}
18316
c19d1205
ZW
18317/* Various frobbings of labels and their addresses. */
18318
18319void
18320arm_start_line_hook (void)
18321{
18322 last_label_seen = NULL;
b99bd4ef
NC
18323}
18324
c19d1205
ZW
18325void
18326arm_frob_label (symbolS * sym)
b99bd4ef 18327{
c19d1205 18328 last_label_seen = sym;
b99bd4ef 18329
c19d1205 18330 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18331
c19d1205
ZW
18332#if defined OBJ_COFF || defined OBJ_ELF
18333 ARM_SET_INTERWORK (sym, support_interwork);
18334#endif
b99bd4ef 18335
e07e6e58
NC
18336 force_automatic_it_block_close ();
18337
5f4273c7 18338 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18339 as Thumb functions. This is because these labels, whilst
18340 they exist inside Thumb code, are not the entry points for
18341 possible ARM->Thumb calls. Also, these labels can be used
18342 as part of a computed goto or switch statement. eg gcc
18343 can generate code that looks like this:
b99bd4ef 18344
c19d1205
ZW
18345 ldr r2, [pc, .Laaa]
18346 lsl r3, r3, #2
18347 ldr r2, [r3, r2]
18348 mov pc, r2
b99bd4ef 18349
c19d1205
ZW
18350 .Lbbb: .word .Lxxx
18351 .Lccc: .word .Lyyy
18352 ..etc...
18353 .Laaa: .word Lbbb
b99bd4ef 18354
c19d1205
ZW
18355 The first instruction loads the address of the jump table.
18356 The second instruction converts a table index into a byte offset.
18357 The third instruction gets the jump address out of the table.
18358 The fourth instruction performs the jump.
b99bd4ef 18359
c19d1205
ZW
18360 If the address stored at .Laaa is that of a symbol which has the
18361 Thumb_Func bit set, then the linker will arrange for this address
18362 to have the bottom bit set, which in turn would mean that the
18363 address computation performed by the third instruction would end
18364 up with the bottom bit set. Since the ARM is capable of unaligned
18365 word loads, the instruction would then load the incorrect address
18366 out of the jump table, and chaos would ensue. */
18367 if (label_is_thumb_function_name
18368 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18369 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18370 {
c19d1205
ZW
18371 /* When the address of a Thumb function is taken the bottom
18372 bit of that address should be set. This will allow
18373 interworking between Arm and Thumb functions to work
18374 correctly. */
b99bd4ef 18375
c19d1205 18376 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18377
c19d1205 18378 label_is_thumb_function_name = FALSE;
b99bd4ef 18379 }
07a53e5c 18380
07a53e5c 18381 dwarf2_emit_label (sym);
b99bd4ef
NC
18382}
18383
c921be7d 18384bfd_boolean
c19d1205 18385arm_data_in_code (void)
b99bd4ef 18386{
c19d1205 18387 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18388 {
c19d1205
ZW
18389 *input_line_pointer = '/';
18390 input_line_pointer += 5;
18391 *input_line_pointer = 0;
c921be7d 18392 return TRUE;
b99bd4ef
NC
18393 }
18394
c921be7d 18395 return FALSE;
b99bd4ef
NC
18396}
18397
c19d1205
ZW
18398char *
18399arm_canonicalize_symbol_name (char * name)
b99bd4ef 18400{
c19d1205 18401 int len;
b99bd4ef 18402
c19d1205
ZW
18403 if (thumb_mode && (len = strlen (name)) > 5
18404 && streq (name + len - 5, "/data"))
18405 *(name + len - 5) = 0;
b99bd4ef 18406
c19d1205 18407 return name;
b99bd4ef 18408}
c19d1205
ZW
18409\f
18410/* Table of all register names defined by default. The user can
18411 define additional names with .req. Note that all register names
18412 should appear in both upper and lowercase variants. Some registers
18413 also have mixed-case names. */
b99bd4ef 18414
dcbf9037 18415#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18416#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18417#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18418#define REGSET(p,t) \
18419 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18420 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18421 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18422 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18423#define REGSETH(p,t) \
18424 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18425 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18426 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18427 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18428#define REGSET2(p,t) \
18429 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18430 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18431 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18432 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18433#define SPLRBANK(base,bank,t) \
18434 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18435 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18436 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18437 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18438 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18439 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18440
c19d1205 18441static const struct reg_entry reg_names[] =
7ed4c4c5 18442{
c19d1205
ZW
18443 /* ARM integer registers. */
18444 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18445
c19d1205
ZW
18446 /* ATPCS synonyms. */
18447 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18448 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18449 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18450
c19d1205
ZW
18451 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18452 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18453 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18454
c19d1205
ZW
18455 /* Well-known aliases. */
18456 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18457 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18458
18459 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18460 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18461
18462 /* Coprocessor numbers. */
18463 REGSET(p, CP), REGSET(P, CP),
18464
18465 /* Coprocessor register numbers. The "cr" variants are for backward
18466 compatibility. */
18467 REGSET(c, CN), REGSET(C, CN),
18468 REGSET(cr, CN), REGSET(CR, CN),
18469
90ec0d68
MGD
18470 /* ARM banked registers. */
18471 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18472 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18473 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18474 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18475 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18476 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18477 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18478
18479 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18480 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18481 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18482 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18483 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18484 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18485 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18486 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18487
18488 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18489 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18490 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18491 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18492 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18493 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18494 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18495 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18496 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18497
c19d1205
ZW
18498 /* FPA registers. */
18499 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18500 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18501
18502 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18503 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18504
18505 /* VFP SP registers. */
5287ad62
JB
18506 REGSET(s,VFS), REGSET(S,VFS),
18507 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18508
18509 /* VFP DP Registers. */
5287ad62
JB
18510 REGSET(d,VFD), REGSET(D,VFD),
18511 /* Extra Neon DP registers. */
18512 REGSETH(d,VFD), REGSETH(D,VFD),
18513
18514 /* Neon QP registers. */
18515 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18516
18517 /* VFP control registers. */
18518 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18519 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18520 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18521 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18522 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18523 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18524
18525 /* Maverick DSP coprocessor registers. */
18526 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18527 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18528
18529 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18530 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18531 REGDEF(dspsc,0,DSPSC),
18532
18533 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18534 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18535 REGDEF(DSPSC,0,DSPSC),
18536
18537 /* iWMMXt data registers - p0, c0-15. */
18538 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18539
18540 /* iWMMXt control registers - p1, c0-3. */
18541 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18542 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18543 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18544 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18545
18546 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18547 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18548 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18549 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18550 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18551
18552 /* XScale accumulator registers. */
18553 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18554};
18555#undef REGDEF
18556#undef REGNUM
18557#undef REGSET
7ed4c4c5 18558
c19d1205
ZW
18559/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18560 within psr_required_here. */
18561static const struct asm_psr psrs[] =
18562{
18563 /* Backward compatibility notation. Note that "all" is no longer
18564 truly all possible PSR bits. */
18565 {"all", PSR_c | PSR_f},
18566 {"flg", PSR_f},
18567 {"ctl", PSR_c},
18568
18569 /* Individual flags. */
18570 {"f", PSR_f},
18571 {"c", PSR_c},
18572 {"x", PSR_x},
18573 {"s", PSR_s},
59b42a0d 18574
c19d1205
ZW
18575 /* Combinations of flags. */
18576 {"fs", PSR_f | PSR_s},
18577 {"fx", PSR_f | PSR_x},
18578 {"fc", PSR_f | PSR_c},
18579 {"sf", PSR_s | PSR_f},
18580 {"sx", PSR_s | PSR_x},
18581 {"sc", PSR_s | PSR_c},
18582 {"xf", PSR_x | PSR_f},
18583 {"xs", PSR_x | PSR_s},
18584 {"xc", PSR_x | PSR_c},
18585 {"cf", PSR_c | PSR_f},
18586 {"cs", PSR_c | PSR_s},
18587 {"cx", PSR_c | PSR_x},
18588 {"fsx", PSR_f | PSR_s | PSR_x},
18589 {"fsc", PSR_f | PSR_s | PSR_c},
18590 {"fxs", PSR_f | PSR_x | PSR_s},
18591 {"fxc", PSR_f | PSR_x | PSR_c},
18592 {"fcs", PSR_f | PSR_c | PSR_s},
18593 {"fcx", PSR_f | PSR_c | PSR_x},
18594 {"sfx", PSR_s | PSR_f | PSR_x},
18595 {"sfc", PSR_s | PSR_f | PSR_c},
18596 {"sxf", PSR_s | PSR_x | PSR_f},
18597 {"sxc", PSR_s | PSR_x | PSR_c},
18598 {"scf", PSR_s | PSR_c | PSR_f},
18599 {"scx", PSR_s | PSR_c | PSR_x},
18600 {"xfs", PSR_x | PSR_f | PSR_s},
18601 {"xfc", PSR_x | PSR_f | PSR_c},
18602 {"xsf", PSR_x | PSR_s | PSR_f},
18603 {"xsc", PSR_x | PSR_s | PSR_c},
18604 {"xcf", PSR_x | PSR_c | PSR_f},
18605 {"xcs", PSR_x | PSR_c | PSR_s},
18606 {"cfs", PSR_c | PSR_f | PSR_s},
18607 {"cfx", PSR_c | PSR_f | PSR_x},
18608 {"csf", PSR_c | PSR_s | PSR_f},
18609 {"csx", PSR_c | PSR_s | PSR_x},
18610 {"cxf", PSR_c | PSR_x | PSR_f},
18611 {"cxs", PSR_c | PSR_x | PSR_s},
18612 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18613 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18614 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18615 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18616 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18617 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18618 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18619 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18620 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18621 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18622 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18623 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18624 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18625 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18626 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18627 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18628 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18629 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18630 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18631 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18632 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18633 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18634 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18635 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18636};
18637
62b3e311
PB
18638/* Table of V7M psr names. */
18639static const struct asm_psr v7m_psrs[] =
18640{
2b744c99
PB
18641 {"apsr", 0 }, {"APSR", 0 },
18642 {"iapsr", 1 }, {"IAPSR", 1 },
18643 {"eapsr", 2 }, {"EAPSR", 2 },
18644 {"psr", 3 }, {"PSR", 3 },
18645 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18646 {"ipsr", 5 }, {"IPSR", 5 },
18647 {"epsr", 6 }, {"EPSR", 6 },
18648 {"iepsr", 7 }, {"IEPSR", 7 },
18649 {"msp", 8 }, {"MSP", 8 },
18650 {"psp", 9 }, {"PSP", 9 },
18651 {"primask", 16}, {"PRIMASK", 16},
18652 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18653 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18654 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18655 {"faultmask", 19}, {"FAULTMASK", 19},
18656 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18657};
18658
c19d1205
ZW
18659/* Table of all shift-in-operand names. */
18660static const struct asm_shift_name shift_names [] =
b99bd4ef 18661{
c19d1205
ZW
18662 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18663 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18664 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18665 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18666 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18667 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18668};
b99bd4ef 18669
c19d1205
ZW
18670/* Table of all explicit relocation names. */
18671#ifdef OBJ_ELF
18672static struct reloc_entry reloc_names[] =
18673{
18674 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18675 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18676 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18677 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18678 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18679 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18680 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18681 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18682 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18683 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18684 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18685 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18686 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18687 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18688 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18689 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18690 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18691 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18692};
18693#endif
b99bd4ef 18694
c19d1205
ZW
18695/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18696static const struct asm_cond conds[] =
18697{
18698 {"eq", 0x0},
18699 {"ne", 0x1},
18700 {"cs", 0x2}, {"hs", 0x2},
18701 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18702 {"mi", 0x4},
18703 {"pl", 0x5},
18704 {"vs", 0x6},
18705 {"vc", 0x7},
18706 {"hi", 0x8},
18707 {"ls", 0x9},
18708 {"ge", 0xa},
18709 {"lt", 0xb},
18710 {"gt", 0xc},
18711 {"le", 0xd},
18712 {"al", 0xe}
18713};
bfae80f2 18714
e797f7e0 18715#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18716 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18717 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18718
62b3e311
PB
18719static struct asm_barrier_opt barrier_opt_names[] =
18720{
e797f7e0
MGD
18721 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18722 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18723 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18724 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18725 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18726 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18727 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18728 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18729 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18730 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18731 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18732 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18733 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18734 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18735 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18736 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18737};
18738
e797f7e0
MGD
18739#undef UL_BARRIER
18740
c19d1205
ZW
18741/* Table of ARM-format instructions. */
18742
18743/* Macros for gluing together operand strings. N.B. In all cases
18744 other than OPS0, the trailing OP_stop comes from default
18745 zero-initialization of the unspecified elements of the array. */
18746#define OPS0() { OP_stop, }
18747#define OPS1(a) { OP_##a, }
18748#define OPS2(a,b) { OP_##a,OP_##b, }
18749#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18750#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18751#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18752#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18753
5be8be5d
DG
18754/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18755 This is useful when mixing operands for ARM and THUMB, i.e. using the
18756 MIX_ARM_THUMB_OPERANDS macro.
18757 In order to use these macros, prefix the number of operands with _
18758 e.g. _3. */
18759#define OPS_1(a) { a, }
18760#define OPS_2(a,b) { a,b, }
18761#define OPS_3(a,b,c) { a,b,c, }
18762#define OPS_4(a,b,c,d) { a,b,c,d, }
18763#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18764#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18765
c19d1205
ZW
18766/* These macros abstract out the exact format of the mnemonic table and
18767 save some repeated characters. */
18768
18769/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18770#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18771 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18772 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18773
18774/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18775 a T_MNEM_xyz enumerator. */
18776#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18777 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18778#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18779 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18780
18781/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18782 infix after the third character. */
18783#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18784 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18785 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18786#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18787 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18788 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18789#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18790 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18791#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18792 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18793#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18794 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18795#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18796 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18797
c19d1205 18798/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18799 field is still 0xE. Many of the Thumb variants can be executed
18800 conditionally, so this is checked separately. */
c19d1205 18801#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18802 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18803 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18804
dd5181d5
KT
18805/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18806 Used by mnemonics that have very minimal differences in the encoding for
18807 ARM and Thumb variants and can be handled in a common function. */
18808#define TUEc(mnem, op, top, nops, ops, en) \
18809 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18810 THUMB_VARIANT, do_##en, do_##en }
18811
c19d1205
ZW
18812/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18813 condition code field. */
18814#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18815 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18816 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18817
18818/* ARM-only variants of all the above. */
6a86118a 18819#define CE(mnem, op, nops, ops, ae) \
21d799b5 18820 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18821
18822#define C3(mnem, op, nops, ops, ae) \
18823 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18824
e3cb604e
PB
18825/* Legacy mnemonics that always have conditional infix after the third
18826 character. */
18827#define CL(mnem, op, nops, ops, ae) \
21d799b5 18828 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18829 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18830
8f06b2d8
PB
18831/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18832#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18833 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18834
e3cb604e
PB
18835/* Legacy coprocessor instructions where conditional infix and conditional
18836 suffix are ambiguous. For consistency this includes all FPA instructions,
18837 not just the potentially ambiguous ones. */
18838#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18839 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18840 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18841
18842/* Coprocessor, takes either a suffix or a position-3 infix
18843 (for an FPA corner case). */
18844#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18845 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18846 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18847
6a86118a 18848#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18849 { m1 #m2 m3, OPS##nops ops, \
18850 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18851 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18852
18853#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18854 xCM_ (m1, , m2, op, nops, ops, ae), \
18855 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18856 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18857 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18858 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18859 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18860 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18861 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18862 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18863 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18864 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18865 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18866 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18867 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18868 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18869 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18870 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18871 xCM_ (m1, le, m2, op, nops, ops, ae), \
18872 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18873
18874#define UE(mnem, op, nops, ops, ae) \
18875 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18876
18877#define UF(mnem, op, nops, ops, ae) \
18878 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18879
5287ad62
JB
18880/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18881 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18882 use the same encoding function for each. */
18883#define NUF(mnem, op, nops, ops, enc) \
18884 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18885 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18886
18887/* Neon data processing, version which indirects through neon_enc_tab for
18888 the various overloaded versions of opcodes. */
18889#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18890 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18891 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18892
18893/* Neon insn with conditional suffix for the ARM version, non-overloaded
18894 version. */
037e8744
JB
18895#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18896 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18897 THUMB_VARIANT, do_##enc, do_##enc }
18898
037e8744 18899#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18900 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18901
18902#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18903 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18904
5287ad62 18905/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18906#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18907 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18908 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18909
037e8744 18910#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18911 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18912
18913#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18914 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18915
c19d1205
ZW
18916#define do_0 0
18917
c19d1205 18918static const struct asm_opcode insns[] =
bfae80f2 18919{
74db7efb
NC
18920#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18921#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18922 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18923 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18924 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18925 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18926 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18927 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18928 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18929 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18930 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18931 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18932 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18933 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18934 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18935 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18936 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18937 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18938
18939 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18940 for setting PSR flag bits. They are obsolete in V6 and do not
18941 have Thumb equivalents. */
21d799b5
NC
18942 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18943 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18944 CL("tstp", 110f000, 2, (RR, SH), cmp),
18945 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18946 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18947 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18948 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18949 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18950 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18951
18952 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 18953 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
18954 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18955 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18956
18957 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18958 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18959 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18960 OP_RRnpc),
18961 OP_ADDRGLDR),ldst, t_ldst),
18962 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
18963
18964 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18965 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18966 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18967 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18968 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18969 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18970
18971 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18972 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18973 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18974 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 18975
c19d1205 18976 /* Pseudo ops. */
21d799b5 18977 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 18978 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 18979 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 18980 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
18981
18982 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
18983 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18984 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18985 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18986 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18987 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18988 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18989 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18990 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18991 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18992 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18993 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18994 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 18995
16a4cf17 18996 /* These may simplify to neg. */
21d799b5
NC
18997 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18998 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 18999
c921be7d
NC
19000#undef THUMB_VARIANT
19001#define THUMB_VARIANT & arm_ext_v6
19002
21d799b5 19003 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19004
19005 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19006#undef THUMB_VARIANT
19007#define THUMB_VARIANT & arm_ext_v6t2
19008
21d799b5
NC
19009 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19010 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19011 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19012
5be8be5d
DG
19013 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19014 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19015 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19016 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19017
21d799b5
NC
19018 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19019 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19020
21d799b5
NC
19021 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19022 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19023
19024 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19025 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19026 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19027
19028 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19029 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19030 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19031 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19032 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19033 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19034 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19035 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19036
c921be7d
NC
19037#undef ARM_VARIANT
19038#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19039#undef THUMB_VARIANT
19040#define THUMB_VARIANT & arm_ext_v4t
19041
21d799b5
NC
19042 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19043 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19044
c921be7d
NC
19045#undef THUMB_VARIANT
19046#define THUMB_VARIANT & arm_ext_v6t2
19047
21d799b5 19048 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19049 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19050
19051 /* Generic coprocessor instructions. */
21d799b5
NC
19052 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19053 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19054 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19055 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19056 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19057 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19058 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19059
c921be7d
NC
19060#undef ARM_VARIANT
19061#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19062
21d799b5 19063 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19064 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19065
c921be7d
NC
19066#undef ARM_VARIANT
19067#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19068#undef THUMB_VARIANT
19069#define THUMB_VARIANT & arm_ext_msr
19070
d2cd1205
JB
19071 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19072 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19073
c921be7d
NC
19074#undef ARM_VARIANT
19075#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19076#undef THUMB_VARIANT
19077#define THUMB_VARIANT & arm_ext_v6t2
19078
21d799b5
NC
19079 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19080 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19081 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19082 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19083 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19084 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19085 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19086 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19087
c921be7d
NC
19088#undef ARM_VARIANT
19089#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19090#undef THUMB_VARIANT
19091#define THUMB_VARIANT & arm_ext_v4t
19092
5be8be5d
DG
19093 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19094 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19095 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19096 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19097 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19098 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19099
c921be7d
NC
19100#undef ARM_VARIANT
19101#define ARM_VARIANT & arm_ext_v4t_5
19102
c19d1205
ZW
19103 /* ARM Architecture 4T. */
19104 /* Note: bx (and blx) are required on V5, even if the processor does
19105 not support Thumb. */
21d799b5 19106 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19107
c921be7d
NC
19108#undef ARM_VARIANT
19109#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19110#undef THUMB_VARIANT
19111#define THUMB_VARIANT & arm_ext_v5t
19112
c19d1205
ZW
19113 /* Note: blx has 2 variants; the .value coded here is for
19114 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19115 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19116 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19117
c921be7d
NC
19118#undef THUMB_VARIANT
19119#define THUMB_VARIANT & arm_ext_v6t2
19120
21d799b5
NC
19121 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19122 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19123 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19124 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19125 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19126 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19127 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19128 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19129
c921be7d 19130#undef ARM_VARIANT
74db7efb
NC
19131#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19132#undef THUMB_VARIANT
19133#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19134
21d799b5
NC
19135 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19136 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19137 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19138 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19139
21d799b5
NC
19140 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19141 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19142
21d799b5
NC
19143 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19144 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19145 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19146 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19147
21d799b5
NC
19148 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19149 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19150 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19151 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19152
21d799b5
NC
19153 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19154 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19155
03ee1b7f
NC
19156 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19157 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19158 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19159 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19160
c921be7d 19161#undef ARM_VARIANT
74db7efb
NC
19162#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19163#undef THUMB_VARIANT
19164#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19165
21d799b5 19166 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19167 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19168 ldrd, t_ldstd),
19169 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19170 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19171
21d799b5
NC
19172 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19173 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19174
c921be7d
NC
19175#undef ARM_VARIANT
19176#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19177
21d799b5 19178 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19179
c921be7d
NC
19180#undef ARM_VARIANT
19181#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19182#undef THUMB_VARIANT
19183#define THUMB_VARIANT & arm_ext_v6
19184
21d799b5
NC
19185 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19186 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19187 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19188 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19189 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19190 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19191 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19192 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19193 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19194 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19195
c921be7d 19196#undef THUMB_VARIANT
ff8646ee 19197#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19198
5be8be5d
DG
19199 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19200 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19201 strex, t_strex),
ff8646ee
TP
19202#undef THUMB_VARIANT
19203#define THUMB_VARIANT & arm_ext_v6t2
19204
21d799b5
NC
19205 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19206 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19207
21d799b5
NC
19208 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19209 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19210
9e3c6df6 19211/* ARM V6 not included in V7M. */
c921be7d
NC
19212#undef THUMB_VARIANT
19213#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19214 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19215 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19216 UF(rfeib, 9900a00, 1, (RRw), rfe),
19217 UF(rfeda, 8100a00, 1, (RRw), rfe),
19218 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19219 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19220 UF(rfefa, 8100a00, 1, (RRw), rfe),
19221 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19222 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19223 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19224 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19225 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19226 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19227 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19228 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19229 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19230 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19231 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19232 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19233
9e3c6df6
PB
19234/* ARM V6 not included in V7M (eg. integer SIMD). */
19235#undef THUMB_VARIANT
19236#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19237 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19238 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19239 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19240 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19241 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19242 /* Old name for QASX. */
74db7efb 19243 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19244 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19245 /* Old name for QSAX. */
74db7efb 19246 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19247 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19248 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19249 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19250 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19251 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19252 /* Old name for SASX. */
74db7efb 19253 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19254 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19255 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19256 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19257 /* Old name for SHASX. */
21d799b5 19258 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19259 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19260 /* Old name for SHSAX. */
21d799b5
NC
19261 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19262 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19263 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19264 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19265 /* Old name for SSAX. */
74db7efb 19266 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19267 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19268 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19269 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19270 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19271 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19272 /* Old name for UASX. */
74db7efb 19273 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19274 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19275 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19276 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19277 /* Old name for UHASX. */
21d799b5
NC
19278 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19279 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19280 /* Old name for UHSAX. */
21d799b5
NC
19281 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19282 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19283 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19284 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19285 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19286 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19287 /* Old name for UQASX. */
21d799b5
NC
19288 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19289 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19290 /* Old name for UQSAX. */
21d799b5
NC
19291 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19292 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19293 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19294 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19295 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19296 /* Old name for USAX. */
74db7efb 19297 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19298 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19299 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19300 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19301 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19302 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19303 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19304 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19305 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19306 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19307 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19308 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19309 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19310 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19311 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19312 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19313 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19314 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19315 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19316 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19317 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19318 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19319 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19320 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19321 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19322 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19323 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19324 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19325 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19326 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19327 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19328 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19329 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19330 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19331
c921be7d
NC
19332#undef ARM_VARIANT
19333#define ARM_VARIANT & arm_ext_v6k
19334#undef THUMB_VARIANT
19335#define THUMB_VARIANT & arm_ext_v6k
19336
21d799b5
NC
19337 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19338 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19339 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19340 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19341
c921be7d
NC
19342#undef THUMB_VARIANT
19343#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19344 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19345 ldrexd, t_ldrexd),
19346 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19347 RRnpcb), strexd, t_strexd),
ebdca51a 19348
c921be7d 19349#undef THUMB_VARIANT
ff8646ee 19350#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19351 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19352 rd_rn, rd_rn),
19353 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19354 rd_rn, rd_rn),
19355 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19356 strex, t_strexbh),
5be8be5d 19357 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19358 strex, t_strexbh),
21d799b5 19359 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19360
c921be7d 19361#undef ARM_VARIANT
f4c65163 19362#define ARM_VARIANT & arm_ext_sec
74db7efb 19363#undef THUMB_VARIANT
f4c65163 19364#define THUMB_VARIANT & arm_ext_sec
c921be7d 19365
21d799b5 19366 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19367
90ec0d68
MGD
19368#undef ARM_VARIANT
19369#define ARM_VARIANT & arm_ext_virt
19370#undef THUMB_VARIANT
19371#define THUMB_VARIANT & arm_ext_virt
19372
19373 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19374 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19375
ddfded2f
MW
19376#undef ARM_VARIANT
19377#define ARM_VARIANT & arm_ext_pan
19378#undef THUMB_VARIANT
19379#define THUMB_VARIANT & arm_ext_pan
19380
19381 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19382
c921be7d 19383#undef ARM_VARIANT
74db7efb 19384#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19385#undef THUMB_VARIANT
19386#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19387
21d799b5
NC
19388 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19389 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19390 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19391 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19392
21d799b5 19393 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19394 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19395
5be8be5d
DG
19396 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19397 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19398 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19399 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19400
ff8646ee
TP
19401#undef THUMB_VARIANT
19402#define THUMB_VARIANT & arm_ext_v6t2_v8m
19403 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19404 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19405
bf3eeda7 19406 /* Thumb-only instructions. */
74db7efb 19407#undef ARM_VARIANT
bf3eeda7
NS
19408#define ARM_VARIANT NULL
19409 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19410 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19411
19412 /* ARM does not really have an IT instruction, so always allow it.
19413 The opcode is copied from Thumb in order to allow warnings in
19414 -mimplicit-it=[never | arm] modes. */
19415#undef ARM_VARIANT
19416#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19417#undef THUMB_VARIANT
19418#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19419
21d799b5
NC
19420 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19421 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19422 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19423 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19424 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19425 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19426 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19427 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19428 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19429 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19430 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19431 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19432 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19433 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19434 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19435 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19436 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19437 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19438
92e90b6e 19439 /* Thumb2 only instructions. */
c921be7d
NC
19440#undef ARM_VARIANT
19441#define ARM_VARIANT NULL
92e90b6e 19442
21d799b5
NC
19443 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19444 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19445 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19446 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19447 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19448 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19449
eea54501
MGD
19450 /* Hardware division instructions. */
19451#undef ARM_VARIANT
19452#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19453#undef THUMB_VARIANT
19454#define THUMB_VARIANT & arm_ext_div
19455
eea54501
MGD
19456 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19457 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19458
7e806470 19459 /* ARM V6M/V7 instructions. */
c921be7d
NC
19460#undef ARM_VARIANT
19461#define ARM_VARIANT & arm_ext_barrier
19462#undef THUMB_VARIANT
19463#define THUMB_VARIANT & arm_ext_barrier
19464
ccb84d65
JB
19465 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19466 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19467 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19468
62b3e311 19469 /* ARM V7 instructions. */
c921be7d
NC
19470#undef ARM_VARIANT
19471#define ARM_VARIANT & arm_ext_v7
19472#undef THUMB_VARIANT
19473#define THUMB_VARIANT & arm_ext_v7
19474
21d799b5
NC
19475 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19476 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19477
74db7efb 19478#undef ARM_VARIANT
60e5ef9f 19479#define ARM_VARIANT & arm_ext_mp
74db7efb 19480#undef THUMB_VARIANT
60e5ef9f
MGD
19481#define THUMB_VARIANT & arm_ext_mp
19482
19483 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19484
53c4b28b
MGD
19485 /* AArchv8 instructions. */
19486#undef ARM_VARIANT
19487#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19488
19489/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19490#undef THUMB_VARIANT
4ed7ed8d 19491#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19492
4ed7ed8d
TP
19493 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19494 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19495 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19496 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19497 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19498 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19499 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19500 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19501 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19502 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19503 stlex, t_stlex),
4b8c8c02
RE
19504 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19505 stlex, t_stlex),
19506 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19507 stlex, t_stlex),
4ed7ed8d
TP
19508#undef THUMB_VARIANT
19509#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19510
4ed7ed8d
TP
19511 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19512 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19513 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19514 ldrexd, t_ldrexd),
19515 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19516 strexd, t_strexd),
8884b720 19517 /* ARMv8 T32 only. */
74db7efb 19518#undef ARM_VARIANT
b79f7053
MGD
19519#define ARM_VARIANT NULL
19520 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19521 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19522 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19523
33399f07
MGD
19524 /* FP for ARMv8. */
19525#undef ARM_VARIANT
a715796b 19526#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19527#undef THUMB_VARIANT
a715796b 19528#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19529
19530 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19531 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19532 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19533 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19534 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19535 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19536 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19537 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19538 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19539 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19540 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19541 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19542 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19543 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19544 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19545 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19546 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19547
91ff7894
MGD
19548 /* Crypto v1 extensions. */
19549#undef ARM_VARIANT
19550#define ARM_VARIANT & fpu_crypto_ext_armv8
19551#undef THUMB_VARIANT
19552#define THUMB_VARIANT & fpu_crypto_ext_armv8
19553
19554 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19555 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19556 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19557 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19558 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19559 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19560 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19561 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19562 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19563 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19564 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19565 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19566 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19567 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19568
dd5181d5 19569#undef ARM_VARIANT
74db7efb 19570#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19571#undef THUMB_VARIANT
19572#define THUMB_VARIANT & crc_ext_armv8
19573 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19574 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19575 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19576 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19577 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19578 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19579
105bde57
MW
19580 /* ARMv8.2 RAS extension. */
19581#undef ARM_VARIANT
19582#define ARM_VARIANT & arm_ext_v8_2
19583#undef THUMB_VARIANT
19584#define THUMB_VARIANT & arm_ext_v8_2
19585 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19586
c921be7d
NC
19587#undef ARM_VARIANT
19588#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19589#undef THUMB_VARIANT
19590#define THUMB_VARIANT NULL
c921be7d 19591
21d799b5
NC
19592 cCE("wfs", e200110, 1, (RR), rd),
19593 cCE("rfs", e300110, 1, (RR), rd),
19594 cCE("wfc", e400110, 1, (RR), rd),
19595 cCE("rfc", e500110, 1, (RR), rd),
19596
19597 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19598 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19599 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19600 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19601
19602 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19603 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19604 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19605 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19606
19607 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19608 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19609 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19610 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19611 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19612 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19613 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19614 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19615 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19616 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19617 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19618 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19619
19620 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19621 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19622 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19623 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19624 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19625 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19626 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19627 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19628 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19629 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19630 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19631 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19632
19633 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19634 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19635 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19636 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19637 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19638 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19639 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19640 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19641 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19642 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19643 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19644 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19645
19646 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19647 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19648 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19649 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19650 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19651 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19652 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19653 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19654 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19655 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19656 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19657 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19658
19659 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19660 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19661 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19662 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19663 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19664 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19665 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19666 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19667 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19668 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19669 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19670 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19671
19672 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19673 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19674 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19675 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19676 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19677 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19678 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19679 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19680 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19681 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19682 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19683 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19684
19685 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19686 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19687 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19688 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19689 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19690 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19691 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19692 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19693 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19694 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19695 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19696 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19697
19698 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19699 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19700 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19701 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19702 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19703 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19704 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19705 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19706 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19707 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19708 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19709 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19710
19711 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19712 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19713 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19714 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19715 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19716 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19717 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19718 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19719 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19720 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19721 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19722 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19723
19724 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19725 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19726 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19727 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19728 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19729 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19730 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19731 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19732 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19733 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19734 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19735 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19736
19737 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19738 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19739 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19740 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19741 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19742 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19743 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19744 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19745 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19746 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19747 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19748 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19749
19750 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19751 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19752 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19753 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19754 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19755 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19756 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19757 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19758 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19759 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19760 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19761 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19762
19763 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19764 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19765 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19766 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19767 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19768 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19769 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19770 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19771 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19772 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19773 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19774 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19775
19776 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19777 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19778 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19779 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19780 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19781 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19782 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19783 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19784 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19785 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19786 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19787 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19788
19789 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19790 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19791 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19792 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19793 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19794 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19795 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19796 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19797 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19798 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19799 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19800 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19801
19802 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19803 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19804 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19805 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19806 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19807 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19808 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19809 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19810 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19811 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19812 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19813 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19814
19815 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19816 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19817 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19818 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19819 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19820 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19821 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19822 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19823 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19824 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19825 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19826 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19827
19828 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19829 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19830 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19831 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19832 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19833 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19834 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19835 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19836 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19837 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19838 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19839 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19840
19841 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19842 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19843 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19844 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19845 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19846 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19847 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19848 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19849 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19850 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19851 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19852 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19853
19854 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19855 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19856 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19857 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19858 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19859 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19860 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19861 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19862 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19863 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19864 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19865 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19866
19867 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19868 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19869 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19870 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19871 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19872 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19873 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19874 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19875 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19876 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19877 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19878 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19879
19880 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19881 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19882 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19883 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19884 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19885 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19886 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19887 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19888 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19889 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19890 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19891 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19892
19893 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19894 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19895 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19896 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19897 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19898 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19899 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19900 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19901 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19902 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19903 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19904 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19905
19906 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19907 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19908 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19909 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19910 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19911 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19912 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19913 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19914 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19915 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19916 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19917 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19918
19919 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19920 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19921 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19922 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19923 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19924 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19925 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19926 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19927 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19928 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19929 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19930 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19931
19932 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19933 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19934 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19935 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19936 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19937 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19938 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19939 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19940 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19941 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19942 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19943 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19944
19945 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19946 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19947 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19948 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19949 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19950 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19951 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19952 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19953 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19954 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19955 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19956 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19957
19958 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19959 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19960 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19961 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19962 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19963 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19964 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19965 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19966 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19967 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19968 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19969 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19970
19971 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19972 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19973 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19974 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19975 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19976 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19977 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19978 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19979 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19980 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19981 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19982 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19983
19984 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19985 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19986 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19987 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19988
19989 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19990 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19991 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19992 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19993 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19994 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19995 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19996 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19997 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19998 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19999 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20000 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20001
c19d1205
ZW
20002 /* The implementation of the FIX instruction is broken on some
20003 assemblers, in that it accepts a precision specifier as well as a
20004 rounding specifier, despite the fact that this is meaningless.
20005 To be more compatible, we accept it as well, though of course it
20006 does not set any bits. */
21d799b5
NC
20007 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20008 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20009 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20010 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20011 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20012 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20013 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20014 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20015 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20016 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20017 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20018 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20019 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20020
c19d1205 20021 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20022#undef ARM_VARIANT
20023#define ARM_VARIANT & fpu_fpa_ext_v2
20024
21d799b5
NC
20025 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20026 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20027 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20028 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20029 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20030 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20031
c921be7d
NC
20032#undef ARM_VARIANT
20033#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20034
c19d1205 20035 /* Moves and type conversions. */
21d799b5
NC
20036 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20037 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20038 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20039 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20040 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20041 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20042 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20043 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20044 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20045 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20046 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20047 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20048 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20049 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20050
20051 /* Memory operations. */
21d799b5
NC
20052 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20053 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20054 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20055 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20056 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20057 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20058 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20059 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20060 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20061 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20062 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20063 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20064 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20065 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20066 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20067 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20068 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20069 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20070
c19d1205 20071 /* Monadic operations. */
21d799b5
NC
20072 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20073 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20074 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20075
20076 /* Dyadic operations. */
21d799b5
NC
20077 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20078 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20079 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20080 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20081 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20082 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20083 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20084 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20085 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20086
c19d1205 20087 /* Comparisons. */
21d799b5
NC
20088 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20089 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20090 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20091 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20092
62f3b8c8
PB
20093 /* Double precision load/store are still present on single precision
20094 implementations. */
20095 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20096 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20097 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20098 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20099 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20100 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20101 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20102 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20103 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20104 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20105
c921be7d
NC
20106#undef ARM_VARIANT
20107#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20108
c19d1205 20109 /* Moves and type conversions. */
21d799b5
NC
20110 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20111 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20112 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20113 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20114 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20115 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20116 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20117 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20118 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20119 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20120 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20121 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20122 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20123
c19d1205 20124 /* Monadic operations. */
21d799b5
NC
20125 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20126 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20127 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20128
20129 /* Dyadic operations. */
21d799b5
NC
20130 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20131 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20132 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20133 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20134 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20135 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20136 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20137 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20138 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20139
c19d1205 20140 /* Comparisons. */
21d799b5
NC
20141 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20142 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20143 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20144 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20145
c921be7d
NC
20146#undef ARM_VARIANT
20147#define ARM_VARIANT & fpu_vfp_ext_v2
20148
21d799b5
NC
20149 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20150 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20151 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20152 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20153
037e8744
JB
20154/* Instructions which may belong to either the Neon or VFP instruction sets.
20155 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20156#undef ARM_VARIANT
20157#define ARM_VARIANT & fpu_vfp_ext_v1xd
20158#undef THUMB_VARIANT
20159#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20160
037e8744
JB
20161 /* These mnemonics are unique to VFP. */
20162 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20163 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20164 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20165 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20166 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20167 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20168 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20169 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20170 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20171 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20172
20173 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20174 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20175 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20176 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20177
21d799b5
NC
20178 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20179 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20180
20181 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20182 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20183
55881a11
MGD
20184 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20185 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20186 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20187 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20188 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20189 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20190 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20191 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20192
5f1af56b 20193 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20194 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20195 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20196 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20197
037e8744
JB
20198
20199 /* NOTE: All VMOV encoding is special-cased! */
20200 NCE(vmov, 0, 1, (VMOV), neon_mov),
20201 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20202
9db2f6b4
RL
20203#undef ARM_VARIANT
20204#define ARM_VARIANT & arm_ext_fp16
20205#undef THUMB_VARIANT
20206#define THUMB_VARIANT & arm_ext_fp16
20207 /* New instructions added from v8.2, allowing the extraction and insertion of
20208 the upper 16 bits of a 32-bit vector register. */
20209 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20210 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20211
c921be7d
NC
20212#undef THUMB_VARIANT
20213#define THUMB_VARIANT & fpu_neon_ext_v1
20214#undef ARM_VARIANT
20215#define ARM_VARIANT & fpu_neon_ext_v1
20216
5287ad62
JB
20217 /* Data processing with three registers of the same length. */
20218 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20219 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20220 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20221 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20222 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20223 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20224 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20225 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20226 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20227 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20228 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20229 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20230 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20231 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20232 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20233 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20234 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20235 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20236 /* If not immediate, fall back to neon_dyadic_i64_su.
20237 shl_imm should accept I8 I16 I32 I64,
20238 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20239 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20240 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20241 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20242 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20243 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20244 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20245 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20246 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20247 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20248 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20249 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20250 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20251 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20252 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20253 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20254 /* Bitfield ops, untyped. */
20255 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20256 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20257 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20258 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20259 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20260 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20261 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
20262 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20263 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20264 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20265 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20266 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20267 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20268 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20269 back to neon_dyadic_if_su. */
21d799b5
NC
20270 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20271 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20272 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20273 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20274 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20275 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20276 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20277 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20278 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20279 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20280 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20281 /* As above, D registers only. */
21d799b5
NC
20282 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20283 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20284 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20285 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20286 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20287 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20288 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20289 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20290 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20291 /* vtst takes sizes 8, 16, 32. */
20292 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20293 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20294 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20295 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20296 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20297 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20298 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20299 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20300 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20301 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20302 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20303 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20304 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20305 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20306 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20307 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20308 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20309 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20310 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20311 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20312 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e
MW
20313 /* ARM v8.1 extension. */
20314 nUF(vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20315 nUF(vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20316 nUF(vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20317 nUF(vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20318
20319 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20320 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20321 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20322
20323 /* Data processing with two registers and a shift amount. */
20324 /* Right shifts, and variants with rounding.
20325 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20326 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20327 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20328 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20329 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20330 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20331 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20332 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20333 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20334 /* Shift and insert. Sizes accepted 8 16 32 64. */
20335 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20336 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20337 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20338 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20339 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20340 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20341 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20342 /* Right shift immediate, saturating & narrowing, with rounding variants.
20343 Types accepted S16 S32 S64 U16 U32 U64. */
20344 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20345 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20346 /* As above, unsigned. Types accepted S16 S32 S64. */
20347 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20348 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20349 /* Right shift narrowing. Types accepted I16 I32 I64. */
20350 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20351 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20352 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20353 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20354 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20355 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20356
4316f0d2
DG
20357 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20358 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20359
20360 /* Data processing, three registers of different lengths. */
20361 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20362 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20363 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20364 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20365 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20366 /* If not scalar, fall back to neon_dyadic_long.
20367 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20368 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20369 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20370 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20371 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20372 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20373 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20374 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20375 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20376 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20377 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20378 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20379 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20380 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20381 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20382 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20383 S16 S32 U16 U32. */
21d799b5 20384 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20385
20386 /* Extract. Size 8. */
3b8d421e
PB
20387 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20388 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20389
20390 /* Two registers, miscellaneous. */
20391 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20392 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20393 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20394 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20395 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20396 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20397 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20398 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20399 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20400 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20401 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20402 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20403 /* VMOVN. Types I16 I32 I64. */
21d799b5 20404 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20405 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20406 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20407 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20408 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20409 /* VZIP / VUZP. Sizes 8 16 32. */
20410 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20411 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20412 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20413 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20414 /* VQABS / VQNEG. Types S8 S16 S32. */
20415 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20416 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20417 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20418 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20419 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20420 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20421 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20422 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20423 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
20424 /* Reciprocal estimates. Types U32 F32. */
20425 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20426 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20427 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20428 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20429 /* VCLS. Types S8 S16 S32. */
20430 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20431 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20432 /* VCLZ. Types I8 I16 I32. */
20433 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20434 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20435 /* VCNT. Size 8. */
20436 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20437 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20438 /* Two address, untyped. */
20439 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20440 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20441 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20442 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20443 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20444
20445 /* Table lookup. Size 8. */
20446 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20447 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20448
c921be7d
NC
20449#undef THUMB_VARIANT
20450#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20451#undef ARM_VARIANT
20452#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20453
5287ad62 20454 /* Neon element/structure load/store. */
21d799b5
NC
20455 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20456 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20457 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20458 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20459 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20460 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20461 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20462 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20463
c921be7d 20464#undef THUMB_VARIANT
74db7efb
NC
20465#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20466#undef ARM_VARIANT
20467#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20468 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20469 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20470 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20471 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20472 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20473 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20474 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20475 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20476 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20477
74db7efb 20478#undef THUMB_VARIANT
c921be7d
NC
20479#define THUMB_VARIANT & fpu_vfp_ext_v3
20480#undef ARM_VARIANT
20481#define ARM_VARIANT & fpu_vfp_ext_v3
20482
21d799b5 20483 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20484 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20485 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20486 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20487 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20488 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20489 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20490 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20491 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20492
74db7efb
NC
20493#undef ARM_VARIANT
20494#define ARM_VARIANT & fpu_vfp_ext_fma
20495#undef THUMB_VARIANT
20496#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20497 /* Mnemonics shared by Neon and VFP. These are included in the
20498 VFP FMA variant; NEON and VFP FMA always includes the NEON
20499 FMA instructions. */
20500 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20501 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20502 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20503 the v form should always be used. */
20504 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20505 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20506 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20507 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20508 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20509 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20510
5287ad62 20511#undef THUMB_VARIANT
c921be7d
NC
20512#undef ARM_VARIANT
20513#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20514
21d799b5
NC
20515 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20516 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20517 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20518 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20519 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20520 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20521 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20522 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20523
c921be7d
NC
20524#undef ARM_VARIANT
20525#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20526
21d799b5
NC
20527 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20528 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20529 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20530 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20531 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20532 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20533 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20534 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20535 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20536 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20537 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20538 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20539 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20540 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20541 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20542 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20543 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20544 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20545 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20546 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20547 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20548 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20549 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20550 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20551 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20552 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20553 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20554 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20555 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20556 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20557 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20558 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20559 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20560 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20561 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20562 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20563 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20564 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20565 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20566 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20567 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20568 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20569 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20570 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20571 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20572 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20573 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20574 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20575 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20576 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20577 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20578 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20579 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20580 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20581 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20582 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20583 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20584 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20585 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20586 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20587 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20588 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20589 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20590 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20591 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20592 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20593 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20594 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20595 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20596 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20597 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20598 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20599 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20600 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20601 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20602 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20603 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20604 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20605 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20606 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20607 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20608 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20609 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20610 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20611 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20612 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20613 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20614 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20615 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20616 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20617 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20618 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20619 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20620 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20621 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20622 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20623 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20624 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20625 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20626 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20627 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20628 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20629 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20630 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20631 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20632 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20633 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20634 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20635 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20636 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20637 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20638 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20639 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20640 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20641 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20642 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20643 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20644 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20645 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20646 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20647 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20648 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20649 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20650 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20651 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20652 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20653 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20654 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20655 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20656 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20657 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20658 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20659 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20660 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20661 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20662 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20663 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20664 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20665 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20666 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20667 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20668 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20669 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20670 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20671 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20672 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20673 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20674 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20675 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20676 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20677 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20678 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20679 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20680 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20681 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20682 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20683 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20684 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20685 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20686 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20687 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20688 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20689
c921be7d
NC
20690#undef ARM_VARIANT
20691#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20692
21d799b5
NC
20693 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20694 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20695 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20696 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20697 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20698 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20699 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20700 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20701 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20702 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20703 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20704 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20705 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20706 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20707 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20708 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20709 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20710 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20711 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20712 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20713 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20714 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20715 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20716 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20717 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20718 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20719 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20720 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20721 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20722 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20723 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20724 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20725 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20726 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20727 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20728 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20729 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20730 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20731 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20732 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20733 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20734 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20735 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20736 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20737 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20738 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20739 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20740 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20741 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20742 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20743 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20744 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20745 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20746 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20747 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20748 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20749 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20750
c921be7d
NC
20751#undef ARM_VARIANT
20752#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20753
21d799b5
NC
20754 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20755 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20756 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20757 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20758 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20759 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20760 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20761 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20762 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20763 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20764 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20765 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20766 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20767 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20768 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20769 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20770 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20771 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20772 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20773 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20774 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20775 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20776 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20777 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20778 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20779 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20780 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20781 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20782 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20783 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20784 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20785 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20786 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20787 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20788 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20789 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20790 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20791 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20792 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20793 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20794 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20795 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20796 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20797 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20798 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20799 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20800 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20801 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20802 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20803 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20804 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20805 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20806 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20807 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20808 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20809 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20810 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20811 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20812 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20813 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20814 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20815 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20816 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20817 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20818 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20819 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20820 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20821 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20822 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20823 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20824 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20825 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20826 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20827 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20828 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20829 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d
TP
20830
20831#undef ARM_VARIANT
20832#define ARM_VARIANT NULL
20833#undef THUMB_VARIANT
20834#define THUMB_VARIANT & arm_ext_v8m
20835 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
20836 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
c19d1205
ZW
20837};
20838#undef ARM_VARIANT
20839#undef THUMB_VARIANT
20840#undef TCE
c19d1205
ZW
20841#undef TUE
20842#undef TUF
20843#undef TCC
8f06b2d8 20844#undef cCE
e3cb604e
PB
20845#undef cCL
20846#undef C3E
c19d1205
ZW
20847#undef CE
20848#undef CM
20849#undef UE
20850#undef UF
20851#undef UT
5287ad62
JB
20852#undef NUF
20853#undef nUF
20854#undef NCE
20855#undef nCE
c19d1205
ZW
20856#undef OPS0
20857#undef OPS1
20858#undef OPS2
20859#undef OPS3
20860#undef OPS4
20861#undef OPS5
20862#undef OPS6
20863#undef do_0
20864\f
20865/* MD interface: bits in the object file. */
bfae80f2 20866
c19d1205
ZW
20867/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20868 for use in the a.out file, and stores them in the array pointed to by buf.
20869 This knows about the endian-ness of the target machine and does
20870 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20871 2 (short) and 4 (long) Floating numbers are put out as a series of
20872 LITTLENUMS (shorts, here at least). */
b99bd4ef 20873
c19d1205
ZW
20874void
20875md_number_to_chars (char * buf, valueT val, int n)
20876{
20877 if (target_big_endian)
20878 number_to_chars_bigendian (buf, val, n);
20879 else
20880 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20881}
20882
c19d1205
ZW
20883static valueT
20884md_chars_to_number (char * buf, int n)
bfae80f2 20885{
c19d1205
ZW
20886 valueT result = 0;
20887 unsigned char * where = (unsigned char *) buf;
bfae80f2 20888
c19d1205 20889 if (target_big_endian)
b99bd4ef 20890 {
c19d1205
ZW
20891 while (n--)
20892 {
20893 result <<= 8;
20894 result |= (*where++ & 255);
20895 }
b99bd4ef 20896 }
c19d1205 20897 else
b99bd4ef 20898 {
c19d1205
ZW
20899 while (n--)
20900 {
20901 result <<= 8;
20902 result |= (where[n] & 255);
20903 }
bfae80f2 20904 }
b99bd4ef 20905
c19d1205 20906 return result;
bfae80f2 20907}
b99bd4ef 20908
c19d1205 20909/* MD interface: Sections. */
b99bd4ef 20910
fa94de6b
RM
20911/* Calculate the maximum variable size (i.e., excluding fr_fix)
20912 that an rs_machine_dependent frag may reach. */
20913
20914unsigned int
20915arm_frag_max_var (fragS *fragp)
20916{
20917 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20918 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20919
20920 Note that we generate relaxable instructions even for cases that don't
20921 really need it, like an immediate that's a trivial constant. So we're
20922 overestimating the instruction size for some of those cases. Rather
20923 than putting more intelligence here, it would probably be better to
20924 avoid generating a relaxation frag in the first place when it can be
20925 determined up front that a short instruction will suffice. */
20926
20927 gas_assert (fragp->fr_type == rs_machine_dependent);
20928 return INSN_SIZE;
20929}
20930
0110f2b8
PB
20931/* Estimate the size of a frag before relaxing. Assume everything fits in
20932 2 bytes. */
20933
c19d1205 20934int
0110f2b8 20935md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20936 segT segtype ATTRIBUTE_UNUSED)
20937{
0110f2b8
PB
20938 fragp->fr_var = 2;
20939 return 2;
20940}
20941
20942/* Convert a machine dependent frag. */
20943
20944void
20945md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20946{
20947 unsigned long insn;
20948 unsigned long old_op;
20949 char *buf;
20950 expressionS exp;
20951 fixS *fixp;
20952 int reloc_type;
20953 int pc_rel;
20954 int opcode;
20955
20956 buf = fragp->fr_literal + fragp->fr_fix;
20957
20958 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20959 if (fragp->fr_symbol)
20960 {
0110f2b8
PB
20961 exp.X_op = O_symbol;
20962 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
20963 }
20964 else
20965 {
0110f2b8 20966 exp.X_op = O_constant;
5f4273c7 20967 }
0110f2b8
PB
20968 exp.X_add_number = fragp->fr_offset;
20969 opcode = fragp->fr_subtype;
20970 switch (opcode)
20971 {
20972 case T_MNEM_ldr_pc:
20973 case T_MNEM_ldr_pc2:
20974 case T_MNEM_ldr_sp:
20975 case T_MNEM_str_sp:
20976 case T_MNEM_ldr:
20977 case T_MNEM_ldrb:
20978 case T_MNEM_ldrh:
20979 case T_MNEM_str:
20980 case T_MNEM_strb:
20981 case T_MNEM_strh:
20982 if (fragp->fr_var == 4)
20983 {
5f4273c7 20984 insn = THUMB_OP32 (opcode);
0110f2b8
PB
20985 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20986 {
20987 insn |= (old_op & 0x700) << 4;
20988 }
20989 else
20990 {
20991 insn |= (old_op & 7) << 12;
20992 insn |= (old_op & 0x38) << 13;
20993 }
20994 insn |= 0x00000c00;
20995 put_thumb32_insn (buf, insn);
20996 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20997 }
20998 else
20999 {
21000 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21001 }
21002 pc_rel = (opcode == T_MNEM_ldr_pc2);
21003 break;
21004 case T_MNEM_adr:
21005 if (fragp->fr_var == 4)
21006 {
21007 insn = THUMB_OP32 (opcode);
21008 insn |= (old_op & 0xf0) << 4;
21009 put_thumb32_insn (buf, insn);
21010 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21011 }
21012 else
21013 {
21014 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21015 exp.X_add_number -= 4;
21016 }
21017 pc_rel = 1;
21018 break;
21019 case T_MNEM_mov:
21020 case T_MNEM_movs:
21021 case T_MNEM_cmp:
21022 case T_MNEM_cmn:
21023 if (fragp->fr_var == 4)
21024 {
21025 int r0off = (opcode == T_MNEM_mov
21026 || opcode == T_MNEM_movs) ? 0 : 8;
21027 insn = THUMB_OP32 (opcode);
21028 insn = (insn & 0xe1ffffff) | 0x10000000;
21029 insn |= (old_op & 0x700) << r0off;
21030 put_thumb32_insn (buf, insn);
21031 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21032 }
21033 else
21034 {
21035 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21036 }
21037 pc_rel = 0;
21038 break;
21039 case T_MNEM_b:
21040 if (fragp->fr_var == 4)
21041 {
21042 insn = THUMB_OP32(opcode);
21043 put_thumb32_insn (buf, insn);
21044 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21045 }
21046 else
21047 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21048 pc_rel = 1;
21049 break;
21050 case T_MNEM_bcond:
21051 if (fragp->fr_var == 4)
21052 {
21053 insn = THUMB_OP32(opcode);
21054 insn |= (old_op & 0xf00) << 14;
21055 put_thumb32_insn (buf, insn);
21056 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21057 }
21058 else
21059 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21060 pc_rel = 1;
21061 break;
21062 case T_MNEM_add_sp:
21063 case T_MNEM_add_pc:
21064 case T_MNEM_inc_sp:
21065 case T_MNEM_dec_sp:
21066 if (fragp->fr_var == 4)
21067 {
21068 /* ??? Choose between add and addw. */
21069 insn = THUMB_OP32 (opcode);
21070 insn |= (old_op & 0xf0) << 4;
21071 put_thumb32_insn (buf, insn);
16805f35
PB
21072 if (opcode == T_MNEM_add_pc)
21073 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21074 else
21075 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21076 }
21077 else
21078 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21079 pc_rel = 0;
21080 break;
21081
21082 case T_MNEM_addi:
21083 case T_MNEM_addis:
21084 case T_MNEM_subi:
21085 case T_MNEM_subis:
21086 if (fragp->fr_var == 4)
21087 {
21088 insn = THUMB_OP32 (opcode);
21089 insn |= (old_op & 0xf0) << 4;
21090 insn |= (old_op & 0xf) << 16;
21091 put_thumb32_insn (buf, insn);
16805f35
PB
21092 if (insn & (1 << 20))
21093 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21094 else
21095 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21096 }
21097 else
21098 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21099 pc_rel = 0;
21100 break;
21101 default:
5f4273c7 21102 abort ();
0110f2b8
PB
21103 }
21104 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21105 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21106 fixp->fx_file = fragp->fr_file;
21107 fixp->fx_line = fragp->fr_line;
21108 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21109
21110 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21111 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21112 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21113 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21114}
21115
21116/* Return the size of a relaxable immediate operand instruction.
21117 SHIFT and SIZE specify the form of the allowable immediate. */
21118static int
21119relax_immediate (fragS *fragp, int size, int shift)
21120{
21121 offsetT offset;
21122 offsetT mask;
21123 offsetT low;
21124
21125 /* ??? Should be able to do better than this. */
21126 if (fragp->fr_symbol)
21127 return 4;
21128
21129 low = (1 << shift) - 1;
21130 mask = (1 << (shift + size)) - (1 << shift);
21131 offset = fragp->fr_offset;
21132 /* Force misaligned offsets to 32-bit variant. */
21133 if (offset & low)
5e77afaa 21134 return 4;
0110f2b8
PB
21135 if (offset & ~mask)
21136 return 4;
21137 return 2;
21138}
21139
5e77afaa
PB
21140/* Get the address of a symbol during relaxation. */
21141static addressT
5f4273c7 21142relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21143{
21144 fragS *sym_frag;
21145 addressT addr;
21146 symbolS *sym;
21147
21148 sym = fragp->fr_symbol;
21149 sym_frag = symbol_get_frag (sym);
21150 know (S_GET_SEGMENT (sym) != absolute_section
21151 || sym_frag == &zero_address_frag);
21152 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21153
21154 /* If frag has yet to be reached on this pass, assume it will
21155 move by STRETCH just as we did. If this is not so, it will
21156 be because some frag between grows, and that will force
21157 another pass. */
21158
21159 if (stretch != 0
21160 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21161 {
21162 fragS *f;
21163
21164 /* Adjust stretch for any alignment frag. Note that if have
21165 been expanding the earlier code, the symbol may be
21166 defined in what appears to be an earlier frag. FIXME:
21167 This doesn't handle the fr_subtype field, which specifies
21168 a maximum number of bytes to skip when doing an
21169 alignment. */
21170 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21171 {
21172 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21173 {
21174 if (stretch < 0)
21175 stretch = - ((- stretch)
21176 & ~ ((1 << (int) f->fr_offset) - 1));
21177 else
21178 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21179 if (stretch == 0)
21180 break;
21181 }
21182 }
21183 if (f != NULL)
21184 addr += stretch;
21185 }
5e77afaa
PB
21186
21187 return addr;
21188}
21189
0110f2b8
PB
21190/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21191 load. */
21192static int
5e77afaa 21193relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21194{
21195 addressT addr;
21196 offsetT val;
21197
21198 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21199 if (fragp->fr_symbol == NULL
21200 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21201 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21202 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21203 return 4;
21204
5f4273c7 21205 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21206 addr = fragp->fr_address + fragp->fr_fix;
21207 addr = (addr + 4) & ~3;
5e77afaa 21208 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21209 if (val & 3)
5e77afaa 21210 return 4;
0110f2b8
PB
21211 val -= addr;
21212 if (val < 0 || val > 1020)
21213 return 4;
21214 return 2;
21215}
21216
21217/* Return the size of a relaxable add/sub immediate instruction. */
21218static int
21219relax_addsub (fragS *fragp, asection *sec)
21220{
21221 char *buf;
21222 int op;
21223
21224 buf = fragp->fr_literal + fragp->fr_fix;
21225 op = bfd_get_16(sec->owner, buf);
21226 if ((op & 0xf) == ((op >> 4) & 0xf))
21227 return relax_immediate (fragp, 8, 0);
21228 else
21229 return relax_immediate (fragp, 3, 0);
21230}
21231
e83a675f
RE
21232/* Return TRUE iff the definition of symbol S could be pre-empted
21233 (overridden) at link or load time. */
21234static bfd_boolean
21235symbol_preemptible (symbolS *s)
21236{
21237 /* Weak symbols can always be pre-empted. */
21238 if (S_IS_WEAK (s))
21239 return TRUE;
21240
21241 /* Non-global symbols cannot be pre-empted. */
21242 if (! S_IS_EXTERNAL (s))
21243 return FALSE;
21244
21245#ifdef OBJ_ELF
21246 /* In ELF, a global symbol can be marked protected, or private. In that
21247 case it can't be pre-empted (other definitions in the same link unit
21248 would violate the ODR). */
21249 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21250 return FALSE;
21251#endif
21252
21253 /* Other global symbols might be pre-empted. */
21254 return TRUE;
21255}
0110f2b8
PB
21256
21257/* Return the size of a relaxable branch instruction. BITS is the
21258 size of the offset field in the narrow instruction. */
21259
21260static int
5e77afaa 21261relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21262{
21263 addressT addr;
21264 offsetT val;
21265 offsetT limit;
21266
21267 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21268 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21269 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21270 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21271 return 4;
21272
267bf995 21273#ifdef OBJ_ELF
e83a675f 21274 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21275 if (S_IS_DEFINED (fragp->fr_symbol)
21276 && ARM_IS_FUNC (fragp->fr_symbol))
21277 return 4;
e83a675f 21278#endif
0d9b4b55 21279
e83a675f 21280 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21281 return 4;
267bf995 21282
5f4273c7 21283 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21284 addr = fragp->fr_address + fragp->fr_fix + 4;
21285 val -= addr;
21286
21287 /* Offset is a signed value *2 */
21288 limit = 1 << bits;
21289 if (val >= limit || val < -limit)
21290 return 4;
21291 return 2;
21292}
21293
21294
21295/* Relax a machine dependent frag. This returns the amount by which
21296 the current size of the frag should change. */
21297
21298int
5e77afaa 21299arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21300{
21301 int oldsize;
21302 int newsize;
21303
21304 oldsize = fragp->fr_var;
21305 switch (fragp->fr_subtype)
21306 {
21307 case T_MNEM_ldr_pc2:
5f4273c7 21308 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21309 break;
21310 case T_MNEM_ldr_pc:
21311 case T_MNEM_ldr_sp:
21312 case T_MNEM_str_sp:
5f4273c7 21313 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21314 break;
21315 case T_MNEM_ldr:
21316 case T_MNEM_str:
5f4273c7 21317 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21318 break;
21319 case T_MNEM_ldrh:
21320 case T_MNEM_strh:
5f4273c7 21321 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21322 break;
21323 case T_MNEM_ldrb:
21324 case T_MNEM_strb:
5f4273c7 21325 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21326 break;
21327 case T_MNEM_adr:
5f4273c7 21328 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21329 break;
21330 case T_MNEM_mov:
21331 case T_MNEM_movs:
21332 case T_MNEM_cmp:
21333 case T_MNEM_cmn:
5f4273c7 21334 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21335 break;
21336 case T_MNEM_b:
5f4273c7 21337 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21338 break;
21339 case T_MNEM_bcond:
5f4273c7 21340 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21341 break;
21342 case T_MNEM_add_sp:
21343 case T_MNEM_add_pc:
21344 newsize = relax_immediate (fragp, 8, 2);
21345 break;
21346 case T_MNEM_inc_sp:
21347 case T_MNEM_dec_sp:
21348 newsize = relax_immediate (fragp, 7, 2);
21349 break;
21350 case T_MNEM_addi:
21351 case T_MNEM_addis:
21352 case T_MNEM_subi:
21353 case T_MNEM_subis:
21354 newsize = relax_addsub (fragp, sec);
21355 break;
21356 default:
5f4273c7 21357 abort ();
0110f2b8 21358 }
5e77afaa
PB
21359
21360 fragp->fr_var = newsize;
21361 /* Freeze wide instructions that are at or before the same location as
21362 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21363 Don't freeze them unconditionally because targets may be artificially
21364 misaligned by the expansion of preceding frags. */
5e77afaa 21365 if (stretch <= 0 && newsize > 2)
0110f2b8 21366 {
0110f2b8 21367 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21368 frag_wane (fragp);
0110f2b8 21369 }
5e77afaa 21370
0110f2b8 21371 return newsize - oldsize;
c19d1205 21372}
b99bd4ef 21373
c19d1205 21374/* Round up a section size to the appropriate boundary. */
b99bd4ef 21375
c19d1205
ZW
21376valueT
21377md_section_align (segT segment ATTRIBUTE_UNUSED,
21378 valueT size)
21379{
f0927246
NC
21380#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21381 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21382 {
21383 /* For a.out, force the section size to be aligned. If we don't do
21384 this, BFD will align it for us, but it will not write out the
21385 final bytes of the section. This may be a bug in BFD, but it is
21386 easier to fix it here since that is how the other a.out targets
21387 work. */
21388 int align;
21389
21390 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21391 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21392 }
c19d1205 21393#endif
f0927246
NC
21394
21395 return size;
bfae80f2 21396}
b99bd4ef 21397
c19d1205
ZW
21398/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21399 of an rs_align_code fragment. */
21400
21401void
21402arm_handle_align (fragS * fragP)
bfae80f2 21403{
e7495e45
NS
21404 static char const arm_noop[2][2][4] =
21405 {
21406 { /* ARMv1 */
21407 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21408 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21409 },
21410 { /* ARMv6k */
21411 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21412 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21413 },
21414 };
21415 static char const thumb_noop[2][2][2] =
21416 {
21417 { /* Thumb-1 */
21418 {0xc0, 0x46}, /* LE */
21419 {0x46, 0xc0}, /* BE */
21420 },
21421 { /* Thumb-2 */
21422 {0x00, 0xbf}, /* LE */
21423 {0xbf, 0x00} /* BE */
21424 }
21425 };
21426 static char const wide_thumb_noop[2][4] =
21427 { /* Wide Thumb-2 */
21428 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21429 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21430 };
c921be7d 21431
e7495e45 21432 unsigned bytes, fix, noop_size;
c19d1205
ZW
21433 char * p;
21434 const char * noop;
e7495e45 21435 const char *narrow_noop = NULL;
cd000bff
DJ
21436#ifdef OBJ_ELF
21437 enum mstate state;
21438#endif
bfae80f2 21439
c19d1205 21440 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21441 return;
21442
c19d1205
ZW
21443 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21444 p = fragP->fr_literal + fragP->fr_fix;
21445 fix = 0;
bfae80f2 21446
c19d1205
ZW
21447 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21448 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21449
cd000bff 21450 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21451
cd000bff 21452 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21453 {
7f78eb34
JW
21454 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21455 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21456 {
21457 narrow_noop = thumb_noop[1][target_big_endian];
21458 noop = wide_thumb_noop[target_big_endian];
21459 }
c19d1205 21460 else
e7495e45
NS
21461 noop = thumb_noop[0][target_big_endian];
21462 noop_size = 2;
cd000bff
DJ
21463#ifdef OBJ_ELF
21464 state = MAP_THUMB;
21465#endif
7ed4c4c5
NC
21466 }
21467 else
21468 {
7f78eb34
JW
21469 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21470 ? selected_cpu : arm_arch_none,
21471 arm_ext_v6k) != 0]
e7495e45
NS
21472 [target_big_endian];
21473 noop_size = 4;
cd000bff
DJ
21474#ifdef OBJ_ELF
21475 state = MAP_ARM;
21476#endif
7ed4c4c5 21477 }
c921be7d 21478
e7495e45 21479 fragP->fr_var = noop_size;
c921be7d 21480
c19d1205 21481 if (bytes & (noop_size - 1))
7ed4c4c5 21482 {
c19d1205 21483 fix = bytes & (noop_size - 1);
cd000bff
DJ
21484#ifdef OBJ_ELF
21485 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21486#endif
c19d1205
ZW
21487 memset (p, 0, fix);
21488 p += fix;
21489 bytes -= fix;
a737bd4d 21490 }
a737bd4d 21491
e7495e45
NS
21492 if (narrow_noop)
21493 {
21494 if (bytes & noop_size)
21495 {
21496 /* Insert a narrow noop. */
21497 memcpy (p, narrow_noop, noop_size);
21498 p += noop_size;
21499 bytes -= noop_size;
21500 fix += noop_size;
21501 }
21502
21503 /* Use wide noops for the remainder */
21504 noop_size = 4;
21505 }
21506
c19d1205 21507 while (bytes >= noop_size)
a737bd4d 21508 {
c19d1205
ZW
21509 memcpy (p, noop, noop_size);
21510 p += noop_size;
21511 bytes -= noop_size;
21512 fix += noop_size;
a737bd4d
NC
21513 }
21514
c19d1205 21515 fragP->fr_fix += fix;
a737bd4d
NC
21516}
21517
c19d1205
ZW
21518/* Called from md_do_align. Used to create an alignment
21519 frag in a code section. */
21520
21521void
21522arm_frag_align_code (int n, int max)
bfae80f2 21523{
c19d1205 21524 char * p;
7ed4c4c5 21525
c19d1205 21526 /* We assume that there will never be a requirement
6ec8e702 21527 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21528 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21529 {
21530 char err_msg[128];
21531
fa94de6b 21532 sprintf (err_msg,
477330fc
RM
21533 _("alignments greater than %d bytes not supported in .text sections."),
21534 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21535 as_fatal ("%s", err_msg);
6ec8e702 21536 }
bfae80f2 21537
c19d1205
ZW
21538 p = frag_var (rs_align_code,
21539 MAX_MEM_FOR_RS_ALIGN_CODE,
21540 1,
21541 (relax_substateT) max,
21542 (symbolS *) NULL,
21543 (offsetT) n,
21544 (char *) NULL);
21545 *p = 0;
21546}
bfae80f2 21547
8dc2430f
NC
21548/* Perform target specific initialisation of a frag.
21549 Note - despite the name this initialisation is not done when the frag
21550 is created, but only when its type is assigned. A frag can be created
21551 and used a long time before its type is set, so beware of assuming that
21552 this initialisationis performed first. */
bfae80f2 21553
cd000bff
DJ
21554#ifndef OBJ_ELF
21555void
21556arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21557{
21558 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21559 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21560}
21561
21562#else /* OBJ_ELF is defined. */
c19d1205 21563void
cd000bff 21564arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21565{
b968d18a
JW
21566 int frag_thumb_mode;
21567
8dc2430f
NC
21568 /* If the current ARM vs THUMB mode has not already
21569 been recorded into this frag then do so now. */
cd000bff 21570 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21571 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21572
21573 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21574
f9c1b181
RL
21575 /* Record a mapping symbol for alignment frags. We will delete this
21576 later if the alignment ends up empty. */
21577 switch (fragP->fr_type)
21578 {
21579 case rs_align:
21580 case rs_align_test:
21581 case rs_fill:
21582 mapping_state_2 (MAP_DATA, max_chars);
21583 break;
21584 case rs_align_code:
b968d18a 21585 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21586 break;
21587 default:
21588 break;
cd000bff 21589 }
bfae80f2
RE
21590}
21591
c19d1205
ZW
21592/* When we change sections we need to issue a new mapping symbol. */
21593
21594void
21595arm_elf_change_section (void)
bfae80f2 21596{
c19d1205
ZW
21597 /* Link an unlinked unwind index table section to the .text section. */
21598 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21599 && elf_linked_to_section (now_seg) == NULL)
21600 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21601}
21602
c19d1205
ZW
21603int
21604arm_elf_section_type (const char * str, size_t len)
e45d0630 21605{
c19d1205
ZW
21606 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21607 return SHT_ARM_EXIDX;
e45d0630 21608
c19d1205
ZW
21609 return -1;
21610}
21611\f
21612/* Code to deal with unwinding tables. */
e45d0630 21613
c19d1205 21614static void add_unwind_adjustsp (offsetT);
e45d0630 21615
5f4273c7 21616/* Generate any deferred unwind frame offset. */
e45d0630 21617
bfae80f2 21618static void
c19d1205 21619flush_pending_unwind (void)
bfae80f2 21620{
c19d1205 21621 offsetT offset;
bfae80f2 21622
c19d1205
ZW
21623 offset = unwind.pending_offset;
21624 unwind.pending_offset = 0;
21625 if (offset != 0)
21626 add_unwind_adjustsp (offset);
bfae80f2
RE
21627}
21628
c19d1205
ZW
21629/* Add an opcode to this list for this function. Two-byte opcodes should
21630 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21631 order. */
21632
bfae80f2 21633static void
c19d1205 21634add_unwind_opcode (valueT op, int length)
bfae80f2 21635{
c19d1205
ZW
21636 /* Add any deferred stack adjustment. */
21637 if (unwind.pending_offset)
21638 flush_pending_unwind ();
bfae80f2 21639
c19d1205 21640 unwind.sp_restored = 0;
bfae80f2 21641
c19d1205 21642 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21643 {
c19d1205
ZW
21644 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21645 if (unwind.opcodes)
21d799b5 21646 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 21647 unwind.opcode_alloc);
c19d1205 21648 else
21d799b5 21649 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 21650 }
c19d1205 21651 while (length > 0)
bfae80f2 21652 {
c19d1205
ZW
21653 length--;
21654 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21655 op >>= 8;
21656 unwind.opcode_count++;
bfae80f2 21657 }
bfae80f2
RE
21658}
21659
c19d1205
ZW
21660/* Add unwind opcodes to adjust the stack pointer. */
21661
bfae80f2 21662static void
c19d1205 21663add_unwind_adjustsp (offsetT offset)
bfae80f2 21664{
c19d1205 21665 valueT op;
bfae80f2 21666
c19d1205 21667 if (offset > 0x200)
bfae80f2 21668 {
c19d1205
ZW
21669 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21670 char bytes[5];
21671 int n;
21672 valueT o;
bfae80f2 21673
c19d1205
ZW
21674 /* Long form: 0xb2, uleb128. */
21675 /* This might not fit in a word so add the individual bytes,
21676 remembering the list is built in reverse order. */
21677 o = (valueT) ((offset - 0x204) >> 2);
21678 if (o == 0)
21679 add_unwind_opcode (0, 1);
bfae80f2 21680
c19d1205
ZW
21681 /* Calculate the uleb128 encoding of the offset. */
21682 n = 0;
21683 while (o)
21684 {
21685 bytes[n] = o & 0x7f;
21686 o >>= 7;
21687 if (o)
21688 bytes[n] |= 0x80;
21689 n++;
21690 }
21691 /* Add the insn. */
21692 for (; n; n--)
21693 add_unwind_opcode (bytes[n - 1], 1);
21694 add_unwind_opcode (0xb2, 1);
21695 }
21696 else if (offset > 0x100)
bfae80f2 21697 {
c19d1205
ZW
21698 /* Two short opcodes. */
21699 add_unwind_opcode (0x3f, 1);
21700 op = (offset - 0x104) >> 2;
21701 add_unwind_opcode (op, 1);
bfae80f2 21702 }
c19d1205
ZW
21703 else if (offset > 0)
21704 {
21705 /* Short opcode. */
21706 op = (offset - 4) >> 2;
21707 add_unwind_opcode (op, 1);
21708 }
21709 else if (offset < 0)
bfae80f2 21710 {
c19d1205
ZW
21711 offset = -offset;
21712 while (offset > 0x100)
bfae80f2 21713 {
c19d1205
ZW
21714 add_unwind_opcode (0x7f, 1);
21715 offset -= 0x100;
bfae80f2 21716 }
c19d1205
ZW
21717 op = ((offset - 4) >> 2) | 0x40;
21718 add_unwind_opcode (op, 1);
bfae80f2 21719 }
bfae80f2
RE
21720}
21721
c19d1205
ZW
21722/* Finish the list of unwind opcodes for this function. */
21723static void
21724finish_unwind_opcodes (void)
bfae80f2 21725{
c19d1205 21726 valueT op;
bfae80f2 21727
c19d1205 21728 if (unwind.fp_used)
bfae80f2 21729 {
708587a4 21730 /* Adjust sp as necessary. */
c19d1205
ZW
21731 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21732 flush_pending_unwind ();
bfae80f2 21733
c19d1205
ZW
21734 /* After restoring sp from the frame pointer. */
21735 op = 0x90 | unwind.fp_reg;
21736 add_unwind_opcode (op, 1);
21737 }
21738 else
21739 flush_pending_unwind ();
bfae80f2
RE
21740}
21741
bfae80f2 21742
c19d1205
ZW
21743/* Start an exception table entry. If idx is nonzero this is an index table
21744 entry. */
bfae80f2
RE
21745
21746static void
c19d1205 21747start_unwind_section (const segT text_seg, int idx)
bfae80f2 21748{
c19d1205
ZW
21749 const char * text_name;
21750 const char * prefix;
21751 const char * prefix_once;
21752 const char * group_name;
21753 size_t prefix_len;
21754 size_t text_len;
21755 char * sec_name;
21756 size_t sec_name_len;
21757 int type;
21758 int flags;
21759 int linkonce;
bfae80f2 21760
c19d1205 21761 if (idx)
bfae80f2 21762 {
c19d1205
ZW
21763 prefix = ELF_STRING_ARM_unwind;
21764 prefix_once = ELF_STRING_ARM_unwind_once;
21765 type = SHT_ARM_EXIDX;
bfae80f2 21766 }
c19d1205 21767 else
bfae80f2 21768 {
c19d1205
ZW
21769 prefix = ELF_STRING_ARM_unwind_info;
21770 prefix_once = ELF_STRING_ARM_unwind_info_once;
21771 type = SHT_PROGBITS;
bfae80f2
RE
21772 }
21773
c19d1205
ZW
21774 text_name = segment_name (text_seg);
21775 if (streq (text_name, ".text"))
21776 text_name = "";
21777
21778 if (strncmp (text_name, ".gnu.linkonce.t.",
21779 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21780 {
c19d1205
ZW
21781 prefix = prefix_once;
21782 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21783 }
21784
c19d1205
ZW
21785 prefix_len = strlen (prefix);
21786 text_len = strlen (text_name);
21787 sec_name_len = prefix_len + text_len;
21d799b5 21788 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21789 memcpy (sec_name, prefix, prefix_len);
21790 memcpy (sec_name + prefix_len, text_name, text_len);
21791 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21792
c19d1205
ZW
21793 flags = SHF_ALLOC;
21794 linkonce = 0;
21795 group_name = 0;
bfae80f2 21796
c19d1205
ZW
21797 /* Handle COMDAT group. */
21798 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21799 {
c19d1205
ZW
21800 group_name = elf_group_name (text_seg);
21801 if (group_name == NULL)
21802 {
bd3ba5d1 21803 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21804 segment_name (text_seg));
21805 ignore_rest_of_line ();
21806 return;
21807 }
21808 flags |= SHF_GROUP;
21809 linkonce = 1;
bfae80f2
RE
21810 }
21811
c19d1205 21812 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21813
5f4273c7 21814 /* Set the section link for index tables. */
c19d1205
ZW
21815 if (idx)
21816 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21817}
21818
bfae80f2 21819
c19d1205
ZW
21820/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21821 personality routine data. Returns zero, or the index table value for
cad0da33 21822 an inline entry. */
c19d1205
ZW
21823
21824static valueT
21825create_unwind_entry (int have_data)
bfae80f2 21826{
c19d1205
ZW
21827 int size;
21828 addressT where;
21829 char *ptr;
21830 /* The current word of data. */
21831 valueT data;
21832 /* The number of bytes left in this word. */
21833 int n;
bfae80f2 21834
c19d1205 21835 finish_unwind_opcodes ();
bfae80f2 21836
c19d1205
ZW
21837 /* Remember the current text section. */
21838 unwind.saved_seg = now_seg;
21839 unwind.saved_subseg = now_subseg;
bfae80f2 21840
c19d1205 21841 start_unwind_section (now_seg, 0);
bfae80f2 21842
c19d1205 21843 if (unwind.personality_routine == NULL)
bfae80f2 21844 {
c19d1205
ZW
21845 if (unwind.personality_index == -2)
21846 {
21847 if (have_data)
5f4273c7 21848 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21849 return 1; /* EXIDX_CANTUNWIND. */
21850 }
bfae80f2 21851
c19d1205
ZW
21852 /* Use a default personality routine if none is specified. */
21853 if (unwind.personality_index == -1)
21854 {
21855 if (unwind.opcode_count > 3)
21856 unwind.personality_index = 1;
21857 else
21858 unwind.personality_index = 0;
21859 }
bfae80f2 21860
c19d1205
ZW
21861 /* Space for the personality routine entry. */
21862 if (unwind.personality_index == 0)
21863 {
21864 if (unwind.opcode_count > 3)
21865 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21866
c19d1205
ZW
21867 if (!have_data)
21868 {
21869 /* All the data is inline in the index table. */
21870 data = 0x80;
21871 n = 3;
21872 while (unwind.opcode_count > 0)
21873 {
21874 unwind.opcode_count--;
21875 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21876 n--;
21877 }
bfae80f2 21878
c19d1205
ZW
21879 /* Pad with "finish" opcodes. */
21880 while (n--)
21881 data = (data << 8) | 0xb0;
bfae80f2 21882
c19d1205
ZW
21883 return data;
21884 }
21885 size = 0;
21886 }
21887 else
21888 /* We get two opcodes "free" in the first word. */
21889 size = unwind.opcode_count - 2;
21890 }
21891 else
5011093d 21892 {
cad0da33
NC
21893 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21894 if (unwind.personality_index != -1)
21895 {
21896 as_bad (_("attempt to recreate an unwind entry"));
21897 return 1;
21898 }
5011093d
NC
21899
21900 /* An extra byte is required for the opcode count. */
21901 size = unwind.opcode_count + 1;
21902 }
bfae80f2 21903
c19d1205
ZW
21904 size = (size + 3) >> 2;
21905 if (size > 0xff)
21906 as_bad (_("too many unwind opcodes"));
bfae80f2 21907
c19d1205
ZW
21908 frag_align (2, 0, 0);
21909 record_alignment (now_seg, 2);
21910 unwind.table_entry = expr_build_dot ();
21911
21912 /* Allocate the table entry. */
21913 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21914 /* PR 13449: Zero the table entries in case some of them are not used. */
21915 memset (ptr, 0, (size << 2) + 4);
c19d1205 21916 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21917
c19d1205 21918 switch (unwind.personality_index)
bfae80f2 21919 {
c19d1205
ZW
21920 case -1:
21921 /* ??? Should this be a PLT generating relocation? */
21922 /* Custom personality routine. */
21923 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21924 BFD_RELOC_ARM_PREL31);
bfae80f2 21925
c19d1205
ZW
21926 where += 4;
21927 ptr += 4;
bfae80f2 21928
c19d1205 21929 /* Set the first byte to the number of additional words. */
5011093d 21930 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21931 n = 3;
21932 break;
bfae80f2 21933
c19d1205
ZW
21934 /* ABI defined personality routines. */
21935 case 0:
21936 /* Three opcodes bytes are packed into the first word. */
21937 data = 0x80;
21938 n = 3;
21939 break;
bfae80f2 21940
c19d1205
ZW
21941 case 1:
21942 case 2:
21943 /* The size and first two opcode bytes go in the first word. */
21944 data = ((0x80 + unwind.personality_index) << 8) | size;
21945 n = 2;
21946 break;
bfae80f2 21947
c19d1205
ZW
21948 default:
21949 /* Should never happen. */
21950 abort ();
21951 }
bfae80f2 21952
c19d1205
ZW
21953 /* Pack the opcodes into words (MSB first), reversing the list at the same
21954 time. */
21955 while (unwind.opcode_count > 0)
21956 {
21957 if (n == 0)
21958 {
21959 md_number_to_chars (ptr, data, 4);
21960 ptr += 4;
21961 n = 4;
21962 data = 0;
21963 }
21964 unwind.opcode_count--;
21965 n--;
21966 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21967 }
21968
21969 /* Finish off the last word. */
21970 if (n < 4)
21971 {
21972 /* Pad with "finish" opcodes. */
21973 while (n--)
21974 data = (data << 8) | 0xb0;
21975
21976 md_number_to_chars (ptr, data, 4);
21977 }
21978
21979 if (!have_data)
21980 {
21981 /* Add an empty descriptor if there is no user-specified data. */
21982 ptr = frag_more (4);
21983 md_number_to_chars (ptr, 0, 4);
21984 }
21985
21986 return 0;
bfae80f2
RE
21987}
21988
f0927246
NC
21989
21990/* Initialize the DWARF-2 unwind information for this procedure. */
21991
21992void
21993tc_arm_frame_initial_instructions (void)
21994{
21995 cfi_add_CFA_def_cfa (REG_SP, 0);
21996}
21997#endif /* OBJ_ELF */
21998
c19d1205
ZW
21999/* Convert REGNAME to a DWARF-2 register number. */
22000
22001int
1df69f4f 22002tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22003{
1df69f4f 22004 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22005 if (reg != FAIL)
22006 return reg;
c19d1205 22007
1f5afe1c
NC
22008 /* PR 16694: Allow VFP registers as well. */
22009 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22010 if (reg != FAIL)
22011 return 64 + reg;
c19d1205 22012
1f5afe1c
NC
22013 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22014 if (reg != FAIL)
22015 return reg + 256;
22016
22017 return -1;
bfae80f2
RE
22018}
22019
f0927246 22020#ifdef TE_PE
c19d1205 22021void
f0927246 22022tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22023{
91d6fa6a 22024 expressionS exp;
bfae80f2 22025
91d6fa6a
NC
22026 exp.X_op = O_secrel;
22027 exp.X_add_symbol = symbol;
22028 exp.X_add_number = 0;
22029 emit_expr (&exp, size);
f0927246
NC
22030}
22031#endif
bfae80f2 22032
c19d1205 22033/* MD interface: Symbol and relocation handling. */
bfae80f2 22034
2fc8bdac
ZW
22035/* Return the address within the segment that a PC-relative fixup is
22036 relative to. For ARM, PC-relative fixups applied to instructions
22037 are generally relative to the location of the fixup plus 8 bytes.
22038 Thumb branches are offset by 4, and Thumb loads relative to PC
22039 require special handling. */
bfae80f2 22040
c19d1205 22041long
2fc8bdac 22042md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22043{
2fc8bdac
ZW
22044 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22045
22046 /* If this is pc-relative and we are going to emit a relocation
22047 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22048 will need. Otherwise we want to use the calculated base.
22049 For WinCE we skip the bias for externals as well, since this
22050 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22051 if (fixP->fx_pcrel
2fc8bdac 22052 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22053 || (arm_force_relocation (fixP)
22054#ifdef TE_WINCE
22055 && !S_IS_EXTERNAL (fixP->fx_addsy)
22056#endif
22057 )))
2fc8bdac 22058 base = 0;
bfae80f2 22059
267bf995 22060
c19d1205 22061 switch (fixP->fx_r_type)
bfae80f2 22062 {
2fc8bdac
ZW
22063 /* PC relative addressing on the Thumb is slightly odd as the
22064 bottom two bits of the PC are forced to zero for the
22065 calculation. This happens *after* application of the
22066 pipeline offset. However, Thumb adrl already adjusts for
22067 this, so we need not do it again. */
c19d1205 22068 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22069 return base & ~3;
c19d1205
ZW
22070
22071 case BFD_RELOC_ARM_THUMB_OFFSET:
22072 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22073 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22074 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22075 return (base + 4) & ~3;
c19d1205 22076
2fc8bdac
ZW
22077 /* Thumb branches are simply offset by +4. */
22078 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22079 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22080 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22081 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22082 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22083 return base + 4;
bfae80f2 22084
267bf995 22085 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22086 if (fixP->fx_addsy
22087 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22088 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22089 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22090 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22091 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22092 return base + 4;
22093
00adf2d4
JB
22094 /* BLX is like branches above, but forces the low two bits of PC to
22095 zero. */
486499d0
CL
22096 case BFD_RELOC_THUMB_PCREL_BLX:
22097 if (fixP->fx_addsy
22098 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22099 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22100 && THUMB_IS_FUNC (fixP->fx_addsy)
22101 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22102 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22103 return (base + 4) & ~3;
22104
2fc8bdac
ZW
22105 /* ARM mode branches are offset by +8. However, the Windows CE
22106 loader expects the relocation not to take this into account. */
267bf995 22107 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22108 if (fixP->fx_addsy
22109 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22110 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22111 && ARM_IS_FUNC (fixP->fx_addsy)
22112 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22113 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22114 return base + 8;
267bf995 22115
486499d0
CL
22116 case BFD_RELOC_ARM_PCREL_CALL:
22117 if (fixP->fx_addsy
22118 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22119 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22120 && THUMB_IS_FUNC (fixP->fx_addsy)
22121 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22122 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22123 return base + 8;
267bf995 22124
2fc8bdac 22125 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22126 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22127 case BFD_RELOC_ARM_PLT32:
c19d1205 22128#ifdef TE_WINCE
5f4273c7 22129 /* When handling fixups immediately, because we have already
477330fc 22130 discovered the value of a symbol, or the address of the frag involved
53baae48 22131 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22132 see fixup_segment() in write.c
22133 The S_IS_EXTERNAL test handles the case of global symbols.
22134 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22135 if (fixP->fx_pcrel
22136 && fixP->fx_addsy != NULL
22137 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22138 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22139 return base + 8;
2fc8bdac 22140 return base;
c19d1205 22141#else
2fc8bdac 22142 return base + 8;
c19d1205 22143#endif
2fc8bdac 22144
267bf995 22145
2fc8bdac
ZW
22146 /* ARM mode loads relative to PC are also offset by +8. Unlike
22147 branches, the Windows CE loader *does* expect the relocation
22148 to take this into account. */
22149 case BFD_RELOC_ARM_OFFSET_IMM:
22150 case BFD_RELOC_ARM_OFFSET_IMM8:
22151 case BFD_RELOC_ARM_HWLITERAL:
22152 case BFD_RELOC_ARM_LITERAL:
22153 case BFD_RELOC_ARM_CP_OFF_IMM:
22154 return base + 8;
22155
22156
22157 /* Other PC-relative relocations are un-offset. */
22158 default:
22159 return base;
22160 }
bfae80f2
RE
22161}
22162
8b2d793c
NC
22163static bfd_boolean flag_warn_syms = TRUE;
22164
ae8714c2
NC
22165bfd_boolean
22166arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22167{
8b2d793c
NC
22168 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22169 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22170 does mean that the resulting code might be very confusing to the reader.
22171 Also this warning can be triggered if the user omits an operand before
22172 an immediate address, eg:
22173
22174 LDR =foo
22175
22176 GAS treats this as an assignment of the value of the symbol foo to a
22177 symbol LDR, and so (without this code) it will not issue any kind of
22178 warning or error message.
22179
22180 Note - ARM instructions are case-insensitive but the strings in the hash
22181 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22182 lower case too. */
22183 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22184 {
22185 char * nbuf = strdup (name);
22186 char * p;
22187
22188 for (p = nbuf; *p; p++)
22189 *p = TOLOWER (*p);
22190 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22191 {
22192 static struct hash_control * already_warned = NULL;
22193
22194 if (already_warned == NULL)
22195 already_warned = hash_new ();
22196 /* Only warn about the symbol once. To keep the code
22197 simple we let hash_insert do the lookup for us. */
22198 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22199 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22200 }
22201 else
22202 free (nbuf);
22203 }
3739860c 22204
ae8714c2
NC
22205 return FALSE;
22206}
22207
22208/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22209 Otherwise we have no need to default values of symbols. */
22210
22211symbolS *
22212md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22213{
22214#ifdef OBJ_ELF
22215 if (name[0] == '_' && name[1] == 'G'
22216 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22217 {
22218 if (!GOT_symbol)
22219 {
22220 if (symbol_find (name))
22221 as_bad (_("GOT already in the symbol table"));
22222
22223 GOT_symbol = symbol_new (name, undefined_section,
22224 (valueT) 0, & zero_address_frag);
22225 }
22226
22227 return GOT_symbol;
22228 }
22229#endif
22230
c921be7d 22231 return NULL;
bfae80f2
RE
22232}
22233
55cf6793 22234/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22235 computed as two separate immediate values, added together. We
22236 already know that this value cannot be computed by just one ARM
22237 instruction. */
22238
22239static unsigned int
22240validate_immediate_twopart (unsigned int val,
22241 unsigned int * highpart)
bfae80f2 22242{
c19d1205
ZW
22243 unsigned int a;
22244 unsigned int i;
bfae80f2 22245
c19d1205
ZW
22246 for (i = 0; i < 32; i += 2)
22247 if (((a = rotate_left (val, i)) & 0xff) != 0)
22248 {
22249 if (a & 0xff00)
22250 {
22251 if (a & ~ 0xffff)
22252 continue;
22253 * highpart = (a >> 8) | ((i + 24) << 7);
22254 }
22255 else if (a & 0xff0000)
22256 {
22257 if (a & 0xff000000)
22258 continue;
22259 * highpart = (a >> 16) | ((i + 16) << 7);
22260 }
22261 else
22262 {
9c2799c2 22263 gas_assert (a & 0xff000000);
c19d1205
ZW
22264 * highpart = (a >> 24) | ((i + 8) << 7);
22265 }
bfae80f2 22266
c19d1205
ZW
22267 return (a & 0xff) | (i << 7);
22268 }
bfae80f2 22269
c19d1205 22270 return FAIL;
bfae80f2
RE
22271}
22272
c19d1205
ZW
22273static int
22274validate_offset_imm (unsigned int val, int hwse)
22275{
22276 if ((hwse && val > 255) || val > 4095)
22277 return FAIL;
22278 return val;
22279}
bfae80f2 22280
55cf6793 22281/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22282 negative immediate constant by altering the instruction. A bit of
22283 a hack really.
22284 MOV <-> MVN
22285 AND <-> BIC
22286 ADC <-> SBC
22287 by inverting the second operand, and
22288 ADD <-> SUB
22289 CMP <-> CMN
22290 by negating the second operand. */
bfae80f2 22291
c19d1205
ZW
22292static int
22293negate_data_op (unsigned long * instruction,
22294 unsigned long value)
bfae80f2 22295{
c19d1205
ZW
22296 int op, new_inst;
22297 unsigned long negated, inverted;
bfae80f2 22298
c19d1205
ZW
22299 negated = encode_arm_immediate (-value);
22300 inverted = encode_arm_immediate (~value);
bfae80f2 22301
c19d1205
ZW
22302 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22303 switch (op)
bfae80f2 22304 {
c19d1205
ZW
22305 /* First negates. */
22306 case OPCODE_SUB: /* ADD <-> SUB */
22307 new_inst = OPCODE_ADD;
22308 value = negated;
22309 break;
bfae80f2 22310
c19d1205
ZW
22311 case OPCODE_ADD:
22312 new_inst = OPCODE_SUB;
22313 value = negated;
22314 break;
bfae80f2 22315
c19d1205
ZW
22316 case OPCODE_CMP: /* CMP <-> CMN */
22317 new_inst = OPCODE_CMN;
22318 value = negated;
22319 break;
bfae80f2 22320
c19d1205
ZW
22321 case OPCODE_CMN:
22322 new_inst = OPCODE_CMP;
22323 value = negated;
22324 break;
bfae80f2 22325
c19d1205
ZW
22326 /* Now Inverted ops. */
22327 case OPCODE_MOV: /* MOV <-> MVN */
22328 new_inst = OPCODE_MVN;
22329 value = inverted;
22330 break;
bfae80f2 22331
c19d1205
ZW
22332 case OPCODE_MVN:
22333 new_inst = OPCODE_MOV;
22334 value = inverted;
22335 break;
bfae80f2 22336
c19d1205
ZW
22337 case OPCODE_AND: /* AND <-> BIC */
22338 new_inst = OPCODE_BIC;
22339 value = inverted;
22340 break;
bfae80f2 22341
c19d1205
ZW
22342 case OPCODE_BIC:
22343 new_inst = OPCODE_AND;
22344 value = inverted;
22345 break;
bfae80f2 22346
c19d1205
ZW
22347 case OPCODE_ADC: /* ADC <-> SBC */
22348 new_inst = OPCODE_SBC;
22349 value = inverted;
22350 break;
bfae80f2 22351
c19d1205
ZW
22352 case OPCODE_SBC:
22353 new_inst = OPCODE_ADC;
22354 value = inverted;
22355 break;
bfae80f2 22356
c19d1205
ZW
22357 /* We cannot do anything. */
22358 default:
22359 return FAIL;
b99bd4ef
NC
22360 }
22361
c19d1205
ZW
22362 if (value == (unsigned) FAIL)
22363 return FAIL;
22364
22365 *instruction &= OPCODE_MASK;
22366 *instruction |= new_inst << DATA_OP_SHIFT;
22367 return value;
b99bd4ef
NC
22368}
22369
ef8d22e6
PB
22370/* Like negate_data_op, but for Thumb-2. */
22371
22372static unsigned int
16dd5e42 22373thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22374{
22375 int op, new_inst;
22376 int rd;
16dd5e42 22377 unsigned int negated, inverted;
ef8d22e6
PB
22378
22379 negated = encode_thumb32_immediate (-value);
22380 inverted = encode_thumb32_immediate (~value);
22381
22382 rd = (*instruction >> 8) & 0xf;
22383 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22384 switch (op)
22385 {
22386 /* ADD <-> SUB. Includes CMP <-> CMN. */
22387 case T2_OPCODE_SUB:
22388 new_inst = T2_OPCODE_ADD;
22389 value = negated;
22390 break;
22391
22392 case T2_OPCODE_ADD:
22393 new_inst = T2_OPCODE_SUB;
22394 value = negated;
22395 break;
22396
22397 /* ORR <-> ORN. Includes MOV <-> MVN. */
22398 case T2_OPCODE_ORR:
22399 new_inst = T2_OPCODE_ORN;
22400 value = inverted;
22401 break;
22402
22403 case T2_OPCODE_ORN:
22404 new_inst = T2_OPCODE_ORR;
22405 value = inverted;
22406 break;
22407
22408 /* AND <-> BIC. TST has no inverted equivalent. */
22409 case T2_OPCODE_AND:
22410 new_inst = T2_OPCODE_BIC;
22411 if (rd == 15)
22412 value = FAIL;
22413 else
22414 value = inverted;
22415 break;
22416
22417 case T2_OPCODE_BIC:
22418 new_inst = T2_OPCODE_AND;
22419 value = inverted;
22420 break;
22421
22422 /* ADC <-> SBC */
22423 case T2_OPCODE_ADC:
22424 new_inst = T2_OPCODE_SBC;
22425 value = inverted;
22426 break;
22427
22428 case T2_OPCODE_SBC:
22429 new_inst = T2_OPCODE_ADC;
22430 value = inverted;
22431 break;
22432
22433 /* We cannot do anything. */
22434 default:
22435 return FAIL;
22436 }
22437
16dd5e42 22438 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22439 return FAIL;
22440
22441 *instruction &= T2_OPCODE_MASK;
22442 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22443 return value;
22444}
22445
8f06b2d8
PB
22446/* Read a 32-bit thumb instruction from buf. */
22447static unsigned long
22448get_thumb32_insn (char * buf)
22449{
22450 unsigned long insn;
22451 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22452 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22453
22454 return insn;
22455}
22456
a8bc6c78
PB
22457
22458/* We usually want to set the low bit on the address of thumb function
22459 symbols. In particular .word foo - . should have the low bit set.
22460 Generic code tries to fold the difference of two symbols to
22461 a constant. Prevent this and force a relocation when the first symbols
22462 is a thumb function. */
c921be7d
NC
22463
22464bfd_boolean
a8bc6c78
PB
22465arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22466{
22467 if (op == O_subtract
22468 && l->X_op == O_symbol
22469 && r->X_op == O_symbol
22470 && THUMB_IS_FUNC (l->X_add_symbol))
22471 {
22472 l->X_op = O_subtract;
22473 l->X_op_symbol = r->X_add_symbol;
22474 l->X_add_number -= r->X_add_number;
c921be7d 22475 return TRUE;
a8bc6c78 22476 }
c921be7d 22477
a8bc6c78 22478 /* Process as normal. */
c921be7d 22479 return FALSE;
a8bc6c78
PB
22480}
22481
4a42ebbc
RR
22482/* Encode Thumb2 unconditional branches and calls. The encoding
22483 for the 2 are identical for the immediate values. */
22484
22485static void
22486encode_thumb2_b_bl_offset (char * buf, offsetT value)
22487{
22488#define T2I1I2MASK ((1 << 13) | (1 << 11))
22489 offsetT newval;
22490 offsetT newval2;
22491 addressT S, I1, I2, lo, hi;
22492
22493 S = (value >> 24) & 0x01;
22494 I1 = (value >> 23) & 0x01;
22495 I2 = (value >> 22) & 0x01;
22496 hi = (value >> 12) & 0x3ff;
fa94de6b 22497 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22498 newval = md_chars_to_number (buf, THUMB_SIZE);
22499 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22500 newval |= (S << 10) | hi;
22501 newval2 &= ~T2I1I2MASK;
22502 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22503 md_number_to_chars (buf, newval, THUMB_SIZE);
22504 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22505}
22506
c19d1205 22507void
55cf6793 22508md_apply_fix (fixS * fixP,
c19d1205
ZW
22509 valueT * valP,
22510 segT seg)
22511{
22512 offsetT value = * valP;
22513 offsetT newval;
22514 unsigned int newimm;
22515 unsigned long temp;
22516 int sign;
22517 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22518
9c2799c2 22519 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22520
c19d1205 22521 /* Note whether this will delete the relocation. */
4962c51a 22522
c19d1205
ZW
22523 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22524 fixP->fx_done = 1;
b99bd4ef 22525
adbaf948 22526 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22527 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22528 for emit_reloc. */
22529 value &= 0xffffffff;
22530 value ^= 0x80000000;
5f4273c7 22531 value -= 0x80000000;
adbaf948
ZW
22532
22533 *valP = value;
c19d1205 22534 fixP->fx_addnumber = value;
b99bd4ef 22535
adbaf948
ZW
22536 /* Same treatment for fixP->fx_offset. */
22537 fixP->fx_offset &= 0xffffffff;
22538 fixP->fx_offset ^= 0x80000000;
22539 fixP->fx_offset -= 0x80000000;
22540
c19d1205 22541 switch (fixP->fx_r_type)
b99bd4ef 22542 {
c19d1205
ZW
22543 case BFD_RELOC_NONE:
22544 /* This will need to go in the object file. */
22545 fixP->fx_done = 0;
22546 break;
b99bd4ef 22547
c19d1205
ZW
22548 case BFD_RELOC_ARM_IMMEDIATE:
22549 /* We claim that this fixup has been processed here,
22550 even if in fact we generate an error because we do
22551 not have a reloc for it, so tc_gen_reloc will reject it. */
22552 fixP->fx_done = 1;
b99bd4ef 22553
77db8e2e 22554 if (fixP->fx_addsy)
b99bd4ef 22555 {
77db8e2e 22556 const char *msg = 0;
b99bd4ef 22557
77db8e2e
NC
22558 if (! S_IS_DEFINED (fixP->fx_addsy))
22559 msg = _("undefined symbol %s used as an immediate value");
22560 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22561 msg = _("symbol %s is in a different section");
22562 else if (S_IS_WEAK (fixP->fx_addsy))
22563 msg = _("symbol %s is weak and may be overridden later");
22564
22565 if (msg)
22566 {
22567 as_bad_where (fixP->fx_file, fixP->fx_line,
22568 msg, S_GET_NAME (fixP->fx_addsy));
22569 break;
22570 }
42e5fcbf
AS
22571 }
22572
c19d1205
ZW
22573 temp = md_chars_to_number (buf, INSN_SIZE);
22574
5e73442d
SL
22575 /* If the offset is negative, we should use encoding A2 for ADR. */
22576 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22577 newimm = negate_data_op (&temp, value);
22578 else
22579 {
22580 newimm = encode_arm_immediate (value);
22581
22582 /* If the instruction will fail, see if we can fix things up by
22583 changing the opcode. */
22584 if (newimm == (unsigned int) FAIL)
22585 newimm = negate_data_op (&temp, value);
22586 }
22587
22588 if (newimm == (unsigned int) FAIL)
b99bd4ef 22589 {
c19d1205
ZW
22590 as_bad_where (fixP->fx_file, fixP->fx_line,
22591 _("invalid constant (%lx) after fixup"),
22592 (unsigned long) value);
22593 break;
b99bd4ef 22594 }
b99bd4ef 22595
c19d1205
ZW
22596 newimm |= (temp & 0xfffff000);
22597 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22598 break;
b99bd4ef 22599
c19d1205
ZW
22600 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22601 {
22602 unsigned int highpart = 0;
22603 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22604
77db8e2e 22605 if (fixP->fx_addsy)
42e5fcbf 22606 {
77db8e2e 22607 const char *msg = 0;
42e5fcbf 22608
77db8e2e
NC
22609 if (! S_IS_DEFINED (fixP->fx_addsy))
22610 msg = _("undefined symbol %s used as an immediate value");
22611 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22612 msg = _("symbol %s is in a different section");
22613 else if (S_IS_WEAK (fixP->fx_addsy))
22614 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22615
77db8e2e
NC
22616 if (msg)
22617 {
22618 as_bad_where (fixP->fx_file, fixP->fx_line,
22619 msg, S_GET_NAME (fixP->fx_addsy));
22620 break;
22621 }
22622 }
fa94de6b 22623
c19d1205
ZW
22624 newimm = encode_arm_immediate (value);
22625 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22626
c19d1205
ZW
22627 /* If the instruction will fail, see if we can fix things up by
22628 changing the opcode. */
22629 if (newimm == (unsigned int) FAIL
22630 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22631 {
22632 /* No ? OK - try using two ADD instructions to generate
22633 the value. */
22634 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22635
c19d1205
ZW
22636 /* Yes - then make sure that the second instruction is
22637 also an add. */
22638 if (newimm != (unsigned int) FAIL)
22639 newinsn = temp;
22640 /* Still No ? Try using a negated value. */
22641 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22642 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22643 /* Otherwise - give up. */
22644 else
22645 {
22646 as_bad_where (fixP->fx_file, fixP->fx_line,
22647 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22648 (long) value);
22649 break;
22650 }
b99bd4ef 22651
c19d1205
ZW
22652 /* Replace the first operand in the 2nd instruction (which
22653 is the PC) with the destination register. We have
22654 already added in the PC in the first instruction and we
22655 do not want to do it again. */
22656 newinsn &= ~ 0xf0000;
22657 newinsn |= ((newinsn & 0x0f000) << 4);
22658 }
b99bd4ef 22659
c19d1205
ZW
22660 newimm |= (temp & 0xfffff000);
22661 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22662
c19d1205
ZW
22663 highpart |= (newinsn & 0xfffff000);
22664 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22665 }
22666 break;
b99bd4ef 22667
c19d1205 22668 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22669 if (!fixP->fx_done && seg->use_rela_p)
22670 value = 0;
22671
c19d1205 22672 case BFD_RELOC_ARM_LITERAL:
26d97720 22673 sign = value > 0;
b99bd4ef 22674
c19d1205
ZW
22675 if (value < 0)
22676 value = - value;
b99bd4ef 22677
c19d1205 22678 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22679 {
c19d1205
ZW
22680 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22681 as_bad_where (fixP->fx_file, fixP->fx_line,
22682 _("invalid literal constant: pool needs to be closer"));
22683 else
22684 as_bad_where (fixP->fx_file, fixP->fx_line,
22685 _("bad immediate value for offset (%ld)"),
22686 (long) value);
22687 break;
f03698e6
RE
22688 }
22689
c19d1205 22690 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22691 if (value == 0)
22692 newval &= 0xfffff000;
22693 else
22694 {
22695 newval &= 0xff7ff000;
22696 newval |= value | (sign ? INDEX_UP : 0);
22697 }
c19d1205
ZW
22698 md_number_to_chars (buf, newval, INSN_SIZE);
22699 break;
b99bd4ef 22700
c19d1205
ZW
22701 case BFD_RELOC_ARM_OFFSET_IMM8:
22702 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22703 sign = value > 0;
b99bd4ef 22704
c19d1205
ZW
22705 if (value < 0)
22706 value = - value;
b99bd4ef 22707
c19d1205 22708 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22709 {
c19d1205
ZW
22710 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22711 as_bad_where (fixP->fx_file, fixP->fx_line,
22712 _("invalid literal constant: pool needs to be closer"));
22713 else
427d0db6
RM
22714 as_bad_where (fixP->fx_file, fixP->fx_line,
22715 _("bad immediate value for 8-bit offset (%ld)"),
22716 (long) value);
c19d1205 22717 break;
b99bd4ef
NC
22718 }
22719
c19d1205 22720 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22721 if (value == 0)
22722 newval &= 0xfffff0f0;
22723 else
22724 {
22725 newval &= 0xff7ff0f0;
22726 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22727 }
c19d1205
ZW
22728 md_number_to_chars (buf, newval, INSN_SIZE);
22729 break;
b99bd4ef 22730
c19d1205
ZW
22731 case BFD_RELOC_ARM_T32_OFFSET_U8:
22732 if (value < 0 || value > 1020 || value % 4 != 0)
22733 as_bad_where (fixP->fx_file, fixP->fx_line,
22734 _("bad immediate value for offset (%ld)"), (long) value);
22735 value /= 4;
b99bd4ef 22736
c19d1205 22737 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22738 newval |= value;
22739 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22740 break;
b99bd4ef 22741
c19d1205
ZW
22742 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22743 /* This is a complicated relocation used for all varieties of Thumb32
22744 load/store instruction with immediate offset:
22745
22746 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22747 *4, optional writeback(W)
c19d1205
ZW
22748 (doubleword load/store)
22749
22750 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22751 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22752 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22753 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22754 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22755
22756 Uppercase letters indicate bits that are already encoded at
22757 this point. Lowercase letters are our problem. For the
22758 second block of instructions, the secondary opcode nybble
22759 (bits 8..11) is present, and bit 23 is zero, even if this is
22760 a PC-relative operation. */
22761 newval = md_chars_to_number (buf, THUMB_SIZE);
22762 newval <<= 16;
22763 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22764
c19d1205 22765 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22766 {
c19d1205
ZW
22767 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22768 if (value >= 0)
22769 newval |= (1 << 23);
22770 else
22771 value = -value;
22772 if (value % 4 != 0)
22773 {
22774 as_bad_where (fixP->fx_file, fixP->fx_line,
22775 _("offset not a multiple of 4"));
22776 break;
22777 }
22778 value /= 4;
216d22bc 22779 if (value > 0xff)
c19d1205
ZW
22780 {
22781 as_bad_where (fixP->fx_file, fixP->fx_line,
22782 _("offset out of range"));
22783 break;
22784 }
22785 newval &= ~0xff;
b99bd4ef 22786 }
c19d1205 22787 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22788 {
c19d1205
ZW
22789 /* PC-relative, 12-bit offset. */
22790 if (value >= 0)
22791 newval |= (1 << 23);
22792 else
22793 value = -value;
216d22bc 22794 if (value > 0xfff)
c19d1205
ZW
22795 {
22796 as_bad_where (fixP->fx_file, fixP->fx_line,
22797 _("offset out of range"));
22798 break;
22799 }
22800 newval &= ~0xfff;
b99bd4ef 22801 }
c19d1205 22802 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22803 {
c19d1205
ZW
22804 /* Writeback: 8-bit, +/- offset. */
22805 if (value >= 0)
22806 newval |= (1 << 9);
22807 else
22808 value = -value;
216d22bc 22809 if (value > 0xff)
c19d1205
ZW
22810 {
22811 as_bad_where (fixP->fx_file, fixP->fx_line,
22812 _("offset out of range"));
22813 break;
22814 }
22815 newval &= ~0xff;
b99bd4ef 22816 }
c19d1205 22817 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22818 {
c19d1205 22819 /* T-instruction: positive 8-bit offset. */
216d22bc 22820 if (value < 0 || value > 0xff)
b99bd4ef 22821 {
c19d1205
ZW
22822 as_bad_where (fixP->fx_file, fixP->fx_line,
22823 _("offset out of range"));
22824 break;
b99bd4ef 22825 }
c19d1205
ZW
22826 newval &= ~0xff;
22827 newval |= value;
b99bd4ef
NC
22828 }
22829 else
b99bd4ef 22830 {
c19d1205
ZW
22831 /* Positive 12-bit or negative 8-bit offset. */
22832 int limit;
22833 if (value >= 0)
b99bd4ef 22834 {
c19d1205
ZW
22835 newval |= (1 << 23);
22836 limit = 0xfff;
22837 }
22838 else
22839 {
22840 value = -value;
22841 limit = 0xff;
22842 }
22843 if (value > limit)
22844 {
22845 as_bad_where (fixP->fx_file, fixP->fx_line,
22846 _("offset out of range"));
22847 break;
b99bd4ef 22848 }
c19d1205 22849 newval &= ~limit;
b99bd4ef 22850 }
b99bd4ef 22851
c19d1205
ZW
22852 newval |= value;
22853 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22854 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22855 break;
404ff6b5 22856
c19d1205
ZW
22857 case BFD_RELOC_ARM_SHIFT_IMM:
22858 newval = md_chars_to_number (buf, INSN_SIZE);
22859 if (((unsigned long) value) > 32
22860 || (value == 32
22861 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22862 {
22863 as_bad_where (fixP->fx_file, fixP->fx_line,
22864 _("shift expression is too large"));
22865 break;
22866 }
404ff6b5 22867
c19d1205
ZW
22868 if (value == 0)
22869 /* Shifts of zero must be done as lsl. */
22870 newval &= ~0x60;
22871 else if (value == 32)
22872 value = 0;
22873 newval &= 0xfffff07f;
22874 newval |= (value & 0x1f) << 7;
22875 md_number_to_chars (buf, newval, INSN_SIZE);
22876 break;
404ff6b5 22877
c19d1205 22878 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22879 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22880 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22881 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22882 /* We claim that this fixup has been processed here,
22883 even if in fact we generate an error because we do
22884 not have a reloc for it, so tc_gen_reloc will reject it. */
22885 fixP->fx_done = 1;
404ff6b5 22886
c19d1205
ZW
22887 if (fixP->fx_addsy
22888 && ! S_IS_DEFINED (fixP->fx_addsy))
22889 {
22890 as_bad_where (fixP->fx_file, fixP->fx_line,
22891 _("undefined symbol %s used as an immediate value"),
22892 S_GET_NAME (fixP->fx_addsy));
22893 break;
22894 }
404ff6b5 22895
c19d1205
ZW
22896 newval = md_chars_to_number (buf, THUMB_SIZE);
22897 newval <<= 16;
22898 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22899
16805f35
PB
22900 newimm = FAIL;
22901 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22902 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22903 {
22904 newimm = encode_thumb32_immediate (value);
22905 if (newimm == (unsigned int) FAIL)
22906 newimm = thumb32_negate_data_op (&newval, value);
22907 }
16805f35
PB
22908 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22909 && newimm == (unsigned int) FAIL)
92e90b6e 22910 {
16805f35
PB
22911 /* Turn add/sum into addw/subw. */
22912 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22913 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22914 /* No flat 12-bit imm encoding for addsw/subsw. */
22915 if ((newval & 0x00100000) == 0)
e9f89963 22916 {
40f246e3
NC
22917 /* 12 bit immediate for addw/subw. */
22918 if (value < 0)
22919 {
22920 value = -value;
22921 newval ^= 0x00a00000;
22922 }
22923 if (value > 0xfff)
22924 newimm = (unsigned int) FAIL;
22925 else
22926 newimm = value;
e9f89963 22927 }
92e90b6e 22928 }
cc8a6dd0 22929
c19d1205 22930 if (newimm == (unsigned int)FAIL)
3631a3c8 22931 {
c19d1205
ZW
22932 as_bad_where (fixP->fx_file, fixP->fx_line,
22933 _("invalid constant (%lx) after fixup"),
22934 (unsigned long) value);
22935 break;
3631a3c8
NC
22936 }
22937
c19d1205
ZW
22938 newval |= (newimm & 0x800) << 15;
22939 newval |= (newimm & 0x700) << 4;
22940 newval |= (newimm & 0x0ff);
cc8a6dd0 22941
c19d1205
ZW
22942 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22943 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22944 break;
a737bd4d 22945
3eb17e6b 22946 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22947 if (((unsigned long) value) > 0xffff)
22948 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22949 _("invalid smc expression"));
2fc8bdac 22950 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22951 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22952 md_number_to_chars (buf, newval, INSN_SIZE);
22953 break;
a737bd4d 22954
90ec0d68
MGD
22955 case BFD_RELOC_ARM_HVC:
22956 if (((unsigned long) value) > 0xffff)
22957 as_bad_where (fixP->fx_file, fixP->fx_line,
22958 _("invalid hvc expression"));
22959 newval = md_chars_to_number (buf, INSN_SIZE);
22960 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22961 md_number_to_chars (buf, newval, INSN_SIZE);
22962 break;
22963
c19d1205 22964 case BFD_RELOC_ARM_SWI:
adbaf948 22965 if (fixP->tc_fix_data != 0)
c19d1205
ZW
22966 {
22967 if (((unsigned long) value) > 0xff)
22968 as_bad_where (fixP->fx_file, fixP->fx_line,
22969 _("invalid swi expression"));
2fc8bdac 22970 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
22971 newval |= value;
22972 md_number_to_chars (buf, newval, THUMB_SIZE);
22973 }
22974 else
22975 {
22976 if (((unsigned long) value) > 0x00ffffff)
22977 as_bad_where (fixP->fx_file, fixP->fx_line,
22978 _("invalid swi expression"));
2fc8bdac 22979 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22980 newval |= value;
22981 md_number_to_chars (buf, newval, INSN_SIZE);
22982 }
22983 break;
a737bd4d 22984
c19d1205
ZW
22985 case BFD_RELOC_ARM_MULTI:
22986 if (((unsigned long) value) > 0xffff)
22987 as_bad_where (fixP->fx_file, fixP->fx_line,
22988 _("invalid expression in load/store multiple"));
22989 newval = value | md_chars_to_number (buf, INSN_SIZE);
22990 md_number_to_chars (buf, newval, INSN_SIZE);
22991 break;
a737bd4d 22992
c19d1205 22993#ifdef OBJ_ELF
39b41c9c 22994 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
22995
22996 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22997 && fixP->fx_addsy
34e77a92 22998 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22999 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23000 && THUMB_IS_FUNC (fixP->fx_addsy))
23001 /* Flip the bl to blx. This is a simple flip
23002 bit here because we generate PCREL_CALL for
23003 unconditional bls. */
23004 {
23005 newval = md_chars_to_number (buf, INSN_SIZE);
23006 newval = newval | 0x10000000;
23007 md_number_to_chars (buf, newval, INSN_SIZE);
23008 temp = 1;
23009 fixP->fx_done = 1;
23010 }
39b41c9c
PB
23011 else
23012 temp = 3;
23013 goto arm_branch_common;
23014
23015 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23016 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23017 && fixP->fx_addsy
34e77a92 23018 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23019 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23020 && THUMB_IS_FUNC (fixP->fx_addsy))
23021 {
23022 /* This would map to a bl<cond>, b<cond>,
23023 b<always> to a Thumb function. We
23024 need to force a relocation for this particular
23025 case. */
23026 newval = md_chars_to_number (buf, INSN_SIZE);
23027 fixP->fx_done = 0;
23028 }
23029
2fc8bdac 23030 case BFD_RELOC_ARM_PLT32:
c19d1205 23031#endif
39b41c9c
PB
23032 case BFD_RELOC_ARM_PCREL_BRANCH:
23033 temp = 3;
23034 goto arm_branch_common;
a737bd4d 23035
39b41c9c 23036 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23037
39b41c9c 23038 temp = 1;
267bf995
RR
23039 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23040 && fixP->fx_addsy
34e77a92 23041 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23042 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23043 && ARM_IS_FUNC (fixP->fx_addsy))
23044 {
23045 /* Flip the blx to a bl and warn. */
23046 const char *name = S_GET_NAME (fixP->fx_addsy);
23047 newval = 0xeb000000;
23048 as_warn_where (fixP->fx_file, fixP->fx_line,
23049 _("blx to '%s' an ARM ISA state function changed to bl"),
23050 name);
23051 md_number_to_chars (buf, newval, INSN_SIZE);
23052 temp = 3;
23053 fixP->fx_done = 1;
23054 }
23055
23056#ifdef OBJ_ELF
23057 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23058 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23059#endif
23060
39b41c9c 23061 arm_branch_common:
c19d1205 23062 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23063 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23064 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23065 also be be clear. */
23066 if (value & temp)
c19d1205 23067 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23068 _("misaligned branch destination"));
23069 if ((value & (offsetT)0xfe000000) != (offsetT)0
23070 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23071 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23072
2fc8bdac 23073 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23074 {
2fc8bdac
ZW
23075 newval = md_chars_to_number (buf, INSN_SIZE);
23076 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23077 /* Set the H bit on BLX instructions. */
23078 if (temp == 1)
23079 {
23080 if (value & 2)
23081 newval |= 0x01000000;
23082 else
23083 newval &= ~0x01000000;
23084 }
2fc8bdac 23085 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23086 }
c19d1205 23087 break;
a737bd4d 23088
25fe350b
MS
23089 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23090 /* CBZ can only branch forward. */
a737bd4d 23091
738755b0 23092 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23093 (which, strictly speaking, are prohibited) will be turned into
23094 no-ops.
738755b0
MS
23095
23096 FIXME: It may be better to remove the instruction completely and
23097 perform relaxation. */
23098 if (value == -2)
2fc8bdac
ZW
23099 {
23100 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23101 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23102 md_number_to_chars (buf, newval, THUMB_SIZE);
23103 }
738755b0
MS
23104 else
23105 {
23106 if (value & ~0x7e)
08f10d51 23107 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23108
477330fc 23109 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23110 {
23111 newval = md_chars_to_number (buf, THUMB_SIZE);
23112 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23113 md_number_to_chars (buf, newval, THUMB_SIZE);
23114 }
23115 }
c19d1205 23116 break;
a737bd4d 23117
c19d1205 23118 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23119 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23120 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23121
2fc8bdac
ZW
23122 if (fixP->fx_done || !seg->use_rela_p)
23123 {
23124 newval = md_chars_to_number (buf, THUMB_SIZE);
23125 newval |= (value & 0x1ff) >> 1;
23126 md_number_to_chars (buf, newval, THUMB_SIZE);
23127 }
c19d1205 23128 break;
a737bd4d 23129
c19d1205 23130 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23131 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23132 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23133
2fc8bdac
ZW
23134 if (fixP->fx_done || !seg->use_rela_p)
23135 {
23136 newval = md_chars_to_number (buf, THUMB_SIZE);
23137 newval |= (value & 0xfff) >> 1;
23138 md_number_to_chars (buf, newval, THUMB_SIZE);
23139 }
c19d1205 23140 break;
a737bd4d 23141
c19d1205 23142 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23143 if (fixP->fx_addsy
23144 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23145 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23146 && ARM_IS_FUNC (fixP->fx_addsy)
23147 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23148 {
23149 /* Force a relocation for a branch 20 bits wide. */
23150 fixP->fx_done = 0;
23151 }
08f10d51 23152 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23153 as_bad_where (fixP->fx_file, fixP->fx_line,
23154 _("conditional branch out of range"));
404ff6b5 23155
2fc8bdac
ZW
23156 if (fixP->fx_done || !seg->use_rela_p)
23157 {
23158 offsetT newval2;
23159 addressT S, J1, J2, lo, hi;
404ff6b5 23160
2fc8bdac
ZW
23161 S = (value & 0x00100000) >> 20;
23162 J2 = (value & 0x00080000) >> 19;
23163 J1 = (value & 0x00040000) >> 18;
23164 hi = (value & 0x0003f000) >> 12;
23165 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23166
2fc8bdac
ZW
23167 newval = md_chars_to_number (buf, THUMB_SIZE);
23168 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23169 newval |= (S << 10) | hi;
23170 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23171 md_number_to_chars (buf, newval, THUMB_SIZE);
23172 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23173 }
c19d1205 23174 break;
6c43fab6 23175
c19d1205 23176 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23177 /* If there is a blx from a thumb state function to
23178 another thumb function flip this to a bl and warn
23179 about it. */
23180
23181 if (fixP->fx_addsy
34e77a92 23182 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23183 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23184 && THUMB_IS_FUNC (fixP->fx_addsy))
23185 {
23186 const char *name = S_GET_NAME (fixP->fx_addsy);
23187 as_warn_where (fixP->fx_file, fixP->fx_line,
23188 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23189 name);
23190 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23191 newval = newval | 0x1000;
23192 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23193 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23194 fixP->fx_done = 1;
23195 }
23196
23197
23198 goto thumb_bl_common;
23199
c19d1205 23200 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23201 /* A bl from Thumb state ISA to an internal ARM state function
23202 is converted to a blx. */
23203 if (fixP->fx_addsy
23204 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23205 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23206 && ARM_IS_FUNC (fixP->fx_addsy)
23207 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23208 {
23209 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23210 newval = newval & ~0x1000;
23211 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23212 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23213 fixP->fx_done = 1;
23214 }
23215
23216 thumb_bl_common:
23217
2fc8bdac
ZW
23218 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23219 /* For a BLX instruction, make sure that the relocation is rounded up
23220 to a word boundary. This follows the semantics of the instruction
23221 which specifies that bit 1 of the target address will come from bit
23222 1 of the base address. */
d406f3e4
JB
23223 value = (value + 3) & ~ 3;
23224
23225#ifdef OBJ_ELF
23226 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23227 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23228 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23229#endif
404ff6b5 23230
2b2f5df9
NC
23231 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23232 {
fc289b0a 23233 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23234 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23235 else if ((value & ~0x1ffffff)
23236 && ((value & ~0x1ffffff) != ~0x1ffffff))
23237 as_bad_where (fixP->fx_file, fixP->fx_line,
23238 _("Thumb2 branch out of range"));
23239 }
4a42ebbc
RR
23240
23241 if (fixP->fx_done || !seg->use_rela_p)
23242 encode_thumb2_b_bl_offset (buf, value);
23243
c19d1205 23244 break;
404ff6b5 23245
c19d1205 23246 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23247 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23248 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23249
2fc8bdac 23250 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23251 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23252
2fc8bdac 23253 break;
a737bd4d 23254
2fc8bdac
ZW
23255 case BFD_RELOC_8:
23256 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23257 *buf = value;
c19d1205 23258 break;
a737bd4d 23259
c19d1205 23260 case BFD_RELOC_16:
2fc8bdac 23261 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23262 md_number_to_chars (buf, value, 2);
c19d1205 23263 break;
a737bd4d 23264
c19d1205 23265#ifdef OBJ_ELF
0855e32b
NS
23266 case BFD_RELOC_ARM_TLS_CALL:
23267 case BFD_RELOC_ARM_THM_TLS_CALL:
23268 case BFD_RELOC_ARM_TLS_DESCSEQ:
23269 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23270 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23271 case BFD_RELOC_ARM_TLS_GD32:
23272 case BFD_RELOC_ARM_TLS_LE32:
23273 case BFD_RELOC_ARM_TLS_IE32:
23274 case BFD_RELOC_ARM_TLS_LDM32:
23275 case BFD_RELOC_ARM_TLS_LDO32:
23276 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23277 break;
6c43fab6 23278
c19d1205
ZW
23279 case BFD_RELOC_ARM_GOT32:
23280 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23281 break;
b43420e6
NC
23282
23283 case BFD_RELOC_ARM_GOT_PREL:
23284 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23285 md_number_to_chars (buf, value, 4);
b43420e6
NC
23286 break;
23287
9a6f4e97
NS
23288 case BFD_RELOC_ARM_TARGET2:
23289 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23290 addend here for REL targets, because it won't be written out
23291 during reloc processing later. */
9a6f4e97
NS
23292 if (fixP->fx_done || !seg->use_rela_p)
23293 md_number_to_chars (buf, fixP->fx_offset, 4);
23294 break;
c19d1205 23295#endif
6c43fab6 23296
c19d1205
ZW
23297 case BFD_RELOC_RVA:
23298 case BFD_RELOC_32:
23299 case BFD_RELOC_ARM_TARGET1:
23300 case BFD_RELOC_ARM_ROSEGREL32:
23301 case BFD_RELOC_ARM_SBREL32:
23302 case BFD_RELOC_32_PCREL:
f0927246
NC
23303#ifdef TE_PE
23304 case BFD_RELOC_32_SECREL:
23305#endif
2fc8bdac 23306 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23307#ifdef TE_WINCE
23308 /* For WinCE we only do this for pcrel fixups. */
23309 if (fixP->fx_done || fixP->fx_pcrel)
23310#endif
23311 md_number_to_chars (buf, value, 4);
c19d1205 23312 break;
6c43fab6 23313
c19d1205
ZW
23314#ifdef OBJ_ELF
23315 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23316 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23317 {
23318 newval = md_chars_to_number (buf, 4) & 0x80000000;
23319 if ((value ^ (value >> 1)) & 0x40000000)
23320 {
23321 as_bad_where (fixP->fx_file, fixP->fx_line,
23322 _("rel31 relocation overflow"));
23323 }
23324 newval |= value & 0x7fffffff;
23325 md_number_to_chars (buf, newval, 4);
23326 }
23327 break;
c19d1205 23328#endif
a737bd4d 23329
c19d1205 23330 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23331 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23332 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23333 newval = md_chars_to_number (buf, INSN_SIZE);
23334 else
23335 newval = get_thumb32_insn (buf);
23336 if ((newval & 0x0f200f00) == 0x0d000900)
23337 {
23338 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23339 has permitted values that are multiples of 2, in the range 0
23340 to 510. */
23341 if (value < -510 || value > 510 || (value & 1))
23342 as_bad_where (fixP->fx_file, fixP->fx_line,
23343 _("co-processor offset out of range"));
23344 }
23345 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23346 as_bad_where (fixP->fx_file, fixP->fx_line,
23347 _("co-processor offset out of range"));
23348 cp_off_common:
26d97720 23349 sign = value > 0;
c19d1205
ZW
23350 if (value < 0)
23351 value = -value;
8f06b2d8
PB
23352 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23353 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23354 newval = md_chars_to_number (buf, INSN_SIZE);
23355 else
23356 newval = get_thumb32_insn (buf);
26d97720
NS
23357 if (value == 0)
23358 newval &= 0xffffff00;
23359 else
23360 {
23361 newval &= 0xff7fff00;
9db2f6b4
RL
23362 if ((newval & 0x0f200f00) == 0x0d000900)
23363 {
23364 /* This is a fp16 vstr/vldr.
23365
23366 It requires the immediate offset in the instruction is shifted
23367 left by 1 to be a half-word offset.
23368
23369 Here, left shift by 1 first, and later right shift by 2
23370 should get the right offset. */
23371 value <<= 1;
23372 }
26d97720
NS
23373 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23374 }
8f06b2d8
PB
23375 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23376 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23377 md_number_to_chars (buf, newval, INSN_SIZE);
23378 else
23379 put_thumb32_insn (buf, newval);
c19d1205 23380 break;
a737bd4d 23381
c19d1205 23382 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23383 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23384 if (value < -255 || value > 255)
23385 as_bad_where (fixP->fx_file, fixP->fx_line,
23386 _("co-processor offset out of range"));
df7849c5 23387 value *= 4;
c19d1205 23388 goto cp_off_common;
6c43fab6 23389
c19d1205
ZW
23390 case BFD_RELOC_ARM_THUMB_OFFSET:
23391 newval = md_chars_to_number (buf, THUMB_SIZE);
23392 /* Exactly what ranges, and where the offset is inserted depends
23393 on the type of instruction, we can establish this from the
23394 top 4 bits. */
23395 switch (newval >> 12)
23396 {
23397 case 4: /* PC load. */
23398 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23399 forced to zero for these loads; md_pcrel_from has already
23400 compensated for this. */
23401 if (value & 3)
23402 as_bad_where (fixP->fx_file, fixP->fx_line,
23403 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23404 (((unsigned long) fixP->fx_frag->fr_address
23405 + (unsigned long) fixP->fx_where) & ~3)
23406 + (unsigned long) value);
a737bd4d 23407
c19d1205
ZW
23408 if (value & ~0x3fc)
23409 as_bad_where (fixP->fx_file, fixP->fx_line,
23410 _("invalid offset, value too big (0x%08lX)"),
23411 (long) value);
a737bd4d 23412
c19d1205
ZW
23413 newval |= value >> 2;
23414 break;
a737bd4d 23415
c19d1205
ZW
23416 case 9: /* SP load/store. */
23417 if (value & ~0x3fc)
23418 as_bad_where (fixP->fx_file, fixP->fx_line,
23419 _("invalid offset, value too big (0x%08lX)"),
23420 (long) value);
23421 newval |= value >> 2;
23422 break;
6c43fab6 23423
c19d1205
ZW
23424 case 6: /* Word load/store. */
23425 if (value & ~0x7c)
23426 as_bad_where (fixP->fx_file, fixP->fx_line,
23427 _("invalid offset, value too big (0x%08lX)"),
23428 (long) value);
23429 newval |= value << 4; /* 6 - 2. */
23430 break;
a737bd4d 23431
c19d1205
ZW
23432 case 7: /* Byte load/store. */
23433 if (value & ~0x1f)
23434 as_bad_where (fixP->fx_file, fixP->fx_line,
23435 _("invalid offset, value too big (0x%08lX)"),
23436 (long) value);
23437 newval |= value << 6;
23438 break;
a737bd4d 23439
c19d1205
ZW
23440 case 8: /* Halfword load/store. */
23441 if (value & ~0x3e)
23442 as_bad_where (fixP->fx_file, fixP->fx_line,
23443 _("invalid offset, value too big (0x%08lX)"),
23444 (long) value);
23445 newval |= value << 5; /* 6 - 1. */
23446 break;
a737bd4d 23447
c19d1205
ZW
23448 default:
23449 as_bad_where (fixP->fx_file, fixP->fx_line,
23450 "Unable to process relocation for thumb opcode: %lx",
23451 (unsigned long) newval);
23452 break;
23453 }
23454 md_number_to_chars (buf, newval, THUMB_SIZE);
23455 break;
a737bd4d 23456
c19d1205
ZW
23457 case BFD_RELOC_ARM_THUMB_ADD:
23458 /* This is a complicated relocation, since we use it for all of
23459 the following immediate relocations:
a737bd4d 23460
c19d1205
ZW
23461 3bit ADD/SUB
23462 8bit ADD/SUB
23463 9bit ADD/SUB SP word-aligned
23464 10bit ADD PC/SP word-aligned
a737bd4d 23465
c19d1205
ZW
23466 The type of instruction being processed is encoded in the
23467 instruction field:
a737bd4d 23468
c19d1205
ZW
23469 0x8000 SUB
23470 0x00F0 Rd
23471 0x000F Rs
23472 */
23473 newval = md_chars_to_number (buf, THUMB_SIZE);
23474 {
23475 int rd = (newval >> 4) & 0xf;
23476 int rs = newval & 0xf;
23477 int subtract = !!(newval & 0x8000);
a737bd4d 23478
c19d1205
ZW
23479 /* Check for HI regs, only very restricted cases allowed:
23480 Adjusting SP, and using PC or SP to get an address. */
23481 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23482 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23483 as_bad_where (fixP->fx_file, fixP->fx_line,
23484 _("invalid Hi register with immediate"));
a737bd4d 23485
c19d1205
ZW
23486 /* If value is negative, choose the opposite instruction. */
23487 if (value < 0)
23488 {
23489 value = -value;
23490 subtract = !subtract;
23491 if (value < 0)
23492 as_bad_where (fixP->fx_file, fixP->fx_line,
23493 _("immediate value out of range"));
23494 }
a737bd4d 23495
c19d1205
ZW
23496 if (rd == REG_SP)
23497 {
75c11999 23498 if (value & ~0x1fc)
c19d1205
ZW
23499 as_bad_where (fixP->fx_file, fixP->fx_line,
23500 _("invalid immediate for stack address calculation"));
23501 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23502 newval |= value >> 2;
23503 }
23504 else if (rs == REG_PC || rs == REG_SP)
23505 {
c12d2c9d
NC
23506 /* PR gas/18541. If the addition is for a defined symbol
23507 within range of an ADR instruction then accept it. */
23508 if (subtract
23509 && value == 4
23510 && fixP->fx_addsy != NULL)
23511 {
23512 subtract = 0;
23513
23514 if (! S_IS_DEFINED (fixP->fx_addsy)
23515 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23516 || S_IS_WEAK (fixP->fx_addsy))
23517 {
23518 as_bad_where (fixP->fx_file, fixP->fx_line,
23519 _("address calculation needs a strongly defined nearby symbol"));
23520 }
23521 else
23522 {
23523 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23524
23525 /* Round up to the next 4-byte boundary. */
23526 if (v & 3)
23527 v = (v + 3) & ~ 3;
23528 else
23529 v += 4;
23530 v = S_GET_VALUE (fixP->fx_addsy) - v;
23531
23532 if (v & ~0x3fc)
23533 {
23534 as_bad_where (fixP->fx_file, fixP->fx_line,
23535 _("symbol too far away"));
23536 }
23537 else
23538 {
23539 fixP->fx_done = 1;
23540 value = v;
23541 }
23542 }
23543 }
23544
c19d1205
ZW
23545 if (subtract || value & ~0x3fc)
23546 as_bad_where (fixP->fx_file, fixP->fx_line,
23547 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23548 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23549 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23550 newval |= rd << 8;
23551 newval |= value >> 2;
23552 }
23553 else if (rs == rd)
23554 {
23555 if (value & ~0xff)
23556 as_bad_where (fixP->fx_file, fixP->fx_line,
23557 _("immediate value out of range"));
23558 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23559 newval |= (rd << 8) | value;
23560 }
23561 else
23562 {
23563 if (value & ~0x7)
23564 as_bad_where (fixP->fx_file, fixP->fx_line,
23565 _("immediate value out of range"));
23566 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23567 newval |= rd | (rs << 3) | (value << 6);
23568 }
23569 }
23570 md_number_to_chars (buf, newval, THUMB_SIZE);
23571 break;
a737bd4d 23572
c19d1205
ZW
23573 case BFD_RELOC_ARM_THUMB_IMM:
23574 newval = md_chars_to_number (buf, THUMB_SIZE);
23575 if (value < 0 || value > 255)
23576 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23577 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23578 (long) value);
23579 newval |= value;
23580 md_number_to_chars (buf, newval, THUMB_SIZE);
23581 break;
a737bd4d 23582
c19d1205
ZW
23583 case BFD_RELOC_ARM_THUMB_SHIFT:
23584 /* 5bit shift value (0..32). LSL cannot take 32. */
23585 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23586 temp = newval & 0xf800;
23587 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23588 as_bad_where (fixP->fx_file, fixP->fx_line,
23589 _("invalid shift value: %ld"), (long) value);
23590 /* Shifts of zero must be encoded as LSL. */
23591 if (value == 0)
23592 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23593 /* Shifts of 32 are encoded as zero. */
23594 else if (value == 32)
23595 value = 0;
23596 newval |= value << 6;
23597 md_number_to_chars (buf, newval, THUMB_SIZE);
23598 break;
a737bd4d 23599
c19d1205
ZW
23600 case BFD_RELOC_VTABLE_INHERIT:
23601 case BFD_RELOC_VTABLE_ENTRY:
23602 fixP->fx_done = 0;
23603 return;
6c43fab6 23604
b6895b4f
PB
23605 case BFD_RELOC_ARM_MOVW:
23606 case BFD_RELOC_ARM_MOVT:
23607 case BFD_RELOC_ARM_THUMB_MOVW:
23608 case BFD_RELOC_ARM_THUMB_MOVT:
23609 if (fixP->fx_done || !seg->use_rela_p)
23610 {
23611 /* REL format relocations are limited to a 16-bit addend. */
23612 if (!fixP->fx_done)
23613 {
39623e12 23614 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23615 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23616 _("offset out of range"));
b6895b4f
PB
23617 }
23618 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23619 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23620 {
23621 value >>= 16;
23622 }
23623
23624 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23625 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23626 {
23627 newval = get_thumb32_insn (buf);
23628 newval &= 0xfbf08f00;
23629 newval |= (value & 0xf000) << 4;
23630 newval |= (value & 0x0800) << 15;
23631 newval |= (value & 0x0700) << 4;
23632 newval |= (value & 0x00ff);
23633 put_thumb32_insn (buf, newval);
23634 }
23635 else
23636 {
23637 newval = md_chars_to_number (buf, 4);
23638 newval &= 0xfff0f000;
23639 newval |= value & 0x0fff;
23640 newval |= (value & 0xf000) << 4;
23641 md_number_to_chars (buf, newval, 4);
23642 }
23643 }
23644 return;
23645
72d98d16
MG
23646 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23647 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23648 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23649 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23650 gas_assert (!fixP->fx_done);
23651 {
23652 bfd_vma insn;
23653 bfd_boolean is_mov;
23654 bfd_vma encoded_addend = value;
23655
23656 /* Check that addend can be encoded in instruction. */
23657 if (!seg->use_rela_p && (value < 0 || value > 255))
23658 as_bad_where (fixP->fx_file, fixP->fx_line,
23659 _("the offset 0x%08lX is not representable"),
23660 (unsigned long) encoded_addend);
23661
23662 /* Extract the instruction. */
23663 insn = md_chars_to_number (buf, THUMB_SIZE);
23664 is_mov = (insn & 0xf800) == 0x2000;
23665
23666 /* Encode insn. */
23667 if (is_mov)
23668 {
23669 if (!seg->use_rela_p)
23670 insn |= encoded_addend;
23671 }
23672 else
23673 {
23674 int rd, rs;
23675
23676 /* Extract the instruction. */
23677 /* Encoding is the following
23678 0x8000 SUB
23679 0x00F0 Rd
23680 0x000F Rs
23681 */
23682 /* The following conditions must be true :
23683 - ADD
23684 - Rd == Rs
23685 - Rd <= 7
23686 */
23687 rd = (insn >> 4) & 0xf;
23688 rs = insn & 0xf;
23689 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23690 as_bad_where (fixP->fx_file, fixP->fx_line,
23691 _("Unable to process relocation for thumb opcode: %lx"),
23692 (unsigned long) insn);
23693
23694 /* Encode as ADD immediate8 thumb 1 code. */
23695 insn = 0x3000 | (rd << 8);
23696
23697 /* Place the encoded addend into the first 8 bits of the
23698 instruction. */
23699 if (!seg->use_rela_p)
23700 insn |= encoded_addend;
23701 }
23702
23703 /* Update the instruction. */
23704 md_number_to_chars (buf, insn, THUMB_SIZE);
23705 }
23706 break;
23707
4962c51a
MS
23708 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23709 case BFD_RELOC_ARM_ALU_PC_G0:
23710 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23711 case BFD_RELOC_ARM_ALU_PC_G1:
23712 case BFD_RELOC_ARM_ALU_PC_G2:
23713 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23714 case BFD_RELOC_ARM_ALU_SB_G0:
23715 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23716 case BFD_RELOC_ARM_ALU_SB_G1:
23717 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23718 gas_assert (!fixP->fx_done);
4962c51a
MS
23719 if (!seg->use_rela_p)
23720 {
477330fc
RM
23721 bfd_vma insn;
23722 bfd_vma encoded_addend;
23723 bfd_vma addend_abs = abs (value);
23724
23725 /* Check that the absolute value of the addend can be
23726 expressed as an 8-bit constant plus a rotation. */
23727 encoded_addend = encode_arm_immediate (addend_abs);
23728 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23729 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23730 _("the offset 0x%08lX is not representable"),
23731 (unsigned long) addend_abs);
23732
23733 /* Extract the instruction. */
23734 insn = md_chars_to_number (buf, INSN_SIZE);
23735
23736 /* If the addend is positive, use an ADD instruction.
23737 Otherwise use a SUB. Take care not to destroy the S bit. */
23738 insn &= 0xff1fffff;
23739 if (value < 0)
23740 insn |= 1 << 22;
23741 else
23742 insn |= 1 << 23;
23743
23744 /* Place the encoded addend into the first 12 bits of the
23745 instruction. */
23746 insn &= 0xfffff000;
23747 insn |= encoded_addend;
23748
23749 /* Update the instruction. */
23750 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23751 }
23752 break;
23753
23754 case BFD_RELOC_ARM_LDR_PC_G0:
23755 case BFD_RELOC_ARM_LDR_PC_G1:
23756 case BFD_RELOC_ARM_LDR_PC_G2:
23757 case BFD_RELOC_ARM_LDR_SB_G0:
23758 case BFD_RELOC_ARM_LDR_SB_G1:
23759 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23760 gas_assert (!fixP->fx_done);
4962c51a 23761 if (!seg->use_rela_p)
477330fc
RM
23762 {
23763 bfd_vma insn;
23764 bfd_vma addend_abs = abs (value);
4962c51a 23765
477330fc
RM
23766 /* Check that the absolute value of the addend can be
23767 encoded in 12 bits. */
23768 if (addend_abs >= 0x1000)
4962c51a 23769 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23770 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23771 (unsigned long) addend_abs);
23772
23773 /* Extract the instruction. */
23774 insn = md_chars_to_number (buf, INSN_SIZE);
23775
23776 /* If the addend is negative, clear bit 23 of the instruction.
23777 Otherwise set it. */
23778 if (value < 0)
23779 insn &= ~(1 << 23);
23780 else
23781 insn |= 1 << 23;
23782
23783 /* Place the absolute value of the addend into the first 12 bits
23784 of the instruction. */
23785 insn &= 0xfffff000;
23786 insn |= addend_abs;
23787
23788 /* Update the instruction. */
23789 md_number_to_chars (buf, insn, INSN_SIZE);
23790 }
4962c51a
MS
23791 break;
23792
23793 case BFD_RELOC_ARM_LDRS_PC_G0:
23794 case BFD_RELOC_ARM_LDRS_PC_G1:
23795 case BFD_RELOC_ARM_LDRS_PC_G2:
23796 case BFD_RELOC_ARM_LDRS_SB_G0:
23797 case BFD_RELOC_ARM_LDRS_SB_G1:
23798 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23799 gas_assert (!fixP->fx_done);
4962c51a 23800 if (!seg->use_rela_p)
477330fc
RM
23801 {
23802 bfd_vma insn;
23803 bfd_vma addend_abs = abs (value);
4962c51a 23804
477330fc
RM
23805 /* Check that the absolute value of the addend can be
23806 encoded in 8 bits. */
23807 if (addend_abs >= 0x100)
4962c51a 23808 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23809 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23810 (unsigned long) addend_abs);
23811
23812 /* Extract the instruction. */
23813 insn = md_chars_to_number (buf, INSN_SIZE);
23814
23815 /* If the addend is negative, clear bit 23 of the instruction.
23816 Otherwise set it. */
23817 if (value < 0)
23818 insn &= ~(1 << 23);
23819 else
23820 insn |= 1 << 23;
23821
23822 /* Place the first four bits of the absolute value of the addend
23823 into the first 4 bits of the instruction, and the remaining
23824 four into bits 8 .. 11. */
23825 insn &= 0xfffff0f0;
23826 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23827
23828 /* Update the instruction. */
23829 md_number_to_chars (buf, insn, INSN_SIZE);
23830 }
4962c51a
MS
23831 break;
23832
23833 case BFD_RELOC_ARM_LDC_PC_G0:
23834 case BFD_RELOC_ARM_LDC_PC_G1:
23835 case BFD_RELOC_ARM_LDC_PC_G2:
23836 case BFD_RELOC_ARM_LDC_SB_G0:
23837 case BFD_RELOC_ARM_LDC_SB_G1:
23838 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23839 gas_assert (!fixP->fx_done);
4962c51a 23840 if (!seg->use_rela_p)
477330fc
RM
23841 {
23842 bfd_vma insn;
23843 bfd_vma addend_abs = abs (value);
4962c51a 23844
477330fc
RM
23845 /* Check that the absolute value of the addend is a multiple of
23846 four and, when divided by four, fits in 8 bits. */
23847 if (addend_abs & 0x3)
4962c51a 23848 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23849 _("bad offset 0x%08lX (must be word-aligned)"),
23850 (unsigned long) addend_abs);
4962c51a 23851
477330fc 23852 if ((addend_abs >> 2) > 0xff)
4962c51a 23853 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23854 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23855 (unsigned long) addend_abs);
23856
23857 /* Extract the instruction. */
23858 insn = md_chars_to_number (buf, INSN_SIZE);
23859
23860 /* If the addend is negative, clear bit 23 of the instruction.
23861 Otherwise set it. */
23862 if (value < 0)
23863 insn &= ~(1 << 23);
23864 else
23865 insn |= 1 << 23;
23866
23867 /* Place the addend (divided by four) into the first eight
23868 bits of the instruction. */
23869 insn &= 0xfffffff0;
23870 insn |= addend_abs >> 2;
23871
23872 /* Update the instruction. */
23873 md_number_to_chars (buf, insn, INSN_SIZE);
23874 }
4962c51a
MS
23875 break;
23876
845b51d6
PB
23877 case BFD_RELOC_ARM_V4BX:
23878 /* This will need to go in the object file. */
23879 fixP->fx_done = 0;
23880 break;
23881
c19d1205
ZW
23882 case BFD_RELOC_UNUSED:
23883 default:
23884 as_bad_where (fixP->fx_file, fixP->fx_line,
23885 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23886 }
6c43fab6
RE
23887}
23888
c19d1205
ZW
23889/* Translate internal representation of relocation info to BFD target
23890 format. */
a737bd4d 23891
c19d1205 23892arelent *
00a97672 23893tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 23894{
c19d1205
ZW
23895 arelent * reloc;
23896 bfd_reloc_code_real_type code;
a737bd4d 23897
21d799b5 23898 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 23899
21d799b5 23900 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
23901 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23902 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 23903
2fc8bdac 23904 if (fixp->fx_pcrel)
00a97672
RS
23905 {
23906 if (section->use_rela_p)
23907 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23908 else
23909 fixp->fx_offset = reloc->address;
23910 }
c19d1205 23911 reloc->addend = fixp->fx_offset;
a737bd4d 23912
c19d1205 23913 switch (fixp->fx_r_type)
a737bd4d 23914 {
c19d1205
ZW
23915 case BFD_RELOC_8:
23916 if (fixp->fx_pcrel)
23917 {
23918 code = BFD_RELOC_8_PCREL;
23919 break;
23920 }
a737bd4d 23921
c19d1205
ZW
23922 case BFD_RELOC_16:
23923 if (fixp->fx_pcrel)
23924 {
23925 code = BFD_RELOC_16_PCREL;
23926 break;
23927 }
6c43fab6 23928
c19d1205
ZW
23929 case BFD_RELOC_32:
23930 if (fixp->fx_pcrel)
23931 {
23932 code = BFD_RELOC_32_PCREL;
23933 break;
23934 }
a737bd4d 23935
b6895b4f
PB
23936 case BFD_RELOC_ARM_MOVW:
23937 if (fixp->fx_pcrel)
23938 {
23939 code = BFD_RELOC_ARM_MOVW_PCREL;
23940 break;
23941 }
23942
23943 case BFD_RELOC_ARM_MOVT:
23944 if (fixp->fx_pcrel)
23945 {
23946 code = BFD_RELOC_ARM_MOVT_PCREL;
23947 break;
23948 }
23949
23950 case BFD_RELOC_ARM_THUMB_MOVW:
23951 if (fixp->fx_pcrel)
23952 {
23953 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23954 break;
23955 }
23956
23957 case BFD_RELOC_ARM_THUMB_MOVT:
23958 if (fixp->fx_pcrel)
23959 {
23960 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
23961 break;
23962 }
23963
c19d1205
ZW
23964 case BFD_RELOC_NONE:
23965 case BFD_RELOC_ARM_PCREL_BRANCH:
23966 case BFD_RELOC_ARM_PCREL_BLX:
23967 case BFD_RELOC_RVA:
23968 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23969 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23970 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23971 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23972 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23973 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
23974 case BFD_RELOC_VTABLE_ENTRY:
23975 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
23976#ifdef TE_PE
23977 case BFD_RELOC_32_SECREL:
23978#endif
c19d1205
ZW
23979 code = fixp->fx_r_type;
23980 break;
a737bd4d 23981
00adf2d4
JB
23982 case BFD_RELOC_THUMB_PCREL_BLX:
23983#ifdef OBJ_ELF
23984 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23985 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
23986 else
23987#endif
23988 code = BFD_RELOC_THUMB_PCREL_BLX;
23989 break;
23990
c19d1205
ZW
23991 case BFD_RELOC_ARM_LITERAL:
23992 case BFD_RELOC_ARM_HWLITERAL:
23993 /* If this is called then the a literal has
23994 been referenced across a section boundary. */
23995 as_bad_where (fixp->fx_file, fixp->fx_line,
23996 _("literal referenced across section boundary"));
23997 return NULL;
a737bd4d 23998
c19d1205 23999#ifdef OBJ_ELF
0855e32b
NS
24000 case BFD_RELOC_ARM_TLS_CALL:
24001 case BFD_RELOC_ARM_THM_TLS_CALL:
24002 case BFD_RELOC_ARM_TLS_DESCSEQ:
24003 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24004 case BFD_RELOC_ARM_GOT32:
24005 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24006 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24007 case BFD_RELOC_ARM_PLT32:
24008 case BFD_RELOC_ARM_TARGET1:
24009 case BFD_RELOC_ARM_ROSEGREL32:
24010 case BFD_RELOC_ARM_SBREL32:
24011 case BFD_RELOC_ARM_PREL31:
24012 case BFD_RELOC_ARM_TARGET2:
c19d1205 24013 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24014 case BFD_RELOC_ARM_PCREL_CALL:
24015 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24016 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24017 case BFD_RELOC_ARM_ALU_PC_G0:
24018 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24019 case BFD_RELOC_ARM_ALU_PC_G1:
24020 case BFD_RELOC_ARM_ALU_PC_G2:
24021 case BFD_RELOC_ARM_LDR_PC_G0:
24022 case BFD_RELOC_ARM_LDR_PC_G1:
24023 case BFD_RELOC_ARM_LDR_PC_G2:
24024 case BFD_RELOC_ARM_LDRS_PC_G0:
24025 case BFD_RELOC_ARM_LDRS_PC_G1:
24026 case BFD_RELOC_ARM_LDRS_PC_G2:
24027 case BFD_RELOC_ARM_LDC_PC_G0:
24028 case BFD_RELOC_ARM_LDC_PC_G1:
24029 case BFD_RELOC_ARM_LDC_PC_G2:
24030 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24031 case BFD_RELOC_ARM_ALU_SB_G0:
24032 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24033 case BFD_RELOC_ARM_ALU_SB_G1:
24034 case BFD_RELOC_ARM_ALU_SB_G2:
24035 case BFD_RELOC_ARM_LDR_SB_G0:
24036 case BFD_RELOC_ARM_LDR_SB_G1:
24037 case BFD_RELOC_ARM_LDR_SB_G2:
24038 case BFD_RELOC_ARM_LDRS_SB_G0:
24039 case BFD_RELOC_ARM_LDRS_SB_G1:
24040 case BFD_RELOC_ARM_LDRS_SB_G2:
24041 case BFD_RELOC_ARM_LDC_SB_G0:
24042 case BFD_RELOC_ARM_LDC_SB_G1:
24043 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24044 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24045 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24046 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24047 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24048 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24049 code = fixp->fx_r_type;
24050 break;
a737bd4d 24051
0855e32b 24052 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24053 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24054 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24055 case BFD_RELOC_ARM_TLS_IE32:
24056 case BFD_RELOC_ARM_TLS_LDM32:
24057 /* BFD will include the symbol's address in the addend.
24058 But we don't want that, so subtract it out again here. */
24059 if (!S_IS_COMMON (fixp->fx_addsy))
24060 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24061 code = fixp->fx_r_type;
24062 break;
24063#endif
a737bd4d 24064
c19d1205
ZW
24065 case BFD_RELOC_ARM_IMMEDIATE:
24066 as_bad_where (fixp->fx_file, fixp->fx_line,
24067 _("internal relocation (type: IMMEDIATE) not fixed up"));
24068 return NULL;
a737bd4d 24069
c19d1205
ZW
24070 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24071 as_bad_where (fixp->fx_file, fixp->fx_line,
24072 _("ADRL used for a symbol not defined in the same file"));
24073 return NULL;
a737bd4d 24074
c19d1205 24075 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24076 if (section->use_rela_p)
24077 {
24078 code = fixp->fx_r_type;
24079 break;
24080 }
24081
c19d1205
ZW
24082 if (fixp->fx_addsy != NULL
24083 && !S_IS_DEFINED (fixp->fx_addsy)
24084 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24085 {
c19d1205
ZW
24086 as_bad_where (fixp->fx_file, fixp->fx_line,
24087 _("undefined local label `%s'"),
24088 S_GET_NAME (fixp->fx_addsy));
24089 return NULL;
a737bd4d
NC
24090 }
24091
c19d1205
ZW
24092 as_bad_where (fixp->fx_file, fixp->fx_line,
24093 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24094 return NULL;
a737bd4d 24095
c19d1205
ZW
24096 default:
24097 {
24098 char * type;
6c43fab6 24099
c19d1205
ZW
24100 switch (fixp->fx_r_type)
24101 {
24102 case BFD_RELOC_NONE: type = "NONE"; break;
24103 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24104 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24105 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24106 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24107 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24108 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24109 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24110 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24111 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24112 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24113 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24114 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24115 default: type = _("<unknown>"); break;
24116 }
24117 as_bad_where (fixp->fx_file, fixp->fx_line,
24118 _("cannot represent %s relocation in this object file format"),
24119 type);
24120 return NULL;
24121 }
a737bd4d 24122 }
6c43fab6 24123
c19d1205
ZW
24124#ifdef OBJ_ELF
24125 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24126 && GOT_symbol
24127 && fixp->fx_addsy == GOT_symbol)
24128 {
24129 code = BFD_RELOC_ARM_GOTPC;
24130 reloc->addend = fixp->fx_offset = reloc->address;
24131 }
24132#endif
6c43fab6 24133
c19d1205 24134 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24135
c19d1205
ZW
24136 if (reloc->howto == NULL)
24137 {
24138 as_bad_where (fixp->fx_file, fixp->fx_line,
24139 _("cannot represent %s relocation in this object file format"),
24140 bfd_get_reloc_code_name (code));
24141 return NULL;
24142 }
6c43fab6 24143
c19d1205
ZW
24144 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24145 vtable entry to be used in the relocation's section offset. */
24146 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24147 reloc->address = fixp->fx_offset;
6c43fab6 24148
c19d1205 24149 return reloc;
6c43fab6
RE
24150}
24151
c19d1205 24152/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24153
c19d1205
ZW
24154void
24155cons_fix_new_arm (fragS * frag,
24156 int where,
24157 int size,
62ebcb5c
AM
24158 expressionS * exp,
24159 bfd_reloc_code_real_type reloc)
6c43fab6 24160{
c19d1205 24161 int pcrel = 0;
6c43fab6 24162
c19d1205
ZW
24163 /* Pick a reloc.
24164 FIXME: @@ Should look at CPU word size. */
24165 switch (size)
24166 {
24167 case 1:
62ebcb5c 24168 reloc = BFD_RELOC_8;
c19d1205
ZW
24169 break;
24170 case 2:
62ebcb5c 24171 reloc = BFD_RELOC_16;
c19d1205
ZW
24172 break;
24173 case 4:
24174 default:
62ebcb5c 24175 reloc = BFD_RELOC_32;
c19d1205
ZW
24176 break;
24177 case 8:
62ebcb5c 24178 reloc = BFD_RELOC_64;
c19d1205
ZW
24179 break;
24180 }
6c43fab6 24181
f0927246
NC
24182#ifdef TE_PE
24183 if (exp->X_op == O_secrel)
24184 {
24185 exp->X_op = O_symbol;
62ebcb5c 24186 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24187 }
24188#endif
24189
62ebcb5c 24190 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24191}
6c43fab6 24192
4343666d 24193#if defined (OBJ_COFF)
c19d1205
ZW
24194void
24195arm_validate_fix (fixS * fixP)
6c43fab6 24196{
c19d1205
ZW
24197 /* If the destination of the branch is a defined symbol which does not have
24198 the THUMB_FUNC attribute, then we must be calling a function which has
24199 the (interfacearm) attribute. We look for the Thumb entry point to that
24200 function and change the branch to refer to that function instead. */
24201 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24202 && fixP->fx_addsy != NULL
24203 && S_IS_DEFINED (fixP->fx_addsy)
24204 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24205 {
c19d1205 24206 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24207 }
c19d1205
ZW
24208}
24209#endif
6c43fab6 24210
267bf995 24211
c19d1205
ZW
24212int
24213arm_force_relocation (struct fix * fixp)
24214{
24215#if defined (OBJ_COFF) && defined (TE_PE)
24216 if (fixp->fx_r_type == BFD_RELOC_RVA)
24217 return 1;
24218#endif
6c43fab6 24219
267bf995
RR
24220 /* In case we have a call or a branch to a function in ARM ISA mode from
24221 a thumb function or vice-versa force the relocation. These relocations
24222 are cleared off for some cores that might have blx and simple transformations
24223 are possible. */
24224
24225#ifdef OBJ_ELF
24226 switch (fixp->fx_r_type)
24227 {
24228 case BFD_RELOC_ARM_PCREL_JUMP:
24229 case BFD_RELOC_ARM_PCREL_CALL:
24230 case BFD_RELOC_THUMB_PCREL_BLX:
24231 if (THUMB_IS_FUNC (fixp->fx_addsy))
24232 return 1;
24233 break;
24234
24235 case BFD_RELOC_ARM_PCREL_BLX:
24236 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24237 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24238 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24239 if (ARM_IS_FUNC (fixp->fx_addsy))
24240 return 1;
24241 break;
24242
24243 default:
24244 break;
24245 }
24246#endif
24247
b5884301
PB
24248 /* Resolve these relocations even if the symbol is extern or weak.
24249 Technically this is probably wrong due to symbol preemption.
24250 In practice these relocations do not have enough range to be useful
24251 at dynamic link time, and some code (e.g. in the Linux kernel)
24252 expects these references to be resolved. */
c19d1205
ZW
24253 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24254 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24255 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24256 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24257 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24258 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24259 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24260 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24261 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24262 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24263 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24264 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24265 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24266 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24267 return 0;
a737bd4d 24268
4962c51a
MS
24269 /* Always leave these relocations for the linker. */
24270 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24271 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24272 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24273 return 1;
24274
f0291e4c
PB
24275 /* Always generate relocations against function symbols. */
24276 if (fixp->fx_r_type == BFD_RELOC_32
24277 && fixp->fx_addsy
24278 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24279 return 1;
24280
c19d1205 24281 return generic_force_reloc (fixp);
404ff6b5
AH
24282}
24283
0ffdc86c 24284#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24285/* Relocations against function names must be left unadjusted,
24286 so that the linker can use this information to generate interworking
24287 stubs. The MIPS version of this function
c19d1205
ZW
24288 also prevents relocations that are mips-16 specific, but I do not
24289 know why it does this.
404ff6b5 24290
c19d1205
ZW
24291 FIXME:
24292 There is one other problem that ought to be addressed here, but
24293 which currently is not: Taking the address of a label (rather
24294 than a function) and then later jumping to that address. Such
24295 addresses also ought to have their bottom bit set (assuming that
24296 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24297
c19d1205
ZW
24298bfd_boolean
24299arm_fix_adjustable (fixS * fixP)
404ff6b5 24300{
c19d1205
ZW
24301 if (fixP->fx_addsy == NULL)
24302 return 1;
404ff6b5 24303
e28387c3
PB
24304 /* Preserve relocations against symbols with function type. */
24305 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24306 return FALSE;
e28387c3 24307
c19d1205
ZW
24308 if (THUMB_IS_FUNC (fixP->fx_addsy)
24309 && fixP->fx_subsy == NULL)
c921be7d 24310 return FALSE;
a737bd4d 24311
c19d1205
ZW
24312 /* We need the symbol name for the VTABLE entries. */
24313 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24314 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24315 return FALSE;
404ff6b5 24316
c19d1205
ZW
24317 /* Don't allow symbols to be discarded on GOT related relocs. */
24318 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24319 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24320 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24321 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24322 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24323 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24324 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24325 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24326 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24327 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24328 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24329 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24330 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24331 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24332 return FALSE;
a737bd4d 24333
4962c51a
MS
24334 /* Similarly for group relocations. */
24335 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24336 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24337 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24338 return FALSE;
4962c51a 24339
79947c54
CD
24340 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24341 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24342 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24343 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24344 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24345 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24346 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24347 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24348 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24349 return FALSE;
79947c54 24350
72d98d16
MG
24351 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24352 offsets, so keep these symbols. */
24353 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24354 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24355 return FALSE;
24356
c921be7d 24357 return TRUE;
a737bd4d 24358}
0ffdc86c
NC
24359#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24360
24361#ifdef OBJ_ELF
c19d1205
ZW
24362const char *
24363elf32_arm_target_format (void)
404ff6b5 24364{
c19d1205
ZW
24365#ifdef TE_SYMBIAN
24366 return (target_big_endian
24367 ? "elf32-bigarm-symbian"
24368 : "elf32-littlearm-symbian");
24369#elif defined (TE_VXWORKS)
24370 return (target_big_endian
24371 ? "elf32-bigarm-vxworks"
24372 : "elf32-littlearm-vxworks");
b38cadfb
NC
24373#elif defined (TE_NACL)
24374 return (target_big_endian
24375 ? "elf32-bigarm-nacl"
24376 : "elf32-littlearm-nacl");
c19d1205
ZW
24377#else
24378 if (target_big_endian)
24379 return "elf32-bigarm";
24380 else
24381 return "elf32-littlearm";
24382#endif
404ff6b5
AH
24383}
24384
c19d1205
ZW
24385void
24386armelf_frob_symbol (symbolS * symp,
24387 int * puntp)
404ff6b5 24388{
c19d1205
ZW
24389 elf_frob_symbol (symp, puntp);
24390}
24391#endif
404ff6b5 24392
c19d1205 24393/* MD interface: Finalization. */
a737bd4d 24394
c19d1205
ZW
24395void
24396arm_cleanup (void)
24397{
24398 literal_pool * pool;
a737bd4d 24399
e07e6e58
NC
24400 /* Ensure that all the IT blocks are properly closed. */
24401 check_it_blocks_finished ();
24402
c19d1205
ZW
24403 for (pool = list_of_pools; pool; pool = pool->next)
24404 {
5f4273c7 24405 /* Put it at the end of the relevant section. */
c19d1205
ZW
24406 subseg_set (pool->section, pool->sub_section);
24407#ifdef OBJ_ELF
24408 arm_elf_change_section ();
24409#endif
24410 s_ltorg (0);
24411 }
404ff6b5
AH
24412}
24413
cd000bff
DJ
24414#ifdef OBJ_ELF
24415/* Remove any excess mapping symbols generated for alignment frags in
24416 SEC. We may have created a mapping symbol before a zero byte
24417 alignment; remove it if there's a mapping symbol after the
24418 alignment. */
24419static void
24420check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24421 void *dummy ATTRIBUTE_UNUSED)
24422{
24423 segment_info_type *seginfo = seg_info (sec);
24424 fragS *fragp;
24425
24426 if (seginfo == NULL || seginfo->frchainP == NULL)
24427 return;
24428
24429 for (fragp = seginfo->frchainP->frch_root;
24430 fragp != NULL;
24431 fragp = fragp->fr_next)
24432 {
24433 symbolS *sym = fragp->tc_frag_data.last_map;
24434 fragS *next = fragp->fr_next;
24435
24436 /* Variable-sized frags have been converted to fixed size by
24437 this point. But if this was variable-sized to start with,
24438 there will be a fixed-size frag after it. So don't handle
24439 next == NULL. */
24440 if (sym == NULL || next == NULL)
24441 continue;
24442
24443 if (S_GET_VALUE (sym) < next->fr_address)
24444 /* Not at the end of this frag. */
24445 continue;
24446 know (S_GET_VALUE (sym) == next->fr_address);
24447
24448 do
24449 {
24450 if (next->tc_frag_data.first_map != NULL)
24451 {
24452 /* Next frag starts with a mapping symbol. Discard this
24453 one. */
24454 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24455 break;
24456 }
24457
24458 if (next->fr_next == NULL)
24459 {
24460 /* This mapping symbol is at the end of the section. Discard
24461 it. */
24462 know (next->fr_fix == 0 && next->fr_var == 0);
24463 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24464 break;
24465 }
24466
24467 /* As long as we have empty frags without any mapping symbols,
24468 keep looking. */
24469 /* If the next frag is non-empty and does not start with a
24470 mapping symbol, then this mapping symbol is required. */
24471 if (next->fr_address != next->fr_next->fr_address)
24472 break;
24473
24474 next = next->fr_next;
24475 }
24476 while (next != NULL);
24477 }
24478}
24479#endif
24480
c19d1205
ZW
24481/* Adjust the symbol table. This marks Thumb symbols as distinct from
24482 ARM ones. */
404ff6b5 24483
c19d1205
ZW
24484void
24485arm_adjust_symtab (void)
404ff6b5 24486{
c19d1205
ZW
24487#ifdef OBJ_COFF
24488 symbolS * sym;
404ff6b5 24489
c19d1205
ZW
24490 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24491 {
24492 if (ARM_IS_THUMB (sym))
24493 {
24494 if (THUMB_IS_FUNC (sym))
24495 {
24496 /* Mark the symbol as a Thumb function. */
24497 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24498 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24499 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24500
c19d1205
ZW
24501 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24502 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24503 else
24504 as_bad (_("%s: unexpected function type: %d"),
24505 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24506 }
24507 else switch (S_GET_STORAGE_CLASS (sym))
24508 {
24509 case C_EXT:
24510 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24511 break;
24512 case C_STAT:
24513 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24514 break;
24515 case C_LABEL:
24516 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24517 break;
24518 default:
24519 /* Do nothing. */
24520 break;
24521 }
24522 }
a737bd4d 24523
c19d1205
ZW
24524 if (ARM_IS_INTERWORK (sym))
24525 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24526 }
c19d1205
ZW
24527#endif
24528#ifdef OBJ_ELF
24529 symbolS * sym;
24530 char bind;
404ff6b5 24531
c19d1205 24532 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24533 {
c19d1205
ZW
24534 if (ARM_IS_THUMB (sym))
24535 {
24536 elf_symbol_type * elf_sym;
404ff6b5 24537
c19d1205
ZW
24538 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24539 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24540
b0796911
PB
24541 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24542 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24543 {
24544 /* If it's a .thumb_func, declare it as so,
24545 otherwise tag label as .code 16. */
24546 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
24547 elf_sym->internal_elf_sym.st_target_internal
24548 = ST_BRANCH_TO_THUMB;
3ba67470 24549 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24550 elf_sym->internal_elf_sym.st_info =
24551 ELF_ST_INFO (bind, STT_ARM_16BIT);
24552 }
24553 }
24554 }
cd000bff
DJ
24555
24556 /* Remove any overlapping mapping symbols generated by alignment frags. */
24557 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24558 /* Now do generic ELF adjustments. */
24559 elf_adjust_symtab ();
c19d1205 24560#endif
404ff6b5
AH
24561}
24562
c19d1205 24563/* MD interface: Initialization. */
404ff6b5 24564
a737bd4d 24565static void
c19d1205 24566set_constant_flonums (void)
a737bd4d 24567{
c19d1205 24568 int i;
404ff6b5 24569
c19d1205
ZW
24570 for (i = 0; i < NUM_FLOAT_VALS; i++)
24571 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24572 abort ();
a737bd4d 24573}
404ff6b5 24574
3e9e4fcf
JB
24575/* Auto-select Thumb mode if it's the only available instruction set for the
24576 given architecture. */
24577
24578static void
24579autoselect_thumb_from_cpu_variant (void)
24580{
24581 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24582 opcode_select (16);
24583}
24584
c19d1205
ZW
24585void
24586md_begin (void)
a737bd4d 24587{
c19d1205
ZW
24588 unsigned mach;
24589 unsigned int i;
404ff6b5 24590
c19d1205
ZW
24591 if ( (arm_ops_hsh = hash_new ()) == NULL
24592 || (arm_cond_hsh = hash_new ()) == NULL
24593 || (arm_shift_hsh = hash_new ()) == NULL
24594 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24595 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24596 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24597 || (arm_reloc_hsh = hash_new ()) == NULL
24598 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24599 as_fatal (_("virtual memory exhausted"));
24600
24601 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24602 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24603 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24604 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24605 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24606 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24607 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24608 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24609 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24610 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24611 (void *) (v7m_psrs + i));
c19d1205 24612 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24613 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24614 for (i = 0;
24615 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24616 i++)
d3ce72d0 24617 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24618 (void *) (barrier_opt_names + i));
c19d1205 24619#ifdef OBJ_ELF
3da1d841
NC
24620 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24621 {
24622 struct reloc_entry * entry = reloc_names + i;
24623
24624 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24625 /* This makes encode_branch() use the EABI versions of this relocation. */
24626 entry->reloc = BFD_RELOC_UNUSED;
24627
24628 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24629 }
c19d1205
ZW
24630#endif
24631
24632 set_constant_flonums ();
404ff6b5 24633
c19d1205
ZW
24634 /* Set the cpu variant based on the command-line options. We prefer
24635 -mcpu= over -march= if both are set (as for GCC); and we prefer
24636 -mfpu= over any other way of setting the floating point unit.
24637 Use of legacy options with new options are faulted. */
e74cfd16 24638 if (legacy_cpu)
404ff6b5 24639 {
e74cfd16 24640 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24641 as_bad (_("use of old and new-style options to set CPU type"));
24642
24643 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24644 }
e74cfd16 24645 else if (!mcpu_cpu_opt)
c19d1205 24646 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24647
e74cfd16 24648 if (legacy_fpu)
c19d1205 24649 {
e74cfd16 24650 if (mfpu_opt)
c19d1205 24651 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24652
24653 mfpu_opt = legacy_fpu;
24654 }
e74cfd16 24655 else if (!mfpu_opt)
03b1477f 24656 {
45eb4c1b
NS
24657#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24658 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24659 /* Some environments specify a default FPU. If they don't, infer it
24660 from the processor. */
e74cfd16 24661 if (mcpu_fpu_opt)
03b1477f
RE
24662 mfpu_opt = mcpu_fpu_opt;
24663 else
24664 mfpu_opt = march_fpu_opt;
39c2da32 24665#else
e74cfd16 24666 mfpu_opt = &fpu_default;
39c2da32 24667#endif
03b1477f
RE
24668 }
24669
e74cfd16 24670 if (!mfpu_opt)
03b1477f 24671 {
493cb6ef 24672 if (mcpu_cpu_opt != NULL)
e74cfd16 24673 mfpu_opt = &fpu_default;
493cb6ef 24674 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24675 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24676 else
e74cfd16 24677 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24678 }
24679
ee065d83 24680#ifdef CPU_DEFAULT
e74cfd16 24681 if (!mcpu_cpu_opt)
ee065d83 24682 {
e74cfd16
PB
24683 mcpu_cpu_opt = &cpu_default;
24684 selected_cpu = cpu_default;
ee065d83 24685 }
73f43896
NC
24686 else if (no_cpu_selected ())
24687 selected_cpu = cpu_default;
e74cfd16
PB
24688#else
24689 if (mcpu_cpu_opt)
24690 selected_cpu = *mcpu_cpu_opt;
ee065d83 24691 else
e74cfd16 24692 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24693#endif
03b1477f 24694
e74cfd16 24695 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24696
3e9e4fcf
JB
24697 autoselect_thumb_from_cpu_variant ();
24698
e74cfd16 24699 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24700
f17c130b 24701#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24702 {
7cc69913
NC
24703 unsigned int flags = 0;
24704
24705#if defined OBJ_ELF
24706 flags = meabi_flags;
d507cf36
PB
24707
24708 switch (meabi_flags)
33a392fb 24709 {
d507cf36 24710 case EF_ARM_EABI_UNKNOWN:
7cc69913 24711#endif
d507cf36
PB
24712 /* Set the flags in the private structure. */
24713 if (uses_apcs_26) flags |= F_APCS26;
24714 if (support_interwork) flags |= F_INTERWORK;
24715 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24716 if (pic_code) flags |= F_PIC;
e74cfd16 24717 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24718 flags |= F_SOFT_FLOAT;
24719
d507cf36
PB
24720 switch (mfloat_abi_opt)
24721 {
24722 case ARM_FLOAT_ABI_SOFT:
24723 case ARM_FLOAT_ABI_SOFTFP:
24724 flags |= F_SOFT_FLOAT;
24725 break;
33a392fb 24726
d507cf36
PB
24727 case ARM_FLOAT_ABI_HARD:
24728 if (flags & F_SOFT_FLOAT)
24729 as_bad (_("hard-float conflicts with specified fpu"));
24730 break;
24731 }
03b1477f 24732
e74cfd16
PB
24733 /* Using pure-endian doubles (even if soft-float). */
24734 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24735 flags |= F_VFP_FLOAT;
f17c130b 24736
fde78edd 24737#if defined OBJ_ELF
e74cfd16 24738 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24739 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24740 break;
24741
8cb51566 24742 case EF_ARM_EABI_VER4:
3a4a14e9 24743 case EF_ARM_EABI_VER5:
c19d1205 24744 /* No additional flags to set. */
d507cf36
PB
24745 break;
24746
24747 default:
24748 abort ();
24749 }
7cc69913 24750#endif
b99bd4ef
NC
24751 bfd_set_private_flags (stdoutput, flags);
24752
24753 /* We have run out flags in the COFF header to encode the
24754 status of ATPCS support, so instead we create a dummy,
c19d1205 24755 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24756 if (atpcs)
24757 {
24758 asection * sec;
24759
24760 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24761
24762 if (sec != NULL)
24763 {
24764 bfd_set_section_flags
24765 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24766 bfd_set_section_size (stdoutput, sec, 0);
24767 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24768 }
24769 }
7cc69913 24770 }
f17c130b 24771#endif
b99bd4ef
NC
24772
24773 /* Record the CPU type as well. */
2d447fca
JM
24774 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24775 mach = bfd_mach_arm_iWMMXt2;
24776 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24777 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24778 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24779 mach = bfd_mach_arm_XScale;
e74cfd16 24780 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24781 mach = bfd_mach_arm_ep9312;
e74cfd16 24782 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24783 mach = bfd_mach_arm_5TE;
e74cfd16 24784 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24785 {
e74cfd16 24786 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24787 mach = bfd_mach_arm_5T;
24788 else
24789 mach = bfd_mach_arm_5;
24790 }
e74cfd16 24791 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24792 {
e74cfd16 24793 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24794 mach = bfd_mach_arm_4T;
24795 else
24796 mach = bfd_mach_arm_4;
24797 }
e74cfd16 24798 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24799 mach = bfd_mach_arm_3M;
e74cfd16
PB
24800 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24801 mach = bfd_mach_arm_3;
24802 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24803 mach = bfd_mach_arm_2a;
24804 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24805 mach = bfd_mach_arm_2;
24806 else
24807 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24808
24809 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24810}
24811
c19d1205 24812/* Command line processing. */
b99bd4ef 24813
c19d1205
ZW
24814/* md_parse_option
24815 Invocation line includes a switch not recognized by the base assembler.
24816 See if it's a processor-specific option.
b99bd4ef 24817
c19d1205
ZW
24818 This routine is somewhat complicated by the need for backwards
24819 compatibility (since older releases of gcc can't be changed).
24820 The new options try to make the interface as compatible as
24821 possible with GCC.
b99bd4ef 24822
c19d1205 24823 New options (supported) are:
b99bd4ef 24824
c19d1205
ZW
24825 -mcpu=<cpu name> Assemble for selected processor
24826 -march=<architecture name> Assemble for selected architecture
24827 -mfpu=<fpu architecture> Assemble for selected FPU.
24828 -EB/-mbig-endian Big-endian
24829 -EL/-mlittle-endian Little-endian
24830 -k Generate PIC code
24831 -mthumb Start in Thumb mode
24832 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24833
278df34e 24834 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24835 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24836
c19d1205 24837 For now we will also provide support for:
b99bd4ef 24838
c19d1205
ZW
24839 -mapcs-32 32-bit Program counter
24840 -mapcs-26 26-bit Program counter
24841 -macps-float Floats passed in FP registers
24842 -mapcs-reentrant Reentrant code
24843 -matpcs
24844 (sometime these will probably be replaced with -mapcs=<list of options>
24845 and -matpcs=<list of options>)
b99bd4ef 24846
c19d1205
ZW
24847 The remaining options are only supported for back-wards compatibility.
24848 Cpu variants, the arm part is optional:
24849 -m[arm]1 Currently not supported.
24850 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24851 -m[arm]3 Arm 3 processor
24852 -m[arm]6[xx], Arm 6 processors
24853 -m[arm]7[xx][t][[d]m] Arm 7 processors
24854 -m[arm]8[10] Arm 8 processors
24855 -m[arm]9[20][tdmi] Arm 9 processors
24856 -mstrongarm[110[0]] StrongARM processors
24857 -mxscale XScale processors
24858 -m[arm]v[2345[t[e]]] Arm architectures
24859 -mall All (except the ARM1)
24860 FP variants:
24861 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24862 -mfpe-old (No float load/store multiples)
24863 -mvfpxd VFP Single precision
24864 -mvfp All VFP
24865 -mno-fpu Disable all floating point instructions
b99bd4ef 24866
c19d1205
ZW
24867 The following CPU names are recognized:
24868 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24869 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24870 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24871 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24872 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24873 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24874 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24875
c19d1205 24876 */
b99bd4ef 24877
c19d1205 24878const char * md_shortopts = "m:k";
b99bd4ef 24879
c19d1205
ZW
24880#ifdef ARM_BI_ENDIAN
24881#define OPTION_EB (OPTION_MD_BASE + 0)
24882#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24883#else
c19d1205
ZW
24884#if TARGET_BYTES_BIG_ENDIAN
24885#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 24886#else
c19d1205
ZW
24887#define OPTION_EL (OPTION_MD_BASE + 1)
24888#endif
b99bd4ef 24889#endif
845b51d6 24890#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 24891
c19d1205 24892struct option md_longopts[] =
b99bd4ef 24893{
c19d1205
ZW
24894#ifdef OPTION_EB
24895 {"EB", no_argument, NULL, OPTION_EB},
24896#endif
24897#ifdef OPTION_EL
24898 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 24899#endif
845b51d6 24900 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
24901 {NULL, no_argument, NULL, 0}
24902};
b99bd4ef 24903
8b2d793c 24904
c19d1205 24905size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 24906
c19d1205 24907struct arm_option_table
b99bd4ef 24908{
c19d1205
ZW
24909 char *option; /* Option name to match. */
24910 char *help; /* Help information. */
24911 int *var; /* Variable to change. */
24912 int value; /* What to change it to. */
24913 char *deprecated; /* If non-null, print this message. */
24914};
b99bd4ef 24915
c19d1205
ZW
24916struct arm_option_table arm_opts[] =
24917{
24918 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24919 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24920 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24921 &support_interwork, 1, NULL},
24922 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24923 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24924 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24925 1, NULL},
24926 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24927 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24928 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24929 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24930 NULL},
b99bd4ef 24931
c19d1205
ZW
24932 /* These are recognized by the assembler, but have no affect on code. */
24933 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24934 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
24935
24936 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24937 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24938 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
24939 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24940 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
24941 {NULL, NULL, NULL, 0, NULL}
24942};
24943
24944struct arm_legacy_option_table
24945{
24946 char *option; /* Option name to match. */
24947 const arm_feature_set **var; /* Variable to change. */
24948 const arm_feature_set value; /* What to change it to. */
24949 char *deprecated; /* If non-null, print this message. */
24950};
b99bd4ef 24951
e74cfd16
PB
24952const struct arm_legacy_option_table arm_legacy_opts[] =
24953{
c19d1205
ZW
24954 /* DON'T add any new processors to this list -- we want the whole list
24955 to go away... Add them to the processors table instead. */
e74cfd16
PB
24956 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24957 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24958 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24959 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24960 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24961 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24962 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24963 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24964 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24965 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24966 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24967 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24968 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24969 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24970 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24971 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24972 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24973 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24974 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24975 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24976 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24977 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24978 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24979 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24980 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24981 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24982 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24983 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24984 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24985 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24986 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24987 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24988 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24989 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24990 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24991 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24992 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24993 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24994 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24995 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24996 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24997 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24998 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24999 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25000 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25001 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25002 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25003 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25004 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25005 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25006 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25007 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25008 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25009 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25010 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25011 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25012 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25013 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25014 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25015 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25016 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25017 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25018 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25019 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25020 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25021 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25022 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25023 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25024 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25025 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25026 N_("use -mcpu=strongarm110")},
e74cfd16 25027 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25028 N_("use -mcpu=strongarm1100")},
e74cfd16 25029 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25030 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25031 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25032 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25033 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25034
c19d1205 25035 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25036 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25037 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25038 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25039 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25040 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25041 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25042 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25043 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25044 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25045 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25046 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25047 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25048 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25049 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25050 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25051 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25052 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25053 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25054
c19d1205 25055 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25056 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25057 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25058 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25059 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25060 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25061
e74cfd16 25062 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25063};
7ed4c4c5 25064
c19d1205 25065struct arm_cpu_option_table
7ed4c4c5 25066{
c19d1205 25067 char *name;
f3bad469 25068 size_t name_len;
e74cfd16 25069 const arm_feature_set value;
c19d1205
ZW
25070 /* For some CPUs we assume an FPU unless the user explicitly sets
25071 -mfpu=... */
e74cfd16 25072 const arm_feature_set default_fpu;
ee065d83
PB
25073 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25074 case. */
25075 const char *canonical_name;
c19d1205 25076};
7ed4c4c5 25077
c19d1205
ZW
25078/* This list should, at a minimum, contain all the cpu names
25079 recognized by GCC. */
f3bad469 25080#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25081static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25082{
f3bad469
MGD
25083 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25084 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25085 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25086 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25087 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25088 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25089 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25090 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25091 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25092 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25093 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25094 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25095 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25096 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25097 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25098 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25099 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25100 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25101 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25102 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25103 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25104 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25105 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25106 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25107 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25108 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25109 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25110 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25111 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25112 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25113 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25114 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25115 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25116 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25117 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25118 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25119 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25120 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25121 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25122 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25123 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25124 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25125 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25126 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25127 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25128 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25129 /* For V5 or later processors we default to using VFP; but the user
25130 should really set the FPU type explicitly. */
f3bad469
MGD
25131 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25132 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25133 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25134 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25135 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25136 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25137 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25138 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25139 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25140 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25141 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25142 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25143 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25144 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25145 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25146 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25147 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25148 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25149 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25150 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25151 "ARM1026EJ-S"),
25152 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25153 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25154 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25155 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25156 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25157 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25158 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25159 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25160 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25161 "ARM1136JF-S"),
25162 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25163 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25164 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25165 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25166 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25167 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25168 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25169 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25170 FPU_NONE, "Cortex-A5"),
c9fb6e58 25171 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25172 "Cortex-A7"),
25173 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25174 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25175 | FPU_NEON_EXT_V1),
f3bad469
MGD
25176 "Cortex-A8"),
25177 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25178 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25179 | FPU_NEON_EXT_V1),
f3bad469 25180 "Cortex-A9"),
c9fb6e58 25181 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25182 "Cortex-A12"),
c9fb6e58 25183 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25184 "Cortex-A15"),
d7adf960
KT
25185 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25186 "Cortex-A17"),
6735952f
KT
25187 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25188 "Cortex-A32"),
43cdc0a8
RR
25189 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25190 "Cortex-A35"),
92eb40d9 25191 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25192 "Cortex-A53"),
92eb40d9 25193 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25194 "Cortex-A57"),
b19f47ad
JW
25195 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25196 "Cortex-A72"),
f3bad469
MGD
25197 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25198 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25199 "Cortex-R4F"),
25200 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25201 FPU_NONE, "Cortex-R5"),
70a8bc5b 25202 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25203 FPU_ARCH_VFP_V3D16,
25204 "Cortex-R7"),
a715796b 25205 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25206 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25207 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25208 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25209 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25210 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
25211 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25212 "Samsung " \
25213 "Exynos M1"),
6b21c2bf
JW
25214 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25215 "Qualcomm "
25216 "QDF24XX"),
25217
c19d1205 25218 /* ??? XSCALE is really an architecture. */
f3bad469 25219 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25220 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25221 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25222 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25223 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25224 /* Maverick */
823d2571 25225 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25226 FPU_ARCH_MAVERICK, "ARM920T"),
25227 /* Marvell processors. */
ff8646ee
TP
25228 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25229 | ARM_EXT_SEC,
25230 ARM_EXT2_V6T2_V8M),
477330fc 25231 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25232 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25233 | ARM_EXT_SEC,
25234 ARM_EXT2_V6T2_V8M),
4347085a 25235 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25236 /* APM X-Gene family. */
25237 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25238 "APM X-Gene 1"),
25239 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25240 "APM X-Gene 2"),
da4339ed 25241
f3bad469 25242 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25243};
f3bad469 25244#undef ARM_CPU_OPT
7ed4c4c5 25245
c19d1205 25246struct arm_arch_option_table
7ed4c4c5 25247{
c19d1205 25248 char *name;
f3bad469 25249 size_t name_len;
e74cfd16
PB
25250 const arm_feature_set value;
25251 const arm_feature_set default_fpu;
c19d1205 25252};
7ed4c4c5 25253
c19d1205
ZW
25254/* This list should, at a minimum, contain all the architecture names
25255 recognized by GCC. */
f3bad469 25256#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25257static const struct arm_arch_option_table arm_archs[] =
c19d1205 25258{
f3bad469
MGD
25259 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25260 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25261 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25262 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25263 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25264 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25265 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25266 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25267 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25268 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25269 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25270 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25271 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25272 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25273 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25274 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25275 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25276 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25277 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25278 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25279 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25280 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25281 kept to preserve existing behaviour. */
25282 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25283 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25284 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25285 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25286 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25287 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25288 kept to preserve existing behaviour. */
25289 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25290 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25291 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25292 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25293 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25294 /* The official spelling of the ARMv7 profile variants is the dashed form.
25295 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25296 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25297 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25298 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25299 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25300 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25301 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25302 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25303 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25304 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25305 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25306 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25307 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25308 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
25309 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25310 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25311 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25312 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25313};
f3bad469 25314#undef ARM_ARCH_OPT
7ed4c4c5 25315
69133863
MGD
25316/* ISA extensions in the co-processor and main instruction set space. */
25317struct arm_option_extension_value_table
c19d1205
ZW
25318{
25319 char *name;
f3bad469 25320 size_t name_len;
5a70a223
JB
25321 const arm_feature_set merge_value;
25322 const arm_feature_set clear_value;
69133863 25323 const arm_feature_set allowed_archs;
c19d1205 25324};
7ed4c4c5 25325
69133863
MGD
25326/* The following table must be in alphabetical order with a NULL last entry.
25327 */
5a70a223 25328#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 25329static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25330{
823d2571
TG
25331 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25332 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25333 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25334 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25335 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
25336 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25337 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25338 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25339 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25340 ARM_ARCH_V8_2A),
823d2571
TG
25341 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25342 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25343 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
25344 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
25345 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
25346 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
25347 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
25348 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
25349 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
25350 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25351 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25352 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
bca38921 25353 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
823d2571
TG
25354 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25355 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
25356 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25357 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25358 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25359 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25360 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25361 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25362 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25363 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25364 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
25365 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25366 | ARM_EXT_DIV),
25367 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25368 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
d6b4b13e
MW
25369 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8,
25370 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25371 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25372 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
25373 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 25374 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 25375};
f3bad469 25376#undef ARM_EXT_OPT
69133863
MGD
25377
25378/* ISA floating-point and Advanced SIMD extensions. */
25379struct arm_option_fpu_value_table
25380{
25381 char *name;
25382 const arm_feature_set value;
c19d1205 25383};
7ed4c4c5 25384
c19d1205
ZW
25385/* This list should, at a minimum, contain all the fpu names
25386 recognized by GCC. */
69133863 25387static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25388{
25389 {"softfpa", FPU_NONE},
25390 {"fpe", FPU_ARCH_FPE},
25391 {"fpe2", FPU_ARCH_FPE},
25392 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25393 {"fpa", FPU_ARCH_FPA},
25394 {"fpa10", FPU_ARCH_FPA},
25395 {"fpa11", FPU_ARCH_FPA},
25396 {"arm7500fe", FPU_ARCH_FPA},
25397 {"softvfp", FPU_ARCH_VFP},
25398 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25399 {"vfp", FPU_ARCH_VFP_V2},
25400 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25401 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25402 {"vfp10", FPU_ARCH_VFP_V2},
25403 {"vfp10-r0", FPU_ARCH_VFP_V1},
25404 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25405 {"vfpv2", FPU_ARCH_VFP_V2},
25406 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25407 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25408 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25409 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25410 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25411 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25412 {"arm1020t", FPU_ARCH_VFP_V1},
25413 {"arm1020e", FPU_ARCH_VFP_V2},
25414 {"arm1136jfs", FPU_ARCH_VFP_V2},
25415 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25416 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25417 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25418 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25419 {"vfpv4", FPU_ARCH_VFP_V4},
25420 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25421 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25422 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25423 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25424 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25425 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25426 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25427 {"crypto-neon-fp-armv8",
25428 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25429 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25430 {"crypto-neon-fp-armv8.1",
25431 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25432 {NULL, ARM_ARCH_NONE}
25433};
25434
25435struct arm_option_value_table
25436{
25437 char *name;
25438 long value;
c19d1205 25439};
7ed4c4c5 25440
e74cfd16 25441static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25442{
25443 {"hard", ARM_FLOAT_ABI_HARD},
25444 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25445 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25446 {NULL, 0}
c19d1205 25447};
7ed4c4c5 25448
c19d1205 25449#ifdef OBJ_ELF
3a4a14e9 25450/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25451static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25452{
25453 {"gnu", EF_ARM_EABI_UNKNOWN},
25454 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25455 {"5", EF_ARM_EABI_VER5},
e74cfd16 25456 {NULL, 0}
c19d1205
ZW
25457};
25458#endif
7ed4c4c5 25459
c19d1205
ZW
25460struct arm_long_option_table
25461{
25462 char * option; /* Substring to match. */
25463 char * help; /* Help information. */
25464 int (* func) (char * subopt); /* Function to decode sub-option. */
25465 char * deprecated; /* If non-null, print this message. */
25466};
7ed4c4c5 25467
c921be7d 25468static bfd_boolean
f3bad469 25469arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 25470{
21d799b5
NC
25471 arm_feature_set *ext_set = (arm_feature_set *)
25472 xmalloc (sizeof (arm_feature_set));
e74cfd16 25473
69133863 25474 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25475 extensions being added before being removed. We achieve this by having
25476 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25477 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25478 or removing it (0) and only allowing it to change in the order
69133863
MGD
25479 -1 -> 1 -> 0. */
25480 const struct arm_option_extension_value_table * opt = NULL;
25481 int adding_value = -1;
25482
e74cfd16
PB
25483 /* Copy the feature set, so that we can modify it. */
25484 *ext_set = **opt_p;
25485 *opt_p = ext_set;
25486
c19d1205 25487 while (str != NULL && *str != 0)
7ed4c4c5 25488 {
f3bad469
MGD
25489 char *ext;
25490 size_t len;
7ed4c4c5 25491
c19d1205
ZW
25492 if (*str != '+')
25493 {
25494 as_bad (_("invalid architectural extension"));
c921be7d 25495 return FALSE;
c19d1205 25496 }
7ed4c4c5 25497
c19d1205
ZW
25498 str++;
25499 ext = strchr (str, '+');
7ed4c4c5 25500
c19d1205 25501 if (ext != NULL)
f3bad469 25502 len = ext - str;
c19d1205 25503 else
f3bad469 25504 len = strlen (str);
7ed4c4c5 25505
f3bad469 25506 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25507 {
25508 if (adding_value != 0)
25509 {
25510 adding_value = 0;
25511 opt = arm_extensions;
25512 }
25513
f3bad469 25514 len -= 2;
69133863
MGD
25515 str += 2;
25516 }
f3bad469 25517 else if (len > 0)
69133863
MGD
25518 {
25519 if (adding_value == -1)
25520 {
25521 adding_value = 1;
25522 opt = arm_extensions;
25523 }
25524 else if (adding_value != 1)
25525 {
25526 as_bad (_("must specify extensions to add before specifying "
25527 "those to remove"));
25528 return FALSE;
25529 }
25530 }
25531
f3bad469 25532 if (len == 0)
c19d1205
ZW
25533 {
25534 as_bad (_("missing architectural extension"));
c921be7d 25535 return FALSE;
c19d1205 25536 }
7ed4c4c5 25537
69133863
MGD
25538 gas_assert (adding_value != -1);
25539 gas_assert (opt != NULL);
25540
25541 /* Scan over the options table trying to find an exact match. */
25542 for (; opt->name != NULL; opt++)
f3bad469 25543 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25544 {
69133863
MGD
25545 /* Check we can apply the extension to this architecture. */
25546 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
25547 {
25548 as_bad (_("extension does not apply to the base architecture"));
25549 return FALSE;
25550 }
25551
25552 /* Add or remove the extension. */
25553 if (adding_value)
5a70a223 25554 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25555 else
5a70a223 25556 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25557
c19d1205
ZW
25558 break;
25559 }
7ed4c4c5 25560
c19d1205
ZW
25561 if (opt->name == NULL)
25562 {
69133863
MGD
25563 /* Did we fail to find an extension because it wasn't specified in
25564 alphabetical order, or because it does not exist? */
25565
25566 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25567 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25568 break;
25569
25570 if (opt->name == NULL)
25571 as_bad (_("unknown architectural extension `%s'"), str);
25572 else
25573 as_bad (_("architectural extensions must be specified in "
25574 "alphabetical order"));
25575
c921be7d 25576 return FALSE;
c19d1205 25577 }
69133863
MGD
25578 else
25579 {
25580 /* We should skip the extension we've just matched the next time
25581 round. */
25582 opt++;
25583 }
7ed4c4c5 25584
c19d1205
ZW
25585 str = ext;
25586 };
7ed4c4c5 25587
c921be7d 25588 return TRUE;
c19d1205 25589}
7ed4c4c5 25590
c921be7d 25591static bfd_boolean
f3bad469 25592arm_parse_cpu (char *str)
7ed4c4c5 25593{
f3bad469
MGD
25594 const struct arm_cpu_option_table *opt;
25595 char *ext = strchr (str, '+');
25596 size_t len;
7ed4c4c5 25597
c19d1205 25598 if (ext != NULL)
f3bad469 25599 len = ext - str;
7ed4c4c5 25600 else
f3bad469 25601 len = strlen (str);
7ed4c4c5 25602
f3bad469 25603 if (len == 0)
7ed4c4c5 25604 {
c19d1205 25605 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25606 return FALSE;
7ed4c4c5
NC
25607 }
25608
c19d1205 25609 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25610 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25611 {
e74cfd16
PB
25612 mcpu_cpu_opt = &opt->value;
25613 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25614 if (opt->canonical_name)
ef8e6722
JW
25615 {
25616 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25617 strcpy (selected_cpu_name, opt->canonical_name);
25618 }
ee065d83
PB
25619 else
25620 {
f3bad469 25621 size_t i;
c921be7d 25622
ef8e6722
JW
25623 if (len >= sizeof selected_cpu_name)
25624 len = (sizeof selected_cpu_name) - 1;
25625
f3bad469 25626 for (i = 0; i < len; i++)
ee065d83
PB
25627 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25628 selected_cpu_name[i] = 0;
25629 }
7ed4c4c5 25630
c19d1205
ZW
25631 if (ext != NULL)
25632 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25633
c921be7d 25634 return TRUE;
c19d1205 25635 }
7ed4c4c5 25636
c19d1205 25637 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25638 return FALSE;
7ed4c4c5
NC
25639}
25640
c921be7d 25641static bfd_boolean
f3bad469 25642arm_parse_arch (char *str)
7ed4c4c5 25643{
e74cfd16 25644 const struct arm_arch_option_table *opt;
c19d1205 25645 char *ext = strchr (str, '+');
f3bad469 25646 size_t len;
7ed4c4c5 25647
c19d1205 25648 if (ext != NULL)
f3bad469 25649 len = ext - str;
7ed4c4c5 25650 else
f3bad469 25651 len = strlen (str);
7ed4c4c5 25652
f3bad469 25653 if (len == 0)
7ed4c4c5 25654 {
c19d1205 25655 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25656 return FALSE;
7ed4c4c5
NC
25657 }
25658
c19d1205 25659 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25660 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25661 {
e74cfd16
PB
25662 march_cpu_opt = &opt->value;
25663 march_fpu_opt = &opt->default_fpu;
5f4273c7 25664 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25665
c19d1205
ZW
25666 if (ext != NULL)
25667 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25668
c921be7d 25669 return TRUE;
c19d1205
ZW
25670 }
25671
25672 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25673 return FALSE;
7ed4c4c5 25674}
eb043451 25675
c921be7d 25676static bfd_boolean
c19d1205
ZW
25677arm_parse_fpu (char * str)
25678{
69133863 25679 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25680
c19d1205
ZW
25681 for (opt = arm_fpus; opt->name != NULL; opt++)
25682 if (streq (opt->name, str))
25683 {
e74cfd16 25684 mfpu_opt = &opt->value;
c921be7d 25685 return TRUE;
c19d1205 25686 }
b99bd4ef 25687
c19d1205 25688 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25689 return FALSE;
c19d1205
ZW
25690}
25691
c921be7d 25692static bfd_boolean
c19d1205 25693arm_parse_float_abi (char * str)
b99bd4ef 25694{
e74cfd16 25695 const struct arm_option_value_table * opt;
b99bd4ef 25696
c19d1205
ZW
25697 for (opt = arm_float_abis; opt->name != NULL; opt++)
25698 if (streq (opt->name, str))
25699 {
25700 mfloat_abi_opt = opt->value;
c921be7d 25701 return TRUE;
c19d1205 25702 }
cc8a6dd0 25703
c19d1205 25704 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25705 return FALSE;
c19d1205 25706}
b99bd4ef 25707
c19d1205 25708#ifdef OBJ_ELF
c921be7d 25709static bfd_boolean
c19d1205
ZW
25710arm_parse_eabi (char * str)
25711{
e74cfd16 25712 const struct arm_option_value_table *opt;
cc8a6dd0 25713
c19d1205
ZW
25714 for (opt = arm_eabis; opt->name != NULL; opt++)
25715 if (streq (opt->name, str))
25716 {
25717 meabi_flags = opt->value;
c921be7d 25718 return TRUE;
c19d1205
ZW
25719 }
25720 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25721 return FALSE;
c19d1205
ZW
25722}
25723#endif
cc8a6dd0 25724
c921be7d 25725static bfd_boolean
e07e6e58
NC
25726arm_parse_it_mode (char * str)
25727{
c921be7d 25728 bfd_boolean ret = TRUE;
e07e6e58
NC
25729
25730 if (streq ("arm", str))
25731 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25732 else if (streq ("thumb", str))
25733 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25734 else if (streq ("always", str))
25735 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25736 else if (streq ("never", str))
25737 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25738 else
25739 {
25740 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25741 "arm, thumb, always, or never."), str);
c921be7d 25742 ret = FALSE;
e07e6e58
NC
25743 }
25744
25745 return ret;
25746}
25747
2e6976a8
DG
25748static bfd_boolean
25749arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25750{
25751 codecomposer_syntax = TRUE;
25752 arm_comment_chars[0] = ';';
25753 arm_line_separator_chars[0] = 0;
25754 return TRUE;
25755}
25756
c19d1205
ZW
25757struct arm_long_option_table arm_long_opts[] =
25758{
25759 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25760 arm_parse_cpu, NULL},
25761 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25762 arm_parse_arch, NULL},
25763 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25764 arm_parse_fpu, NULL},
25765 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25766 arm_parse_float_abi, NULL},
25767#ifdef OBJ_ELF
7fac0536 25768 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25769 arm_parse_eabi, NULL},
25770#endif
e07e6e58
NC
25771 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25772 arm_parse_it_mode, NULL},
2e6976a8
DG
25773 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25774 arm_ccs_mode, NULL},
c19d1205
ZW
25775 {NULL, NULL, 0, NULL}
25776};
cc8a6dd0 25777
c19d1205
ZW
25778int
25779md_parse_option (int c, char * arg)
25780{
25781 struct arm_option_table *opt;
e74cfd16 25782 const struct arm_legacy_option_table *fopt;
c19d1205 25783 struct arm_long_option_table *lopt;
b99bd4ef 25784
c19d1205 25785 switch (c)
b99bd4ef 25786 {
c19d1205
ZW
25787#ifdef OPTION_EB
25788 case OPTION_EB:
25789 target_big_endian = 1;
25790 break;
25791#endif
cc8a6dd0 25792
c19d1205
ZW
25793#ifdef OPTION_EL
25794 case OPTION_EL:
25795 target_big_endian = 0;
25796 break;
25797#endif
b99bd4ef 25798
845b51d6
PB
25799 case OPTION_FIX_V4BX:
25800 fix_v4bx = TRUE;
25801 break;
25802
c19d1205
ZW
25803 case 'a':
25804 /* Listing option. Just ignore these, we don't support additional
25805 ones. */
25806 return 0;
b99bd4ef 25807
c19d1205
ZW
25808 default:
25809 for (opt = arm_opts; opt->option != NULL; opt++)
25810 {
25811 if (c == opt->option[0]
25812 && ((arg == NULL && opt->option[1] == 0)
25813 || streq (arg, opt->option + 1)))
25814 {
c19d1205 25815 /* If the option is deprecated, tell the user. */
278df34e 25816 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25817 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25818 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25819
c19d1205
ZW
25820 if (opt->var != NULL)
25821 *opt->var = opt->value;
cc8a6dd0 25822
c19d1205
ZW
25823 return 1;
25824 }
25825 }
b99bd4ef 25826
e74cfd16
PB
25827 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25828 {
25829 if (c == fopt->option[0]
25830 && ((arg == NULL && fopt->option[1] == 0)
25831 || streq (arg, fopt->option + 1)))
25832 {
e74cfd16 25833 /* If the option is deprecated, tell the user. */
278df34e 25834 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25835 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25836 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25837
25838 if (fopt->var != NULL)
25839 *fopt->var = &fopt->value;
25840
25841 return 1;
25842 }
25843 }
25844
c19d1205
ZW
25845 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25846 {
25847 /* These options are expected to have an argument. */
25848 if (c == lopt->option[0]
25849 && arg != NULL
25850 && strncmp (arg, lopt->option + 1,
25851 strlen (lopt->option + 1)) == 0)
25852 {
c19d1205 25853 /* If the option is deprecated, tell the user. */
278df34e 25854 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25855 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25856 _(lopt->deprecated));
b99bd4ef 25857
c19d1205
ZW
25858 /* Call the sup-option parser. */
25859 return lopt->func (arg + strlen (lopt->option) - 1);
25860 }
25861 }
a737bd4d 25862
c19d1205
ZW
25863 return 0;
25864 }
a394c00f 25865
c19d1205
ZW
25866 return 1;
25867}
a394c00f 25868
c19d1205
ZW
25869void
25870md_show_usage (FILE * fp)
a394c00f 25871{
c19d1205
ZW
25872 struct arm_option_table *opt;
25873 struct arm_long_option_table *lopt;
a394c00f 25874
c19d1205 25875 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25876
c19d1205
ZW
25877 for (opt = arm_opts; opt->option != NULL; opt++)
25878 if (opt->help != NULL)
25879 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25880
c19d1205
ZW
25881 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25882 if (lopt->help != NULL)
25883 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 25884
c19d1205
ZW
25885#ifdef OPTION_EB
25886 fprintf (fp, _("\
25887 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
25888#endif
25889
c19d1205
ZW
25890#ifdef OPTION_EL
25891 fprintf (fp, _("\
25892 -EL assemble code for a little-endian cpu\n"));
a737bd4d 25893#endif
845b51d6
PB
25894
25895 fprintf (fp, _("\
25896 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 25897}
ee065d83
PB
25898
25899
25900#ifdef OBJ_ELF
62b3e311
PB
25901typedef struct
25902{
25903 int val;
25904 arm_feature_set flags;
25905} cpu_arch_ver_table;
25906
4ed7ed8d
TP
25907/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
25908 must be sorted least features first but some reordering is needed, eg. for
25909 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
25910static const cpu_arch_ver_table cpu_arch_ver[] =
25911{
25912 {1, ARM_ARCH_V4},
25913 {2, ARM_ARCH_V4T},
25914 {3, ARM_ARCH_V5},
ee3c0378 25915 {3, ARM_ARCH_V5T},
62b3e311
PB
25916 {4, ARM_ARCH_V5TE},
25917 {5, ARM_ARCH_V5TEJ},
25918 {6, ARM_ARCH_V6},
7e806470 25919 {9, ARM_ARCH_V6K},
f4c65163 25920 {7, ARM_ARCH_V6Z},
91e22acd 25921 {11, ARM_ARCH_V6M},
b2a5fbdc 25922 {12, ARM_ARCH_V6SM},
7e806470 25923 {8, ARM_ARCH_V6T2},
c9fb6e58 25924 {10, ARM_ARCH_V7VE},
62b3e311
PB
25925 {10, ARM_ARCH_V7R},
25926 {10, ARM_ARCH_V7M},
bca38921 25927 {14, ARM_ARCH_V8A},
ff8646ee 25928 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 25929 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
25930 {0, ARM_ARCH_NONE}
25931};
25932
ee3c0378
AS
25933/* Set an attribute if it has not already been set by the user. */
25934static void
25935aeabi_set_attribute_int (int tag, int value)
25936{
25937 if (tag < 1
25938 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25939 || !attributes_set_explicitly[tag])
25940 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25941}
25942
25943static void
25944aeabi_set_attribute_string (int tag, const char *value)
25945{
25946 if (tag < 1
25947 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25948 || !attributes_set_explicitly[tag])
25949 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25950}
25951
ee065d83 25952/* Set the public EABI object attributes. */
3cfdb781 25953void
ee065d83
PB
25954aeabi_set_public_attributes (void)
25955{
25956 int arch;
69239280 25957 char profile;
90ec0d68 25958 int virt_sec = 0;
bca38921 25959 int fp16_optional = 0;
e74cfd16 25960 arm_feature_set flags;
62b3e311 25961 arm_feature_set tmp;
ff8646ee 25962 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 25963 const cpu_arch_ver_table *p;
ee065d83
PB
25964
25965 /* Choose the architecture based on the capabilities of the requested cpu
25966 (if any) and/or the instructions actually used. */
e74cfd16
PB
25967 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
25968 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
25969 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
25970
25971 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
25972 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
25973
25974 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
25975 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
25976
7f78eb34
JW
25977 selected_cpu = flags;
25978
ddd7f988 25979 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
25980 if (object_arch)
25981 {
25982 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
25983 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
25984 }
25985
251665fc
MGD
25986 /* We need to make sure that the attributes do not identify us as v6S-M
25987 when the only v6S-M feature in use is the Operating System Extensions. */
25988 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
25989 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 25990 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 25991
62b3e311
PB
25992 tmp = flags;
25993 arch = 0;
25994 for (p = cpu_arch_ver; p->val; p++)
25995 {
25996 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
25997 {
25998 arch = p->val;
25999 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26000 }
26001 }
ee065d83 26002
9e3c6df6
PB
26003 /* The table lookup above finds the last architecture to contribute
26004 a new feature. Unfortunately, Tag13 is a subset of the union of
26005 v6T2 and v7-M, so it is never seen as contributing a new feature.
26006 We can not search for the last entry which is entirely used,
26007 because if no CPU is specified we build up only those flags
26008 actually used. Perhaps we should separate out the specified
26009 and implicit cases. Avoid taking this path for -march=all by
26010 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26011 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26012 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26013 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26014 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
4ed7ed8d
TP
26015 arch = TAG_CPU_ARCH_V7E_M;
26016
ff8646ee
TP
26017 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26018 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
26019 arch = TAG_CPU_ARCH_V8M_MAIN;
26020
4ed7ed8d
TP
26021 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26022 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26023 ARMv8-M, -march=all must be detected as ARMv8-A. */
26024 if (arch == TAG_CPU_ARCH_V8M_MAIN
26025 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
26026 arch = TAG_CPU_ARCH_V8;
9e3c6df6 26027
ee065d83
PB
26028 /* Tag_CPU_name. */
26029 if (selected_cpu_name[0])
26030 {
91d6fa6a 26031 char *q;
ee065d83 26032
91d6fa6a
NC
26033 q = selected_cpu_name;
26034 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26035 {
26036 int i;
5f4273c7 26037
91d6fa6a
NC
26038 q += 4;
26039 for (i = 0; q[i]; i++)
26040 q[i] = TOUPPER (q[i]);
ee065d83 26041 }
91d6fa6a 26042 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26043 }
62f3b8c8 26044
ee065d83 26045 /* Tag_CPU_arch. */
ee3c0378 26046 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26047
62b3e311 26048 /* Tag_CPU_arch_profile. */
10c9892b 26049 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26050 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26051 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
26052 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)))
69239280 26053 profile = 'A';
62b3e311 26054 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26055 profile = 'R';
7e806470 26056 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26057 profile = 'M';
26058 else
26059 profile = '\0';
26060
26061 if (profile != '\0')
26062 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26063
ee065d83 26064 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26065 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26066 || arch == 0)
26067 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26068
ee065d83 26069 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26070 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26071 || arch == 0)
4ed7ed8d
TP
26072 {
26073 int thumb_isa_use;
26074
26075 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26076 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
26077 thumb_isa_use = 3;
26078 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26079 thumb_isa_use = 2;
26080 else
26081 thumb_isa_use = 1;
26082 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26083 }
62f3b8c8 26084
ee065d83 26085 /* Tag_VFP_arch. */
a715796b
TG
26086 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26087 aeabi_set_attribute_int (Tag_VFP_arch,
26088 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26089 ? 7 : 8);
bca38921 26090 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26091 aeabi_set_attribute_int (Tag_VFP_arch,
26092 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26093 ? 5 : 6);
26094 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26095 {
26096 fp16_optional = 1;
26097 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26098 }
ada65aa3 26099 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26100 {
26101 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26102 fp16_optional = 1;
26103 }
ee3c0378
AS
26104 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26105 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26106 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26107 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26108 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26109
4547cb56
NC
26110 /* Tag_ABI_HardFP_use. */
26111 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26112 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26113 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26114
ee065d83 26115 /* Tag_WMMX_arch. */
ee3c0378
AS
26116 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26117 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26118 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26119 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26120
ee3c0378 26121 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
26122 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
26123 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26124 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26125 {
26126 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26127 {
26128 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26129 }
26130 else
26131 {
26132 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26133 fp16_optional = 1;
26134 }
26135 }
fa94de6b 26136
ee3c0378 26137 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26138 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26139 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26140
69239280
MGD
26141 /* Tag_DIV_use.
26142
26143 We set Tag_DIV_use to two when integer divide instructions have been used
26144 in ARM state, or when Thumb integer divide instructions have been used,
26145 but we have no architecture profile set, nor have we any ARM instructions.
26146
4ed7ed8d
TP
26147 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26148 by the base architecture.
bca38921 26149
69239280 26150 For new architectures we will have to check these tests. */
ff8646ee
TP
26151 gas_assert (arch <= TAG_CPU_ARCH_V8
26152 || (arch >= TAG_CPU_ARCH_V8M_BASE
26153 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26154 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26155 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26156 aeabi_set_attribute_int (Tag_DIV_use, 0);
26157 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26158 || (profile == '\0'
26159 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26160 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26161 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26162
26163 /* Tag_MP_extension_use. */
26164 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26165 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26166
26167 /* Tag Virtualization_use. */
26168 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26169 virt_sec |= 1;
26170 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26171 virt_sec |= 2;
26172 if (virt_sec != 0)
26173 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26174}
26175
104d59d1 26176/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26177void
26178arm_md_end (void)
26179{
ee065d83
PB
26180 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26181 return;
26182
26183 aeabi_set_public_attributes ();
ee065d83 26184}
8463be01 26185#endif /* OBJ_ELF */
ee065d83
PB
26186
26187
26188/* Parse a .cpu directive. */
26189
26190static void
26191s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26192{
e74cfd16 26193 const struct arm_cpu_option_table *opt;
ee065d83
PB
26194 char *name;
26195 char saved_char;
26196
26197 name = input_line_pointer;
5f4273c7 26198 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26199 input_line_pointer++;
26200 saved_char = *input_line_pointer;
26201 *input_line_pointer = 0;
26202
26203 /* Skip the first "all" entry. */
26204 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26205 if (streq (opt->name, name))
26206 {
e74cfd16
PB
26207 mcpu_cpu_opt = &opt->value;
26208 selected_cpu = opt->value;
ee065d83 26209 if (opt->canonical_name)
5f4273c7 26210 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26211 else
26212 {
26213 int i;
26214 for (i = 0; opt->name[i]; i++)
26215 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26216
ee065d83
PB
26217 selected_cpu_name[i] = 0;
26218 }
e74cfd16 26219 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26220 *input_line_pointer = saved_char;
26221 demand_empty_rest_of_line ();
26222 return;
26223 }
26224 as_bad (_("unknown cpu `%s'"), name);
26225 *input_line_pointer = saved_char;
26226 ignore_rest_of_line ();
26227}
26228
26229
26230/* Parse a .arch directive. */
26231
26232static void
26233s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26234{
e74cfd16 26235 const struct arm_arch_option_table *opt;
ee065d83
PB
26236 char saved_char;
26237 char *name;
26238
26239 name = input_line_pointer;
5f4273c7 26240 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26241 input_line_pointer++;
26242 saved_char = *input_line_pointer;
26243 *input_line_pointer = 0;
26244
26245 /* Skip the first "all" entry. */
26246 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26247 if (streq (opt->name, name))
26248 {
e74cfd16
PB
26249 mcpu_cpu_opt = &opt->value;
26250 selected_cpu = opt->value;
5f4273c7 26251 strcpy (selected_cpu_name, opt->name);
e74cfd16 26252 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26253 *input_line_pointer = saved_char;
26254 demand_empty_rest_of_line ();
26255 return;
26256 }
26257
26258 as_bad (_("unknown architecture `%s'\n"), name);
26259 *input_line_pointer = saved_char;
26260 ignore_rest_of_line ();
26261}
26262
26263
7a1d4c38
PB
26264/* Parse a .object_arch directive. */
26265
26266static void
26267s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26268{
26269 const struct arm_arch_option_table *opt;
26270 char saved_char;
26271 char *name;
26272
26273 name = input_line_pointer;
5f4273c7 26274 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26275 input_line_pointer++;
26276 saved_char = *input_line_pointer;
26277 *input_line_pointer = 0;
26278
26279 /* Skip the first "all" entry. */
26280 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26281 if (streq (opt->name, name))
26282 {
26283 object_arch = &opt->value;
26284 *input_line_pointer = saved_char;
26285 demand_empty_rest_of_line ();
26286 return;
26287 }
26288
26289 as_bad (_("unknown architecture `%s'\n"), name);
26290 *input_line_pointer = saved_char;
26291 ignore_rest_of_line ();
26292}
26293
69133863
MGD
26294/* Parse a .arch_extension directive. */
26295
26296static void
26297s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26298{
26299 const struct arm_option_extension_value_table *opt;
26300 char saved_char;
26301 char *name;
26302 int adding_value = 1;
26303
26304 name = input_line_pointer;
26305 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26306 input_line_pointer++;
26307 saved_char = *input_line_pointer;
26308 *input_line_pointer = 0;
26309
26310 if (strlen (name) >= 2
26311 && strncmp (name, "no", 2) == 0)
26312 {
26313 adding_value = 0;
26314 name += 2;
26315 }
26316
26317 for (opt = arm_extensions; opt->name != NULL; opt++)
26318 if (streq (opt->name, name))
26319 {
26320 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
26321 {
26322 as_bad (_("architectural extension `%s' is not allowed for the "
26323 "current base architecture"), name);
26324 break;
26325 }
26326
26327 if (adding_value)
5a70a223
JB
26328 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26329 opt->merge_value);
69133863 26330 else
5a70a223 26331 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26332
26333 mcpu_cpu_opt = &selected_cpu;
26334 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26335 *input_line_pointer = saved_char;
26336 demand_empty_rest_of_line ();
26337 return;
26338 }
26339
26340 if (opt->name == NULL)
e673710a 26341 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26342
26343 *input_line_pointer = saved_char;
26344 ignore_rest_of_line ();
26345}
26346
ee065d83
PB
26347/* Parse a .fpu directive. */
26348
26349static void
26350s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26351{
69133863 26352 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26353 char saved_char;
26354 char *name;
26355
26356 name = input_line_pointer;
5f4273c7 26357 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26358 input_line_pointer++;
26359 saved_char = *input_line_pointer;
26360 *input_line_pointer = 0;
5f4273c7 26361
ee065d83
PB
26362 for (opt = arm_fpus; opt->name != NULL; opt++)
26363 if (streq (opt->name, name))
26364 {
e74cfd16
PB
26365 mfpu_opt = &opt->value;
26366 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26367 *input_line_pointer = saved_char;
26368 demand_empty_rest_of_line ();
26369 return;
26370 }
26371
26372 as_bad (_("unknown floating point format `%s'\n"), name);
26373 *input_line_pointer = saved_char;
26374 ignore_rest_of_line ();
26375}
ee065d83 26376
794ba86a 26377/* Copy symbol information. */
f31fef98 26378
794ba86a
DJ
26379void
26380arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26381{
26382 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26383}
e04befd0 26384
f31fef98 26385#ifdef OBJ_ELF
e04befd0
AS
26386/* Given a symbolic attribute NAME, return the proper integer value.
26387 Returns -1 if the attribute is not known. */
f31fef98 26388
e04befd0
AS
26389int
26390arm_convert_symbolic_attribute (const char *name)
26391{
f31fef98
NC
26392 static const struct
26393 {
26394 const char * name;
26395 const int tag;
26396 }
26397 attribute_table[] =
26398 {
26399 /* When you modify this table you should
26400 also modify the list in doc/c-arm.texi. */
e04befd0 26401#define T(tag) {#tag, tag}
f31fef98
NC
26402 T (Tag_CPU_raw_name),
26403 T (Tag_CPU_name),
26404 T (Tag_CPU_arch),
26405 T (Tag_CPU_arch_profile),
26406 T (Tag_ARM_ISA_use),
26407 T (Tag_THUMB_ISA_use),
75375b3e 26408 T (Tag_FP_arch),
f31fef98
NC
26409 T (Tag_VFP_arch),
26410 T (Tag_WMMX_arch),
26411 T (Tag_Advanced_SIMD_arch),
26412 T (Tag_PCS_config),
26413 T (Tag_ABI_PCS_R9_use),
26414 T (Tag_ABI_PCS_RW_data),
26415 T (Tag_ABI_PCS_RO_data),
26416 T (Tag_ABI_PCS_GOT_use),
26417 T (Tag_ABI_PCS_wchar_t),
26418 T (Tag_ABI_FP_rounding),
26419 T (Tag_ABI_FP_denormal),
26420 T (Tag_ABI_FP_exceptions),
26421 T (Tag_ABI_FP_user_exceptions),
26422 T (Tag_ABI_FP_number_model),
75375b3e 26423 T (Tag_ABI_align_needed),
f31fef98 26424 T (Tag_ABI_align8_needed),
75375b3e 26425 T (Tag_ABI_align_preserved),
f31fef98
NC
26426 T (Tag_ABI_align8_preserved),
26427 T (Tag_ABI_enum_size),
26428 T (Tag_ABI_HardFP_use),
26429 T (Tag_ABI_VFP_args),
26430 T (Tag_ABI_WMMX_args),
26431 T (Tag_ABI_optimization_goals),
26432 T (Tag_ABI_FP_optimization_goals),
26433 T (Tag_compatibility),
26434 T (Tag_CPU_unaligned_access),
75375b3e 26435 T (Tag_FP_HP_extension),
f31fef98
NC
26436 T (Tag_VFP_HP_extension),
26437 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26438 T (Tag_MPextension_use),
26439 T (Tag_DIV_use),
f31fef98
NC
26440 T (Tag_nodefaults),
26441 T (Tag_also_compatible_with),
26442 T (Tag_conformance),
26443 T (Tag_T2EE_use),
26444 T (Tag_Virtualization_use),
cd21e546 26445 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26446#undef T
f31fef98 26447 };
e04befd0
AS
26448 unsigned int i;
26449
26450 if (name == NULL)
26451 return -1;
26452
f31fef98 26453 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26454 if (streq (name, attribute_table[i].name))
e04befd0
AS
26455 return attribute_table[i].tag;
26456
26457 return -1;
26458}
267bf995
RR
26459
26460
93ef582d
NC
26461/* Apply sym value for relocations only in the case that they are for
26462 local symbols in the same segment as the fixup and you have the
26463 respective architectural feature for blx and simple switches. */
267bf995 26464int
93ef582d 26465arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26466{
26467 if (fixP->fx_addsy
26468 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26469 /* PR 17444: If the local symbol is in a different section then a reloc
26470 will always be generated for it, so applying the symbol value now
26471 will result in a double offset being stored in the relocation. */
26472 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26473 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26474 {
26475 switch (fixP->fx_r_type)
26476 {
26477 case BFD_RELOC_ARM_PCREL_BLX:
26478 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26479 if (ARM_IS_FUNC (fixP->fx_addsy))
26480 return 1;
26481 break;
26482
26483 case BFD_RELOC_ARM_PCREL_CALL:
26484 case BFD_RELOC_THUMB_PCREL_BLX:
26485 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26486 return 1;
267bf995
RR
26487 break;
26488
26489 default:
26490 break;
26491 }
26492
26493 }
26494 return 0;
26495}
f31fef98 26496#endif /* OBJ_ELF */