Mark the i370 target as obsolete.
[deliverable/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 273static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 274 ARM_FEATURE_COPROC (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{
e0471c16 519 const char * name;
c921be7d 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
643afb90
MW
6088/* Record a use of the given feature. */
6089static void
6090record_feature_use (const arm_feature_set *feature)
6091{
6092 if (thumb_mode)
6093 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6094 else
6095 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6096}
6097
e797f7e0
MGD
6098/* If the given feature available in the selected CPU, mark it as used.
6099 Returns TRUE iff feature is available. */
6100static bfd_boolean
6101mark_feature_used (const arm_feature_set *feature)
6102{
6103 /* Ensure the option is valid on the current architecture. */
6104 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6105 return FALSE;
6106
6107 /* Add the appropriate architecture feature for the barrier option used.
6108 */
643afb90 6109 record_feature_use (feature);
e797f7e0
MGD
6110
6111 return TRUE;
6112}
6113
62b3e311
PB
6114/* Parse an option for a barrier instruction. Returns the encoding for the
6115 option, or FAIL. */
6116static int
6117parse_barrier (char **str)
6118{
6119 char *p, *q;
6120 const struct asm_barrier_opt *o;
6121
6122 p = q = *str;
6123 while (ISALPHA (*q))
6124 q++;
6125
21d799b5 6126 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6127 q - p);
62b3e311
PB
6128 if (!o)
6129 return FAIL;
6130
e797f7e0
MGD
6131 if (!mark_feature_used (&o->arch))
6132 return FAIL;
6133
62b3e311
PB
6134 *str = q;
6135 return o->value;
6136}
6137
92e90b6e
PB
6138/* Parse the operands of a table branch instruction. Similar to a memory
6139 operand. */
6140static int
6141parse_tb (char **str)
6142{
6143 char * p = *str;
6144 int reg;
6145
6146 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6147 {
6148 inst.error = _("'[' expected");
6149 return FAIL;
6150 }
92e90b6e 6151
dcbf9037 6152 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6153 {
6154 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6155 return FAIL;
6156 }
6157 inst.operands[0].reg = reg;
6158
6159 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6160 {
6161 inst.error = _("',' expected");
6162 return FAIL;
6163 }
5f4273c7 6164
dcbf9037 6165 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6166 {
6167 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6168 return FAIL;
6169 }
6170 inst.operands[0].imm = reg;
6171
6172 if (skip_past_comma (&p) == SUCCESS)
6173 {
6174 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6175 return FAIL;
6176 if (inst.reloc.exp.X_add_number != 1)
6177 {
6178 inst.error = _("invalid shift");
6179 return FAIL;
6180 }
6181 inst.operands[0].shifted = 1;
6182 }
6183
6184 if (skip_past_char (&p, ']') == FAIL)
6185 {
6186 inst.error = _("']' expected");
6187 return FAIL;
6188 }
6189 *str = p;
6190 return SUCCESS;
6191}
6192
5287ad62
JB
6193/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6194 information on the types the operands can take and how they are encoded.
037e8744
JB
6195 Up to four operands may be read; this function handles setting the
6196 ".present" field for each read operand itself.
5287ad62
JB
6197 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6198 else returns FAIL. */
6199
6200static int
6201parse_neon_mov (char **str, int *which_operand)
6202{
6203 int i = *which_operand, val;
6204 enum arm_reg_type rtype;
6205 char *ptr = *str;
dcbf9037 6206 struct neon_type_el optype;
5f4273c7 6207
dcbf9037 6208 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6209 {
6210 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6211 inst.operands[i].reg = val;
6212 inst.operands[i].isscalar = 1;
dcbf9037 6213 inst.operands[i].vectype = optype;
5287ad62
JB
6214 inst.operands[i++].present = 1;
6215
6216 if (skip_past_comma (&ptr) == FAIL)
477330fc 6217 goto wanted_comma;
5f4273c7 6218
dcbf9037 6219 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6220 goto wanted_arm;
5f4273c7 6221
5287ad62
JB
6222 inst.operands[i].reg = val;
6223 inst.operands[i].isreg = 1;
6224 inst.operands[i].present = 1;
6225 }
037e8744 6226 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6227 != FAIL)
5287ad62
JB
6228 {
6229 /* Cases 0, 1, 2, 3, 5 (D only). */
6230 if (skip_past_comma (&ptr) == FAIL)
477330fc 6231 goto wanted_comma;
5f4273c7 6232
5287ad62
JB
6233 inst.operands[i].reg = val;
6234 inst.operands[i].isreg = 1;
6235 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6236 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6237 inst.operands[i].isvec = 1;
dcbf9037 6238 inst.operands[i].vectype = optype;
5287ad62
JB
6239 inst.operands[i++].present = 1;
6240
dcbf9037 6241 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6242 {
6243 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6244 Case 13: VMOV <Sd>, <Rm> */
6245 inst.operands[i].reg = val;
6246 inst.operands[i].isreg = 1;
6247 inst.operands[i].present = 1;
6248
6249 if (rtype == REG_TYPE_NQ)
6250 {
6251 first_error (_("can't use Neon quad register here"));
6252 return FAIL;
6253 }
6254 else if (rtype != REG_TYPE_VFS)
6255 {
6256 i++;
6257 if (skip_past_comma (&ptr) == FAIL)
6258 goto wanted_comma;
6259 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6260 goto wanted_arm;
6261 inst.operands[i].reg = val;
6262 inst.operands[i].isreg = 1;
6263 inst.operands[i].present = 1;
6264 }
6265 }
037e8744 6266 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6267 &optype)) != FAIL)
6268 {
6269 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6270 Case 1: VMOV<c><q> <Dd>, <Dm>
6271 Case 8: VMOV.F32 <Sd>, <Sm>
6272 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6273
6274 inst.operands[i].reg = val;
6275 inst.operands[i].isreg = 1;
6276 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6277 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6278 inst.operands[i].isvec = 1;
6279 inst.operands[i].vectype = optype;
6280 inst.operands[i].present = 1;
6281
6282 if (skip_past_comma (&ptr) == SUCCESS)
6283 {
6284 /* Case 15. */
6285 i++;
6286
6287 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6288 goto wanted_arm;
6289
6290 inst.operands[i].reg = val;
6291 inst.operands[i].isreg = 1;
6292 inst.operands[i++].present = 1;
6293
6294 if (skip_past_comma (&ptr) == FAIL)
6295 goto wanted_comma;
6296
6297 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6298 goto wanted_arm;
6299
6300 inst.operands[i].reg = val;
6301 inst.operands[i].isreg = 1;
6302 inst.operands[i].present = 1;
6303 }
6304 }
4641781c 6305 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6306 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6307 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6308 Case 10: VMOV.F32 <Sd>, #<imm>
6309 Case 11: VMOV.F64 <Dd>, #<imm> */
6310 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6311 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6312 == SUCCESS)
477330fc
RM
6313 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6314 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6315 ;
5287ad62 6316 else
477330fc
RM
6317 {
6318 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6319 return FAIL;
6320 }
5287ad62 6321 }
dcbf9037 6322 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6323 {
6324 /* Cases 6, 7. */
6325 inst.operands[i].reg = val;
6326 inst.operands[i].isreg = 1;
6327 inst.operands[i++].present = 1;
5f4273c7 6328
5287ad62 6329 if (skip_past_comma (&ptr) == FAIL)
477330fc 6330 goto wanted_comma;
5f4273c7 6331
dcbf9037 6332 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6333 {
6334 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6335 inst.operands[i].reg = val;
6336 inst.operands[i].isscalar = 1;
6337 inst.operands[i].present = 1;
6338 inst.operands[i].vectype = optype;
6339 }
dcbf9037 6340 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6341 {
6342 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6343 inst.operands[i].reg = val;
6344 inst.operands[i].isreg = 1;
6345 inst.operands[i++].present = 1;
6346
6347 if (skip_past_comma (&ptr) == FAIL)
6348 goto wanted_comma;
6349
6350 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6351 == FAIL)
6352 {
6353 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6354 return FAIL;
6355 }
6356
6357 inst.operands[i].reg = val;
6358 inst.operands[i].isreg = 1;
6359 inst.operands[i].isvec = 1;
6360 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6361 inst.operands[i].vectype = optype;
6362 inst.operands[i].present = 1;
6363
6364 if (rtype == REG_TYPE_VFS)
6365 {
6366 /* Case 14. */
6367 i++;
6368 if (skip_past_comma (&ptr) == FAIL)
6369 goto wanted_comma;
6370 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6371 &optype)) == FAIL)
6372 {
6373 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6374 return FAIL;
6375 }
6376 inst.operands[i].reg = val;
6377 inst.operands[i].isreg = 1;
6378 inst.operands[i].isvec = 1;
6379 inst.operands[i].issingle = 1;
6380 inst.operands[i].vectype = optype;
6381 inst.operands[i].present = 1;
6382 }
6383 }
037e8744 6384 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6385 != FAIL)
6386 {
6387 /* Case 13. */
6388 inst.operands[i].reg = val;
6389 inst.operands[i].isreg = 1;
6390 inst.operands[i].isvec = 1;
6391 inst.operands[i].issingle = 1;
6392 inst.operands[i].vectype = optype;
6393 inst.operands[i].present = 1;
6394 }
5287ad62
JB
6395 }
6396 else
6397 {
dcbf9037 6398 first_error (_("parse error"));
5287ad62
JB
6399 return FAIL;
6400 }
6401
6402 /* Successfully parsed the operands. Update args. */
6403 *which_operand = i;
6404 *str = ptr;
6405 return SUCCESS;
6406
5f4273c7 6407 wanted_comma:
dcbf9037 6408 first_error (_("expected comma"));
5287ad62 6409 return FAIL;
5f4273c7
NC
6410
6411 wanted_arm:
dcbf9037 6412 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6413 return FAIL;
5287ad62
JB
6414}
6415
5be8be5d
DG
6416/* Use this macro when the operand constraints are different
6417 for ARM and THUMB (e.g. ldrd). */
6418#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6419 ((arm_operand) | ((thumb_operand) << 16))
6420
c19d1205
ZW
6421/* Matcher codes for parse_operands. */
6422enum operand_parse_code
6423{
6424 OP_stop, /* end of line */
6425
6426 OP_RR, /* ARM register */
6427 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6428 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6429 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6430 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6431 optional trailing ! */
c19d1205
ZW
6432 OP_RRw, /* ARM register, not r15, optional trailing ! */
6433 OP_RCP, /* Coprocessor number */
6434 OP_RCN, /* Coprocessor register */
6435 OP_RF, /* FPA register */
6436 OP_RVS, /* VFP single precision register */
5287ad62
JB
6437 OP_RVD, /* VFP double precision register (0..15) */
6438 OP_RND, /* Neon double precision register (0..31) */
6439 OP_RNQ, /* Neon quad precision register */
037e8744 6440 OP_RVSD, /* VFP single or double precision register */
5287ad62 6441 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6442 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6443 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6444 OP_RVC, /* VFP control register */
6445 OP_RMF, /* Maverick F register */
6446 OP_RMD, /* Maverick D register */
6447 OP_RMFX, /* Maverick FX register */
6448 OP_RMDX, /* Maverick DX register */
6449 OP_RMAX, /* Maverick AX register */
6450 OP_RMDS, /* Maverick DSPSC register */
6451 OP_RIWR, /* iWMMXt wR register */
6452 OP_RIWC, /* iWMMXt wC register */
6453 OP_RIWG, /* iWMMXt wCG register */
6454 OP_RXA, /* XScale accumulator register */
6455
6456 OP_REGLST, /* ARM register list */
6457 OP_VRSLST, /* VFP single-precision register list */
6458 OP_VRDLST, /* VFP double-precision register list */
037e8744 6459 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6460 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6461 OP_NSTRLST, /* Neon element/structure list */
6462
5287ad62 6463 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6464 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6465 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6466 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6467 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6468 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6469 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6470 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6471 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6472 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6473 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6474
6475 OP_I0, /* immediate zero */
c19d1205
ZW
6476 OP_I7, /* immediate value 0 .. 7 */
6477 OP_I15, /* 0 .. 15 */
6478 OP_I16, /* 1 .. 16 */
5287ad62 6479 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6480 OP_I31, /* 0 .. 31 */
6481 OP_I31w, /* 0 .. 31, optional trailing ! */
6482 OP_I32, /* 1 .. 32 */
5287ad62
JB
6483 OP_I32z, /* 0 .. 32 */
6484 OP_I63, /* 0 .. 63 */
c19d1205 6485 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6486 OP_I64, /* 1 .. 64 */
6487 OP_I64z, /* 0 .. 64 */
c19d1205 6488 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6489
6490 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6491 OP_I7b, /* 0 .. 7 */
6492 OP_I15b, /* 0 .. 15 */
6493 OP_I31b, /* 0 .. 31 */
6494
6495 OP_SH, /* shifter operand */
4962c51a 6496 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6497 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6498 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6499 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6500 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6501 OP_EXP, /* arbitrary expression */
6502 OP_EXPi, /* same, with optional immediate prefix */
6503 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6504 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6505
6506 OP_CPSF, /* CPS flags */
6507 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6508 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6509 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6510 OP_COND, /* conditional code */
92e90b6e 6511 OP_TB, /* Table branch. */
c19d1205 6512
037e8744
JB
6513 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6514
c19d1205
ZW
6515 OP_RRnpc_I0, /* ARM register or literal 0 */
6516 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6517 OP_RR_EXi, /* ARM register or expression with imm prefix */
6518 OP_RF_IF, /* FPA register or immediate */
6519 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6520 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6521
6522 /* Optional operands. */
6523 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6524 OP_oI31b, /* 0 .. 31 */
5287ad62 6525 OP_oI32b, /* 1 .. 32 */
5f1af56b 6526 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6527 OP_oIffffb, /* 0 .. 65535 */
6528 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6529
6530 OP_oRR, /* ARM register */
6531 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6532 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6533 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6534 OP_oRND, /* Optional Neon double precision register */
6535 OP_oRNQ, /* Optional Neon quad precision register */
6536 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6537 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6538 OP_oSHll, /* LSL immediate */
6539 OP_oSHar, /* ASR immediate */
6540 OP_oSHllar, /* LSL or ASR immediate */
6541 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6542 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6543
5be8be5d
DG
6544 /* Some pre-defined mixed (ARM/THUMB) operands. */
6545 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6546 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6547 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6548
c19d1205
ZW
6549 OP_FIRST_OPTIONAL = OP_oI7b
6550};
a737bd4d 6551
c19d1205
ZW
6552/* Generic instruction operand parser. This does no encoding and no
6553 semantic validation; it merely squirrels values away in the inst
6554 structure. Returns SUCCESS or FAIL depending on whether the
6555 specified grammar matched. */
6556static int
5be8be5d 6557parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6558{
5be8be5d 6559 unsigned const int *upat = pattern;
c19d1205
ZW
6560 char *backtrack_pos = 0;
6561 const char *backtrack_error = 0;
99aad254 6562 int i, val = 0, backtrack_index = 0;
5287ad62 6563 enum arm_reg_type rtype;
4962c51a 6564 parse_operand_result result;
5be8be5d 6565 unsigned int op_parse_code;
c19d1205 6566
e07e6e58
NC
6567#define po_char_or_fail(chr) \
6568 do \
6569 { \
6570 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6571 goto bad_args; \
e07e6e58
NC
6572 } \
6573 while (0)
c19d1205 6574
e07e6e58
NC
6575#define po_reg_or_fail(regtype) \
6576 do \
dcbf9037 6577 { \
e07e6e58 6578 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6579 & inst.operands[i].vectype); \
e07e6e58 6580 if (val == FAIL) \
477330fc
RM
6581 { \
6582 first_error (_(reg_expected_msgs[regtype])); \
6583 goto failure; \
6584 } \
e07e6e58
NC
6585 inst.operands[i].reg = val; \
6586 inst.operands[i].isreg = 1; \
6587 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6588 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6589 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6590 || rtype == REG_TYPE_VFD \
6591 || rtype == REG_TYPE_NQ); \
dcbf9037 6592 } \
e07e6e58
NC
6593 while (0)
6594
6595#define po_reg_or_goto(regtype, label) \
6596 do \
6597 { \
6598 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6599 & inst.operands[i].vectype); \
6600 if (val == FAIL) \
6601 goto label; \
dcbf9037 6602 \
e07e6e58
NC
6603 inst.operands[i].reg = val; \
6604 inst.operands[i].isreg = 1; \
6605 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6606 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6607 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6608 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6609 || rtype == REG_TYPE_NQ); \
6610 } \
6611 while (0)
6612
6613#define po_imm_or_fail(min, max, popt) \
6614 do \
6615 { \
6616 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6617 goto failure; \
6618 inst.operands[i].imm = val; \
6619 } \
6620 while (0)
6621
6622#define po_scalar_or_goto(elsz, label) \
6623 do \
6624 { \
6625 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6626 if (val == FAIL) \
6627 goto label; \
6628 inst.operands[i].reg = val; \
6629 inst.operands[i].isscalar = 1; \
6630 } \
6631 while (0)
6632
6633#define po_misc_or_fail(expr) \
6634 do \
6635 { \
6636 if (expr) \
6637 goto failure; \
6638 } \
6639 while (0)
6640
6641#define po_misc_or_fail_no_backtrack(expr) \
6642 do \
6643 { \
6644 result = expr; \
6645 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6646 backtrack_pos = 0; \
6647 if (result != PARSE_OPERAND_SUCCESS) \
6648 goto failure; \
6649 } \
6650 while (0)
4962c51a 6651
52e7f43d
RE
6652#define po_barrier_or_imm(str) \
6653 do \
6654 { \
6655 val = parse_barrier (&str); \
ccb84d65
JB
6656 if (val == FAIL && ! ISALPHA (*str)) \
6657 goto immediate; \
6658 if (val == FAIL \
6659 /* ISB can only take SY as an option. */ \
6660 || ((inst.instruction & 0xf0) == 0x60 \
6661 && val != 0xf)) \
52e7f43d 6662 { \
ccb84d65
JB
6663 inst.error = _("invalid barrier type"); \
6664 backtrack_pos = 0; \
6665 goto failure; \
52e7f43d
RE
6666 } \
6667 } \
6668 while (0)
6669
c19d1205
ZW
6670 skip_whitespace (str);
6671
6672 for (i = 0; upat[i] != OP_stop; i++)
6673 {
5be8be5d
DG
6674 op_parse_code = upat[i];
6675 if (op_parse_code >= 1<<16)
6676 op_parse_code = thumb ? (op_parse_code >> 16)
6677 : (op_parse_code & ((1<<16)-1));
6678
6679 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6680 {
6681 /* Remember where we are in case we need to backtrack. */
9c2799c2 6682 gas_assert (!backtrack_pos);
c19d1205
ZW
6683 backtrack_pos = str;
6684 backtrack_error = inst.error;
6685 backtrack_index = i;
6686 }
6687
b6702015 6688 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6689 po_char_or_fail (',');
6690
5be8be5d 6691 switch (op_parse_code)
c19d1205
ZW
6692 {
6693 /* Registers */
6694 case OP_oRRnpc:
5be8be5d 6695 case OP_oRRnpcsp:
c19d1205 6696 case OP_RRnpc:
5be8be5d 6697 case OP_RRnpcsp:
c19d1205
ZW
6698 case OP_oRR:
6699 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6700 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6701 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6702 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6703 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6704 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6705 case OP_oRND:
5287ad62 6706 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6707 case OP_RVC:
6708 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6709 break;
6710 /* Also accept generic coprocessor regs for unknown registers. */
6711 coproc_reg:
6712 po_reg_or_fail (REG_TYPE_CN);
6713 break;
c19d1205
ZW
6714 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6715 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6716 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6717 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6718 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6719 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6720 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6721 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6722 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6723 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6724 case OP_oRNQ:
5287ad62 6725 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6726 case OP_oRNDQ:
5287ad62 6727 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6728 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6729 case OP_oRNSDQ:
6730 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6731
6732 /* Neon scalar. Using an element size of 8 means that some invalid
6733 scalars are accepted here, so deal with those in later code. */
6734 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6735
6736 case OP_RNDQ_I0:
6737 {
6738 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6739 break;
6740 try_imm0:
6741 po_imm_or_fail (0, 0, TRUE);
6742 }
6743 break;
6744
6745 case OP_RVSD_I0:
6746 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6747 break;
6748
aacf0b33
KT
6749 case OP_RSVD_FI0:
6750 {
6751 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6752 break;
6753 try_ifimm0:
6754 if (parse_ifimm_zero (&str))
6755 inst.operands[i].imm = 0;
6756 else
6757 {
6758 inst.error
6759 = _("only floating point zero is allowed as immediate value");
6760 goto failure;
6761 }
6762 }
6763 break;
6764
477330fc
RM
6765 case OP_RR_RNSC:
6766 {
6767 po_scalar_or_goto (8, try_rr);
6768 break;
6769 try_rr:
6770 po_reg_or_fail (REG_TYPE_RN);
6771 }
6772 break;
6773
6774 case OP_RNSDQ_RNSC:
6775 {
6776 po_scalar_or_goto (8, try_nsdq);
6777 break;
6778 try_nsdq:
6779 po_reg_or_fail (REG_TYPE_NSDQ);
6780 }
6781 break;
6782
6783 case OP_RNDQ_RNSC:
6784 {
6785 po_scalar_or_goto (8, try_ndq);
6786 break;
6787 try_ndq:
6788 po_reg_or_fail (REG_TYPE_NDQ);
6789 }
6790 break;
6791
6792 case OP_RND_RNSC:
6793 {
6794 po_scalar_or_goto (8, try_vfd);
6795 break;
6796 try_vfd:
6797 po_reg_or_fail (REG_TYPE_VFD);
6798 }
6799 break;
6800
6801 case OP_VMOV:
6802 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6803 not careful then bad things might happen. */
6804 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6805 break;
6806
6807 case OP_RNDQ_Ibig:
6808 {
6809 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6810 break;
6811 try_immbig:
6812 /* There's a possibility of getting a 64-bit immediate here, so
6813 we need special handling. */
8335d6aa
JW
6814 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6815 == FAIL)
477330fc
RM
6816 {
6817 inst.error = _("immediate value is out of range");
6818 goto failure;
6819 }
6820 }
6821 break;
6822
6823 case OP_RNDQ_I63b:
6824 {
6825 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6826 break;
6827 try_shimm:
6828 po_imm_or_fail (0, 63, TRUE);
6829 }
6830 break;
c19d1205
ZW
6831
6832 case OP_RRnpcb:
6833 po_char_or_fail ('[');
6834 po_reg_or_fail (REG_TYPE_RN);
6835 po_char_or_fail (']');
6836 break;
a737bd4d 6837
55881a11 6838 case OP_RRnpctw:
c19d1205 6839 case OP_RRw:
b6702015 6840 case OP_oRRw:
c19d1205
ZW
6841 po_reg_or_fail (REG_TYPE_RN);
6842 if (skip_past_char (&str, '!') == SUCCESS)
6843 inst.operands[i].writeback = 1;
6844 break;
6845
6846 /* Immediates */
6847 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6848 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6849 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6850 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6851 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6852 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6853 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6854 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6855 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6856 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6857 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6858 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6859
6860 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6861 case OP_oI7b:
6862 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6863 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6864 case OP_oI31b:
6865 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6866 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6867 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6868 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6869
6870 /* Immediate variants */
6871 case OP_oI255c:
6872 po_char_or_fail ('{');
6873 po_imm_or_fail (0, 255, TRUE);
6874 po_char_or_fail ('}');
6875 break;
6876
6877 case OP_I31w:
6878 /* The expression parser chokes on a trailing !, so we have
6879 to find it first and zap it. */
6880 {
6881 char *s = str;
6882 while (*s && *s != ',')
6883 s++;
6884 if (s[-1] == '!')
6885 {
6886 s[-1] = '\0';
6887 inst.operands[i].writeback = 1;
6888 }
6889 po_imm_or_fail (0, 31, TRUE);
6890 if (str == s - 1)
6891 str = s;
6892 }
6893 break;
6894
6895 /* Expressions */
6896 case OP_EXPi: EXPi:
6897 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6898 GE_OPT_PREFIX));
6899 break;
6900
6901 case OP_EXP:
6902 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6903 GE_NO_PREFIX));
6904 break;
6905
6906 case OP_EXPr: EXPr:
6907 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6908 GE_NO_PREFIX));
6909 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6910 {
c19d1205
ZW
6911 val = parse_reloc (&str);
6912 if (val == -1)
6913 {
6914 inst.error = _("unrecognized relocation suffix");
6915 goto failure;
6916 }
6917 else if (val != BFD_RELOC_UNUSED)
6918 {
6919 inst.operands[i].imm = val;
6920 inst.operands[i].hasreloc = 1;
6921 }
a737bd4d 6922 }
c19d1205 6923 break;
a737bd4d 6924
b6895b4f
PB
6925 /* Operand for MOVW or MOVT. */
6926 case OP_HALF:
6927 po_misc_or_fail (parse_half (&str));
6928 break;
6929
e07e6e58 6930 /* Register or expression. */
c19d1205
ZW
6931 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6932 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6933
e07e6e58 6934 /* Register or immediate. */
c19d1205
ZW
6935 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6936 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6937
c19d1205
ZW
6938 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6939 IF:
6940 if (!is_immediate_prefix (*str))
6941 goto bad_args;
6942 str++;
6943 val = parse_fpa_immediate (&str);
6944 if (val == FAIL)
6945 goto failure;
6946 /* FPA immediates are encoded as registers 8-15.
6947 parse_fpa_immediate has already applied the offset. */
6948 inst.operands[i].reg = val;
6949 inst.operands[i].isreg = 1;
6950 break;
09d92015 6951
2d447fca
JM
6952 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6953 I32z: po_imm_or_fail (0, 32, FALSE); break;
6954
e07e6e58 6955 /* Two kinds of register. */
c19d1205
ZW
6956 case OP_RIWR_RIWC:
6957 {
6958 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6959 if (!rege
6960 || (rege->type != REG_TYPE_MMXWR
6961 && rege->type != REG_TYPE_MMXWC
6962 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6963 {
6964 inst.error = _("iWMMXt data or control register expected");
6965 goto failure;
6966 }
6967 inst.operands[i].reg = rege->number;
6968 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6969 }
6970 break;
09d92015 6971
41adaa5c
JM
6972 case OP_RIWC_RIWG:
6973 {
6974 struct reg_entry *rege = arm_reg_parse_multi (&str);
6975 if (!rege
6976 || (rege->type != REG_TYPE_MMXWC
6977 && rege->type != REG_TYPE_MMXWCG))
6978 {
6979 inst.error = _("iWMMXt control register expected");
6980 goto failure;
6981 }
6982 inst.operands[i].reg = rege->number;
6983 inst.operands[i].isreg = 1;
6984 }
6985 break;
6986
c19d1205
ZW
6987 /* Misc */
6988 case OP_CPSF: val = parse_cps_flags (&str); break;
6989 case OP_ENDI: val = parse_endian_specifier (&str); break;
6990 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6991 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6992 case OP_oBARRIER_I15:
6993 po_barrier_or_imm (str); break;
6994 immediate:
6995 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 6996 goto failure;
52e7f43d 6997 break;
c19d1205 6998
fa94de6b 6999 case OP_wPSR:
d2cd1205 7000 case OP_rPSR:
90ec0d68
MGD
7001 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7002 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7003 {
7004 inst.error = _("Banked registers are not available with this "
7005 "architecture.");
7006 goto failure;
7007 }
7008 break;
d2cd1205
JB
7009 try_psr:
7010 val = parse_psr (&str, op_parse_code == OP_wPSR);
7011 break;
037e8744 7012
477330fc
RM
7013 case OP_APSR_RR:
7014 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7015 break;
7016 try_apsr:
7017 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7018 instruction). */
7019 if (strncasecmp (str, "APSR_", 5) == 0)
7020 {
7021 unsigned found = 0;
7022 str += 5;
7023 while (found < 15)
7024 switch (*str++)
7025 {
7026 case 'c': found = (found & 1) ? 16 : found | 1; break;
7027 case 'n': found = (found & 2) ? 16 : found | 2; break;
7028 case 'z': found = (found & 4) ? 16 : found | 4; break;
7029 case 'v': found = (found & 8) ? 16 : found | 8; break;
7030 default: found = 16;
7031 }
7032 if (found != 15)
7033 goto failure;
7034 inst.operands[i].isvec = 1;
f7c21dc7
NC
7035 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7036 inst.operands[i].reg = REG_PC;
477330fc
RM
7037 }
7038 else
7039 goto failure;
7040 break;
037e8744 7041
92e90b6e
PB
7042 case OP_TB:
7043 po_misc_or_fail (parse_tb (&str));
7044 break;
7045
e07e6e58 7046 /* Register lists. */
c19d1205
ZW
7047 case OP_REGLST:
7048 val = parse_reg_list (&str);
7049 if (*str == '^')
7050 {
5e0d7f77 7051 inst.operands[i].writeback = 1;
c19d1205
ZW
7052 str++;
7053 }
7054 break;
09d92015 7055
c19d1205 7056 case OP_VRSLST:
5287ad62 7057 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7058 break;
09d92015 7059
c19d1205 7060 case OP_VRDLST:
5287ad62 7061 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7062 break;
a737bd4d 7063
477330fc
RM
7064 case OP_VRSDLST:
7065 /* Allow Q registers too. */
7066 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7067 REGLIST_NEON_D);
7068 if (val == FAIL)
7069 {
7070 inst.error = NULL;
7071 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7072 REGLIST_VFP_S);
7073 inst.operands[i].issingle = 1;
7074 }
7075 break;
7076
7077 case OP_NRDLST:
7078 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7079 REGLIST_NEON_D);
7080 break;
5287ad62
JB
7081
7082 case OP_NSTRLST:
477330fc
RM
7083 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7084 &inst.operands[i].vectype);
7085 break;
5287ad62 7086
c19d1205
ZW
7087 /* Addressing modes */
7088 case OP_ADDR:
7089 po_misc_or_fail (parse_address (&str, i));
7090 break;
09d92015 7091
4962c51a
MS
7092 case OP_ADDRGLDR:
7093 po_misc_or_fail_no_backtrack (
477330fc 7094 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7095 break;
7096
7097 case OP_ADDRGLDRS:
7098 po_misc_or_fail_no_backtrack (
477330fc 7099 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7100 break;
7101
7102 case OP_ADDRGLDC:
7103 po_misc_or_fail_no_backtrack (
477330fc 7104 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7105 break;
7106
c19d1205
ZW
7107 case OP_SH:
7108 po_misc_or_fail (parse_shifter_operand (&str, i));
7109 break;
09d92015 7110
4962c51a
MS
7111 case OP_SHG:
7112 po_misc_or_fail_no_backtrack (
477330fc 7113 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7114 break;
7115
c19d1205
ZW
7116 case OP_oSHll:
7117 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7118 break;
09d92015 7119
c19d1205
ZW
7120 case OP_oSHar:
7121 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7122 break;
09d92015 7123
c19d1205
ZW
7124 case OP_oSHllar:
7125 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7126 break;
09d92015 7127
c19d1205 7128 default:
5be8be5d 7129 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7130 }
09d92015 7131
c19d1205
ZW
7132 /* Various value-based sanity checks and shared operations. We
7133 do not signal immediate failures for the register constraints;
7134 this allows a syntax error to take precedence. */
5be8be5d 7135 switch (op_parse_code)
c19d1205
ZW
7136 {
7137 case OP_oRRnpc:
7138 case OP_RRnpc:
7139 case OP_RRnpcb:
7140 case OP_RRw:
b6702015 7141 case OP_oRRw:
c19d1205
ZW
7142 case OP_RRnpc_I0:
7143 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7144 inst.error = BAD_PC;
7145 break;
09d92015 7146
5be8be5d
DG
7147 case OP_oRRnpcsp:
7148 case OP_RRnpcsp:
7149 if (inst.operands[i].isreg)
7150 {
7151 if (inst.operands[i].reg == REG_PC)
7152 inst.error = BAD_PC;
7153 else if (inst.operands[i].reg == REG_SP)
7154 inst.error = BAD_SP;
7155 }
7156 break;
7157
55881a11 7158 case OP_RRnpctw:
fa94de6b
RM
7159 if (inst.operands[i].isreg
7160 && inst.operands[i].reg == REG_PC
55881a11
MGD
7161 && (inst.operands[i].writeback || thumb))
7162 inst.error = BAD_PC;
7163 break;
7164
c19d1205
ZW
7165 case OP_CPSF:
7166 case OP_ENDI:
7167 case OP_oROR:
d2cd1205
JB
7168 case OP_wPSR:
7169 case OP_rPSR:
c19d1205 7170 case OP_COND:
52e7f43d 7171 case OP_oBARRIER_I15:
c19d1205
ZW
7172 case OP_REGLST:
7173 case OP_VRSLST:
7174 case OP_VRDLST:
477330fc
RM
7175 case OP_VRSDLST:
7176 case OP_NRDLST:
7177 case OP_NSTRLST:
c19d1205
ZW
7178 if (val == FAIL)
7179 goto failure;
7180 inst.operands[i].imm = val;
7181 break;
a737bd4d 7182
c19d1205
ZW
7183 default:
7184 break;
7185 }
09d92015 7186
c19d1205
ZW
7187 /* If we get here, this operand was successfully parsed. */
7188 inst.operands[i].present = 1;
7189 continue;
09d92015 7190
c19d1205 7191 bad_args:
09d92015 7192 inst.error = BAD_ARGS;
c19d1205
ZW
7193
7194 failure:
7195 if (!backtrack_pos)
d252fdde
PB
7196 {
7197 /* The parse routine should already have set inst.error, but set a
5f4273c7 7198 default here just in case. */
d252fdde
PB
7199 if (!inst.error)
7200 inst.error = _("syntax error");
7201 return FAIL;
7202 }
c19d1205
ZW
7203
7204 /* Do not backtrack over a trailing optional argument that
7205 absorbed some text. We will only fail again, with the
7206 'garbage following instruction' error message, which is
7207 probably less helpful than the current one. */
7208 if (backtrack_index == i && backtrack_pos != str
7209 && upat[i+1] == OP_stop)
d252fdde
PB
7210 {
7211 if (!inst.error)
7212 inst.error = _("syntax error");
7213 return FAIL;
7214 }
c19d1205
ZW
7215
7216 /* Try again, skipping the optional argument at backtrack_pos. */
7217 str = backtrack_pos;
7218 inst.error = backtrack_error;
7219 inst.operands[backtrack_index].present = 0;
7220 i = backtrack_index;
7221 backtrack_pos = 0;
09d92015 7222 }
09d92015 7223
c19d1205
ZW
7224 /* Check that we have parsed all the arguments. */
7225 if (*str != '\0' && !inst.error)
7226 inst.error = _("garbage following instruction");
09d92015 7227
c19d1205 7228 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7229}
7230
c19d1205
ZW
7231#undef po_char_or_fail
7232#undef po_reg_or_fail
7233#undef po_reg_or_goto
7234#undef po_imm_or_fail
5287ad62 7235#undef po_scalar_or_fail
52e7f43d 7236#undef po_barrier_or_imm
e07e6e58 7237
c19d1205 7238/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7239#define constraint(expr, err) \
7240 do \
c19d1205 7241 { \
e07e6e58
NC
7242 if (expr) \
7243 { \
7244 inst.error = err; \
7245 return; \
7246 } \
c19d1205 7247 } \
e07e6e58 7248 while (0)
c19d1205 7249
fdfde340
JM
7250/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7251 instructions are unpredictable if these registers are used. This
7252 is the BadReg predicate in ARM's Thumb-2 documentation. */
7253#define reject_bad_reg(reg) \
7254 do \
7255 if (reg == REG_SP || reg == REG_PC) \
7256 { \
7257 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7258 return; \
7259 } \
7260 while (0)
7261
94206790
MM
7262/* If REG is R13 (the stack pointer), warn that its use is
7263 deprecated. */
7264#define warn_deprecated_sp(reg) \
7265 do \
7266 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7267 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7268 while (0)
7269
c19d1205
ZW
7270/* Functions for operand encoding. ARM, then Thumb. */
7271
d840c081 7272#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7273
9db2f6b4
RL
7274/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7275
7276 The only binary encoding difference is the Coprocessor number. Coprocessor
7277 9 is used for half-precision calculations or conversions. The format of the
7278 instruction is the same as the equivalent Coprocessor 10 instuction that
7279 exists for Single-Precision operation. */
7280
7281static void
7282do_scalar_fp16_v82_encode (void)
7283{
7284 if (inst.cond != COND_ALWAYS)
7285 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7286 " the behaviour is UNPREDICTABLE"));
7287 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7288 _(BAD_FP16));
7289
7290 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7291 mark_feature_used (&arm_ext_fp16);
7292}
7293
c19d1205
ZW
7294/* If VAL can be encoded in the immediate field of an ARM instruction,
7295 return the encoded form. Otherwise, return FAIL. */
7296
7297static unsigned int
7298encode_arm_immediate (unsigned int val)
09d92015 7299{
c19d1205
ZW
7300 unsigned int a, i;
7301
4f1d6205
L
7302 if (val <= 0xff)
7303 return val;
7304
7305 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7306 if ((a = rotate_left (val, i)) <= 0xff)
7307 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7308
7309 return FAIL;
09d92015
MM
7310}
7311
c19d1205
ZW
7312/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7313 return the encoded form. Otherwise, return FAIL. */
7314static unsigned int
7315encode_thumb32_immediate (unsigned int val)
09d92015 7316{
c19d1205 7317 unsigned int a, i;
09d92015 7318
9c3c69f2 7319 if (val <= 0xff)
c19d1205 7320 return val;
a737bd4d 7321
9c3c69f2 7322 for (i = 1; i <= 24; i++)
09d92015 7323 {
9c3c69f2
PB
7324 a = val >> i;
7325 if ((val & ~(0xff << i)) == 0)
7326 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7327 }
a737bd4d 7328
c19d1205
ZW
7329 a = val & 0xff;
7330 if (val == ((a << 16) | a))
7331 return 0x100 | a;
7332 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7333 return 0x300 | a;
09d92015 7334
c19d1205
ZW
7335 a = val & 0xff00;
7336 if (val == ((a << 16) | a))
7337 return 0x200 | (a >> 8);
a737bd4d 7338
c19d1205 7339 return FAIL;
09d92015 7340}
5287ad62 7341/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7342
7343static void
5287ad62
JB
7344encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7345{
7346 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7347 && reg > 15)
7348 {
b1cc4aeb 7349 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7350 {
7351 if (thumb_mode)
7352 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7353 fpu_vfp_ext_d32);
7354 else
7355 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7356 fpu_vfp_ext_d32);
7357 }
5287ad62 7358 else
477330fc
RM
7359 {
7360 first_error (_("D register out of range for selected VFP version"));
7361 return;
7362 }
5287ad62
JB
7363 }
7364
c19d1205 7365 switch (pos)
09d92015 7366 {
c19d1205
ZW
7367 case VFP_REG_Sd:
7368 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7369 break;
7370
7371 case VFP_REG_Sn:
7372 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7373 break;
7374
7375 case VFP_REG_Sm:
7376 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7377 break;
7378
5287ad62
JB
7379 case VFP_REG_Dd:
7380 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7381 break;
5f4273c7 7382
5287ad62
JB
7383 case VFP_REG_Dn:
7384 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7385 break;
5f4273c7 7386
5287ad62
JB
7387 case VFP_REG_Dm:
7388 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7389 break;
7390
c19d1205
ZW
7391 default:
7392 abort ();
09d92015 7393 }
09d92015
MM
7394}
7395
c19d1205 7396/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7397 if any, is handled by md_apply_fix. */
09d92015 7398static void
c19d1205 7399encode_arm_shift (int i)
09d92015 7400{
c19d1205
ZW
7401 if (inst.operands[i].shift_kind == SHIFT_RRX)
7402 inst.instruction |= SHIFT_ROR << 5;
7403 else
09d92015 7404 {
c19d1205
ZW
7405 inst.instruction |= inst.operands[i].shift_kind << 5;
7406 if (inst.operands[i].immisreg)
7407 {
7408 inst.instruction |= SHIFT_BY_REG;
7409 inst.instruction |= inst.operands[i].imm << 8;
7410 }
7411 else
7412 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7413 }
c19d1205 7414}
09d92015 7415
c19d1205
ZW
7416static void
7417encode_arm_shifter_operand (int i)
7418{
7419 if (inst.operands[i].isreg)
09d92015 7420 {
c19d1205
ZW
7421 inst.instruction |= inst.operands[i].reg;
7422 encode_arm_shift (i);
09d92015 7423 }
c19d1205 7424 else
a415b1cd
JB
7425 {
7426 inst.instruction |= INST_IMMEDIATE;
7427 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7428 inst.instruction |= inst.operands[i].imm;
7429 }
09d92015
MM
7430}
7431
c19d1205 7432/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7433static void
c19d1205 7434encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7435{
2b2f5df9
NC
7436 /* PR 14260:
7437 Generate an error if the operand is not a register. */
7438 constraint (!inst.operands[i].isreg,
7439 _("Instruction does not support =N addresses"));
7440
c19d1205 7441 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7442
c19d1205 7443 if (inst.operands[i].preind)
09d92015 7444 {
c19d1205
ZW
7445 if (is_t)
7446 {
7447 inst.error = _("instruction does not accept preindexed addressing");
7448 return;
7449 }
7450 inst.instruction |= PRE_INDEX;
7451 if (inst.operands[i].writeback)
7452 inst.instruction |= WRITE_BACK;
09d92015 7453
c19d1205
ZW
7454 }
7455 else if (inst.operands[i].postind)
7456 {
9c2799c2 7457 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7458 if (is_t)
7459 inst.instruction |= WRITE_BACK;
7460 }
7461 else /* unindexed - only for coprocessor */
09d92015 7462 {
c19d1205 7463 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7464 return;
7465 }
7466
c19d1205
ZW
7467 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7468 && (((inst.instruction & 0x000f0000) >> 16)
7469 == ((inst.instruction & 0x0000f000) >> 12)))
7470 as_warn ((inst.instruction & LOAD_BIT)
7471 ? _("destination register same as write-back base")
7472 : _("source register same as write-back base"));
09d92015
MM
7473}
7474
c19d1205
ZW
7475/* inst.operands[i] was set up by parse_address. Encode it into an
7476 ARM-format mode 2 load or store instruction. If is_t is true,
7477 reject forms that cannot be used with a T instruction (i.e. not
7478 post-indexed). */
a737bd4d 7479static void
c19d1205 7480encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7481{
5be8be5d
DG
7482 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7483
c19d1205 7484 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7485
c19d1205 7486 if (inst.operands[i].immisreg)
09d92015 7487 {
5be8be5d
DG
7488 constraint ((inst.operands[i].imm == REG_PC
7489 || (is_pc && inst.operands[i].writeback)),
7490 BAD_PC_ADDRESSING);
c19d1205
ZW
7491 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7492 inst.instruction |= inst.operands[i].imm;
7493 if (!inst.operands[i].negative)
7494 inst.instruction |= INDEX_UP;
7495 if (inst.operands[i].shifted)
7496 {
7497 if (inst.operands[i].shift_kind == SHIFT_RRX)
7498 inst.instruction |= SHIFT_ROR << 5;
7499 else
7500 {
7501 inst.instruction |= inst.operands[i].shift_kind << 5;
7502 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7503 }
7504 }
09d92015 7505 }
c19d1205 7506 else /* immediate offset in inst.reloc */
09d92015 7507 {
5be8be5d
DG
7508 if (is_pc && !inst.reloc.pc_rel)
7509 {
7510 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7511
7512 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7513 cannot use PC in addressing.
7514 PC cannot be used in writeback addressing, either. */
7515 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7516 BAD_PC_ADDRESSING);
23a10334 7517
dc5ec521 7518 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7519 if (warn_on_deprecated
7520 && !is_load
7521 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7522 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7523 }
7524
c19d1205 7525 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7526 {
7527 /* Prefer + for zero encoded value. */
7528 if (!inst.operands[i].negative)
7529 inst.instruction |= INDEX_UP;
7530 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7531 }
09d92015 7532 }
09d92015
MM
7533}
7534
c19d1205
ZW
7535/* inst.operands[i] was set up by parse_address. Encode it into an
7536 ARM-format mode 3 load or store instruction. Reject forms that
7537 cannot be used with such instructions. If is_t is true, reject
7538 forms that cannot be used with a T instruction (i.e. not
7539 post-indexed). */
7540static void
7541encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7542{
c19d1205 7543 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7544 {
c19d1205
ZW
7545 inst.error = _("instruction does not accept scaled register index");
7546 return;
09d92015 7547 }
a737bd4d 7548
c19d1205 7549 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7550
c19d1205
ZW
7551 if (inst.operands[i].immisreg)
7552 {
5be8be5d 7553 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7554 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7555 BAD_PC_ADDRESSING);
eb9f3f00
JB
7556 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7557 BAD_PC_WRITEBACK);
c19d1205
ZW
7558 inst.instruction |= inst.operands[i].imm;
7559 if (!inst.operands[i].negative)
7560 inst.instruction |= INDEX_UP;
7561 }
7562 else /* immediate offset in inst.reloc */
7563 {
5be8be5d
DG
7564 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7565 && inst.operands[i].writeback),
7566 BAD_PC_WRITEBACK);
c19d1205
ZW
7567 inst.instruction |= HWOFFSET_IMM;
7568 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7569 {
7570 /* Prefer + for zero encoded value. */
7571 if (!inst.operands[i].negative)
7572 inst.instruction |= INDEX_UP;
7573
7574 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7575 }
c19d1205 7576 }
a737bd4d
NC
7577}
7578
8335d6aa
JW
7579/* Write immediate bits [7:0] to the following locations:
7580
7581 |28/24|23 19|18 16|15 4|3 0|
7582 | 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|
7583
7584 This function is used by VMOV/VMVN/VORR/VBIC. */
7585
7586static void
7587neon_write_immbits (unsigned immbits)
7588{
7589 inst.instruction |= immbits & 0xf;
7590 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7591 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7592}
7593
7594/* Invert low-order SIZE bits of XHI:XLO. */
7595
7596static void
7597neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7598{
7599 unsigned immlo = xlo ? *xlo : 0;
7600 unsigned immhi = xhi ? *xhi : 0;
7601
7602 switch (size)
7603 {
7604 case 8:
7605 immlo = (~immlo) & 0xff;
7606 break;
7607
7608 case 16:
7609 immlo = (~immlo) & 0xffff;
7610 break;
7611
7612 case 64:
7613 immhi = (~immhi) & 0xffffffff;
7614 /* fall through. */
7615
7616 case 32:
7617 immlo = (~immlo) & 0xffffffff;
7618 break;
7619
7620 default:
7621 abort ();
7622 }
7623
7624 if (xlo)
7625 *xlo = immlo;
7626
7627 if (xhi)
7628 *xhi = immhi;
7629}
7630
7631/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7632 A, B, C, D. */
09d92015 7633
c19d1205 7634static int
8335d6aa 7635neon_bits_same_in_bytes (unsigned imm)
09d92015 7636{
8335d6aa
JW
7637 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7638 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7639 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7640 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7641}
a737bd4d 7642
8335d6aa 7643/* For immediate of above form, return 0bABCD. */
09d92015 7644
8335d6aa
JW
7645static unsigned
7646neon_squash_bits (unsigned imm)
7647{
7648 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7649 | ((imm & 0x01000000) >> 21);
7650}
7651
7652/* Compress quarter-float representation to 0b...000 abcdefgh. */
7653
7654static unsigned
7655neon_qfloat_bits (unsigned imm)
7656{
7657 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7658}
7659
7660/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7661 the instruction. *OP is passed as the initial value of the op field, and
7662 may be set to a different value depending on the constant (i.e.
7663 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7664 MVN). If the immediate looks like a repeated pattern then also
7665 try smaller element sizes. */
7666
7667static int
7668neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7669 unsigned *immbits, int *op, int size,
7670 enum neon_el_type type)
7671{
7672 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7673 float. */
7674 if (type == NT_float && !float_p)
7675 return FAIL;
7676
7677 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7678 {
8335d6aa
JW
7679 if (size != 32 || *op == 1)
7680 return FAIL;
7681 *immbits = neon_qfloat_bits (immlo);
7682 return 0xf;
7683 }
7684
7685 if (size == 64)
7686 {
7687 if (neon_bits_same_in_bytes (immhi)
7688 && neon_bits_same_in_bytes (immlo))
c19d1205 7689 {
8335d6aa
JW
7690 if (*op == 1)
7691 return FAIL;
7692 *immbits = (neon_squash_bits (immhi) << 4)
7693 | neon_squash_bits (immlo);
7694 *op = 1;
7695 return 0xe;
c19d1205 7696 }
a737bd4d 7697
8335d6aa
JW
7698 if (immhi != immlo)
7699 return FAIL;
7700 }
a737bd4d 7701
8335d6aa 7702 if (size >= 32)
09d92015 7703 {
8335d6aa 7704 if (immlo == (immlo & 0x000000ff))
c19d1205 7705 {
8335d6aa
JW
7706 *immbits = immlo;
7707 return 0x0;
c19d1205 7708 }
8335d6aa 7709 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7710 {
8335d6aa
JW
7711 *immbits = immlo >> 8;
7712 return 0x2;
c19d1205 7713 }
8335d6aa
JW
7714 else if (immlo == (immlo & 0x00ff0000))
7715 {
7716 *immbits = immlo >> 16;
7717 return 0x4;
7718 }
7719 else if (immlo == (immlo & 0xff000000))
7720 {
7721 *immbits = immlo >> 24;
7722 return 0x6;
7723 }
7724 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7725 {
7726 *immbits = (immlo >> 8) & 0xff;
7727 return 0xc;
7728 }
7729 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7730 {
7731 *immbits = (immlo >> 16) & 0xff;
7732 return 0xd;
7733 }
7734
7735 if ((immlo & 0xffff) != (immlo >> 16))
7736 return FAIL;
7737 immlo &= 0xffff;
09d92015 7738 }
a737bd4d 7739
8335d6aa 7740 if (size >= 16)
4962c51a 7741 {
8335d6aa
JW
7742 if (immlo == (immlo & 0x000000ff))
7743 {
7744 *immbits = immlo;
7745 return 0x8;
7746 }
7747 else if (immlo == (immlo & 0x0000ff00))
7748 {
7749 *immbits = immlo >> 8;
7750 return 0xa;
7751 }
7752
7753 if ((immlo & 0xff) != (immlo >> 8))
7754 return FAIL;
7755 immlo &= 0xff;
4962c51a
MS
7756 }
7757
8335d6aa
JW
7758 if (immlo == (immlo & 0x000000ff))
7759 {
7760 /* Don't allow MVN with 8-bit immediate. */
7761 if (*op == 1)
7762 return FAIL;
7763 *immbits = immlo;
7764 return 0xe;
7765 }
26d97720 7766
8335d6aa 7767 return FAIL;
c19d1205 7768}
a737bd4d 7769
5fc177c8 7770#if defined BFD_HOST_64_BIT
ba592044
AM
7771/* Returns TRUE if double precision value V may be cast
7772 to single precision without loss of accuracy. */
7773
7774static bfd_boolean
5fc177c8 7775is_double_a_single (bfd_int64_t v)
ba592044 7776{
5fc177c8 7777 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7778 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7779
7780 return (exp == 0 || exp == 0x7FF
7781 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7782 && (mantissa & 0x1FFFFFFFl) == 0;
7783}
7784
3739860c 7785/* Returns a double precision value casted to single precision
ba592044
AM
7786 (ignoring the least significant bits in exponent and mantissa). */
7787
7788static int
5fc177c8 7789double_to_single (bfd_int64_t v)
ba592044
AM
7790{
7791 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7792 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7793 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7794
7795 if (exp == 0x7FF)
7796 exp = 0xFF;
7797 else
7798 {
7799 exp = exp - 1023 + 127;
7800 if (exp >= 0xFF)
7801 {
7802 /* Infinity. */
7803 exp = 0x7F;
7804 mantissa = 0;
7805 }
7806 else if (exp < 0)
7807 {
7808 /* No denormalized numbers. */
7809 exp = 0;
7810 mantissa = 0;
7811 }
7812 }
7813 mantissa >>= 29;
7814 return (sign << 31) | (exp << 23) | mantissa;
7815}
5fc177c8 7816#endif /* BFD_HOST_64_BIT */
ba592044 7817
8335d6aa
JW
7818enum lit_type
7819{
7820 CONST_THUMB,
7821 CONST_ARM,
7822 CONST_VEC
7823};
7824
ba592044
AM
7825static void do_vfp_nsyn_opcode (const char *);
7826
c19d1205
ZW
7827/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7828 Determine whether it can be performed with a move instruction; if
7829 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7830 return TRUE; if it can't, convert inst.instruction to a literal-pool
7831 load and return FALSE. If this is not a valid thing to do in the
7832 current context, set inst.error and return TRUE.
a737bd4d 7833
c19d1205
ZW
7834 inst.operands[i] describes the destination register. */
7835
c921be7d 7836static bfd_boolean
8335d6aa 7837move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7838{
53365c0d 7839 unsigned long tbit;
8335d6aa
JW
7840 bfd_boolean thumb_p = (t == CONST_THUMB);
7841 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7842
7843 if (thumb_p)
7844 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7845 else
7846 tbit = LOAD_BIT;
7847
7848 if ((inst.instruction & tbit) == 0)
09d92015 7849 {
c19d1205 7850 inst.error = _("invalid pseudo operation");
c921be7d 7851 return TRUE;
09d92015 7852 }
ba592044 7853
8335d6aa
JW
7854 if (inst.reloc.exp.X_op != O_constant
7855 && inst.reloc.exp.X_op != O_symbol
7856 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7857 {
7858 inst.error = _("constant expression expected");
c921be7d 7859 return TRUE;
09d92015 7860 }
ba592044
AM
7861
7862 if (inst.reloc.exp.X_op == O_constant
7863 || inst.reloc.exp.X_op == O_big)
8335d6aa 7864 {
5fc177c8
NC
7865#if defined BFD_HOST_64_BIT
7866 bfd_int64_t v;
7867#else
ba592044 7868 offsetT v;
5fc177c8 7869#endif
ba592044 7870 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7871 {
ba592044
AM
7872 LITTLENUM_TYPE w[X_PRECISION];
7873 LITTLENUM_TYPE * l;
7874
7875 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7876 {
ba592044
AM
7877 gen_to_words (w, X_PRECISION, E_PRECISION);
7878 l = w;
7879 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7880 }
ba592044
AM
7881 else
7882 l = generic_bignum;
3739860c 7883
5fc177c8
NC
7884#if defined BFD_HOST_64_BIT
7885 v =
7886 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7887 << LITTLENUM_NUMBER_OF_BITS)
7888 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7889 << LITTLENUM_NUMBER_OF_BITS)
7890 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7891 << LITTLENUM_NUMBER_OF_BITS)
7892 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7893#else
ba592044
AM
7894 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7895 | (l[0] & LITTLENUM_MASK);
5fc177c8 7896#endif
8335d6aa 7897 }
ba592044
AM
7898 else
7899 v = inst.reloc.exp.X_add_number;
7900
7901 if (!inst.operands[i].issingle)
8335d6aa 7902 {
12569877 7903 if (thumb_p)
8335d6aa 7904 {
2c32be70
CM
7905 /* This can be encoded only for a low register. */
7906 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7907 {
7908 /* This can be done with a mov(1) instruction. */
7909 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7910 inst.instruction |= v;
7911 return TRUE;
7912 }
12569877 7913
ff8646ee
TP
7914 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7915 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7916 {
fc289b0a
TP
7917 /* Check if on thumb2 it can be done with a mov.w, mvn or
7918 movw instruction. */
12569877
AM
7919 unsigned int newimm;
7920 bfd_boolean isNegated;
7921
7922 newimm = encode_thumb32_immediate (v);
7923 if (newimm != (unsigned int) FAIL)
7924 isNegated = FALSE;
7925 else
7926 {
582cfe03 7927 newimm = encode_thumb32_immediate (~v);
12569877
AM
7928 if (newimm != (unsigned int) FAIL)
7929 isNegated = TRUE;
7930 }
7931
fc289b0a
TP
7932 /* The number can be loaded with a mov.w or mvn
7933 instruction. */
ff8646ee
TP
7934 if (newimm != (unsigned int) FAIL
7935 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7936 {
fc289b0a 7937 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7938 | (inst.operands[i].reg << 8));
fc289b0a 7939 /* Change to MOVN. */
582cfe03 7940 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7941 inst.instruction |= (newimm & 0x800) << 15;
7942 inst.instruction |= (newimm & 0x700) << 4;
7943 inst.instruction |= (newimm & 0x0ff);
7944 return TRUE;
7945 }
fc289b0a 7946 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
7947 else if ((v & ~0xFFFF) == 0
7948 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 7949 {
582cfe03 7950 int imm = v & 0xFFFF;
12569877 7951
582cfe03 7952 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7953 inst.instruction |= (inst.operands[i].reg << 8);
7954 inst.instruction |= (imm & 0xf000) << 4;
7955 inst.instruction |= (imm & 0x0800) << 15;
7956 inst.instruction |= (imm & 0x0700) << 4;
7957 inst.instruction |= (imm & 0x00ff);
7958 return TRUE;
7959 }
7960 }
8335d6aa 7961 }
12569877 7962 else if (arm_p)
ba592044
AM
7963 {
7964 int value = encode_arm_immediate (v);
12569877 7965
ba592044
AM
7966 if (value != FAIL)
7967 {
7968 /* This can be done with a mov instruction. */
7969 inst.instruction &= LITERAL_MASK;
7970 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7971 inst.instruction |= value & 0xfff;
7972 return TRUE;
7973 }
8335d6aa 7974
ba592044
AM
7975 value = encode_arm_immediate (~ v);
7976 if (value != FAIL)
7977 {
7978 /* This can be done with a mvn instruction. */
7979 inst.instruction &= LITERAL_MASK;
7980 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7981 inst.instruction |= value & 0xfff;
7982 return TRUE;
7983 }
7984 }
7985 else if (t == CONST_VEC)
8335d6aa 7986 {
ba592044
AM
7987 int op = 0;
7988 unsigned immbits = 0;
7989 unsigned immlo = inst.operands[1].imm;
7990 unsigned immhi = inst.operands[1].regisimm
7991 ? inst.operands[1].reg
7992 : inst.reloc.exp.X_unsigned
7993 ? 0
7994 : ((bfd_int64_t)((int) immlo)) >> 32;
7995 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7996 &op, 64, NT_invtype);
7997
7998 if (cmode == FAIL)
7999 {
8000 neon_invert_size (&immlo, &immhi, 64);
8001 op = !op;
8002 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8003 &op, 64, NT_invtype);
8004 }
8005
8006 if (cmode != FAIL)
8007 {
8008 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8009 | (1 << 23)
8010 | (cmode << 8)
8011 | (op << 5)
8012 | (1 << 4);
8013
8014 /* Fill other bits in vmov encoding for both thumb and arm. */
8015 if (thumb_mode)
eff0bc54 8016 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8017 else
eff0bc54 8018 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8019 neon_write_immbits (immbits);
8020 return TRUE;
8021 }
8335d6aa
JW
8022 }
8023 }
8335d6aa 8024
ba592044
AM
8025 if (t == CONST_VEC)
8026 {
8027 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8028 if (inst.operands[i].issingle
8029 && is_quarter_float (inst.operands[1].imm)
8030 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8031 {
ba592044
AM
8032 inst.operands[1].imm =
8033 neon_qfloat_bits (v);
8034 do_vfp_nsyn_opcode ("fconsts");
8035 return TRUE;
8335d6aa 8036 }
5fc177c8
NC
8037
8038 /* If our host does not support a 64-bit type then we cannot perform
8039 the following optimization. This mean that there will be a
8040 discrepancy between the output produced by an assembler built for
8041 a 32-bit-only host and the output produced from a 64-bit host, but
8042 this cannot be helped. */
8043#if defined BFD_HOST_64_BIT
ba592044
AM
8044 else if (!inst.operands[1].issingle
8045 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8046 {
ba592044
AM
8047 if (is_double_a_single (v)
8048 && is_quarter_float (double_to_single (v)))
8049 {
8050 inst.operands[1].imm =
8051 neon_qfloat_bits (double_to_single (v));
8052 do_vfp_nsyn_opcode ("fconstd");
8053 return TRUE;
8054 }
8335d6aa 8055 }
5fc177c8 8056#endif
8335d6aa
JW
8057 }
8058 }
8059
8060 if (add_to_lit_pool ((!inst.operands[i].isvec
8061 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8062 return TRUE;
8063
8064 inst.operands[1].reg = REG_PC;
8065 inst.operands[1].isreg = 1;
8066 inst.operands[1].preind = 1;
8067 inst.reloc.pc_rel = 1;
8068 inst.reloc.type = (thumb_p
8069 ? BFD_RELOC_ARM_THUMB_OFFSET
8070 : (mode_3
8071 ? BFD_RELOC_ARM_HWLITERAL
8072 : BFD_RELOC_ARM_LITERAL));
8073 return FALSE;
8074}
8075
8076/* inst.operands[i] was set up by parse_address. Encode it into an
8077 ARM-format instruction. Reject all forms which cannot be encoded
8078 into a coprocessor load/store instruction. If wb_ok is false,
8079 reject use of writeback; if unind_ok is false, reject use of
8080 unindexed addressing. If reloc_override is not 0, use it instead
8081 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8082 (in which case it is preserved). */
8083
8084static int
8085encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8086{
8087 if (!inst.operands[i].isreg)
8088 {
99b2a2dd
NC
8089 /* PR 18256 */
8090 if (! inst.operands[0].isvec)
8091 {
8092 inst.error = _("invalid co-processor operand");
8093 return FAIL;
8094 }
8335d6aa
JW
8095 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8096 return SUCCESS;
8097 }
8098
8099 inst.instruction |= inst.operands[i].reg << 16;
8100
8101 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8102
8103 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8104 {
8105 gas_assert (!inst.operands[i].writeback);
8106 if (!unind_ok)
8107 {
8108 inst.error = _("instruction does not support unindexed addressing");
8109 return FAIL;
8110 }
8111 inst.instruction |= inst.operands[i].imm;
8112 inst.instruction |= INDEX_UP;
8113 return SUCCESS;
8114 }
8115
8116 if (inst.operands[i].preind)
8117 inst.instruction |= PRE_INDEX;
8118
8119 if (inst.operands[i].writeback)
09d92015 8120 {
8335d6aa 8121 if (inst.operands[i].reg == REG_PC)
c19d1205 8122 {
8335d6aa
JW
8123 inst.error = _("pc may not be used with write-back");
8124 return FAIL;
c19d1205 8125 }
8335d6aa 8126 if (!wb_ok)
c19d1205 8127 {
8335d6aa
JW
8128 inst.error = _("instruction does not support writeback");
8129 return FAIL;
c19d1205 8130 }
8335d6aa 8131 inst.instruction |= WRITE_BACK;
09d92015
MM
8132 }
8133
8335d6aa
JW
8134 if (reloc_override)
8135 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8136 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8137 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8138 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8139 {
8335d6aa
JW
8140 if (thumb_mode)
8141 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8142 else
8143 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8144 }
8335d6aa
JW
8145
8146 /* Prefer + for zero encoded value. */
8147 if (!inst.operands[i].negative)
8148 inst.instruction |= INDEX_UP;
8149
8150 return SUCCESS;
09d92015
MM
8151}
8152
5f4273c7 8153/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8154 First some generics; their names are taken from the conventional
8155 bit positions for register arguments in ARM format instructions. */
09d92015 8156
a737bd4d 8157static void
c19d1205 8158do_noargs (void)
09d92015 8159{
c19d1205 8160}
a737bd4d 8161
c19d1205
ZW
8162static void
8163do_rd (void)
8164{
8165 inst.instruction |= inst.operands[0].reg << 12;
8166}
a737bd4d 8167
c19d1205
ZW
8168static void
8169do_rd_rm (void)
8170{
8171 inst.instruction |= inst.operands[0].reg << 12;
8172 inst.instruction |= inst.operands[1].reg;
8173}
09d92015 8174
9eb6c0f1
MGD
8175static void
8176do_rm_rn (void)
8177{
8178 inst.instruction |= inst.operands[0].reg;
8179 inst.instruction |= inst.operands[1].reg << 16;
8180}
8181
c19d1205
ZW
8182static void
8183do_rd_rn (void)
8184{
8185 inst.instruction |= inst.operands[0].reg << 12;
8186 inst.instruction |= inst.operands[1].reg << 16;
8187}
a737bd4d 8188
c19d1205
ZW
8189static void
8190do_rn_rd (void)
8191{
8192 inst.instruction |= inst.operands[0].reg << 16;
8193 inst.instruction |= inst.operands[1].reg << 12;
8194}
09d92015 8195
4ed7ed8d
TP
8196static void
8197do_tt (void)
8198{
8199 inst.instruction |= inst.operands[0].reg << 8;
8200 inst.instruction |= inst.operands[1].reg << 16;
8201}
8202
59d09be6
MGD
8203static bfd_boolean
8204check_obsolete (const arm_feature_set *feature, const char *msg)
8205{
8206 if (ARM_CPU_IS_ANY (cpu_variant))
8207 {
5c3696f8 8208 as_tsktsk ("%s", msg);
59d09be6
MGD
8209 return TRUE;
8210 }
8211 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8212 {
8213 as_bad ("%s", msg);
8214 return TRUE;
8215 }
8216
8217 return FALSE;
8218}
8219
c19d1205
ZW
8220static void
8221do_rd_rm_rn (void)
8222{
9a64e435 8223 unsigned Rn = inst.operands[2].reg;
708587a4 8224 /* Enforce restrictions on SWP instruction. */
9a64e435 8225 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8226 {
8227 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8228 _("Rn must not overlap other operands"));
8229
59d09be6
MGD
8230 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8231 */
8232 if (!check_obsolete (&arm_ext_v8,
8233 _("swp{b} use is obsoleted for ARMv8 and later"))
8234 && warn_on_deprecated
8235 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8236 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8237 }
59d09be6 8238
c19d1205
ZW
8239 inst.instruction |= inst.operands[0].reg << 12;
8240 inst.instruction |= inst.operands[1].reg;
9a64e435 8241 inst.instruction |= Rn << 16;
c19d1205 8242}
09d92015 8243
c19d1205
ZW
8244static void
8245do_rd_rn_rm (void)
8246{
8247 inst.instruction |= inst.operands[0].reg << 12;
8248 inst.instruction |= inst.operands[1].reg << 16;
8249 inst.instruction |= inst.operands[2].reg;
8250}
a737bd4d 8251
c19d1205
ZW
8252static void
8253do_rm_rd_rn (void)
8254{
5be8be5d
DG
8255 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8256 constraint (((inst.reloc.exp.X_op != O_constant
8257 && inst.reloc.exp.X_op != O_illegal)
8258 || inst.reloc.exp.X_add_number != 0),
8259 BAD_ADDR_MODE);
c19d1205
ZW
8260 inst.instruction |= inst.operands[0].reg;
8261 inst.instruction |= inst.operands[1].reg << 12;
8262 inst.instruction |= inst.operands[2].reg << 16;
8263}
09d92015 8264
c19d1205
ZW
8265static void
8266do_imm0 (void)
8267{
8268 inst.instruction |= inst.operands[0].imm;
8269}
09d92015 8270
c19d1205
ZW
8271static void
8272do_rd_cpaddr (void)
8273{
8274 inst.instruction |= inst.operands[0].reg << 12;
8275 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8276}
a737bd4d 8277
c19d1205
ZW
8278/* ARM instructions, in alphabetical order by function name (except
8279 that wrapper functions appear immediately after the function they
8280 wrap). */
09d92015 8281
c19d1205
ZW
8282/* This is a pseudo-op of the form "adr rd, label" to be converted
8283 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8284
8285static void
c19d1205 8286do_adr (void)
09d92015 8287{
c19d1205 8288 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8289
c19d1205
ZW
8290 /* Frag hacking will turn this into a sub instruction if the offset turns
8291 out to be negative. */
8292 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8293 inst.reloc.pc_rel = 1;
2fc8bdac 8294 inst.reloc.exp.X_add_number -= 8;
c19d1205 8295}
b99bd4ef 8296
c19d1205
ZW
8297/* This is a pseudo-op of the form "adrl rd, label" to be converted
8298 into a relative address of the form:
8299 add rd, pc, #low(label-.-8)"
8300 add rd, rd, #high(label-.-8)" */
b99bd4ef 8301
c19d1205
ZW
8302static void
8303do_adrl (void)
8304{
8305 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8306
c19d1205
ZW
8307 /* Frag hacking will turn this into a sub instruction if the offset turns
8308 out to be negative. */
8309 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8310 inst.reloc.pc_rel = 1;
8311 inst.size = INSN_SIZE * 2;
2fc8bdac 8312 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8313}
8314
b99bd4ef 8315static void
c19d1205 8316do_arit (void)
b99bd4ef 8317{
c19d1205
ZW
8318 if (!inst.operands[1].present)
8319 inst.operands[1].reg = inst.operands[0].reg;
8320 inst.instruction |= inst.operands[0].reg << 12;
8321 inst.instruction |= inst.operands[1].reg << 16;
8322 encode_arm_shifter_operand (2);
8323}
b99bd4ef 8324
62b3e311
PB
8325static void
8326do_barrier (void)
8327{
8328 if (inst.operands[0].present)
ccb84d65 8329 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8330 else
8331 inst.instruction |= 0xf;
8332}
8333
c19d1205
ZW
8334static void
8335do_bfc (void)
8336{
8337 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8338 constraint (msb > 32, _("bit-field extends past end of register"));
8339 /* The instruction encoding stores the LSB and MSB,
8340 not the LSB and width. */
8341 inst.instruction |= inst.operands[0].reg << 12;
8342 inst.instruction |= inst.operands[1].imm << 7;
8343 inst.instruction |= (msb - 1) << 16;
8344}
b99bd4ef 8345
c19d1205
ZW
8346static void
8347do_bfi (void)
8348{
8349 unsigned int msb;
b99bd4ef 8350
c19d1205
ZW
8351 /* #0 in second position is alternative syntax for bfc, which is
8352 the same instruction but with REG_PC in the Rm field. */
8353 if (!inst.operands[1].isreg)
8354 inst.operands[1].reg = REG_PC;
b99bd4ef 8355
c19d1205
ZW
8356 msb = inst.operands[2].imm + inst.operands[3].imm;
8357 constraint (msb > 32, _("bit-field extends past end of register"));
8358 /* The instruction encoding stores the LSB and MSB,
8359 not the LSB and width. */
8360 inst.instruction |= inst.operands[0].reg << 12;
8361 inst.instruction |= inst.operands[1].reg;
8362 inst.instruction |= inst.operands[2].imm << 7;
8363 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8364}
8365
b99bd4ef 8366static void
c19d1205 8367do_bfx (void)
b99bd4ef 8368{
c19d1205
ZW
8369 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8370 _("bit-field extends past end of register"));
8371 inst.instruction |= inst.operands[0].reg << 12;
8372 inst.instruction |= inst.operands[1].reg;
8373 inst.instruction |= inst.operands[2].imm << 7;
8374 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8375}
09d92015 8376
c19d1205
ZW
8377/* ARM V5 breakpoint instruction (argument parse)
8378 BKPT <16 bit unsigned immediate>
8379 Instruction is not conditional.
8380 The bit pattern given in insns[] has the COND_ALWAYS condition,
8381 and it is an error if the caller tried to override that. */
b99bd4ef 8382
c19d1205
ZW
8383static void
8384do_bkpt (void)
8385{
8386 /* Top 12 of 16 bits to bits 19:8. */
8387 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8388
c19d1205
ZW
8389 /* Bottom 4 of 16 bits to bits 3:0. */
8390 inst.instruction |= inst.operands[0].imm & 0xf;
8391}
09d92015 8392
c19d1205
ZW
8393static void
8394encode_branch (int default_reloc)
8395{
8396 if (inst.operands[0].hasreloc)
8397 {
0855e32b
NS
8398 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8399 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8400 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8401 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8402 ? BFD_RELOC_ARM_PLT32
8403 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8404 }
b99bd4ef 8405 else
9ae92b05 8406 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8407 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8408}
8409
b99bd4ef 8410static void
c19d1205 8411do_branch (void)
b99bd4ef 8412{
39b41c9c
PB
8413#ifdef OBJ_ELF
8414 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8415 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8416 else
8417#endif
8418 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8419}
8420
8421static void
8422do_bl (void)
8423{
8424#ifdef OBJ_ELF
8425 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8426 {
8427 if (inst.cond == COND_ALWAYS)
8428 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8429 else
8430 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8431 }
8432 else
8433#endif
8434 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8435}
b99bd4ef 8436
c19d1205
ZW
8437/* ARM V5 branch-link-exchange instruction (argument parse)
8438 BLX <target_addr> ie BLX(1)
8439 BLX{<condition>} <Rm> ie BLX(2)
8440 Unfortunately, there are two different opcodes for this mnemonic.
8441 So, the insns[].value is not used, and the code here zaps values
8442 into inst.instruction.
8443 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8444
c19d1205
ZW
8445static void
8446do_blx (void)
8447{
8448 if (inst.operands[0].isreg)
b99bd4ef 8449 {
c19d1205
ZW
8450 /* Arg is a register; the opcode provided by insns[] is correct.
8451 It is not illegal to do "blx pc", just useless. */
8452 if (inst.operands[0].reg == REG_PC)
8453 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8454
c19d1205
ZW
8455 inst.instruction |= inst.operands[0].reg;
8456 }
8457 else
b99bd4ef 8458 {
c19d1205 8459 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8460 conditionally, and the opcode must be adjusted.
8461 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8462 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8463 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8464 inst.instruction = 0xfa000000;
267bf995 8465 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8466 }
c19d1205
ZW
8467}
8468
8469static void
8470do_bx (void)
8471{
845b51d6
PB
8472 bfd_boolean want_reloc;
8473
c19d1205
ZW
8474 if (inst.operands[0].reg == REG_PC)
8475 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8476
c19d1205 8477 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8478 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8479 it is for ARMv4t or earlier. */
8480 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8481 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8482 want_reloc = TRUE;
8483
5ad34203 8484#ifdef OBJ_ELF
845b51d6 8485 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8486#endif
584206db 8487 want_reloc = FALSE;
845b51d6
PB
8488
8489 if (want_reloc)
8490 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8491}
8492
c19d1205
ZW
8493
8494/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8495
8496static void
c19d1205 8497do_bxj (void)
a737bd4d 8498{
c19d1205
ZW
8499 if (inst.operands[0].reg == REG_PC)
8500 as_tsktsk (_("use of r15 in bxj is not really useful"));
8501
8502 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8503}
8504
c19d1205
ZW
8505/* Co-processor data operation:
8506 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8507 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8508static void
8509do_cdp (void)
8510{
8511 inst.instruction |= inst.operands[0].reg << 8;
8512 inst.instruction |= inst.operands[1].imm << 20;
8513 inst.instruction |= inst.operands[2].reg << 12;
8514 inst.instruction |= inst.operands[3].reg << 16;
8515 inst.instruction |= inst.operands[4].reg;
8516 inst.instruction |= inst.operands[5].imm << 5;
8517}
a737bd4d
NC
8518
8519static void
c19d1205 8520do_cmp (void)
a737bd4d 8521{
c19d1205
ZW
8522 inst.instruction |= inst.operands[0].reg << 16;
8523 encode_arm_shifter_operand (1);
a737bd4d
NC
8524}
8525
c19d1205
ZW
8526/* Transfer between coprocessor and ARM registers.
8527 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8528 MRC2
8529 MCR{cond}
8530 MCR2
8531
8532 No special properties. */
09d92015 8533
dcbd0d71
MGD
8534struct deprecated_coproc_regs_s
8535{
8536 unsigned cp;
8537 int opc1;
8538 unsigned crn;
8539 unsigned crm;
8540 int opc2;
8541 arm_feature_set deprecated;
8542 arm_feature_set obsoleted;
8543 const char *dep_msg;
8544 const char *obs_msg;
8545};
8546
8547#define DEPR_ACCESS_V8 \
8548 N_("This coprocessor register access is deprecated in ARMv8")
8549
8550/* Table of all deprecated coprocessor registers. */
8551static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8552{
8553 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8554 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8555 DEPR_ACCESS_V8, NULL},
8556 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8557 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8558 DEPR_ACCESS_V8, NULL},
8559 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8560 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8561 DEPR_ACCESS_V8, NULL},
8562 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8563 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8564 DEPR_ACCESS_V8, NULL},
8565 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8566 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8567 DEPR_ACCESS_V8, NULL},
8568};
8569
8570#undef DEPR_ACCESS_V8
8571
8572static const size_t deprecated_coproc_reg_count =
8573 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8574
09d92015 8575static void
c19d1205 8576do_co_reg (void)
09d92015 8577{
fdfde340 8578 unsigned Rd;
dcbd0d71 8579 size_t i;
fdfde340
JM
8580
8581 Rd = inst.operands[2].reg;
8582 if (thumb_mode)
8583 {
8584 if (inst.instruction == 0xee000010
8585 || inst.instruction == 0xfe000010)
8586 /* MCR, MCR2 */
8587 reject_bad_reg (Rd);
8588 else
8589 /* MRC, MRC2 */
8590 constraint (Rd == REG_SP, BAD_SP);
8591 }
8592 else
8593 {
8594 /* MCR */
8595 if (inst.instruction == 0xe000010)
8596 constraint (Rd == REG_PC, BAD_PC);
8597 }
8598
dcbd0d71
MGD
8599 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8600 {
8601 const struct deprecated_coproc_regs_s *r =
8602 deprecated_coproc_regs + i;
8603
8604 if (inst.operands[0].reg == r->cp
8605 && inst.operands[1].imm == r->opc1
8606 && inst.operands[3].reg == r->crn
8607 && inst.operands[4].reg == r->crm
8608 && inst.operands[5].imm == r->opc2)
8609 {
b10bf8c5 8610 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8611 && warn_on_deprecated
dcbd0d71 8612 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8613 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8614 }
8615 }
fdfde340 8616
c19d1205
ZW
8617 inst.instruction |= inst.operands[0].reg << 8;
8618 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8619 inst.instruction |= Rd << 12;
c19d1205
ZW
8620 inst.instruction |= inst.operands[3].reg << 16;
8621 inst.instruction |= inst.operands[4].reg;
8622 inst.instruction |= inst.operands[5].imm << 5;
8623}
09d92015 8624
c19d1205
ZW
8625/* Transfer between coprocessor register and pair of ARM registers.
8626 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8627 MCRR2
8628 MRRC{cond}
8629 MRRC2
b99bd4ef 8630
c19d1205 8631 Two XScale instructions are special cases of these:
09d92015 8632
c19d1205
ZW
8633 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8634 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8635
5f4273c7 8636 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8637
c19d1205
ZW
8638static void
8639do_co_reg2c (void)
8640{
fdfde340
JM
8641 unsigned Rd, Rn;
8642
8643 Rd = inst.operands[2].reg;
8644 Rn = inst.operands[3].reg;
8645
8646 if (thumb_mode)
8647 {
8648 reject_bad_reg (Rd);
8649 reject_bad_reg (Rn);
8650 }
8651 else
8652 {
8653 constraint (Rd == REG_PC, BAD_PC);
8654 constraint (Rn == REG_PC, BAD_PC);
8655 }
8656
c19d1205
ZW
8657 inst.instruction |= inst.operands[0].reg << 8;
8658 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8659 inst.instruction |= Rd << 12;
8660 inst.instruction |= Rn << 16;
c19d1205 8661 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8662}
8663
c19d1205
ZW
8664static void
8665do_cpsi (void)
8666{
8667 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8668 if (inst.operands[1].present)
8669 {
8670 inst.instruction |= CPSI_MMOD;
8671 inst.instruction |= inst.operands[1].imm;
8672 }
c19d1205 8673}
b99bd4ef 8674
62b3e311
PB
8675static void
8676do_dbg (void)
8677{
8678 inst.instruction |= inst.operands[0].imm;
8679}
8680
eea54501
MGD
8681static void
8682do_div (void)
8683{
8684 unsigned Rd, Rn, Rm;
8685
8686 Rd = inst.operands[0].reg;
8687 Rn = (inst.operands[1].present
8688 ? inst.operands[1].reg : Rd);
8689 Rm = inst.operands[2].reg;
8690
8691 constraint ((Rd == REG_PC), BAD_PC);
8692 constraint ((Rn == REG_PC), BAD_PC);
8693 constraint ((Rm == REG_PC), BAD_PC);
8694
8695 inst.instruction |= Rd << 16;
8696 inst.instruction |= Rn << 0;
8697 inst.instruction |= Rm << 8;
8698}
8699
b99bd4ef 8700static void
c19d1205 8701do_it (void)
b99bd4ef 8702{
c19d1205 8703 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8704 process it to do the validation as if in
8705 thumb mode, just in case the code gets
8706 assembled for thumb using the unified syntax. */
8707
c19d1205 8708 inst.size = 0;
e07e6e58
NC
8709 if (unified_syntax)
8710 {
8711 set_it_insn_type (IT_INSN);
8712 now_it.mask = (inst.instruction & 0xf) | 0x10;
8713 now_it.cc = inst.operands[0].imm;
8714 }
09d92015 8715}
b99bd4ef 8716
6530b175
NC
8717/* If there is only one register in the register list,
8718 then return its register number. Otherwise return -1. */
8719static int
8720only_one_reg_in_list (int range)
8721{
8722 int i = ffs (range) - 1;
8723 return (i > 15 || range != (1 << i)) ? -1 : i;
8724}
8725
09d92015 8726static void
6530b175 8727encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8728{
c19d1205
ZW
8729 int base_reg = inst.operands[0].reg;
8730 int range = inst.operands[1].imm;
6530b175 8731 int one_reg;
ea6ef066 8732
c19d1205
ZW
8733 inst.instruction |= base_reg << 16;
8734 inst.instruction |= range;
ea6ef066 8735
c19d1205
ZW
8736 if (inst.operands[1].writeback)
8737 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8738
c19d1205 8739 if (inst.operands[0].writeback)
ea6ef066 8740 {
c19d1205
ZW
8741 inst.instruction |= WRITE_BACK;
8742 /* Check for unpredictable uses of writeback. */
8743 if (inst.instruction & LOAD_BIT)
09d92015 8744 {
c19d1205
ZW
8745 /* Not allowed in LDM type 2. */
8746 if ((inst.instruction & LDM_TYPE_2_OR_3)
8747 && ((range & (1 << REG_PC)) == 0))
8748 as_warn (_("writeback of base register is UNPREDICTABLE"));
8749 /* Only allowed if base reg not in list for other types. */
8750 else if (range & (1 << base_reg))
8751 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8752 }
8753 else /* STM. */
8754 {
8755 /* Not allowed for type 2. */
8756 if (inst.instruction & LDM_TYPE_2_OR_3)
8757 as_warn (_("writeback of base register is UNPREDICTABLE"));
8758 /* Only allowed if base reg not in list, or first in list. */
8759 else if ((range & (1 << base_reg))
8760 && (range & ((1 << base_reg) - 1)))
8761 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8762 }
ea6ef066 8763 }
6530b175
NC
8764
8765 /* If PUSH/POP has only one register, then use the A2 encoding. */
8766 one_reg = only_one_reg_in_list (range);
8767 if (from_push_pop_mnem && one_reg >= 0)
8768 {
8769 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8770
8771 inst.instruction &= A_COND_MASK;
8772 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8773 inst.instruction |= one_reg << 12;
8774 }
8775}
8776
8777static void
8778do_ldmstm (void)
8779{
8780 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8781}
8782
c19d1205
ZW
8783/* ARMv5TE load-consecutive (argument parse)
8784 Mode is like LDRH.
8785
8786 LDRccD R, mode
8787 STRccD R, mode. */
8788
a737bd4d 8789static void
c19d1205 8790do_ldrd (void)
a737bd4d 8791{
c19d1205 8792 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8793 _("first transfer register must be even"));
c19d1205
ZW
8794 constraint (inst.operands[1].present
8795 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8796 _("can only transfer two consecutive registers"));
c19d1205
ZW
8797 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8798 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8799
c19d1205
ZW
8800 if (!inst.operands[1].present)
8801 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8802
c56791bb
RE
8803 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8804 register and the first register written; we have to diagnose
8805 overlap between the base and the second register written here. */
ea6ef066 8806
c56791bb
RE
8807 if (inst.operands[2].reg == inst.operands[1].reg
8808 && (inst.operands[2].writeback || inst.operands[2].postind))
8809 as_warn (_("base register written back, and overlaps "
8810 "second transfer register"));
b05fe5cf 8811
c56791bb
RE
8812 if (!(inst.instruction & V4_STR_BIT))
8813 {
c19d1205 8814 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8815 destination (even if not write-back). */
8816 if (inst.operands[2].immisreg
8817 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8818 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8819 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8820 }
c19d1205
ZW
8821 inst.instruction |= inst.operands[0].reg << 12;
8822 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8823}
8824
8825static void
c19d1205 8826do_ldrex (void)
b05fe5cf 8827{
c19d1205
ZW
8828 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8829 || inst.operands[1].postind || inst.operands[1].writeback
8830 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8831 || inst.operands[1].negative
8832 /* This can arise if the programmer has written
8833 strex rN, rM, foo
8834 or if they have mistakenly used a register name as the last
8835 operand, eg:
8836 strex rN, rM, rX
8837 It is very difficult to distinguish between these two cases
8838 because "rX" might actually be a label. ie the register
8839 name has been occluded by a symbol of the same name. So we
8840 just generate a general 'bad addressing mode' type error
8841 message and leave it up to the programmer to discover the
8842 true cause and fix their mistake. */
8843 || (inst.operands[1].reg == REG_PC),
8844 BAD_ADDR_MODE);
b05fe5cf 8845
c19d1205
ZW
8846 constraint (inst.reloc.exp.X_op != O_constant
8847 || inst.reloc.exp.X_add_number != 0,
8848 _("offset must be zero in ARM encoding"));
b05fe5cf 8849
5be8be5d
DG
8850 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8851
c19d1205
ZW
8852 inst.instruction |= inst.operands[0].reg << 12;
8853 inst.instruction |= inst.operands[1].reg << 16;
8854 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8855}
8856
8857static void
c19d1205 8858do_ldrexd (void)
b05fe5cf 8859{
c19d1205
ZW
8860 constraint (inst.operands[0].reg % 2 != 0,
8861 _("even register required"));
8862 constraint (inst.operands[1].present
8863 && inst.operands[1].reg != inst.operands[0].reg + 1,
8864 _("can only load two consecutive registers"));
8865 /* If op 1 were present and equal to PC, this function wouldn't
8866 have been called in the first place. */
8867 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8868
c19d1205
ZW
8869 inst.instruction |= inst.operands[0].reg << 12;
8870 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8871}
8872
1be5fd2e
NC
8873/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8874 which is not a multiple of four is UNPREDICTABLE. */
8875static void
8876check_ldr_r15_aligned (void)
8877{
8878 constraint (!(inst.operands[1].immisreg)
8879 && (inst.operands[0].reg == REG_PC
8880 && inst.operands[1].reg == REG_PC
8881 && (inst.reloc.exp.X_add_number & 0x3)),
8882 _("ldr to register 15 must be 4-byte alligned"));
8883}
8884
b05fe5cf 8885static void
c19d1205 8886do_ldst (void)
b05fe5cf 8887{
c19d1205
ZW
8888 inst.instruction |= inst.operands[0].reg << 12;
8889 if (!inst.operands[1].isreg)
8335d6aa 8890 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8891 return;
c19d1205 8892 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8893 check_ldr_r15_aligned ();
b05fe5cf
ZW
8894}
8895
8896static void
c19d1205 8897do_ldstt (void)
b05fe5cf 8898{
c19d1205
ZW
8899 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8900 reject [Rn,...]. */
8901 if (inst.operands[1].preind)
b05fe5cf 8902 {
bd3ba5d1
NC
8903 constraint (inst.reloc.exp.X_op != O_constant
8904 || inst.reloc.exp.X_add_number != 0,
c19d1205 8905 _("this instruction requires a post-indexed address"));
b05fe5cf 8906
c19d1205
ZW
8907 inst.operands[1].preind = 0;
8908 inst.operands[1].postind = 1;
8909 inst.operands[1].writeback = 1;
b05fe5cf 8910 }
c19d1205
ZW
8911 inst.instruction |= inst.operands[0].reg << 12;
8912 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8913}
b05fe5cf 8914
c19d1205 8915/* Halfword and signed-byte load/store operations. */
b05fe5cf 8916
c19d1205
ZW
8917static void
8918do_ldstv4 (void)
8919{
ff4a8d2b 8920 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8921 inst.instruction |= inst.operands[0].reg << 12;
8922 if (!inst.operands[1].isreg)
8335d6aa 8923 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8924 return;
c19d1205 8925 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8926}
8927
8928static void
c19d1205 8929do_ldsttv4 (void)
b05fe5cf 8930{
c19d1205
ZW
8931 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8932 reject [Rn,...]. */
8933 if (inst.operands[1].preind)
b05fe5cf 8934 {
bd3ba5d1
NC
8935 constraint (inst.reloc.exp.X_op != O_constant
8936 || inst.reloc.exp.X_add_number != 0,
c19d1205 8937 _("this instruction requires a post-indexed address"));
b05fe5cf 8938
c19d1205
ZW
8939 inst.operands[1].preind = 0;
8940 inst.operands[1].postind = 1;
8941 inst.operands[1].writeback = 1;
b05fe5cf 8942 }
c19d1205
ZW
8943 inst.instruction |= inst.operands[0].reg << 12;
8944 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8945}
b05fe5cf 8946
c19d1205
ZW
8947/* Co-processor register load/store.
8948 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8949static void
8950do_lstc (void)
8951{
8952 inst.instruction |= inst.operands[0].reg << 8;
8953 inst.instruction |= inst.operands[1].reg << 12;
8954 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8955}
8956
b05fe5cf 8957static void
c19d1205 8958do_mlas (void)
b05fe5cf 8959{
8fb9d7b9 8960 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8961 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8962 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8963 && !(inst.instruction & 0x00400000))
8fb9d7b9 8964 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8965
c19d1205
ZW
8966 inst.instruction |= inst.operands[0].reg << 16;
8967 inst.instruction |= inst.operands[1].reg;
8968 inst.instruction |= inst.operands[2].reg << 8;
8969 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8970}
b05fe5cf 8971
c19d1205
ZW
8972static void
8973do_mov (void)
8974{
8975 inst.instruction |= inst.operands[0].reg << 12;
8976 encode_arm_shifter_operand (1);
8977}
b05fe5cf 8978
c19d1205
ZW
8979/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8980static void
8981do_mov16 (void)
8982{
b6895b4f
PB
8983 bfd_vma imm;
8984 bfd_boolean top;
8985
8986 top = (inst.instruction & 0x00400000) != 0;
8987 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8988 _(":lower16: not allowed this instruction"));
8989 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8990 _(":upper16: not allowed instruction"));
c19d1205 8991 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8992 if (inst.reloc.type == BFD_RELOC_UNUSED)
8993 {
8994 imm = inst.reloc.exp.X_add_number;
8995 /* The value is in two pieces: 0:11, 16:19. */
8996 inst.instruction |= (imm & 0x00000fff);
8997 inst.instruction |= (imm & 0x0000f000) << 4;
8998 }
b05fe5cf 8999}
b99bd4ef 9000
037e8744
JB
9001static int
9002do_vfp_nsyn_mrs (void)
9003{
9004 if (inst.operands[0].isvec)
9005 {
9006 if (inst.operands[1].reg != 1)
477330fc 9007 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9008 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9009 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9010 do_vfp_nsyn_opcode ("fmstat");
9011 }
9012 else if (inst.operands[1].isvec)
9013 do_vfp_nsyn_opcode ("fmrx");
9014 else
9015 return FAIL;
5f4273c7 9016
037e8744
JB
9017 return SUCCESS;
9018}
9019
9020static int
9021do_vfp_nsyn_msr (void)
9022{
9023 if (inst.operands[0].isvec)
9024 do_vfp_nsyn_opcode ("fmxr");
9025 else
9026 return FAIL;
9027
9028 return SUCCESS;
9029}
9030
f7c21dc7
NC
9031static void
9032do_vmrs (void)
9033{
9034 unsigned Rt = inst.operands[0].reg;
fa94de6b 9035
16d02dc9 9036 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9037 {
9038 inst.error = BAD_SP;
9039 return;
9040 }
9041
9042 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9043 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9044 {
9045 inst.error = BAD_PC;
9046 return;
9047 }
9048
16d02dc9
JB
9049 /* If we get through parsing the register name, we just insert the number
9050 generated into the instruction without further validation. */
9051 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9052 inst.instruction |= (Rt << 12);
9053}
9054
9055static void
9056do_vmsr (void)
9057{
9058 unsigned Rt = inst.operands[1].reg;
fa94de6b 9059
f7c21dc7
NC
9060 if (thumb_mode)
9061 reject_bad_reg (Rt);
9062 else if (Rt == REG_PC)
9063 {
9064 inst.error = BAD_PC;
9065 return;
9066 }
9067
16d02dc9
JB
9068 /* If we get through parsing the register name, we just insert the number
9069 generated into the instruction without further validation. */
9070 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9071 inst.instruction |= (Rt << 12);
9072}
9073
b99bd4ef 9074static void
c19d1205 9075do_mrs (void)
b99bd4ef 9076{
90ec0d68
MGD
9077 unsigned br;
9078
037e8744
JB
9079 if (do_vfp_nsyn_mrs () == SUCCESS)
9080 return;
9081
ff4a8d2b 9082 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9083 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9084
9085 if (inst.operands[1].isreg)
9086 {
9087 br = inst.operands[1].reg;
9088 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9089 as_bad (_("bad register for mrs"));
9090 }
9091 else
9092 {
9093 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9094 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9095 != (PSR_c|PSR_f),
d2cd1205 9096 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9097 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9098 }
9099
9100 inst.instruction |= br;
c19d1205 9101}
b99bd4ef 9102
c19d1205
ZW
9103/* Two possible forms:
9104 "{C|S}PSR_<field>, Rm",
9105 "{C|S}PSR_f, #expression". */
b99bd4ef 9106
c19d1205
ZW
9107static void
9108do_msr (void)
9109{
037e8744
JB
9110 if (do_vfp_nsyn_msr () == SUCCESS)
9111 return;
9112
c19d1205
ZW
9113 inst.instruction |= inst.operands[0].imm;
9114 if (inst.operands[1].isreg)
9115 inst.instruction |= inst.operands[1].reg;
9116 else
b99bd4ef 9117 {
c19d1205
ZW
9118 inst.instruction |= INST_IMMEDIATE;
9119 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9120 inst.reloc.pc_rel = 0;
b99bd4ef 9121 }
b99bd4ef
NC
9122}
9123
c19d1205
ZW
9124static void
9125do_mul (void)
a737bd4d 9126{
ff4a8d2b
NC
9127 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9128
c19d1205
ZW
9129 if (!inst.operands[2].present)
9130 inst.operands[2].reg = inst.operands[0].reg;
9131 inst.instruction |= inst.operands[0].reg << 16;
9132 inst.instruction |= inst.operands[1].reg;
9133 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9134
8fb9d7b9
MS
9135 if (inst.operands[0].reg == inst.operands[1].reg
9136 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9137 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9138}
9139
c19d1205
ZW
9140/* Long Multiply Parser
9141 UMULL RdLo, RdHi, Rm, Rs
9142 SMULL RdLo, RdHi, Rm, Rs
9143 UMLAL RdLo, RdHi, Rm, Rs
9144 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9145
9146static void
c19d1205 9147do_mull (void)
b99bd4ef 9148{
c19d1205
ZW
9149 inst.instruction |= inst.operands[0].reg << 12;
9150 inst.instruction |= inst.operands[1].reg << 16;
9151 inst.instruction |= inst.operands[2].reg;
9152 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9153
682b27ad
PB
9154 /* rdhi and rdlo must be different. */
9155 if (inst.operands[0].reg == inst.operands[1].reg)
9156 as_tsktsk (_("rdhi and rdlo must be different"));
9157
9158 /* rdhi, rdlo and rm must all be different before armv6. */
9159 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9160 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9161 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9162 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9163}
b99bd4ef 9164
c19d1205
ZW
9165static void
9166do_nop (void)
9167{
e7495e45
NS
9168 if (inst.operands[0].present
9169 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9170 {
9171 /* Architectural NOP hints are CPSR sets with no bits selected. */
9172 inst.instruction &= 0xf0000000;
e7495e45
NS
9173 inst.instruction |= 0x0320f000;
9174 if (inst.operands[0].present)
9175 inst.instruction |= inst.operands[0].imm;
c19d1205 9176 }
b99bd4ef
NC
9177}
9178
c19d1205
ZW
9179/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9180 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9181 Condition defaults to COND_ALWAYS.
9182 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9183
9184static void
c19d1205 9185do_pkhbt (void)
b99bd4ef 9186{
c19d1205
ZW
9187 inst.instruction |= inst.operands[0].reg << 12;
9188 inst.instruction |= inst.operands[1].reg << 16;
9189 inst.instruction |= inst.operands[2].reg;
9190 if (inst.operands[3].present)
9191 encode_arm_shift (3);
9192}
b99bd4ef 9193
c19d1205 9194/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9195
c19d1205
ZW
9196static void
9197do_pkhtb (void)
9198{
9199 if (!inst.operands[3].present)
b99bd4ef 9200 {
c19d1205
ZW
9201 /* If the shift specifier is omitted, turn the instruction
9202 into pkhbt rd, rm, rn. */
9203 inst.instruction &= 0xfff00010;
9204 inst.instruction |= inst.operands[0].reg << 12;
9205 inst.instruction |= inst.operands[1].reg;
9206 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9207 }
9208 else
9209 {
c19d1205
ZW
9210 inst.instruction |= inst.operands[0].reg << 12;
9211 inst.instruction |= inst.operands[1].reg << 16;
9212 inst.instruction |= inst.operands[2].reg;
9213 encode_arm_shift (3);
b99bd4ef
NC
9214 }
9215}
9216
c19d1205 9217/* ARMv5TE: Preload-Cache
60e5ef9f 9218 MP Extensions: Preload for write
c19d1205 9219
60e5ef9f 9220 PLD(W) <addr_mode>
c19d1205
ZW
9221
9222 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9223
9224static void
c19d1205 9225do_pld (void)
b99bd4ef 9226{
c19d1205
ZW
9227 constraint (!inst.operands[0].isreg,
9228 _("'[' expected after PLD mnemonic"));
9229 constraint (inst.operands[0].postind,
9230 _("post-indexed expression used in preload instruction"));
9231 constraint (inst.operands[0].writeback,
9232 _("writeback used in preload instruction"));
9233 constraint (!inst.operands[0].preind,
9234 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9235 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9236}
b99bd4ef 9237
62b3e311
PB
9238/* ARMv7: PLI <addr_mode> */
9239static void
9240do_pli (void)
9241{
9242 constraint (!inst.operands[0].isreg,
9243 _("'[' expected after PLI mnemonic"));
9244 constraint (inst.operands[0].postind,
9245 _("post-indexed expression used in preload instruction"));
9246 constraint (inst.operands[0].writeback,
9247 _("writeback used in preload instruction"));
9248 constraint (!inst.operands[0].preind,
9249 _("unindexed addressing used in preload instruction"));
9250 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9251 inst.instruction &= ~PRE_INDEX;
9252}
9253
c19d1205
ZW
9254static void
9255do_push_pop (void)
9256{
5e0d7f77
MP
9257 constraint (inst.operands[0].writeback,
9258 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9259 inst.operands[1] = inst.operands[0];
9260 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9261 inst.operands[0].isreg = 1;
9262 inst.operands[0].writeback = 1;
9263 inst.operands[0].reg = REG_SP;
6530b175 9264 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9265}
b99bd4ef 9266
c19d1205
ZW
9267/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9268 word at the specified address and the following word
9269 respectively.
9270 Unconditionally executed.
9271 Error if Rn is R15. */
b99bd4ef 9272
c19d1205
ZW
9273static void
9274do_rfe (void)
9275{
9276 inst.instruction |= inst.operands[0].reg << 16;
9277 if (inst.operands[0].writeback)
9278 inst.instruction |= WRITE_BACK;
9279}
b99bd4ef 9280
c19d1205 9281/* ARM V6 ssat (argument parse). */
b99bd4ef 9282
c19d1205
ZW
9283static void
9284do_ssat (void)
9285{
9286 inst.instruction |= inst.operands[0].reg << 12;
9287 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9288 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9289
c19d1205
ZW
9290 if (inst.operands[3].present)
9291 encode_arm_shift (3);
b99bd4ef
NC
9292}
9293
c19d1205 9294/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9295
9296static void
c19d1205 9297do_usat (void)
b99bd4ef 9298{
c19d1205
ZW
9299 inst.instruction |= inst.operands[0].reg << 12;
9300 inst.instruction |= inst.operands[1].imm << 16;
9301 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9302
c19d1205
ZW
9303 if (inst.operands[3].present)
9304 encode_arm_shift (3);
b99bd4ef
NC
9305}
9306
c19d1205 9307/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9308
9309static void
c19d1205 9310do_ssat16 (void)
09d92015 9311{
c19d1205
ZW
9312 inst.instruction |= inst.operands[0].reg << 12;
9313 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9314 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9315}
9316
c19d1205
ZW
9317static void
9318do_usat16 (void)
a737bd4d 9319{
c19d1205
ZW
9320 inst.instruction |= inst.operands[0].reg << 12;
9321 inst.instruction |= inst.operands[1].imm << 16;
9322 inst.instruction |= inst.operands[2].reg;
9323}
a737bd4d 9324
c19d1205
ZW
9325/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9326 preserving the other bits.
a737bd4d 9327
c19d1205
ZW
9328 setend <endian_specifier>, where <endian_specifier> is either
9329 BE or LE. */
a737bd4d 9330
c19d1205
ZW
9331static void
9332do_setend (void)
9333{
12e37cbc
MGD
9334 if (warn_on_deprecated
9335 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9336 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9337
c19d1205
ZW
9338 if (inst.operands[0].imm)
9339 inst.instruction |= 0x200;
a737bd4d
NC
9340}
9341
9342static void
c19d1205 9343do_shift (void)
a737bd4d 9344{
c19d1205
ZW
9345 unsigned int Rm = (inst.operands[1].present
9346 ? inst.operands[1].reg
9347 : inst.operands[0].reg);
a737bd4d 9348
c19d1205
ZW
9349 inst.instruction |= inst.operands[0].reg << 12;
9350 inst.instruction |= Rm;
9351 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9352 {
c19d1205
ZW
9353 inst.instruction |= inst.operands[2].reg << 8;
9354 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9355 /* PR 12854: Error on extraneous shifts. */
9356 constraint (inst.operands[2].shifted,
9357 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9358 }
9359 else
c19d1205 9360 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9361}
9362
09d92015 9363static void
3eb17e6b 9364do_smc (void)
09d92015 9365{
3eb17e6b 9366 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9367 inst.reloc.pc_rel = 0;
09d92015
MM
9368}
9369
90ec0d68
MGD
9370static void
9371do_hvc (void)
9372{
9373 inst.reloc.type = BFD_RELOC_ARM_HVC;
9374 inst.reloc.pc_rel = 0;
9375}
9376
09d92015 9377static void
c19d1205 9378do_swi (void)
09d92015 9379{
c19d1205
ZW
9380 inst.reloc.type = BFD_RELOC_ARM_SWI;
9381 inst.reloc.pc_rel = 0;
09d92015
MM
9382}
9383
ddfded2f
MW
9384static void
9385do_setpan (void)
9386{
9387 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9388 _("selected processor does not support SETPAN instruction"));
9389
9390 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9391}
9392
9393static void
9394do_t_setpan (void)
9395{
9396 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9397 _("selected processor does not support SETPAN instruction"));
9398
9399 inst.instruction |= (inst.operands[0].imm << 3);
9400}
9401
c19d1205
ZW
9402/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9403 SMLAxy{cond} Rd,Rm,Rs,Rn
9404 SMLAWy{cond} Rd,Rm,Rs,Rn
9405 Error if any register is R15. */
e16bb312 9406
c19d1205
ZW
9407static void
9408do_smla (void)
e16bb312 9409{
c19d1205
ZW
9410 inst.instruction |= inst.operands[0].reg << 16;
9411 inst.instruction |= inst.operands[1].reg;
9412 inst.instruction |= inst.operands[2].reg << 8;
9413 inst.instruction |= inst.operands[3].reg << 12;
9414}
a737bd4d 9415
c19d1205
ZW
9416/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9417 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9418 Error if any register is R15.
9419 Warning if Rdlo == Rdhi. */
a737bd4d 9420
c19d1205
ZW
9421static void
9422do_smlal (void)
9423{
9424 inst.instruction |= inst.operands[0].reg << 12;
9425 inst.instruction |= inst.operands[1].reg << 16;
9426 inst.instruction |= inst.operands[2].reg;
9427 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9428
c19d1205
ZW
9429 if (inst.operands[0].reg == inst.operands[1].reg)
9430 as_tsktsk (_("rdhi and rdlo must be different"));
9431}
a737bd4d 9432
c19d1205
ZW
9433/* ARM V5E (El Segundo) signed-multiply (argument parse)
9434 SMULxy{cond} Rd,Rm,Rs
9435 Error if any register is R15. */
a737bd4d 9436
c19d1205
ZW
9437static void
9438do_smul (void)
9439{
9440 inst.instruction |= inst.operands[0].reg << 16;
9441 inst.instruction |= inst.operands[1].reg;
9442 inst.instruction |= inst.operands[2].reg << 8;
9443}
a737bd4d 9444
b6702015
PB
9445/* ARM V6 srs (argument parse). The variable fields in the encoding are
9446 the same for both ARM and Thumb-2. */
a737bd4d 9447
c19d1205
ZW
9448static void
9449do_srs (void)
9450{
b6702015
PB
9451 int reg;
9452
9453 if (inst.operands[0].present)
9454 {
9455 reg = inst.operands[0].reg;
fdfde340 9456 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9457 }
9458 else
fdfde340 9459 reg = REG_SP;
b6702015
PB
9460
9461 inst.instruction |= reg << 16;
9462 inst.instruction |= inst.operands[1].imm;
9463 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9464 inst.instruction |= WRITE_BACK;
9465}
a737bd4d 9466
c19d1205 9467/* ARM V6 strex (argument parse). */
a737bd4d 9468
c19d1205
ZW
9469static void
9470do_strex (void)
9471{
9472 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9473 || inst.operands[2].postind || inst.operands[2].writeback
9474 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9475 || inst.operands[2].negative
9476 /* See comment in do_ldrex(). */
9477 || (inst.operands[2].reg == REG_PC),
9478 BAD_ADDR_MODE);
a737bd4d 9479
c19d1205
ZW
9480 constraint (inst.operands[0].reg == inst.operands[1].reg
9481 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9482
c19d1205
ZW
9483 constraint (inst.reloc.exp.X_op != O_constant
9484 || inst.reloc.exp.X_add_number != 0,
9485 _("offset must be zero in ARM encoding"));
a737bd4d 9486
c19d1205
ZW
9487 inst.instruction |= inst.operands[0].reg << 12;
9488 inst.instruction |= inst.operands[1].reg;
9489 inst.instruction |= inst.operands[2].reg << 16;
9490 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9491}
9492
877807f8
NC
9493static void
9494do_t_strexbh (void)
9495{
9496 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9497 || inst.operands[2].postind || inst.operands[2].writeback
9498 || inst.operands[2].immisreg || inst.operands[2].shifted
9499 || inst.operands[2].negative,
9500 BAD_ADDR_MODE);
9501
9502 constraint (inst.operands[0].reg == inst.operands[1].reg
9503 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9504
9505 do_rm_rd_rn ();
9506}
9507
e16bb312 9508static void
c19d1205 9509do_strexd (void)
e16bb312 9510{
c19d1205
ZW
9511 constraint (inst.operands[1].reg % 2 != 0,
9512 _("even register required"));
9513 constraint (inst.operands[2].present
9514 && inst.operands[2].reg != inst.operands[1].reg + 1,
9515 _("can only store two consecutive registers"));
9516 /* If op 2 were present and equal to PC, this function wouldn't
9517 have been called in the first place. */
9518 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9519
c19d1205
ZW
9520 constraint (inst.operands[0].reg == inst.operands[1].reg
9521 || inst.operands[0].reg == inst.operands[1].reg + 1
9522 || inst.operands[0].reg == inst.operands[3].reg,
9523 BAD_OVERLAP);
e16bb312 9524
c19d1205
ZW
9525 inst.instruction |= inst.operands[0].reg << 12;
9526 inst.instruction |= inst.operands[1].reg;
9527 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9528}
9529
9eb6c0f1
MGD
9530/* ARM V8 STRL. */
9531static void
4b8c8c02 9532do_stlex (void)
9eb6c0f1
MGD
9533{
9534 constraint (inst.operands[0].reg == inst.operands[1].reg
9535 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9536
9537 do_rd_rm_rn ();
9538}
9539
9540static void
4b8c8c02 9541do_t_stlex (void)
9eb6c0f1
MGD
9542{
9543 constraint (inst.operands[0].reg == inst.operands[1].reg
9544 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9545
9546 do_rm_rd_rn ();
9547}
9548
c19d1205
ZW
9549/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9550 extends it to 32-bits, and adds the result to a value in another
9551 register. You can specify a rotation by 0, 8, 16, or 24 bits
9552 before extracting the 16-bit value.
9553 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9554 Condition defaults to COND_ALWAYS.
9555 Error if any register uses R15. */
9556
e16bb312 9557static void
c19d1205 9558do_sxtah (void)
e16bb312 9559{
c19d1205
ZW
9560 inst.instruction |= inst.operands[0].reg << 12;
9561 inst.instruction |= inst.operands[1].reg << 16;
9562 inst.instruction |= inst.operands[2].reg;
9563 inst.instruction |= inst.operands[3].imm << 10;
9564}
e16bb312 9565
c19d1205 9566/* ARM V6 SXTH.
e16bb312 9567
c19d1205
ZW
9568 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9569 Condition defaults to COND_ALWAYS.
9570 Error if any register uses R15. */
e16bb312
NC
9571
9572static void
c19d1205 9573do_sxth (void)
e16bb312 9574{
c19d1205
ZW
9575 inst.instruction |= inst.operands[0].reg << 12;
9576 inst.instruction |= inst.operands[1].reg;
9577 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9578}
c19d1205
ZW
9579\f
9580/* VFP instructions. In a logical order: SP variant first, monad
9581 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9582
9583static void
c19d1205 9584do_vfp_sp_monadic (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_Sm);
e16bb312
NC
9588}
9589
9590static void
c19d1205 9591do_vfp_sp_dyadic (void)
e16bb312 9592{
5287ad62
JB
9593 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9594 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9595 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9596}
9597
9598static void
c19d1205 9599do_vfp_sp_compare_z (void)
e16bb312 9600{
5287ad62 9601 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9602}
9603
9604static void
c19d1205 9605do_vfp_dp_sp_cvt (void)
e16bb312 9606{
5287ad62
JB
9607 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9608 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9609}
9610
9611static void
c19d1205 9612do_vfp_sp_dp_cvt (void)
e16bb312 9613{
5287ad62
JB
9614 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9615 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9616}
9617
9618static void
c19d1205 9619do_vfp_reg_from_sp (void)
e16bb312 9620{
c19d1205 9621 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9622 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9623}
9624
9625static void
c19d1205 9626do_vfp_reg2_from_sp2 (void)
e16bb312 9627{
c19d1205
ZW
9628 constraint (inst.operands[2].imm != 2,
9629 _("only two consecutive VFP SP registers allowed here"));
9630 inst.instruction |= inst.operands[0].reg << 12;
9631 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9632 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9633}
9634
9635static void
c19d1205 9636do_vfp_sp_from_reg (void)
e16bb312 9637{
5287ad62 9638 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9639 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9640}
9641
9642static void
c19d1205 9643do_vfp_sp2_from_reg2 (void)
e16bb312 9644{
c19d1205
ZW
9645 constraint (inst.operands[0].imm != 2,
9646 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9647 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9648 inst.instruction |= inst.operands[1].reg << 12;
9649 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9650}
9651
9652static void
c19d1205 9653do_vfp_sp_ldst (void)
e16bb312 9654{
5287ad62 9655 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9656 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9657}
9658
9659static void
c19d1205 9660do_vfp_dp_ldst (void)
e16bb312 9661{
5287ad62 9662 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9663 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9664}
9665
c19d1205 9666
e16bb312 9667static void
c19d1205 9668vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9669{
c19d1205
ZW
9670 if (inst.operands[0].writeback)
9671 inst.instruction |= WRITE_BACK;
9672 else
9673 constraint (ldstm_type != VFP_LDSTMIA,
9674 _("this addressing mode requires base-register writeback"));
9675 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9676 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9677 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9678}
9679
9680static void
c19d1205 9681vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9682{
c19d1205 9683 int count;
e16bb312 9684
c19d1205
ZW
9685 if (inst.operands[0].writeback)
9686 inst.instruction |= WRITE_BACK;
9687 else
9688 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9689 _("this addressing mode requires base-register writeback"));
e16bb312 9690
c19d1205 9691 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9692 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9693
c19d1205
ZW
9694 count = inst.operands[1].imm << 1;
9695 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9696 count += 1;
e16bb312 9697
c19d1205 9698 inst.instruction |= count;
e16bb312
NC
9699}
9700
9701static void
c19d1205 9702do_vfp_sp_ldstmia (void)
e16bb312 9703{
c19d1205 9704 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9705}
9706
9707static void
c19d1205 9708do_vfp_sp_ldstmdb (void)
e16bb312 9709{
c19d1205 9710 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9711}
9712
9713static void
c19d1205 9714do_vfp_dp_ldstmia (void)
e16bb312 9715{
c19d1205 9716 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9717}
9718
9719static void
c19d1205 9720do_vfp_dp_ldstmdb (void)
e16bb312 9721{
c19d1205 9722 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9723}
9724
9725static void
c19d1205 9726do_vfp_xp_ldstmia (void)
e16bb312 9727{
c19d1205
ZW
9728 vfp_dp_ldstm (VFP_LDSTMIAX);
9729}
e16bb312 9730
c19d1205
ZW
9731static void
9732do_vfp_xp_ldstmdb (void)
9733{
9734 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9735}
5287ad62
JB
9736
9737static void
9738do_vfp_dp_rd_rm (void)
9739{
9740 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9741 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9742}
9743
9744static void
9745do_vfp_dp_rn_rd (void)
9746{
9747 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9748 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9749}
9750
9751static void
9752do_vfp_dp_rd_rn (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}
9757
9758static void
9759do_vfp_dp_rd_rn_rm (void)
9760{
9761 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9762 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9763 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9764}
9765
9766static void
9767do_vfp_dp_rd (void)
9768{
9769 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9770}
9771
9772static void
9773do_vfp_dp_rm_rd_rn (void)
9774{
9775 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9777 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9778}
9779
9780/* VFPv3 instructions. */
9781static void
9782do_vfp_sp_const (void)
9783{
9784 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9785 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9786 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9787}
9788
9789static void
9790do_vfp_dp_const (void)
9791{
9792 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9793 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9794 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9795}
9796
9797static void
9798vfp_conv (int srcsize)
9799{
5f1af56b
MGD
9800 int immbits = srcsize - inst.operands[1].imm;
9801
fa94de6b
RM
9802 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9803 {
5f1af56b 9804 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9805 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9806 inst.error = _("immediate value out of range, expected range [0, 16]");
9807 return;
9808 }
fa94de6b 9809 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9810 {
9811 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9812 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9813 inst.error = _("immediate value out of range, expected range [1, 32]");
9814 return;
9815 }
9816
5287ad62
JB
9817 inst.instruction |= (immbits & 1) << 5;
9818 inst.instruction |= (immbits >> 1);
9819}
9820
9821static void
9822do_vfp_sp_conv_16 (void)
9823{
9824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9825 vfp_conv (16);
9826}
9827
9828static void
9829do_vfp_dp_conv_16 (void)
9830{
9831 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9832 vfp_conv (16);
9833}
9834
9835static void
9836do_vfp_sp_conv_32 (void)
9837{
9838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9839 vfp_conv (32);
9840}
9841
9842static void
9843do_vfp_dp_conv_32 (void)
9844{
9845 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9846 vfp_conv (32);
9847}
c19d1205
ZW
9848\f
9849/* FPA instructions. Also in a logical order. */
e16bb312 9850
c19d1205
ZW
9851static void
9852do_fpa_cmp (void)
9853{
9854 inst.instruction |= inst.operands[0].reg << 16;
9855 inst.instruction |= inst.operands[1].reg;
9856}
b99bd4ef
NC
9857
9858static void
c19d1205 9859do_fpa_ldmstm (void)
b99bd4ef 9860{
c19d1205
ZW
9861 inst.instruction |= inst.operands[0].reg << 12;
9862 switch (inst.operands[1].imm)
9863 {
9864 case 1: inst.instruction |= CP_T_X; break;
9865 case 2: inst.instruction |= CP_T_Y; break;
9866 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9867 case 4: break;
9868 default: abort ();
9869 }
b99bd4ef 9870
c19d1205
ZW
9871 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9872 {
9873 /* The instruction specified "ea" or "fd", so we can only accept
9874 [Rn]{!}. The instruction does not really support stacking or
9875 unstacking, so we have to emulate these by setting appropriate
9876 bits and offsets. */
9877 constraint (inst.reloc.exp.X_op != O_constant
9878 || inst.reloc.exp.X_add_number != 0,
9879 _("this instruction does not support indexing"));
b99bd4ef 9880
c19d1205
ZW
9881 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9882 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9883
c19d1205
ZW
9884 if (!(inst.instruction & INDEX_UP))
9885 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9886
c19d1205
ZW
9887 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9888 {
9889 inst.operands[2].preind = 0;
9890 inst.operands[2].postind = 1;
9891 }
9892 }
b99bd4ef 9893
c19d1205 9894 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9895}
c19d1205
ZW
9896\f
9897/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9898
c19d1205
ZW
9899static void
9900do_iwmmxt_tandorc (void)
9901{
9902 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9903}
b99bd4ef 9904
c19d1205
ZW
9905static void
9906do_iwmmxt_textrc (void)
9907{
9908 inst.instruction |= inst.operands[0].reg << 12;
9909 inst.instruction |= inst.operands[1].imm;
9910}
b99bd4ef
NC
9911
9912static void
c19d1205 9913do_iwmmxt_textrm (void)
b99bd4ef 9914{
c19d1205
ZW
9915 inst.instruction |= inst.operands[0].reg << 12;
9916 inst.instruction |= inst.operands[1].reg << 16;
9917 inst.instruction |= inst.operands[2].imm;
9918}
b99bd4ef 9919
c19d1205
ZW
9920static void
9921do_iwmmxt_tinsr (void)
9922{
9923 inst.instruction |= inst.operands[0].reg << 16;
9924 inst.instruction |= inst.operands[1].reg << 12;
9925 inst.instruction |= inst.operands[2].imm;
9926}
b99bd4ef 9927
c19d1205
ZW
9928static void
9929do_iwmmxt_tmia (void)
9930{
9931 inst.instruction |= inst.operands[0].reg << 5;
9932 inst.instruction |= inst.operands[1].reg;
9933 inst.instruction |= inst.operands[2].reg << 12;
9934}
b99bd4ef 9935
c19d1205
ZW
9936static void
9937do_iwmmxt_waligni (void)
9938{
9939 inst.instruction |= inst.operands[0].reg << 12;
9940 inst.instruction |= inst.operands[1].reg << 16;
9941 inst.instruction |= inst.operands[2].reg;
9942 inst.instruction |= inst.operands[3].imm << 20;
9943}
b99bd4ef 9944
2d447fca
JM
9945static void
9946do_iwmmxt_wmerge (void)
9947{
9948 inst.instruction |= inst.operands[0].reg << 12;
9949 inst.instruction |= inst.operands[1].reg << 16;
9950 inst.instruction |= inst.operands[2].reg;
9951 inst.instruction |= inst.operands[3].imm << 21;
9952}
9953
c19d1205
ZW
9954static void
9955do_iwmmxt_wmov (void)
9956{
9957 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9958 inst.instruction |= inst.operands[0].reg << 12;
9959 inst.instruction |= inst.operands[1].reg << 16;
9960 inst.instruction |= inst.operands[1].reg;
9961}
b99bd4ef 9962
c19d1205
ZW
9963static void
9964do_iwmmxt_wldstbh (void)
9965{
8f06b2d8 9966 int reloc;
c19d1205 9967 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9968 if (thumb_mode)
9969 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9970 else
9971 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9972 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9973}
9974
c19d1205
ZW
9975static void
9976do_iwmmxt_wldstw (void)
9977{
9978 /* RIWR_RIWC clears .isreg for a control register. */
9979 if (!inst.operands[0].isreg)
9980 {
9981 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9982 inst.instruction |= 0xf0000000;
9983 }
b99bd4ef 9984
c19d1205
ZW
9985 inst.instruction |= inst.operands[0].reg << 12;
9986 encode_arm_cp_address (1, TRUE, TRUE, 0);
9987}
b99bd4ef
NC
9988
9989static void
c19d1205 9990do_iwmmxt_wldstd (void)
b99bd4ef 9991{
c19d1205 9992 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9993 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9994 && inst.operands[1].immisreg)
9995 {
9996 inst.instruction &= ~0x1a000ff;
eff0bc54 9997 inst.instruction |= (0xfU << 28);
2d447fca
JM
9998 if (inst.operands[1].preind)
9999 inst.instruction |= PRE_INDEX;
10000 if (!inst.operands[1].negative)
10001 inst.instruction |= INDEX_UP;
10002 if (inst.operands[1].writeback)
10003 inst.instruction |= WRITE_BACK;
10004 inst.instruction |= inst.operands[1].reg << 16;
10005 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10006 inst.instruction |= inst.operands[1].imm;
10007 }
10008 else
10009 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10010}
b99bd4ef 10011
c19d1205
ZW
10012static void
10013do_iwmmxt_wshufh (void)
10014{
10015 inst.instruction |= inst.operands[0].reg << 12;
10016 inst.instruction |= inst.operands[1].reg << 16;
10017 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10018 inst.instruction |= (inst.operands[2].imm & 0x0f);
10019}
b99bd4ef 10020
c19d1205
ZW
10021static void
10022do_iwmmxt_wzero (void)
10023{
10024 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10025 inst.instruction |= inst.operands[0].reg;
10026 inst.instruction |= inst.operands[0].reg << 12;
10027 inst.instruction |= inst.operands[0].reg << 16;
10028}
2d447fca
JM
10029
10030static void
10031do_iwmmxt_wrwrwr_or_imm5 (void)
10032{
10033 if (inst.operands[2].isreg)
10034 do_rd_rn_rm ();
10035 else {
10036 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10037 _("immediate operand requires iWMMXt2"));
10038 do_rd_rn ();
10039 if (inst.operands[2].imm == 0)
10040 {
10041 switch ((inst.instruction >> 20) & 0xf)
10042 {
10043 case 4:
10044 case 5:
10045 case 6:
5f4273c7 10046 case 7:
2d447fca
JM
10047 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10048 inst.operands[2].imm = 16;
10049 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10050 break;
10051 case 8:
10052 case 9:
10053 case 10:
10054 case 11:
10055 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10056 inst.operands[2].imm = 32;
10057 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10058 break;
10059 case 12:
10060 case 13:
10061 case 14:
10062 case 15:
10063 {
10064 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10065 unsigned long wrn;
10066 wrn = (inst.instruction >> 16) & 0xf;
10067 inst.instruction &= 0xff0fff0f;
10068 inst.instruction |= wrn;
10069 /* Bail out here; the instruction is now assembled. */
10070 return;
10071 }
10072 }
10073 }
10074 /* Map 32 -> 0, etc. */
10075 inst.operands[2].imm &= 0x1f;
eff0bc54 10076 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10077 }
10078}
c19d1205
ZW
10079\f
10080/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10081 operations first, then control, shift, and load/store. */
b99bd4ef 10082
c19d1205 10083/* Insns like "foo X,Y,Z". */
b99bd4ef 10084
c19d1205
ZW
10085static void
10086do_mav_triple (void)
10087{
10088 inst.instruction |= inst.operands[0].reg << 16;
10089 inst.instruction |= inst.operands[1].reg;
10090 inst.instruction |= inst.operands[2].reg << 12;
10091}
b99bd4ef 10092
c19d1205
ZW
10093/* Insns like "foo W,X,Y,Z".
10094 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10095
c19d1205
ZW
10096static void
10097do_mav_quad (void)
10098{
10099 inst.instruction |= inst.operands[0].reg << 5;
10100 inst.instruction |= inst.operands[1].reg << 12;
10101 inst.instruction |= inst.operands[2].reg << 16;
10102 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10103}
10104
c19d1205
ZW
10105/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10106static void
10107do_mav_dspsc (void)
a737bd4d 10108{
c19d1205
ZW
10109 inst.instruction |= inst.operands[1].reg << 12;
10110}
a737bd4d 10111
c19d1205
ZW
10112/* Maverick shift immediate instructions.
10113 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10114 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10115
c19d1205
ZW
10116static void
10117do_mav_shift (void)
10118{
10119 int imm = inst.operands[2].imm;
a737bd4d 10120
c19d1205
ZW
10121 inst.instruction |= inst.operands[0].reg << 12;
10122 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10123
c19d1205
ZW
10124 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10125 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10126 Bit 4 should be 0. */
10127 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10128
c19d1205
ZW
10129 inst.instruction |= imm;
10130}
10131\f
10132/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10133
c19d1205
ZW
10134/* Xscale multiply-accumulate (argument parse)
10135 MIAcc acc0,Rm,Rs
10136 MIAPHcc acc0,Rm,Rs
10137 MIAxycc acc0,Rm,Rs. */
a737bd4d 10138
c19d1205
ZW
10139static void
10140do_xsc_mia (void)
10141{
10142 inst.instruction |= inst.operands[1].reg;
10143 inst.instruction |= inst.operands[2].reg << 12;
10144}
a737bd4d 10145
c19d1205 10146/* Xscale move-accumulator-register (argument parse)
a737bd4d 10147
c19d1205 10148 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10149
c19d1205
ZW
10150static void
10151do_xsc_mar (void)
10152{
10153 inst.instruction |= inst.operands[1].reg << 12;
10154 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10155}
10156
c19d1205 10157/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10158
c19d1205 10159 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10160
10161static void
c19d1205 10162do_xsc_mra (void)
b99bd4ef 10163{
c19d1205
ZW
10164 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10165 inst.instruction |= inst.operands[0].reg << 12;
10166 inst.instruction |= inst.operands[1].reg << 16;
10167}
10168\f
10169/* Encoding functions relevant only to Thumb. */
b99bd4ef 10170
c19d1205
ZW
10171/* inst.operands[i] is a shifted-register operand; encode
10172 it into inst.instruction in the format used by Thumb32. */
10173
10174static void
10175encode_thumb32_shifted_operand (int i)
10176{
10177 unsigned int value = inst.reloc.exp.X_add_number;
10178 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10179
9c3c69f2
PB
10180 constraint (inst.operands[i].immisreg,
10181 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10182 inst.instruction |= inst.operands[i].reg;
10183 if (shift == SHIFT_RRX)
10184 inst.instruction |= SHIFT_ROR << 4;
10185 else
b99bd4ef 10186 {
c19d1205
ZW
10187 constraint (inst.reloc.exp.X_op != O_constant,
10188 _("expression too complex"));
10189
10190 constraint (value > 32
10191 || (value == 32 && (shift == SHIFT_LSL
10192 || shift == SHIFT_ROR)),
10193 _("shift expression is too large"));
10194
10195 if (value == 0)
10196 shift = SHIFT_LSL;
10197 else if (value == 32)
10198 value = 0;
10199
10200 inst.instruction |= shift << 4;
10201 inst.instruction |= (value & 0x1c) << 10;
10202 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10203 }
c19d1205 10204}
b99bd4ef 10205
b99bd4ef 10206
c19d1205
ZW
10207/* inst.operands[i] was set up by parse_address. Encode it into a
10208 Thumb32 format load or store instruction. Reject forms that cannot
10209 be used with such instructions. If is_t is true, reject forms that
10210 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10211 that cannot be used with a D instruction. If it is a store insn,
10212 reject PC in Rn. */
b99bd4ef 10213
c19d1205
ZW
10214static void
10215encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10216{
5be8be5d 10217 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10218
10219 constraint (!inst.operands[i].isreg,
53365c0d 10220 _("Instruction does not support =N addresses"));
b99bd4ef 10221
c19d1205
ZW
10222 inst.instruction |= inst.operands[i].reg << 16;
10223 if (inst.operands[i].immisreg)
b99bd4ef 10224 {
5be8be5d 10225 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10226 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10227 constraint (inst.operands[i].negative,
10228 _("Thumb does not support negative register indexing"));
10229 constraint (inst.operands[i].postind,
10230 _("Thumb does not support register post-indexing"));
10231 constraint (inst.operands[i].writeback,
10232 _("Thumb does not support register indexing with writeback"));
10233 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10234 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10235
f40d1643 10236 inst.instruction |= inst.operands[i].imm;
c19d1205 10237 if (inst.operands[i].shifted)
b99bd4ef 10238 {
c19d1205
ZW
10239 constraint (inst.reloc.exp.X_op != O_constant,
10240 _("expression too complex"));
9c3c69f2
PB
10241 constraint (inst.reloc.exp.X_add_number < 0
10242 || inst.reloc.exp.X_add_number > 3,
c19d1205 10243 _("shift out of range"));
9c3c69f2 10244 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10245 }
10246 inst.reloc.type = BFD_RELOC_UNUSED;
10247 }
10248 else if (inst.operands[i].preind)
10249 {
5be8be5d 10250 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10251 constraint (is_t && inst.operands[i].writeback,
c19d1205 10252 _("cannot use writeback with this instruction"));
4755303e
WN
10253 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10254 BAD_PC_ADDRESSING);
c19d1205
ZW
10255
10256 if (is_d)
10257 {
10258 inst.instruction |= 0x01000000;
10259 if (inst.operands[i].writeback)
10260 inst.instruction |= 0x00200000;
b99bd4ef 10261 }
c19d1205 10262 else
b99bd4ef 10263 {
c19d1205
ZW
10264 inst.instruction |= 0x00000c00;
10265 if (inst.operands[i].writeback)
10266 inst.instruction |= 0x00000100;
b99bd4ef 10267 }
c19d1205 10268 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10269 }
c19d1205 10270 else if (inst.operands[i].postind)
b99bd4ef 10271 {
9c2799c2 10272 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10273 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10274 constraint (is_t, _("cannot use post-indexing with this instruction"));
10275
10276 if (is_d)
10277 inst.instruction |= 0x00200000;
10278 else
10279 inst.instruction |= 0x00000900;
10280 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10281 }
10282 else /* unindexed - only for coprocessor */
10283 inst.error = _("instruction does not accept unindexed addressing");
10284}
10285
10286/* Table of Thumb instructions which exist in both 16- and 32-bit
10287 encodings (the latter only in post-V6T2 cores). The index is the
10288 value used in the insns table below. When there is more than one
10289 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10290 holds variant (1).
10291 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10292#define T16_32_TAB \
21d799b5
NC
10293 X(_adc, 4140, eb400000), \
10294 X(_adcs, 4140, eb500000), \
10295 X(_add, 1c00, eb000000), \
10296 X(_adds, 1c00, eb100000), \
10297 X(_addi, 0000, f1000000), \
10298 X(_addis, 0000, f1100000), \
10299 X(_add_pc,000f, f20f0000), \
10300 X(_add_sp,000d, f10d0000), \
10301 X(_adr, 000f, f20f0000), \
10302 X(_and, 4000, ea000000), \
10303 X(_ands, 4000, ea100000), \
10304 X(_asr, 1000, fa40f000), \
10305 X(_asrs, 1000, fa50f000), \
10306 X(_b, e000, f000b000), \
10307 X(_bcond, d000, f0008000), \
10308 X(_bic, 4380, ea200000), \
10309 X(_bics, 4380, ea300000), \
10310 X(_cmn, 42c0, eb100f00), \
10311 X(_cmp, 2800, ebb00f00), \
10312 X(_cpsie, b660, f3af8400), \
10313 X(_cpsid, b670, f3af8600), \
10314 X(_cpy, 4600, ea4f0000), \
10315 X(_dec_sp,80dd, f1ad0d00), \
10316 X(_eor, 4040, ea800000), \
10317 X(_eors, 4040, ea900000), \
10318 X(_inc_sp,00dd, f10d0d00), \
10319 X(_ldmia, c800, e8900000), \
10320 X(_ldr, 6800, f8500000), \
10321 X(_ldrb, 7800, f8100000), \
10322 X(_ldrh, 8800, f8300000), \
10323 X(_ldrsb, 5600, f9100000), \
10324 X(_ldrsh, 5e00, f9300000), \
10325 X(_ldr_pc,4800, f85f0000), \
10326 X(_ldr_pc2,4800, f85f0000), \
10327 X(_ldr_sp,9800, f85d0000), \
10328 X(_lsl, 0000, fa00f000), \
10329 X(_lsls, 0000, fa10f000), \
10330 X(_lsr, 0800, fa20f000), \
10331 X(_lsrs, 0800, fa30f000), \
10332 X(_mov, 2000, ea4f0000), \
10333 X(_movs, 2000, ea5f0000), \
10334 X(_mul, 4340, fb00f000), \
10335 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10336 X(_mvn, 43c0, ea6f0000), \
10337 X(_mvns, 43c0, ea7f0000), \
10338 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10339 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10340 X(_orr, 4300, ea400000), \
10341 X(_orrs, 4300, ea500000), \
10342 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10343 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10344 X(_rev, ba00, fa90f080), \
10345 X(_rev16, ba40, fa90f090), \
10346 X(_revsh, bac0, fa90f0b0), \
10347 X(_ror, 41c0, fa60f000), \
10348 X(_rors, 41c0, fa70f000), \
10349 X(_sbc, 4180, eb600000), \
10350 X(_sbcs, 4180, eb700000), \
10351 X(_stmia, c000, e8800000), \
10352 X(_str, 6000, f8400000), \
10353 X(_strb, 7000, f8000000), \
10354 X(_strh, 8000, f8200000), \
10355 X(_str_sp,9000, f84d0000), \
10356 X(_sub, 1e00, eba00000), \
10357 X(_subs, 1e00, ebb00000), \
10358 X(_subi, 8000, f1a00000), \
10359 X(_subis, 8000, f1b00000), \
10360 X(_sxtb, b240, fa4ff080), \
10361 X(_sxth, b200, fa0ff080), \
10362 X(_tst, 4200, ea100f00), \
10363 X(_uxtb, b2c0, fa5ff080), \
10364 X(_uxth, b280, fa1ff080), \
10365 X(_nop, bf00, f3af8000), \
10366 X(_yield, bf10, f3af8001), \
10367 X(_wfe, bf20, f3af8002), \
10368 X(_wfi, bf30, f3af8003), \
53c4b28b 10369 X(_sev, bf40, f3af8004), \
74db7efb
NC
10370 X(_sevl, bf50, f3af8005), \
10371 X(_udf, de00, f7f0a000)
c19d1205
ZW
10372
10373/* To catch errors in encoding functions, the codes are all offset by
10374 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10375 as 16-bit instructions. */
21d799b5 10376#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10377enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10378#undef X
10379
10380#define X(a,b,c) 0x##b
10381static const unsigned short thumb_op16[] = { T16_32_TAB };
10382#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10383#undef X
10384
10385#define X(a,b,c) 0x##c
10386static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10387#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10388#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10389#undef X
10390#undef T16_32_TAB
10391
10392/* Thumb instruction encoders, in alphabetical order. */
10393
92e90b6e 10394/* ADDW or SUBW. */
c921be7d 10395
92e90b6e
PB
10396static void
10397do_t_add_sub_w (void)
10398{
10399 int Rd, Rn;
10400
10401 Rd = inst.operands[0].reg;
10402 Rn = inst.operands[1].reg;
10403
539d4391
NC
10404 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10405 is the SP-{plus,minus}-immediate form of the instruction. */
10406 if (Rn == REG_SP)
10407 constraint (Rd == REG_PC, BAD_PC);
10408 else
10409 reject_bad_reg (Rd);
fdfde340 10410
92e90b6e
PB
10411 inst.instruction |= (Rn << 16) | (Rd << 8);
10412 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10413}
10414
c19d1205
ZW
10415/* Parse an add or subtract instruction. We get here with inst.instruction
10416 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10417
10418static void
10419do_t_add_sub (void)
10420{
10421 int Rd, Rs, Rn;
10422
10423 Rd = inst.operands[0].reg;
10424 Rs = (inst.operands[1].present
10425 ? inst.operands[1].reg /* Rd, Rs, foo */
10426 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10427
e07e6e58
NC
10428 if (Rd == REG_PC)
10429 set_it_insn_type_last ();
10430
c19d1205
ZW
10431 if (unified_syntax)
10432 {
0110f2b8
PB
10433 bfd_boolean flags;
10434 bfd_boolean narrow;
10435 int opcode;
10436
10437 flags = (inst.instruction == T_MNEM_adds
10438 || inst.instruction == T_MNEM_subs);
10439 if (flags)
e07e6e58 10440 narrow = !in_it_block ();
0110f2b8 10441 else
e07e6e58 10442 narrow = in_it_block ();
c19d1205 10443 if (!inst.operands[2].isreg)
b99bd4ef 10444 {
16805f35
PB
10445 int add;
10446
fdfde340
JM
10447 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10448
16805f35
PB
10449 add = (inst.instruction == T_MNEM_add
10450 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10451 opcode = 0;
10452 if (inst.size_req != 4)
10453 {
0110f2b8 10454 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10455 appropriate. */
0110f2b8
PB
10456 if (Rd == REG_SP && Rs == REG_SP && !flags)
10457 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10458 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10459 opcode = T_MNEM_add_sp;
10460 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10461 opcode = T_MNEM_add_pc;
10462 else if (Rd <= 7 && Rs <= 7 && narrow)
10463 {
10464 if (flags)
10465 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10466 else
10467 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10468 }
10469 if (opcode)
10470 {
10471 inst.instruction = THUMB_OP16(opcode);
10472 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10473 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10474 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
10475 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
0110f2b8
PB
10476 if (inst.size_req != 2)
10477 inst.relax = opcode;
10478 }
10479 else
10480 constraint (inst.size_req == 2, BAD_HIREG);
10481 }
10482 if (inst.size_req == 4
10483 || (inst.size_req != 2 && !opcode))
10484 {
efd81785
PB
10485 if (Rd == REG_PC)
10486 {
fdfde340 10487 constraint (add, BAD_PC);
efd81785
PB
10488 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10489 _("only SUBS PC, LR, #const allowed"));
10490 constraint (inst.reloc.exp.X_op != O_constant,
10491 _("expression too complex"));
10492 constraint (inst.reloc.exp.X_add_number < 0
10493 || inst.reloc.exp.X_add_number > 0xff,
10494 _("immediate value out of range"));
10495 inst.instruction = T2_SUBS_PC_LR
10496 | inst.reloc.exp.X_add_number;
10497 inst.reloc.type = BFD_RELOC_UNUSED;
10498 return;
10499 }
10500 else if (Rs == REG_PC)
16805f35
PB
10501 {
10502 /* Always use addw/subw. */
10503 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10504 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10505 }
10506 else
10507 {
10508 inst.instruction = THUMB_OP32 (inst.instruction);
10509 inst.instruction = (inst.instruction & 0xe1ffffff)
10510 | 0x10000000;
10511 if (flags)
10512 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10513 else
10514 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10515 }
dc4503c6
PB
10516 inst.instruction |= Rd << 8;
10517 inst.instruction |= Rs << 16;
0110f2b8 10518 }
b99bd4ef 10519 }
c19d1205
ZW
10520 else
10521 {
5f4cb198
NC
10522 unsigned int value = inst.reloc.exp.X_add_number;
10523 unsigned int shift = inst.operands[2].shift_kind;
10524
c19d1205
ZW
10525 Rn = inst.operands[2].reg;
10526 /* See if we can do this with a 16-bit instruction. */
10527 if (!inst.operands[2].shifted && inst.size_req != 4)
10528 {
e27ec89e
PB
10529 if (Rd > 7 || Rs > 7 || Rn > 7)
10530 narrow = FALSE;
10531
10532 if (narrow)
c19d1205 10533 {
e27ec89e
PB
10534 inst.instruction = ((inst.instruction == T_MNEM_adds
10535 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10536 ? T_OPCODE_ADD_R3
10537 : T_OPCODE_SUB_R3);
10538 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10539 return;
10540 }
b99bd4ef 10541
7e806470 10542 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10543 {
7e806470
PB
10544 /* Thumb-1 cores (except v6-M) require at least one high
10545 register in a narrow non flag setting add. */
10546 if (Rd > 7 || Rn > 7
10547 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10548 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10549 {
7e806470
PB
10550 if (Rd == Rn)
10551 {
10552 Rn = Rs;
10553 Rs = Rd;
10554 }
c19d1205
ZW
10555 inst.instruction = T_OPCODE_ADD_HI;
10556 inst.instruction |= (Rd & 8) << 4;
10557 inst.instruction |= (Rd & 7);
10558 inst.instruction |= Rn << 3;
10559 return;
10560 }
c19d1205
ZW
10561 }
10562 }
c921be7d 10563
fdfde340
JM
10564 constraint (Rd == REG_PC, BAD_PC);
10565 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10566 constraint (Rs == REG_PC, BAD_PC);
10567 reject_bad_reg (Rn);
10568
c19d1205
ZW
10569 /* If we get here, it can't be done in 16 bits. */
10570 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10571 _("shift must be constant"));
10572 inst.instruction = THUMB_OP32 (inst.instruction);
10573 inst.instruction |= Rd << 8;
10574 inst.instruction |= Rs << 16;
5f4cb198
NC
10575 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10576 _("shift value over 3 not allowed in thumb mode"));
10577 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10578 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10579 encode_thumb32_shifted_operand (2);
10580 }
10581 }
10582 else
10583 {
10584 constraint (inst.instruction == T_MNEM_adds
10585 || inst.instruction == T_MNEM_subs,
10586 BAD_THUMB32);
b99bd4ef 10587
c19d1205 10588 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10589 {
c19d1205
ZW
10590 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10591 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10592 BAD_HIREG);
10593
10594 inst.instruction = (inst.instruction == T_MNEM_add
10595 ? 0x0000 : 0x8000);
10596 inst.instruction |= (Rd << 4) | Rs;
10597 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10598 return;
10599 }
10600
c19d1205
ZW
10601 Rn = inst.operands[2].reg;
10602 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10603
c19d1205
ZW
10604 /* We now have Rd, Rs, and Rn set to registers. */
10605 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10606 {
c19d1205
ZW
10607 /* Can't do this for SUB. */
10608 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10609 inst.instruction = T_OPCODE_ADD_HI;
10610 inst.instruction |= (Rd & 8) << 4;
10611 inst.instruction |= (Rd & 7);
10612 if (Rs == Rd)
10613 inst.instruction |= Rn << 3;
10614 else if (Rn == Rd)
10615 inst.instruction |= Rs << 3;
10616 else
10617 constraint (1, _("dest must overlap one source register"));
10618 }
10619 else
10620 {
10621 inst.instruction = (inst.instruction == T_MNEM_add
10622 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10623 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10624 }
b99bd4ef 10625 }
b99bd4ef
NC
10626}
10627
c19d1205
ZW
10628static void
10629do_t_adr (void)
10630{
fdfde340
JM
10631 unsigned Rd;
10632
10633 Rd = inst.operands[0].reg;
10634 reject_bad_reg (Rd);
10635
10636 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10637 {
10638 /* Defer to section relaxation. */
10639 inst.relax = inst.instruction;
10640 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10641 inst.instruction |= Rd << 4;
0110f2b8
PB
10642 }
10643 else if (unified_syntax && inst.size_req != 2)
e9f89963 10644 {
0110f2b8 10645 /* Generate a 32-bit opcode. */
e9f89963 10646 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10647 inst.instruction |= Rd << 8;
e9f89963
PB
10648 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10649 inst.reloc.pc_rel = 1;
10650 }
10651 else
10652 {
0110f2b8 10653 /* Generate a 16-bit opcode. */
e9f89963
PB
10654 inst.instruction = THUMB_OP16 (inst.instruction);
10655 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10656 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10657 inst.reloc.pc_rel = 1;
b99bd4ef 10658
fdfde340 10659 inst.instruction |= Rd << 4;
e9f89963 10660 }
c19d1205 10661}
b99bd4ef 10662
c19d1205
ZW
10663/* Arithmetic instructions for which there is just one 16-bit
10664 instruction encoding, and it allows only two low registers.
10665 For maximal compatibility with ARM syntax, we allow three register
10666 operands even when Thumb-32 instructions are not available, as long
10667 as the first two are identical. For instance, both "sbc r0,r1" and
10668 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10669static void
c19d1205 10670do_t_arit3 (void)
b99bd4ef 10671{
c19d1205 10672 int Rd, Rs, Rn;
b99bd4ef 10673
c19d1205
ZW
10674 Rd = inst.operands[0].reg;
10675 Rs = (inst.operands[1].present
10676 ? inst.operands[1].reg /* Rd, Rs, foo */
10677 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10678 Rn = inst.operands[2].reg;
b99bd4ef 10679
fdfde340
JM
10680 reject_bad_reg (Rd);
10681 reject_bad_reg (Rs);
10682 if (inst.operands[2].isreg)
10683 reject_bad_reg (Rn);
10684
c19d1205 10685 if (unified_syntax)
b99bd4ef 10686 {
c19d1205
ZW
10687 if (!inst.operands[2].isreg)
10688 {
10689 /* For an immediate, we always generate a 32-bit opcode;
10690 section relaxation will shrink it later if possible. */
10691 inst.instruction = THUMB_OP32 (inst.instruction);
10692 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10693 inst.instruction |= Rd << 8;
10694 inst.instruction |= Rs << 16;
10695 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10696 }
10697 else
10698 {
e27ec89e
PB
10699 bfd_boolean narrow;
10700
c19d1205 10701 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10702 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10703 narrow = !in_it_block ();
e27ec89e 10704 else
e07e6e58 10705 narrow = in_it_block ();
e27ec89e
PB
10706
10707 if (Rd > 7 || Rn > 7 || Rs > 7)
10708 narrow = FALSE;
10709 if (inst.operands[2].shifted)
10710 narrow = FALSE;
10711 if (inst.size_req == 4)
10712 narrow = FALSE;
10713
10714 if (narrow
c19d1205
ZW
10715 && Rd == Rs)
10716 {
10717 inst.instruction = THUMB_OP16 (inst.instruction);
10718 inst.instruction |= Rd;
10719 inst.instruction |= Rn << 3;
10720 return;
10721 }
b99bd4ef 10722
c19d1205
ZW
10723 /* If we get here, it can't be done in 16 bits. */
10724 constraint (inst.operands[2].shifted
10725 && inst.operands[2].immisreg,
10726 _("shift must be constant"));
10727 inst.instruction = THUMB_OP32 (inst.instruction);
10728 inst.instruction |= Rd << 8;
10729 inst.instruction |= Rs << 16;
10730 encode_thumb32_shifted_operand (2);
10731 }
a737bd4d 10732 }
c19d1205 10733 else
b99bd4ef 10734 {
c19d1205
ZW
10735 /* On its face this is a lie - the instruction does set the
10736 flags. However, the only supported mnemonic in this mode
10737 says it doesn't. */
10738 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10739
c19d1205
ZW
10740 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10741 _("unshifted register required"));
10742 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10743 constraint (Rd != Rs,
10744 _("dest and source1 must be the same register"));
a737bd4d 10745
c19d1205
ZW
10746 inst.instruction = THUMB_OP16 (inst.instruction);
10747 inst.instruction |= Rd;
10748 inst.instruction |= Rn << 3;
b99bd4ef 10749 }
a737bd4d 10750}
b99bd4ef 10751
c19d1205
ZW
10752/* Similarly, but for instructions where the arithmetic operation is
10753 commutative, so we can allow either of them to be different from
10754 the destination operand in a 16-bit instruction. For instance, all
10755 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10756 accepted. */
10757static void
10758do_t_arit3c (void)
a737bd4d 10759{
c19d1205 10760 int Rd, Rs, Rn;
b99bd4ef 10761
c19d1205
ZW
10762 Rd = inst.operands[0].reg;
10763 Rs = (inst.operands[1].present
10764 ? inst.operands[1].reg /* Rd, Rs, foo */
10765 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10766 Rn = inst.operands[2].reg;
c921be7d 10767
fdfde340
JM
10768 reject_bad_reg (Rd);
10769 reject_bad_reg (Rs);
10770 if (inst.operands[2].isreg)
10771 reject_bad_reg (Rn);
a737bd4d 10772
c19d1205 10773 if (unified_syntax)
a737bd4d 10774 {
c19d1205 10775 if (!inst.operands[2].isreg)
b99bd4ef 10776 {
c19d1205
ZW
10777 /* For an immediate, we always generate a 32-bit opcode;
10778 section relaxation will shrink it later if possible. */
10779 inst.instruction = THUMB_OP32 (inst.instruction);
10780 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10781 inst.instruction |= Rd << 8;
10782 inst.instruction |= Rs << 16;
10783 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10784 }
c19d1205 10785 else
a737bd4d 10786 {
e27ec89e
PB
10787 bfd_boolean narrow;
10788
c19d1205 10789 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10790 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10791 narrow = !in_it_block ();
e27ec89e 10792 else
e07e6e58 10793 narrow = in_it_block ();
e27ec89e
PB
10794
10795 if (Rd > 7 || Rn > 7 || Rs > 7)
10796 narrow = FALSE;
10797 if (inst.operands[2].shifted)
10798 narrow = FALSE;
10799 if (inst.size_req == 4)
10800 narrow = FALSE;
10801
10802 if (narrow)
a737bd4d 10803 {
c19d1205 10804 if (Rd == Rs)
a737bd4d 10805 {
c19d1205
ZW
10806 inst.instruction = THUMB_OP16 (inst.instruction);
10807 inst.instruction |= Rd;
10808 inst.instruction |= Rn << 3;
10809 return;
a737bd4d 10810 }
c19d1205 10811 if (Rd == Rn)
a737bd4d 10812 {
c19d1205
ZW
10813 inst.instruction = THUMB_OP16 (inst.instruction);
10814 inst.instruction |= Rd;
10815 inst.instruction |= Rs << 3;
10816 return;
a737bd4d
NC
10817 }
10818 }
c19d1205
ZW
10819
10820 /* If we get here, it can't be done in 16 bits. */
10821 constraint (inst.operands[2].shifted
10822 && inst.operands[2].immisreg,
10823 _("shift must be constant"));
10824 inst.instruction = THUMB_OP32 (inst.instruction);
10825 inst.instruction |= Rd << 8;
10826 inst.instruction |= Rs << 16;
10827 encode_thumb32_shifted_operand (2);
a737bd4d 10828 }
b99bd4ef 10829 }
c19d1205
ZW
10830 else
10831 {
10832 /* On its face this is a lie - the instruction does set the
10833 flags. However, the only supported mnemonic in this mode
10834 says it doesn't. */
10835 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10836
c19d1205
ZW
10837 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10838 _("unshifted register required"));
10839 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10840
10841 inst.instruction = THUMB_OP16 (inst.instruction);
10842 inst.instruction |= Rd;
10843
10844 if (Rd == Rs)
10845 inst.instruction |= Rn << 3;
10846 else if (Rd == Rn)
10847 inst.instruction |= Rs << 3;
10848 else
10849 constraint (1, _("dest must overlap one source register"));
10850 }
a737bd4d
NC
10851}
10852
c19d1205
ZW
10853static void
10854do_t_bfc (void)
a737bd4d 10855{
fdfde340 10856 unsigned Rd;
c19d1205
ZW
10857 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10858 constraint (msb > 32, _("bit-field extends past end of register"));
10859 /* The instruction encoding stores the LSB and MSB,
10860 not the LSB and width. */
fdfde340
JM
10861 Rd = inst.operands[0].reg;
10862 reject_bad_reg (Rd);
10863 inst.instruction |= Rd << 8;
c19d1205
ZW
10864 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10865 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10866 inst.instruction |= msb - 1;
b99bd4ef
NC
10867}
10868
c19d1205
ZW
10869static void
10870do_t_bfi (void)
b99bd4ef 10871{
fdfde340 10872 int Rd, Rn;
c19d1205 10873 unsigned int msb;
b99bd4ef 10874
fdfde340
JM
10875 Rd = inst.operands[0].reg;
10876 reject_bad_reg (Rd);
10877
c19d1205
ZW
10878 /* #0 in second position is alternative syntax for bfc, which is
10879 the same instruction but with REG_PC in the Rm field. */
10880 if (!inst.operands[1].isreg)
fdfde340
JM
10881 Rn = REG_PC;
10882 else
10883 {
10884 Rn = inst.operands[1].reg;
10885 reject_bad_reg (Rn);
10886 }
b99bd4ef 10887
c19d1205
ZW
10888 msb = inst.operands[2].imm + inst.operands[3].imm;
10889 constraint (msb > 32, _("bit-field extends past end of register"));
10890 /* The instruction encoding stores the LSB and MSB,
10891 not the LSB and width. */
fdfde340
JM
10892 inst.instruction |= Rd << 8;
10893 inst.instruction |= Rn << 16;
c19d1205
ZW
10894 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10895 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10896 inst.instruction |= msb - 1;
b99bd4ef
NC
10897}
10898
c19d1205
ZW
10899static void
10900do_t_bfx (void)
b99bd4ef 10901{
fdfde340
JM
10902 unsigned Rd, Rn;
10903
10904 Rd = inst.operands[0].reg;
10905 Rn = inst.operands[1].reg;
10906
10907 reject_bad_reg (Rd);
10908 reject_bad_reg (Rn);
10909
c19d1205
ZW
10910 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10911 _("bit-field extends past end of register"));
fdfde340
JM
10912 inst.instruction |= Rd << 8;
10913 inst.instruction |= Rn << 16;
c19d1205
ZW
10914 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10915 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10916 inst.instruction |= inst.operands[3].imm - 1;
10917}
b99bd4ef 10918
c19d1205
ZW
10919/* ARM V5 Thumb BLX (argument parse)
10920 BLX <target_addr> which is BLX(1)
10921 BLX <Rm> which is BLX(2)
10922 Unfortunately, there are two different opcodes for this mnemonic.
10923 So, the insns[].value is not used, and the code here zaps values
10924 into inst.instruction.
b99bd4ef 10925
c19d1205
ZW
10926 ??? How to take advantage of the additional two bits of displacement
10927 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10928
c19d1205
ZW
10929static void
10930do_t_blx (void)
10931{
e07e6e58
NC
10932 set_it_insn_type_last ();
10933
c19d1205 10934 if (inst.operands[0].isreg)
fdfde340
JM
10935 {
10936 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10937 /* We have a register, so this is BLX(2). */
10938 inst.instruction |= inst.operands[0].reg << 3;
10939 }
b99bd4ef
NC
10940 else
10941 {
c19d1205 10942 /* No register. This must be BLX(1). */
2fc8bdac 10943 inst.instruction = 0xf000e800;
0855e32b 10944 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10945 }
10946}
10947
c19d1205
ZW
10948static void
10949do_t_branch (void)
b99bd4ef 10950{
0110f2b8 10951 int opcode;
dfa9f0d5 10952 int cond;
9ae92b05 10953 int reloc;
dfa9f0d5 10954
e07e6e58
NC
10955 cond = inst.cond;
10956 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10957
10958 if (in_it_block ())
dfa9f0d5
PB
10959 {
10960 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10961 branches. */
dfa9f0d5 10962 cond = COND_ALWAYS;
dfa9f0d5
PB
10963 }
10964 else
10965 cond = inst.cond;
10966
10967 if (cond != COND_ALWAYS)
0110f2b8
PB
10968 opcode = T_MNEM_bcond;
10969 else
10970 opcode = inst.instruction;
10971
12d6b0b7
RS
10972 if (unified_syntax
10973 && (inst.size_req == 4
10960bfb
PB
10974 || (inst.size_req != 2
10975 && (inst.operands[0].hasreloc
10976 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10977 {
0110f2b8 10978 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10979 if (cond == COND_ALWAYS)
9ae92b05 10980 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10981 else
10982 {
ff8646ee
TP
10983 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
10984 _("selected architecture does not support "
10985 "wide conditional branch instruction"));
10986
9c2799c2 10987 gas_assert (cond != 0xF);
dfa9f0d5 10988 inst.instruction |= cond << 22;
9ae92b05 10989 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10990 }
10991 }
b99bd4ef
NC
10992 else
10993 {
0110f2b8 10994 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10995 if (cond == COND_ALWAYS)
9ae92b05 10996 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10997 else
b99bd4ef 10998 {
dfa9f0d5 10999 inst.instruction |= cond << 8;
9ae92b05 11000 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11001 }
0110f2b8
PB
11002 /* Allow section relaxation. */
11003 if (unified_syntax && inst.size_req != 2)
11004 inst.relax = opcode;
b99bd4ef 11005 }
9ae92b05 11006 inst.reloc.type = reloc;
c19d1205 11007 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11008}
11009
8884b720 11010/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11011 between the two is the maximum immediate allowed - which is passed in
8884b720 11012 RANGE. */
b99bd4ef 11013static void
8884b720 11014do_t_bkpt_hlt1 (int range)
b99bd4ef 11015{
dfa9f0d5
PB
11016 constraint (inst.cond != COND_ALWAYS,
11017 _("instruction is always unconditional"));
c19d1205 11018 if (inst.operands[0].present)
b99bd4ef 11019 {
8884b720 11020 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11021 _("immediate value out of range"));
11022 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11023 }
8884b720
MGD
11024
11025 set_it_insn_type (NEUTRAL_IT_INSN);
11026}
11027
11028static void
11029do_t_hlt (void)
11030{
11031 do_t_bkpt_hlt1 (63);
11032}
11033
11034static void
11035do_t_bkpt (void)
11036{
11037 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11038}
11039
11040static void
c19d1205 11041do_t_branch23 (void)
b99bd4ef 11042{
e07e6e58 11043 set_it_insn_type_last ();
0855e32b 11044 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11045
0855e32b
NS
11046 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11047 this file. We used to simply ignore the PLT reloc type here --
11048 the branch encoding is now needed to deal with TLSCALL relocs.
11049 So if we see a PLT reloc now, put it back to how it used to be to
11050 keep the preexisting behaviour. */
11051 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11052 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11053
4343666d 11054#if defined(OBJ_COFF)
c19d1205
ZW
11055 /* If the destination of the branch is a defined symbol which does not have
11056 the THUMB_FUNC attribute, then we must be calling a function which has
11057 the (interfacearm) attribute. We look for the Thumb entry point to that
11058 function and change the branch to refer to that function instead. */
11059 if ( inst.reloc.exp.X_op == O_symbol
11060 && inst.reloc.exp.X_add_symbol != NULL
11061 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11062 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11063 inst.reloc.exp.X_add_symbol =
11064 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11065#endif
90e4755a
RE
11066}
11067
11068static void
c19d1205 11069do_t_bx (void)
90e4755a 11070{
e07e6e58 11071 set_it_insn_type_last ();
c19d1205
ZW
11072 inst.instruction |= inst.operands[0].reg << 3;
11073 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11074 should cause the alignment to be checked once it is known. This is
11075 because BX PC only works if the instruction is word aligned. */
11076}
90e4755a 11077
c19d1205
ZW
11078static void
11079do_t_bxj (void)
11080{
fdfde340 11081 int Rm;
90e4755a 11082
e07e6e58 11083 set_it_insn_type_last ();
fdfde340
JM
11084 Rm = inst.operands[0].reg;
11085 reject_bad_reg (Rm);
11086 inst.instruction |= Rm << 16;
90e4755a
RE
11087}
11088
11089static void
c19d1205 11090do_t_clz (void)
90e4755a 11091{
fdfde340
JM
11092 unsigned Rd;
11093 unsigned Rm;
11094
11095 Rd = inst.operands[0].reg;
11096 Rm = inst.operands[1].reg;
11097
11098 reject_bad_reg (Rd);
11099 reject_bad_reg (Rm);
11100
11101 inst.instruction |= Rd << 8;
11102 inst.instruction |= Rm << 16;
11103 inst.instruction |= Rm;
c19d1205 11104}
90e4755a 11105
dfa9f0d5
PB
11106static void
11107do_t_cps (void)
11108{
e07e6e58 11109 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11110 inst.instruction |= inst.operands[0].imm;
11111}
11112
c19d1205
ZW
11113static void
11114do_t_cpsi (void)
11115{
e07e6e58 11116 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11117 if (unified_syntax
62b3e311
PB
11118 && (inst.operands[1].present || inst.size_req == 4)
11119 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11120 {
c19d1205
ZW
11121 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11122 inst.instruction = 0xf3af8000;
11123 inst.instruction |= imod << 9;
11124 inst.instruction |= inst.operands[0].imm << 5;
11125 if (inst.operands[1].present)
11126 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11127 }
c19d1205 11128 else
90e4755a 11129 {
62b3e311
PB
11130 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11131 && (inst.operands[0].imm & 4),
11132 _("selected processor does not support 'A' form "
11133 "of this instruction"));
11134 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11135 _("Thumb does not support the 2-argument "
11136 "form of this instruction"));
11137 inst.instruction |= inst.operands[0].imm;
90e4755a 11138 }
90e4755a
RE
11139}
11140
c19d1205
ZW
11141/* THUMB CPY instruction (argument parse). */
11142
90e4755a 11143static void
c19d1205 11144do_t_cpy (void)
90e4755a 11145{
c19d1205 11146 if (inst.size_req == 4)
90e4755a 11147 {
c19d1205
ZW
11148 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11149 inst.instruction |= inst.operands[0].reg << 8;
11150 inst.instruction |= inst.operands[1].reg;
90e4755a 11151 }
c19d1205 11152 else
90e4755a 11153 {
c19d1205
ZW
11154 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11155 inst.instruction |= (inst.operands[0].reg & 0x7);
11156 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11157 }
90e4755a
RE
11158}
11159
90e4755a 11160static void
25fe350b 11161do_t_cbz (void)
90e4755a 11162{
e07e6e58 11163 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11164 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11165 inst.instruction |= inst.operands[0].reg;
11166 inst.reloc.pc_rel = 1;
11167 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11168}
90e4755a 11169
62b3e311
PB
11170static void
11171do_t_dbg (void)
11172{
11173 inst.instruction |= inst.operands[0].imm;
11174}
11175
11176static void
11177do_t_div (void)
11178{
fdfde340
JM
11179 unsigned Rd, Rn, Rm;
11180
11181 Rd = inst.operands[0].reg;
11182 Rn = (inst.operands[1].present
11183 ? inst.operands[1].reg : Rd);
11184 Rm = inst.operands[2].reg;
11185
11186 reject_bad_reg (Rd);
11187 reject_bad_reg (Rn);
11188 reject_bad_reg (Rm);
11189
11190 inst.instruction |= Rd << 8;
11191 inst.instruction |= Rn << 16;
11192 inst.instruction |= Rm;
62b3e311
PB
11193}
11194
c19d1205
ZW
11195static void
11196do_t_hint (void)
11197{
11198 if (unified_syntax && inst.size_req == 4)
11199 inst.instruction = THUMB_OP32 (inst.instruction);
11200 else
11201 inst.instruction = THUMB_OP16 (inst.instruction);
11202}
90e4755a 11203
c19d1205
ZW
11204static void
11205do_t_it (void)
11206{
11207 unsigned int cond = inst.operands[0].imm;
e27ec89e 11208
e07e6e58
NC
11209 set_it_insn_type (IT_INSN);
11210 now_it.mask = (inst.instruction & 0xf) | 0x10;
11211 now_it.cc = cond;
5a01bb1d 11212 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11213
11214 /* If the condition is a negative condition, invert the mask. */
c19d1205 11215 if ((cond & 0x1) == 0x0)
90e4755a 11216 {
c19d1205 11217 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11218
c19d1205 11219 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11220 {
11221 /* No conversion needed. */
11222 now_it.block_length = 1;
11223 }
c19d1205 11224 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11225 {
11226 mask ^= 0x8;
11227 now_it.block_length = 2;
11228 }
e27ec89e 11229 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11230 {
11231 mask ^= 0xC;
11232 now_it.block_length = 3;
11233 }
c19d1205 11234 else
5a01bb1d
MGD
11235 {
11236 mask ^= 0xE;
11237 now_it.block_length = 4;
11238 }
90e4755a 11239
e27ec89e
PB
11240 inst.instruction &= 0xfff0;
11241 inst.instruction |= mask;
c19d1205 11242 }
90e4755a 11243
c19d1205
ZW
11244 inst.instruction |= cond << 4;
11245}
90e4755a 11246
3c707909
PB
11247/* Helper function used for both push/pop and ldm/stm. */
11248static void
11249encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11250{
11251 bfd_boolean load;
11252
11253 load = (inst.instruction & (1 << 20)) != 0;
11254
11255 if (mask & (1 << 13))
11256 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11257
11258 if ((mask & (1 << base)) != 0
11259 && writeback)
11260 inst.error = _("having the base register in the register list when "
11261 "using write back is UNPREDICTABLE");
11262
3c707909
PB
11263 if (load)
11264 {
e07e6e58 11265 if (mask & (1 << 15))
477330fc
RM
11266 {
11267 if (mask & (1 << 14))
11268 inst.error = _("LR and PC should not both be in register list");
11269 else
11270 set_it_insn_type_last ();
11271 }
3c707909
PB
11272 }
11273 else
11274 {
11275 if (mask & (1 << 15))
11276 inst.error = _("PC not allowed in register list");
3c707909
PB
11277 }
11278
11279 if ((mask & (mask - 1)) == 0)
11280 {
11281 /* Single register transfers implemented as str/ldr. */
11282 if (writeback)
11283 {
11284 if (inst.instruction & (1 << 23))
11285 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11286 else
11287 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11288 }
11289 else
11290 {
11291 if (inst.instruction & (1 << 23))
11292 inst.instruction = 0x00800000; /* ia -> [base] */
11293 else
11294 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11295 }
11296
11297 inst.instruction |= 0xf8400000;
11298 if (load)
11299 inst.instruction |= 0x00100000;
11300
5f4273c7 11301 mask = ffs (mask) - 1;
3c707909
PB
11302 mask <<= 12;
11303 }
11304 else if (writeback)
11305 inst.instruction |= WRITE_BACK;
11306
11307 inst.instruction |= mask;
11308 inst.instruction |= base << 16;
11309}
11310
c19d1205
ZW
11311static void
11312do_t_ldmstm (void)
11313{
11314 /* This really doesn't seem worth it. */
11315 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11316 _("expression too complex"));
11317 constraint (inst.operands[1].writeback,
11318 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11319
c19d1205
ZW
11320 if (unified_syntax)
11321 {
3c707909
PB
11322 bfd_boolean narrow;
11323 unsigned mask;
11324
11325 narrow = FALSE;
c19d1205
ZW
11326 /* See if we can use a 16-bit instruction. */
11327 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11328 && inst.size_req != 4
3c707909 11329 && !(inst.operands[1].imm & ~0xff))
90e4755a 11330 {
3c707909 11331 mask = 1 << inst.operands[0].reg;
90e4755a 11332
eab4f823 11333 if (inst.operands[0].reg <= 7)
90e4755a 11334 {
3c707909 11335 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11336 ? inst.operands[0].writeback
11337 : (inst.operands[0].writeback
11338 == !(inst.operands[1].imm & mask)))
477330fc 11339 {
eab4f823
MGD
11340 if (inst.instruction == T_MNEM_stmia
11341 && (inst.operands[1].imm & mask)
11342 && (inst.operands[1].imm & (mask - 1)))
11343 as_warn (_("value stored for r%d is UNKNOWN"),
11344 inst.operands[0].reg);
3c707909 11345
eab4f823
MGD
11346 inst.instruction = THUMB_OP16 (inst.instruction);
11347 inst.instruction |= inst.operands[0].reg << 8;
11348 inst.instruction |= inst.operands[1].imm;
11349 narrow = TRUE;
11350 }
11351 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11352 {
11353 /* This means 1 register in reg list one of 3 situations:
11354 1. Instruction is stmia, but without writeback.
11355 2. lmdia without writeback, but with Rn not in
477330fc 11356 reglist.
eab4f823
MGD
11357 3. ldmia with writeback, but with Rn in reglist.
11358 Case 3 is UNPREDICTABLE behaviour, so we handle
11359 case 1 and 2 which can be converted into a 16-bit
11360 str or ldr. The SP cases are handled below. */
11361 unsigned long opcode;
11362 /* First, record an error for Case 3. */
11363 if (inst.operands[1].imm & mask
11364 && inst.operands[0].writeback)
fa94de6b 11365 inst.error =
eab4f823
MGD
11366 _("having the base register in the register list when "
11367 "using write back is UNPREDICTABLE");
fa94de6b
RM
11368
11369 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11370 : T_MNEM_ldr);
11371 inst.instruction = THUMB_OP16 (opcode);
11372 inst.instruction |= inst.operands[0].reg << 3;
11373 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11374 narrow = TRUE;
11375 }
90e4755a 11376 }
eab4f823 11377 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11378 {
eab4f823
MGD
11379 if (inst.operands[0].writeback)
11380 {
fa94de6b 11381 inst.instruction =
eab4f823 11382 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11383 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11384 inst.instruction |= inst.operands[1].imm;
477330fc 11385 narrow = TRUE;
eab4f823
MGD
11386 }
11387 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11388 {
fa94de6b 11389 inst.instruction =
eab4f823 11390 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11391 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11392 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11393 narrow = TRUE;
eab4f823 11394 }
90e4755a 11395 }
3c707909
PB
11396 }
11397
11398 if (!narrow)
11399 {
c19d1205
ZW
11400 if (inst.instruction < 0xffff)
11401 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11402
5f4273c7
NC
11403 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11404 inst.operands[0].writeback);
90e4755a
RE
11405 }
11406 }
c19d1205 11407 else
90e4755a 11408 {
c19d1205
ZW
11409 constraint (inst.operands[0].reg > 7
11410 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11411 constraint (inst.instruction != T_MNEM_ldmia
11412 && inst.instruction != T_MNEM_stmia,
11413 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11414 if (inst.instruction == T_MNEM_stmia)
f03698e6 11415 {
c19d1205
ZW
11416 if (!inst.operands[0].writeback)
11417 as_warn (_("this instruction will write back the base register"));
11418 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11419 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11420 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11421 inst.operands[0].reg);
f03698e6 11422 }
c19d1205 11423 else
90e4755a 11424 {
c19d1205
ZW
11425 if (!inst.operands[0].writeback
11426 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11427 as_warn (_("this instruction will write back the base register"));
11428 else if (inst.operands[0].writeback
11429 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11430 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11431 }
11432
c19d1205
ZW
11433 inst.instruction = THUMB_OP16 (inst.instruction);
11434 inst.instruction |= inst.operands[0].reg << 8;
11435 inst.instruction |= inst.operands[1].imm;
11436 }
11437}
e28cd48c 11438
c19d1205
ZW
11439static void
11440do_t_ldrex (void)
11441{
11442 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11443 || inst.operands[1].postind || inst.operands[1].writeback
11444 || inst.operands[1].immisreg || inst.operands[1].shifted
11445 || inst.operands[1].negative,
01cfc07f 11446 BAD_ADDR_MODE);
e28cd48c 11447
5be8be5d
DG
11448 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11449
c19d1205
ZW
11450 inst.instruction |= inst.operands[0].reg << 12;
11451 inst.instruction |= inst.operands[1].reg << 16;
11452 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11453}
e28cd48c 11454
c19d1205
ZW
11455static void
11456do_t_ldrexd (void)
11457{
11458 if (!inst.operands[1].present)
1cac9012 11459 {
c19d1205
ZW
11460 constraint (inst.operands[0].reg == REG_LR,
11461 _("r14 not allowed as first register "
11462 "when second register is omitted"));
11463 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11464 }
c19d1205
ZW
11465 constraint (inst.operands[0].reg == inst.operands[1].reg,
11466 BAD_OVERLAP);
b99bd4ef 11467
c19d1205
ZW
11468 inst.instruction |= inst.operands[0].reg << 12;
11469 inst.instruction |= inst.operands[1].reg << 8;
11470 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11471}
11472
11473static void
c19d1205 11474do_t_ldst (void)
b99bd4ef 11475{
0110f2b8
PB
11476 unsigned long opcode;
11477 int Rn;
11478
e07e6e58
NC
11479 if (inst.operands[0].isreg
11480 && !inst.operands[0].preind
11481 && inst.operands[0].reg == REG_PC)
11482 set_it_insn_type_last ();
11483
0110f2b8 11484 opcode = inst.instruction;
c19d1205 11485 if (unified_syntax)
b99bd4ef 11486 {
53365c0d
PB
11487 if (!inst.operands[1].isreg)
11488 {
11489 if (opcode <= 0xffff)
11490 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11491 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11492 return;
11493 }
0110f2b8
PB
11494 if (inst.operands[1].isreg
11495 && !inst.operands[1].writeback
c19d1205
ZW
11496 && !inst.operands[1].shifted && !inst.operands[1].postind
11497 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11498 && opcode <= 0xffff
11499 && inst.size_req != 4)
c19d1205 11500 {
0110f2b8
PB
11501 /* Insn may have a 16-bit form. */
11502 Rn = inst.operands[1].reg;
11503 if (inst.operands[1].immisreg)
11504 {
11505 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11506 /* [Rn, Rik] */
0110f2b8
PB
11507 if (Rn <= 7 && inst.operands[1].imm <= 7)
11508 goto op16;
5be8be5d
DG
11509 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11510 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11511 }
11512 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11513 && opcode != T_MNEM_ldrsb)
11514 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11515 || (Rn == REG_SP && opcode == T_MNEM_str))
11516 {
11517 /* [Rn, #const] */
11518 if (Rn > 7)
11519 {
11520 if (Rn == REG_PC)
11521 {
11522 if (inst.reloc.pc_rel)
11523 opcode = T_MNEM_ldr_pc2;
11524 else
11525 opcode = T_MNEM_ldr_pc;
11526 }
11527 else
11528 {
11529 if (opcode == T_MNEM_ldr)
11530 opcode = T_MNEM_ldr_sp;
11531 else
11532 opcode = T_MNEM_str_sp;
11533 }
11534 inst.instruction = inst.operands[0].reg << 8;
11535 }
11536 else
11537 {
11538 inst.instruction = inst.operands[0].reg;
11539 inst.instruction |= inst.operands[1].reg << 3;
11540 }
11541 inst.instruction |= THUMB_OP16 (opcode);
11542 if (inst.size_req == 2)
11543 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11544 else
11545 inst.relax = opcode;
11546 return;
11547 }
c19d1205 11548 }
0110f2b8 11549 /* Definitely a 32-bit variant. */
5be8be5d 11550
8d67f500
NC
11551 /* Warning for Erratum 752419. */
11552 if (opcode == T_MNEM_ldr
11553 && inst.operands[0].reg == REG_SP
11554 && inst.operands[1].writeback == 1
11555 && !inst.operands[1].immisreg)
11556 {
11557 if (no_cpu_selected ()
11558 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11559 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11560 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11561 as_warn (_("This instruction may be unpredictable "
11562 "if executed on M-profile cores "
11563 "with interrupts enabled."));
11564 }
11565
5be8be5d 11566 /* Do some validations regarding addressing modes. */
1be5fd2e 11567 if (inst.operands[1].immisreg)
5be8be5d
DG
11568 reject_bad_reg (inst.operands[1].imm);
11569
1be5fd2e
NC
11570 constraint (inst.operands[1].writeback == 1
11571 && inst.operands[0].reg == inst.operands[1].reg,
11572 BAD_OVERLAP);
11573
0110f2b8 11574 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11575 inst.instruction |= inst.operands[0].reg << 12;
11576 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11577 check_ldr_r15_aligned ();
b99bd4ef
NC
11578 return;
11579 }
11580
c19d1205
ZW
11581 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11582
11583 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11584 {
c19d1205
ZW
11585 /* Only [Rn,Rm] is acceptable. */
11586 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11587 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11588 || inst.operands[1].postind || inst.operands[1].shifted
11589 || inst.operands[1].negative,
11590 _("Thumb does not support this addressing mode"));
11591 inst.instruction = THUMB_OP16 (inst.instruction);
11592 goto op16;
b99bd4ef 11593 }
5f4273c7 11594
c19d1205
ZW
11595 inst.instruction = THUMB_OP16 (inst.instruction);
11596 if (!inst.operands[1].isreg)
8335d6aa 11597 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11598 return;
b99bd4ef 11599
c19d1205
ZW
11600 constraint (!inst.operands[1].preind
11601 || inst.operands[1].shifted
11602 || inst.operands[1].writeback,
11603 _("Thumb does not support this addressing mode"));
11604 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11605 {
c19d1205
ZW
11606 constraint (inst.instruction & 0x0600,
11607 _("byte or halfword not valid for base register"));
11608 constraint (inst.operands[1].reg == REG_PC
11609 && !(inst.instruction & THUMB_LOAD_BIT),
11610 _("r15 based store not allowed"));
11611 constraint (inst.operands[1].immisreg,
11612 _("invalid base register for register offset"));
b99bd4ef 11613
c19d1205
ZW
11614 if (inst.operands[1].reg == REG_PC)
11615 inst.instruction = T_OPCODE_LDR_PC;
11616 else if (inst.instruction & THUMB_LOAD_BIT)
11617 inst.instruction = T_OPCODE_LDR_SP;
11618 else
11619 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11620
c19d1205
ZW
11621 inst.instruction |= inst.operands[0].reg << 8;
11622 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11623 return;
11624 }
90e4755a 11625
c19d1205
ZW
11626 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11627 if (!inst.operands[1].immisreg)
11628 {
11629 /* Immediate offset. */
11630 inst.instruction |= inst.operands[0].reg;
11631 inst.instruction |= inst.operands[1].reg << 3;
11632 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11633 return;
11634 }
90e4755a 11635
c19d1205
ZW
11636 /* Register offset. */
11637 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11638 constraint (inst.operands[1].negative,
11639 _("Thumb does not support this addressing mode"));
90e4755a 11640
c19d1205
ZW
11641 op16:
11642 switch (inst.instruction)
11643 {
11644 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11645 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11646 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11647 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11648 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11649 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11650 case 0x5600 /* ldrsb */:
11651 case 0x5e00 /* ldrsh */: break;
11652 default: abort ();
11653 }
90e4755a 11654
c19d1205
ZW
11655 inst.instruction |= inst.operands[0].reg;
11656 inst.instruction |= inst.operands[1].reg << 3;
11657 inst.instruction |= inst.operands[1].imm << 6;
11658}
90e4755a 11659
c19d1205
ZW
11660static void
11661do_t_ldstd (void)
11662{
11663 if (!inst.operands[1].present)
b99bd4ef 11664 {
c19d1205
ZW
11665 inst.operands[1].reg = inst.operands[0].reg + 1;
11666 constraint (inst.operands[0].reg == REG_LR,
11667 _("r14 not allowed here"));
bd340a04 11668 constraint (inst.operands[0].reg == REG_R12,
477330fc 11669 _("r12 not allowed here"));
b99bd4ef 11670 }
bd340a04
MGD
11671
11672 if (inst.operands[2].writeback
11673 && (inst.operands[0].reg == inst.operands[2].reg
11674 || inst.operands[1].reg == inst.operands[2].reg))
11675 as_warn (_("base register written back, and overlaps "
477330fc 11676 "one of transfer registers"));
bd340a04 11677
c19d1205
ZW
11678 inst.instruction |= inst.operands[0].reg << 12;
11679 inst.instruction |= inst.operands[1].reg << 8;
11680 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11681}
11682
c19d1205
ZW
11683static void
11684do_t_ldstt (void)
11685{
11686 inst.instruction |= inst.operands[0].reg << 12;
11687 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11688}
a737bd4d 11689
b99bd4ef 11690static void
c19d1205 11691do_t_mla (void)
b99bd4ef 11692{
fdfde340 11693 unsigned Rd, Rn, Rm, Ra;
c921be7d 11694
fdfde340
JM
11695 Rd = inst.operands[0].reg;
11696 Rn = inst.operands[1].reg;
11697 Rm = inst.operands[2].reg;
11698 Ra = inst.operands[3].reg;
11699
11700 reject_bad_reg (Rd);
11701 reject_bad_reg (Rn);
11702 reject_bad_reg (Rm);
11703 reject_bad_reg (Ra);
11704
11705 inst.instruction |= Rd << 8;
11706 inst.instruction |= Rn << 16;
11707 inst.instruction |= Rm;
11708 inst.instruction |= Ra << 12;
c19d1205 11709}
b99bd4ef 11710
c19d1205
ZW
11711static void
11712do_t_mlal (void)
11713{
fdfde340
JM
11714 unsigned RdLo, RdHi, Rn, Rm;
11715
11716 RdLo = inst.operands[0].reg;
11717 RdHi = inst.operands[1].reg;
11718 Rn = inst.operands[2].reg;
11719 Rm = inst.operands[3].reg;
11720
11721 reject_bad_reg (RdLo);
11722 reject_bad_reg (RdHi);
11723 reject_bad_reg (Rn);
11724 reject_bad_reg (Rm);
11725
11726 inst.instruction |= RdLo << 12;
11727 inst.instruction |= RdHi << 8;
11728 inst.instruction |= Rn << 16;
11729 inst.instruction |= Rm;
c19d1205 11730}
b99bd4ef 11731
c19d1205
ZW
11732static void
11733do_t_mov_cmp (void)
11734{
fdfde340
JM
11735 unsigned Rn, Rm;
11736
11737 Rn = inst.operands[0].reg;
11738 Rm = inst.operands[1].reg;
11739
e07e6e58
NC
11740 if (Rn == REG_PC)
11741 set_it_insn_type_last ();
11742
c19d1205 11743 if (unified_syntax)
b99bd4ef 11744 {
c19d1205
ZW
11745 int r0off = (inst.instruction == T_MNEM_mov
11746 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11747 unsigned long opcode;
3d388997
PB
11748 bfd_boolean narrow;
11749 bfd_boolean low_regs;
11750
fdfde340 11751 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11752 opcode = inst.instruction;
e07e6e58 11753 if (in_it_block ())
0110f2b8 11754 narrow = opcode != T_MNEM_movs;
3d388997 11755 else
0110f2b8 11756 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11757 if (inst.size_req == 4
11758 || inst.operands[1].shifted)
11759 narrow = FALSE;
11760
efd81785
PB
11761 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11762 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11763 && !inst.operands[1].shifted
fdfde340
JM
11764 && Rn == REG_PC
11765 && Rm == REG_LR)
efd81785
PB
11766 {
11767 inst.instruction = T2_SUBS_PC_LR;
11768 return;
11769 }
11770
fdfde340
JM
11771 if (opcode == T_MNEM_cmp)
11772 {
11773 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11774 if (narrow)
11775 {
11776 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11777 but valid. */
11778 warn_deprecated_sp (Rm);
11779 /* R15 was documented as a valid choice for Rm in ARMv6,
11780 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11781 tools reject R15, so we do too. */
11782 constraint (Rm == REG_PC, BAD_PC);
11783 }
11784 else
11785 reject_bad_reg (Rm);
fdfde340
JM
11786 }
11787 else if (opcode == T_MNEM_mov
11788 || opcode == T_MNEM_movs)
11789 {
11790 if (inst.operands[1].isreg)
11791 {
11792 if (opcode == T_MNEM_movs)
11793 {
11794 reject_bad_reg (Rn);
11795 reject_bad_reg (Rm);
11796 }
76fa04a4
MGD
11797 else if (narrow)
11798 {
11799 /* This is mov.n. */
11800 if ((Rn == REG_SP || Rn == REG_PC)
11801 && (Rm == REG_SP || Rm == REG_PC))
11802 {
5c3696f8 11803 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11804 "deprecated when r%u is the destination "
11805 "register."), Rm, Rn);
11806 }
11807 }
11808 else
11809 {
11810 /* This is mov.w. */
11811 constraint (Rn == REG_PC, BAD_PC);
11812 constraint (Rm == REG_PC, BAD_PC);
11813 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11814 }
fdfde340
JM
11815 }
11816 else
11817 reject_bad_reg (Rn);
11818 }
11819
c19d1205
ZW
11820 if (!inst.operands[1].isreg)
11821 {
0110f2b8 11822 /* Immediate operand. */
e07e6e58 11823 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11824 narrow = 0;
11825 if (low_regs && narrow)
11826 {
11827 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11828 inst.instruction |= Rn << 8;
0110f2b8 11829 if (inst.size_req == 2)
72d98d16
MG
11830 {
11831 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11832 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
11833 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11834 }
0110f2b8 11835 else
72d98d16 11836 inst.relax = opcode;
0110f2b8
PB
11837 }
11838 else
11839 {
11840 inst.instruction = THUMB_OP32 (inst.instruction);
11841 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11842 inst.instruction |= Rn << r0off;
0110f2b8
PB
11843 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11844 }
c19d1205 11845 }
728ca7c9
PB
11846 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11847 && (inst.instruction == T_MNEM_mov
11848 || inst.instruction == T_MNEM_movs))
11849 {
11850 /* Register shifts are encoded as separate shift instructions. */
11851 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11852
e07e6e58 11853 if (in_it_block ())
728ca7c9
PB
11854 narrow = !flags;
11855 else
11856 narrow = flags;
11857
11858 if (inst.size_req == 4)
11859 narrow = FALSE;
11860
11861 if (!low_regs || inst.operands[1].imm > 7)
11862 narrow = FALSE;
11863
fdfde340 11864 if (Rn != Rm)
728ca7c9
PB
11865 narrow = FALSE;
11866
11867 switch (inst.operands[1].shift_kind)
11868 {
11869 case SHIFT_LSL:
11870 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11871 break;
11872 case SHIFT_ASR:
11873 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11874 break;
11875 case SHIFT_LSR:
11876 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11877 break;
11878 case SHIFT_ROR:
11879 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11880 break;
11881 default:
5f4273c7 11882 abort ();
728ca7c9
PB
11883 }
11884
11885 inst.instruction = opcode;
11886 if (narrow)
11887 {
fdfde340 11888 inst.instruction |= Rn;
728ca7c9
PB
11889 inst.instruction |= inst.operands[1].imm << 3;
11890 }
11891 else
11892 {
11893 if (flags)
11894 inst.instruction |= CONDS_BIT;
11895
fdfde340
JM
11896 inst.instruction |= Rn << 8;
11897 inst.instruction |= Rm << 16;
728ca7c9
PB
11898 inst.instruction |= inst.operands[1].imm;
11899 }
11900 }
3d388997 11901 else if (!narrow)
c19d1205 11902 {
728ca7c9
PB
11903 /* Some mov with immediate shift have narrow variants.
11904 Register shifts are handled above. */
11905 if (low_regs && inst.operands[1].shifted
11906 && (inst.instruction == T_MNEM_mov
11907 || inst.instruction == T_MNEM_movs))
11908 {
e07e6e58 11909 if (in_it_block ())
728ca7c9
PB
11910 narrow = (inst.instruction == T_MNEM_mov);
11911 else
11912 narrow = (inst.instruction == T_MNEM_movs);
11913 }
11914
11915 if (narrow)
11916 {
11917 switch (inst.operands[1].shift_kind)
11918 {
11919 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11920 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11921 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11922 default: narrow = FALSE; break;
11923 }
11924 }
11925
11926 if (narrow)
11927 {
fdfde340
JM
11928 inst.instruction |= Rn;
11929 inst.instruction |= Rm << 3;
728ca7c9
PB
11930 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11931 }
11932 else
11933 {
11934 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11935 inst.instruction |= Rn << r0off;
728ca7c9
PB
11936 encode_thumb32_shifted_operand (1);
11937 }
c19d1205
ZW
11938 }
11939 else
11940 switch (inst.instruction)
11941 {
11942 case T_MNEM_mov:
837b3435 11943 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11944 results. Don't allow this. */
11945 if (low_regs)
11946 {
11947 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11948 "MOV Rd, Rs with two low registers is not "
11949 "permitted on this architecture");
fa94de6b 11950 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11951 arm_ext_v6);
11952 }
11953
c19d1205 11954 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11955 inst.instruction |= (Rn & 0x8) << 4;
11956 inst.instruction |= (Rn & 0x7);
11957 inst.instruction |= Rm << 3;
c19d1205 11958 break;
b99bd4ef 11959
c19d1205
ZW
11960 case T_MNEM_movs:
11961 /* We know we have low registers at this point.
941a8a52
MGD
11962 Generate LSLS Rd, Rs, #0. */
11963 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11964 inst.instruction |= Rn;
11965 inst.instruction |= Rm << 3;
c19d1205
ZW
11966 break;
11967
11968 case T_MNEM_cmp:
3d388997 11969 if (low_regs)
c19d1205
ZW
11970 {
11971 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11972 inst.instruction |= Rn;
11973 inst.instruction |= Rm << 3;
c19d1205
ZW
11974 }
11975 else
11976 {
11977 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11978 inst.instruction |= (Rn & 0x8) << 4;
11979 inst.instruction |= (Rn & 0x7);
11980 inst.instruction |= Rm << 3;
c19d1205
ZW
11981 }
11982 break;
11983 }
b99bd4ef
NC
11984 return;
11985 }
11986
c19d1205 11987 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11988
11989 /* PR 10443: Do not silently ignore shifted operands. */
11990 constraint (inst.operands[1].shifted,
11991 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11992
c19d1205 11993 if (inst.operands[1].isreg)
b99bd4ef 11994 {
fdfde340 11995 if (Rn < 8 && Rm < 8)
b99bd4ef 11996 {
c19d1205
ZW
11997 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11998 since a MOV instruction produces unpredictable results. */
11999 if (inst.instruction == T_OPCODE_MOV_I8)
12000 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12001 else
c19d1205 12002 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12003
fdfde340
JM
12004 inst.instruction |= Rn;
12005 inst.instruction |= Rm << 3;
b99bd4ef
NC
12006 }
12007 else
12008 {
c19d1205
ZW
12009 if (inst.instruction == T_OPCODE_MOV_I8)
12010 inst.instruction = T_OPCODE_MOV_HR;
12011 else
12012 inst.instruction = T_OPCODE_CMP_HR;
12013 do_t_cpy ();
b99bd4ef
NC
12014 }
12015 }
c19d1205 12016 else
b99bd4ef 12017 {
fdfde340 12018 constraint (Rn > 7,
c19d1205 12019 _("only lo regs allowed with immediate"));
fdfde340 12020 inst.instruction |= Rn << 8;
c19d1205
ZW
12021 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12022 }
12023}
b99bd4ef 12024
c19d1205
ZW
12025static void
12026do_t_mov16 (void)
12027{
fdfde340 12028 unsigned Rd;
b6895b4f
PB
12029 bfd_vma imm;
12030 bfd_boolean top;
12031
12032 top = (inst.instruction & 0x00800000) != 0;
12033 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12034 {
12035 constraint (top, _(":lower16: not allowed this instruction"));
12036 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12037 }
12038 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12039 {
12040 constraint (!top, _(":upper16: not allowed this instruction"));
12041 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12042 }
12043
fdfde340
JM
12044 Rd = inst.operands[0].reg;
12045 reject_bad_reg (Rd);
12046
12047 inst.instruction |= Rd << 8;
b6895b4f
PB
12048 if (inst.reloc.type == BFD_RELOC_UNUSED)
12049 {
12050 imm = inst.reloc.exp.X_add_number;
12051 inst.instruction |= (imm & 0xf000) << 4;
12052 inst.instruction |= (imm & 0x0800) << 15;
12053 inst.instruction |= (imm & 0x0700) << 4;
12054 inst.instruction |= (imm & 0x00ff);
12055 }
c19d1205 12056}
b99bd4ef 12057
c19d1205
ZW
12058static void
12059do_t_mvn_tst (void)
12060{
fdfde340 12061 unsigned Rn, Rm;
c921be7d 12062
fdfde340
JM
12063 Rn = inst.operands[0].reg;
12064 Rm = inst.operands[1].reg;
12065
12066 if (inst.instruction == T_MNEM_cmp
12067 || inst.instruction == T_MNEM_cmn)
12068 constraint (Rn == REG_PC, BAD_PC);
12069 else
12070 reject_bad_reg (Rn);
12071 reject_bad_reg (Rm);
12072
c19d1205
ZW
12073 if (unified_syntax)
12074 {
12075 int r0off = (inst.instruction == T_MNEM_mvn
12076 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12077 bfd_boolean narrow;
12078
12079 if (inst.size_req == 4
12080 || inst.instruction > 0xffff
12081 || inst.operands[1].shifted
fdfde340 12082 || Rn > 7 || Rm > 7)
3d388997 12083 narrow = FALSE;
fe8b4cc3
KT
12084 else if (inst.instruction == T_MNEM_cmn
12085 || inst.instruction == T_MNEM_tst)
3d388997
PB
12086 narrow = TRUE;
12087 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12088 narrow = !in_it_block ();
3d388997 12089 else
e07e6e58 12090 narrow = in_it_block ();
3d388997 12091
c19d1205 12092 if (!inst.operands[1].isreg)
b99bd4ef 12093 {
c19d1205
ZW
12094 /* For an immediate, we always generate a 32-bit opcode;
12095 section relaxation will shrink it later if possible. */
12096 if (inst.instruction < 0xffff)
12097 inst.instruction = THUMB_OP32 (inst.instruction);
12098 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12099 inst.instruction |= Rn << r0off;
c19d1205 12100 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12101 }
c19d1205 12102 else
b99bd4ef 12103 {
c19d1205 12104 /* See if we can do this with a 16-bit instruction. */
3d388997 12105 if (narrow)
b99bd4ef 12106 {
c19d1205 12107 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12108 inst.instruction |= Rn;
12109 inst.instruction |= Rm << 3;
b99bd4ef 12110 }
c19d1205 12111 else
b99bd4ef 12112 {
c19d1205
ZW
12113 constraint (inst.operands[1].shifted
12114 && inst.operands[1].immisreg,
12115 _("shift must be constant"));
12116 if (inst.instruction < 0xffff)
12117 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12118 inst.instruction |= Rn << r0off;
c19d1205 12119 encode_thumb32_shifted_operand (1);
b99bd4ef 12120 }
b99bd4ef
NC
12121 }
12122 }
12123 else
12124 {
c19d1205
ZW
12125 constraint (inst.instruction > 0xffff
12126 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12127 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12128 _("unshifted register required"));
fdfde340 12129 constraint (Rn > 7 || Rm > 7,
c19d1205 12130 BAD_HIREG);
b99bd4ef 12131
c19d1205 12132 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12133 inst.instruction |= Rn;
12134 inst.instruction |= Rm << 3;
b99bd4ef 12135 }
b99bd4ef
NC
12136}
12137
b05fe5cf 12138static void
c19d1205 12139do_t_mrs (void)
b05fe5cf 12140{
fdfde340 12141 unsigned Rd;
037e8744
JB
12142
12143 if (do_vfp_nsyn_mrs () == SUCCESS)
12144 return;
12145
90ec0d68
MGD
12146 Rd = inst.operands[0].reg;
12147 reject_bad_reg (Rd);
12148 inst.instruction |= Rd << 8;
12149
12150 if (inst.operands[1].isreg)
62b3e311 12151 {
90ec0d68
MGD
12152 unsigned br = inst.operands[1].reg;
12153 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12154 as_bad (_("bad register for mrs"));
12155
12156 inst.instruction |= br & (0xf << 16);
12157 inst.instruction |= (br & 0x300) >> 4;
12158 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12159 }
12160 else
12161 {
90ec0d68 12162 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12163
d2cd1205 12164 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12165 {
12166 /* PR gas/12698: The constraint is only applied for m_profile.
12167 If the user has specified -march=all, we want to ignore it as
12168 we are building for any CPU type, including non-m variants. */
823d2571
TG
12169 bfd_boolean m_profile =
12170 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12171 constraint ((flags != 0) && m_profile, _("selected processor does "
12172 "not support requested special purpose register"));
12173 }
90ec0d68 12174 else
d2cd1205
JB
12175 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12176 devices). */
12177 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12178 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12179
90ec0d68
MGD
12180 inst.instruction |= (flags & SPSR_BIT) >> 2;
12181 inst.instruction |= inst.operands[1].imm & 0xff;
12182 inst.instruction |= 0xf0000;
12183 }
c19d1205 12184}
b05fe5cf 12185
c19d1205
ZW
12186static void
12187do_t_msr (void)
12188{
62b3e311 12189 int flags;
fdfde340 12190 unsigned Rn;
62b3e311 12191
037e8744
JB
12192 if (do_vfp_nsyn_msr () == SUCCESS)
12193 return;
12194
c19d1205
ZW
12195 constraint (!inst.operands[1].isreg,
12196 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12197
12198 if (inst.operands[0].isreg)
12199 flags = (int)(inst.operands[0].reg);
12200 else
12201 flags = inst.operands[0].imm;
12202
d2cd1205 12203 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12204 {
d2cd1205
JB
12205 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12206
1a43faaf 12207 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12208 If the user has specified -march=all, we want to ignore it as
12209 we are building for any CPU type, including non-m variants. */
823d2571
TG
12210 bfd_boolean m_profile =
12211 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12212 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12213 && (bits & ~(PSR_s | PSR_f)) != 0)
12214 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12215 && bits != PSR_f)) && m_profile,
12216 _("selected processor does not support requested special "
12217 "purpose register"));
62b3e311
PB
12218 }
12219 else
d2cd1205
JB
12220 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12221 "requested special purpose register"));
c921be7d 12222
fdfde340
JM
12223 Rn = inst.operands[1].reg;
12224 reject_bad_reg (Rn);
12225
62b3e311 12226 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12227 inst.instruction |= (flags & 0xf0000) >> 8;
12228 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12229 inst.instruction |= (flags & 0xff);
fdfde340 12230 inst.instruction |= Rn << 16;
c19d1205 12231}
b05fe5cf 12232
c19d1205
ZW
12233static void
12234do_t_mul (void)
12235{
17828f45 12236 bfd_boolean narrow;
fdfde340 12237 unsigned Rd, Rn, Rm;
17828f45 12238
c19d1205
ZW
12239 if (!inst.operands[2].present)
12240 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12241
fdfde340
JM
12242 Rd = inst.operands[0].reg;
12243 Rn = inst.operands[1].reg;
12244 Rm = inst.operands[2].reg;
12245
17828f45 12246 if (unified_syntax)
b05fe5cf 12247 {
17828f45 12248 if (inst.size_req == 4
fdfde340
JM
12249 || (Rd != Rn
12250 && Rd != Rm)
12251 || Rn > 7
12252 || Rm > 7)
17828f45
JM
12253 narrow = FALSE;
12254 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12255 narrow = !in_it_block ();
17828f45 12256 else
e07e6e58 12257 narrow = in_it_block ();
b05fe5cf 12258 }
c19d1205 12259 else
b05fe5cf 12260 {
17828f45 12261 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12262 constraint (Rn > 7 || Rm > 7,
c19d1205 12263 BAD_HIREG);
17828f45
JM
12264 narrow = TRUE;
12265 }
b05fe5cf 12266
17828f45
JM
12267 if (narrow)
12268 {
12269 /* 16-bit MULS/Conditional MUL. */
c19d1205 12270 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12271 inst.instruction |= Rd;
b05fe5cf 12272
fdfde340
JM
12273 if (Rd == Rn)
12274 inst.instruction |= Rm << 3;
12275 else if (Rd == Rm)
12276 inst.instruction |= Rn << 3;
c19d1205
ZW
12277 else
12278 constraint (1, _("dest must overlap one source register"));
12279 }
17828f45
JM
12280 else
12281 {
e07e6e58
NC
12282 constraint (inst.instruction != T_MNEM_mul,
12283 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12284 /* 32-bit MUL. */
12285 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12286 inst.instruction |= Rd << 8;
12287 inst.instruction |= Rn << 16;
12288 inst.instruction |= Rm << 0;
12289
12290 reject_bad_reg (Rd);
12291 reject_bad_reg (Rn);
12292 reject_bad_reg (Rm);
17828f45 12293 }
c19d1205 12294}
b05fe5cf 12295
c19d1205
ZW
12296static void
12297do_t_mull (void)
12298{
fdfde340 12299 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12300
fdfde340
JM
12301 RdLo = inst.operands[0].reg;
12302 RdHi = inst.operands[1].reg;
12303 Rn = inst.operands[2].reg;
12304 Rm = inst.operands[3].reg;
12305
12306 reject_bad_reg (RdLo);
12307 reject_bad_reg (RdHi);
12308 reject_bad_reg (Rn);
12309 reject_bad_reg (Rm);
12310
12311 inst.instruction |= RdLo << 12;
12312 inst.instruction |= RdHi << 8;
12313 inst.instruction |= Rn << 16;
12314 inst.instruction |= Rm;
12315
12316 if (RdLo == RdHi)
c19d1205
ZW
12317 as_tsktsk (_("rdhi and rdlo must be different"));
12318}
b05fe5cf 12319
c19d1205
ZW
12320static void
12321do_t_nop (void)
12322{
e07e6e58
NC
12323 set_it_insn_type (NEUTRAL_IT_INSN);
12324
c19d1205
ZW
12325 if (unified_syntax)
12326 {
12327 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12328 {
c19d1205
ZW
12329 inst.instruction = THUMB_OP32 (inst.instruction);
12330 inst.instruction |= inst.operands[0].imm;
12331 }
12332 else
12333 {
bc2d1808
NC
12334 /* PR9722: Check for Thumb2 availability before
12335 generating a thumb2 nop instruction. */
afa62d5e 12336 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12337 {
12338 inst.instruction = THUMB_OP16 (inst.instruction);
12339 inst.instruction |= inst.operands[0].imm << 4;
12340 }
12341 else
12342 inst.instruction = 0x46c0;
c19d1205
ZW
12343 }
12344 }
12345 else
12346 {
12347 constraint (inst.operands[0].present,
12348 _("Thumb does not support NOP with hints"));
12349 inst.instruction = 0x46c0;
12350 }
12351}
b05fe5cf 12352
c19d1205
ZW
12353static void
12354do_t_neg (void)
12355{
12356 if (unified_syntax)
12357 {
3d388997
PB
12358 bfd_boolean narrow;
12359
12360 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12361 narrow = !in_it_block ();
3d388997 12362 else
e07e6e58 12363 narrow = in_it_block ();
3d388997
PB
12364 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12365 narrow = FALSE;
12366 if (inst.size_req == 4)
12367 narrow = FALSE;
12368
12369 if (!narrow)
c19d1205
ZW
12370 {
12371 inst.instruction = THUMB_OP32 (inst.instruction);
12372 inst.instruction |= inst.operands[0].reg << 8;
12373 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12374 }
12375 else
12376 {
c19d1205
ZW
12377 inst.instruction = THUMB_OP16 (inst.instruction);
12378 inst.instruction |= inst.operands[0].reg;
12379 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12380 }
12381 }
12382 else
12383 {
c19d1205
ZW
12384 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12385 BAD_HIREG);
12386 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12387
12388 inst.instruction = THUMB_OP16 (inst.instruction);
12389 inst.instruction |= inst.operands[0].reg;
12390 inst.instruction |= inst.operands[1].reg << 3;
12391 }
12392}
12393
1c444d06
JM
12394static void
12395do_t_orn (void)
12396{
12397 unsigned Rd, Rn;
12398
12399 Rd = inst.operands[0].reg;
12400 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12401
fdfde340
JM
12402 reject_bad_reg (Rd);
12403 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12404 reject_bad_reg (Rn);
12405
1c444d06
JM
12406 inst.instruction |= Rd << 8;
12407 inst.instruction |= Rn << 16;
12408
12409 if (!inst.operands[2].isreg)
12410 {
12411 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12412 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12413 }
12414 else
12415 {
12416 unsigned Rm;
12417
12418 Rm = inst.operands[2].reg;
fdfde340 12419 reject_bad_reg (Rm);
1c444d06
JM
12420
12421 constraint (inst.operands[2].shifted
12422 && inst.operands[2].immisreg,
12423 _("shift must be constant"));
12424 encode_thumb32_shifted_operand (2);
12425 }
12426}
12427
c19d1205
ZW
12428static void
12429do_t_pkhbt (void)
12430{
fdfde340
JM
12431 unsigned Rd, Rn, Rm;
12432
12433 Rd = inst.operands[0].reg;
12434 Rn = inst.operands[1].reg;
12435 Rm = inst.operands[2].reg;
12436
12437 reject_bad_reg (Rd);
12438 reject_bad_reg (Rn);
12439 reject_bad_reg (Rm);
12440
12441 inst.instruction |= Rd << 8;
12442 inst.instruction |= Rn << 16;
12443 inst.instruction |= Rm;
c19d1205
ZW
12444 if (inst.operands[3].present)
12445 {
12446 unsigned int val = inst.reloc.exp.X_add_number;
12447 constraint (inst.reloc.exp.X_op != O_constant,
12448 _("expression too complex"));
12449 inst.instruction |= (val & 0x1c) << 10;
12450 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12451 }
c19d1205 12452}
b05fe5cf 12453
c19d1205
ZW
12454static void
12455do_t_pkhtb (void)
12456{
12457 if (!inst.operands[3].present)
1ef52f49
NC
12458 {
12459 unsigned Rtmp;
12460
12461 inst.instruction &= ~0x00000020;
12462
12463 /* PR 10168. Swap the Rm and Rn registers. */
12464 Rtmp = inst.operands[1].reg;
12465 inst.operands[1].reg = inst.operands[2].reg;
12466 inst.operands[2].reg = Rtmp;
12467 }
c19d1205 12468 do_t_pkhbt ();
b05fe5cf
ZW
12469}
12470
c19d1205
ZW
12471static void
12472do_t_pld (void)
12473{
fdfde340
JM
12474 if (inst.operands[0].immisreg)
12475 reject_bad_reg (inst.operands[0].imm);
12476
c19d1205
ZW
12477 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12478}
b05fe5cf 12479
c19d1205
ZW
12480static void
12481do_t_push_pop (void)
b99bd4ef 12482{
e9f89963 12483 unsigned mask;
5f4273c7 12484
c19d1205
ZW
12485 constraint (inst.operands[0].writeback,
12486 _("push/pop do not support {reglist}^"));
12487 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12488 _("expression too complex"));
b99bd4ef 12489
e9f89963 12490 mask = inst.operands[0].imm;
d3bfe16e 12491 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12492 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
12493 else if (inst.size_req != 4
12494 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12495 ? REG_LR : REG_PC)))
b99bd4ef 12496 {
c19d1205
ZW
12497 inst.instruction = THUMB_OP16 (inst.instruction);
12498 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12499 inst.instruction |= mask & 0xff;
c19d1205
ZW
12500 }
12501 else if (unified_syntax)
12502 {
3c707909 12503 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12504 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12505 }
12506 else
12507 {
12508 inst.error = _("invalid register list to push/pop instruction");
12509 return;
12510 }
c19d1205 12511}
b99bd4ef 12512
c19d1205
ZW
12513static void
12514do_t_rbit (void)
12515{
fdfde340
JM
12516 unsigned Rd, Rm;
12517
12518 Rd = inst.operands[0].reg;
12519 Rm = inst.operands[1].reg;
12520
12521 reject_bad_reg (Rd);
12522 reject_bad_reg (Rm);
12523
12524 inst.instruction |= Rd << 8;
12525 inst.instruction |= Rm << 16;
12526 inst.instruction |= Rm;
c19d1205 12527}
b99bd4ef 12528
c19d1205
ZW
12529static void
12530do_t_rev (void)
12531{
fdfde340
JM
12532 unsigned Rd, Rm;
12533
12534 Rd = inst.operands[0].reg;
12535 Rm = inst.operands[1].reg;
12536
12537 reject_bad_reg (Rd);
12538 reject_bad_reg (Rm);
12539
12540 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12541 && inst.size_req != 4)
12542 {
12543 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12544 inst.instruction |= Rd;
12545 inst.instruction |= Rm << 3;
c19d1205
ZW
12546 }
12547 else if (unified_syntax)
12548 {
12549 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12550 inst.instruction |= Rd << 8;
12551 inst.instruction |= Rm << 16;
12552 inst.instruction |= Rm;
c19d1205
ZW
12553 }
12554 else
12555 inst.error = BAD_HIREG;
12556}
b99bd4ef 12557
1c444d06
JM
12558static void
12559do_t_rrx (void)
12560{
12561 unsigned Rd, Rm;
12562
12563 Rd = inst.operands[0].reg;
12564 Rm = inst.operands[1].reg;
12565
fdfde340
JM
12566 reject_bad_reg (Rd);
12567 reject_bad_reg (Rm);
c921be7d 12568
1c444d06
JM
12569 inst.instruction |= Rd << 8;
12570 inst.instruction |= Rm;
12571}
12572
c19d1205
ZW
12573static void
12574do_t_rsb (void)
12575{
fdfde340 12576 unsigned Rd, Rs;
b99bd4ef 12577
c19d1205
ZW
12578 Rd = inst.operands[0].reg;
12579 Rs = (inst.operands[1].present
12580 ? inst.operands[1].reg /* Rd, Rs, foo */
12581 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12582
fdfde340
JM
12583 reject_bad_reg (Rd);
12584 reject_bad_reg (Rs);
12585 if (inst.operands[2].isreg)
12586 reject_bad_reg (inst.operands[2].reg);
12587
c19d1205
ZW
12588 inst.instruction |= Rd << 8;
12589 inst.instruction |= Rs << 16;
12590 if (!inst.operands[2].isreg)
12591 {
026d3abb
PB
12592 bfd_boolean narrow;
12593
12594 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12595 narrow = !in_it_block ();
026d3abb 12596 else
e07e6e58 12597 narrow = in_it_block ();
026d3abb
PB
12598
12599 if (Rd > 7 || Rs > 7)
12600 narrow = FALSE;
12601
12602 if (inst.size_req == 4 || !unified_syntax)
12603 narrow = FALSE;
12604
12605 if (inst.reloc.exp.X_op != O_constant
12606 || inst.reloc.exp.X_add_number != 0)
12607 narrow = FALSE;
12608
12609 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12610 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12611 if (narrow)
12612 {
12613 inst.reloc.type = BFD_RELOC_UNUSED;
12614 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12615 inst.instruction |= Rs << 3;
12616 inst.instruction |= Rd;
12617 }
12618 else
12619 {
12620 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12621 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12622 }
c19d1205
ZW
12623 }
12624 else
12625 encode_thumb32_shifted_operand (2);
12626}
b99bd4ef 12627
c19d1205
ZW
12628static void
12629do_t_setend (void)
12630{
12e37cbc
MGD
12631 if (warn_on_deprecated
12632 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12633 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12634
e07e6e58 12635 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12636 if (inst.operands[0].imm)
12637 inst.instruction |= 0x8;
12638}
b99bd4ef 12639
c19d1205
ZW
12640static void
12641do_t_shift (void)
12642{
12643 if (!inst.operands[1].present)
12644 inst.operands[1].reg = inst.operands[0].reg;
12645
12646 if (unified_syntax)
12647 {
3d388997
PB
12648 bfd_boolean narrow;
12649 int shift_kind;
12650
12651 switch (inst.instruction)
12652 {
12653 case T_MNEM_asr:
12654 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12655 case T_MNEM_lsl:
12656 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12657 case T_MNEM_lsr:
12658 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12659 case T_MNEM_ror:
12660 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12661 default: abort ();
12662 }
12663
12664 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12665 narrow = !in_it_block ();
3d388997 12666 else
e07e6e58 12667 narrow = in_it_block ();
3d388997
PB
12668 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12669 narrow = FALSE;
12670 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12671 narrow = FALSE;
12672 if (inst.operands[2].isreg
12673 && (inst.operands[1].reg != inst.operands[0].reg
12674 || inst.operands[2].reg > 7))
12675 narrow = FALSE;
12676 if (inst.size_req == 4)
12677 narrow = FALSE;
12678
fdfde340
JM
12679 reject_bad_reg (inst.operands[0].reg);
12680 reject_bad_reg (inst.operands[1].reg);
c921be7d 12681
3d388997 12682 if (!narrow)
c19d1205
ZW
12683 {
12684 if (inst.operands[2].isreg)
b99bd4ef 12685 {
fdfde340 12686 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12687 inst.instruction = THUMB_OP32 (inst.instruction);
12688 inst.instruction |= inst.operands[0].reg << 8;
12689 inst.instruction |= inst.operands[1].reg << 16;
12690 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12691
12692 /* PR 12854: Error on extraneous shifts. */
12693 constraint (inst.operands[2].shifted,
12694 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12695 }
12696 else
12697 {
12698 inst.operands[1].shifted = 1;
3d388997 12699 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12700 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12701 ? T_MNEM_movs : T_MNEM_mov);
12702 inst.instruction |= inst.operands[0].reg << 8;
12703 encode_thumb32_shifted_operand (1);
12704 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12705 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12706 }
12707 }
12708 else
12709 {
c19d1205 12710 if (inst.operands[2].isreg)
b99bd4ef 12711 {
3d388997 12712 switch (shift_kind)
b99bd4ef 12713 {
3d388997
PB
12714 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12715 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12716 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12717 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12718 default: abort ();
b99bd4ef 12719 }
5f4273c7 12720
c19d1205
ZW
12721 inst.instruction |= inst.operands[0].reg;
12722 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12723
12724 /* PR 12854: Error on extraneous shifts. */
12725 constraint (inst.operands[2].shifted,
12726 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12727 }
12728 else
12729 {
3d388997 12730 switch (shift_kind)
b99bd4ef 12731 {
3d388997
PB
12732 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12733 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12734 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12735 default: abort ();
b99bd4ef 12736 }
c19d1205
ZW
12737 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12738 inst.instruction |= inst.operands[0].reg;
12739 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12740 }
12741 }
c19d1205
ZW
12742 }
12743 else
12744 {
12745 constraint (inst.operands[0].reg > 7
12746 || inst.operands[1].reg > 7, BAD_HIREG);
12747 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12748
c19d1205
ZW
12749 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12750 {
12751 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12752 constraint (inst.operands[0].reg != inst.operands[1].reg,
12753 _("source1 and dest must be same register"));
b99bd4ef 12754
c19d1205
ZW
12755 switch (inst.instruction)
12756 {
12757 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12758 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12759 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12760 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12761 default: abort ();
12762 }
5f4273c7 12763
c19d1205
ZW
12764 inst.instruction |= inst.operands[0].reg;
12765 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12766
12767 /* PR 12854: Error on extraneous shifts. */
12768 constraint (inst.operands[2].shifted,
12769 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12770 }
12771 else
b99bd4ef 12772 {
c19d1205
ZW
12773 switch (inst.instruction)
12774 {
12775 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12776 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12777 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12778 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12779 default: abort ();
12780 }
12781 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12782 inst.instruction |= inst.operands[0].reg;
12783 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12784 }
12785 }
b99bd4ef
NC
12786}
12787
12788static void
c19d1205 12789do_t_simd (void)
b99bd4ef 12790{
fdfde340
JM
12791 unsigned Rd, Rn, Rm;
12792
12793 Rd = inst.operands[0].reg;
12794 Rn = inst.operands[1].reg;
12795 Rm = inst.operands[2].reg;
12796
12797 reject_bad_reg (Rd);
12798 reject_bad_reg (Rn);
12799 reject_bad_reg (Rm);
12800
12801 inst.instruction |= Rd << 8;
12802 inst.instruction |= Rn << 16;
12803 inst.instruction |= Rm;
c19d1205 12804}
b99bd4ef 12805
03ee1b7f
NC
12806static void
12807do_t_simd2 (void)
12808{
12809 unsigned Rd, Rn, Rm;
12810
12811 Rd = inst.operands[0].reg;
12812 Rm = inst.operands[1].reg;
12813 Rn = inst.operands[2].reg;
12814
12815 reject_bad_reg (Rd);
12816 reject_bad_reg (Rn);
12817 reject_bad_reg (Rm);
12818
12819 inst.instruction |= Rd << 8;
12820 inst.instruction |= Rn << 16;
12821 inst.instruction |= Rm;
12822}
12823
c19d1205 12824static void
3eb17e6b 12825do_t_smc (void)
c19d1205
ZW
12826{
12827 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12828 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12829 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12830 constraint (inst.reloc.exp.X_op != O_constant,
12831 _("expression too complex"));
12832 inst.reloc.type = BFD_RELOC_UNUSED;
12833 inst.instruction |= (value & 0xf000) >> 12;
12834 inst.instruction |= (value & 0x0ff0);
12835 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12836 /* PR gas/15623: SMC instructions must be last in an IT block. */
12837 set_it_insn_type_last ();
c19d1205 12838}
b99bd4ef 12839
90ec0d68
MGD
12840static void
12841do_t_hvc (void)
12842{
12843 unsigned int value = inst.reloc.exp.X_add_number;
12844
12845 inst.reloc.type = BFD_RELOC_UNUSED;
12846 inst.instruction |= (value & 0x0fff);
12847 inst.instruction |= (value & 0xf000) << 4;
12848}
12849
c19d1205 12850static void
3a21c15a 12851do_t_ssat_usat (int bias)
c19d1205 12852{
fdfde340
JM
12853 unsigned Rd, Rn;
12854
12855 Rd = inst.operands[0].reg;
12856 Rn = inst.operands[2].reg;
12857
12858 reject_bad_reg (Rd);
12859 reject_bad_reg (Rn);
12860
12861 inst.instruction |= Rd << 8;
3a21c15a 12862 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12863 inst.instruction |= Rn << 16;
b99bd4ef 12864
c19d1205 12865 if (inst.operands[3].present)
b99bd4ef 12866 {
3a21c15a
NC
12867 offsetT shift_amount = inst.reloc.exp.X_add_number;
12868
12869 inst.reloc.type = BFD_RELOC_UNUSED;
12870
c19d1205
ZW
12871 constraint (inst.reloc.exp.X_op != O_constant,
12872 _("expression too complex"));
b99bd4ef 12873
3a21c15a 12874 if (shift_amount != 0)
6189168b 12875 {
3a21c15a
NC
12876 constraint (shift_amount > 31,
12877 _("shift expression is too large"));
12878
c19d1205 12879 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12880 inst.instruction |= 0x00200000; /* sh bit. */
12881
12882 inst.instruction |= (shift_amount & 0x1c) << 10;
12883 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12884 }
12885 }
b99bd4ef 12886}
c921be7d 12887
3a21c15a
NC
12888static void
12889do_t_ssat (void)
12890{
12891 do_t_ssat_usat (1);
12892}
b99bd4ef 12893
0dd132b6 12894static void
c19d1205 12895do_t_ssat16 (void)
0dd132b6 12896{
fdfde340
JM
12897 unsigned Rd, Rn;
12898
12899 Rd = inst.operands[0].reg;
12900 Rn = inst.operands[2].reg;
12901
12902 reject_bad_reg (Rd);
12903 reject_bad_reg (Rn);
12904
12905 inst.instruction |= Rd << 8;
c19d1205 12906 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12907 inst.instruction |= Rn << 16;
c19d1205 12908}
0dd132b6 12909
c19d1205
ZW
12910static void
12911do_t_strex (void)
12912{
12913 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12914 || inst.operands[2].postind || inst.operands[2].writeback
12915 || inst.operands[2].immisreg || inst.operands[2].shifted
12916 || inst.operands[2].negative,
01cfc07f 12917 BAD_ADDR_MODE);
0dd132b6 12918
5be8be5d
DG
12919 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12920
c19d1205
ZW
12921 inst.instruction |= inst.operands[0].reg << 8;
12922 inst.instruction |= inst.operands[1].reg << 12;
12923 inst.instruction |= inst.operands[2].reg << 16;
12924 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12925}
12926
b99bd4ef 12927static void
c19d1205 12928do_t_strexd (void)
b99bd4ef 12929{
c19d1205
ZW
12930 if (!inst.operands[2].present)
12931 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12932
c19d1205
ZW
12933 constraint (inst.operands[0].reg == inst.operands[1].reg
12934 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12935 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12936 BAD_OVERLAP);
b99bd4ef 12937
c19d1205
ZW
12938 inst.instruction |= inst.operands[0].reg;
12939 inst.instruction |= inst.operands[1].reg << 12;
12940 inst.instruction |= inst.operands[2].reg << 8;
12941 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12942}
12943
12944static void
c19d1205 12945do_t_sxtah (void)
b99bd4ef 12946{
fdfde340
JM
12947 unsigned Rd, Rn, Rm;
12948
12949 Rd = inst.operands[0].reg;
12950 Rn = inst.operands[1].reg;
12951 Rm = inst.operands[2].reg;
12952
12953 reject_bad_reg (Rd);
12954 reject_bad_reg (Rn);
12955 reject_bad_reg (Rm);
12956
12957 inst.instruction |= Rd << 8;
12958 inst.instruction |= Rn << 16;
12959 inst.instruction |= Rm;
c19d1205
ZW
12960 inst.instruction |= inst.operands[3].imm << 4;
12961}
b99bd4ef 12962
c19d1205
ZW
12963static void
12964do_t_sxth (void)
12965{
fdfde340
JM
12966 unsigned Rd, Rm;
12967
12968 Rd = inst.operands[0].reg;
12969 Rm = inst.operands[1].reg;
12970
12971 reject_bad_reg (Rd);
12972 reject_bad_reg (Rm);
c921be7d
NC
12973
12974 if (inst.instruction <= 0xffff
12975 && inst.size_req != 4
fdfde340 12976 && Rd <= 7 && Rm <= 7
c19d1205 12977 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12978 {
c19d1205 12979 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12980 inst.instruction |= Rd;
12981 inst.instruction |= Rm << 3;
b99bd4ef 12982 }
c19d1205 12983 else if (unified_syntax)
b99bd4ef 12984 {
c19d1205
ZW
12985 if (inst.instruction <= 0xffff)
12986 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12987 inst.instruction |= Rd << 8;
12988 inst.instruction |= Rm;
c19d1205 12989 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12990 }
c19d1205 12991 else
b99bd4ef 12992 {
c19d1205
ZW
12993 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12994 _("Thumb encoding does not support rotation"));
12995 constraint (1, BAD_HIREG);
b99bd4ef 12996 }
c19d1205 12997}
b99bd4ef 12998
c19d1205
ZW
12999static void
13000do_t_swi (void)
13001{
b2a5fbdc
MGD
13002 /* We have to do the following check manually as ARM_EXT_OS only applies
13003 to ARM_EXT_V6M. */
13004 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13005 {
ac7f631b
NC
13006 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
13007 /* This only applies to the v6m howver, not later architectures. */
13008 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13009 as_bad (_("SVC is not permitted on this architecture"));
13010 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13011 }
13012
c19d1205
ZW
13013 inst.reloc.type = BFD_RELOC_ARM_SWI;
13014}
b99bd4ef 13015
92e90b6e
PB
13016static void
13017do_t_tb (void)
13018{
fdfde340 13019 unsigned Rn, Rm;
92e90b6e
PB
13020 int half;
13021
13022 half = (inst.instruction & 0x10) != 0;
e07e6e58 13023 set_it_insn_type_last ();
dfa9f0d5
PB
13024 constraint (inst.operands[0].immisreg,
13025 _("instruction requires register index"));
fdfde340
JM
13026
13027 Rn = inst.operands[0].reg;
13028 Rm = inst.operands[0].imm;
c921be7d 13029
fdfde340
JM
13030 constraint (Rn == REG_SP, BAD_SP);
13031 reject_bad_reg (Rm);
13032
92e90b6e
PB
13033 constraint (!half && inst.operands[0].shifted,
13034 _("instruction does not allow shifted index"));
fdfde340 13035 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13036}
13037
74db7efb
NC
13038static void
13039do_t_udf (void)
13040{
13041 if (!inst.operands[0].present)
13042 inst.operands[0].imm = 0;
13043
13044 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13045 {
13046 constraint (inst.size_req == 2,
13047 _("immediate value out of range"));
13048 inst.instruction = THUMB_OP32 (inst.instruction);
13049 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13050 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13051 }
13052 else
13053 {
13054 inst.instruction = THUMB_OP16 (inst.instruction);
13055 inst.instruction |= inst.operands[0].imm;
13056 }
13057
13058 set_it_insn_type (NEUTRAL_IT_INSN);
13059}
13060
13061
c19d1205
ZW
13062static void
13063do_t_usat (void)
13064{
3a21c15a 13065 do_t_ssat_usat (0);
b99bd4ef
NC
13066}
13067
13068static void
c19d1205 13069do_t_usat16 (void)
b99bd4ef 13070{
fdfde340
JM
13071 unsigned Rd, Rn;
13072
13073 Rd = inst.operands[0].reg;
13074 Rn = inst.operands[2].reg;
13075
13076 reject_bad_reg (Rd);
13077 reject_bad_reg (Rn);
13078
13079 inst.instruction |= Rd << 8;
c19d1205 13080 inst.instruction |= inst.operands[1].imm;
fdfde340 13081 inst.instruction |= Rn << 16;
b99bd4ef 13082}
c19d1205 13083
5287ad62 13084/* Neon instruction encoder helpers. */
5f4273c7 13085
5287ad62 13086/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13087
5287ad62
JB
13088/* An "invalid" code for the following tables. */
13089#define N_INV -1u
13090
13091struct neon_tab_entry
b99bd4ef 13092{
5287ad62
JB
13093 unsigned integer;
13094 unsigned float_or_poly;
13095 unsigned scalar_or_imm;
13096};
5f4273c7 13097
5287ad62
JB
13098/* Map overloaded Neon opcodes to their respective encodings. */
13099#define NEON_ENC_TAB \
13100 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13101 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13102 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13103 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13104 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13105 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13106 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13107 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13108 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13109 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13110 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13111 /* Register variants of the following two instructions are encoded as
e07e6e58 13112 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13113 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13114 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13115 X(vfma, N_INV, 0x0000c10, N_INV), \
13116 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13117 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13118 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13119 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13120 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13121 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13122 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13123 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13124 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13125 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13126 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13127 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13128 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13129 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13130 X(vshl, 0x0000400, N_INV, 0x0800510), \
13131 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13132 X(vand, 0x0000110, N_INV, 0x0800030), \
13133 X(vbic, 0x0100110, N_INV, 0x0800030), \
13134 X(veor, 0x1000110, N_INV, N_INV), \
13135 X(vorn, 0x0300110, N_INV, 0x0800010), \
13136 X(vorr, 0x0200110, N_INV, 0x0800010), \
13137 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13138 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13139 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13140 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13141 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13142 X(vst1, 0x0000000, 0x0800000, N_INV), \
13143 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13144 X(vst2, 0x0000100, 0x0800100, N_INV), \
13145 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13146 X(vst3, 0x0000200, 0x0800200, N_INV), \
13147 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13148 X(vst4, 0x0000300, 0x0800300, N_INV), \
13149 X(vmovn, 0x1b20200, N_INV, N_INV), \
13150 X(vtrn, 0x1b20080, N_INV, N_INV), \
13151 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13152 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13153 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13154 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13155 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13156 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13157 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13158 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13159 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13160 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13161 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13162 X(vseleq, 0xe000a00, N_INV, N_INV), \
13163 X(vselvs, 0xe100a00, N_INV, N_INV), \
13164 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13165 X(vselgt, 0xe300a00, N_INV, N_INV), \
13166 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13167 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13168 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13169 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13170 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13171 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13172 X(sha3op, 0x2000c00, N_INV, N_INV), \
13173 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13174 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13175
13176enum neon_opc
13177{
13178#define X(OPC,I,F,S) N_MNEM_##OPC
13179NEON_ENC_TAB
13180#undef X
13181};
b99bd4ef 13182
5287ad62
JB
13183static const struct neon_tab_entry neon_enc_tab[] =
13184{
13185#define X(OPC,I,F,S) { (I), (F), (S) }
13186NEON_ENC_TAB
13187#undef X
13188};
b99bd4ef 13189
88714cb8
DG
13190/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13191#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13192#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13193#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13194#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13195#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13196#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13197#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13198#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13199#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13200#define NEON_ENC_SINGLE_(X) \
037e8744 13201 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13202#define NEON_ENC_DOUBLE_(X) \
037e8744 13203 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13204#define NEON_ENC_FPV8_(X) \
13205 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13206
88714cb8
DG
13207#define NEON_ENCODE(type, inst) \
13208 do \
13209 { \
13210 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13211 inst.is_neon = 1; \
13212 } \
13213 while (0)
13214
13215#define check_neon_suffixes \
13216 do \
13217 { \
13218 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13219 { \
13220 as_bad (_("invalid neon suffix for non neon instruction")); \
13221 return; \
13222 } \
13223 } \
13224 while (0)
13225
037e8744
JB
13226/* Define shapes for instruction operands. The following mnemonic characters
13227 are used in this table:
5287ad62 13228
037e8744 13229 F - VFP S<n> register
5287ad62
JB
13230 D - Neon D<n> register
13231 Q - Neon Q<n> register
13232 I - Immediate
13233 S - Scalar
13234 R - ARM register
13235 L - D<n> register list
5f4273c7 13236
037e8744
JB
13237 This table is used to generate various data:
13238 - enumerations of the form NS_DDR to be used as arguments to
13239 neon_select_shape.
13240 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13241 - a table used to drive neon_select_shape. */
b99bd4ef 13242
037e8744
JB
13243#define NEON_SHAPE_DEF \
13244 X(3, (D, D, D), DOUBLE), \
13245 X(3, (Q, Q, Q), QUAD), \
13246 X(3, (D, D, I), DOUBLE), \
13247 X(3, (Q, Q, I), QUAD), \
13248 X(3, (D, D, S), DOUBLE), \
13249 X(3, (Q, Q, S), QUAD), \
13250 X(2, (D, D), DOUBLE), \
13251 X(2, (Q, Q), QUAD), \
13252 X(2, (D, S), DOUBLE), \
13253 X(2, (Q, S), QUAD), \
13254 X(2, (D, R), DOUBLE), \
13255 X(2, (Q, R), QUAD), \
13256 X(2, (D, I), DOUBLE), \
13257 X(2, (Q, I), QUAD), \
13258 X(3, (D, L, D), DOUBLE), \
13259 X(2, (D, Q), MIXED), \
13260 X(2, (Q, D), MIXED), \
13261 X(3, (D, Q, I), MIXED), \
13262 X(3, (Q, D, I), MIXED), \
13263 X(3, (Q, D, D), MIXED), \
13264 X(3, (D, Q, Q), MIXED), \
13265 X(3, (Q, Q, D), MIXED), \
13266 X(3, (Q, D, S), MIXED), \
13267 X(3, (D, Q, S), MIXED), \
13268 X(4, (D, D, D, I), DOUBLE), \
13269 X(4, (Q, Q, Q, I), QUAD), \
13270 X(2, (F, F), SINGLE), \
13271 X(3, (F, F, F), SINGLE), \
13272 X(2, (F, I), SINGLE), \
13273 X(2, (F, D), MIXED), \
13274 X(2, (D, F), MIXED), \
13275 X(3, (F, F, I), MIXED), \
13276 X(4, (R, R, F, F), SINGLE), \
13277 X(4, (F, F, R, R), SINGLE), \
13278 X(3, (D, R, R), DOUBLE), \
13279 X(3, (R, R, D), DOUBLE), \
13280 X(2, (S, R), SINGLE), \
13281 X(2, (R, S), SINGLE), \
13282 X(2, (F, R), SINGLE), \
d54af2d0
RL
13283 X(2, (R, F), SINGLE), \
13284/* Half float shape supported so far. */\
13285 X (2, (H, D), MIXED), \
13286 X (2, (D, H), MIXED), \
13287 X (2, (H, F), MIXED), \
13288 X (2, (F, H), MIXED), \
13289 X (2, (H, H), HALF), \
13290 X (2, (H, R), HALF), \
13291 X (2, (R, H), HALF), \
13292 X (2, (H, I), HALF), \
13293 X (3, (H, H, H), HALF), \
13294 X (3, (H, F, I), MIXED), \
13295 X (3, (F, H, I), MIXED)
037e8744
JB
13296
13297#define S2(A,B) NS_##A##B
13298#define S3(A,B,C) NS_##A##B##C
13299#define S4(A,B,C,D) NS_##A##B##C##D
13300
13301#define X(N, L, C) S##N L
13302
5287ad62
JB
13303enum neon_shape
13304{
037e8744
JB
13305 NEON_SHAPE_DEF,
13306 NS_NULL
5287ad62 13307};
b99bd4ef 13308
037e8744
JB
13309#undef X
13310#undef S2
13311#undef S3
13312#undef S4
13313
13314enum neon_shape_class
13315{
d54af2d0 13316 SC_HALF,
037e8744
JB
13317 SC_SINGLE,
13318 SC_DOUBLE,
13319 SC_QUAD,
13320 SC_MIXED
13321};
13322
13323#define X(N, L, C) SC_##C
13324
13325static enum neon_shape_class neon_shape_class[] =
13326{
13327 NEON_SHAPE_DEF
13328};
13329
13330#undef X
13331
13332enum neon_shape_el
13333{
d54af2d0 13334 SE_H,
037e8744
JB
13335 SE_F,
13336 SE_D,
13337 SE_Q,
13338 SE_I,
13339 SE_S,
13340 SE_R,
13341 SE_L
13342};
13343
13344/* Register widths of above. */
13345static unsigned neon_shape_el_size[] =
13346{
d54af2d0 13347 16,
037e8744
JB
13348 32,
13349 64,
13350 128,
13351 0,
13352 32,
13353 32,
13354 0
13355};
13356
13357struct neon_shape_info
13358{
13359 unsigned els;
13360 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13361};
13362
13363#define S2(A,B) { SE_##A, SE_##B }
13364#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13365#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13366
13367#define X(N, L, C) { N, S##N L }
13368
13369static struct neon_shape_info neon_shape_tab[] =
13370{
13371 NEON_SHAPE_DEF
13372};
13373
13374#undef X
13375#undef S2
13376#undef S3
13377#undef S4
13378
5287ad62
JB
13379/* Bit masks used in type checking given instructions.
13380 'N_EQK' means the type must be the same as (or based on in some way) the key
13381 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13382 set, various other bits can be set as well in order to modify the meaning of
13383 the type constraint. */
13384
13385enum neon_type_mask
13386{
8e79c3df
CM
13387 N_S8 = 0x0000001,
13388 N_S16 = 0x0000002,
13389 N_S32 = 0x0000004,
13390 N_S64 = 0x0000008,
13391 N_U8 = 0x0000010,
13392 N_U16 = 0x0000020,
13393 N_U32 = 0x0000040,
13394 N_U64 = 0x0000080,
13395 N_I8 = 0x0000100,
13396 N_I16 = 0x0000200,
13397 N_I32 = 0x0000400,
13398 N_I64 = 0x0000800,
13399 N_8 = 0x0001000,
13400 N_16 = 0x0002000,
13401 N_32 = 0x0004000,
13402 N_64 = 0x0008000,
13403 N_P8 = 0x0010000,
13404 N_P16 = 0x0020000,
13405 N_F16 = 0x0040000,
13406 N_F32 = 0x0080000,
13407 N_F64 = 0x0100000,
4f51b4bd 13408 N_P64 = 0x0200000,
c921be7d
NC
13409 N_KEY = 0x1000000, /* Key element (main type specifier). */
13410 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13411 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13412 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13413 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13414 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13415 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13416 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13417 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13418 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13419 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13420 N_UTYP = 0,
4f51b4bd 13421 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13422};
13423
dcbf9037
JB
13424#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13425
5287ad62
JB
13426#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13427#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13428#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13429#define N_SUF_32 (N_SU_32 | N_F32)
13430#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13431#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
d54af2d0 13432#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13433
13434/* Pass this as the first type argument to neon_check_type to ignore types
13435 altogether. */
13436#define N_IGNORE_TYPE (N_KEY | N_EQK)
13437
037e8744
JB
13438/* Select a "shape" for the current instruction (describing register types or
13439 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13440 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13441 function of operand parsing, so this function doesn't need to be called.
13442 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13443
13444static enum neon_shape
037e8744 13445neon_select_shape (enum neon_shape shape, ...)
5287ad62 13446{
037e8744
JB
13447 va_list ap;
13448 enum neon_shape first_shape = shape;
5287ad62
JB
13449
13450 /* Fix missing optional operands. FIXME: we don't know at this point how
13451 many arguments we should have, so this makes the assumption that we have
13452 > 1. This is true of all current Neon opcodes, I think, but may not be
13453 true in the future. */
13454 if (!inst.operands[1].present)
13455 inst.operands[1] = inst.operands[0];
13456
037e8744 13457 va_start (ap, shape);
5f4273c7 13458
21d799b5 13459 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13460 {
13461 unsigned j;
13462 int matches = 1;
13463
13464 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13465 {
13466 if (!inst.operands[j].present)
13467 {
13468 matches = 0;
13469 break;
13470 }
13471
13472 switch (neon_shape_tab[shape].el[j])
13473 {
d54af2d0
RL
13474 /* If a .f16, .16, .u16, .s16 type specifier is given over
13475 a VFP single precision register operand, it's essentially
13476 means only half of the register is used.
13477
13478 If the type specifier is given after the mnemonics, the
13479 information is stored in inst.vectype. If the type specifier
13480 is given after register operand, the information is stored
13481 in inst.operands[].vectype.
13482
13483 When there is only one type specifier, and all the register
13484 operands are the same type of hardware register, the type
13485 specifier applies to all register operands.
13486
13487 If no type specifier is given, the shape is inferred from
13488 operand information.
13489
13490 for example:
13491 vadd.f16 s0, s1, s2: NS_HHH
13492 vabs.f16 s0, s1: NS_HH
13493 vmov.f16 s0, r1: NS_HR
13494 vmov.f16 r0, s1: NS_RH
13495 vcvt.f16 r0, s1: NS_RH
13496 vcvt.f16.s32 s2, s2, #29: NS_HFI
13497 vcvt.f16.s32 s2, s2: NS_HF
13498 */
13499 case SE_H:
13500 if (!(inst.operands[j].isreg
13501 && inst.operands[j].isvec
13502 && inst.operands[j].issingle
13503 && !inst.operands[j].isquad
13504 && ((inst.vectype.elems == 1
13505 && inst.vectype.el[0].size == 16)
13506 || (inst.vectype.elems > 1
13507 && inst.vectype.el[j].size == 16)
13508 || (inst.vectype.elems == 0
13509 && inst.operands[j].vectype.type != NT_invtype
13510 && inst.operands[j].vectype.size == 16))))
13511 matches = 0;
13512 break;
13513
477330fc
RM
13514 case SE_F:
13515 if (!(inst.operands[j].isreg
13516 && inst.operands[j].isvec
13517 && inst.operands[j].issingle
d54af2d0
RL
13518 && !inst.operands[j].isquad
13519 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13520 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13521 || (inst.vectype.elems == 0
13522 && (inst.operands[j].vectype.size == 32
13523 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13524 matches = 0;
13525 break;
13526
13527 case SE_D:
13528 if (!(inst.operands[j].isreg
13529 && inst.operands[j].isvec
13530 && !inst.operands[j].isquad
13531 && !inst.operands[j].issingle))
13532 matches = 0;
13533 break;
13534
13535 case SE_R:
13536 if (!(inst.operands[j].isreg
13537 && !inst.operands[j].isvec))
13538 matches = 0;
13539 break;
13540
13541 case SE_Q:
13542 if (!(inst.operands[j].isreg
13543 && inst.operands[j].isvec
13544 && inst.operands[j].isquad
13545 && !inst.operands[j].issingle))
13546 matches = 0;
13547 break;
13548
13549 case SE_I:
13550 if (!(!inst.operands[j].isreg
13551 && !inst.operands[j].isscalar))
13552 matches = 0;
13553 break;
13554
13555 case SE_S:
13556 if (!(!inst.operands[j].isreg
13557 && inst.operands[j].isscalar))
13558 matches = 0;
13559 break;
13560
13561 case SE_L:
13562 break;
13563 }
3fde54a2
JZ
13564 if (!matches)
13565 break;
477330fc 13566 }
ad6cec43
MGD
13567 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13568 /* We've matched all the entries in the shape table, and we don't
13569 have any left over operands which have not been matched. */
477330fc 13570 break;
037e8744 13571 }
5f4273c7 13572
037e8744 13573 va_end (ap);
5287ad62 13574
037e8744
JB
13575 if (shape == NS_NULL && first_shape != NS_NULL)
13576 first_error (_("invalid instruction shape"));
5287ad62 13577
037e8744
JB
13578 return shape;
13579}
5287ad62 13580
037e8744
JB
13581/* True if SHAPE is predominantly a quadword operation (most of the time, this
13582 means the Q bit should be set). */
13583
13584static int
13585neon_quad (enum neon_shape shape)
13586{
13587 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13588}
037e8744 13589
5287ad62
JB
13590static void
13591neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13592 unsigned *g_size)
5287ad62
JB
13593{
13594 /* Allow modification to be made to types which are constrained to be
13595 based on the key element, based on bits set alongside N_EQK. */
13596 if ((typebits & N_EQK) != 0)
13597 {
13598 if ((typebits & N_HLF) != 0)
13599 *g_size /= 2;
13600 else if ((typebits & N_DBL) != 0)
13601 *g_size *= 2;
13602 if ((typebits & N_SGN) != 0)
13603 *g_type = NT_signed;
13604 else if ((typebits & N_UNS) != 0)
477330fc 13605 *g_type = NT_unsigned;
5287ad62 13606 else if ((typebits & N_INT) != 0)
477330fc 13607 *g_type = NT_integer;
5287ad62 13608 else if ((typebits & N_FLT) != 0)
477330fc 13609 *g_type = NT_float;
dcbf9037 13610 else if ((typebits & N_SIZ) != 0)
477330fc 13611 *g_type = NT_untyped;
5287ad62
JB
13612 }
13613}
5f4273c7 13614
5287ad62
JB
13615/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13616 operand type, i.e. the single type specified in a Neon instruction when it
13617 is the only one given. */
13618
13619static struct neon_type_el
13620neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13621{
13622 struct neon_type_el dest = *key;
5f4273c7 13623
9c2799c2 13624 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13625
5287ad62
JB
13626 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13627
13628 return dest;
13629}
13630
13631/* Convert Neon type and size into compact bitmask representation. */
13632
13633static enum neon_type_mask
13634type_chk_of_el_type (enum neon_el_type type, unsigned size)
13635{
13636 switch (type)
13637 {
13638 case NT_untyped:
13639 switch (size)
477330fc
RM
13640 {
13641 case 8: return N_8;
13642 case 16: return N_16;
13643 case 32: return N_32;
13644 case 64: return N_64;
13645 default: ;
13646 }
5287ad62
JB
13647 break;
13648
13649 case NT_integer:
13650 switch (size)
477330fc
RM
13651 {
13652 case 8: return N_I8;
13653 case 16: return N_I16;
13654 case 32: return N_I32;
13655 case 64: return N_I64;
13656 default: ;
13657 }
5287ad62
JB
13658 break;
13659
13660 case NT_float:
037e8744 13661 switch (size)
477330fc 13662 {
8e79c3df 13663 case 16: return N_F16;
477330fc
RM
13664 case 32: return N_F32;
13665 case 64: return N_F64;
13666 default: ;
13667 }
5287ad62
JB
13668 break;
13669
13670 case NT_poly:
13671 switch (size)
477330fc
RM
13672 {
13673 case 8: return N_P8;
13674 case 16: return N_P16;
4f51b4bd 13675 case 64: return N_P64;
477330fc
RM
13676 default: ;
13677 }
5287ad62
JB
13678 break;
13679
13680 case NT_signed:
13681 switch (size)
477330fc
RM
13682 {
13683 case 8: return N_S8;
13684 case 16: return N_S16;
13685 case 32: return N_S32;
13686 case 64: return N_S64;
13687 default: ;
13688 }
5287ad62
JB
13689 break;
13690
13691 case NT_unsigned:
13692 switch (size)
477330fc
RM
13693 {
13694 case 8: return N_U8;
13695 case 16: return N_U16;
13696 case 32: return N_U32;
13697 case 64: return N_U64;
13698 default: ;
13699 }
5287ad62
JB
13700 break;
13701
13702 default: ;
13703 }
5f4273c7 13704
5287ad62
JB
13705 return N_UTYP;
13706}
13707
13708/* Convert compact Neon bitmask type representation to a type and size. Only
13709 handles the case where a single bit is set in the mask. */
13710
dcbf9037 13711static int
5287ad62 13712el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13713 enum neon_type_mask mask)
5287ad62 13714{
dcbf9037
JB
13715 if ((mask & N_EQK) != 0)
13716 return FAIL;
13717
5287ad62
JB
13718 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13719 *size = 8;
c70a8987 13720 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13721 *size = 16;
dcbf9037 13722 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13723 *size = 32;
4f51b4bd 13724 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13725 *size = 64;
dcbf9037
JB
13726 else
13727 return FAIL;
13728
5287ad62
JB
13729 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13730 *type = NT_signed;
dcbf9037 13731 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13732 *type = NT_unsigned;
dcbf9037 13733 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13734 *type = NT_integer;
dcbf9037 13735 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13736 *type = NT_untyped;
4f51b4bd 13737 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13738 *type = NT_poly;
d54af2d0 13739 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13740 *type = NT_float;
dcbf9037
JB
13741 else
13742 return FAIL;
5f4273c7 13743
dcbf9037 13744 return SUCCESS;
5287ad62
JB
13745}
13746
13747/* Modify a bitmask of allowed types. This is only needed for type
13748 relaxation. */
13749
13750static unsigned
13751modify_types_allowed (unsigned allowed, unsigned mods)
13752{
13753 unsigned size;
13754 enum neon_el_type type;
13755 unsigned destmask;
13756 int i;
5f4273c7 13757
5287ad62 13758 destmask = 0;
5f4273c7 13759
5287ad62
JB
13760 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13761 {
21d799b5 13762 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13763 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13764 {
13765 neon_modify_type_size (mods, &type, &size);
13766 destmask |= type_chk_of_el_type (type, size);
13767 }
5287ad62 13768 }
5f4273c7 13769
5287ad62
JB
13770 return destmask;
13771}
13772
13773/* Check type and return type classification.
13774 The manual states (paraphrase): If one datatype is given, it indicates the
13775 type given in:
13776 - the second operand, if there is one
13777 - the operand, if there is no second operand
13778 - the result, if there are no operands.
13779 This isn't quite good enough though, so we use a concept of a "key" datatype
13780 which is set on a per-instruction basis, which is the one which matters when
13781 only one data type is written.
13782 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13783 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13784
13785static struct neon_type_el
13786neon_check_type (unsigned els, enum neon_shape ns, ...)
13787{
13788 va_list ap;
13789 unsigned i, pass, key_el = 0;
13790 unsigned types[NEON_MAX_TYPE_ELS];
13791 enum neon_el_type k_type = NT_invtype;
13792 unsigned k_size = -1u;
13793 struct neon_type_el badtype = {NT_invtype, -1};
13794 unsigned key_allowed = 0;
13795
13796 /* Optional registers in Neon instructions are always (not) in operand 1.
13797 Fill in the missing operand here, if it was omitted. */
13798 if (els > 1 && !inst.operands[1].present)
13799 inst.operands[1] = inst.operands[0];
13800
13801 /* Suck up all the varargs. */
13802 va_start (ap, ns);
13803 for (i = 0; i < els; i++)
13804 {
13805 unsigned thisarg = va_arg (ap, unsigned);
13806 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13807 {
13808 va_end (ap);
13809 return badtype;
13810 }
5287ad62
JB
13811 types[i] = thisarg;
13812 if ((thisarg & N_KEY) != 0)
477330fc 13813 key_el = i;
5287ad62
JB
13814 }
13815 va_end (ap);
13816
dcbf9037
JB
13817 if (inst.vectype.elems > 0)
13818 for (i = 0; i < els; i++)
13819 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13820 {
13821 first_error (_("types specified in both the mnemonic and operands"));
13822 return badtype;
13823 }
dcbf9037 13824
5287ad62
JB
13825 /* Duplicate inst.vectype elements here as necessary.
13826 FIXME: No idea if this is exactly the same as the ARM assembler,
13827 particularly when an insn takes one register and one non-register
13828 operand. */
13829 if (inst.vectype.elems == 1 && els > 1)
13830 {
13831 unsigned j;
13832 inst.vectype.elems = els;
13833 inst.vectype.el[key_el] = inst.vectype.el[0];
13834 for (j = 0; j < els; j++)
477330fc
RM
13835 if (j != key_el)
13836 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13837 types[j]);
dcbf9037
JB
13838 }
13839 else if (inst.vectype.elems == 0 && els > 0)
13840 {
13841 unsigned j;
13842 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13843 after each operand. We allow some flexibility here; as long as the
13844 "key" operand has a type, we can infer the others. */
dcbf9037 13845 for (j = 0; j < els; j++)
477330fc
RM
13846 if (inst.operands[j].vectype.type != NT_invtype)
13847 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13848
13849 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13850 {
13851 for (j = 0; j < els; j++)
13852 if (inst.operands[j].vectype.type == NT_invtype)
13853 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13854 types[j]);
13855 }
dcbf9037 13856 else
477330fc
RM
13857 {
13858 first_error (_("operand types can't be inferred"));
13859 return badtype;
13860 }
5287ad62
JB
13861 }
13862 else if (inst.vectype.elems != els)
13863 {
dcbf9037 13864 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13865 return badtype;
13866 }
13867
13868 for (pass = 0; pass < 2; pass++)
13869 {
13870 for (i = 0; i < els; i++)
477330fc
RM
13871 {
13872 unsigned thisarg = types[i];
13873 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13874 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13875 enum neon_el_type g_type = inst.vectype.el[i].type;
13876 unsigned g_size = inst.vectype.el[i].size;
13877
13878 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13879 integer types if sign-specific variants are unavailable. */
477330fc 13880 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13881 && (types_allowed & N_SU_ALL) == 0)
13882 g_type = NT_integer;
13883
477330fc 13884 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13885 them. Some instructions only care about signs for some element
13886 sizes, so handle that properly. */
477330fc 13887 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13888 && ((g_size == 8 && (types_allowed & N_8) != 0)
13889 || (g_size == 16 && (types_allowed & N_16) != 0)
13890 || (g_size == 32 && (types_allowed & N_32) != 0)
13891 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13892 g_type = NT_untyped;
13893
477330fc
RM
13894 if (pass == 0)
13895 {
13896 if ((thisarg & N_KEY) != 0)
13897 {
13898 k_type = g_type;
13899 k_size = g_size;
13900 key_allowed = thisarg & ~N_KEY;
13901 }
13902 }
13903 else
13904 {
13905 if ((thisarg & N_VFP) != 0)
13906 {
13907 enum neon_shape_el regshape;
13908 unsigned regwidth, match;
99b253c5
NC
13909
13910 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13911 if (ns == NS_NULL)
13912 {
13913 first_error (_("invalid instruction shape"));
13914 return badtype;
13915 }
477330fc
RM
13916 regshape = neon_shape_tab[ns].el[i];
13917 regwidth = neon_shape_el_size[regshape];
13918
13919 /* In VFP mode, operands must match register widths. If we
13920 have a key operand, use its width, else use the width of
13921 the current operand. */
13922 if (k_size != -1u)
13923 match = k_size;
13924 else
13925 match = g_size;
13926
9db2f6b4
RL
13927 /* FP16 will use a single precision register. */
13928 if (regwidth == 32 && match == 16)
13929 {
13930 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13931 match = regwidth;
13932 else
13933 {
13934 inst.error = _(BAD_FP16);
13935 return badtype;
13936 }
13937 }
13938
477330fc
RM
13939 if (regwidth != match)
13940 {
13941 first_error (_("operand size must match register width"));
13942 return badtype;
13943 }
13944 }
13945
13946 if ((thisarg & N_EQK) == 0)
13947 {
13948 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13949
13950 if ((given_type & types_allowed) == 0)
13951 {
13952 first_error (_("bad type in Neon instruction"));
13953 return badtype;
13954 }
13955 }
13956 else
13957 {
13958 enum neon_el_type mod_k_type = k_type;
13959 unsigned mod_k_size = k_size;
13960 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13961 if (g_type != mod_k_type || g_size != mod_k_size)
13962 {
13963 first_error (_("inconsistent types in Neon instruction"));
13964 return badtype;
13965 }
13966 }
13967 }
13968 }
5287ad62
JB
13969 }
13970
13971 return inst.vectype.el[key_el];
13972}
13973
037e8744 13974/* Neon-style VFP instruction forwarding. */
5287ad62 13975
037e8744
JB
13976/* Thumb VFP instructions have 0xE in the condition field. */
13977
13978static void
13979do_vfp_cond_or_thumb (void)
5287ad62 13980{
88714cb8
DG
13981 inst.is_neon = 1;
13982
5287ad62 13983 if (thumb_mode)
037e8744 13984 inst.instruction |= 0xe0000000;
5287ad62 13985 else
037e8744 13986 inst.instruction |= inst.cond << 28;
5287ad62
JB
13987}
13988
037e8744
JB
13989/* Look up and encode a simple mnemonic, for use as a helper function for the
13990 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13991 etc. It is assumed that operand parsing has already been done, and that the
13992 operands are in the form expected by the given opcode (this isn't necessarily
13993 the same as the form in which they were parsed, hence some massaging must
13994 take place before this function is called).
13995 Checks current arch version against that in the looked-up opcode. */
5287ad62 13996
037e8744
JB
13997static void
13998do_vfp_nsyn_opcode (const char *opname)
5287ad62 13999{
037e8744 14000 const struct asm_opcode *opcode;
5f4273c7 14001
21d799b5 14002 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14003
037e8744
JB
14004 if (!opcode)
14005 abort ();
5287ad62 14006
037e8744 14007 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14008 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14009 _(BAD_FPU));
5287ad62 14010
88714cb8
DG
14011 inst.is_neon = 1;
14012
037e8744
JB
14013 if (thumb_mode)
14014 {
14015 inst.instruction = opcode->tvalue;
14016 opcode->tencode ();
14017 }
14018 else
14019 {
14020 inst.instruction = (inst.cond << 28) | opcode->avalue;
14021 opcode->aencode ();
14022 }
14023}
5287ad62
JB
14024
14025static void
037e8744 14026do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14027{
037e8744
JB
14028 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14029
9db2f6b4 14030 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14031 {
14032 if (is_add)
477330fc 14033 do_vfp_nsyn_opcode ("fadds");
037e8744 14034 else
477330fc 14035 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14036
14037 /* ARMv8.2 fp16 instruction. */
14038 if (rs == NS_HHH)
14039 do_scalar_fp16_v82_encode ();
037e8744
JB
14040 }
14041 else
14042 {
14043 if (is_add)
477330fc 14044 do_vfp_nsyn_opcode ("faddd");
037e8744 14045 else
477330fc 14046 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14047 }
14048}
14049
14050/* Check operand types to see if this is a VFP instruction, and if so call
14051 PFN (). */
14052
14053static int
14054try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14055{
14056 enum neon_shape rs;
14057 struct neon_type_el et;
14058
14059 switch (args)
14060 {
14061 case 2:
9db2f6b4
RL
14062 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14063 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14064 break;
5f4273c7 14065
037e8744 14066 case 3:
9db2f6b4
RL
14067 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14068 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14069 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14070 break;
14071
14072 default:
14073 abort ();
14074 }
14075
14076 if (et.type != NT_invtype)
14077 {
14078 pfn (rs);
14079 return SUCCESS;
14080 }
037e8744 14081
99b253c5 14082 inst.error = NULL;
037e8744
JB
14083 return FAIL;
14084}
14085
14086static void
14087do_vfp_nsyn_mla_mls (enum neon_shape rs)
14088{
14089 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14090
9db2f6b4 14091 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14092 {
14093 if (is_mla)
477330fc 14094 do_vfp_nsyn_opcode ("fmacs");
037e8744 14095 else
477330fc 14096 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14097
14098 /* ARMv8.2 fp16 instruction. */
14099 if (rs == NS_HHH)
14100 do_scalar_fp16_v82_encode ();
037e8744
JB
14101 }
14102 else
14103 {
14104 if (is_mla)
477330fc 14105 do_vfp_nsyn_opcode ("fmacd");
037e8744 14106 else
477330fc 14107 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14108 }
14109}
14110
62f3b8c8
PB
14111static void
14112do_vfp_nsyn_fma_fms (enum neon_shape rs)
14113{
14114 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14115
9db2f6b4 14116 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14117 {
14118 if (is_fma)
477330fc 14119 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14120 else
477330fc 14121 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14122
14123 /* ARMv8.2 fp16 instruction. */
14124 if (rs == NS_HHH)
14125 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14126 }
14127 else
14128 {
14129 if (is_fma)
477330fc 14130 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14131 else
477330fc 14132 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14133 }
14134}
14135
037e8744
JB
14136static void
14137do_vfp_nsyn_mul (enum neon_shape rs)
14138{
9db2f6b4
RL
14139 if (rs == NS_FFF || rs == NS_HHH)
14140 {
14141 do_vfp_nsyn_opcode ("fmuls");
14142
14143 /* ARMv8.2 fp16 instruction. */
14144 if (rs == NS_HHH)
14145 do_scalar_fp16_v82_encode ();
14146 }
037e8744
JB
14147 else
14148 do_vfp_nsyn_opcode ("fmuld");
14149}
14150
14151static void
14152do_vfp_nsyn_abs_neg (enum neon_shape rs)
14153{
14154 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14155 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14156
9db2f6b4 14157 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14158 {
14159 if (is_neg)
477330fc 14160 do_vfp_nsyn_opcode ("fnegs");
037e8744 14161 else
477330fc 14162 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14163
14164 /* ARMv8.2 fp16 instruction. */
14165 if (rs == NS_HH)
14166 do_scalar_fp16_v82_encode ();
037e8744
JB
14167 }
14168 else
14169 {
14170 if (is_neg)
477330fc 14171 do_vfp_nsyn_opcode ("fnegd");
037e8744 14172 else
477330fc 14173 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14174 }
14175}
14176
14177/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14178 insns belong to Neon, and are handled elsewhere. */
14179
14180static void
14181do_vfp_nsyn_ldm_stm (int is_dbmode)
14182{
14183 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14184 if (is_ldm)
14185 {
14186 if (is_dbmode)
477330fc 14187 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14188 else
477330fc 14189 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14190 }
14191 else
14192 {
14193 if (is_dbmode)
477330fc 14194 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14195 else
477330fc 14196 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14197 }
14198}
14199
037e8744
JB
14200static void
14201do_vfp_nsyn_sqrt (void)
14202{
9db2f6b4
RL
14203 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14204 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14205
9db2f6b4
RL
14206 if (rs == NS_FF || rs == NS_HH)
14207 {
14208 do_vfp_nsyn_opcode ("fsqrts");
14209
14210 /* ARMv8.2 fp16 instruction. */
14211 if (rs == NS_HH)
14212 do_scalar_fp16_v82_encode ();
14213 }
037e8744
JB
14214 else
14215 do_vfp_nsyn_opcode ("fsqrtd");
14216}
14217
14218static void
14219do_vfp_nsyn_div (void)
14220{
9db2f6b4 14221 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14222 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14223 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14224
9db2f6b4
RL
14225 if (rs == NS_FFF || rs == NS_HHH)
14226 {
14227 do_vfp_nsyn_opcode ("fdivs");
14228
14229 /* ARMv8.2 fp16 instruction. */
14230 if (rs == NS_HHH)
14231 do_scalar_fp16_v82_encode ();
14232 }
037e8744
JB
14233 else
14234 do_vfp_nsyn_opcode ("fdivd");
14235}
14236
14237static void
14238do_vfp_nsyn_nmul (void)
14239{
9db2f6b4 14240 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14241 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14242 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14243
9db2f6b4 14244 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14245 {
88714cb8 14246 NEON_ENCODE (SINGLE, inst);
037e8744 14247 do_vfp_sp_dyadic ();
9db2f6b4
RL
14248
14249 /* ARMv8.2 fp16 instruction. */
14250 if (rs == NS_HHH)
14251 do_scalar_fp16_v82_encode ();
037e8744
JB
14252 }
14253 else
14254 {
88714cb8 14255 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14256 do_vfp_dp_rd_rn_rm ();
14257 }
14258 do_vfp_cond_or_thumb ();
9db2f6b4 14259
037e8744
JB
14260}
14261
14262static void
14263do_vfp_nsyn_cmp (void)
14264{
9db2f6b4 14265 enum neon_shape rs;
037e8744
JB
14266 if (inst.operands[1].isreg)
14267 {
9db2f6b4
RL
14268 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14269 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14270
9db2f6b4 14271 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14272 {
14273 NEON_ENCODE (SINGLE, inst);
14274 do_vfp_sp_monadic ();
14275 }
037e8744 14276 else
477330fc
RM
14277 {
14278 NEON_ENCODE (DOUBLE, inst);
14279 do_vfp_dp_rd_rm ();
14280 }
037e8744
JB
14281 }
14282 else
14283 {
9db2f6b4
RL
14284 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14285 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14286
14287 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14288 {
14289 case N_MNEM_vcmp:
14290 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14291 break;
14292 case N_MNEM_vcmpe:
14293 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14294 break;
14295 default:
14296 abort ();
14297 }
5f4273c7 14298
9db2f6b4 14299 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14300 {
14301 NEON_ENCODE (SINGLE, inst);
14302 do_vfp_sp_compare_z ();
14303 }
037e8744 14304 else
477330fc
RM
14305 {
14306 NEON_ENCODE (DOUBLE, inst);
14307 do_vfp_dp_rd ();
14308 }
037e8744
JB
14309 }
14310 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14311
14312 /* ARMv8.2 fp16 instruction. */
14313 if (rs == NS_HI || rs == NS_HH)
14314 do_scalar_fp16_v82_encode ();
037e8744
JB
14315}
14316
14317static void
14318nsyn_insert_sp (void)
14319{
14320 inst.operands[1] = inst.operands[0];
14321 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14322 inst.operands[0].reg = REG_SP;
037e8744
JB
14323 inst.operands[0].isreg = 1;
14324 inst.operands[0].writeback = 1;
14325 inst.operands[0].present = 1;
14326}
14327
14328static void
14329do_vfp_nsyn_push (void)
14330{
14331 nsyn_insert_sp ();
14332 if (inst.operands[1].issingle)
14333 do_vfp_nsyn_opcode ("fstmdbs");
14334 else
14335 do_vfp_nsyn_opcode ("fstmdbd");
14336}
14337
14338static void
14339do_vfp_nsyn_pop (void)
14340{
14341 nsyn_insert_sp ();
14342 if (inst.operands[1].issingle)
22b5b651 14343 do_vfp_nsyn_opcode ("fldmias");
037e8744 14344 else
22b5b651 14345 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14346}
14347
14348/* Fix up Neon data-processing instructions, ORing in the correct bits for
14349 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14350
88714cb8
DG
14351static void
14352neon_dp_fixup (struct arm_it* insn)
037e8744 14353{
88714cb8
DG
14354 unsigned int i = insn->instruction;
14355 insn->is_neon = 1;
14356
037e8744
JB
14357 if (thumb_mode)
14358 {
14359 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14360 if (i & (1 << 24))
477330fc 14361 i |= 1 << 28;
5f4273c7 14362
037e8744 14363 i &= ~(1 << 24);
5f4273c7 14364
037e8744
JB
14365 i |= 0xef000000;
14366 }
14367 else
14368 i |= 0xf2000000;
5f4273c7 14369
88714cb8 14370 insn->instruction = i;
037e8744
JB
14371}
14372
14373/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14374 (0, 1, 2, 3). */
14375
14376static unsigned
14377neon_logbits (unsigned x)
14378{
14379 return ffs (x) - 4;
14380}
14381
14382#define LOW4(R) ((R) & 0xf)
14383#define HI1(R) (((R) >> 4) & 1)
14384
14385/* Encode insns with bit pattern:
14386
14387 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14388 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14389
037e8744
JB
14390 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14391 different meaning for some instruction. */
14392
14393static void
14394neon_three_same (int isquad, int ubit, int size)
14395{
14396 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14397 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14398 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14399 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14400 inst.instruction |= LOW4 (inst.operands[2].reg);
14401 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14402 inst.instruction |= (isquad != 0) << 6;
14403 inst.instruction |= (ubit != 0) << 24;
14404 if (size != -1)
14405 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14406
88714cb8 14407 neon_dp_fixup (&inst);
037e8744
JB
14408}
14409
14410/* Encode instructions of the form:
14411
14412 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14413 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14414
14415 Don't write size if SIZE == -1. */
14416
14417static void
14418neon_two_same (int qbit, int ubit, int size)
14419{
14420 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14421 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14422 inst.instruction |= LOW4 (inst.operands[1].reg);
14423 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14424 inst.instruction |= (qbit != 0) << 6;
14425 inst.instruction |= (ubit != 0) << 24;
14426
14427 if (size != -1)
14428 inst.instruction |= neon_logbits (size) << 18;
14429
88714cb8 14430 neon_dp_fixup (&inst);
5287ad62
JB
14431}
14432
14433/* Neon instruction encoders, in approximate order of appearance. */
14434
14435static void
14436do_neon_dyadic_i_su (void)
14437{
037e8744 14438 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14439 struct neon_type_el et = neon_check_type (3, rs,
14440 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14441 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14442}
14443
14444static void
14445do_neon_dyadic_i64_su (void)
14446{
037e8744 14447 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14448 struct neon_type_el et = neon_check_type (3, rs,
14449 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14450 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14451}
14452
14453static void
14454neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14455 unsigned immbits)
5287ad62
JB
14456{
14457 unsigned size = et.size >> 3;
14458 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14459 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14460 inst.instruction |= LOW4 (inst.operands[1].reg);
14461 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14462 inst.instruction |= (isquad != 0) << 6;
14463 inst.instruction |= immbits << 16;
14464 inst.instruction |= (size >> 3) << 7;
14465 inst.instruction |= (size & 0x7) << 19;
14466 if (write_ubit)
14467 inst.instruction |= (uval != 0) << 24;
14468
88714cb8 14469 neon_dp_fixup (&inst);
5287ad62
JB
14470}
14471
14472static void
14473do_neon_shl_imm (void)
14474{
14475 if (!inst.operands[2].isreg)
14476 {
037e8744 14477 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14478 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14479 int imm = inst.operands[2].imm;
14480
14481 constraint (imm < 0 || (unsigned)imm >= et.size,
14482 _("immediate out of range for shift"));
88714cb8 14483 NEON_ENCODE (IMMED, inst);
cb3b1e65 14484 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14485 }
14486 else
14487 {
037e8744 14488 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14489 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14490 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14491 unsigned int tmp;
14492
14493 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14494 vshl.xx Dd, Dm, Dn
14495 whereas other 3-register operations encoded by neon_three_same have
14496 syntax like:
14497 vadd.xx Dd, Dn, Dm
14498 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14499 here. */
627907b7
JB
14500 tmp = inst.operands[2].reg;
14501 inst.operands[2].reg = inst.operands[1].reg;
14502 inst.operands[1].reg = tmp;
88714cb8 14503 NEON_ENCODE (INTEGER, inst);
037e8744 14504 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14505 }
14506}
14507
14508static void
14509do_neon_qshl_imm (void)
14510{
14511 if (!inst.operands[2].isreg)
14512 {
037e8744 14513 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14514 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14515 int imm = inst.operands[2].imm;
627907b7 14516
cb3b1e65
JB
14517 constraint (imm < 0 || (unsigned)imm >= et.size,
14518 _("immediate out of range for shift"));
88714cb8 14519 NEON_ENCODE (IMMED, inst);
cb3b1e65 14520 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14521 }
14522 else
14523 {
037e8744 14524 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14525 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14526 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14527 unsigned int tmp;
14528
14529 /* See note in do_neon_shl_imm. */
14530 tmp = inst.operands[2].reg;
14531 inst.operands[2].reg = inst.operands[1].reg;
14532 inst.operands[1].reg = tmp;
88714cb8 14533 NEON_ENCODE (INTEGER, inst);
037e8744 14534 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14535 }
14536}
14537
627907b7
JB
14538static void
14539do_neon_rshl (void)
14540{
14541 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14542 struct neon_type_el et = neon_check_type (3, rs,
14543 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14544 unsigned int tmp;
14545
14546 tmp = inst.operands[2].reg;
14547 inst.operands[2].reg = inst.operands[1].reg;
14548 inst.operands[1].reg = tmp;
14549 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14550}
14551
5287ad62
JB
14552static int
14553neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14554{
036dc3f7
PB
14555 /* Handle .I8 pseudo-instructions. */
14556 if (size == 8)
5287ad62 14557 {
5287ad62 14558 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14559 FIXME is this the intended semantics? There doesn't seem much point in
14560 accepting .I8 if so. */
5287ad62
JB
14561 immediate |= immediate << 8;
14562 size = 16;
036dc3f7
PB
14563 }
14564
14565 if (size >= 32)
14566 {
14567 if (immediate == (immediate & 0x000000ff))
14568 {
14569 *immbits = immediate;
14570 return 0x1;
14571 }
14572 else if (immediate == (immediate & 0x0000ff00))
14573 {
14574 *immbits = immediate >> 8;
14575 return 0x3;
14576 }
14577 else if (immediate == (immediate & 0x00ff0000))
14578 {
14579 *immbits = immediate >> 16;
14580 return 0x5;
14581 }
14582 else if (immediate == (immediate & 0xff000000))
14583 {
14584 *immbits = immediate >> 24;
14585 return 0x7;
14586 }
14587 if ((immediate & 0xffff) != (immediate >> 16))
14588 goto bad_immediate;
14589 immediate &= 0xffff;
5287ad62
JB
14590 }
14591
14592 if (immediate == (immediate & 0x000000ff))
14593 {
14594 *immbits = immediate;
036dc3f7 14595 return 0x9;
5287ad62
JB
14596 }
14597 else if (immediate == (immediate & 0x0000ff00))
14598 {
14599 *immbits = immediate >> 8;
036dc3f7 14600 return 0xb;
5287ad62
JB
14601 }
14602
14603 bad_immediate:
dcbf9037 14604 first_error (_("immediate value out of range"));
5287ad62
JB
14605 return FAIL;
14606}
14607
5287ad62
JB
14608static void
14609do_neon_logic (void)
14610{
14611 if (inst.operands[2].present && inst.operands[2].isreg)
14612 {
037e8744 14613 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14614 neon_check_type (3, rs, N_IGNORE_TYPE);
14615 /* U bit and size field were set as part of the bitmask. */
88714cb8 14616 NEON_ENCODE (INTEGER, inst);
037e8744 14617 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14618 }
14619 else
14620 {
4316f0d2
DG
14621 const int three_ops_form = (inst.operands[2].present
14622 && !inst.operands[2].isreg);
14623 const int immoperand = (three_ops_form ? 2 : 1);
14624 enum neon_shape rs = (three_ops_form
14625 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14626 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14627 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14628 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14629 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14630 unsigned immbits;
14631 int cmode;
5f4273c7 14632
5287ad62 14633 if (et.type == NT_invtype)
477330fc 14634 return;
5f4273c7 14635
4316f0d2
DG
14636 if (three_ops_form)
14637 constraint (inst.operands[0].reg != inst.operands[1].reg,
14638 _("first and second operands shall be the same register"));
14639
88714cb8 14640 NEON_ENCODE (IMMED, inst);
5287ad62 14641
4316f0d2 14642 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14643 if (et.size == 64)
14644 {
14645 /* .i64 is a pseudo-op, so the immediate must be a repeating
14646 pattern. */
4316f0d2
DG
14647 if (immbits != (inst.operands[immoperand].regisimm ?
14648 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14649 {
14650 /* Set immbits to an invalid constant. */
14651 immbits = 0xdeadbeef;
14652 }
14653 }
14654
5287ad62 14655 switch (opcode)
477330fc
RM
14656 {
14657 case N_MNEM_vbic:
14658 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14659 break;
14660
14661 case N_MNEM_vorr:
14662 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14663 break;
14664
14665 case N_MNEM_vand:
14666 /* Pseudo-instruction for VBIC. */
14667 neon_invert_size (&immbits, 0, et.size);
14668 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14669 break;
14670
14671 case N_MNEM_vorn:
14672 /* Pseudo-instruction for VORR. */
14673 neon_invert_size (&immbits, 0, et.size);
14674 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14675 break;
14676
14677 default:
14678 abort ();
14679 }
5287ad62
JB
14680
14681 if (cmode == FAIL)
477330fc 14682 return;
5287ad62 14683
037e8744 14684 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14685 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14686 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14687 inst.instruction |= cmode << 8;
14688 neon_write_immbits (immbits);
5f4273c7 14689
88714cb8 14690 neon_dp_fixup (&inst);
5287ad62
JB
14691 }
14692}
14693
14694static void
14695do_neon_bitfield (void)
14696{
037e8744 14697 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14698 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14699 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14700}
14701
14702static void
dcbf9037 14703neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14704 unsigned destbits)
5287ad62 14705{
037e8744 14706 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14707 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14708 types | N_KEY);
5287ad62
JB
14709 if (et.type == NT_float)
14710 {
88714cb8 14711 NEON_ENCODE (FLOAT, inst);
037e8744 14712 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14713 }
14714 else
14715 {
88714cb8 14716 NEON_ENCODE (INTEGER, inst);
037e8744 14717 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14718 }
14719}
14720
14721static void
14722do_neon_dyadic_if_su (void)
14723{
dcbf9037 14724 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14725}
14726
14727static void
14728do_neon_dyadic_if_su_d (void)
14729{
14730 /* This version only allow D registers, but that constraint is enforced during
14731 operand parsing so we don't need to do anything extra here. */
dcbf9037 14732 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14733}
14734
5287ad62
JB
14735static void
14736do_neon_dyadic_if_i_d (void)
14737{
428e3f1f
PB
14738 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14739 affected if we specify unsigned args. */
14740 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14741}
14742
037e8744
JB
14743enum vfp_or_neon_is_neon_bits
14744{
14745 NEON_CHECK_CC = 1,
73924fbc
MGD
14746 NEON_CHECK_ARCH = 2,
14747 NEON_CHECK_ARCH8 = 4
037e8744
JB
14748};
14749
14750/* Call this function if an instruction which may have belonged to the VFP or
14751 Neon instruction sets, but turned out to be a Neon instruction (due to the
14752 operand types involved, etc.). We have to check and/or fix-up a couple of
14753 things:
14754
14755 - Make sure the user hasn't attempted to make a Neon instruction
14756 conditional.
14757 - Alter the value in the condition code field if necessary.
14758 - Make sure that the arch supports Neon instructions.
14759
14760 Which of these operations take place depends on bits from enum
14761 vfp_or_neon_is_neon_bits.
14762
14763 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14764 current instruction's condition is COND_ALWAYS, the condition field is
14765 changed to inst.uncond_value. This is necessary because instructions shared
14766 between VFP and Neon may be conditional for the VFP variants only, and the
14767 unconditional Neon version must have, e.g., 0xF in the condition field. */
14768
14769static int
14770vfp_or_neon_is_neon (unsigned check)
14771{
14772 /* Conditions are always legal in Thumb mode (IT blocks). */
14773 if (!thumb_mode && (check & NEON_CHECK_CC))
14774 {
14775 if (inst.cond != COND_ALWAYS)
477330fc
RM
14776 {
14777 first_error (_(BAD_COND));
14778 return FAIL;
14779 }
037e8744 14780 if (inst.uncond_value != -1)
477330fc 14781 inst.instruction |= inst.uncond_value << 28;
037e8744 14782 }
5f4273c7 14783
037e8744 14784 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14785 && !mark_feature_used (&fpu_neon_ext_v1))
14786 {
14787 first_error (_(BAD_FPU));
14788 return FAIL;
14789 }
14790
14791 if ((check & NEON_CHECK_ARCH8)
14792 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14793 {
14794 first_error (_(BAD_FPU));
14795 return FAIL;
14796 }
5f4273c7 14797
037e8744
JB
14798 return SUCCESS;
14799}
14800
5287ad62
JB
14801static void
14802do_neon_addsub_if_i (void)
14803{
037e8744
JB
14804 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14805 return;
14806
14807 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14808 return;
14809
5287ad62
JB
14810 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14811 affected if we specify unsigned args. */
dcbf9037 14812 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14813}
14814
14815/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14816 result to be:
14817 V<op> A,B (A is operand 0, B is operand 2)
14818 to mean:
14819 V<op> A,B,A
14820 not:
14821 V<op> A,B,B
14822 so handle that case specially. */
14823
14824static void
14825neon_exchange_operands (void)
14826{
14827 void *scratch = alloca (sizeof (inst.operands[0]));
14828 if (inst.operands[1].present)
14829 {
14830 /* Swap operands[1] and operands[2]. */
14831 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14832 inst.operands[1] = inst.operands[2];
14833 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14834 }
14835 else
14836 {
14837 inst.operands[1] = inst.operands[2];
14838 inst.operands[2] = inst.operands[0];
14839 }
14840}
14841
14842static void
14843neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14844{
14845 if (inst.operands[2].isreg)
14846 {
14847 if (invert)
477330fc 14848 neon_exchange_operands ();
dcbf9037 14849 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14850 }
14851 else
14852 {
037e8744 14853 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14854 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14855 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14856
88714cb8 14857 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14858 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14859 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14860 inst.instruction |= LOW4 (inst.operands[1].reg);
14861 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14862 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14863 inst.instruction |= (et.type == NT_float) << 10;
14864 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14865
88714cb8 14866 neon_dp_fixup (&inst);
5287ad62
JB
14867 }
14868}
14869
14870static void
14871do_neon_cmp (void)
14872{
14873 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14874}
14875
14876static void
14877do_neon_cmp_inv (void)
14878{
14879 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14880}
14881
14882static void
14883do_neon_ceq (void)
14884{
14885 neon_compare (N_IF_32, N_IF_32, FALSE);
14886}
14887
14888/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14889 scalars, which are encoded in 5 bits, M : Rm.
14890 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14891 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14892 index in M. */
14893
14894static unsigned
14895neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14896{
dcbf9037
JB
14897 unsigned regno = NEON_SCALAR_REG (scalar);
14898 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14899
14900 switch (elsize)
14901 {
14902 case 16:
14903 if (regno > 7 || elno > 3)
477330fc 14904 goto bad_scalar;
5287ad62 14905 return regno | (elno << 3);
5f4273c7 14906
5287ad62
JB
14907 case 32:
14908 if (regno > 15 || elno > 1)
477330fc 14909 goto bad_scalar;
5287ad62
JB
14910 return regno | (elno << 4);
14911
14912 default:
14913 bad_scalar:
dcbf9037 14914 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14915 }
14916
14917 return 0;
14918}
14919
14920/* Encode multiply / multiply-accumulate scalar instructions. */
14921
14922static void
14923neon_mul_mac (struct neon_type_el et, int ubit)
14924{
dcbf9037
JB
14925 unsigned scalar;
14926
14927 /* Give a more helpful error message if we have an invalid type. */
14928 if (et.type == NT_invtype)
14929 return;
5f4273c7 14930
dcbf9037 14931 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14932 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14933 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14934 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14935 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14936 inst.instruction |= LOW4 (scalar);
14937 inst.instruction |= HI1 (scalar) << 5;
14938 inst.instruction |= (et.type == NT_float) << 8;
14939 inst.instruction |= neon_logbits (et.size) << 20;
14940 inst.instruction |= (ubit != 0) << 24;
14941
88714cb8 14942 neon_dp_fixup (&inst);
5287ad62
JB
14943}
14944
14945static void
14946do_neon_mac_maybe_scalar (void)
14947{
037e8744
JB
14948 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14949 return;
14950
14951 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14952 return;
14953
5287ad62
JB
14954 if (inst.operands[2].isscalar)
14955 {
037e8744 14956 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14957 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14958 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14959 NEON_ENCODE (SCALAR, inst);
037e8744 14960 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14961 }
14962 else
428e3f1f
PB
14963 {
14964 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14965 affected if we specify unsigned args. */
14966 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14967 }
5287ad62
JB
14968}
14969
62f3b8c8
PB
14970static void
14971do_neon_fmac (void)
14972{
14973 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14974 return;
14975
14976 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14977 return;
14978
14979 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14980}
14981
5287ad62
JB
14982static void
14983do_neon_tst (void)
14984{
037e8744 14985 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14986 struct neon_type_el et = neon_check_type (3, rs,
14987 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14988 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14989}
14990
14991/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14992 same types as the MAC equivalents. The polynomial type for this instruction
14993 is encoded the same as the integer type. */
14994
14995static void
14996do_neon_mul (void)
14997{
037e8744
JB
14998 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14999 return;
15000
15001 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15002 return;
15003
5287ad62
JB
15004 if (inst.operands[2].isscalar)
15005 do_neon_mac_maybe_scalar ();
15006 else
dcbf9037 15007 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
15008}
15009
15010static void
15011do_neon_qdmulh (void)
15012{
15013 if (inst.operands[2].isscalar)
15014 {
037e8744 15015 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15016 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15017 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15018 NEON_ENCODE (SCALAR, inst);
037e8744 15019 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15020 }
15021 else
15022 {
037e8744 15023 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15024 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15025 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15026 NEON_ENCODE (INTEGER, inst);
5287ad62 15027 /* The U bit (rounding) comes from bit mask. */
037e8744 15028 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15029 }
15030}
15031
643afb90
MW
15032static void
15033do_neon_qrdmlah (void)
15034{
15035 /* Check we're on the correct architecture. */
15036 if (!mark_feature_used (&fpu_neon_ext_armv8))
15037 inst.error =
15038 _("instruction form not available on this architecture.");
15039 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15040 {
15041 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15042 record_feature_use (&fpu_neon_ext_v8_1);
15043 }
15044
15045 if (inst.operands[2].isscalar)
15046 {
15047 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15048 struct neon_type_el et = neon_check_type (3, rs,
15049 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15050 NEON_ENCODE (SCALAR, inst);
15051 neon_mul_mac (et, neon_quad (rs));
15052 }
15053 else
15054 {
15055 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15056 struct neon_type_el et = neon_check_type (3, rs,
15057 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15058 NEON_ENCODE (INTEGER, inst);
15059 /* The U bit (rounding) comes from bit mask. */
15060 neon_three_same (neon_quad (rs), 0, et.size);
15061 }
15062}
15063
5287ad62
JB
15064static void
15065do_neon_fcmp_absolute (void)
15066{
037e8744 15067 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15068 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
15069 /* Size field comes from bit mask. */
037e8744 15070 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
15071}
15072
15073static void
15074do_neon_fcmp_absolute_inv (void)
15075{
15076 neon_exchange_operands ();
15077 do_neon_fcmp_absolute ();
15078}
15079
15080static void
15081do_neon_step (void)
15082{
037e8744 15083 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15084 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 15085 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
15086}
15087
15088static void
15089do_neon_abs_neg (void)
15090{
037e8744
JB
15091 enum neon_shape rs;
15092 struct neon_type_el et;
5f4273c7 15093
037e8744
JB
15094 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15095 return;
15096
15097 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15098 return;
15099
15100 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15101 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 15102
5287ad62
JB
15103 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15104 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15105 inst.instruction |= LOW4 (inst.operands[1].reg);
15106 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15107 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15108 inst.instruction |= (et.type == NT_float) << 10;
15109 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15110
88714cb8 15111 neon_dp_fixup (&inst);
5287ad62
JB
15112}
15113
15114static void
15115do_neon_sli (void)
15116{
037e8744 15117 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15118 struct neon_type_el et = neon_check_type (2, rs,
15119 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15120 int imm = inst.operands[2].imm;
15121 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15122 _("immediate out of range for insert"));
037e8744 15123 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15124}
15125
15126static void
15127do_neon_sri (void)
15128{
037e8744 15129 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15130 struct neon_type_el et = neon_check_type (2, rs,
15131 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15132 int imm = inst.operands[2].imm;
15133 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15134 _("immediate out of range for insert"));
037e8744 15135 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15136}
15137
15138static void
15139do_neon_qshlu_imm (void)
15140{
037e8744 15141 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15142 struct neon_type_el et = neon_check_type (2, rs,
15143 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15144 int imm = inst.operands[2].imm;
15145 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15146 _("immediate out of range for shift"));
5287ad62
JB
15147 /* Only encodes the 'U present' variant of the instruction.
15148 In this case, signed types have OP (bit 8) set to 0.
15149 Unsigned types have OP set to 1. */
15150 inst.instruction |= (et.type == NT_unsigned) << 8;
15151 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15152 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15153}
15154
15155static void
15156do_neon_qmovn (void)
15157{
15158 struct neon_type_el et = neon_check_type (2, NS_DQ,
15159 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15160 /* Saturating move where operands can be signed or unsigned, and the
15161 destination has the same signedness. */
88714cb8 15162 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15163 if (et.type == NT_unsigned)
15164 inst.instruction |= 0xc0;
15165 else
15166 inst.instruction |= 0x80;
15167 neon_two_same (0, 1, et.size / 2);
15168}
15169
15170static void
15171do_neon_qmovun (void)
15172{
15173 struct neon_type_el et = neon_check_type (2, NS_DQ,
15174 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15175 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15176 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15177 neon_two_same (0, 1, et.size / 2);
15178}
15179
15180static void
15181do_neon_rshift_sat_narrow (void)
15182{
15183 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15184 or unsigned. If operands are unsigned, results must also be unsigned. */
15185 struct neon_type_el et = neon_check_type (2, NS_DQI,
15186 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15187 int imm = inst.operands[2].imm;
15188 /* This gets the bounds check, size encoding and immediate bits calculation
15189 right. */
15190 et.size /= 2;
5f4273c7 15191
5287ad62
JB
15192 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15193 VQMOVN.I<size> <Dd>, <Qm>. */
15194 if (imm == 0)
15195 {
15196 inst.operands[2].present = 0;
15197 inst.instruction = N_MNEM_vqmovn;
15198 do_neon_qmovn ();
15199 return;
15200 }
5f4273c7 15201
5287ad62 15202 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15203 _("immediate out of range"));
5287ad62
JB
15204 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15205}
15206
15207static void
15208do_neon_rshift_sat_narrow_u (void)
15209{
15210 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15211 or unsigned. If operands are unsigned, results must also be unsigned. */
15212 struct neon_type_el et = neon_check_type (2, NS_DQI,
15213 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15214 int imm = inst.operands[2].imm;
15215 /* This gets the bounds check, size encoding and immediate bits calculation
15216 right. */
15217 et.size /= 2;
15218
15219 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15220 VQMOVUN.I<size> <Dd>, <Qm>. */
15221 if (imm == 0)
15222 {
15223 inst.operands[2].present = 0;
15224 inst.instruction = N_MNEM_vqmovun;
15225 do_neon_qmovun ();
15226 return;
15227 }
15228
15229 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15230 _("immediate out of range"));
5287ad62
JB
15231 /* FIXME: The manual is kind of unclear about what value U should have in
15232 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15233 must be 1. */
15234 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15235}
15236
15237static void
15238do_neon_movn (void)
15239{
15240 struct neon_type_el et = neon_check_type (2, NS_DQ,
15241 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15242 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15243 neon_two_same (0, 1, et.size / 2);
15244}
15245
15246static void
15247do_neon_rshift_narrow (void)
15248{
15249 struct neon_type_el et = neon_check_type (2, NS_DQI,
15250 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15251 int imm = inst.operands[2].imm;
15252 /* This gets the bounds check, size encoding and immediate bits calculation
15253 right. */
15254 et.size /= 2;
5f4273c7 15255
5287ad62
JB
15256 /* If immediate is zero then we are a pseudo-instruction for
15257 VMOVN.I<size> <Dd>, <Qm> */
15258 if (imm == 0)
15259 {
15260 inst.operands[2].present = 0;
15261 inst.instruction = N_MNEM_vmovn;
15262 do_neon_movn ();
15263 return;
15264 }
5f4273c7 15265
5287ad62 15266 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15267 _("immediate out of range for narrowing operation"));
5287ad62
JB
15268 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15269}
15270
15271static void
15272do_neon_shll (void)
15273{
15274 /* FIXME: Type checking when lengthening. */
15275 struct neon_type_el et = neon_check_type (2, NS_QDI,
15276 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15277 unsigned imm = inst.operands[2].imm;
15278
15279 if (imm == et.size)
15280 {
15281 /* Maximum shift variant. */
88714cb8 15282 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15283 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15284 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15285 inst.instruction |= LOW4 (inst.operands[1].reg);
15286 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15287 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15288
88714cb8 15289 neon_dp_fixup (&inst);
5287ad62
JB
15290 }
15291 else
15292 {
15293 /* A more-specific type check for non-max versions. */
15294 et = neon_check_type (2, NS_QDI,
477330fc 15295 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15296 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15297 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15298 }
15299}
15300
037e8744 15301/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15302 the current instruction is. */
15303
6b9a8b67
MGD
15304#define CVT_FLAVOUR_VAR \
15305 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15306 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15307 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15308 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15309 /* Half-precision conversions. */ \
15310 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15311 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15312 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15313 Compared with single/double precision variants, only the co-processor \
15314 field is different, so the encoding flow is reused here. */ \
15315 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15316 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15317 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15318 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15319 /* VFP instructions. */ \
15320 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15321 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15322 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15323 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15324 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15325 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15326 /* VFP instructions with bitshift. */ \
15327 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15328 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15329 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15330 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15331 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15332 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15333 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15334 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15335
15336#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15337 neon_cvt_flavour_##C,
15338
15339/* The different types of conversions we can do. */
15340enum neon_cvt_flavour
15341{
15342 CVT_FLAVOUR_VAR
15343 neon_cvt_flavour_invalid,
15344 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15345};
15346
15347#undef CVT_VAR
15348
15349static enum neon_cvt_flavour
15350get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15351{
6b9a8b67
MGD
15352#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15353 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15354 if (et.type != NT_invtype) \
15355 { \
15356 inst.error = NULL; \
15357 return (neon_cvt_flavour_##C); \
5287ad62 15358 }
6b9a8b67 15359
5287ad62 15360 struct neon_type_el et;
037e8744 15361 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15362 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15363 /* The instruction versions which take an immediate take one register
15364 argument, which is extended to the width of the full register. Thus the
15365 "source" and "destination" registers must have the same width. Hack that
15366 here by making the size equal to the key (wider, in this case) operand. */
15367 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15368
6b9a8b67
MGD
15369 CVT_FLAVOUR_VAR;
15370
15371 return neon_cvt_flavour_invalid;
5287ad62
JB
15372#undef CVT_VAR
15373}
15374
7e8e6784
MGD
15375enum neon_cvt_mode
15376{
15377 neon_cvt_mode_a,
15378 neon_cvt_mode_n,
15379 neon_cvt_mode_p,
15380 neon_cvt_mode_m,
15381 neon_cvt_mode_z,
30bdf752
MGD
15382 neon_cvt_mode_x,
15383 neon_cvt_mode_r
7e8e6784
MGD
15384};
15385
037e8744
JB
15386/* Neon-syntax VFP conversions. */
15387
5287ad62 15388static void
6b9a8b67 15389do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15390{
037e8744 15391 const char *opname = 0;
5f4273c7 15392
d54af2d0
RL
15393 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15394 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15395 {
037e8744
JB
15396 /* Conversions with immediate bitshift. */
15397 const char *enc[] =
477330fc 15398 {
6b9a8b67
MGD
15399#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15400 CVT_FLAVOUR_VAR
15401 NULL
15402#undef CVT_VAR
477330fc 15403 };
037e8744 15404
6b9a8b67 15405 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15406 {
15407 opname = enc[flavour];
15408 constraint (inst.operands[0].reg != inst.operands[1].reg,
15409 _("operands 0 and 1 must be the same register"));
15410 inst.operands[1] = inst.operands[2];
15411 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15412 }
5287ad62
JB
15413 }
15414 else
15415 {
037e8744
JB
15416 /* Conversions without bitshift. */
15417 const char *enc[] =
477330fc 15418 {
6b9a8b67
MGD
15419#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15420 CVT_FLAVOUR_VAR
15421 NULL
15422#undef CVT_VAR
477330fc 15423 };
037e8744 15424
6b9a8b67 15425 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15426 opname = enc[flavour];
037e8744
JB
15427 }
15428
15429 if (opname)
15430 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15431
15432 /* ARMv8.2 fp16 VCVT instruction. */
15433 if (flavour == neon_cvt_flavour_s32_f16
15434 || flavour == neon_cvt_flavour_u32_f16
15435 || flavour == neon_cvt_flavour_f16_u32
15436 || flavour == neon_cvt_flavour_f16_s32)
15437 do_scalar_fp16_v82_encode ();
037e8744
JB
15438}
15439
15440static void
15441do_vfp_nsyn_cvtz (void)
15442{
d54af2d0 15443 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15444 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15445 const char *enc[] =
15446 {
6b9a8b67
MGD
15447#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15448 CVT_FLAVOUR_VAR
15449 NULL
15450#undef CVT_VAR
037e8744
JB
15451 };
15452
6b9a8b67 15453 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15454 do_vfp_nsyn_opcode (enc[flavour]);
15455}
f31fef98 15456
037e8744 15457static void
bacebabc 15458do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15459 enum neon_cvt_mode mode)
15460{
15461 int sz, op;
15462 int rm;
15463
a715796b
TG
15464 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15465 D register operands. */
15466 if (flavour == neon_cvt_flavour_s32_f64
15467 || flavour == neon_cvt_flavour_u32_f64)
15468 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15469 _(BAD_FPU));
15470
9db2f6b4
RL
15471 if (flavour == neon_cvt_flavour_s32_f16
15472 || flavour == neon_cvt_flavour_u32_f16)
15473 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15474 _(BAD_FP16));
15475
7e8e6784
MGD
15476 set_it_insn_type (OUTSIDE_IT_INSN);
15477
15478 switch (flavour)
15479 {
15480 case neon_cvt_flavour_s32_f64:
15481 sz = 1;
827f64ff 15482 op = 1;
7e8e6784
MGD
15483 break;
15484 case neon_cvt_flavour_s32_f32:
15485 sz = 0;
15486 op = 1;
15487 break;
9db2f6b4
RL
15488 case neon_cvt_flavour_s32_f16:
15489 sz = 0;
15490 op = 1;
15491 break;
7e8e6784
MGD
15492 case neon_cvt_flavour_u32_f64:
15493 sz = 1;
15494 op = 0;
15495 break;
15496 case neon_cvt_flavour_u32_f32:
15497 sz = 0;
15498 op = 0;
15499 break;
9db2f6b4
RL
15500 case neon_cvt_flavour_u32_f16:
15501 sz = 0;
15502 op = 0;
15503 break;
7e8e6784
MGD
15504 default:
15505 first_error (_("invalid instruction shape"));
15506 return;
15507 }
15508
15509 switch (mode)
15510 {
15511 case neon_cvt_mode_a: rm = 0; break;
15512 case neon_cvt_mode_n: rm = 1; break;
15513 case neon_cvt_mode_p: rm = 2; break;
15514 case neon_cvt_mode_m: rm = 3; break;
15515 default: first_error (_("invalid rounding mode")); return;
15516 }
15517
15518 NEON_ENCODE (FPV8, inst);
15519 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15520 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15521 inst.instruction |= sz << 8;
9db2f6b4
RL
15522
15523 /* ARMv8.2 fp16 VCVT instruction. */
15524 if (flavour == neon_cvt_flavour_s32_f16
15525 ||flavour == neon_cvt_flavour_u32_f16)
15526 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15527 inst.instruction |= op << 7;
15528 inst.instruction |= rm << 16;
15529 inst.instruction |= 0xf0000000;
15530 inst.is_neon = TRUE;
15531}
15532
15533static void
15534do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15535{
15536 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15537 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15538 NS_FH, NS_HF, NS_FHI, NS_HFI,
15539 NS_NULL);
6b9a8b67 15540 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15541
e3e535bc 15542 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15543 if (mode == neon_cvt_mode_z
e3e535bc 15544 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
15545 && (flavour == neon_cvt_flavour_s32_f32
15546 || flavour == neon_cvt_flavour_u32_f32
15547 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15548 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15549 && (rs == NS_FD || rs == NS_FF))
15550 {
15551 do_vfp_nsyn_cvtz ();
15552 return;
15553 }
15554
9db2f6b4
RL
15555 /* ARMv8.2 fp16 VCVT conversions. */
15556 if (mode == neon_cvt_mode_z
15557 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15558 && (flavour == neon_cvt_flavour_s32_f16
15559 || flavour == neon_cvt_flavour_u32_f16)
15560 && (rs == NS_FH))
15561 {
15562 do_vfp_nsyn_cvtz ();
15563 do_scalar_fp16_v82_encode ();
15564 return;
15565 }
15566
037e8744 15567 /* VFP rather than Neon conversions. */
6b9a8b67 15568 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15569 {
7e8e6784
MGD
15570 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15571 do_vfp_nsyn_cvt (rs, flavour);
15572 else
15573 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15574
037e8744
JB
15575 return;
15576 }
15577
15578 switch (rs)
15579 {
15580 case NS_DDI:
15581 case NS_QQI:
15582 {
477330fc
RM
15583 unsigned immbits;
15584 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 15585
477330fc
RM
15586 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15587 return;
037e8744 15588
477330fc
RM
15589 /* Fixed-point conversion with #0 immediate is encoded as an
15590 integer conversion. */
15591 if (inst.operands[2].present && inst.operands[2].imm == 0)
15592 goto int_encode;
35997600 15593 immbits = 32 - inst.operands[2].imm;
477330fc
RM
15594 NEON_ENCODE (IMMED, inst);
15595 if (flavour != neon_cvt_flavour_invalid)
15596 inst.instruction |= enctab[flavour];
15597 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15598 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15599 inst.instruction |= LOW4 (inst.operands[1].reg);
15600 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15601 inst.instruction |= neon_quad (rs) << 6;
15602 inst.instruction |= 1 << 21;
15603 inst.instruction |= immbits << 16;
15604
15605 neon_dp_fixup (&inst);
037e8744
JB
15606 }
15607 break;
15608
15609 case NS_DD:
15610 case NS_QQ:
7e8e6784
MGD
15611 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15612 {
15613 NEON_ENCODE (FLOAT, inst);
15614 set_it_insn_type (OUTSIDE_IT_INSN);
15615
15616 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15617 return;
15618
15619 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15620 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15621 inst.instruction |= LOW4 (inst.operands[1].reg);
15622 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15623 inst.instruction |= neon_quad (rs) << 6;
15624 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15625 inst.instruction |= mode << 8;
15626 if (thumb_mode)
15627 inst.instruction |= 0xfc000000;
15628 else
15629 inst.instruction |= 0xf0000000;
15630 }
15631 else
15632 {
037e8744 15633 int_encode:
7e8e6784
MGD
15634 {
15635 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 15636
7e8e6784 15637 NEON_ENCODE (INTEGER, inst);
037e8744 15638
7e8e6784
MGD
15639 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15640 return;
037e8744 15641
7e8e6784
MGD
15642 if (flavour != neon_cvt_flavour_invalid)
15643 inst.instruction |= enctab[flavour];
037e8744 15644
7e8e6784
MGD
15645 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15646 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15647 inst.instruction |= LOW4 (inst.operands[1].reg);
15648 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15649 inst.instruction |= neon_quad (rs) << 6;
15650 inst.instruction |= 2 << 18;
037e8744 15651
7e8e6784
MGD
15652 neon_dp_fixup (&inst);
15653 }
15654 }
15655 break;
037e8744 15656
8e79c3df
CM
15657 /* Half-precision conversions for Advanced SIMD -- neon. */
15658 case NS_QD:
15659 case NS_DQ:
15660
15661 if ((rs == NS_DQ)
15662 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15663 {
15664 as_bad (_("operand size must match register width"));
15665 break;
15666 }
15667
15668 if ((rs == NS_QD)
15669 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15670 {
15671 as_bad (_("operand size must match register width"));
15672 break;
15673 }
15674
15675 if (rs == NS_DQ)
477330fc 15676 inst.instruction = 0x3b60600;
8e79c3df
CM
15677 else
15678 inst.instruction = 0x3b60700;
15679
15680 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15681 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15682 inst.instruction |= LOW4 (inst.operands[1].reg);
15683 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15684 neon_dp_fixup (&inst);
8e79c3df
CM
15685 break;
15686
037e8744
JB
15687 default:
15688 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15689 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15690 do_vfp_nsyn_cvt (rs, flavour);
15691 else
15692 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15693 }
5287ad62
JB
15694}
15695
e3e535bc
NC
15696static void
15697do_neon_cvtr (void)
15698{
7e8e6784 15699 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15700}
15701
15702static void
15703do_neon_cvt (void)
15704{
7e8e6784
MGD
15705 do_neon_cvt_1 (neon_cvt_mode_z);
15706}
15707
15708static void
15709do_neon_cvta (void)
15710{
15711 do_neon_cvt_1 (neon_cvt_mode_a);
15712}
15713
15714static void
15715do_neon_cvtn (void)
15716{
15717 do_neon_cvt_1 (neon_cvt_mode_n);
15718}
15719
15720static void
15721do_neon_cvtp (void)
15722{
15723 do_neon_cvt_1 (neon_cvt_mode_p);
15724}
15725
15726static void
15727do_neon_cvtm (void)
15728{
15729 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15730}
15731
8e79c3df 15732static void
c70a8987 15733do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15734{
c70a8987
MGD
15735 if (is_double)
15736 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15737
c70a8987
MGD
15738 encode_arm_vfp_reg (inst.operands[0].reg,
15739 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15740 encode_arm_vfp_reg (inst.operands[1].reg,
15741 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15742 inst.instruction |= to ? 0x10000 : 0;
15743 inst.instruction |= t ? 0x80 : 0;
15744 inst.instruction |= is_double ? 0x100 : 0;
15745 do_vfp_cond_or_thumb ();
15746}
8e79c3df 15747
c70a8987
MGD
15748static void
15749do_neon_cvttb_1 (bfd_boolean t)
15750{
d54af2d0
RL
15751 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15752 NS_DF, NS_DH, NS_NULL);
8e79c3df 15753
c70a8987
MGD
15754 if (rs == NS_NULL)
15755 return;
15756 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15757 {
15758 inst.error = NULL;
15759 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15760 }
15761 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15762 {
15763 inst.error = NULL;
15764 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15765 }
15766 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15767 {
a715796b
TG
15768 /* The VCVTB and VCVTT instructions with D-register operands
15769 don't work for SP only targets. */
15770 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15771 _(BAD_FPU));
15772
c70a8987
MGD
15773 inst.error = NULL;
15774 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15775 }
15776 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15777 {
a715796b
TG
15778 /* The VCVTB and VCVTT instructions with D-register operands
15779 don't work for SP only targets. */
15780 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15781 _(BAD_FPU));
15782
c70a8987
MGD
15783 inst.error = NULL;
15784 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15785 }
15786 else
15787 return;
15788}
15789
15790static void
15791do_neon_cvtb (void)
15792{
15793 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15794}
15795
15796
15797static void
15798do_neon_cvtt (void)
15799{
c70a8987 15800 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15801}
15802
5287ad62
JB
15803static void
15804neon_move_immediate (void)
15805{
037e8744
JB
15806 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15807 struct neon_type_el et = neon_check_type (2, rs,
15808 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15809 unsigned immlo, immhi = 0, immbits;
c96612cc 15810 int op, cmode, float_p;
5287ad62 15811
037e8744 15812 constraint (et.type == NT_invtype,
477330fc 15813 _("operand size must be specified for immediate VMOV"));
037e8744 15814
5287ad62
JB
15815 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15816 op = (inst.instruction & (1 << 5)) != 0;
15817
15818 immlo = inst.operands[1].imm;
15819 if (inst.operands[1].regisimm)
15820 immhi = inst.operands[1].reg;
15821
15822 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15823 _("immediate has bits set outside the operand size"));
5287ad62 15824
c96612cc
JB
15825 float_p = inst.operands[1].immisfloat;
15826
15827 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15828 et.size, et.type)) == FAIL)
5287ad62
JB
15829 {
15830 /* Invert relevant bits only. */
15831 neon_invert_size (&immlo, &immhi, et.size);
15832 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15833 with one or the other; those cases are caught by
15834 neon_cmode_for_move_imm. */
5287ad62 15835 op = !op;
c96612cc
JB
15836 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15837 &op, et.size, et.type)) == FAIL)
477330fc
RM
15838 {
15839 first_error (_("immediate out of range"));
15840 return;
15841 }
5287ad62
JB
15842 }
15843
15844 inst.instruction &= ~(1 << 5);
15845 inst.instruction |= op << 5;
15846
15847 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15848 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15849 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15850 inst.instruction |= cmode << 8;
15851
15852 neon_write_immbits (immbits);
15853}
15854
15855static void
15856do_neon_mvn (void)
15857{
15858 if (inst.operands[1].isreg)
15859 {
037e8744 15860 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15861
88714cb8 15862 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15863 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15864 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15865 inst.instruction |= LOW4 (inst.operands[1].reg);
15866 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15867 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15868 }
15869 else
15870 {
88714cb8 15871 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15872 neon_move_immediate ();
15873 }
15874
88714cb8 15875 neon_dp_fixup (&inst);
5287ad62
JB
15876}
15877
15878/* Encode instructions of form:
15879
15880 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15881 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15882
15883static void
15884neon_mixed_length (struct neon_type_el et, unsigned size)
15885{
15886 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15887 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15888 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15889 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15890 inst.instruction |= LOW4 (inst.operands[2].reg);
15891 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15892 inst.instruction |= (et.type == NT_unsigned) << 24;
15893 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15894
88714cb8 15895 neon_dp_fixup (&inst);
5287ad62
JB
15896}
15897
15898static void
15899do_neon_dyadic_long (void)
15900{
15901 /* FIXME: Type checking for lengthening op. */
15902 struct neon_type_el et = neon_check_type (3, NS_QDD,
15903 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15904 neon_mixed_length (et, et.size);
15905}
15906
15907static void
15908do_neon_abal (void)
15909{
15910 struct neon_type_el et = neon_check_type (3, NS_QDD,
15911 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15912 neon_mixed_length (et, et.size);
15913}
15914
15915static void
15916neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15917{
15918 if (inst.operands[2].isscalar)
15919 {
dcbf9037 15920 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15921 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15922 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15923 neon_mul_mac (et, et.type == NT_unsigned);
15924 }
15925 else
15926 {
15927 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15928 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15929 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15930 neon_mixed_length (et, et.size);
15931 }
15932}
15933
15934static void
15935do_neon_mac_maybe_scalar_long (void)
15936{
15937 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15938}
15939
15940static void
15941do_neon_dyadic_wide (void)
15942{
15943 struct neon_type_el et = neon_check_type (3, NS_QQD,
15944 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15945 neon_mixed_length (et, et.size);
15946}
15947
15948static void
15949do_neon_dyadic_narrow (void)
15950{
15951 struct neon_type_el et = neon_check_type (3, NS_QDD,
15952 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15953 /* Operand sign is unimportant, and the U bit is part of the opcode,
15954 so force the operand type to integer. */
15955 et.type = NT_integer;
5287ad62
JB
15956 neon_mixed_length (et, et.size / 2);
15957}
15958
15959static void
15960do_neon_mul_sat_scalar_long (void)
15961{
15962 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15963}
15964
15965static void
15966do_neon_vmull (void)
15967{
15968 if (inst.operands[2].isscalar)
15969 do_neon_mac_maybe_scalar_long ();
15970 else
15971 {
15972 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15973 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15974
5287ad62 15975 if (et.type == NT_poly)
477330fc 15976 NEON_ENCODE (POLY, inst);
5287ad62 15977 else
477330fc 15978 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15979
15980 /* For polynomial encoding the U bit must be zero, and the size must
15981 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15982 obviously, as 0b10). */
15983 if (et.size == 64)
15984 {
15985 /* Check we're on the correct architecture. */
15986 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15987 inst.error =
15988 _("Instruction form not available on this architecture.");
15989
15990 et.size = 32;
15991 }
15992
5287ad62
JB
15993 neon_mixed_length (et, et.size);
15994 }
15995}
15996
15997static void
15998do_neon_ext (void)
15999{
037e8744 16000 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16001 struct neon_type_el et = neon_check_type (3, rs,
16002 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16003 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16004
16005 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16006 _("shift out of range"));
5287ad62
JB
16007 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16008 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16009 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16010 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16011 inst.instruction |= LOW4 (inst.operands[2].reg);
16012 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16013 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16014 inst.instruction |= imm << 8;
5f4273c7 16015
88714cb8 16016 neon_dp_fixup (&inst);
5287ad62
JB
16017}
16018
16019static void
16020do_neon_rev (void)
16021{
037e8744 16022 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16023 struct neon_type_el et = neon_check_type (2, rs,
16024 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16025 unsigned op = (inst.instruction >> 7) & 3;
16026 /* N (width of reversed regions) is encoded as part of the bitmask. We
16027 extract it here to check the elements to be reversed are smaller.
16028 Otherwise we'd get a reserved instruction. */
16029 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16030 gas_assert (elsize != 0);
5287ad62 16031 constraint (et.size >= elsize,
477330fc 16032 _("elements must be smaller than reversal region"));
037e8744 16033 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16034}
16035
16036static void
16037do_neon_dup (void)
16038{
16039 if (inst.operands[1].isscalar)
16040 {
037e8744 16041 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16042 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16043 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16044 unsigned sizebits = et.size >> 3;
dcbf9037 16045 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16046 int logsize = neon_logbits (et.size);
dcbf9037 16047 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16048
16049 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16050 return;
037e8744 16051
88714cb8 16052 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16053 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16054 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16055 inst.instruction |= LOW4 (dm);
16056 inst.instruction |= HI1 (dm) << 5;
037e8744 16057 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16058 inst.instruction |= x << 17;
16059 inst.instruction |= sizebits << 16;
5f4273c7 16060
88714cb8 16061 neon_dp_fixup (&inst);
5287ad62
JB
16062 }
16063 else
16064 {
037e8744
JB
16065 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16066 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16067 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16068 /* Duplicate ARM register to lanes of vector. */
88714cb8 16069 NEON_ENCODE (ARMREG, inst);
5287ad62 16070 switch (et.size)
477330fc
RM
16071 {
16072 case 8: inst.instruction |= 0x400000; break;
16073 case 16: inst.instruction |= 0x000020; break;
16074 case 32: inst.instruction |= 0x000000; break;
16075 default: break;
16076 }
5287ad62
JB
16077 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16078 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16079 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16080 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16081 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16082 variants, except for the condition field. */
037e8744 16083 do_vfp_cond_or_thumb ();
5287ad62
JB
16084 }
16085}
16086
16087/* VMOV has particularly many variations. It can be one of:
16088 0. VMOV<c><q> <Qd>, <Qm>
16089 1. VMOV<c><q> <Dd>, <Dm>
16090 (Register operations, which are VORR with Rm = Rn.)
16091 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16092 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16093 (Immediate loads.)
16094 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16095 (ARM register to scalar.)
16096 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16097 (Two ARM registers to vector.)
16098 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16099 (Scalar to ARM register.)
16100 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16101 (Vector to two ARM registers.)
037e8744
JB
16102 8. VMOV.F32 <Sd>, <Sm>
16103 9. VMOV.F64 <Dd>, <Dm>
16104 (VFP register moves.)
16105 10. VMOV.F32 <Sd>, #imm
16106 11. VMOV.F64 <Dd>, #imm
16107 (VFP float immediate load.)
16108 12. VMOV <Rd>, <Sm>
16109 (VFP single to ARM reg.)
16110 13. VMOV <Sd>, <Rm>
16111 (ARM reg to VFP single.)
16112 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16113 (Two ARM regs to two VFP singles.)
16114 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16115 (Two VFP singles to two ARM regs.)
5f4273c7 16116
037e8744
JB
16117 These cases can be disambiguated using neon_select_shape, except cases 1/9
16118 and 3/11 which depend on the operand type too.
5f4273c7 16119
5287ad62 16120 All the encoded bits are hardcoded by this function.
5f4273c7 16121
b7fc2769
JB
16122 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16123 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16124
5287ad62 16125 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16126 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16127
16128static void
16129do_neon_mov (void)
16130{
037e8744 16131 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16132 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16133 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16134 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16135 struct neon_type_el et;
16136 const char *ldconst = 0;
5287ad62 16137
037e8744 16138 switch (rs)
5287ad62 16139 {
037e8744
JB
16140 case NS_DD: /* case 1/9. */
16141 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16142 /* It is not an error here if no type is given. */
16143 inst.error = NULL;
16144 if (et.type == NT_float && et.size == 64)
477330fc
RM
16145 {
16146 do_vfp_nsyn_opcode ("fcpyd");
16147 break;
16148 }
037e8744 16149 /* fall through. */
5287ad62 16150
037e8744
JB
16151 case NS_QQ: /* case 0/1. */
16152 {
477330fc
RM
16153 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16154 return;
16155 /* The architecture manual I have doesn't explicitly state which
16156 value the U bit should have for register->register moves, but
16157 the equivalent VORR instruction has U = 0, so do that. */
16158 inst.instruction = 0x0200110;
16159 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16160 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16161 inst.instruction |= LOW4 (inst.operands[1].reg);
16162 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16163 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16164 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16165 inst.instruction |= neon_quad (rs) << 6;
16166
16167 neon_dp_fixup (&inst);
037e8744
JB
16168 }
16169 break;
5f4273c7 16170
037e8744
JB
16171 case NS_DI: /* case 3/11. */
16172 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16173 inst.error = NULL;
16174 if (et.type == NT_float && et.size == 64)
477330fc
RM
16175 {
16176 /* case 11 (fconstd). */
16177 ldconst = "fconstd";
16178 goto encode_fconstd;
16179 }
037e8744
JB
16180 /* fall through. */
16181
16182 case NS_QI: /* case 2/3. */
16183 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16184 return;
037e8744
JB
16185 inst.instruction = 0x0800010;
16186 neon_move_immediate ();
88714cb8 16187 neon_dp_fixup (&inst);
5287ad62 16188 break;
5f4273c7 16189
037e8744
JB
16190 case NS_SR: /* case 4. */
16191 {
477330fc
RM
16192 unsigned bcdebits = 0;
16193 int logsize;
16194 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16195 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16196
05ac0ffb
JB
16197 /* .<size> is optional here, defaulting to .32. */
16198 if (inst.vectype.elems == 0
16199 && inst.operands[0].vectype.type == NT_invtype
16200 && inst.operands[1].vectype.type == NT_invtype)
16201 {
16202 inst.vectype.el[0].type = NT_untyped;
16203 inst.vectype.el[0].size = 32;
16204 inst.vectype.elems = 1;
16205 }
16206
477330fc
RM
16207 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16208 logsize = neon_logbits (et.size);
16209
16210 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16211 _(BAD_FPU));
16212 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16213 && et.size != 32, _(BAD_FPU));
16214 constraint (et.type == NT_invtype, _("bad type for scalar"));
16215 constraint (x >= 64 / et.size, _("scalar index out of range"));
16216
16217 switch (et.size)
16218 {
16219 case 8: bcdebits = 0x8; break;
16220 case 16: bcdebits = 0x1; break;
16221 case 32: bcdebits = 0x0; break;
16222 default: ;
16223 }
16224
16225 bcdebits |= x << logsize;
16226
16227 inst.instruction = 0xe000b10;
16228 do_vfp_cond_or_thumb ();
16229 inst.instruction |= LOW4 (dn) << 16;
16230 inst.instruction |= HI1 (dn) << 7;
16231 inst.instruction |= inst.operands[1].reg << 12;
16232 inst.instruction |= (bcdebits & 3) << 5;
16233 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16234 }
16235 break;
5f4273c7 16236
037e8744 16237 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16238 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16239 _(BAD_FPU));
b7fc2769 16240
037e8744
JB
16241 inst.instruction = 0xc400b10;
16242 do_vfp_cond_or_thumb ();
16243 inst.instruction |= LOW4 (inst.operands[0].reg);
16244 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16245 inst.instruction |= inst.operands[1].reg << 12;
16246 inst.instruction |= inst.operands[2].reg << 16;
16247 break;
5f4273c7 16248
037e8744
JB
16249 case NS_RS: /* case 6. */
16250 {
477330fc
RM
16251 unsigned logsize;
16252 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16253 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16254 unsigned abcdebits = 0;
037e8744 16255
05ac0ffb
JB
16256 /* .<dt> is optional here, defaulting to .32. */
16257 if (inst.vectype.elems == 0
16258 && inst.operands[0].vectype.type == NT_invtype
16259 && inst.operands[1].vectype.type == NT_invtype)
16260 {
16261 inst.vectype.el[0].type = NT_untyped;
16262 inst.vectype.el[0].size = 32;
16263 inst.vectype.elems = 1;
16264 }
16265
91d6fa6a
NC
16266 et = neon_check_type (2, NS_NULL,
16267 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16268 logsize = neon_logbits (et.size);
16269
16270 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16271 _(BAD_FPU));
16272 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16273 && et.size != 32, _(BAD_FPU));
16274 constraint (et.type == NT_invtype, _("bad type for scalar"));
16275 constraint (x >= 64 / et.size, _("scalar index out of range"));
16276
16277 switch (et.size)
16278 {
16279 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16280 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16281 case 32: abcdebits = 0x00; break;
16282 default: ;
16283 }
16284
16285 abcdebits |= x << logsize;
16286 inst.instruction = 0xe100b10;
16287 do_vfp_cond_or_thumb ();
16288 inst.instruction |= LOW4 (dn) << 16;
16289 inst.instruction |= HI1 (dn) << 7;
16290 inst.instruction |= inst.operands[0].reg << 12;
16291 inst.instruction |= (abcdebits & 3) << 5;
16292 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16293 }
16294 break;
5f4273c7 16295
037e8744
JB
16296 case NS_RRD: /* case 7 (fmrrd). */
16297 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16298 _(BAD_FPU));
037e8744
JB
16299
16300 inst.instruction = 0xc500b10;
16301 do_vfp_cond_or_thumb ();
16302 inst.instruction |= inst.operands[0].reg << 12;
16303 inst.instruction |= inst.operands[1].reg << 16;
16304 inst.instruction |= LOW4 (inst.operands[2].reg);
16305 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16306 break;
5f4273c7 16307
037e8744
JB
16308 case NS_FF: /* case 8 (fcpys). */
16309 do_vfp_nsyn_opcode ("fcpys");
16310 break;
5f4273c7 16311
9db2f6b4 16312 case NS_HI:
037e8744
JB
16313 case NS_FI: /* case 10 (fconsts). */
16314 ldconst = "fconsts";
16315 encode_fconstd:
16316 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16317 {
16318 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16319 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16320
16321 /* ARMv8.2 fp16 vmov.f16 instruction. */
16322 if (rs == NS_HI)
16323 do_scalar_fp16_v82_encode ();
477330fc 16324 }
5287ad62 16325 else
477330fc 16326 first_error (_("immediate out of range"));
037e8744 16327 break;
5f4273c7 16328
9db2f6b4 16329 case NS_RH:
037e8744
JB
16330 case NS_RF: /* case 12 (fmrs). */
16331 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16332 /* ARMv8.2 fp16 vmov.f16 instruction. */
16333 if (rs == NS_RH)
16334 do_scalar_fp16_v82_encode ();
037e8744 16335 break;
5f4273c7 16336
9db2f6b4 16337 case NS_HR:
037e8744
JB
16338 case NS_FR: /* case 13 (fmsr). */
16339 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16340 /* ARMv8.2 fp16 vmov.f16 instruction. */
16341 if (rs == NS_HR)
16342 do_scalar_fp16_v82_encode ();
037e8744 16343 break;
5f4273c7 16344
037e8744
JB
16345 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16346 (one of which is a list), but we have parsed four. Do some fiddling to
16347 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16348 expect. */
16349 case NS_RRFF: /* case 14 (fmrrs). */
16350 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16351 _("VFP registers must be adjacent"));
037e8744
JB
16352 inst.operands[2].imm = 2;
16353 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16354 do_vfp_nsyn_opcode ("fmrrs");
16355 break;
5f4273c7 16356
037e8744
JB
16357 case NS_FFRR: /* case 15 (fmsrr). */
16358 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16359 _("VFP registers must be adjacent"));
037e8744
JB
16360 inst.operands[1] = inst.operands[2];
16361 inst.operands[2] = inst.operands[3];
16362 inst.operands[0].imm = 2;
16363 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16364 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16365 break;
5f4273c7 16366
4c261dff
NC
16367 case NS_NULL:
16368 /* neon_select_shape has determined that the instruction
16369 shape is wrong and has already set the error message. */
16370 break;
16371
5287ad62
JB
16372 default:
16373 abort ();
16374 }
16375}
16376
16377static void
16378do_neon_rshift_round_imm (void)
16379{
037e8744 16380 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16381 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16382 int imm = inst.operands[2].imm;
16383
16384 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16385 if (imm == 0)
16386 {
16387 inst.operands[2].present = 0;
16388 do_neon_mov ();
16389 return;
16390 }
16391
16392 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16393 _("immediate out of range for shift"));
037e8744 16394 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16395 et.size - imm);
5287ad62
JB
16396}
16397
9db2f6b4
RL
16398static void
16399do_neon_movhf (void)
16400{
16401 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16402 constraint (rs != NS_HH, _("invalid suffix"));
16403
16404 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16405 _(BAD_FPU));
16406
16407 do_vfp_sp_monadic ();
16408
16409 inst.is_neon = 1;
16410 inst.instruction |= 0xf0000000;
16411}
16412
5287ad62
JB
16413static void
16414do_neon_movl (void)
16415{
16416 struct neon_type_el et = neon_check_type (2, NS_QD,
16417 N_EQK | N_DBL, N_SU_32 | N_KEY);
16418 unsigned sizebits = et.size >> 3;
16419 inst.instruction |= sizebits << 19;
16420 neon_two_same (0, et.type == NT_unsigned, -1);
16421}
16422
16423static void
16424do_neon_trn (void)
16425{
037e8744 16426 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16427 struct neon_type_el et = neon_check_type (2, rs,
16428 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16429 NEON_ENCODE (INTEGER, inst);
037e8744 16430 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16431}
16432
16433static void
16434do_neon_zip_uzp (void)
16435{
037e8744 16436 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16437 struct neon_type_el et = neon_check_type (2, rs,
16438 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16439 if (rs == NS_DD && et.size == 32)
16440 {
16441 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16442 inst.instruction = N_MNEM_vtrn;
16443 do_neon_trn ();
16444 return;
16445 }
037e8744 16446 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16447}
16448
16449static void
16450do_neon_sat_abs_neg (void)
16451{
037e8744 16452 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16453 struct neon_type_el et = neon_check_type (2, rs,
16454 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16455 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16456}
16457
16458static void
16459do_neon_pair_long (void)
16460{
037e8744 16461 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16462 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16463 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16464 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16465 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16466}
16467
16468static void
16469do_neon_recip_est (void)
16470{
037e8744 16471 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16472 struct neon_type_el et = neon_check_type (2, rs,
16473 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16474 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16475 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16476}
16477
16478static void
16479do_neon_cls (void)
16480{
037e8744 16481 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16482 struct neon_type_el et = neon_check_type (2, rs,
16483 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16484 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16485}
16486
16487static void
16488do_neon_clz (void)
16489{
037e8744 16490 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16491 struct neon_type_el et = neon_check_type (2, rs,
16492 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16493 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16494}
16495
16496static void
16497do_neon_cnt (void)
16498{
037e8744 16499 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16500 struct neon_type_el et = neon_check_type (2, rs,
16501 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16502 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16503}
16504
16505static void
16506do_neon_swp (void)
16507{
037e8744
JB
16508 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16509 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16510}
16511
16512static void
16513do_neon_tbl_tbx (void)
16514{
16515 unsigned listlenbits;
dcbf9037 16516 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16517
5287ad62
JB
16518 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16519 {
dcbf9037 16520 first_error (_("bad list length for table lookup"));
5287ad62
JB
16521 return;
16522 }
5f4273c7 16523
5287ad62
JB
16524 listlenbits = inst.operands[1].imm - 1;
16525 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16526 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16527 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16528 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16529 inst.instruction |= LOW4 (inst.operands[2].reg);
16530 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16531 inst.instruction |= listlenbits << 8;
5f4273c7 16532
88714cb8 16533 neon_dp_fixup (&inst);
5287ad62
JB
16534}
16535
16536static void
16537do_neon_ldm_stm (void)
16538{
16539 /* P, U and L bits are part of bitmask. */
16540 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16541 unsigned offsetbits = inst.operands[1].imm * 2;
16542
037e8744
JB
16543 if (inst.operands[1].issingle)
16544 {
16545 do_vfp_nsyn_ldm_stm (is_dbmode);
16546 return;
16547 }
16548
5287ad62 16549 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16550 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16551
16552 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16553 _("register list must contain at least 1 and at most 16 "
16554 "registers"));
5287ad62
JB
16555
16556 inst.instruction |= inst.operands[0].reg << 16;
16557 inst.instruction |= inst.operands[0].writeback << 21;
16558 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16559 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16560
16561 inst.instruction |= offsetbits;
5f4273c7 16562
037e8744 16563 do_vfp_cond_or_thumb ();
5287ad62
JB
16564}
16565
16566static void
16567do_neon_ldr_str (void)
16568{
5287ad62 16569 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16570
6844b2c2
MGD
16571 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16572 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16573 if (!is_ldr
6844b2c2 16574 && inst.operands[1].reg == REG_PC
ba86b375 16575 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16576 {
94dcf8bf 16577 if (thumb_mode)
6844b2c2 16578 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16579 else if (warn_on_deprecated)
5c3696f8 16580 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16581 }
16582
037e8744
JB
16583 if (inst.operands[0].issingle)
16584 {
cd2f129f 16585 if (is_ldr)
477330fc 16586 do_vfp_nsyn_opcode ("flds");
cd2f129f 16587 else
477330fc 16588 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16589
16590 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16591 if (inst.vectype.el[0].size == 16)
16592 do_scalar_fp16_v82_encode ();
5287ad62
JB
16593 }
16594 else
5287ad62 16595 {
cd2f129f 16596 if (is_ldr)
477330fc 16597 do_vfp_nsyn_opcode ("fldd");
5287ad62 16598 else
477330fc 16599 do_vfp_nsyn_opcode ("fstd");
5287ad62 16600 }
5287ad62
JB
16601}
16602
16603/* "interleave" version also handles non-interleaving register VLD1/VST1
16604 instructions. */
16605
16606static void
16607do_neon_ld_st_interleave (void)
16608{
037e8744 16609 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16610 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16611 unsigned alignbits = 0;
16612 unsigned idx;
16613 /* The bits in this table go:
16614 0: register stride of one (0) or two (1)
16615 1,2: register list length, minus one (1, 2, 3, 4).
16616 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16617 We use -1 for invalid entries. */
16618 const int typetable[] =
16619 {
16620 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16621 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16622 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16623 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16624 };
16625 int typebits;
16626
dcbf9037
JB
16627 if (et.type == NT_invtype)
16628 return;
16629
5287ad62
JB
16630 if (inst.operands[1].immisalign)
16631 switch (inst.operands[1].imm >> 8)
16632 {
16633 case 64: alignbits = 1; break;
16634 case 128:
477330fc 16635 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16636 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16637 goto bad_alignment;
16638 alignbits = 2;
16639 break;
5287ad62 16640 case 256:
477330fc
RM
16641 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16642 goto bad_alignment;
16643 alignbits = 3;
16644 break;
5287ad62
JB
16645 default:
16646 bad_alignment:
477330fc
RM
16647 first_error (_("bad alignment"));
16648 return;
5287ad62
JB
16649 }
16650
16651 inst.instruction |= alignbits << 4;
16652 inst.instruction |= neon_logbits (et.size) << 6;
16653
16654 /* Bits [4:6] of the immediate in a list specifier encode register stride
16655 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16656 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16657 up the right value for "type" in a table based on this value and the given
16658 list style, then stick it back. */
16659 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16660 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16661
16662 typebits = typetable[idx];
5f4273c7 16663
5287ad62 16664 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16665 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16666 _("bad element type for instruction"));
5287ad62
JB
16667
16668 inst.instruction &= ~0xf00;
16669 inst.instruction |= typebits << 8;
16670}
16671
16672/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16673 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16674 otherwise. The variable arguments are a list of pairs of legal (size, align)
16675 values, terminated with -1. */
16676
16677static int
aa8a0863 16678neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16679{
16680 va_list ap;
16681 int result = FAIL, thissize, thisalign;
5f4273c7 16682
5287ad62
JB
16683 if (!inst.operands[1].immisalign)
16684 {
aa8a0863 16685 *do_alignment = 0;
5287ad62
JB
16686 return SUCCESS;
16687 }
5f4273c7 16688
aa8a0863 16689 va_start (ap, do_alignment);
5287ad62
JB
16690
16691 do
16692 {
16693 thissize = va_arg (ap, int);
16694 if (thissize == -1)
477330fc 16695 break;
5287ad62
JB
16696 thisalign = va_arg (ap, int);
16697
16698 if (size == thissize && align == thisalign)
477330fc 16699 result = SUCCESS;
5287ad62
JB
16700 }
16701 while (result != SUCCESS);
16702
16703 va_end (ap);
16704
16705 if (result == SUCCESS)
aa8a0863 16706 *do_alignment = 1;
5287ad62 16707 else
dcbf9037 16708 first_error (_("unsupported alignment for instruction"));
5f4273c7 16709
5287ad62
JB
16710 return result;
16711}
16712
16713static void
16714do_neon_ld_st_lane (void)
16715{
037e8744 16716 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16717 int align_good, do_alignment = 0;
5287ad62
JB
16718 int logsize = neon_logbits (et.size);
16719 int align = inst.operands[1].imm >> 8;
16720 int n = (inst.instruction >> 8) & 3;
16721 int max_el = 64 / et.size;
5f4273c7 16722
dcbf9037
JB
16723 if (et.type == NT_invtype)
16724 return;
5f4273c7 16725
5287ad62 16726 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16727 _("bad list length"));
5287ad62 16728 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16729 _("scalar index out of range"));
5287ad62 16730 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16731 && et.size == 8,
16732 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16733
5287ad62
JB
16734 switch (n)
16735 {
16736 case 0: /* VLD1 / VST1. */
aa8a0863 16737 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16738 32, 32, -1);
5287ad62 16739 if (align_good == FAIL)
477330fc 16740 return;
aa8a0863 16741 if (do_alignment)
477330fc
RM
16742 {
16743 unsigned alignbits = 0;
16744 switch (et.size)
16745 {
16746 case 16: alignbits = 0x1; break;
16747 case 32: alignbits = 0x3; break;
16748 default: ;
16749 }
16750 inst.instruction |= alignbits << 4;
16751 }
5287ad62
JB
16752 break;
16753
16754 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16755 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16756 16, 32, 32, 64, -1);
5287ad62 16757 if (align_good == FAIL)
477330fc 16758 return;
aa8a0863 16759 if (do_alignment)
477330fc 16760 inst.instruction |= 1 << 4;
5287ad62
JB
16761 break;
16762
16763 case 2: /* VLD3 / VST3. */
16764 constraint (inst.operands[1].immisalign,
477330fc 16765 _("can't use alignment with this instruction"));
5287ad62
JB
16766 break;
16767
16768 case 3: /* VLD4 / VST4. */
aa8a0863 16769 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16770 16, 64, 32, 64, 32, 128, -1);
5287ad62 16771 if (align_good == FAIL)
477330fc 16772 return;
aa8a0863 16773 if (do_alignment)
477330fc
RM
16774 {
16775 unsigned alignbits = 0;
16776 switch (et.size)
16777 {
16778 case 8: alignbits = 0x1; break;
16779 case 16: alignbits = 0x1; break;
16780 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16781 default: ;
16782 }
16783 inst.instruction |= alignbits << 4;
16784 }
5287ad62
JB
16785 break;
16786
16787 default: ;
16788 }
16789
16790 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16791 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16792 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16793
5287ad62
JB
16794 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16795 inst.instruction |= logsize << 10;
16796}
16797
16798/* Encode single n-element structure to all lanes VLD<n> instructions. */
16799
16800static void
16801do_neon_ld_dup (void)
16802{
037e8744 16803 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16804 int align_good, do_alignment = 0;
5287ad62 16805
dcbf9037
JB
16806 if (et.type == NT_invtype)
16807 return;
16808
5287ad62
JB
16809 switch ((inst.instruction >> 8) & 3)
16810 {
16811 case 0: /* VLD1. */
9c2799c2 16812 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16813 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16814 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16815 if (align_good == FAIL)
477330fc 16816 return;
5287ad62 16817 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16818 {
16819 case 1: break;
16820 case 2: inst.instruction |= 1 << 5; break;
16821 default: first_error (_("bad list length")); return;
16822 }
5287ad62
JB
16823 inst.instruction |= neon_logbits (et.size) << 6;
16824 break;
16825
16826 case 1: /* VLD2. */
16827 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16828 &do_alignment, 8, 16, 16, 32, 32, 64,
16829 -1);
5287ad62 16830 if (align_good == FAIL)
477330fc 16831 return;
5287ad62 16832 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16833 _("bad list length"));
5287ad62 16834 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16835 inst.instruction |= 1 << 5;
5287ad62
JB
16836 inst.instruction |= neon_logbits (et.size) << 6;
16837 break;
16838
16839 case 2: /* VLD3. */
16840 constraint (inst.operands[1].immisalign,
477330fc 16841 _("can't use alignment with this instruction"));
5287ad62 16842 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16843 _("bad list length"));
5287ad62 16844 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16845 inst.instruction |= 1 << 5;
5287ad62
JB
16846 inst.instruction |= neon_logbits (et.size) << 6;
16847 break;
16848
16849 case 3: /* VLD4. */
16850 {
477330fc 16851 int align = inst.operands[1].imm >> 8;
aa8a0863 16852 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
16853 16, 64, 32, 64, 32, 128, -1);
16854 if (align_good == FAIL)
16855 return;
16856 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16857 _("bad list length"));
16858 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16859 inst.instruction |= 1 << 5;
16860 if (et.size == 32 && align == 128)
16861 inst.instruction |= 0x3 << 6;
16862 else
16863 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16864 }
16865 break;
16866
16867 default: ;
16868 }
16869
aa8a0863 16870 inst.instruction |= do_alignment << 4;
5287ad62
JB
16871}
16872
16873/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16874 apart from bits [11:4]. */
16875
16876static void
16877do_neon_ldx_stx (void)
16878{
b1a769ed
DG
16879 if (inst.operands[1].isreg)
16880 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16881
5287ad62
JB
16882 switch (NEON_LANE (inst.operands[0].imm))
16883 {
16884 case NEON_INTERLEAVE_LANES:
88714cb8 16885 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16886 do_neon_ld_st_interleave ();
16887 break;
5f4273c7 16888
5287ad62 16889 case NEON_ALL_LANES:
88714cb8 16890 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16891 if (inst.instruction == N_INV)
16892 {
16893 first_error ("only loads support such operands");
16894 break;
16895 }
5287ad62
JB
16896 do_neon_ld_dup ();
16897 break;
5f4273c7 16898
5287ad62 16899 default:
88714cb8 16900 NEON_ENCODE (LANE, inst);
5287ad62
JB
16901 do_neon_ld_st_lane ();
16902 }
16903
16904 /* L bit comes from bit mask. */
16905 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16906 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16907 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16908
5287ad62
JB
16909 if (inst.operands[1].postind)
16910 {
16911 int postreg = inst.operands[1].imm & 0xf;
16912 constraint (!inst.operands[1].immisreg,
477330fc 16913 _("post-index must be a register"));
5287ad62 16914 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16915 _("bad register for post-index"));
5287ad62
JB
16916 inst.instruction |= postreg;
16917 }
4f2374c7 16918 else
5287ad62 16919 {
4f2374c7
WN
16920 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16921 constraint (inst.reloc.exp.X_op != O_constant
16922 || inst.reloc.exp.X_add_number != 0,
16923 BAD_ADDR_MODE);
16924
16925 if (inst.operands[1].writeback)
16926 {
16927 inst.instruction |= 0xd;
16928 }
16929 else
16930 inst.instruction |= 0xf;
5287ad62 16931 }
5f4273c7 16932
5287ad62
JB
16933 if (thumb_mode)
16934 inst.instruction |= 0xf9000000;
16935 else
16936 inst.instruction |= 0xf4000000;
16937}
33399f07
MGD
16938
16939/* FP v8. */
16940static void
16941do_vfp_nsyn_fpv8 (enum neon_shape rs)
16942{
a715796b
TG
16943 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16944 D register operands. */
16945 if (neon_shape_class[rs] == SC_DOUBLE)
16946 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16947 _(BAD_FPU));
16948
33399f07
MGD
16949 NEON_ENCODE (FPV8, inst);
16950
9db2f6b4
RL
16951 if (rs == NS_FFF || rs == NS_HHH)
16952 {
16953 do_vfp_sp_dyadic ();
16954
16955 /* ARMv8.2 fp16 instruction. */
16956 if (rs == NS_HHH)
16957 do_scalar_fp16_v82_encode ();
16958 }
33399f07
MGD
16959 else
16960 do_vfp_dp_rd_rn_rm ();
16961
16962 if (rs == NS_DDD)
16963 inst.instruction |= 0x100;
16964
16965 inst.instruction |= 0xf0000000;
16966}
16967
16968static void
16969do_vsel (void)
16970{
16971 set_it_insn_type (OUTSIDE_IT_INSN);
16972
16973 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16974 first_error (_("invalid instruction shape"));
16975}
16976
73924fbc
MGD
16977static void
16978do_vmaxnm (void)
16979{
16980 set_it_insn_type (OUTSIDE_IT_INSN);
16981
16982 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16983 return;
16984
16985 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16986 return;
16987
16988 neon_dyadic_misc (NT_untyped, N_F32, 0);
16989}
16990
30bdf752
MGD
16991static void
16992do_vrint_1 (enum neon_cvt_mode mode)
16993{
9db2f6b4 16994 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
16995 struct neon_type_el et;
16996
16997 if (rs == NS_NULL)
16998 return;
16999
a715796b
TG
17000 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17001 D register operands. */
17002 if (neon_shape_class[rs] == SC_DOUBLE)
17003 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17004 _(BAD_FPU));
17005
9db2f6b4
RL
17006 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17007 | N_VFP);
30bdf752
MGD
17008 if (et.type != NT_invtype)
17009 {
17010 /* VFP encodings. */
17011 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17012 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17013 set_it_insn_type (OUTSIDE_IT_INSN);
17014
17015 NEON_ENCODE (FPV8, inst);
9db2f6b4 17016 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17017 do_vfp_sp_monadic ();
17018 else
17019 do_vfp_dp_rd_rm ();
17020
17021 switch (mode)
17022 {
17023 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17024 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17025 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17026 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17027 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17028 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17029 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17030 default: abort ();
17031 }
17032
17033 inst.instruction |= (rs == NS_DD) << 8;
17034 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17035
17036 /* ARMv8.2 fp16 vrint instruction. */
17037 if (rs == NS_HH)
17038 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17039 }
17040 else
17041 {
17042 /* Neon encodings (or something broken...). */
17043 inst.error = NULL;
17044 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
17045
17046 if (et.type == NT_invtype)
17047 return;
17048
17049 set_it_insn_type (OUTSIDE_IT_INSN);
17050 NEON_ENCODE (FLOAT, inst);
17051
17052 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17053 return;
17054
17055 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17056 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17057 inst.instruction |= LOW4 (inst.operands[1].reg);
17058 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17059 inst.instruction |= neon_quad (rs) << 6;
17060 switch (mode)
17061 {
17062 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17063 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17064 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17065 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17066 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17067 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17068 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17069 default: abort ();
17070 }
17071
17072 if (thumb_mode)
17073 inst.instruction |= 0xfc000000;
17074 else
17075 inst.instruction |= 0xf0000000;
17076 }
17077}
17078
17079static void
17080do_vrintx (void)
17081{
17082 do_vrint_1 (neon_cvt_mode_x);
17083}
17084
17085static void
17086do_vrintz (void)
17087{
17088 do_vrint_1 (neon_cvt_mode_z);
17089}
17090
17091static void
17092do_vrintr (void)
17093{
17094 do_vrint_1 (neon_cvt_mode_r);
17095}
17096
17097static void
17098do_vrinta (void)
17099{
17100 do_vrint_1 (neon_cvt_mode_a);
17101}
17102
17103static void
17104do_vrintn (void)
17105{
17106 do_vrint_1 (neon_cvt_mode_n);
17107}
17108
17109static void
17110do_vrintp (void)
17111{
17112 do_vrint_1 (neon_cvt_mode_p);
17113}
17114
17115static void
17116do_vrintm (void)
17117{
17118 do_vrint_1 (neon_cvt_mode_m);
17119}
17120
91ff7894
MGD
17121/* Crypto v1 instructions. */
17122static void
17123do_crypto_2op_1 (unsigned elttype, int op)
17124{
17125 set_it_insn_type (OUTSIDE_IT_INSN);
17126
17127 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17128 == NT_invtype)
17129 return;
17130
17131 inst.error = NULL;
17132
17133 NEON_ENCODE (INTEGER, inst);
17134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17135 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17136 inst.instruction |= LOW4 (inst.operands[1].reg);
17137 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17138 if (op != -1)
17139 inst.instruction |= op << 6;
17140
17141 if (thumb_mode)
17142 inst.instruction |= 0xfc000000;
17143 else
17144 inst.instruction |= 0xf0000000;
17145}
17146
48adcd8e
MGD
17147static void
17148do_crypto_3op_1 (int u, int op)
17149{
17150 set_it_insn_type (OUTSIDE_IT_INSN);
17151
17152 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17153 N_32 | N_UNT | N_KEY).type == NT_invtype)
17154 return;
17155
17156 inst.error = NULL;
17157
17158 NEON_ENCODE (INTEGER, inst);
17159 neon_three_same (1, u, 8 << op);
17160}
17161
91ff7894
MGD
17162static void
17163do_aese (void)
17164{
17165 do_crypto_2op_1 (N_8, 0);
17166}
17167
17168static void
17169do_aesd (void)
17170{
17171 do_crypto_2op_1 (N_8, 1);
17172}
17173
17174static void
17175do_aesmc (void)
17176{
17177 do_crypto_2op_1 (N_8, 2);
17178}
17179
17180static void
17181do_aesimc (void)
17182{
17183 do_crypto_2op_1 (N_8, 3);
17184}
17185
48adcd8e
MGD
17186static void
17187do_sha1c (void)
17188{
17189 do_crypto_3op_1 (0, 0);
17190}
17191
17192static void
17193do_sha1p (void)
17194{
17195 do_crypto_3op_1 (0, 1);
17196}
17197
17198static void
17199do_sha1m (void)
17200{
17201 do_crypto_3op_1 (0, 2);
17202}
17203
17204static void
17205do_sha1su0 (void)
17206{
17207 do_crypto_3op_1 (0, 3);
17208}
91ff7894 17209
48adcd8e
MGD
17210static void
17211do_sha256h (void)
17212{
17213 do_crypto_3op_1 (1, 0);
17214}
17215
17216static void
17217do_sha256h2 (void)
17218{
17219 do_crypto_3op_1 (1, 1);
17220}
17221
17222static void
17223do_sha256su1 (void)
17224{
17225 do_crypto_3op_1 (1, 2);
17226}
3c9017d2
MGD
17227
17228static void
17229do_sha1h (void)
17230{
17231 do_crypto_2op_1 (N_32, -1);
17232}
17233
17234static void
17235do_sha1su1 (void)
17236{
17237 do_crypto_2op_1 (N_32, 0);
17238}
17239
17240static void
17241do_sha256su0 (void)
17242{
17243 do_crypto_2op_1 (N_32, 1);
17244}
dd5181d5
KT
17245
17246static void
17247do_crc32_1 (unsigned int poly, unsigned int sz)
17248{
17249 unsigned int Rd = inst.operands[0].reg;
17250 unsigned int Rn = inst.operands[1].reg;
17251 unsigned int Rm = inst.operands[2].reg;
17252
17253 set_it_insn_type (OUTSIDE_IT_INSN);
17254 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17255 inst.instruction |= LOW4 (Rn) << 16;
17256 inst.instruction |= LOW4 (Rm);
17257 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17258 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17259
17260 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17261 as_warn (UNPRED_REG ("r15"));
17262 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17263 as_warn (UNPRED_REG ("r13"));
17264}
17265
17266static void
17267do_crc32b (void)
17268{
17269 do_crc32_1 (0, 0);
17270}
17271
17272static void
17273do_crc32h (void)
17274{
17275 do_crc32_1 (0, 1);
17276}
17277
17278static void
17279do_crc32w (void)
17280{
17281 do_crc32_1 (0, 2);
17282}
17283
17284static void
17285do_crc32cb (void)
17286{
17287 do_crc32_1 (1, 0);
17288}
17289
17290static void
17291do_crc32ch (void)
17292{
17293 do_crc32_1 (1, 1);
17294}
17295
17296static void
17297do_crc32cw (void)
17298{
17299 do_crc32_1 (1, 2);
17300}
17301
5287ad62
JB
17302\f
17303/* Overall per-instruction processing. */
17304
17305/* We need to be able to fix up arbitrary expressions in some statements.
17306 This is so that we can handle symbols that are an arbitrary distance from
17307 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17308 which returns part of an address in a form which will be valid for
17309 a data instruction. We do this by pushing the expression into a symbol
17310 in the expr_section, and creating a fix for that. */
17311
17312static void
17313fix_new_arm (fragS * frag,
17314 int where,
17315 short int size,
17316 expressionS * exp,
17317 int pc_rel,
17318 int reloc)
17319{
17320 fixS * new_fix;
17321
17322 switch (exp->X_op)
17323 {
17324 case O_constant:
6e7ce2cd
PB
17325 if (pc_rel)
17326 {
17327 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17328 refer to in the object file. Unfortunately for us, gas's
17329 generic expression parsing will already have folded out
17330 any use of .set foo/.type foo %function that may have
17331 been used to set type information of the target location,
17332 that's being specified symbolically. We have to presume
17333 the user knows what they are doing. */
6e7ce2cd
PB
17334 char name[16 + 8];
17335 symbolS *symbol;
17336
17337 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17338
17339 symbol = symbol_find_or_make (name);
17340 S_SET_SEGMENT (symbol, absolute_section);
17341 symbol_set_frag (symbol, &zero_address_frag);
17342 S_SET_VALUE (symbol, exp->X_add_number);
17343 exp->X_op = O_symbol;
17344 exp->X_add_symbol = symbol;
17345 exp->X_add_number = 0;
17346 }
17347 /* FALLTHROUGH */
5287ad62
JB
17348 case O_symbol:
17349 case O_add:
17350 case O_subtract:
21d799b5 17351 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17352 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17353 break;
17354
17355 default:
21d799b5 17356 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17357 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17358 break;
17359 }
17360
17361 /* Mark whether the fix is to a THUMB instruction, or an ARM
17362 instruction. */
17363 new_fix->tc_fix_data = thumb_mode;
17364}
17365
17366/* Create a frg for an instruction requiring relaxation. */
17367static void
17368output_relax_insn (void)
17369{
17370 char * to;
17371 symbolS *sym;
0110f2b8
PB
17372 int offset;
17373
6e1cb1a6
PB
17374 /* The size of the instruction is unknown, so tie the debug info to the
17375 start of the instruction. */
17376 dwarf2_emit_insn (0);
6e1cb1a6 17377
0110f2b8
PB
17378 switch (inst.reloc.exp.X_op)
17379 {
17380 case O_symbol:
17381 sym = inst.reloc.exp.X_add_symbol;
17382 offset = inst.reloc.exp.X_add_number;
17383 break;
17384 case O_constant:
17385 sym = NULL;
17386 offset = inst.reloc.exp.X_add_number;
17387 break;
17388 default:
17389 sym = make_expr_symbol (&inst.reloc.exp);
17390 offset = 0;
17391 break;
17392 }
17393 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17394 inst.relax, sym, offset, NULL/*offset, opcode*/);
17395 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17396}
17397
17398/* Write a 32-bit thumb instruction to buf. */
17399static void
17400put_thumb32_insn (char * buf, unsigned long insn)
17401{
17402 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17403 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17404}
17405
b99bd4ef 17406static void
c19d1205 17407output_inst (const char * str)
b99bd4ef 17408{
c19d1205 17409 char * to = NULL;
b99bd4ef 17410
c19d1205 17411 if (inst.error)
b99bd4ef 17412 {
c19d1205 17413 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17414 return;
17415 }
5f4273c7
NC
17416 if (inst.relax)
17417 {
17418 output_relax_insn ();
0110f2b8 17419 return;
5f4273c7 17420 }
c19d1205
ZW
17421 if (inst.size == 0)
17422 return;
b99bd4ef 17423
c19d1205 17424 to = frag_more (inst.size);
8dc2430f
NC
17425 /* PR 9814: Record the thumb mode into the current frag so that we know
17426 what type of NOP padding to use, if necessary. We override any previous
17427 setting so that if the mode has changed then the NOPS that we use will
17428 match the encoding of the last instruction in the frag. */
cd000bff 17429 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17430
17431 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17432 {
9c2799c2 17433 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17434 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17435 }
c19d1205 17436 else if (inst.size > INSN_SIZE)
b99bd4ef 17437 {
9c2799c2 17438 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17439 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17440 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17441 }
c19d1205
ZW
17442 else
17443 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17444
c19d1205
ZW
17445 if (inst.reloc.type != BFD_RELOC_UNUSED)
17446 fix_new_arm (frag_now, to - frag_now->fr_literal,
17447 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17448 inst.reloc.type);
b99bd4ef 17449
c19d1205 17450 dwarf2_emit_insn (inst.size);
c19d1205 17451}
b99bd4ef 17452
e07e6e58
NC
17453static char *
17454output_it_inst (int cond, int mask, char * to)
17455{
17456 unsigned long instruction = 0xbf00;
17457
17458 mask &= 0xf;
17459 instruction |= mask;
17460 instruction |= cond << 4;
17461
17462 if (to == NULL)
17463 {
17464 to = frag_more (2);
17465#ifdef OBJ_ELF
17466 dwarf2_emit_insn (2);
17467#endif
17468 }
17469
17470 md_number_to_chars (to, instruction, 2);
17471
17472 return to;
17473}
17474
c19d1205
ZW
17475/* Tag values used in struct asm_opcode's tag field. */
17476enum opcode_tag
17477{
17478 OT_unconditional, /* Instruction cannot be conditionalized.
17479 The ARM condition field is still 0xE. */
17480 OT_unconditionalF, /* Instruction cannot be conditionalized
17481 and carries 0xF in its ARM condition field. */
17482 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17483 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17484 suffix, others place 0xF where the condition field
17485 would be. */
c19d1205
ZW
17486 OT_cinfix3, /* Instruction takes a conditional infix,
17487 beginning at character index 3. (In
17488 unified mode, it becomes a suffix.) */
088fa78e
KH
17489 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17490 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17491 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17492 character index 3, even in unified mode. Used for
17493 legacy instructions where suffix and infix forms
17494 may be ambiguous. */
c19d1205 17495 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17496 suffix or an infix at character index 3. */
c19d1205
ZW
17497 OT_odd_infix_unc, /* This is the unconditional variant of an
17498 instruction that takes a conditional infix
17499 at an unusual position. In unified mode,
17500 this variant will accept a suffix. */
17501 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17502 are the conditional variants of instructions that
17503 take conditional infixes in unusual positions.
17504 The infix appears at character index
17505 (tag - OT_odd_infix_0). These are not accepted
17506 in unified mode. */
17507};
b99bd4ef 17508
c19d1205
ZW
17509/* Subroutine of md_assemble, responsible for looking up the primary
17510 opcode from the mnemonic the user wrote. STR points to the
17511 beginning of the mnemonic.
17512
17513 This is not simply a hash table lookup, because of conditional
17514 variants. Most instructions have conditional variants, which are
17515 expressed with a _conditional affix_ to the mnemonic. If we were
17516 to encode each conditional variant as a literal string in the opcode
17517 table, it would have approximately 20,000 entries.
17518
17519 Most mnemonics take this affix as a suffix, and in unified syntax,
17520 'most' is upgraded to 'all'. However, in the divided syntax, some
17521 instructions take the affix as an infix, notably the s-variants of
17522 the arithmetic instructions. Of those instructions, all but six
17523 have the infix appear after the third character of the mnemonic.
17524
17525 Accordingly, the algorithm for looking up primary opcodes given
17526 an identifier is:
17527
17528 1. Look up the identifier in the opcode table.
17529 If we find a match, go to step U.
17530
17531 2. Look up the last two characters of the identifier in the
17532 conditions table. If we find a match, look up the first N-2
17533 characters of the identifier in the opcode table. If we
17534 find a match, go to step CE.
17535
17536 3. Look up the fourth and fifth characters of the identifier in
17537 the conditions table. If we find a match, extract those
17538 characters from the identifier, and look up the remaining
17539 characters in the opcode table. If we find a match, go
17540 to step CM.
17541
17542 4. Fail.
17543
17544 U. Examine the tag field of the opcode structure, in case this is
17545 one of the six instructions with its conditional infix in an
17546 unusual place. If it is, the tag tells us where to find the
17547 infix; look it up in the conditions table and set inst.cond
17548 accordingly. Otherwise, this is an unconditional instruction.
17549 Again set inst.cond accordingly. Return the opcode structure.
17550
17551 CE. Examine the tag field to make sure this is an instruction that
17552 should receive a conditional suffix. If it is not, fail.
17553 Otherwise, set inst.cond from the suffix we already looked up,
17554 and return the opcode structure.
17555
17556 CM. Examine the tag field to make sure this is an instruction that
17557 should receive a conditional infix after the third character.
17558 If it is not, fail. Otherwise, undo the edits to the current
17559 line of input and proceed as for case CE. */
17560
17561static const struct asm_opcode *
17562opcode_lookup (char **str)
17563{
17564 char *end, *base;
17565 char *affix;
17566 const struct asm_opcode *opcode;
17567 const struct asm_cond *cond;
e3cb604e 17568 char save[2];
c19d1205
ZW
17569
17570 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17571 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17572 for (base = end = *str; *end != '\0'; end++)
721a8186 17573 if (*end == ' ' || *end == '.')
c19d1205 17574 break;
b99bd4ef 17575
c19d1205 17576 if (end == base)
c921be7d 17577 return NULL;
b99bd4ef 17578
5287ad62 17579 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17580 if (end[0] == '.')
b99bd4ef 17581 {
5287ad62 17582 int offset = 2;
5f4273c7 17583
267d2029 17584 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17585 use. */
267d2029 17586 if (unified_syntax && end[1] == 'w')
c19d1205 17587 inst.size_req = 4;
267d2029 17588 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17589 inst.size_req = 2;
17590 else
477330fc 17591 offset = 0;
5287ad62
JB
17592
17593 inst.vectype.elems = 0;
17594
17595 *str = end + offset;
b99bd4ef 17596
5f4273c7 17597 if (end[offset] == '.')
5287ad62 17598 {
267d2029 17599 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17600 non-unified ARM syntax mode). */
17601 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17602 return NULL;
477330fc 17603 }
5287ad62 17604 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17605 return NULL;
b99bd4ef 17606 }
c19d1205
ZW
17607 else
17608 *str = end;
b99bd4ef 17609
c19d1205 17610 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17611 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17612 end - base);
c19d1205 17613 if (opcode)
b99bd4ef 17614 {
c19d1205
ZW
17615 /* step U */
17616 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17617 {
c19d1205
ZW
17618 inst.cond = COND_ALWAYS;
17619 return opcode;
b99bd4ef 17620 }
b99bd4ef 17621
278df34e 17622 if (warn_on_deprecated && unified_syntax)
5c3696f8 17623 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17624 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17625 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17626 gas_assert (cond);
b99bd4ef 17627
c19d1205
ZW
17628 inst.cond = cond->value;
17629 return opcode;
17630 }
b99bd4ef 17631
c19d1205
ZW
17632 /* Cannot have a conditional suffix on a mnemonic of less than two
17633 characters. */
17634 if (end - base < 3)
c921be7d 17635 return NULL;
b99bd4ef 17636
c19d1205
ZW
17637 /* Look for suffixed mnemonic. */
17638 affix = end - 2;
21d799b5
NC
17639 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17640 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17641 affix - base);
c19d1205
ZW
17642 if (opcode && cond)
17643 {
17644 /* step CE */
17645 switch (opcode->tag)
17646 {
e3cb604e
PB
17647 case OT_cinfix3_legacy:
17648 /* Ignore conditional suffixes matched on infix only mnemonics. */
17649 break;
17650
c19d1205 17651 case OT_cinfix3:
088fa78e 17652 case OT_cinfix3_deprecated:
c19d1205
ZW
17653 case OT_odd_infix_unc:
17654 if (!unified_syntax)
e3cb604e 17655 return 0;
c19d1205
ZW
17656 /* else fall through */
17657
17658 case OT_csuffix:
477330fc 17659 case OT_csuffixF:
c19d1205
ZW
17660 case OT_csuf_or_in3:
17661 inst.cond = cond->value;
17662 return opcode;
17663
17664 case OT_unconditional:
17665 case OT_unconditionalF:
dfa9f0d5 17666 if (thumb_mode)
c921be7d 17667 inst.cond = cond->value;
dfa9f0d5
PB
17668 else
17669 {
c921be7d 17670 /* Delayed diagnostic. */
dfa9f0d5
PB
17671 inst.error = BAD_COND;
17672 inst.cond = COND_ALWAYS;
17673 }
c19d1205 17674 return opcode;
b99bd4ef 17675
c19d1205 17676 default:
c921be7d 17677 return NULL;
c19d1205
ZW
17678 }
17679 }
b99bd4ef 17680
c19d1205
ZW
17681 /* Cannot have a usual-position infix on a mnemonic of less than
17682 six characters (five would be a suffix). */
17683 if (end - base < 6)
c921be7d 17684 return NULL;
b99bd4ef 17685
c19d1205
ZW
17686 /* Look for infixed mnemonic in the usual position. */
17687 affix = base + 3;
21d799b5 17688 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17689 if (!cond)
c921be7d 17690 return NULL;
e3cb604e
PB
17691
17692 memcpy (save, affix, 2);
17693 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17694 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17695 (end - base) - 2);
e3cb604e
PB
17696 memmove (affix + 2, affix, (end - affix) - 2);
17697 memcpy (affix, save, 2);
17698
088fa78e
KH
17699 if (opcode
17700 && (opcode->tag == OT_cinfix3
17701 || opcode->tag == OT_cinfix3_deprecated
17702 || opcode->tag == OT_csuf_or_in3
17703 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17704 {
c921be7d 17705 /* Step CM. */
278df34e 17706 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17707 && (opcode->tag == OT_cinfix3
17708 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17709 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17710
17711 inst.cond = cond->value;
17712 return opcode;
b99bd4ef
NC
17713 }
17714
c921be7d 17715 return NULL;
b99bd4ef
NC
17716}
17717
e07e6e58
NC
17718/* This function generates an initial IT instruction, leaving its block
17719 virtually open for the new instructions. Eventually,
17720 the mask will be updated by now_it_add_mask () each time
17721 a new instruction needs to be included in the IT block.
17722 Finally, the block is closed with close_automatic_it_block ().
17723 The block closure can be requested either from md_assemble (),
17724 a tencode (), or due to a label hook. */
17725
17726static void
17727new_automatic_it_block (int cond)
17728{
17729 now_it.state = AUTOMATIC_IT_BLOCK;
17730 now_it.mask = 0x18;
17731 now_it.cc = cond;
17732 now_it.block_length = 1;
cd000bff 17733 mapping_state (MAP_THUMB);
e07e6e58 17734 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17735 now_it.warn_deprecated = FALSE;
17736 now_it.insn_cond = TRUE;
e07e6e58
NC
17737}
17738
17739/* Close an automatic IT block.
17740 See comments in new_automatic_it_block (). */
17741
17742static void
17743close_automatic_it_block (void)
17744{
17745 now_it.mask = 0x10;
17746 now_it.block_length = 0;
17747}
17748
17749/* Update the mask of the current automatically-generated IT
17750 instruction. See comments in new_automatic_it_block (). */
17751
17752static void
17753now_it_add_mask (int cond)
17754{
17755#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17756#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17757 | ((bitvalue) << (nbit)))
e07e6e58 17758 const int resulting_bit = (cond & 1);
c921be7d 17759
e07e6e58
NC
17760 now_it.mask &= 0xf;
17761 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17762 resulting_bit,
17763 (5 - now_it.block_length));
e07e6e58 17764 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17765 1,
17766 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17767 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17768
17769#undef CLEAR_BIT
17770#undef SET_BIT_VALUE
e07e6e58
NC
17771}
17772
17773/* The IT blocks handling machinery is accessed through the these functions:
17774 it_fsm_pre_encode () from md_assemble ()
17775 set_it_insn_type () optional, from the tencode functions
17776 set_it_insn_type_last () ditto
17777 in_it_block () ditto
17778 it_fsm_post_encode () from md_assemble ()
17779 force_automatic_it_block_close () from label habdling functions
17780
17781 Rationale:
17782 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17783 initializing the IT insn type with a generic initial value depending
17784 on the inst.condition.
e07e6e58 17785 2) During the tencode function, two things may happen:
477330fc
RM
17786 a) The tencode function overrides the IT insn type by
17787 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17788 b) The tencode function queries the IT block state by
17789 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17790
17791 Both set_it_insn_type and in_it_block run the internal FSM state
17792 handling function (handle_it_state), because: a) setting the IT insn
17793 type may incur in an invalid state (exiting the function),
17794 and b) querying the state requires the FSM to be updated.
17795 Specifically we want to avoid creating an IT block for conditional
17796 branches, so it_fsm_pre_encode is actually a guess and we can't
17797 determine whether an IT block is required until the tencode () routine
17798 has decided what type of instruction this actually it.
17799 Because of this, if set_it_insn_type and in_it_block have to be used,
17800 set_it_insn_type has to be called first.
17801
17802 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17803 determines the insn IT type depending on the inst.cond code.
17804 When a tencode () routine encodes an instruction that can be
17805 either outside an IT block, or, in the case of being inside, has to be
17806 the last one, set_it_insn_type_last () will determine the proper
17807 IT instruction type based on the inst.cond code. Otherwise,
17808 set_it_insn_type can be called for overriding that logic or
17809 for covering other cases.
17810
17811 Calling handle_it_state () may not transition the IT block state to
17812 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17813 still queried. Instead, if the FSM determines that the state should
17814 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17815 after the tencode () function: that's what it_fsm_post_encode () does.
17816
17817 Since in_it_block () calls the state handling function to get an
17818 updated state, an error may occur (due to invalid insns combination).
17819 In that case, inst.error is set.
17820 Therefore, inst.error has to be checked after the execution of
17821 the tencode () routine.
e07e6e58
NC
17822
17823 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17824 any pending state change (if any) that didn't take place in
17825 handle_it_state () as explained above. */
e07e6e58
NC
17826
17827static void
17828it_fsm_pre_encode (void)
17829{
17830 if (inst.cond != COND_ALWAYS)
17831 inst.it_insn_type = INSIDE_IT_INSN;
17832 else
17833 inst.it_insn_type = OUTSIDE_IT_INSN;
17834
17835 now_it.state_handled = 0;
17836}
17837
17838/* IT state FSM handling function. */
17839
17840static int
17841handle_it_state (void)
17842{
17843 now_it.state_handled = 1;
5a01bb1d 17844 now_it.insn_cond = FALSE;
e07e6e58
NC
17845
17846 switch (now_it.state)
17847 {
17848 case OUTSIDE_IT_BLOCK:
17849 switch (inst.it_insn_type)
17850 {
17851 case OUTSIDE_IT_INSN:
17852 break;
17853
17854 case INSIDE_IT_INSN:
17855 case INSIDE_IT_LAST_INSN:
17856 if (thumb_mode == 0)
17857 {
c921be7d 17858 if (unified_syntax
e07e6e58
NC
17859 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17860 as_tsktsk (_("Warning: conditional outside an IT block"\
17861 " for Thumb."));
17862 }
17863 else
17864 {
17865 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 17866 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
17867 {
17868 /* Automatically generate the IT instruction. */
17869 new_automatic_it_block (inst.cond);
17870 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17871 close_automatic_it_block ();
17872 }
17873 else
17874 {
17875 inst.error = BAD_OUT_IT;
17876 return FAIL;
17877 }
17878 }
17879 break;
17880
17881 case IF_INSIDE_IT_LAST_INSN:
17882 case NEUTRAL_IT_INSN:
17883 break;
17884
17885 case IT_INSN:
17886 now_it.state = MANUAL_IT_BLOCK;
17887 now_it.block_length = 0;
17888 break;
17889 }
17890 break;
17891
17892 case AUTOMATIC_IT_BLOCK:
17893 /* Three things may happen now:
17894 a) We should increment current it block size;
17895 b) We should close current it block (closing insn or 4 insns);
17896 c) We should close current it block and start a new one (due
17897 to incompatible conditions or
17898 4 insns-length block reached). */
17899
17900 switch (inst.it_insn_type)
17901 {
17902 case OUTSIDE_IT_INSN:
17903 /* The closure of the block shall happen immediatelly,
17904 so any in_it_block () call reports the block as closed. */
17905 force_automatic_it_block_close ();
17906 break;
17907
17908 case INSIDE_IT_INSN:
17909 case INSIDE_IT_LAST_INSN:
17910 case IF_INSIDE_IT_LAST_INSN:
17911 now_it.block_length++;
17912
17913 if (now_it.block_length > 4
17914 || !now_it_compatible (inst.cond))
17915 {
17916 force_automatic_it_block_close ();
17917 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17918 new_automatic_it_block (inst.cond);
17919 }
17920 else
17921 {
5a01bb1d 17922 now_it.insn_cond = TRUE;
e07e6e58
NC
17923 now_it_add_mask (inst.cond);
17924 }
17925
17926 if (now_it.state == AUTOMATIC_IT_BLOCK
17927 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17928 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17929 close_automatic_it_block ();
17930 break;
17931
17932 case NEUTRAL_IT_INSN:
17933 now_it.block_length++;
5a01bb1d 17934 now_it.insn_cond = TRUE;
e07e6e58
NC
17935
17936 if (now_it.block_length > 4)
17937 force_automatic_it_block_close ();
17938 else
17939 now_it_add_mask (now_it.cc & 1);
17940 break;
17941
17942 case IT_INSN:
17943 close_automatic_it_block ();
17944 now_it.state = MANUAL_IT_BLOCK;
17945 break;
17946 }
17947 break;
17948
17949 case MANUAL_IT_BLOCK:
17950 {
17951 /* Check conditional suffixes. */
17952 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17953 int is_last;
17954 now_it.mask <<= 1;
17955 now_it.mask &= 0x1f;
17956 is_last = (now_it.mask == 0x10);
5a01bb1d 17957 now_it.insn_cond = TRUE;
e07e6e58
NC
17958
17959 switch (inst.it_insn_type)
17960 {
17961 case OUTSIDE_IT_INSN:
17962 inst.error = BAD_NOT_IT;
17963 return FAIL;
17964
17965 case INSIDE_IT_INSN:
17966 if (cond != inst.cond)
17967 {
17968 inst.error = BAD_IT_COND;
17969 return FAIL;
17970 }
17971 break;
17972
17973 case INSIDE_IT_LAST_INSN:
17974 case IF_INSIDE_IT_LAST_INSN:
17975 if (cond != inst.cond)
17976 {
17977 inst.error = BAD_IT_COND;
17978 return FAIL;
17979 }
17980 if (!is_last)
17981 {
17982 inst.error = BAD_BRANCH;
17983 return FAIL;
17984 }
17985 break;
17986
17987 case NEUTRAL_IT_INSN:
17988 /* The BKPT instruction is unconditional even in an IT block. */
17989 break;
17990
17991 case IT_INSN:
17992 inst.error = BAD_IT_IT;
17993 return FAIL;
17994 }
17995 }
17996 break;
17997 }
17998
17999 return SUCCESS;
18000}
18001
5a01bb1d
MGD
18002struct depr_insn_mask
18003{
18004 unsigned long pattern;
18005 unsigned long mask;
18006 const char* description;
18007};
18008
18009/* List of 16-bit instruction patterns deprecated in an IT block in
18010 ARMv8. */
18011static const struct depr_insn_mask depr_it_insns[] = {
18012 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18013 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18014 { 0xa000, 0xb800, N_("ADR") },
18015 { 0x4800, 0xf800, N_("Literal loads") },
18016 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18017 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18018 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18019 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18020 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18021 { 0, 0, NULL }
18022};
18023
e07e6e58
NC
18024static void
18025it_fsm_post_encode (void)
18026{
18027 int is_last;
18028
18029 if (!now_it.state_handled)
18030 handle_it_state ();
18031
5a01bb1d
MGD
18032 if (now_it.insn_cond
18033 && !now_it.warn_deprecated
18034 && warn_on_deprecated
18035 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18036 {
18037 if (inst.instruction >= 0x10000)
18038 {
5c3696f8 18039 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18040 "deprecated in ARMv8"));
18041 now_it.warn_deprecated = TRUE;
18042 }
18043 else
18044 {
18045 const struct depr_insn_mask *p = depr_it_insns;
18046
18047 while (p->mask != 0)
18048 {
18049 if ((inst.instruction & p->mask) == p->pattern)
18050 {
5c3696f8 18051 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18052 "of the following class are deprecated in ARMv8: "
18053 "%s"), p->description);
18054 now_it.warn_deprecated = TRUE;
18055 break;
18056 }
18057
18058 ++p;
18059 }
18060 }
18061
18062 if (now_it.block_length > 1)
18063 {
5c3696f8 18064 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18065 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18066 now_it.warn_deprecated = TRUE;
18067 }
18068 }
18069
e07e6e58
NC
18070 is_last = (now_it.mask == 0x10);
18071 if (is_last)
18072 {
18073 now_it.state = OUTSIDE_IT_BLOCK;
18074 now_it.mask = 0;
18075 }
18076}
18077
18078static void
18079force_automatic_it_block_close (void)
18080{
18081 if (now_it.state == AUTOMATIC_IT_BLOCK)
18082 {
18083 close_automatic_it_block ();
18084 now_it.state = OUTSIDE_IT_BLOCK;
18085 now_it.mask = 0;
18086 }
18087}
18088
18089static int
18090in_it_block (void)
18091{
18092 if (!now_it.state_handled)
18093 handle_it_state ();
18094
18095 return now_it.state != OUTSIDE_IT_BLOCK;
18096}
18097
ff8646ee
TP
18098/* Whether OPCODE only has T32 encoding. Since this function is only used by
18099 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18100 here, hence the "known" in the function name. */
fc289b0a
TP
18101
18102static bfd_boolean
ff8646ee 18103known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18104{
18105 /* Original Thumb-1 wide instruction. */
18106 if (opcode->tencode == do_t_blx
18107 || opcode->tencode == do_t_branch23
18108 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18109 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18110 return TRUE;
18111
ff8646ee
TP
18112 /* Wide-only instruction added to ARMv8-M. */
18113 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m)
18114 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18115 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18116 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18117 return TRUE;
18118
18119 return FALSE;
18120}
18121
18122/* Whether wide instruction variant can be used if available for a valid OPCODE
18123 in ARCH. */
18124
18125static bfd_boolean
18126t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18127{
18128 if (known_t32_only_insn (opcode))
18129 return TRUE;
18130
18131 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18132 of variant T3 of B.W is checked in do_t_branch. */
18133 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18134 && opcode->tencode == do_t_branch)
18135 return TRUE;
18136
18137 /* Wide instruction variants of all instructions with narrow *and* wide
18138 variants become available with ARMv6t2. Other opcodes are either
18139 narrow-only or wide-only and are thus available if OPCODE is valid. */
18140 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18141 return TRUE;
18142
18143 /* OPCODE with narrow only instruction variant or wide variant not
18144 available. */
fc289b0a
TP
18145 return FALSE;
18146}
18147
c19d1205
ZW
18148void
18149md_assemble (char *str)
b99bd4ef 18150{
c19d1205
ZW
18151 char *p = str;
18152 const struct asm_opcode * opcode;
b99bd4ef 18153
c19d1205
ZW
18154 /* Align the previous label if needed. */
18155 if (last_label_seen != NULL)
b99bd4ef 18156 {
c19d1205
ZW
18157 symbol_set_frag (last_label_seen, frag_now);
18158 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18159 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18160 }
18161
c19d1205
ZW
18162 memset (&inst, '\0', sizeof (inst));
18163 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18164
c19d1205
ZW
18165 opcode = opcode_lookup (&p);
18166 if (!opcode)
b99bd4ef 18167 {
c19d1205 18168 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18169 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18170 if (! create_register_alias (str, p)
477330fc 18171 && ! create_neon_reg_alias (str, p))
c19d1205 18172 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18173
b99bd4ef
NC
18174 return;
18175 }
18176
278df34e 18177 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18178 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18179
037e8744
JB
18180 /* The value which unconditional instructions should have in place of the
18181 condition field. */
18182 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18183
c19d1205 18184 if (thumb_mode)
b99bd4ef 18185 {
e74cfd16 18186 arm_feature_set variant;
8f06b2d8
PB
18187
18188 variant = cpu_variant;
18189 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18190 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18191 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18192 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18193 if (!opcode->tvariant
18194 || (thumb_mode == 1
18195 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18196 {
84b52b66 18197 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18198 return;
18199 }
c19d1205
ZW
18200 if (inst.cond != COND_ALWAYS && !unified_syntax
18201 && opcode->tencode != do_t_branch)
b99bd4ef 18202 {
c19d1205 18203 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18204 return;
18205 }
18206
fc289b0a
TP
18207 /* Two things are addressed here:
18208 1) Implicit require narrow instructions on Thumb-1.
18209 This avoids relaxation accidentally introducing Thumb-2
18210 instructions.
18211 2) Reject wide instructions in non Thumb-2 cores.
18212
18213 Only instructions with narrow and wide variants need to be handled
18214 but selecting all non wide-only instructions is easier. */
18215 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18216 && !t32_insn_ok (variant, opcode))
076d447c 18217 {
fc289b0a
TP
18218 if (inst.size_req == 0)
18219 inst.size_req = 2;
18220 else if (inst.size_req == 4)
752d5da4 18221 {
ff8646ee
TP
18222 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18223 as_bad (_("selected processor does not support 32bit wide "
18224 "variant of instruction `%s'"), str);
18225 else
18226 as_bad (_("selected processor does not support `%s' in "
18227 "Thumb-2 mode"), str);
fc289b0a 18228 return;
752d5da4 18229 }
076d447c
PB
18230 }
18231
c19d1205
ZW
18232 inst.instruction = opcode->tvalue;
18233
5be8be5d 18234 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18235 {
18236 /* Prepare the it_insn_type for those encodings that don't set
18237 it. */
18238 it_fsm_pre_encode ();
c19d1205 18239
477330fc 18240 opcode->tencode ();
e07e6e58 18241
477330fc
RM
18242 it_fsm_post_encode ();
18243 }
e27ec89e 18244
0110f2b8 18245 if (!(inst.error || inst.relax))
b99bd4ef 18246 {
9c2799c2 18247 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18248 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18249 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18250 {
c19d1205 18251 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18252 return;
18253 }
18254 }
076d447c
PB
18255
18256 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18257 instruction. */
9c2799c2 18258 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18259
e74cfd16
PB
18260 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18261 *opcode->tvariant);
ee065d83 18262 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18263 set those bits when Thumb-2 32-bit instructions are seen. The impact
18264 of relaxable instructions will be considered later after we finish all
18265 relaxation. */
ff8646ee
TP
18266 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18267 variant = arm_arch_none;
18268 else
18269 variant = cpu_variant;
18270 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18271 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18272 arm_ext_v6t2);
cd000bff 18273
88714cb8
DG
18274 check_neon_suffixes;
18275
cd000bff 18276 if (!inst.error)
c877a2f2
NC
18277 {
18278 mapping_state (MAP_THUMB);
18279 }
c19d1205 18280 }
3e9e4fcf 18281 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18282 {
845b51d6
PB
18283 bfd_boolean is_bx;
18284
18285 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18286 is_bx = (opcode->aencode == do_bx);
18287
c19d1205 18288 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18289 if (!(is_bx && fix_v4bx)
18290 && !(opcode->avariant &&
18291 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18292 {
84b52b66 18293 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18294 return;
b99bd4ef 18295 }
c19d1205 18296 if (inst.size_req)
b99bd4ef 18297 {
c19d1205
ZW
18298 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18299 return;
b99bd4ef
NC
18300 }
18301
c19d1205
ZW
18302 inst.instruction = opcode->avalue;
18303 if (opcode->tag == OT_unconditionalF)
eff0bc54 18304 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18305 else
18306 inst.instruction |= inst.cond << 28;
18307 inst.size = INSN_SIZE;
5be8be5d 18308 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18309 {
18310 it_fsm_pre_encode ();
18311 opcode->aencode ();
18312 it_fsm_post_encode ();
18313 }
ee065d83 18314 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18315 on a hypothetical non-thumb v5 core. */
845b51d6 18316 if (is_bx)
e74cfd16 18317 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18318 else
e74cfd16
PB
18319 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18320 *opcode->avariant);
88714cb8
DG
18321
18322 check_neon_suffixes;
18323
cd000bff 18324 if (!inst.error)
c877a2f2
NC
18325 {
18326 mapping_state (MAP_ARM);
18327 }
b99bd4ef 18328 }
3e9e4fcf
JB
18329 else
18330 {
18331 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18332 "-- `%s'"), str);
18333 return;
18334 }
c19d1205
ZW
18335 output_inst (str);
18336}
b99bd4ef 18337
e07e6e58
NC
18338static void
18339check_it_blocks_finished (void)
18340{
18341#ifdef OBJ_ELF
18342 asection *sect;
18343
18344 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18345 if (seg_info (sect)->tc_segment_info_data.current_it.state
18346 == MANUAL_IT_BLOCK)
18347 {
18348 as_warn (_("section '%s' finished with an open IT block."),
18349 sect->name);
18350 }
18351#else
18352 if (now_it.state == MANUAL_IT_BLOCK)
18353 as_warn (_("file finished with an open IT block."));
18354#endif
18355}
18356
c19d1205
ZW
18357/* Various frobbings of labels and their addresses. */
18358
18359void
18360arm_start_line_hook (void)
18361{
18362 last_label_seen = NULL;
b99bd4ef
NC
18363}
18364
c19d1205
ZW
18365void
18366arm_frob_label (symbolS * sym)
b99bd4ef 18367{
c19d1205 18368 last_label_seen = sym;
b99bd4ef 18369
c19d1205 18370 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18371
c19d1205
ZW
18372#if defined OBJ_COFF || defined OBJ_ELF
18373 ARM_SET_INTERWORK (sym, support_interwork);
18374#endif
b99bd4ef 18375
e07e6e58
NC
18376 force_automatic_it_block_close ();
18377
5f4273c7 18378 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18379 as Thumb functions. This is because these labels, whilst
18380 they exist inside Thumb code, are not the entry points for
18381 possible ARM->Thumb calls. Also, these labels can be used
18382 as part of a computed goto or switch statement. eg gcc
18383 can generate code that looks like this:
b99bd4ef 18384
c19d1205
ZW
18385 ldr r2, [pc, .Laaa]
18386 lsl r3, r3, #2
18387 ldr r2, [r3, r2]
18388 mov pc, r2
b99bd4ef 18389
c19d1205
ZW
18390 .Lbbb: .word .Lxxx
18391 .Lccc: .word .Lyyy
18392 ..etc...
18393 .Laaa: .word Lbbb
b99bd4ef 18394
c19d1205
ZW
18395 The first instruction loads the address of the jump table.
18396 The second instruction converts a table index into a byte offset.
18397 The third instruction gets the jump address out of the table.
18398 The fourth instruction performs the jump.
b99bd4ef 18399
c19d1205
ZW
18400 If the address stored at .Laaa is that of a symbol which has the
18401 Thumb_Func bit set, then the linker will arrange for this address
18402 to have the bottom bit set, which in turn would mean that the
18403 address computation performed by the third instruction would end
18404 up with the bottom bit set. Since the ARM is capable of unaligned
18405 word loads, the instruction would then load the incorrect address
18406 out of the jump table, and chaos would ensue. */
18407 if (label_is_thumb_function_name
18408 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18409 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18410 {
c19d1205
ZW
18411 /* When the address of a Thumb function is taken the bottom
18412 bit of that address should be set. This will allow
18413 interworking between Arm and Thumb functions to work
18414 correctly. */
b99bd4ef 18415
c19d1205 18416 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18417
c19d1205 18418 label_is_thumb_function_name = FALSE;
b99bd4ef 18419 }
07a53e5c 18420
07a53e5c 18421 dwarf2_emit_label (sym);
b99bd4ef
NC
18422}
18423
c921be7d 18424bfd_boolean
c19d1205 18425arm_data_in_code (void)
b99bd4ef 18426{
c19d1205 18427 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18428 {
c19d1205
ZW
18429 *input_line_pointer = '/';
18430 input_line_pointer += 5;
18431 *input_line_pointer = 0;
c921be7d 18432 return TRUE;
b99bd4ef
NC
18433 }
18434
c921be7d 18435 return FALSE;
b99bd4ef
NC
18436}
18437
c19d1205
ZW
18438char *
18439arm_canonicalize_symbol_name (char * name)
b99bd4ef 18440{
c19d1205 18441 int len;
b99bd4ef 18442
c19d1205
ZW
18443 if (thumb_mode && (len = strlen (name)) > 5
18444 && streq (name + len - 5, "/data"))
18445 *(name + len - 5) = 0;
b99bd4ef 18446
c19d1205 18447 return name;
b99bd4ef 18448}
c19d1205
ZW
18449\f
18450/* Table of all register names defined by default. The user can
18451 define additional names with .req. Note that all register names
18452 should appear in both upper and lowercase variants. Some registers
18453 also have mixed-case names. */
b99bd4ef 18454
dcbf9037 18455#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18456#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18457#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18458#define REGSET(p,t) \
18459 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18460 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18461 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18462 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18463#define REGSETH(p,t) \
18464 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18465 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18466 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18467 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18468#define REGSET2(p,t) \
18469 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18470 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18471 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18472 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18473#define SPLRBANK(base,bank,t) \
18474 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18475 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18476 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18477 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18478 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18479 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18480
c19d1205 18481static const struct reg_entry reg_names[] =
7ed4c4c5 18482{
c19d1205
ZW
18483 /* ARM integer registers. */
18484 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18485
c19d1205
ZW
18486 /* ATPCS synonyms. */
18487 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18488 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18489 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18490
c19d1205
ZW
18491 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18492 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18493 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18494
c19d1205
ZW
18495 /* Well-known aliases. */
18496 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18497 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18498
18499 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18500 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18501
18502 /* Coprocessor numbers. */
18503 REGSET(p, CP), REGSET(P, CP),
18504
18505 /* Coprocessor register numbers. The "cr" variants are for backward
18506 compatibility. */
18507 REGSET(c, CN), REGSET(C, CN),
18508 REGSET(cr, CN), REGSET(CR, CN),
18509
90ec0d68
MGD
18510 /* ARM banked registers. */
18511 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18512 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18513 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18514 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18515 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18516 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18517 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18518
18519 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18520 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18521 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18522 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18523 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18524 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18525 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18526 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18527
18528 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18529 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18530 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18531 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18532 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18533 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18534 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18535 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18536 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18537
c19d1205
ZW
18538 /* FPA registers. */
18539 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18540 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18541
18542 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18543 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18544
18545 /* VFP SP registers. */
5287ad62
JB
18546 REGSET(s,VFS), REGSET(S,VFS),
18547 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18548
18549 /* VFP DP Registers. */
5287ad62
JB
18550 REGSET(d,VFD), REGSET(D,VFD),
18551 /* Extra Neon DP registers. */
18552 REGSETH(d,VFD), REGSETH(D,VFD),
18553
18554 /* Neon QP registers. */
18555 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18556
18557 /* VFP control registers. */
18558 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18559 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18560 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18561 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18562 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18563 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18564
18565 /* Maverick DSP coprocessor registers. */
18566 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18567 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18568
18569 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18570 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18571 REGDEF(dspsc,0,DSPSC),
18572
18573 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18574 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18575 REGDEF(DSPSC,0,DSPSC),
18576
18577 /* iWMMXt data registers - p0, c0-15. */
18578 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18579
18580 /* iWMMXt control registers - p1, c0-3. */
18581 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18582 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18583 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18584 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18585
18586 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18587 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18588 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18589 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18590 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18591
18592 /* XScale accumulator registers. */
18593 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18594};
18595#undef REGDEF
18596#undef REGNUM
18597#undef REGSET
7ed4c4c5 18598
c19d1205
ZW
18599/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18600 within psr_required_here. */
18601static const struct asm_psr psrs[] =
18602{
18603 /* Backward compatibility notation. Note that "all" is no longer
18604 truly all possible PSR bits. */
18605 {"all", PSR_c | PSR_f},
18606 {"flg", PSR_f},
18607 {"ctl", PSR_c},
18608
18609 /* Individual flags. */
18610 {"f", PSR_f},
18611 {"c", PSR_c},
18612 {"x", PSR_x},
18613 {"s", PSR_s},
59b42a0d 18614
c19d1205
ZW
18615 /* Combinations of flags. */
18616 {"fs", PSR_f | PSR_s},
18617 {"fx", PSR_f | PSR_x},
18618 {"fc", PSR_f | PSR_c},
18619 {"sf", PSR_s | PSR_f},
18620 {"sx", PSR_s | PSR_x},
18621 {"sc", PSR_s | PSR_c},
18622 {"xf", PSR_x | PSR_f},
18623 {"xs", PSR_x | PSR_s},
18624 {"xc", PSR_x | PSR_c},
18625 {"cf", PSR_c | PSR_f},
18626 {"cs", PSR_c | PSR_s},
18627 {"cx", PSR_c | PSR_x},
18628 {"fsx", PSR_f | PSR_s | PSR_x},
18629 {"fsc", PSR_f | PSR_s | PSR_c},
18630 {"fxs", PSR_f | PSR_x | PSR_s},
18631 {"fxc", PSR_f | PSR_x | PSR_c},
18632 {"fcs", PSR_f | PSR_c | PSR_s},
18633 {"fcx", PSR_f | PSR_c | PSR_x},
18634 {"sfx", PSR_s | PSR_f | PSR_x},
18635 {"sfc", PSR_s | PSR_f | PSR_c},
18636 {"sxf", PSR_s | PSR_x | PSR_f},
18637 {"sxc", PSR_s | PSR_x | PSR_c},
18638 {"scf", PSR_s | PSR_c | PSR_f},
18639 {"scx", PSR_s | PSR_c | PSR_x},
18640 {"xfs", PSR_x | PSR_f | PSR_s},
18641 {"xfc", PSR_x | PSR_f | PSR_c},
18642 {"xsf", PSR_x | PSR_s | PSR_f},
18643 {"xsc", PSR_x | PSR_s | PSR_c},
18644 {"xcf", PSR_x | PSR_c | PSR_f},
18645 {"xcs", PSR_x | PSR_c | PSR_s},
18646 {"cfs", PSR_c | PSR_f | PSR_s},
18647 {"cfx", PSR_c | PSR_f | PSR_x},
18648 {"csf", PSR_c | PSR_s | PSR_f},
18649 {"csx", PSR_c | PSR_s | PSR_x},
18650 {"cxf", PSR_c | PSR_x | PSR_f},
18651 {"cxs", PSR_c | PSR_x | PSR_s},
18652 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18653 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18654 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18655 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18656 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18657 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18658 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18659 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18660 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18661 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18662 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18663 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18664 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18665 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18666 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18667 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18668 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18669 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18670 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18671 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18672 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18673 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18674 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18675 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18676};
18677
62b3e311
PB
18678/* Table of V7M psr names. */
18679static const struct asm_psr v7m_psrs[] =
18680{
2b744c99
PB
18681 {"apsr", 0 }, {"APSR", 0 },
18682 {"iapsr", 1 }, {"IAPSR", 1 },
18683 {"eapsr", 2 }, {"EAPSR", 2 },
18684 {"psr", 3 }, {"PSR", 3 },
18685 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18686 {"ipsr", 5 }, {"IPSR", 5 },
18687 {"epsr", 6 }, {"EPSR", 6 },
18688 {"iepsr", 7 }, {"IEPSR", 7 },
18689 {"msp", 8 }, {"MSP", 8 },
18690 {"psp", 9 }, {"PSP", 9 },
18691 {"primask", 16}, {"PRIMASK", 16},
18692 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18693 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18694 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18695 {"faultmask", 19}, {"FAULTMASK", 19},
18696 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18697};
18698
c19d1205
ZW
18699/* Table of all shift-in-operand names. */
18700static const struct asm_shift_name shift_names [] =
b99bd4ef 18701{
c19d1205
ZW
18702 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18703 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18704 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18705 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18706 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18707 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18708};
b99bd4ef 18709
c19d1205
ZW
18710/* Table of all explicit relocation names. */
18711#ifdef OBJ_ELF
18712static struct reloc_entry reloc_names[] =
18713{
18714 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18715 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18716 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18717 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18718 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18719 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18720 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18721 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18722 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18723 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18724 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18725 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18726 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18727 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18728 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18729 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18730 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18731 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18732};
18733#endif
b99bd4ef 18734
c19d1205
ZW
18735/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18736static const struct asm_cond conds[] =
18737{
18738 {"eq", 0x0},
18739 {"ne", 0x1},
18740 {"cs", 0x2}, {"hs", 0x2},
18741 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18742 {"mi", 0x4},
18743 {"pl", 0x5},
18744 {"vs", 0x6},
18745 {"vc", 0x7},
18746 {"hi", 0x8},
18747 {"ls", 0x9},
18748 {"ge", 0xa},
18749 {"lt", 0xb},
18750 {"gt", 0xc},
18751 {"le", 0xd},
18752 {"al", 0xe}
18753};
bfae80f2 18754
e797f7e0 18755#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18756 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18757 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18758
62b3e311
PB
18759static struct asm_barrier_opt barrier_opt_names[] =
18760{
e797f7e0
MGD
18761 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18762 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18763 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18764 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18765 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18766 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18767 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18768 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18769 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18770 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18771 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18772 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18773 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18774 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18775 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18776 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18777};
18778
e797f7e0
MGD
18779#undef UL_BARRIER
18780
c19d1205
ZW
18781/* Table of ARM-format instructions. */
18782
18783/* Macros for gluing together operand strings. N.B. In all cases
18784 other than OPS0, the trailing OP_stop comes from default
18785 zero-initialization of the unspecified elements of the array. */
18786#define OPS0() { OP_stop, }
18787#define OPS1(a) { OP_##a, }
18788#define OPS2(a,b) { OP_##a,OP_##b, }
18789#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18790#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18791#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18792#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18793
5be8be5d
DG
18794/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18795 This is useful when mixing operands for ARM and THUMB, i.e. using the
18796 MIX_ARM_THUMB_OPERANDS macro.
18797 In order to use these macros, prefix the number of operands with _
18798 e.g. _3. */
18799#define OPS_1(a) { a, }
18800#define OPS_2(a,b) { a,b, }
18801#define OPS_3(a,b,c) { a,b,c, }
18802#define OPS_4(a,b,c,d) { a,b,c,d, }
18803#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18804#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18805
c19d1205
ZW
18806/* These macros abstract out the exact format of the mnemonic table and
18807 save some repeated characters. */
18808
18809/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18810#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18811 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18812 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18813
18814/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18815 a T_MNEM_xyz enumerator. */
18816#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18817 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18818#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18819 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18820
18821/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18822 infix after the third character. */
18823#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18824 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18825 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18826#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18827 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18828 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18829#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18830 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18831#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18832 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18833#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18834 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18835#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18836 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18837
c19d1205 18838/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18839 field is still 0xE. Many of the Thumb variants can be executed
18840 conditionally, so this is checked separately. */
c19d1205 18841#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18842 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18843 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18844
dd5181d5
KT
18845/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18846 Used by mnemonics that have very minimal differences in the encoding for
18847 ARM and Thumb variants and can be handled in a common function. */
18848#define TUEc(mnem, op, top, nops, ops, en) \
18849 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18850 THUMB_VARIANT, do_##en, do_##en }
18851
c19d1205
ZW
18852/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18853 condition code field. */
18854#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18855 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18856 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18857
18858/* ARM-only variants of all the above. */
6a86118a 18859#define CE(mnem, op, nops, ops, ae) \
21d799b5 18860 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18861
18862#define C3(mnem, op, nops, ops, ae) \
18863 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18864
e3cb604e
PB
18865/* Legacy mnemonics that always have conditional infix after the third
18866 character. */
18867#define CL(mnem, op, nops, ops, ae) \
21d799b5 18868 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18869 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18870
8f06b2d8
PB
18871/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18872#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18873 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18874
e3cb604e
PB
18875/* Legacy coprocessor instructions where conditional infix and conditional
18876 suffix are ambiguous. For consistency this includes all FPA instructions,
18877 not just the potentially ambiguous ones. */
18878#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18879 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18880 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18881
18882/* Coprocessor, takes either a suffix or a position-3 infix
18883 (for an FPA corner case). */
18884#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18885 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18886 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18887
6a86118a 18888#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18889 { m1 #m2 m3, OPS##nops ops, \
18890 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18891 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18892
18893#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18894 xCM_ (m1, , m2, op, nops, ops, ae), \
18895 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18896 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18897 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18898 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18899 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18900 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18901 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18902 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18903 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18904 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18905 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18906 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18907 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18908 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18909 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18910 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18911 xCM_ (m1, le, m2, op, nops, ops, ae), \
18912 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18913
18914#define UE(mnem, op, nops, ops, ae) \
18915 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18916
18917#define UF(mnem, op, nops, ops, ae) \
18918 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18919
5287ad62
JB
18920/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18921 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18922 use the same encoding function for each. */
18923#define NUF(mnem, op, nops, ops, enc) \
18924 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18925 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18926
18927/* Neon data processing, version which indirects through neon_enc_tab for
18928 the various overloaded versions of opcodes. */
18929#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18930 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18931 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18932
18933/* Neon insn with conditional suffix for the ARM version, non-overloaded
18934 version. */
037e8744
JB
18935#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18936 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18937 THUMB_VARIANT, do_##enc, do_##enc }
18938
037e8744 18939#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18940 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18941
18942#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18943 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18944
5287ad62 18945/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18946#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18947 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18948 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18949
037e8744 18950#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18951 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18952
18953#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18954 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18955
c19d1205
ZW
18956#define do_0 0
18957
c19d1205 18958static const struct asm_opcode insns[] =
bfae80f2 18959{
74db7efb
NC
18960#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18961#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18962 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18963 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18964 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18965 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18966 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18967 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18968 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18969 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18970 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18971 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18972 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18973 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18974 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18975 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18976 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18977 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18978
18979 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18980 for setting PSR flag bits. They are obsolete in V6 and do not
18981 have Thumb equivalents. */
21d799b5
NC
18982 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18983 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18984 CL("tstp", 110f000, 2, (RR, SH), cmp),
18985 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18986 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18987 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18988 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18989 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18990 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18991
18992 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 18993 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
18994 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18995 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18996
18997 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18998 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18999 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19000 OP_RRnpc),
19001 OP_ADDRGLDR),ldst, t_ldst),
19002 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19003
19004 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19005 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19006 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19007 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19008 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19009 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19010
19011 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19012 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19013 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19014 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19015
c19d1205 19016 /* Pseudo ops. */
21d799b5 19017 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19018 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19019 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19020 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19021
19022 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19023 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19024 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19025 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19026 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19027 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19028 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19029 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19030 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19031 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19032 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19033 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19034 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19035
16a4cf17 19036 /* These may simplify to neg. */
21d799b5
NC
19037 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19038 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19039
c921be7d
NC
19040#undef THUMB_VARIANT
19041#define THUMB_VARIANT & arm_ext_v6
19042
21d799b5 19043 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19044
19045 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19046#undef THUMB_VARIANT
19047#define THUMB_VARIANT & arm_ext_v6t2
19048
21d799b5
NC
19049 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19050 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19051 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19052
5be8be5d
DG
19053 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19054 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19055 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19056 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19057
21d799b5
NC
19058 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19059 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19060
21d799b5
NC
19061 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19062 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19063
19064 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19065 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19066 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19067
19068 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19069 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19070 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19071 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19072 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19073 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19074 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19075 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19076
c921be7d
NC
19077#undef ARM_VARIANT
19078#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19079#undef THUMB_VARIANT
19080#define THUMB_VARIANT & arm_ext_v4t
19081
21d799b5
NC
19082 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19083 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19084
c921be7d
NC
19085#undef THUMB_VARIANT
19086#define THUMB_VARIANT & arm_ext_v6t2
19087
21d799b5 19088 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19089 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19090
19091 /* Generic coprocessor instructions. */
21d799b5
NC
19092 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19093 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19094 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19095 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19096 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19097 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19098 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19099
c921be7d
NC
19100#undef ARM_VARIANT
19101#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19102
21d799b5 19103 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19104 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19105
c921be7d
NC
19106#undef ARM_VARIANT
19107#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19108#undef THUMB_VARIANT
19109#define THUMB_VARIANT & arm_ext_msr
19110
d2cd1205
JB
19111 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19112 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19113
c921be7d
NC
19114#undef ARM_VARIANT
19115#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19116#undef THUMB_VARIANT
19117#define THUMB_VARIANT & arm_ext_v6t2
19118
21d799b5
NC
19119 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19120 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19121 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19122 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19123 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19124 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19125 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19126 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19127
c921be7d
NC
19128#undef ARM_VARIANT
19129#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19130#undef THUMB_VARIANT
19131#define THUMB_VARIANT & arm_ext_v4t
19132
5be8be5d
DG
19133 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19134 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19135 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19136 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19137 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19138 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19139
c921be7d
NC
19140#undef ARM_VARIANT
19141#define ARM_VARIANT & arm_ext_v4t_5
19142
c19d1205
ZW
19143 /* ARM Architecture 4T. */
19144 /* Note: bx (and blx) are required on V5, even if the processor does
19145 not support Thumb. */
21d799b5 19146 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19147
c921be7d
NC
19148#undef ARM_VARIANT
19149#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19150#undef THUMB_VARIANT
19151#define THUMB_VARIANT & arm_ext_v5t
19152
c19d1205
ZW
19153 /* Note: blx has 2 variants; the .value coded here is for
19154 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19155 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19156 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19157
c921be7d
NC
19158#undef THUMB_VARIANT
19159#define THUMB_VARIANT & arm_ext_v6t2
19160
21d799b5
NC
19161 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19162 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19163 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19164 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19165 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19166 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19167 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19168 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19169
c921be7d 19170#undef ARM_VARIANT
74db7efb
NC
19171#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19172#undef THUMB_VARIANT
19173#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19174
21d799b5
NC
19175 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19176 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19177 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19178 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19179
21d799b5
NC
19180 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19181 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19182
21d799b5
NC
19183 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19184 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19185 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19186 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19187
21d799b5
NC
19188 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19189 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19190 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19191 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19192
21d799b5
NC
19193 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19194 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19195
03ee1b7f
NC
19196 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19197 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19198 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19199 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19200
c921be7d 19201#undef ARM_VARIANT
74db7efb
NC
19202#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19203#undef THUMB_VARIANT
19204#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19205
21d799b5 19206 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19207 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19208 ldrd, t_ldstd),
19209 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19210 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19211
21d799b5
NC
19212 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19213 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19214
c921be7d
NC
19215#undef ARM_VARIANT
19216#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19217
21d799b5 19218 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19219
c921be7d
NC
19220#undef ARM_VARIANT
19221#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19222#undef THUMB_VARIANT
19223#define THUMB_VARIANT & arm_ext_v6
19224
21d799b5
NC
19225 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19226 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19227 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19228 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19229 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19230 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19231 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19232 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19233 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19234 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19235
c921be7d 19236#undef THUMB_VARIANT
ff8646ee 19237#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19238
5be8be5d
DG
19239 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19240 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19241 strex, t_strex),
ff8646ee
TP
19242#undef THUMB_VARIANT
19243#define THUMB_VARIANT & arm_ext_v6t2
19244
21d799b5
NC
19245 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19246 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19247
21d799b5
NC
19248 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19249 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19250
9e3c6df6 19251/* ARM V6 not included in V7M. */
c921be7d
NC
19252#undef THUMB_VARIANT
19253#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19254 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19255 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19256 UF(rfeib, 9900a00, 1, (RRw), rfe),
19257 UF(rfeda, 8100a00, 1, (RRw), rfe),
19258 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19259 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19260 UF(rfefa, 8100a00, 1, (RRw), rfe),
19261 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19262 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19263 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19264 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19265 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19266 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19267 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19268 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19269 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19270 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19271 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19272 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19273
9e3c6df6
PB
19274/* ARM V6 not included in V7M (eg. integer SIMD). */
19275#undef THUMB_VARIANT
19276#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19277 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19278 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19279 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19280 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19281 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19282 /* Old name for QASX. */
74db7efb 19283 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19284 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19285 /* Old name for QSAX. */
74db7efb 19286 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19287 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19288 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19289 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19290 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19291 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19292 /* Old name for SASX. */
74db7efb 19293 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19294 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19295 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19296 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19297 /* Old name for SHASX. */
21d799b5 19298 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19299 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19300 /* Old name for SHSAX. */
21d799b5
NC
19301 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19302 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19303 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19304 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19305 /* Old name for SSAX. */
74db7efb 19306 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19307 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19308 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19309 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19310 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19311 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19312 /* Old name for UASX. */
74db7efb 19313 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19314 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19315 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19316 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19317 /* Old name for UHASX. */
21d799b5
NC
19318 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19319 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19320 /* Old name for UHSAX. */
21d799b5
NC
19321 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19322 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19323 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19324 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19325 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19326 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19327 /* Old name for UQASX. */
21d799b5
NC
19328 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19329 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19330 /* Old name for UQSAX. */
21d799b5
NC
19331 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19332 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19333 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19334 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19335 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19336 /* Old name for USAX. */
74db7efb 19337 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19338 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19339 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19340 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19341 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19342 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19343 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19344 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19345 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19346 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19347 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19348 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19349 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19350 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19351 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19352 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19353 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19354 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19355 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19356 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19357 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19358 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19359 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19360 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19361 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19362 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19363 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19364 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19365 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19366 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19367 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19368 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19369 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19370 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19371
c921be7d
NC
19372#undef ARM_VARIANT
19373#define ARM_VARIANT & arm_ext_v6k
19374#undef THUMB_VARIANT
19375#define THUMB_VARIANT & arm_ext_v6k
19376
21d799b5
NC
19377 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19378 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19379 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19380 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19381
c921be7d
NC
19382#undef THUMB_VARIANT
19383#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19384 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19385 ldrexd, t_ldrexd),
19386 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19387 RRnpcb), strexd, t_strexd),
ebdca51a 19388
c921be7d 19389#undef THUMB_VARIANT
ff8646ee 19390#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19391 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19392 rd_rn, rd_rn),
19393 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19394 rd_rn, rd_rn),
19395 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19396 strex, t_strexbh),
5be8be5d 19397 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19398 strex, t_strexbh),
21d799b5 19399 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19400
c921be7d 19401#undef ARM_VARIANT
f4c65163 19402#define ARM_VARIANT & arm_ext_sec
74db7efb 19403#undef THUMB_VARIANT
f4c65163 19404#define THUMB_VARIANT & arm_ext_sec
c921be7d 19405
21d799b5 19406 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19407
90ec0d68
MGD
19408#undef ARM_VARIANT
19409#define ARM_VARIANT & arm_ext_virt
19410#undef THUMB_VARIANT
19411#define THUMB_VARIANT & arm_ext_virt
19412
19413 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19414 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19415
ddfded2f
MW
19416#undef ARM_VARIANT
19417#define ARM_VARIANT & arm_ext_pan
19418#undef THUMB_VARIANT
19419#define THUMB_VARIANT & arm_ext_pan
19420
19421 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19422
c921be7d 19423#undef ARM_VARIANT
74db7efb 19424#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19425#undef THUMB_VARIANT
19426#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19427
21d799b5
NC
19428 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19429 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19430 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19431 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19432
21d799b5 19433 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19434 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19435
5be8be5d
DG
19436 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19437 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19438 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19439 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19440
ff8646ee
TP
19441#undef THUMB_VARIANT
19442#define THUMB_VARIANT & arm_ext_v6t2_v8m
19443 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19444 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19445
bf3eeda7 19446 /* Thumb-only instructions. */
74db7efb 19447#undef ARM_VARIANT
bf3eeda7
NS
19448#define ARM_VARIANT NULL
19449 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19450 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19451
19452 /* ARM does not really have an IT instruction, so always allow it.
19453 The opcode is copied from Thumb in order to allow warnings in
19454 -mimplicit-it=[never | arm] modes. */
19455#undef ARM_VARIANT
19456#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19457#undef THUMB_VARIANT
19458#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19459
21d799b5
NC
19460 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19461 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19462 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19463 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19464 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19465 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19466 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19467 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19468 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19469 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19470 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19471 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19472 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19473 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19474 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19475 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19476 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19477 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19478
92e90b6e 19479 /* Thumb2 only instructions. */
c921be7d
NC
19480#undef ARM_VARIANT
19481#define ARM_VARIANT NULL
92e90b6e 19482
21d799b5
NC
19483 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19484 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19485 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19486 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19487 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19488 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19489
eea54501
MGD
19490 /* Hardware division instructions. */
19491#undef ARM_VARIANT
19492#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19493#undef THUMB_VARIANT
19494#define THUMB_VARIANT & arm_ext_div
19495
eea54501
MGD
19496 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19497 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19498
7e806470 19499 /* ARM V6M/V7 instructions. */
c921be7d
NC
19500#undef ARM_VARIANT
19501#define ARM_VARIANT & arm_ext_barrier
19502#undef THUMB_VARIANT
19503#define THUMB_VARIANT & arm_ext_barrier
19504
ccb84d65
JB
19505 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19506 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19507 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19508
62b3e311 19509 /* ARM V7 instructions. */
c921be7d
NC
19510#undef ARM_VARIANT
19511#define ARM_VARIANT & arm_ext_v7
19512#undef THUMB_VARIANT
19513#define THUMB_VARIANT & arm_ext_v7
19514
21d799b5
NC
19515 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19516 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19517
74db7efb 19518#undef ARM_VARIANT
60e5ef9f 19519#define ARM_VARIANT & arm_ext_mp
74db7efb 19520#undef THUMB_VARIANT
60e5ef9f
MGD
19521#define THUMB_VARIANT & arm_ext_mp
19522
19523 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19524
53c4b28b
MGD
19525 /* AArchv8 instructions. */
19526#undef ARM_VARIANT
19527#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19528
19529/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19530#undef THUMB_VARIANT
4ed7ed8d 19531#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19532
4ed7ed8d
TP
19533 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19534 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19535 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19536 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19537 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19538 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19539 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19540 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19541 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19542 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19543 stlex, t_stlex),
4b8c8c02
RE
19544 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19545 stlex, t_stlex),
19546 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19547 stlex, t_stlex),
4ed7ed8d
TP
19548#undef THUMB_VARIANT
19549#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19550
4ed7ed8d
TP
19551 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19552 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19553 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19554 ldrexd, t_ldrexd),
19555 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19556 strexd, t_strexd),
8884b720 19557 /* ARMv8 T32 only. */
74db7efb 19558#undef ARM_VARIANT
b79f7053
MGD
19559#define ARM_VARIANT NULL
19560 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19561 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19562 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19563
33399f07
MGD
19564 /* FP for ARMv8. */
19565#undef ARM_VARIANT
a715796b 19566#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19567#undef THUMB_VARIANT
a715796b 19568#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19569
19570 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19571 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19572 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19573 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19574 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19575 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19576 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19577 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19578 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19579 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19580 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19581 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19582 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19583 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19584 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19585 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19586 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19587
91ff7894
MGD
19588 /* Crypto v1 extensions. */
19589#undef ARM_VARIANT
19590#define ARM_VARIANT & fpu_crypto_ext_armv8
19591#undef THUMB_VARIANT
19592#define THUMB_VARIANT & fpu_crypto_ext_armv8
19593
19594 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19595 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19596 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19597 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19598 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19599 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19600 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19601 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19602 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19603 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19604 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19605 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19606 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19607 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19608
dd5181d5 19609#undef ARM_VARIANT
74db7efb 19610#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19611#undef THUMB_VARIANT
19612#define THUMB_VARIANT & crc_ext_armv8
19613 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19614 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19615 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19616 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19617 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19618 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19619
105bde57
MW
19620 /* ARMv8.2 RAS extension. */
19621#undef ARM_VARIANT
19622#define ARM_VARIANT & arm_ext_v8_2
19623#undef THUMB_VARIANT
19624#define THUMB_VARIANT & arm_ext_v8_2
19625 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19626
c921be7d
NC
19627#undef ARM_VARIANT
19628#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19629#undef THUMB_VARIANT
19630#define THUMB_VARIANT NULL
c921be7d 19631
21d799b5
NC
19632 cCE("wfs", e200110, 1, (RR), rd),
19633 cCE("rfs", e300110, 1, (RR), rd),
19634 cCE("wfc", e400110, 1, (RR), rd),
19635 cCE("rfc", e500110, 1, (RR), rd),
19636
19637 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19638 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19639 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19640 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19641
19642 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19643 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19644 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19645 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19646
19647 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19648 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19649 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19650 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19651 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19652 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19653 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19654 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19655 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19656 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19657 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19658 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19659
19660 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19661 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19662 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19663 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19664 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19665 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19666 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19667 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19668 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19669 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19670 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19671 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19672
19673 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19674 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19675 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19676 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19677 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19678 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19679 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19680 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19681 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19682 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19683 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19684 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19685
19686 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19687 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19688 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19689 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19690 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19691 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19692 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19693 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19694 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19695 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19696 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19697 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19698
19699 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19700 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19701 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19702 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19703 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19704 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19705 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19706 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19707 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19708 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19709 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19710 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19711
19712 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19713 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19714 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19715 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19716 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19717 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19718 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19719 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19720 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19721 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19722 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19723 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19724
19725 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19726 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19727 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19728 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19729 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19730 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19731 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19732 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19733 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19734 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19735 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19736 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19737
19738 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19739 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19740 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19741 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19742 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19743 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19744 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19745 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19746 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19747 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19748 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19749 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19750
19751 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19752 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19753 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19754 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19755 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19756 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19757 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19758 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19759 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19760 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19761 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19762 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19763
19764 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19765 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19766 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19767 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19768 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19769 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19770 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19771 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19772 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19773 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19774 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19775 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19776
19777 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19778 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19779 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19780 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19781 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19782 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19783 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19784 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19785 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19786 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19787 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19788 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19789
19790 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19791 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19792 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19793 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19794 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19795 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19796 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19797 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19798 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19799 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19800 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19801 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19802
19803 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19804 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19805 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19806 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19807 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19808 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19809 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19810 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19811 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19812 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19813 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19814 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19815
19816 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19817 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19818 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19819 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19820 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19821 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19822 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19823 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19824 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19825 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19826 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19827 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19828
19829 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19830 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19831 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19832 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19833 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19834 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19835 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19836 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19837 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19838 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19839 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19840 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19841
19842 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19843 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19844 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19845 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19846 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19847 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19848 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19849 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19850 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19851 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19852 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19853 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19854
19855 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19856 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19857 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19858 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19859 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19860 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19861 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19862 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19863 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19864 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19865 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19866 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19867
19868 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19869 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19870 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19871 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19872 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19873 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19874 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19875 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19876 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19877 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19878 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19879 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19880
19881 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19882 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19883 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19884 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19885 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19886 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19887 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19888 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19889 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19890 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19891 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19892 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19893
19894 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19895 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19896 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19897 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19898 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19899 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19900 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19901 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19902 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19903 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19904 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19905 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19906
19907 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19908 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19909 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19910 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19911 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19912 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19913 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19914 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19915 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19916 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19917 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19918 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19919
19920 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19921 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19922 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19923 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19924 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19925 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19926 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19927 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19928 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19929 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19930 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19931 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19932
19933 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19934 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19935 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19936 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19937 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19938 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19939 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19940 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19941 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19942 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19943 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19944 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19945
19946 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19947 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19948 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19949 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19950 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19951 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19952 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19953 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19954 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19955 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19956 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19957 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19958
19959 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19960 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19961 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19962 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19963 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19964 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19965 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19966 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19967 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19968 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19969 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19970 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19971
19972 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19973 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19974 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19975 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19976 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19977 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19978 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19979 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19980 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19981 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19982 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19983 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19984
19985 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19986 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19987 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19988 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19989 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19990 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19991 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19992 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19993 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19994 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19995 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19996 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19997
19998 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19999 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20000 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20001 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20002 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20003 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20004 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20005 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20006 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20007 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20008 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20009 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20010
20011 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20012 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20013 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20014 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20015 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20016 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20017 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20018 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20019 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20020 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20021 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20022 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20023
20024 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20025 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20026 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20027 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20028
20029 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20030 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20031 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20032 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20033 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20034 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20035 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20036 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20037 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20038 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20039 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20040 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20041
c19d1205
ZW
20042 /* The implementation of the FIX instruction is broken on some
20043 assemblers, in that it accepts a precision specifier as well as a
20044 rounding specifier, despite the fact that this is meaningless.
20045 To be more compatible, we accept it as well, though of course it
20046 does not set any bits. */
21d799b5
NC
20047 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20048 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20049 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20050 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20051 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20052 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20053 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20054 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20055 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20056 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20057 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20058 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20059 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20060
c19d1205 20061 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20062#undef ARM_VARIANT
20063#define ARM_VARIANT & fpu_fpa_ext_v2
20064
21d799b5
NC
20065 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20066 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20067 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20068 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20069 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20070 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20071
c921be7d
NC
20072#undef ARM_VARIANT
20073#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20074
c19d1205 20075 /* Moves and type conversions. */
21d799b5
NC
20076 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20077 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20078 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20079 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20080 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20081 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20082 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20083 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20084 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20085 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20086 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20087 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20088 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20089 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20090
20091 /* Memory operations. */
21d799b5
NC
20092 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20093 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20094 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20095 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20096 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20097 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20098 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20099 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20100 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20101 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20102 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20103 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20104 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20105 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20106 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20107 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20108 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20109 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20110
c19d1205 20111 /* Monadic operations. */
21d799b5
NC
20112 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20113 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20114 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20115
20116 /* Dyadic operations. */
21d799b5
NC
20117 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20118 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20119 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20120 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20121 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20122 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20123 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20124 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20125 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20126
c19d1205 20127 /* Comparisons. */
21d799b5
NC
20128 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20129 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20130 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20131 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20132
62f3b8c8
PB
20133 /* Double precision load/store are still present on single precision
20134 implementations. */
20135 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20136 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20137 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20138 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20139 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20140 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20141 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20142 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20143 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20144 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20145
c921be7d
NC
20146#undef ARM_VARIANT
20147#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20148
c19d1205 20149 /* Moves and type conversions. */
21d799b5
NC
20150 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20151 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20152 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20153 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20154 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20155 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20156 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20157 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20158 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20159 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20160 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20161 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20162 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20163
c19d1205 20164 /* Monadic operations. */
21d799b5
NC
20165 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20166 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20167 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20168
20169 /* Dyadic operations. */
21d799b5
NC
20170 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20171 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20172 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20173 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20174 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20175 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20176 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20177 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20178 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20179
c19d1205 20180 /* Comparisons. */
21d799b5
NC
20181 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20182 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20183 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20184 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20185
c921be7d
NC
20186#undef ARM_VARIANT
20187#define ARM_VARIANT & fpu_vfp_ext_v2
20188
21d799b5
NC
20189 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20190 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20191 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20192 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20193
037e8744
JB
20194/* Instructions which may belong to either the Neon or VFP instruction sets.
20195 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20196#undef ARM_VARIANT
20197#define ARM_VARIANT & fpu_vfp_ext_v1xd
20198#undef THUMB_VARIANT
20199#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20200
037e8744
JB
20201 /* These mnemonics are unique to VFP. */
20202 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20203 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20204 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20205 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20206 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20207 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20208 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20209 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20210 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20211 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20212
20213 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20214 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20215 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20216 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20217
21d799b5
NC
20218 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20219 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20220
20221 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20222 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20223
55881a11
MGD
20224 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20225 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20226 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20227 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20228 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20229 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20230 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20231 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20232
5f1af56b 20233 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20234 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20235 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20236 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20237
037e8744
JB
20238
20239 /* NOTE: All VMOV encoding is special-cased! */
20240 NCE(vmov, 0, 1, (VMOV), neon_mov),
20241 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20242
9db2f6b4
RL
20243#undef ARM_VARIANT
20244#define ARM_VARIANT & arm_ext_fp16
20245#undef THUMB_VARIANT
20246#define THUMB_VARIANT & arm_ext_fp16
20247 /* New instructions added from v8.2, allowing the extraction and insertion of
20248 the upper 16 bits of a 32-bit vector register. */
20249 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20250 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20251
c921be7d
NC
20252#undef THUMB_VARIANT
20253#define THUMB_VARIANT & fpu_neon_ext_v1
20254#undef ARM_VARIANT
20255#define ARM_VARIANT & fpu_neon_ext_v1
20256
5287ad62
JB
20257 /* Data processing with three registers of the same length. */
20258 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20259 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20260 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20261 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20262 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20263 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20264 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20265 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20266 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20267 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20268 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20269 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20270 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20271 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20272 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20273 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20274 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20275 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20276 /* If not immediate, fall back to neon_dyadic_i64_su.
20277 shl_imm should accept I8 I16 I32 I64,
20278 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20279 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20280 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20281 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20282 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20283 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20284 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20285 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20286 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20287 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20288 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20289 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20290 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20291 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20292 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20293 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20294 /* Bitfield ops, untyped. */
20295 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20296 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20297 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20298 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20299 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20300 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20301 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
20302 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20303 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20304 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20305 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20306 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20307 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20308 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20309 back to neon_dyadic_if_su. */
21d799b5
NC
20310 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20311 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20312 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20313 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20314 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20315 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20316 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20317 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20318 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20319 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20320 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20321 /* As above, D registers only. */
21d799b5
NC
20322 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20323 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20324 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20325 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20326 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20327 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20328 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20329 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20330 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20331 /* vtst takes sizes 8, 16, 32. */
20332 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20333 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20334 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20335 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20336 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20337 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20338 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20339 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20340 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20341 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20342 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20343 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20344 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20345 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20346 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20347 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20348 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20349 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20350 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20351 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20352 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20353 /* ARM v8.1 extension. */
643afb90
MW
20354 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20355 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20356 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20357 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20358
20359 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20360 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20361 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20362
20363 /* Data processing with two registers and a shift amount. */
20364 /* Right shifts, and variants with rounding.
20365 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20366 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20367 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20368 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20369 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20370 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20371 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20372 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20373 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20374 /* Shift and insert. Sizes accepted 8 16 32 64. */
20375 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20376 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20377 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20378 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20379 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20380 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20381 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20382 /* Right shift immediate, saturating & narrowing, with rounding variants.
20383 Types accepted S16 S32 S64 U16 U32 U64. */
20384 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20385 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20386 /* As above, unsigned. Types accepted S16 S32 S64. */
20387 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20388 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20389 /* Right shift narrowing. Types accepted I16 I32 I64. */
20390 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20391 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20392 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20393 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20394 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20395 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20396
4316f0d2
DG
20397 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20398 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20399
20400 /* Data processing, three registers of different lengths. */
20401 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20402 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20403 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20404 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20405 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20406 /* If not scalar, fall back to neon_dyadic_long.
20407 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20408 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20409 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20410 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20411 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20412 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20413 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20414 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20415 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20416 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20417 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20418 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20419 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20420 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20421 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20422 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20423 S16 S32 U16 U32. */
21d799b5 20424 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20425
20426 /* Extract. Size 8. */
3b8d421e
PB
20427 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20428 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20429
20430 /* Two registers, miscellaneous. */
20431 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20432 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20433 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20434 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20435 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20436 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20437 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20438 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20439 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20440 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20441 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20442 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20443 /* VMOVN. Types I16 I32 I64. */
21d799b5 20444 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20445 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20446 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20447 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20448 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20449 /* VZIP / VUZP. Sizes 8 16 32. */
20450 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20451 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20452 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20453 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20454 /* VQABS / VQNEG. Types S8 S16 S32. */
20455 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20456 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20457 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20458 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20459 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20460 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20461 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20462 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20463 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
20464 /* Reciprocal estimates. Types U32 F32. */
20465 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20466 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20467 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20468 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20469 /* VCLS. Types S8 S16 S32. */
20470 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20471 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20472 /* VCLZ. Types I8 I16 I32. */
20473 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20474 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20475 /* VCNT. Size 8. */
20476 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20477 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20478 /* Two address, untyped. */
20479 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20480 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20481 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20482 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20483 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20484
20485 /* Table lookup. Size 8. */
20486 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20487 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20488
c921be7d
NC
20489#undef THUMB_VARIANT
20490#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20491#undef ARM_VARIANT
20492#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20493
5287ad62 20494 /* Neon element/structure load/store. */
21d799b5
NC
20495 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20496 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20497 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20498 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20499 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20500 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20501 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20502 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20503
c921be7d 20504#undef THUMB_VARIANT
74db7efb
NC
20505#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20506#undef ARM_VARIANT
20507#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20508 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20509 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20510 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20511 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20512 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20513 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20514 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20515 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20516 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20517
74db7efb 20518#undef THUMB_VARIANT
c921be7d
NC
20519#define THUMB_VARIANT & fpu_vfp_ext_v3
20520#undef ARM_VARIANT
20521#define ARM_VARIANT & fpu_vfp_ext_v3
20522
21d799b5 20523 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20524 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20525 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20526 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20527 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20528 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20529 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20530 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20531 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20532
74db7efb
NC
20533#undef ARM_VARIANT
20534#define ARM_VARIANT & fpu_vfp_ext_fma
20535#undef THUMB_VARIANT
20536#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20537 /* Mnemonics shared by Neon and VFP. These are included in the
20538 VFP FMA variant; NEON and VFP FMA always includes the NEON
20539 FMA instructions. */
20540 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20541 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20542 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20543 the v form should always be used. */
20544 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20545 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20546 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20547 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20548 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20549 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20550
5287ad62 20551#undef THUMB_VARIANT
c921be7d
NC
20552#undef ARM_VARIANT
20553#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20554
21d799b5
NC
20555 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20556 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20557 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20558 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20559 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20560 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20561 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20562 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20563
c921be7d
NC
20564#undef ARM_VARIANT
20565#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20566
21d799b5
NC
20567 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20568 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20569 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20570 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20571 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20572 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20573 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20574 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20575 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20576 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20577 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20578 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20579 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20580 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20581 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20582 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20583 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20584 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20585 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20586 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20587 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20588 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20589 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20590 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20591 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20592 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20593 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20594 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20595 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20596 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20597 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20598 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20599 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20600 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20601 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20602 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20603 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20604 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20605 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20606 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20607 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20608 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20609 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20610 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20611 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20612 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20613 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20614 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20615 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20616 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20617 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20618 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20619 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20620 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20621 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20622 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20623 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20624 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20625 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20626 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20627 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20628 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20629 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20630 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20631 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20632 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20633 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20634 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20635 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20636 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20637 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20638 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20639 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20640 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20641 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20642 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20643 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20644 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20645 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20646 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20647 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20648 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20649 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20650 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20651 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20652 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20653 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20654 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20655 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20656 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20657 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20658 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20659 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20660 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20661 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20662 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20663 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20664 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20665 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20666 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20667 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20668 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20669 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20670 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20671 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20672 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20673 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20674 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20675 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20676 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20677 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20678 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20679 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20680 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20681 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20682 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20683 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20684 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20685 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20686 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20687 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20688 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20689 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20690 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20691 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20692 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20693 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20694 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20695 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20696 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20697 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20698 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20699 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20700 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20701 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20702 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20703 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20704 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20705 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20706 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20707 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20708 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20709 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20710 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20711 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20712 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20713 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20714 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20715 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20716 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20717 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20718 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20719 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20720 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20721 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20722 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20723 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20724 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20725 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20726 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20727 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20728 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20729
c921be7d
NC
20730#undef ARM_VARIANT
20731#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20732
21d799b5
NC
20733 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20734 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20735 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20736 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20737 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20738 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20739 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20740 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20741 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20742 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20743 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20744 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20745 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20746 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20747 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20748 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20749 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20750 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20751 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20752 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20753 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20754 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20755 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20756 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20757 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20758 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20759 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20760 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20761 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20762 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20763 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20764 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20765 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20766 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20767 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20768 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20769 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20770 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20771 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20772 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20773 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20774 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20775 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20776 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20777 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20778 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20779 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20780 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20781 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20782 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20783 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20784 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20785 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20786 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20787 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20788 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20789 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20790
c921be7d
NC
20791#undef ARM_VARIANT
20792#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20793
21d799b5
NC
20794 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20795 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20796 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20797 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20798 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20799 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20800 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20801 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20802 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20803 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20804 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20805 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20806 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20807 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20808 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20809 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20810 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20811 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20812 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20813 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20814 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20815 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20816 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20817 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20818 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20819 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20820 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20821 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20822 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20823 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20824 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20825 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20826 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20827 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20828 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20829 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20830 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20831 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20832 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20833 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20834 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20835 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20836 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20837 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20838 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20839 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20840 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20841 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20842 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20843 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20844 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20845 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20846 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20847 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20848 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20849 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20850 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20851 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20852 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20853 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20854 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20855 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20856 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20857 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20858 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20859 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20860 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20861 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20862 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20863 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20864 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20865 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20866 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20867 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20868 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20869 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d
TP
20870
20871#undef ARM_VARIANT
20872#define ARM_VARIANT NULL
20873#undef THUMB_VARIANT
20874#define THUMB_VARIANT & arm_ext_v8m
20875 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
20876 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
c19d1205
ZW
20877};
20878#undef ARM_VARIANT
20879#undef THUMB_VARIANT
20880#undef TCE
c19d1205
ZW
20881#undef TUE
20882#undef TUF
20883#undef TCC
8f06b2d8 20884#undef cCE
e3cb604e
PB
20885#undef cCL
20886#undef C3E
c19d1205
ZW
20887#undef CE
20888#undef CM
20889#undef UE
20890#undef UF
20891#undef UT
5287ad62
JB
20892#undef NUF
20893#undef nUF
20894#undef NCE
20895#undef nCE
c19d1205
ZW
20896#undef OPS0
20897#undef OPS1
20898#undef OPS2
20899#undef OPS3
20900#undef OPS4
20901#undef OPS5
20902#undef OPS6
20903#undef do_0
20904\f
20905/* MD interface: bits in the object file. */
bfae80f2 20906
c19d1205
ZW
20907/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20908 for use in the a.out file, and stores them in the array pointed to by buf.
20909 This knows about the endian-ness of the target machine and does
20910 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20911 2 (short) and 4 (long) Floating numbers are put out as a series of
20912 LITTLENUMS (shorts, here at least). */
b99bd4ef 20913
c19d1205
ZW
20914void
20915md_number_to_chars (char * buf, valueT val, int n)
20916{
20917 if (target_big_endian)
20918 number_to_chars_bigendian (buf, val, n);
20919 else
20920 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20921}
20922
c19d1205
ZW
20923static valueT
20924md_chars_to_number (char * buf, int n)
bfae80f2 20925{
c19d1205
ZW
20926 valueT result = 0;
20927 unsigned char * where = (unsigned char *) buf;
bfae80f2 20928
c19d1205 20929 if (target_big_endian)
b99bd4ef 20930 {
c19d1205
ZW
20931 while (n--)
20932 {
20933 result <<= 8;
20934 result |= (*where++ & 255);
20935 }
b99bd4ef 20936 }
c19d1205 20937 else
b99bd4ef 20938 {
c19d1205
ZW
20939 while (n--)
20940 {
20941 result <<= 8;
20942 result |= (where[n] & 255);
20943 }
bfae80f2 20944 }
b99bd4ef 20945
c19d1205 20946 return result;
bfae80f2 20947}
b99bd4ef 20948
c19d1205 20949/* MD interface: Sections. */
b99bd4ef 20950
fa94de6b
RM
20951/* Calculate the maximum variable size (i.e., excluding fr_fix)
20952 that an rs_machine_dependent frag may reach. */
20953
20954unsigned int
20955arm_frag_max_var (fragS *fragp)
20956{
20957 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20958 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20959
20960 Note that we generate relaxable instructions even for cases that don't
20961 really need it, like an immediate that's a trivial constant. So we're
20962 overestimating the instruction size for some of those cases. Rather
20963 than putting more intelligence here, it would probably be better to
20964 avoid generating a relaxation frag in the first place when it can be
20965 determined up front that a short instruction will suffice. */
20966
20967 gas_assert (fragp->fr_type == rs_machine_dependent);
20968 return INSN_SIZE;
20969}
20970
0110f2b8
PB
20971/* Estimate the size of a frag before relaxing. Assume everything fits in
20972 2 bytes. */
20973
c19d1205 20974int
0110f2b8 20975md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20976 segT segtype ATTRIBUTE_UNUSED)
20977{
0110f2b8
PB
20978 fragp->fr_var = 2;
20979 return 2;
20980}
20981
20982/* Convert a machine dependent frag. */
20983
20984void
20985md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20986{
20987 unsigned long insn;
20988 unsigned long old_op;
20989 char *buf;
20990 expressionS exp;
20991 fixS *fixp;
20992 int reloc_type;
20993 int pc_rel;
20994 int opcode;
20995
20996 buf = fragp->fr_literal + fragp->fr_fix;
20997
20998 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20999 if (fragp->fr_symbol)
21000 {
0110f2b8
PB
21001 exp.X_op = O_symbol;
21002 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21003 }
21004 else
21005 {
0110f2b8 21006 exp.X_op = O_constant;
5f4273c7 21007 }
0110f2b8
PB
21008 exp.X_add_number = fragp->fr_offset;
21009 opcode = fragp->fr_subtype;
21010 switch (opcode)
21011 {
21012 case T_MNEM_ldr_pc:
21013 case T_MNEM_ldr_pc2:
21014 case T_MNEM_ldr_sp:
21015 case T_MNEM_str_sp:
21016 case T_MNEM_ldr:
21017 case T_MNEM_ldrb:
21018 case T_MNEM_ldrh:
21019 case T_MNEM_str:
21020 case T_MNEM_strb:
21021 case T_MNEM_strh:
21022 if (fragp->fr_var == 4)
21023 {
5f4273c7 21024 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21025 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21026 {
21027 insn |= (old_op & 0x700) << 4;
21028 }
21029 else
21030 {
21031 insn |= (old_op & 7) << 12;
21032 insn |= (old_op & 0x38) << 13;
21033 }
21034 insn |= 0x00000c00;
21035 put_thumb32_insn (buf, insn);
21036 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21037 }
21038 else
21039 {
21040 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21041 }
21042 pc_rel = (opcode == T_MNEM_ldr_pc2);
21043 break;
21044 case T_MNEM_adr:
21045 if (fragp->fr_var == 4)
21046 {
21047 insn = THUMB_OP32 (opcode);
21048 insn |= (old_op & 0xf0) << 4;
21049 put_thumb32_insn (buf, insn);
21050 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21051 }
21052 else
21053 {
21054 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21055 exp.X_add_number -= 4;
21056 }
21057 pc_rel = 1;
21058 break;
21059 case T_MNEM_mov:
21060 case T_MNEM_movs:
21061 case T_MNEM_cmp:
21062 case T_MNEM_cmn:
21063 if (fragp->fr_var == 4)
21064 {
21065 int r0off = (opcode == T_MNEM_mov
21066 || opcode == T_MNEM_movs) ? 0 : 8;
21067 insn = THUMB_OP32 (opcode);
21068 insn = (insn & 0xe1ffffff) | 0x10000000;
21069 insn |= (old_op & 0x700) << r0off;
21070 put_thumb32_insn (buf, insn);
21071 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21072 }
21073 else
21074 {
21075 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21076 }
21077 pc_rel = 0;
21078 break;
21079 case T_MNEM_b:
21080 if (fragp->fr_var == 4)
21081 {
21082 insn = THUMB_OP32(opcode);
21083 put_thumb32_insn (buf, insn);
21084 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21085 }
21086 else
21087 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21088 pc_rel = 1;
21089 break;
21090 case T_MNEM_bcond:
21091 if (fragp->fr_var == 4)
21092 {
21093 insn = THUMB_OP32(opcode);
21094 insn |= (old_op & 0xf00) << 14;
21095 put_thumb32_insn (buf, insn);
21096 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21097 }
21098 else
21099 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21100 pc_rel = 1;
21101 break;
21102 case T_MNEM_add_sp:
21103 case T_MNEM_add_pc:
21104 case T_MNEM_inc_sp:
21105 case T_MNEM_dec_sp:
21106 if (fragp->fr_var == 4)
21107 {
21108 /* ??? Choose between add and addw. */
21109 insn = THUMB_OP32 (opcode);
21110 insn |= (old_op & 0xf0) << 4;
21111 put_thumb32_insn (buf, insn);
16805f35
PB
21112 if (opcode == T_MNEM_add_pc)
21113 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21114 else
21115 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21116 }
21117 else
21118 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21119 pc_rel = 0;
21120 break;
21121
21122 case T_MNEM_addi:
21123 case T_MNEM_addis:
21124 case T_MNEM_subi:
21125 case T_MNEM_subis:
21126 if (fragp->fr_var == 4)
21127 {
21128 insn = THUMB_OP32 (opcode);
21129 insn |= (old_op & 0xf0) << 4;
21130 insn |= (old_op & 0xf) << 16;
21131 put_thumb32_insn (buf, insn);
16805f35
PB
21132 if (insn & (1 << 20))
21133 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21134 else
21135 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21136 }
21137 else
21138 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21139 pc_rel = 0;
21140 break;
21141 default:
5f4273c7 21142 abort ();
0110f2b8
PB
21143 }
21144 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21145 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21146 fixp->fx_file = fragp->fr_file;
21147 fixp->fx_line = fragp->fr_line;
21148 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21149
21150 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21151 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21152 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21153 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21154}
21155
21156/* Return the size of a relaxable immediate operand instruction.
21157 SHIFT and SIZE specify the form of the allowable immediate. */
21158static int
21159relax_immediate (fragS *fragp, int size, int shift)
21160{
21161 offsetT offset;
21162 offsetT mask;
21163 offsetT low;
21164
21165 /* ??? Should be able to do better than this. */
21166 if (fragp->fr_symbol)
21167 return 4;
21168
21169 low = (1 << shift) - 1;
21170 mask = (1 << (shift + size)) - (1 << shift);
21171 offset = fragp->fr_offset;
21172 /* Force misaligned offsets to 32-bit variant. */
21173 if (offset & low)
5e77afaa 21174 return 4;
0110f2b8
PB
21175 if (offset & ~mask)
21176 return 4;
21177 return 2;
21178}
21179
5e77afaa
PB
21180/* Get the address of a symbol during relaxation. */
21181static addressT
5f4273c7 21182relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21183{
21184 fragS *sym_frag;
21185 addressT addr;
21186 symbolS *sym;
21187
21188 sym = fragp->fr_symbol;
21189 sym_frag = symbol_get_frag (sym);
21190 know (S_GET_SEGMENT (sym) != absolute_section
21191 || sym_frag == &zero_address_frag);
21192 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21193
21194 /* If frag has yet to be reached on this pass, assume it will
21195 move by STRETCH just as we did. If this is not so, it will
21196 be because some frag between grows, and that will force
21197 another pass. */
21198
21199 if (stretch != 0
21200 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21201 {
21202 fragS *f;
21203
21204 /* Adjust stretch for any alignment frag. Note that if have
21205 been expanding the earlier code, the symbol may be
21206 defined in what appears to be an earlier frag. FIXME:
21207 This doesn't handle the fr_subtype field, which specifies
21208 a maximum number of bytes to skip when doing an
21209 alignment. */
21210 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21211 {
21212 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21213 {
21214 if (stretch < 0)
21215 stretch = - ((- stretch)
21216 & ~ ((1 << (int) f->fr_offset) - 1));
21217 else
21218 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21219 if (stretch == 0)
21220 break;
21221 }
21222 }
21223 if (f != NULL)
21224 addr += stretch;
21225 }
5e77afaa
PB
21226
21227 return addr;
21228}
21229
0110f2b8
PB
21230/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21231 load. */
21232static int
5e77afaa 21233relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21234{
21235 addressT addr;
21236 offsetT val;
21237
21238 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21239 if (fragp->fr_symbol == NULL
21240 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21241 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21242 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21243 return 4;
21244
5f4273c7 21245 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21246 addr = fragp->fr_address + fragp->fr_fix;
21247 addr = (addr + 4) & ~3;
5e77afaa 21248 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21249 if (val & 3)
5e77afaa 21250 return 4;
0110f2b8
PB
21251 val -= addr;
21252 if (val < 0 || val > 1020)
21253 return 4;
21254 return 2;
21255}
21256
21257/* Return the size of a relaxable add/sub immediate instruction. */
21258static int
21259relax_addsub (fragS *fragp, asection *sec)
21260{
21261 char *buf;
21262 int op;
21263
21264 buf = fragp->fr_literal + fragp->fr_fix;
21265 op = bfd_get_16(sec->owner, buf);
21266 if ((op & 0xf) == ((op >> 4) & 0xf))
21267 return relax_immediate (fragp, 8, 0);
21268 else
21269 return relax_immediate (fragp, 3, 0);
21270}
21271
e83a675f
RE
21272/* Return TRUE iff the definition of symbol S could be pre-empted
21273 (overridden) at link or load time. */
21274static bfd_boolean
21275symbol_preemptible (symbolS *s)
21276{
21277 /* Weak symbols can always be pre-empted. */
21278 if (S_IS_WEAK (s))
21279 return TRUE;
21280
21281 /* Non-global symbols cannot be pre-empted. */
21282 if (! S_IS_EXTERNAL (s))
21283 return FALSE;
21284
21285#ifdef OBJ_ELF
21286 /* In ELF, a global symbol can be marked protected, or private. In that
21287 case it can't be pre-empted (other definitions in the same link unit
21288 would violate the ODR). */
21289 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21290 return FALSE;
21291#endif
21292
21293 /* Other global symbols might be pre-empted. */
21294 return TRUE;
21295}
0110f2b8
PB
21296
21297/* Return the size of a relaxable branch instruction. BITS is the
21298 size of the offset field in the narrow instruction. */
21299
21300static int
5e77afaa 21301relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21302{
21303 addressT addr;
21304 offsetT val;
21305 offsetT limit;
21306
21307 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21308 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21309 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21310 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21311 return 4;
21312
267bf995 21313#ifdef OBJ_ELF
e83a675f 21314 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21315 if (S_IS_DEFINED (fragp->fr_symbol)
21316 && ARM_IS_FUNC (fragp->fr_symbol))
21317 return 4;
e83a675f 21318#endif
0d9b4b55 21319
e83a675f 21320 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21321 return 4;
267bf995 21322
5f4273c7 21323 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21324 addr = fragp->fr_address + fragp->fr_fix + 4;
21325 val -= addr;
21326
21327 /* Offset is a signed value *2 */
21328 limit = 1 << bits;
21329 if (val >= limit || val < -limit)
21330 return 4;
21331 return 2;
21332}
21333
21334
21335/* Relax a machine dependent frag. This returns the amount by which
21336 the current size of the frag should change. */
21337
21338int
5e77afaa 21339arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21340{
21341 int oldsize;
21342 int newsize;
21343
21344 oldsize = fragp->fr_var;
21345 switch (fragp->fr_subtype)
21346 {
21347 case T_MNEM_ldr_pc2:
5f4273c7 21348 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21349 break;
21350 case T_MNEM_ldr_pc:
21351 case T_MNEM_ldr_sp:
21352 case T_MNEM_str_sp:
5f4273c7 21353 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21354 break;
21355 case T_MNEM_ldr:
21356 case T_MNEM_str:
5f4273c7 21357 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21358 break;
21359 case T_MNEM_ldrh:
21360 case T_MNEM_strh:
5f4273c7 21361 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21362 break;
21363 case T_MNEM_ldrb:
21364 case T_MNEM_strb:
5f4273c7 21365 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21366 break;
21367 case T_MNEM_adr:
5f4273c7 21368 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21369 break;
21370 case T_MNEM_mov:
21371 case T_MNEM_movs:
21372 case T_MNEM_cmp:
21373 case T_MNEM_cmn:
5f4273c7 21374 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21375 break;
21376 case T_MNEM_b:
5f4273c7 21377 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21378 break;
21379 case T_MNEM_bcond:
5f4273c7 21380 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21381 break;
21382 case T_MNEM_add_sp:
21383 case T_MNEM_add_pc:
21384 newsize = relax_immediate (fragp, 8, 2);
21385 break;
21386 case T_MNEM_inc_sp:
21387 case T_MNEM_dec_sp:
21388 newsize = relax_immediate (fragp, 7, 2);
21389 break;
21390 case T_MNEM_addi:
21391 case T_MNEM_addis:
21392 case T_MNEM_subi:
21393 case T_MNEM_subis:
21394 newsize = relax_addsub (fragp, sec);
21395 break;
21396 default:
5f4273c7 21397 abort ();
0110f2b8 21398 }
5e77afaa
PB
21399
21400 fragp->fr_var = newsize;
21401 /* Freeze wide instructions that are at or before the same location as
21402 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21403 Don't freeze them unconditionally because targets may be artificially
21404 misaligned by the expansion of preceding frags. */
5e77afaa 21405 if (stretch <= 0 && newsize > 2)
0110f2b8 21406 {
0110f2b8 21407 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21408 frag_wane (fragp);
0110f2b8 21409 }
5e77afaa 21410
0110f2b8 21411 return newsize - oldsize;
c19d1205 21412}
b99bd4ef 21413
c19d1205 21414/* Round up a section size to the appropriate boundary. */
b99bd4ef 21415
c19d1205
ZW
21416valueT
21417md_section_align (segT segment ATTRIBUTE_UNUSED,
21418 valueT size)
21419{
f0927246
NC
21420#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21421 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21422 {
21423 /* For a.out, force the section size to be aligned. If we don't do
21424 this, BFD will align it for us, but it will not write out the
21425 final bytes of the section. This may be a bug in BFD, but it is
21426 easier to fix it here since that is how the other a.out targets
21427 work. */
21428 int align;
21429
21430 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21431 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21432 }
c19d1205 21433#endif
f0927246
NC
21434
21435 return size;
bfae80f2 21436}
b99bd4ef 21437
c19d1205
ZW
21438/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21439 of an rs_align_code fragment. */
21440
21441void
21442arm_handle_align (fragS * fragP)
bfae80f2 21443{
e7495e45
NS
21444 static char const arm_noop[2][2][4] =
21445 {
21446 { /* ARMv1 */
21447 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21448 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21449 },
21450 { /* ARMv6k */
21451 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21452 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21453 },
21454 };
21455 static char const thumb_noop[2][2][2] =
21456 {
21457 { /* Thumb-1 */
21458 {0xc0, 0x46}, /* LE */
21459 {0x46, 0xc0}, /* BE */
21460 },
21461 { /* Thumb-2 */
21462 {0x00, 0xbf}, /* LE */
21463 {0xbf, 0x00} /* BE */
21464 }
21465 };
21466 static char const wide_thumb_noop[2][4] =
21467 { /* Wide Thumb-2 */
21468 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21469 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21470 };
c921be7d 21471
e7495e45 21472 unsigned bytes, fix, noop_size;
c19d1205
ZW
21473 char * p;
21474 const char * noop;
e7495e45 21475 const char *narrow_noop = NULL;
cd000bff
DJ
21476#ifdef OBJ_ELF
21477 enum mstate state;
21478#endif
bfae80f2 21479
c19d1205 21480 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21481 return;
21482
c19d1205
ZW
21483 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21484 p = fragP->fr_literal + fragP->fr_fix;
21485 fix = 0;
bfae80f2 21486
c19d1205
ZW
21487 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21488 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21489
cd000bff 21490 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21491
cd000bff 21492 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21493 {
7f78eb34
JW
21494 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21495 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21496 {
21497 narrow_noop = thumb_noop[1][target_big_endian];
21498 noop = wide_thumb_noop[target_big_endian];
21499 }
c19d1205 21500 else
e7495e45
NS
21501 noop = thumb_noop[0][target_big_endian];
21502 noop_size = 2;
cd000bff
DJ
21503#ifdef OBJ_ELF
21504 state = MAP_THUMB;
21505#endif
7ed4c4c5
NC
21506 }
21507 else
21508 {
7f78eb34
JW
21509 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21510 ? selected_cpu : arm_arch_none,
21511 arm_ext_v6k) != 0]
e7495e45
NS
21512 [target_big_endian];
21513 noop_size = 4;
cd000bff
DJ
21514#ifdef OBJ_ELF
21515 state = MAP_ARM;
21516#endif
7ed4c4c5 21517 }
c921be7d 21518
e7495e45 21519 fragP->fr_var = noop_size;
c921be7d 21520
c19d1205 21521 if (bytes & (noop_size - 1))
7ed4c4c5 21522 {
c19d1205 21523 fix = bytes & (noop_size - 1);
cd000bff
DJ
21524#ifdef OBJ_ELF
21525 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21526#endif
c19d1205
ZW
21527 memset (p, 0, fix);
21528 p += fix;
21529 bytes -= fix;
a737bd4d 21530 }
a737bd4d 21531
e7495e45
NS
21532 if (narrow_noop)
21533 {
21534 if (bytes & noop_size)
21535 {
21536 /* Insert a narrow noop. */
21537 memcpy (p, narrow_noop, noop_size);
21538 p += noop_size;
21539 bytes -= noop_size;
21540 fix += noop_size;
21541 }
21542
21543 /* Use wide noops for the remainder */
21544 noop_size = 4;
21545 }
21546
c19d1205 21547 while (bytes >= noop_size)
a737bd4d 21548 {
c19d1205
ZW
21549 memcpy (p, noop, noop_size);
21550 p += noop_size;
21551 bytes -= noop_size;
21552 fix += noop_size;
a737bd4d
NC
21553 }
21554
c19d1205 21555 fragP->fr_fix += fix;
a737bd4d
NC
21556}
21557
c19d1205
ZW
21558/* Called from md_do_align. Used to create an alignment
21559 frag in a code section. */
21560
21561void
21562arm_frag_align_code (int n, int max)
bfae80f2 21563{
c19d1205 21564 char * p;
7ed4c4c5 21565
c19d1205 21566 /* We assume that there will never be a requirement
6ec8e702 21567 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21568 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21569 {
21570 char err_msg[128];
21571
fa94de6b 21572 sprintf (err_msg,
477330fc
RM
21573 _("alignments greater than %d bytes not supported in .text sections."),
21574 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21575 as_fatal ("%s", err_msg);
6ec8e702 21576 }
bfae80f2 21577
c19d1205
ZW
21578 p = frag_var (rs_align_code,
21579 MAX_MEM_FOR_RS_ALIGN_CODE,
21580 1,
21581 (relax_substateT) max,
21582 (symbolS *) NULL,
21583 (offsetT) n,
21584 (char *) NULL);
21585 *p = 0;
21586}
bfae80f2 21587
8dc2430f
NC
21588/* Perform target specific initialisation of a frag.
21589 Note - despite the name this initialisation is not done when the frag
21590 is created, but only when its type is assigned. A frag can be created
21591 and used a long time before its type is set, so beware of assuming that
21592 this initialisationis performed first. */
bfae80f2 21593
cd000bff
DJ
21594#ifndef OBJ_ELF
21595void
21596arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21597{
21598 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21599 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21600}
21601
21602#else /* OBJ_ELF is defined. */
c19d1205 21603void
cd000bff 21604arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21605{
b968d18a
JW
21606 int frag_thumb_mode;
21607
8dc2430f
NC
21608 /* If the current ARM vs THUMB mode has not already
21609 been recorded into this frag then do so now. */
cd000bff 21610 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21611 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21612
21613 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21614
f9c1b181
RL
21615 /* Record a mapping symbol for alignment frags. We will delete this
21616 later if the alignment ends up empty. */
21617 switch (fragP->fr_type)
21618 {
21619 case rs_align:
21620 case rs_align_test:
21621 case rs_fill:
21622 mapping_state_2 (MAP_DATA, max_chars);
21623 break;
21624 case rs_align_code:
b968d18a 21625 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21626 break;
21627 default:
21628 break;
cd000bff 21629 }
bfae80f2
RE
21630}
21631
c19d1205
ZW
21632/* When we change sections we need to issue a new mapping symbol. */
21633
21634void
21635arm_elf_change_section (void)
bfae80f2 21636{
c19d1205
ZW
21637 /* Link an unlinked unwind index table section to the .text section. */
21638 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21639 && elf_linked_to_section (now_seg) == NULL)
21640 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21641}
21642
c19d1205
ZW
21643int
21644arm_elf_section_type (const char * str, size_t len)
e45d0630 21645{
c19d1205
ZW
21646 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21647 return SHT_ARM_EXIDX;
e45d0630 21648
c19d1205
ZW
21649 return -1;
21650}
21651\f
21652/* Code to deal with unwinding tables. */
e45d0630 21653
c19d1205 21654static void add_unwind_adjustsp (offsetT);
e45d0630 21655
5f4273c7 21656/* Generate any deferred unwind frame offset. */
e45d0630 21657
bfae80f2 21658static void
c19d1205 21659flush_pending_unwind (void)
bfae80f2 21660{
c19d1205 21661 offsetT offset;
bfae80f2 21662
c19d1205
ZW
21663 offset = unwind.pending_offset;
21664 unwind.pending_offset = 0;
21665 if (offset != 0)
21666 add_unwind_adjustsp (offset);
bfae80f2
RE
21667}
21668
c19d1205
ZW
21669/* Add an opcode to this list for this function. Two-byte opcodes should
21670 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21671 order. */
21672
bfae80f2 21673static void
c19d1205 21674add_unwind_opcode (valueT op, int length)
bfae80f2 21675{
c19d1205
ZW
21676 /* Add any deferred stack adjustment. */
21677 if (unwind.pending_offset)
21678 flush_pending_unwind ();
bfae80f2 21679
c19d1205 21680 unwind.sp_restored = 0;
bfae80f2 21681
c19d1205 21682 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21683 {
c19d1205
ZW
21684 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21685 if (unwind.opcodes)
21d799b5 21686 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 21687 unwind.opcode_alloc);
c19d1205 21688 else
21d799b5 21689 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 21690 }
c19d1205 21691 while (length > 0)
bfae80f2 21692 {
c19d1205
ZW
21693 length--;
21694 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21695 op >>= 8;
21696 unwind.opcode_count++;
bfae80f2 21697 }
bfae80f2
RE
21698}
21699
c19d1205
ZW
21700/* Add unwind opcodes to adjust the stack pointer. */
21701
bfae80f2 21702static void
c19d1205 21703add_unwind_adjustsp (offsetT offset)
bfae80f2 21704{
c19d1205 21705 valueT op;
bfae80f2 21706
c19d1205 21707 if (offset > 0x200)
bfae80f2 21708 {
c19d1205
ZW
21709 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21710 char bytes[5];
21711 int n;
21712 valueT o;
bfae80f2 21713
c19d1205
ZW
21714 /* Long form: 0xb2, uleb128. */
21715 /* This might not fit in a word so add the individual bytes,
21716 remembering the list is built in reverse order. */
21717 o = (valueT) ((offset - 0x204) >> 2);
21718 if (o == 0)
21719 add_unwind_opcode (0, 1);
bfae80f2 21720
c19d1205
ZW
21721 /* Calculate the uleb128 encoding of the offset. */
21722 n = 0;
21723 while (o)
21724 {
21725 bytes[n] = o & 0x7f;
21726 o >>= 7;
21727 if (o)
21728 bytes[n] |= 0x80;
21729 n++;
21730 }
21731 /* Add the insn. */
21732 for (; n; n--)
21733 add_unwind_opcode (bytes[n - 1], 1);
21734 add_unwind_opcode (0xb2, 1);
21735 }
21736 else if (offset > 0x100)
bfae80f2 21737 {
c19d1205
ZW
21738 /* Two short opcodes. */
21739 add_unwind_opcode (0x3f, 1);
21740 op = (offset - 0x104) >> 2;
21741 add_unwind_opcode (op, 1);
bfae80f2 21742 }
c19d1205
ZW
21743 else if (offset > 0)
21744 {
21745 /* Short opcode. */
21746 op = (offset - 4) >> 2;
21747 add_unwind_opcode (op, 1);
21748 }
21749 else if (offset < 0)
bfae80f2 21750 {
c19d1205
ZW
21751 offset = -offset;
21752 while (offset > 0x100)
bfae80f2 21753 {
c19d1205
ZW
21754 add_unwind_opcode (0x7f, 1);
21755 offset -= 0x100;
bfae80f2 21756 }
c19d1205
ZW
21757 op = ((offset - 4) >> 2) | 0x40;
21758 add_unwind_opcode (op, 1);
bfae80f2 21759 }
bfae80f2
RE
21760}
21761
c19d1205
ZW
21762/* Finish the list of unwind opcodes for this function. */
21763static void
21764finish_unwind_opcodes (void)
bfae80f2 21765{
c19d1205 21766 valueT op;
bfae80f2 21767
c19d1205 21768 if (unwind.fp_used)
bfae80f2 21769 {
708587a4 21770 /* Adjust sp as necessary. */
c19d1205
ZW
21771 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21772 flush_pending_unwind ();
bfae80f2 21773
c19d1205
ZW
21774 /* After restoring sp from the frame pointer. */
21775 op = 0x90 | unwind.fp_reg;
21776 add_unwind_opcode (op, 1);
21777 }
21778 else
21779 flush_pending_unwind ();
bfae80f2
RE
21780}
21781
bfae80f2 21782
c19d1205
ZW
21783/* Start an exception table entry. If idx is nonzero this is an index table
21784 entry. */
bfae80f2
RE
21785
21786static void
c19d1205 21787start_unwind_section (const segT text_seg, int idx)
bfae80f2 21788{
c19d1205
ZW
21789 const char * text_name;
21790 const char * prefix;
21791 const char * prefix_once;
21792 const char * group_name;
21793 size_t prefix_len;
21794 size_t text_len;
21795 char * sec_name;
21796 size_t sec_name_len;
21797 int type;
21798 int flags;
21799 int linkonce;
bfae80f2 21800
c19d1205 21801 if (idx)
bfae80f2 21802 {
c19d1205
ZW
21803 prefix = ELF_STRING_ARM_unwind;
21804 prefix_once = ELF_STRING_ARM_unwind_once;
21805 type = SHT_ARM_EXIDX;
bfae80f2 21806 }
c19d1205 21807 else
bfae80f2 21808 {
c19d1205
ZW
21809 prefix = ELF_STRING_ARM_unwind_info;
21810 prefix_once = ELF_STRING_ARM_unwind_info_once;
21811 type = SHT_PROGBITS;
bfae80f2
RE
21812 }
21813
c19d1205
ZW
21814 text_name = segment_name (text_seg);
21815 if (streq (text_name, ".text"))
21816 text_name = "";
21817
21818 if (strncmp (text_name, ".gnu.linkonce.t.",
21819 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21820 {
c19d1205
ZW
21821 prefix = prefix_once;
21822 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21823 }
21824
c19d1205
ZW
21825 prefix_len = strlen (prefix);
21826 text_len = strlen (text_name);
21827 sec_name_len = prefix_len + text_len;
21d799b5 21828 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21829 memcpy (sec_name, prefix, prefix_len);
21830 memcpy (sec_name + prefix_len, text_name, text_len);
21831 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21832
c19d1205
ZW
21833 flags = SHF_ALLOC;
21834 linkonce = 0;
21835 group_name = 0;
bfae80f2 21836
c19d1205
ZW
21837 /* Handle COMDAT group. */
21838 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21839 {
c19d1205
ZW
21840 group_name = elf_group_name (text_seg);
21841 if (group_name == NULL)
21842 {
bd3ba5d1 21843 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21844 segment_name (text_seg));
21845 ignore_rest_of_line ();
21846 return;
21847 }
21848 flags |= SHF_GROUP;
21849 linkonce = 1;
bfae80f2
RE
21850 }
21851
c19d1205 21852 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21853
5f4273c7 21854 /* Set the section link for index tables. */
c19d1205
ZW
21855 if (idx)
21856 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21857}
21858
bfae80f2 21859
c19d1205
ZW
21860/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21861 personality routine data. Returns zero, or the index table value for
cad0da33 21862 an inline entry. */
c19d1205
ZW
21863
21864static valueT
21865create_unwind_entry (int have_data)
bfae80f2 21866{
c19d1205
ZW
21867 int size;
21868 addressT where;
21869 char *ptr;
21870 /* The current word of data. */
21871 valueT data;
21872 /* The number of bytes left in this word. */
21873 int n;
bfae80f2 21874
c19d1205 21875 finish_unwind_opcodes ();
bfae80f2 21876
c19d1205
ZW
21877 /* Remember the current text section. */
21878 unwind.saved_seg = now_seg;
21879 unwind.saved_subseg = now_subseg;
bfae80f2 21880
c19d1205 21881 start_unwind_section (now_seg, 0);
bfae80f2 21882
c19d1205 21883 if (unwind.personality_routine == NULL)
bfae80f2 21884 {
c19d1205
ZW
21885 if (unwind.personality_index == -2)
21886 {
21887 if (have_data)
5f4273c7 21888 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21889 return 1; /* EXIDX_CANTUNWIND. */
21890 }
bfae80f2 21891
c19d1205
ZW
21892 /* Use a default personality routine if none is specified. */
21893 if (unwind.personality_index == -1)
21894 {
21895 if (unwind.opcode_count > 3)
21896 unwind.personality_index = 1;
21897 else
21898 unwind.personality_index = 0;
21899 }
bfae80f2 21900
c19d1205
ZW
21901 /* Space for the personality routine entry. */
21902 if (unwind.personality_index == 0)
21903 {
21904 if (unwind.opcode_count > 3)
21905 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21906
c19d1205
ZW
21907 if (!have_data)
21908 {
21909 /* All the data is inline in the index table. */
21910 data = 0x80;
21911 n = 3;
21912 while (unwind.opcode_count > 0)
21913 {
21914 unwind.opcode_count--;
21915 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21916 n--;
21917 }
bfae80f2 21918
c19d1205
ZW
21919 /* Pad with "finish" opcodes. */
21920 while (n--)
21921 data = (data << 8) | 0xb0;
bfae80f2 21922
c19d1205
ZW
21923 return data;
21924 }
21925 size = 0;
21926 }
21927 else
21928 /* We get two opcodes "free" in the first word. */
21929 size = unwind.opcode_count - 2;
21930 }
21931 else
5011093d 21932 {
cad0da33
NC
21933 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21934 if (unwind.personality_index != -1)
21935 {
21936 as_bad (_("attempt to recreate an unwind entry"));
21937 return 1;
21938 }
5011093d
NC
21939
21940 /* An extra byte is required for the opcode count. */
21941 size = unwind.opcode_count + 1;
21942 }
bfae80f2 21943
c19d1205
ZW
21944 size = (size + 3) >> 2;
21945 if (size > 0xff)
21946 as_bad (_("too many unwind opcodes"));
bfae80f2 21947
c19d1205
ZW
21948 frag_align (2, 0, 0);
21949 record_alignment (now_seg, 2);
21950 unwind.table_entry = expr_build_dot ();
21951
21952 /* Allocate the table entry. */
21953 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21954 /* PR 13449: Zero the table entries in case some of them are not used. */
21955 memset (ptr, 0, (size << 2) + 4);
c19d1205 21956 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21957
c19d1205 21958 switch (unwind.personality_index)
bfae80f2 21959 {
c19d1205
ZW
21960 case -1:
21961 /* ??? Should this be a PLT generating relocation? */
21962 /* Custom personality routine. */
21963 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21964 BFD_RELOC_ARM_PREL31);
bfae80f2 21965
c19d1205
ZW
21966 where += 4;
21967 ptr += 4;
bfae80f2 21968
c19d1205 21969 /* Set the first byte to the number of additional words. */
5011093d 21970 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21971 n = 3;
21972 break;
bfae80f2 21973
c19d1205
ZW
21974 /* ABI defined personality routines. */
21975 case 0:
21976 /* Three opcodes bytes are packed into the first word. */
21977 data = 0x80;
21978 n = 3;
21979 break;
bfae80f2 21980
c19d1205
ZW
21981 case 1:
21982 case 2:
21983 /* The size and first two opcode bytes go in the first word. */
21984 data = ((0x80 + unwind.personality_index) << 8) | size;
21985 n = 2;
21986 break;
bfae80f2 21987
c19d1205
ZW
21988 default:
21989 /* Should never happen. */
21990 abort ();
21991 }
bfae80f2 21992
c19d1205
ZW
21993 /* Pack the opcodes into words (MSB first), reversing the list at the same
21994 time. */
21995 while (unwind.opcode_count > 0)
21996 {
21997 if (n == 0)
21998 {
21999 md_number_to_chars (ptr, data, 4);
22000 ptr += 4;
22001 n = 4;
22002 data = 0;
22003 }
22004 unwind.opcode_count--;
22005 n--;
22006 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22007 }
22008
22009 /* Finish off the last word. */
22010 if (n < 4)
22011 {
22012 /* Pad with "finish" opcodes. */
22013 while (n--)
22014 data = (data << 8) | 0xb0;
22015
22016 md_number_to_chars (ptr, data, 4);
22017 }
22018
22019 if (!have_data)
22020 {
22021 /* Add an empty descriptor if there is no user-specified data. */
22022 ptr = frag_more (4);
22023 md_number_to_chars (ptr, 0, 4);
22024 }
22025
22026 return 0;
bfae80f2
RE
22027}
22028
f0927246
NC
22029
22030/* Initialize the DWARF-2 unwind information for this procedure. */
22031
22032void
22033tc_arm_frame_initial_instructions (void)
22034{
22035 cfi_add_CFA_def_cfa (REG_SP, 0);
22036}
22037#endif /* OBJ_ELF */
22038
c19d1205
ZW
22039/* Convert REGNAME to a DWARF-2 register number. */
22040
22041int
1df69f4f 22042tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22043{
1df69f4f 22044 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22045 if (reg != FAIL)
22046 return reg;
c19d1205 22047
1f5afe1c
NC
22048 /* PR 16694: Allow VFP registers as well. */
22049 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22050 if (reg != FAIL)
22051 return 64 + reg;
c19d1205 22052
1f5afe1c
NC
22053 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22054 if (reg != FAIL)
22055 return reg + 256;
22056
22057 return -1;
bfae80f2
RE
22058}
22059
f0927246 22060#ifdef TE_PE
c19d1205 22061void
f0927246 22062tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22063{
91d6fa6a 22064 expressionS exp;
bfae80f2 22065
91d6fa6a
NC
22066 exp.X_op = O_secrel;
22067 exp.X_add_symbol = symbol;
22068 exp.X_add_number = 0;
22069 emit_expr (&exp, size);
f0927246
NC
22070}
22071#endif
bfae80f2 22072
c19d1205 22073/* MD interface: Symbol and relocation handling. */
bfae80f2 22074
2fc8bdac
ZW
22075/* Return the address within the segment that a PC-relative fixup is
22076 relative to. For ARM, PC-relative fixups applied to instructions
22077 are generally relative to the location of the fixup plus 8 bytes.
22078 Thumb branches are offset by 4, and Thumb loads relative to PC
22079 require special handling. */
bfae80f2 22080
c19d1205 22081long
2fc8bdac 22082md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22083{
2fc8bdac
ZW
22084 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22085
22086 /* If this is pc-relative and we are going to emit a relocation
22087 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22088 will need. Otherwise we want to use the calculated base.
22089 For WinCE we skip the bias for externals as well, since this
22090 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22091 if (fixP->fx_pcrel
2fc8bdac 22092 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22093 || (arm_force_relocation (fixP)
22094#ifdef TE_WINCE
22095 && !S_IS_EXTERNAL (fixP->fx_addsy)
22096#endif
22097 )))
2fc8bdac 22098 base = 0;
bfae80f2 22099
267bf995 22100
c19d1205 22101 switch (fixP->fx_r_type)
bfae80f2 22102 {
2fc8bdac
ZW
22103 /* PC relative addressing on the Thumb is slightly odd as the
22104 bottom two bits of the PC are forced to zero for the
22105 calculation. This happens *after* application of the
22106 pipeline offset. However, Thumb adrl already adjusts for
22107 this, so we need not do it again. */
c19d1205 22108 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22109 return base & ~3;
c19d1205
ZW
22110
22111 case BFD_RELOC_ARM_THUMB_OFFSET:
22112 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22113 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22114 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22115 return (base + 4) & ~3;
c19d1205 22116
2fc8bdac
ZW
22117 /* Thumb branches are simply offset by +4. */
22118 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22119 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22120 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22121 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22122 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22123 return base + 4;
bfae80f2 22124
267bf995 22125 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22126 if (fixP->fx_addsy
22127 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22128 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22129 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22130 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22131 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22132 return base + 4;
22133
00adf2d4
JB
22134 /* BLX is like branches above, but forces the low two bits of PC to
22135 zero. */
486499d0
CL
22136 case BFD_RELOC_THUMB_PCREL_BLX:
22137 if (fixP->fx_addsy
22138 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22139 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22140 && THUMB_IS_FUNC (fixP->fx_addsy)
22141 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22142 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22143 return (base + 4) & ~3;
22144
2fc8bdac
ZW
22145 /* ARM mode branches are offset by +8. However, the Windows CE
22146 loader expects the relocation not to take this into account. */
267bf995 22147 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22148 if (fixP->fx_addsy
22149 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22150 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22151 && ARM_IS_FUNC (fixP->fx_addsy)
22152 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22153 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22154 return base + 8;
267bf995 22155
486499d0
CL
22156 case BFD_RELOC_ARM_PCREL_CALL:
22157 if (fixP->fx_addsy
22158 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22159 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22160 && THUMB_IS_FUNC (fixP->fx_addsy)
22161 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22162 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22163 return base + 8;
267bf995 22164
2fc8bdac 22165 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22166 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22167 case BFD_RELOC_ARM_PLT32:
c19d1205 22168#ifdef TE_WINCE
5f4273c7 22169 /* When handling fixups immediately, because we have already
477330fc 22170 discovered the value of a symbol, or the address of the frag involved
53baae48 22171 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22172 see fixup_segment() in write.c
22173 The S_IS_EXTERNAL test handles the case of global symbols.
22174 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22175 if (fixP->fx_pcrel
22176 && fixP->fx_addsy != NULL
22177 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22178 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22179 return base + 8;
2fc8bdac 22180 return base;
c19d1205 22181#else
2fc8bdac 22182 return base + 8;
c19d1205 22183#endif
2fc8bdac 22184
267bf995 22185
2fc8bdac
ZW
22186 /* ARM mode loads relative to PC are also offset by +8. Unlike
22187 branches, the Windows CE loader *does* expect the relocation
22188 to take this into account. */
22189 case BFD_RELOC_ARM_OFFSET_IMM:
22190 case BFD_RELOC_ARM_OFFSET_IMM8:
22191 case BFD_RELOC_ARM_HWLITERAL:
22192 case BFD_RELOC_ARM_LITERAL:
22193 case BFD_RELOC_ARM_CP_OFF_IMM:
22194 return base + 8;
22195
22196
22197 /* Other PC-relative relocations are un-offset. */
22198 default:
22199 return base;
22200 }
bfae80f2
RE
22201}
22202
8b2d793c
NC
22203static bfd_boolean flag_warn_syms = TRUE;
22204
ae8714c2
NC
22205bfd_boolean
22206arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22207{
8b2d793c
NC
22208 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22209 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22210 does mean that the resulting code might be very confusing to the reader.
22211 Also this warning can be triggered if the user omits an operand before
22212 an immediate address, eg:
22213
22214 LDR =foo
22215
22216 GAS treats this as an assignment of the value of the symbol foo to a
22217 symbol LDR, and so (without this code) it will not issue any kind of
22218 warning or error message.
22219
22220 Note - ARM instructions are case-insensitive but the strings in the hash
22221 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22222 lower case too. */
22223 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22224 {
22225 char * nbuf = strdup (name);
22226 char * p;
22227
22228 for (p = nbuf; *p; p++)
22229 *p = TOLOWER (*p);
22230 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22231 {
22232 static struct hash_control * already_warned = NULL;
22233
22234 if (already_warned == NULL)
22235 already_warned = hash_new ();
22236 /* Only warn about the symbol once. To keep the code
22237 simple we let hash_insert do the lookup for us. */
22238 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22239 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22240 }
22241 else
22242 free (nbuf);
22243 }
3739860c 22244
ae8714c2
NC
22245 return FALSE;
22246}
22247
22248/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22249 Otherwise we have no need to default values of symbols. */
22250
22251symbolS *
22252md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22253{
22254#ifdef OBJ_ELF
22255 if (name[0] == '_' && name[1] == 'G'
22256 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22257 {
22258 if (!GOT_symbol)
22259 {
22260 if (symbol_find (name))
22261 as_bad (_("GOT already in the symbol table"));
22262
22263 GOT_symbol = symbol_new (name, undefined_section,
22264 (valueT) 0, & zero_address_frag);
22265 }
22266
22267 return GOT_symbol;
22268 }
22269#endif
22270
c921be7d 22271 return NULL;
bfae80f2
RE
22272}
22273
55cf6793 22274/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22275 computed as two separate immediate values, added together. We
22276 already know that this value cannot be computed by just one ARM
22277 instruction. */
22278
22279static unsigned int
22280validate_immediate_twopart (unsigned int val,
22281 unsigned int * highpart)
bfae80f2 22282{
c19d1205
ZW
22283 unsigned int a;
22284 unsigned int i;
bfae80f2 22285
c19d1205
ZW
22286 for (i = 0; i < 32; i += 2)
22287 if (((a = rotate_left (val, i)) & 0xff) != 0)
22288 {
22289 if (a & 0xff00)
22290 {
22291 if (a & ~ 0xffff)
22292 continue;
22293 * highpart = (a >> 8) | ((i + 24) << 7);
22294 }
22295 else if (a & 0xff0000)
22296 {
22297 if (a & 0xff000000)
22298 continue;
22299 * highpart = (a >> 16) | ((i + 16) << 7);
22300 }
22301 else
22302 {
9c2799c2 22303 gas_assert (a & 0xff000000);
c19d1205
ZW
22304 * highpart = (a >> 24) | ((i + 8) << 7);
22305 }
bfae80f2 22306
c19d1205
ZW
22307 return (a & 0xff) | (i << 7);
22308 }
bfae80f2 22309
c19d1205 22310 return FAIL;
bfae80f2
RE
22311}
22312
c19d1205
ZW
22313static int
22314validate_offset_imm (unsigned int val, int hwse)
22315{
22316 if ((hwse && val > 255) || val > 4095)
22317 return FAIL;
22318 return val;
22319}
bfae80f2 22320
55cf6793 22321/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22322 negative immediate constant by altering the instruction. A bit of
22323 a hack really.
22324 MOV <-> MVN
22325 AND <-> BIC
22326 ADC <-> SBC
22327 by inverting the second operand, and
22328 ADD <-> SUB
22329 CMP <-> CMN
22330 by negating the second operand. */
bfae80f2 22331
c19d1205
ZW
22332static int
22333negate_data_op (unsigned long * instruction,
22334 unsigned long value)
bfae80f2 22335{
c19d1205
ZW
22336 int op, new_inst;
22337 unsigned long negated, inverted;
bfae80f2 22338
c19d1205
ZW
22339 negated = encode_arm_immediate (-value);
22340 inverted = encode_arm_immediate (~value);
bfae80f2 22341
c19d1205
ZW
22342 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22343 switch (op)
bfae80f2 22344 {
c19d1205
ZW
22345 /* First negates. */
22346 case OPCODE_SUB: /* ADD <-> SUB */
22347 new_inst = OPCODE_ADD;
22348 value = negated;
22349 break;
bfae80f2 22350
c19d1205
ZW
22351 case OPCODE_ADD:
22352 new_inst = OPCODE_SUB;
22353 value = negated;
22354 break;
bfae80f2 22355
c19d1205
ZW
22356 case OPCODE_CMP: /* CMP <-> CMN */
22357 new_inst = OPCODE_CMN;
22358 value = negated;
22359 break;
bfae80f2 22360
c19d1205
ZW
22361 case OPCODE_CMN:
22362 new_inst = OPCODE_CMP;
22363 value = negated;
22364 break;
bfae80f2 22365
c19d1205
ZW
22366 /* Now Inverted ops. */
22367 case OPCODE_MOV: /* MOV <-> MVN */
22368 new_inst = OPCODE_MVN;
22369 value = inverted;
22370 break;
bfae80f2 22371
c19d1205
ZW
22372 case OPCODE_MVN:
22373 new_inst = OPCODE_MOV;
22374 value = inverted;
22375 break;
bfae80f2 22376
c19d1205
ZW
22377 case OPCODE_AND: /* AND <-> BIC */
22378 new_inst = OPCODE_BIC;
22379 value = inverted;
22380 break;
bfae80f2 22381
c19d1205
ZW
22382 case OPCODE_BIC:
22383 new_inst = OPCODE_AND;
22384 value = inverted;
22385 break;
bfae80f2 22386
c19d1205
ZW
22387 case OPCODE_ADC: /* ADC <-> SBC */
22388 new_inst = OPCODE_SBC;
22389 value = inverted;
22390 break;
bfae80f2 22391
c19d1205
ZW
22392 case OPCODE_SBC:
22393 new_inst = OPCODE_ADC;
22394 value = inverted;
22395 break;
bfae80f2 22396
c19d1205
ZW
22397 /* We cannot do anything. */
22398 default:
22399 return FAIL;
b99bd4ef
NC
22400 }
22401
c19d1205
ZW
22402 if (value == (unsigned) FAIL)
22403 return FAIL;
22404
22405 *instruction &= OPCODE_MASK;
22406 *instruction |= new_inst << DATA_OP_SHIFT;
22407 return value;
b99bd4ef
NC
22408}
22409
ef8d22e6
PB
22410/* Like negate_data_op, but for Thumb-2. */
22411
22412static unsigned int
16dd5e42 22413thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22414{
22415 int op, new_inst;
22416 int rd;
16dd5e42 22417 unsigned int negated, inverted;
ef8d22e6
PB
22418
22419 negated = encode_thumb32_immediate (-value);
22420 inverted = encode_thumb32_immediate (~value);
22421
22422 rd = (*instruction >> 8) & 0xf;
22423 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22424 switch (op)
22425 {
22426 /* ADD <-> SUB. Includes CMP <-> CMN. */
22427 case T2_OPCODE_SUB:
22428 new_inst = T2_OPCODE_ADD;
22429 value = negated;
22430 break;
22431
22432 case T2_OPCODE_ADD:
22433 new_inst = T2_OPCODE_SUB;
22434 value = negated;
22435 break;
22436
22437 /* ORR <-> ORN. Includes MOV <-> MVN. */
22438 case T2_OPCODE_ORR:
22439 new_inst = T2_OPCODE_ORN;
22440 value = inverted;
22441 break;
22442
22443 case T2_OPCODE_ORN:
22444 new_inst = T2_OPCODE_ORR;
22445 value = inverted;
22446 break;
22447
22448 /* AND <-> BIC. TST has no inverted equivalent. */
22449 case T2_OPCODE_AND:
22450 new_inst = T2_OPCODE_BIC;
22451 if (rd == 15)
22452 value = FAIL;
22453 else
22454 value = inverted;
22455 break;
22456
22457 case T2_OPCODE_BIC:
22458 new_inst = T2_OPCODE_AND;
22459 value = inverted;
22460 break;
22461
22462 /* ADC <-> SBC */
22463 case T2_OPCODE_ADC:
22464 new_inst = T2_OPCODE_SBC;
22465 value = inverted;
22466 break;
22467
22468 case T2_OPCODE_SBC:
22469 new_inst = T2_OPCODE_ADC;
22470 value = inverted;
22471 break;
22472
22473 /* We cannot do anything. */
22474 default:
22475 return FAIL;
22476 }
22477
16dd5e42 22478 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22479 return FAIL;
22480
22481 *instruction &= T2_OPCODE_MASK;
22482 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22483 return value;
22484}
22485
8f06b2d8
PB
22486/* Read a 32-bit thumb instruction from buf. */
22487static unsigned long
22488get_thumb32_insn (char * buf)
22489{
22490 unsigned long insn;
22491 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22492 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22493
22494 return insn;
22495}
22496
a8bc6c78
PB
22497
22498/* We usually want to set the low bit on the address of thumb function
22499 symbols. In particular .word foo - . should have the low bit set.
22500 Generic code tries to fold the difference of two symbols to
22501 a constant. Prevent this and force a relocation when the first symbols
22502 is a thumb function. */
c921be7d
NC
22503
22504bfd_boolean
a8bc6c78
PB
22505arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22506{
22507 if (op == O_subtract
22508 && l->X_op == O_symbol
22509 && r->X_op == O_symbol
22510 && THUMB_IS_FUNC (l->X_add_symbol))
22511 {
22512 l->X_op = O_subtract;
22513 l->X_op_symbol = r->X_add_symbol;
22514 l->X_add_number -= r->X_add_number;
c921be7d 22515 return TRUE;
a8bc6c78 22516 }
c921be7d 22517
a8bc6c78 22518 /* Process as normal. */
c921be7d 22519 return FALSE;
a8bc6c78
PB
22520}
22521
4a42ebbc
RR
22522/* Encode Thumb2 unconditional branches and calls. The encoding
22523 for the 2 are identical for the immediate values. */
22524
22525static void
22526encode_thumb2_b_bl_offset (char * buf, offsetT value)
22527{
22528#define T2I1I2MASK ((1 << 13) | (1 << 11))
22529 offsetT newval;
22530 offsetT newval2;
22531 addressT S, I1, I2, lo, hi;
22532
22533 S = (value >> 24) & 0x01;
22534 I1 = (value >> 23) & 0x01;
22535 I2 = (value >> 22) & 0x01;
22536 hi = (value >> 12) & 0x3ff;
fa94de6b 22537 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22538 newval = md_chars_to_number (buf, THUMB_SIZE);
22539 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22540 newval |= (S << 10) | hi;
22541 newval2 &= ~T2I1I2MASK;
22542 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22543 md_number_to_chars (buf, newval, THUMB_SIZE);
22544 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22545}
22546
c19d1205 22547void
55cf6793 22548md_apply_fix (fixS * fixP,
c19d1205
ZW
22549 valueT * valP,
22550 segT seg)
22551{
22552 offsetT value = * valP;
22553 offsetT newval;
22554 unsigned int newimm;
22555 unsigned long temp;
22556 int sign;
22557 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22558
9c2799c2 22559 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22560
c19d1205 22561 /* Note whether this will delete the relocation. */
4962c51a 22562
c19d1205
ZW
22563 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22564 fixP->fx_done = 1;
b99bd4ef 22565
adbaf948 22566 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22567 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22568 for emit_reloc. */
22569 value &= 0xffffffff;
22570 value ^= 0x80000000;
5f4273c7 22571 value -= 0x80000000;
adbaf948
ZW
22572
22573 *valP = value;
c19d1205 22574 fixP->fx_addnumber = value;
b99bd4ef 22575
adbaf948
ZW
22576 /* Same treatment for fixP->fx_offset. */
22577 fixP->fx_offset &= 0xffffffff;
22578 fixP->fx_offset ^= 0x80000000;
22579 fixP->fx_offset -= 0x80000000;
22580
c19d1205 22581 switch (fixP->fx_r_type)
b99bd4ef 22582 {
c19d1205
ZW
22583 case BFD_RELOC_NONE:
22584 /* This will need to go in the object file. */
22585 fixP->fx_done = 0;
22586 break;
b99bd4ef 22587
c19d1205
ZW
22588 case BFD_RELOC_ARM_IMMEDIATE:
22589 /* We claim that this fixup has been processed here,
22590 even if in fact we generate an error because we do
22591 not have a reloc for it, so tc_gen_reloc will reject it. */
22592 fixP->fx_done = 1;
b99bd4ef 22593
77db8e2e 22594 if (fixP->fx_addsy)
b99bd4ef 22595 {
77db8e2e 22596 const char *msg = 0;
b99bd4ef 22597
77db8e2e
NC
22598 if (! S_IS_DEFINED (fixP->fx_addsy))
22599 msg = _("undefined symbol %s used as an immediate value");
22600 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22601 msg = _("symbol %s is in a different section");
22602 else if (S_IS_WEAK (fixP->fx_addsy))
22603 msg = _("symbol %s is weak and may be overridden later");
22604
22605 if (msg)
22606 {
22607 as_bad_where (fixP->fx_file, fixP->fx_line,
22608 msg, S_GET_NAME (fixP->fx_addsy));
22609 break;
22610 }
42e5fcbf
AS
22611 }
22612
c19d1205
ZW
22613 temp = md_chars_to_number (buf, INSN_SIZE);
22614
5e73442d
SL
22615 /* If the offset is negative, we should use encoding A2 for ADR. */
22616 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22617 newimm = negate_data_op (&temp, value);
22618 else
22619 {
22620 newimm = encode_arm_immediate (value);
22621
22622 /* If the instruction will fail, see if we can fix things up by
22623 changing the opcode. */
22624 if (newimm == (unsigned int) FAIL)
22625 newimm = negate_data_op (&temp, value);
22626 }
22627
22628 if (newimm == (unsigned int) FAIL)
b99bd4ef 22629 {
c19d1205
ZW
22630 as_bad_where (fixP->fx_file, fixP->fx_line,
22631 _("invalid constant (%lx) after fixup"),
22632 (unsigned long) value);
22633 break;
b99bd4ef 22634 }
b99bd4ef 22635
c19d1205
ZW
22636 newimm |= (temp & 0xfffff000);
22637 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22638 break;
b99bd4ef 22639
c19d1205
ZW
22640 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22641 {
22642 unsigned int highpart = 0;
22643 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22644
77db8e2e 22645 if (fixP->fx_addsy)
42e5fcbf 22646 {
77db8e2e 22647 const char *msg = 0;
42e5fcbf 22648
77db8e2e
NC
22649 if (! S_IS_DEFINED (fixP->fx_addsy))
22650 msg = _("undefined symbol %s used as an immediate value");
22651 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22652 msg = _("symbol %s is in a different section");
22653 else if (S_IS_WEAK (fixP->fx_addsy))
22654 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22655
77db8e2e
NC
22656 if (msg)
22657 {
22658 as_bad_where (fixP->fx_file, fixP->fx_line,
22659 msg, S_GET_NAME (fixP->fx_addsy));
22660 break;
22661 }
22662 }
fa94de6b 22663
c19d1205
ZW
22664 newimm = encode_arm_immediate (value);
22665 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22666
c19d1205
ZW
22667 /* If the instruction will fail, see if we can fix things up by
22668 changing the opcode. */
22669 if (newimm == (unsigned int) FAIL
22670 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22671 {
22672 /* No ? OK - try using two ADD instructions to generate
22673 the value. */
22674 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22675
c19d1205
ZW
22676 /* Yes - then make sure that the second instruction is
22677 also an add. */
22678 if (newimm != (unsigned int) FAIL)
22679 newinsn = temp;
22680 /* Still No ? Try using a negated value. */
22681 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22682 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22683 /* Otherwise - give up. */
22684 else
22685 {
22686 as_bad_where (fixP->fx_file, fixP->fx_line,
22687 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22688 (long) value);
22689 break;
22690 }
b99bd4ef 22691
c19d1205
ZW
22692 /* Replace the first operand in the 2nd instruction (which
22693 is the PC) with the destination register. We have
22694 already added in the PC in the first instruction and we
22695 do not want to do it again. */
22696 newinsn &= ~ 0xf0000;
22697 newinsn |= ((newinsn & 0x0f000) << 4);
22698 }
b99bd4ef 22699
c19d1205
ZW
22700 newimm |= (temp & 0xfffff000);
22701 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22702
c19d1205
ZW
22703 highpart |= (newinsn & 0xfffff000);
22704 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22705 }
22706 break;
b99bd4ef 22707
c19d1205 22708 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22709 if (!fixP->fx_done && seg->use_rela_p)
22710 value = 0;
22711
c19d1205 22712 case BFD_RELOC_ARM_LITERAL:
26d97720 22713 sign = value > 0;
b99bd4ef 22714
c19d1205
ZW
22715 if (value < 0)
22716 value = - value;
b99bd4ef 22717
c19d1205 22718 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22719 {
c19d1205
ZW
22720 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22721 as_bad_where (fixP->fx_file, fixP->fx_line,
22722 _("invalid literal constant: pool needs to be closer"));
22723 else
22724 as_bad_where (fixP->fx_file, fixP->fx_line,
22725 _("bad immediate value for offset (%ld)"),
22726 (long) value);
22727 break;
f03698e6
RE
22728 }
22729
c19d1205 22730 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22731 if (value == 0)
22732 newval &= 0xfffff000;
22733 else
22734 {
22735 newval &= 0xff7ff000;
22736 newval |= value | (sign ? INDEX_UP : 0);
22737 }
c19d1205
ZW
22738 md_number_to_chars (buf, newval, INSN_SIZE);
22739 break;
b99bd4ef 22740
c19d1205
ZW
22741 case BFD_RELOC_ARM_OFFSET_IMM8:
22742 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22743 sign = value > 0;
b99bd4ef 22744
c19d1205
ZW
22745 if (value < 0)
22746 value = - value;
b99bd4ef 22747
c19d1205 22748 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22749 {
c19d1205
ZW
22750 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22751 as_bad_where (fixP->fx_file, fixP->fx_line,
22752 _("invalid literal constant: pool needs to be closer"));
22753 else
427d0db6
RM
22754 as_bad_where (fixP->fx_file, fixP->fx_line,
22755 _("bad immediate value for 8-bit offset (%ld)"),
22756 (long) value);
c19d1205 22757 break;
b99bd4ef
NC
22758 }
22759
c19d1205 22760 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22761 if (value == 0)
22762 newval &= 0xfffff0f0;
22763 else
22764 {
22765 newval &= 0xff7ff0f0;
22766 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22767 }
c19d1205
ZW
22768 md_number_to_chars (buf, newval, INSN_SIZE);
22769 break;
b99bd4ef 22770
c19d1205
ZW
22771 case BFD_RELOC_ARM_T32_OFFSET_U8:
22772 if (value < 0 || value > 1020 || value % 4 != 0)
22773 as_bad_where (fixP->fx_file, fixP->fx_line,
22774 _("bad immediate value for offset (%ld)"), (long) value);
22775 value /= 4;
b99bd4ef 22776
c19d1205 22777 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22778 newval |= value;
22779 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22780 break;
b99bd4ef 22781
c19d1205
ZW
22782 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22783 /* This is a complicated relocation used for all varieties of Thumb32
22784 load/store instruction with immediate offset:
22785
22786 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22787 *4, optional writeback(W)
c19d1205
ZW
22788 (doubleword load/store)
22789
22790 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22791 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22792 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22793 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22794 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22795
22796 Uppercase letters indicate bits that are already encoded at
22797 this point. Lowercase letters are our problem. For the
22798 second block of instructions, the secondary opcode nybble
22799 (bits 8..11) is present, and bit 23 is zero, even if this is
22800 a PC-relative operation. */
22801 newval = md_chars_to_number (buf, THUMB_SIZE);
22802 newval <<= 16;
22803 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22804
c19d1205 22805 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22806 {
c19d1205
ZW
22807 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22808 if (value >= 0)
22809 newval |= (1 << 23);
22810 else
22811 value = -value;
22812 if (value % 4 != 0)
22813 {
22814 as_bad_where (fixP->fx_file, fixP->fx_line,
22815 _("offset not a multiple of 4"));
22816 break;
22817 }
22818 value /= 4;
216d22bc 22819 if (value > 0xff)
c19d1205
ZW
22820 {
22821 as_bad_where (fixP->fx_file, fixP->fx_line,
22822 _("offset out of range"));
22823 break;
22824 }
22825 newval &= ~0xff;
b99bd4ef 22826 }
c19d1205 22827 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22828 {
c19d1205
ZW
22829 /* PC-relative, 12-bit offset. */
22830 if (value >= 0)
22831 newval |= (1 << 23);
22832 else
22833 value = -value;
216d22bc 22834 if (value > 0xfff)
c19d1205
ZW
22835 {
22836 as_bad_where (fixP->fx_file, fixP->fx_line,
22837 _("offset out of range"));
22838 break;
22839 }
22840 newval &= ~0xfff;
b99bd4ef 22841 }
c19d1205 22842 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22843 {
c19d1205
ZW
22844 /* Writeback: 8-bit, +/- offset. */
22845 if (value >= 0)
22846 newval |= (1 << 9);
22847 else
22848 value = -value;
216d22bc 22849 if (value > 0xff)
c19d1205
ZW
22850 {
22851 as_bad_where (fixP->fx_file, fixP->fx_line,
22852 _("offset out of range"));
22853 break;
22854 }
22855 newval &= ~0xff;
b99bd4ef 22856 }
c19d1205 22857 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22858 {
c19d1205 22859 /* T-instruction: positive 8-bit offset. */
216d22bc 22860 if (value < 0 || value > 0xff)
b99bd4ef 22861 {
c19d1205
ZW
22862 as_bad_where (fixP->fx_file, fixP->fx_line,
22863 _("offset out of range"));
22864 break;
b99bd4ef 22865 }
c19d1205
ZW
22866 newval &= ~0xff;
22867 newval |= value;
b99bd4ef
NC
22868 }
22869 else
b99bd4ef 22870 {
c19d1205
ZW
22871 /* Positive 12-bit or negative 8-bit offset. */
22872 int limit;
22873 if (value >= 0)
b99bd4ef 22874 {
c19d1205
ZW
22875 newval |= (1 << 23);
22876 limit = 0xfff;
22877 }
22878 else
22879 {
22880 value = -value;
22881 limit = 0xff;
22882 }
22883 if (value > limit)
22884 {
22885 as_bad_where (fixP->fx_file, fixP->fx_line,
22886 _("offset out of range"));
22887 break;
b99bd4ef 22888 }
c19d1205 22889 newval &= ~limit;
b99bd4ef 22890 }
b99bd4ef 22891
c19d1205
ZW
22892 newval |= value;
22893 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22894 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22895 break;
404ff6b5 22896
c19d1205
ZW
22897 case BFD_RELOC_ARM_SHIFT_IMM:
22898 newval = md_chars_to_number (buf, INSN_SIZE);
22899 if (((unsigned long) value) > 32
22900 || (value == 32
22901 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22902 {
22903 as_bad_where (fixP->fx_file, fixP->fx_line,
22904 _("shift expression is too large"));
22905 break;
22906 }
404ff6b5 22907
c19d1205
ZW
22908 if (value == 0)
22909 /* Shifts of zero must be done as lsl. */
22910 newval &= ~0x60;
22911 else if (value == 32)
22912 value = 0;
22913 newval &= 0xfffff07f;
22914 newval |= (value & 0x1f) << 7;
22915 md_number_to_chars (buf, newval, INSN_SIZE);
22916 break;
404ff6b5 22917
c19d1205 22918 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22919 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22920 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22921 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22922 /* We claim that this fixup has been processed here,
22923 even if in fact we generate an error because we do
22924 not have a reloc for it, so tc_gen_reloc will reject it. */
22925 fixP->fx_done = 1;
404ff6b5 22926
c19d1205
ZW
22927 if (fixP->fx_addsy
22928 && ! S_IS_DEFINED (fixP->fx_addsy))
22929 {
22930 as_bad_where (fixP->fx_file, fixP->fx_line,
22931 _("undefined symbol %s used as an immediate value"),
22932 S_GET_NAME (fixP->fx_addsy));
22933 break;
22934 }
404ff6b5 22935
c19d1205
ZW
22936 newval = md_chars_to_number (buf, THUMB_SIZE);
22937 newval <<= 16;
22938 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22939
16805f35
PB
22940 newimm = FAIL;
22941 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22942 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22943 {
22944 newimm = encode_thumb32_immediate (value);
22945 if (newimm == (unsigned int) FAIL)
22946 newimm = thumb32_negate_data_op (&newval, value);
22947 }
16805f35
PB
22948 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22949 && newimm == (unsigned int) FAIL)
92e90b6e 22950 {
16805f35
PB
22951 /* Turn add/sum into addw/subw. */
22952 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22953 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22954 /* No flat 12-bit imm encoding for addsw/subsw. */
22955 if ((newval & 0x00100000) == 0)
e9f89963 22956 {
40f246e3
NC
22957 /* 12 bit immediate for addw/subw. */
22958 if (value < 0)
22959 {
22960 value = -value;
22961 newval ^= 0x00a00000;
22962 }
22963 if (value > 0xfff)
22964 newimm = (unsigned int) FAIL;
22965 else
22966 newimm = value;
e9f89963 22967 }
92e90b6e 22968 }
cc8a6dd0 22969
c19d1205 22970 if (newimm == (unsigned int)FAIL)
3631a3c8 22971 {
c19d1205
ZW
22972 as_bad_where (fixP->fx_file, fixP->fx_line,
22973 _("invalid constant (%lx) after fixup"),
22974 (unsigned long) value);
22975 break;
3631a3c8
NC
22976 }
22977
c19d1205
ZW
22978 newval |= (newimm & 0x800) << 15;
22979 newval |= (newimm & 0x700) << 4;
22980 newval |= (newimm & 0x0ff);
cc8a6dd0 22981
c19d1205
ZW
22982 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22983 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22984 break;
a737bd4d 22985
3eb17e6b 22986 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22987 if (((unsigned long) value) > 0xffff)
22988 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22989 _("invalid smc expression"));
2fc8bdac 22990 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22991 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22992 md_number_to_chars (buf, newval, INSN_SIZE);
22993 break;
a737bd4d 22994
90ec0d68
MGD
22995 case BFD_RELOC_ARM_HVC:
22996 if (((unsigned long) value) > 0xffff)
22997 as_bad_where (fixP->fx_file, fixP->fx_line,
22998 _("invalid hvc expression"));
22999 newval = md_chars_to_number (buf, INSN_SIZE);
23000 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23001 md_number_to_chars (buf, newval, INSN_SIZE);
23002 break;
23003
c19d1205 23004 case BFD_RELOC_ARM_SWI:
adbaf948 23005 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23006 {
23007 if (((unsigned long) value) > 0xff)
23008 as_bad_where (fixP->fx_file, fixP->fx_line,
23009 _("invalid swi expression"));
2fc8bdac 23010 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23011 newval |= value;
23012 md_number_to_chars (buf, newval, THUMB_SIZE);
23013 }
23014 else
23015 {
23016 if (((unsigned long) value) > 0x00ffffff)
23017 as_bad_where (fixP->fx_file, fixP->fx_line,
23018 _("invalid swi expression"));
2fc8bdac 23019 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23020 newval |= value;
23021 md_number_to_chars (buf, newval, INSN_SIZE);
23022 }
23023 break;
a737bd4d 23024
c19d1205
ZW
23025 case BFD_RELOC_ARM_MULTI:
23026 if (((unsigned long) value) > 0xffff)
23027 as_bad_where (fixP->fx_file, fixP->fx_line,
23028 _("invalid expression in load/store multiple"));
23029 newval = value | md_chars_to_number (buf, INSN_SIZE);
23030 md_number_to_chars (buf, newval, INSN_SIZE);
23031 break;
a737bd4d 23032
c19d1205 23033#ifdef OBJ_ELF
39b41c9c 23034 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23035
23036 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23037 && fixP->fx_addsy
34e77a92 23038 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23039 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23040 && THUMB_IS_FUNC (fixP->fx_addsy))
23041 /* Flip the bl to blx. This is a simple flip
23042 bit here because we generate PCREL_CALL for
23043 unconditional bls. */
23044 {
23045 newval = md_chars_to_number (buf, INSN_SIZE);
23046 newval = newval | 0x10000000;
23047 md_number_to_chars (buf, newval, INSN_SIZE);
23048 temp = 1;
23049 fixP->fx_done = 1;
23050 }
39b41c9c
PB
23051 else
23052 temp = 3;
23053 goto arm_branch_common;
23054
23055 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23056 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23057 && fixP->fx_addsy
34e77a92 23058 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23059 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23060 && THUMB_IS_FUNC (fixP->fx_addsy))
23061 {
23062 /* This would map to a bl<cond>, b<cond>,
23063 b<always> to a Thumb function. We
23064 need to force a relocation for this particular
23065 case. */
23066 newval = md_chars_to_number (buf, INSN_SIZE);
23067 fixP->fx_done = 0;
23068 }
23069
2fc8bdac 23070 case BFD_RELOC_ARM_PLT32:
c19d1205 23071#endif
39b41c9c
PB
23072 case BFD_RELOC_ARM_PCREL_BRANCH:
23073 temp = 3;
23074 goto arm_branch_common;
a737bd4d 23075
39b41c9c 23076 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23077
39b41c9c 23078 temp = 1;
267bf995
RR
23079 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23080 && fixP->fx_addsy
34e77a92 23081 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23082 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23083 && ARM_IS_FUNC (fixP->fx_addsy))
23084 {
23085 /* Flip the blx to a bl and warn. */
23086 const char *name = S_GET_NAME (fixP->fx_addsy);
23087 newval = 0xeb000000;
23088 as_warn_where (fixP->fx_file, fixP->fx_line,
23089 _("blx to '%s' an ARM ISA state function changed to bl"),
23090 name);
23091 md_number_to_chars (buf, newval, INSN_SIZE);
23092 temp = 3;
23093 fixP->fx_done = 1;
23094 }
23095
23096#ifdef OBJ_ELF
23097 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23098 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23099#endif
23100
39b41c9c 23101 arm_branch_common:
c19d1205 23102 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23103 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23104 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23105 also be be clear. */
23106 if (value & temp)
c19d1205 23107 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23108 _("misaligned branch destination"));
23109 if ((value & (offsetT)0xfe000000) != (offsetT)0
23110 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23111 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23112
2fc8bdac 23113 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23114 {
2fc8bdac
ZW
23115 newval = md_chars_to_number (buf, INSN_SIZE);
23116 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23117 /* Set the H bit on BLX instructions. */
23118 if (temp == 1)
23119 {
23120 if (value & 2)
23121 newval |= 0x01000000;
23122 else
23123 newval &= ~0x01000000;
23124 }
2fc8bdac 23125 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23126 }
c19d1205 23127 break;
a737bd4d 23128
25fe350b
MS
23129 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23130 /* CBZ can only branch forward. */
a737bd4d 23131
738755b0 23132 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23133 (which, strictly speaking, are prohibited) will be turned into
23134 no-ops.
738755b0
MS
23135
23136 FIXME: It may be better to remove the instruction completely and
23137 perform relaxation. */
23138 if (value == -2)
2fc8bdac
ZW
23139 {
23140 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23141 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23142 md_number_to_chars (buf, newval, THUMB_SIZE);
23143 }
738755b0
MS
23144 else
23145 {
23146 if (value & ~0x7e)
08f10d51 23147 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23148
477330fc 23149 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23150 {
23151 newval = md_chars_to_number (buf, THUMB_SIZE);
23152 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23153 md_number_to_chars (buf, newval, THUMB_SIZE);
23154 }
23155 }
c19d1205 23156 break;
a737bd4d 23157
c19d1205 23158 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23159 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23160 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23161
2fc8bdac
ZW
23162 if (fixP->fx_done || !seg->use_rela_p)
23163 {
23164 newval = md_chars_to_number (buf, THUMB_SIZE);
23165 newval |= (value & 0x1ff) >> 1;
23166 md_number_to_chars (buf, newval, THUMB_SIZE);
23167 }
c19d1205 23168 break;
a737bd4d 23169
c19d1205 23170 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23171 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23172 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23173
2fc8bdac
ZW
23174 if (fixP->fx_done || !seg->use_rela_p)
23175 {
23176 newval = md_chars_to_number (buf, THUMB_SIZE);
23177 newval |= (value & 0xfff) >> 1;
23178 md_number_to_chars (buf, newval, THUMB_SIZE);
23179 }
c19d1205 23180 break;
a737bd4d 23181
c19d1205 23182 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23183 if (fixP->fx_addsy
23184 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23185 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23186 && ARM_IS_FUNC (fixP->fx_addsy)
23187 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23188 {
23189 /* Force a relocation for a branch 20 bits wide. */
23190 fixP->fx_done = 0;
23191 }
08f10d51 23192 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23193 as_bad_where (fixP->fx_file, fixP->fx_line,
23194 _("conditional branch out of range"));
404ff6b5 23195
2fc8bdac
ZW
23196 if (fixP->fx_done || !seg->use_rela_p)
23197 {
23198 offsetT newval2;
23199 addressT S, J1, J2, lo, hi;
404ff6b5 23200
2fc8bdac
ZW
23201 S = (value & 0x00100000) >> 20;
23202 J2 = (value & 0x00080000) >> 19;
23203 J1 = (value & 0x00040000) >> 18;
23204 hi = (value & 0x0003f000) >> 12;
23205 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23206
2fc8bdac
ZW
23207 newval = md_chars_to_number (buf, THUMB_SIZE);
23208 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23209 newval |= (S << 10) | hi;
23210 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23211 md_number_to_chars (buf, newval, THUMB_SIZE);
23212 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23213 }
c19d1205 23214 break;
6c43fab6 23215
c19d1205 23216 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23217 /* If there is a blx from a thumb state function to
23218 another thumb function flip this to a bl and warn
23219 about it. */
23220
23221 if (fixP->fx_addsy
34e77a92 23222 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23223 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23224 && THUMB_IS_FUNC (fixP->fx_addsy))
23225 {
23226 const char *name = S_GET_NAME (fixP->fx_addsy);
23227 as_warn_where (fixP->fx_file, fixP->fx_line,
23228 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23229 name);
23230 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23231 newval = newval | 0x1000;
23232 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23233 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23234 fixP->fx_done = 1;
23235 }
23236
23237
23238 goto thumb_bl_common;
23239
c19d1205 23240 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23241 /* A bl from Thumb state ISA to an internal ARM state function
23242 is converted to a blx. */
23243 if (fixP->fx_addsy
23244 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23245 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23246 && ARM_IS_FUNC (fixP->fx_addsy)
23247 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23248 {
23249 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23250 newval = newval & ~0x1000;
23251 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23252 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23253 fixP->fx_done = 1;
23254 }
23255
23256 thumb_bl_common:
23257
2fc8bdac
ZW
23258 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23259 /* For a BLX instruction, make sure that the relocation is rounded up
23260 to a word boundary. This follows the semantics of the instruction
23261 which specifies that bit 1 of the target address will come from bit
23262 1 of the base address. */
d406f3e4
JB
23263 value = (value + 3) & ~ 3;
23264
23265#ifdef OBJ_ELF
23266 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23267 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23268 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23269#endif
404ff6b5 23270
2b2f5df9
NC
23271 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23272 {
fc289b0a 23273 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23274 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23275 else if ((value & ~0x1ffffff)
23276 && ((value & ~0x1ffffff) != ~0x1ffffff))
23277 as_bad_where (fixP->fx_file, fixP->fx_line,
23278 _("Thumb2 branch out of range"));
23279 }
4a42ebbc
RR
23280
23281 if (fixP->fx_done || !seg->use_rela_p)
23282 encode_thumb2_b_bl_offset (buf, value);
23283
c19d1205 23284 break;
404ff6b5 23285
c19d1205 23286 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23287 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23288 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23289
2fc8bdac 23290 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23291 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23292
2fc8bdac 23293 break;
a737bd4d 23294
2fc8bdac
ZW
23295 case BFD_RELOC_8:
23296 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23297 *buf = value;
c19d1205 23298 break;
a737bd4d 23299
c19d1205 23300 case BFD_RELOC_16:
2fc8bdac 23301 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23302 md_number_to_chars (buf, value, 2);
c19d1205 23303 break;
a737bd4d 23304
c19d1205 23305#ifdef OBJ_ELF
0855e32b
NS
23306 case BFD_RELOC_ARM_TLS_CALL:
23307 case BFD_RELOC_ARM_THM_TLS_CALL:
23308 case BFD_RELOC_ARM_TLS_DESCSEQ:
23309 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23310 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23311 case BFD_RELOC_ARM_TLS_GD32:
23312 case BFD_RELOC_ARM_TLS_LE32:
23313 case BFD_RELOC_ARM_TLS_IE32:
23314 case BFD_RELOC_ARM_TLS_LDM32:
23315 case BFD_RELOC_ARM_TLS_LDO32:
23316 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23317 break;
6c43fab6 23318
c19d1205
ZW
23319 case BFD_RELOC_ARM_GOT32:
23320 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23321 break;
b43420e6
NC
23322
23323 case BFD_RELOC_ARM_GOT_PREL:
23324 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23325 md_number_to_chars (buf, value, 4);
b43420e6
NC
23326 break;
23327
9a6f4e97
NS
23328 case BFD_RELOC_ARM_TARGET2:
23329 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23330 addend here for REL targets, because it won't be written out
23331 during reloc processing later. */
9a6f4e97
NS
23332 if (fixP->fx_done || !seg->use_rela_p)
23333 md_number_to_chars (buf, fixP->fx_offset, 4);
23334 break;
c19d1205 23335#endif
6c43fab6 23336
c19d1205
ZW
23337 case BFD_RELOC_RVA:
23338 case BFD_RELOC_32:
23339 case BFD_RELOC_ARM_TARGET1:
23340 case BFD_RELOC_ARM_ROSEGREL32:
23341 case BFD_RELOC_ARM_SBREL32:
23342 case BFD_RELOC_32_PCREL:
f0927246
NC
23343#ifdef TE_PE
23344 case BFD_RELOC_32_SECREL:
23345#endif
2fc8bdac 23346 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23347#ifdef TE_WINCE
23348 /* For WinCE we only do this for pcrel fixups. */
23349 if (fixP->fx_done || fixP->fx_pcrel)
23350#endif
23351 md_number_to_chars (buf, value, 4);
c19d1205 23352 break;
6c43fab6 23353
c19d1205
ZW
23354#ifdef OBJ_ELF
23355 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23356 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23357 {
23358 newval = md_chars_to_number (buf, 4) & 0x80000000;
23359 if ((value ^ (value >> 1)) & 0x40000000)
23360 {
23361 as_bad_where (fixP->fx_file, fixP->fx_line,
23362 _("rel31 relocation overflow"));
23363 }
23364 newval |= value & 0x7fffffff;
23365 md_number_to_chars (buf, newval, 4);
23366 }
23367 break;
c19d1205 23368#endif
a737bd4d 23369
c19d1205 23370 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23371 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23372 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23373 newval = md_chars_to_number (buf, INSN_SIZE);
23374 else
23375 newval = get_thumb32_insn (buf);
23376 if ((newval & 0x0f200f00) == 0x0d000900)
23377 {
23378 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23379 has permitted values that are multiples of 2, in the range 0
23380 to 510. */
23381 if (value < -510 || value > 510 || (value & 1))
23382 as_bad_where (fixP->fx_file, fixP->fx_line,
23383 _("co-processor offset out of range"));
23384 }
23385 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23386 as_bad_where (fixP->fx_file, fixP->fx_line,
23387 _("co-processor offset out of range"));
23388 cp_off_common:
26d97720 23389 sign = value > 0;
c19d1205
ZW
23390 if (value < 0)
23391 value = -value;
8f06b2d8
PB
23392 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23393 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23394 newval = md_chars_to_number (buf, INSN_SIZE);
23395 else
23396 newval = get_thumb32_insn (buf);
26d97720
NS
23397 if (value == 0)
23398 newval &= 0xffffff00;
23399 else
23400 {
23401 newval &= 0xff7fff00;
9db2f6b4
RL
23402 if ((newval & 0x0f200f00) == 0x0d000900)
23403 {
23404 /* This is a fp16 vstr/vldr.
23405
23406 It requires the immediate offset in the instruction is shifted
23407 left by 1 to be a half-word offset.
23408
23409 Here, left shift by 1 first, and later right shift by 2
23410 should get the right offset. */
23411 value <<= 1;
23412 }
26d97720
NS
23413 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23414 }
8f06b2d8
PB
23415 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23416 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23417 md_number_to_chars (buf, newval, INSN_SIZE);
23418 else
23419 put_thumb32_insn (buf, newval);
c19d1205 23420 break;
a737bd4d 23421
c19d1205 23422 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23423 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23424 if (value < -255 || value > 255)
23425 as_bad_where (fixP->fx_file, fixP->fx_line,
23426 _("co-processor offset out of range"));
df7849c5 23427 value *= 4;
c19d1205 23428 goto cp_off_common;
6c43fab6 23429
c19d1205
ZW
23430 case BFD_RELOC_ARM_THUMB_OFFSET:
23431 newval = md_chars_to_number (buf, THUMB_SIZE);
23432 /* Exactly what ranges, and where the offset is inserted depends
23433 on the type of instruction, we can establish this from the
23434 top 4 bits. */
23435 switch (newval >> 12)
23436 {
23437 case 4: /* PC load. */
23438 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23439 forced to zero for these loads; md_pcrel_from has already
23440 compensated for this. */
23441 if (value & 3)
23442 as_bad_where (fixP->fx_file, fixP->fx_line,
23443 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23444 (((unsigned long) fixP->fx_frag->fr_address
23445 + (unsigned long) fixP->fx_where) & ~3)
23446 + (unsigned long) value);
a737bd4d 23447
c19d1205
ZW
23448 if (value & ~0x3fc)
23449 as_bad_where (fixP->fx_file, fixP->fx_line,
23450 _("invalid offset, value too big (0x%08lX)"),
23451 (long) value);
a737bd4d 23452
c19d1205
ZW
23453 newval |= value >> 2;
23454 break;
a737bd4d 23455
c19d1205
ZW
23456 case 9: /* SP load/store. */
23457 if (value & ~0x3fc)
23458 as_bad_where (fixP->fx_file, fixP->fx_line,
23459 _("invalid offset, value too big (0x%08lX)"),
23460 (long) value);
23461 newval |= value >> 2;
23462 break;
6c43fab6 23463
c19d1205
ZW
23464 case 6: /* Word load/store. */
23465 if (value & ~0x7c)
23466 as_bad_where (fixP->fx_file, fixP->fx_line,
23467 _("invalid offset, value too big (0x%08lX)"),
23468 (long) value);
23469 newval |= value << 4; /* 6 - 2. */
23470 break;
a737bd4d 23471
c19d1205
ZW
23472 case 7: /* Byte load/store. */
23473 if (value & ~0x1f)
23474 as_bad_where (fixP->fx_file, fixP->fx_line,
23475 _("invalid offset, value too big (0x%08lX)"),
23476 (long) value);
23477 newval |= value << 6;
23478 break;
a737bd4d 23479
c19d1205
ZW
23480 case 8: /* Halfword load/store. */
23481 if (value & ~0x3e)
23482 as_bad_where (fixP->fx_file, fixP->fx_line,
23483 _("invalid offset, value too big (0x%08lX)"),
23484 (long) value);
23485 newval |= value << 5; /* 6 - 1. */
23486 break;
a737bd4d 23487
c19d1205
ZW
23488 default:
23489 as_bad_where (fixP->fx_file, fixP->fx_line,
23490 "Unable to process relocation for thumb opcode: %lx",
23491 (unsigned long) newval);
23492 break;
23493 }
23494 md_number_to_chars (buf, newval, THUMB_SIZE);
23495 break;
a737bd4d 23496
c19d1205
ZW
23497 case BFD_RELOC_ARM_THUMB_ADD:
23498 /* This is a complicated relocation, since we use it for all of
23499 the following immediate relocations:
a737bd4d 23500
c19d1205
ZW
23501 3bit ADD/SUB
23502 8bit ADD/SUB
23503 9bit ADD/SUB SP word-aligned
23504 10bit ADD PC/SP word-aligned
a737bd4d 23505
c19d1205
ZW
23506 The type of instruction being processed is encoded in the
23507 instruction field:
a737bd4d 23508
c19d1205
ZW
23509 0x8000 SUB
23510 0x00F0 Rd
23511 0x000F Rs
23512 */
23513 newval = md_chars_to_number (buf, THUMB_SIZE);
23514 {
23515 int rd = (newval >> 4) & 0xf;
23516 int rs = newval & 0xf;
23517 int subtract = !!(newval & 0x8000);
a737bd4d 23518
c19d1205
ZW
23519 /* Check for HI regs, only very restricted cases allowed:
23520 Adjusting SP, and using PC or SP to get an address. */
23521 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23522 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23523 as_bad_where (fixP->fx_file, fixP->fx_line,
23524 _("invalid Hi register with immediate"));
a737bd4d 23525
c19d1205
ZW
23526 /* If value is negative, choose the opposite instruction. */
23527 if (value < 0)
23528 {
23529 value = -value;
23530 subtract = !subtract;
23531 if (value < 0)
23532 as_bad_where (fixP->fx_file, fixP->fx_line,
23533 _("immediate value out of range"));
23534 }
a737bd4d 23535
c19d1205
ZW
23536 if (rd == REG_SP)
23537 {
75c11999 23538 if (value & ~0x1fc)
c19d1205
ZW
23539 as_bad_where (fixP->fx_file, fixP->fx_line,
23540 _("invalid immediate for stack address calculation"));
23541 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23542 newval |= value >> 2;
23543 }
23544 else if (rs == REG_PC || rs == REG_SP)
23545 {
c12d2c9d
NC
23546 /* PR gas/18541. If the addition is for a defined symbol
23547 within range of an ADR instruction then accept it. */
23548 if (subtract
23549 && value == 4
23550 && fixP->fx_addsy != NULL)
23551 {
23552 subtract = 0;
23553
23554 if (! S_IS_DEFINED (fixP->fx_addsy)
23555 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23556 || S_IS_WEAK (fixP->fx_addsy))
23557 {
23558 as_bad_where (fixP->fx_file, fixP->fx_line,
23559 _("address calculation needs a strongly defined nearby symbol"));
23560 }
23561 else
23562 {
23563 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23564
23565 /* Round up to the next 4-byte boundary. */
23566 if (v & 3)
23567 v = (v + 3) & ~ 3;
23568 else
23569 v += 4;
23570 v = S_GET_VALUE (fixP->fx_addsy) - v;
23571
23572 if (v & ~0x3fc)
23573 {
23574 as_bad_where (fixP->fx_file, fixP->fx_line,
23575 _("symbol too far away"));
23576 }
23577 else
23578 {
23579 fixP->fx_done = 1;
23580 value = v;
23581 }
23582 }
23583 }
23584
c19d1205
ZW
23585 if (subtract || value & ~0x3fc)
23586 as_bad_where (fixP->fx_file, fixP->fx_line,
23587 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23588 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23589 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23590 newval |= rd << 8;
23591 newval |= value >> 2;
23592 }
23593 else if (rs == rd)
23594 {
23595 if (value & ~0xff)
23596 as_bad_where (fixP->fx_file, fixP->fx_line,
23597 _("immediate value out of range"));
23598 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23599 newval |= (rd << 8) | value;
23600 }
23601 else
23602 {
23603 if (value & ~0x7)
23604 as_bad_where (fixP->fx_file, fixP->fx_line,
23605 _("immediate value out of range"));
23606 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23607 newval |= rd | (rs << 3) | (value << 6);
23608 }
23609 }
23610 md_number_to_chars (buf, newval, THUMB_SIZE);
23611 break;
a737bd4d 23612
c19d1205
ZW
23613 case BFD_RELOC_ARM_THUMB_IMM:
23614 newval = md_chars_to_number (buf, THUMB_SIZE);
23615 if (value < 0 || value > 255)
23616 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23617 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23618 (long) value);
23619 newval |= value;
23620 md_number_to_chars (buf, newval, THUMB_SIZE);
23621 break;
a737bd4d 23622
c19d1205
ZW
23623 case BFD_RELOC_ARM_THUMB_SHIFT:
23624 /* 5bit shift value (0..32). LSL cannot take 32. */
23625 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23626 temp = newval & 0xf800;
23627 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23628 as_bad_where (fixP->fx_file, fixP->fx_line,
23629 _("invalid shift value: %ld"), (long) value);
23630 /* Shifts of zero must be encoded as LSL. */
23631 if (value == 0)
23632 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23633 /* Shifts of 32 are encoded as zero. */
23634 else if (value == 32)
23635 value = 0;
23636 newval |= value << 6;
23637 md_number_to_chars (buf, newval, THUMB_SIZE);
23638 break;
a737bd4d 23639
c19d1205
ZW
23640 case BFD_RELOC_VTABLE_INHERIT:
23641 case BFD_RELOC_VTABLE_ENTRY:
23642 fixP->fx_done = 0;
23643 return;
6c43fab6 23644
b6895b4f
PB
23645 case BFD_RELOC_ARM_MOVW:
23646 case BFD_RELOC_ARM_MOVT:
23647 case BFD_RELOC_ARM_THUMB_MOVW:
23648 case BFD_RELOC_ARM_THUMB_MOVT:
23649 if (fixP->fx_done || !seg->use_rela_p)
23650 {
23651 /* REL format relocations are limited to a 16-bit addend. */
23652 if (!fixP->fx_done)
23653 {
39623e12 23654 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23655 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23656 _("offset out of range"));
b6895b4f
PB
23657 }
23658 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23659 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23660 {
23661 value >>= 16;
23662 }
23663
23664 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23665 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23666 {
23667 newval = get_thumb32_insn (buf);
23668 newval &= 0xfbf08f00;
23669 newval |= (value & 0xf000) << 4;
23670 newval |= (value & 0x0800) << 15;
23671 newval |= (value & 0x0700) << 4;
23672 newval |= (value & 0x00ff);
23673 put_thumb32_insn (buf, newval);
23674 }
23675 else
23676 {
23677 newval = md_chars_to_number (buf, 4);
23678 newval &= 0xfff0f000;
23679 newval |= value & 0x0fff;
23680 newval |= (value & 0xf000) << 4;
23681 md_number_to_chars (buf, newval, 4);
23682 }
23683 }
23684 return;
23685
72d98d16
MG
23686 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23687 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23688 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23689 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23690 gas_assert (!fixP->fx_done);
23691 {
23692 bfd_vma insn;
23693 bfd_boolean is_mov;
23694 bfd_vma encoded_addend = value;
23695
23696 /* Check that addend can be encoded in instruction. */
23697 if (!seg->use_rela_p && (value < 0 || value > 255))
23698 as_bad_where (fixP->fx_file, fixP->fx_line,
23699 _("the offset 0x%08lX is not representable"),
23700 (unsigned long) encoded_addend);
23701
23702 /* Extract the instruction. */
23703 insn = md_chars_to_number (buf, THUMB_SIZE);
23704 is_mov = (insn & 0xf800) == 0x2000;
23705
23706 /* Encode insn. */
23707 if (is_mov)
23708 {
23709 if (!seg->use_rela_p)
23710 insn |= encoded_addend;
23711 }
23712 else
23713 {
23714 int rd, rs;
23715
23716 /* Extract the instruction. */
23717 /* Encoding is the following
23718 0x8000 SUB
23719 0x00F0 Rd
23720 0x000F Rs
23721 */
23722 /* The following conditions must be true :
23723 - ADD
23724 - Rd == Rs
23725 - Rd <= 7
23726 */
23727 rd = (insn >> 4) & 0xf;
23728 rs = insn & 0xf;
23729 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23730 as_bad_where (fixP->fx_file, fixP->fx_line,
23731 _("Unable to process relocation for thumb opcode: %lx"),
23732 (unsigned long) insn);
23733
23734 /* Encode as ADD immediate8 thumb 1 code. */
23735 insn = 0x3000 | (rd << 8);
23736
23737 /* Place the encoded addend into the first 8 bits of the
23738 instruction. */
23739 if (!seg->use_rela_p)
23740 insn |= encoded_addend;
23741 }
23742
23743 /* Update the instruction. */
23744 md_number_to_chars (buf, insn, THUMB_SIZE);
23745 }
23746 break;
23747
4962c51a
MS
23748 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23749 case BFD_RELOC_ARM_ALU_PC_G0:
23750 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23751 case BFD_RELOC_ARM_ALU_PC_G1:
23752 case BFD_RELOC_ARM_ALU_PC_G2:
23753 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23754 case BFD_RELOC_ARM_ALU_SB_G0:
23755 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23756 case BFD_RELOC_ARM_ALU_SB_G1:
23757 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23758 gas_assert (!fixP->fx_done);
4962c51a
MS
23759 if (!seg->use_rela_p)
23760 {
477330fc
RM
23761 bfd_vma insn;
23762 bfd_vma encoded_addend;
23763 bfd_vma addend_abs = abs (value);
23764
23765 /* Check that the absolute value of the addend can be
23766 expressed as an 8-bit constant plus a rotation. */
23767 encoded_addend = encode_arm_immediate (addend_abs);
23768 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23769 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23770 _("the offset 0x%08lX is not representable"),
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 positive, use an ADD instruction.
23777 Otherwise use a SUB. Take care not to destroy the S bit. */
23778 insn &= 0xff1fffff;
23779 if (value < 0)
23780 insn |= 1 << 22;
23781 else
23782 insn |= 1 << 23;
23783
23784 /* Place the encoded addend into the first 12 bits of the
23785 instruction. */
23786 insn &= 0xfffff000;
23787 insn |= encoded_addend;
23788
23789 /* Update the instruction. */
23790 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23791 }
23792 break;
23793
23794 case BFD_RELOC_ARM_LDR_PC_G0:
23795 case BFD_RELOC_ARM_LDR_PC_G1:
23796 case BFD_RELOC_ARM_LDR_PC_G2:
23797 case BFD_RELOC_ARM_LDR_SB_G0:
23798 case BFD_RELOC_ARM_LDR_SB_G1:
23799 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23800 gas_assert (!fixP->fx_done);
4962c51a 23801 if (!seg->use_rela_p)
477330fc
RM
23802 {
23803 bfd_vma insn;
23804 bfd_vma addend_abs = abs (value);
4962c51a 23805
477330fc
RM
23806 /* Check that the absolute value of the addend can be
23807 encoded in 12 bits. */
23808 if (addend_abs >= 0x1000)
4962c51a 23809 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23810 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23811 (unsigned long) addend_abs);
23812
23813 /* Extract the instruction. */
23814 insn = md_chars_to_number (buf, INSN_SIZE);
23815
23816 /* If the addend is negative, clear bit 23 of the instruction.
23817 Otherwise set it. */
23818 if (value < 0)
23819 insn &= ~(1 << 23);
23820 else
23821 insn |= 1 << 23;
23822
23823 /* Place the absolute value of the addend into the first 12 bits
23824 of the instruction. */
23825 insn &= 0xfffff000;
23826 insn |= addend_abs;
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_LDRS_PC_G0:
23834 case BFD_RELOC_ARM_LDRS_PC_G1:
23835 case BFD_RELOC_ARM_LDRS_PC_G2:
23836 case BFD_RELOC_ARM_LDRS_SB_G0:
23837 case BFD_RELOC_ARM_LDRS_SB_G1:
23838 case BFD_RELOC_ARM_LDRS_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 can be
23846 encoded in 8 bits. */
23847 if (addend_abs >= 0x100)
4962c51a 23848 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23849 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23850 (unsigned long) addend_abs);
23851
23852 /* Extract the instruction. */
23853 insn = md_chars_to_number (buf, INSN_SIZE);
23854
23855 /* If the addend is negative, clear bit 23 of the instruction.
23856 Otherwise set it. */
23857 if (value < 0)
23858 insn &= ~(1 << 23);
23859 else
23860 insn |= 1 << 23;
23861
23862 /* Place the first four bits of the absolute value of the addend
23863 into the first 4 bits of the instruction, and the remaining
23864 four into bits 8 .. 11. */
23865 insn &= 0xfffff0f0;
23866 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23867
23868 /* Update the instruction. */
23869 md_number_to_chars (buf, insn, INSN_SIZE);
23870 }
4962c51a
MS
23871 break;
23872
23873 case BFD_RELOC_ARM_LDC_PC_G0:
23874 case BFD_RELOC_ARM_LDC_PC_G1:
23875 case BFD_RELOC_ARM_LDC_PC_G2:
23876 case BFD_RELOC_ARM_LDC_SB_G0:
23877 case BFD_RELOC_ARM_LDC_SB_G1:
23878 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23879 gas_assert (!fixP->fx_done);
4962c51a 23880 if (!seg->use_rela_p)
477330fc
RM
23881 {
23882 bfd_vma insn;
23883 bfd_vma addend_abs = abs (value);
4962c51a 23884
477330fc
RM
23885 /* Check that the absolute value of the addend is a multiple of
23886 four and, when divided by four, fits in 8 bits. */
23887 if (addend_abs & 0x3)
4962c51a 23888 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23889 _("bad offset 0x%08lX (must be word-aligned)"),
23890 (unsigned long) addend_abs);
4962c51a 23891
477330fc 23892 if ((addend_abs >> 2) > 0xff)
4962c51a 23893 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23894 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23895 (unsigned long) addend_abs);
23896
23897 /* Extract the instruction. */
23898 insn = md_chars_to_number (buf, INSN_SIZE);
23899
23900 /* If the addend is negative, clear bit 23 of the instruction.
23901 Otherwise set it. */
23902 if (value < 0)
23903 insn &= ~(1 << 23);
23904 else
23905 insn |= 1 << 23;
23906
23907 /* Place the addend (divided by four) into the first eight
23908 bits of the instruction. */
23909 insn &= 0xfffffff0;
23910 insn |= addend_abs >> 2;
23911
23912 /* Update the instruction. */
23913 md_number_to_chars (buf, insn, INSN_SIZE);
23914 }
4962c51a
MS
23915 break;
23916
845b51d6
PB
23917 case BFD_RELOC_ARM_V4BX:
23918 /* This will need to go in the object file. */
23919 fixP->fx_done = 0;
23920 break;
23921
c19d1205
ZW
23922 case BFD_RELOC_UNUSED:
23923 default:
23924 as_bad_where (fixP->fx_file, fixP->fx_line,
23925 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23926 }
6c43fab6
RE
23927}
23928
c19d1205
ZW
23929/* Translate internal representation of relocation info to BFD target
23930 format. */
a737bd4d 23931
c19d1205 23932arelent *
00a97672 23933tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 23934{
c19d1205
ZW
23935 arelent * reloc;
23936 bfd_reloc_code_real_type code;
a737bd4d 23937
21d799b5 23938 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 23939
21d799b5 23940 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
23941 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23942 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 23943
2fc8bdac 23944 if (fixp->fx_pcrel)
00a97672
RS
23945 {
23946 if (section->use_rela_p)
23947 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23948 else
23949 fixp->fx_offset = reloc->address;
23950 }
c19d1205 23951 reloc->addend = fixp->fx_offset;
a737bd4d 23952
c19d1205 23953 switch (fixp->fx_r_type)
a737bd4d 23954 {
c19d1205
ZW
23955 case BFD_RELOC_8:
23956 if (fixp->fx_pcrel)
23957 {
23958 code = BFD_RELOC_8_PCREL;
23959 break;
23960 }
a737bd4d 23961
c19d1205
ZW
23962 case BFD_RELOC_16:
23963 if (fixp->fx_pcrel)
23964 {
23965 code = BFD_RELOC_16_PCREL;
23966 break;
23967 }
6c43fab6 23968
c19d1205
ZW
23969 case BFD_RELOC_32:
23970 if (fixp->fx_pcrel)
23971 {
23972 code = BFD_RELOC_32_PCREL;
23973 break;
23974 }
a737bd4d 23975
b6895b4f
PB
23976 case BFD_RELOC_ARM_MOVW:
23977 if (fixp->fx_pcrel)
23978 {
23979 code = BFD_RELOC_ARM_MOVW_PCREL;
23980 break;
23981 }
23982
23983 case BFD_RELOC_ARM_MOVT:
23984 if (fixp->fx_pcrel)
23985 {
23986 code = BFD_RELOC_ARM_MOVT_PCREL;
23987 break;
23988 }
23989
23990 case BFD_RELOC_ARM_THUMB_MOVW:
23991 if (fixp->fx_pcrel)
23992 {
23993 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23994 break;
23995 }
23996
23997 case BFD_RELOC_ARM_THUMB_MOVT:
23998 if (fixp->fx_pcrel)
23999 {
24000 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24001 break;
24002 }
24003
c19d1205
ZW
24004 case BFD_RELOC_NONE:
24005 case BFD_RELOC_ARM_PCREL_BRANCH:
24006 case BFD_RELOC_ARM_PCREL_BLX:
24007 case BFD_RELOC_RVA:
24008 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24009 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24010 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24011 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24012 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24013 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24014 case BFD_RELOC_VTABLE_ENTRY:
24015 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24016#ifdef TE_PE
24017 case BFD_RELOC_32_SECREL:
24018#endif
c19d1205
ZW
24019 code = fixp->fx_r_type;
24020 break;
a737bd4d 24021
00adf2d4
JB
24022 case BFD_RELOC_THUMB_PCREL_BLX:
24023#ifdef OBJ_ELF
24024 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24025 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24026 else
24027#endif
24028 code = BFD_RELOC_THUMB_PCREL_BLX;
24029 break;
24030
c19d1205
ZW
24031 case BFD_RELOC_ARM_LITERAL:
24032 case BFD_RELOC_ARM_HWLITERAL:
24033 /* If this is called then the a literal has
24034 been referenced across a section boundary. */
24035 as_bad_where (fixp->fx_file, fixp->fx_line,
24036 _("literal referenced across section boundary"));
24037 return NULL;
a737bd4d 24038
c19d1205 24039#ifdef OBJ_ELF
0855e32b
NS
24040 case BFD_RELOC_ARM_TLS_CALL:
24041 case BFD_RELOC_ARM_THM_TLS_CALL:
24042 case BFD_RELOC_ARM_TLS_DESCSEQ:
24043 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24044 case BFD_RELOC_ARM_GOT32:
24045 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24046 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24047 case BFD_RELOC_ARM_PLT32:
24048 case BFD_RELOC_ARM_TARGET1:
24049 case BFD_RELOC_ARM_ROSEGREL32:
24050 case BFD_RELOC_ARM_SBREL32:
24051 case BFD_RELOC_ARM_PREL31:
24052 case BFD_RELOC_ARM_TARGET2:
c19d1205 24053 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24054 case BFD_RELOC_ARM_PCREL_CALL:
24055 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24056 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24057 case BFD_RELOC_ARM_ALU_PC_G0:
24058 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24059 case BFD_RELOC_ARM_ALU_PC_G1:
24060 case BFD_RELOC_ARM_ALU_PC_G2:
24061 case BFD_RELOC_ARM_LDR_PC_G0:
24062 case BFD_RELOC_ARM_LDR_PC_G1:
24063 case BFD_RELOC_ARM_LDR_PC_G2:
24064 case BFD_RELOC_ARM_LDRS_PC_G0:
24065 case BFD_RELOC_ARM_LDRS_PC_G1:
24066 case BFD_RELOC_ARM_LDRS_PC_G2:
24067 case BFD_RELOC_ARM_LDC_PC_G0:
24068 case BFD_RELOC_ARM_LDC_PC_G1:
24069 case BFD_RELOC_ARM_LDC_PC_G2:
24070 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24071 case BFD_RELOC_ARM_ALU_SB_G0:
24072 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24073 case BFD_RELOC_ARM_ALU_SB_G1:
24074 case BFD_RELOC_ARM_ALU_SB_G2:
24075 case BFD_RELOC_ARM_LDR_SB_G0:
24076 case BFD_RELOC_ARM_LDR_SB_G1:
24077 case BFD_RELOC_ARM_LDR_SB_G2:
24078 case BFD_RELOC_ARM_LDRS_SB_G0:
24079 case BFD_RELOC_ARM_LDRS_SB_G1:
24080 case BFD_RELOC_ARM_LDRS_SB_G2:
24081 case BFD_RELOC_ARM_LDC_SB_G0:
24082 case BFD_RELOC_ARM_LDC_SB_G1:
24083 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24084 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24085 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24086 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24087 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24088 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24089 code = fixp->fx_r_type;
24090 break;
a737bd4d 24091
0855e32b 24092 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24093 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24094 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24095 case BFD_RELOC_ARM_TLS_IE32:
24096 case BFD_RELOC_ARM_TLS_LDM32:
24097 /* BFD will include the symbol's address in the addend.
24098 But we don't want that, so subtract it out again here. */
24099 if (!S_IS_COMMON (fixp->fx_addsy))
24100 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24101 code = fixp->fx_r_type;
24102 break;
24103#endif
a737bd4d 24104
c19d1205
ZW
24105 case BFD_RELOC_ARM_IMMEDIATE:
24106 as_bad_where (fixp->fx_file, fixp->fx_line,
24107 _("internal relocation (type: IMMEDIATE) not fixed up"));
24108 return NULL;
a737bd4d 24109
c19d1205
ZW
24110 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24111 as_bad_where (fixp->fx_file, fixp->fx_line,
24112 _("ADRL used for a symbol not defined in the same file"));
24113 return NULL;
a737bd4d 24114
c19d1205 24115 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24116 if (section->use_rela_p)
24117 {
24118 code = fixp->fx_r_type;
24119 break;
24120 }
24121
c19d1205
ZW
24122 if (fixp->fx_addsy != NULL
24123 && !S_IS_DEFINED (fixp->fx_addsy)
24124 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24125 {
c19d1205
ZW
24126 as_bad_where (fixp->fx_file, fixp->fx_line,
24127 _("undefined local label `%s'"),
24128 S_GET_NAME (fixp->fx_addsy));
24129 return NULL;
a737bd4d
NC
24130 }
24131
c19d1205
ZW
24132 as_bad_where (fixp->fx_file, fixp->fx_line,
24133 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24134 return NULL;
a737bd4d 24135
c19d1205
ZW
24136 default:
24137 {
e0471c16 24138 const char * type;
6c43fab6 24139
c19d1205
ZW
24140 switch (fixp->fx_r_type)
24141 {
24142 case BFD_RELOC_NONE: type = "NONE"; break;
24143 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24144 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24145 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24146 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24147 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24148 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24149 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24150 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24151 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24152 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24153 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24154 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24155 default: type = _("<unknown>"); break;
24156 }
24157 as_bad_where (fixp->fx_file, fixp->fx_line,
24158 _("cannot represent %s relocation in this object file format"),
24159 type);
24160 return NULL;
24161 }
a737bd4d 24162 }
6c43fab6 24163
c19d1205
ZW
24164#ifdef OBJ_ELF
24165 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24166 && GOT_symbol
24167 && fixp->fx_addsy == GOT_symbol)
24168 {
24169 code = BFD_RELOC_ARM_GOTPC;
24170 reloc->addend = fixp->fx_offset = reloc->address;
24171 }
24172#endif
6c43fab6 24173
c19d1205 24174 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24175
c19d1205
ZW
24176 if (reloc->howto == NULL)
24177 {
24178 as_bad_where (fixp->fx_file, fixp->fx_line,
24179 _("cannot represent %s relocation in this object file format"),
24180 bfd_get_reloc_code_name (code));
24181 return NULL;
24182 }
6c43fab6 24183
c19d1205
ZW
24184 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24185 vtable entry to be used in the relocation's section offset. */
24186 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24187 reloc->address = fixp->fx_offset;
6c43fab6 24188
c19d1205 24189 return reloc;
6c43fab6
RE
24190}
24191
c19d1205 24192/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24193
c19d1205
ZW
24194void
24195cons_fix_new_arm (fragS * frag,
24196 int where,
24197 int size,
62ebcb5c
AM
24198 expressionS * exp,
24199 bfd_reloc_code_real_type reloc)
6c43fab6 24200{
c19d1205 24201 int pcrel = 0;
6c43fab6 24202
c19d1205
ZW
24203 /* Pick a reloc.
24204 FIXME: @@ Should look at CPU word size. */
24205 switch (size)
24206 {
24207 case 1:
62ebcb5c 24208 reloc = BFD_RELOC_8;
c19d1205
ZW
24209 break;
24210 case 2:
62ebcb5c 24211 reloc = BFD_RELOC_16;
c19d1205
ZW
24212 break;
24213 case 4:
24214 default:
62ebcb5c 24215 reloc = BFD_RELOC_32;
c19d1205
ZW
24216 break;
24217 case 8:
62ebcb5c 24218 reloc = BFD_RELOC_64;
c19d1205
ZW
24219 break;
24220 }
6c43fab6 24221
f0927246
NC
24222#ifdef TE_PE
24223 if (exp->X_op == O_secrel)
24224 {
24225 exp->X_op = O_symbol;
62ebcb5c 24226 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24227 }
24228#endif
24229
62ebcb5c 24230 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24231}
6c43fab6 24232
4343666d 24233#if defined (OBJ_COFF)
c19d1205
ZW
24234void
24235arm_validate_fix (fixS * fixP)
6c43fab6 24236{
c19d1205
ZW
24237 /* If the destination of the branch is a defined symbol which does not have
24238 the THUMB_FUNC attribute, then we must be calling a function which has
24239 the (interfacearm) attribute. We look for the Thumb entry point to that
24240 function and change the branch to refer to that function instead. */
24241 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24242 && fixP->fx_addsy != NULL
24243 && S_IS_DEFINED (fixP->fx_addsy)
24244 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24245 {
c19d1205 24246 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24247 }
c19d1205
ZW
24248}
24249#endif
6c43fab6 24250
267bf995 24251
c19d1205
ZW
24252int
24253arm_force_relocation (struct fix * fixp)
24254{
24255#if defined (OBJ_COFF) && defined (TE_PE)
24256 if (fixp->fx_r_type == BFD_RELOC_RVA)
24257 return 1;
24258#endif
6c43fab6 24259
267bf995
RR
24260 /* In case we have a call or a branch to a function in ARM ISA mode from
24261 a thumb function or vice-versa force the relocation. These relocations
24262 are cleared off for some cores that might have blx and simple transformations
24263 are possible. */
24264
24265#ifdef OBJ_ELF
24266 switch (fixp->fx_r_type)
24267 {
24268 case BFD_RELOC_ARM_PCREL_JUMP:
24269 case BFD_RELOC_ARM_PCREL_CALL:
24270 case BFD_RELOC_THUMB_PCREL_BLX:
24271 if (THUMB_IS_FUNC (fixp->fx_addsy))
24272 return 1;
24273 break;
24274
24275 case BFD_RELOC_ARM_PCREL_BLX:
24276 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24277 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24278 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24279 if (ARM_IS_FUNC (fixp->fx_addsy))
24280 return 1;
24281 break;
24282
24283 default:
24284 break;
24285 }
24286#endif
24287
b5884301
PB
24288 /* Resolve these relocations even if the symbol is extern or weak.
24289 Technically this is probably wrong due to symbol preemption.
24290 In practice these relocations do not have enough range to be useful
24291 at dynamic link time, and some code (e.g. in the Linux kernel)
24292 expects these references to be resolved. */
c19d1205
ZW
24293 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24294 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24295 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24296 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24297 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24298 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24299 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24300 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24301 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24302 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24303 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24304 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24305 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24306 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24307 return 0;
a737bd4d 24308
4962c51a
MS
24309 /* Always leave these relocations for the linker. */
24310 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24311 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24312 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24313 return 1;
24314
f0291e4c
PB
24315 /* Always generate relocations against function symbols. */
24316 if (fixp->fx_r_type == BFD_RELOC_32
24317 && fixp->fx_addsy
24318 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24319 return 1;
24320
c19d1205 24321 return generic_force_reloc (fixp);
404ff6b5
AH
24322}
24323
0ffdc86c 24324#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24325/* Relocations against function names must be left unadjusted,
24326 so that the linker can use this information to generate interworking
24327 stubs. The MIPS version of this function
c19d1205
ZW
24328 also prevents relocations that are mips-16 specific, but I do not
24329 know why it does this.
404ff6b5 24330
c19d1205
ZW
24331 FIXME:
24332 There is one other problem that ought to be addressed here, but
24333 which currently is not: Taking the address of a label (rather
24334 than a function) and then later jumping to that address. Such
24335 addresses also ought to have their bottom bit set (assuming that
24336 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24337
c19d1205
ZW
24338bfd_boolean
24339arm_fix_adjustable (fixS * fixP)
404ff6b5 24340{
c19d1205
ZW
24341 if (fixP->fx_addsy == NULL)
24342 return 1;
404ff6b5 24343
e28387c3
PB
24344 /* Preserve relocations against symbols with function type. */
24345 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24346 return FALSE;
e28387c3 24347
c19d1205
ZW
24348 if (THUMB_IS_FUNC (fixP->fx_addsy)
24349 && fixP->fx_subsy == NULL)
c921be7d 24350 return FALSE;
a737bd4d 24351
c19d1205
ZW
24352 /* We need the symbol name for the VTABLE entries. */
24353 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24354 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24355 return FALSE;
404ff6b5 24356
c19d1205
ZW
24357 /* Don't allow symbols to be discarded on GOT related relocs. */
24358 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24359 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24360 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24361 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24362 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24363 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24364 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24365 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24366 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24367 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24368 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24369 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24370 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24371 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24372 return FALSE;
a737bd4d 24373
4962c51a
MS
24374 /* Similarly for group relocations. */
24375 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24376 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24377 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24378 return FALSE;
4962c51a 24379
79947c54
CD
24380 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24381 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24382 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24383 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24384 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24385 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24386 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24387 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24388 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24389 return FALSE;
79947c54 24390
72d98d16
MG
24391 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24392 offsets, so keep these symbols. */
24393 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24394 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24395 return FALSE;
24396
c921be7d 24397 return TRUE;
a737bd4d 24398}
0ffdc86c
NC
24399#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24400
24401#ifdef OBJ_ELF
c19d1205
ZW
24402const char *
24403elf32_arm_target_format (void)
404ff6b5 24404{
c19d1205
ZW
24405#ifdef TE_SYMBIAN
24406 return (target_big_endian
24407 ? "elf32-bigarm-symbian"
24408 : "elf32-littlearm-symbian");
24409#elif defined (TE_VXWORKS)
24410 return (target_big_endian
24411 ? "elf32-bigarm-vxworks"
24412 : "elf32-littlearm-vxworks");
b38cadfb
NC
24413#elif defined (TE_NACL)
24414 return (target_big_endian
24415 ? "elf32-bigarm-nacl"
24416 : "elf32-littlearm-nacl");
c19d1205
ZW
24417#else
24418 if (target_big_endian)
24419 return "elf32-bigarm";
24420 else
24421 return "elf32-littlearm";
24422#endif
404ff6b5
AH
24423}
24424
c19d1205
ZW
24425void
24426armelf_frob_symbol (symbolS * symp,
24427 int * puntp)
404ff6b5 24428{
c19d1205
ZW
24429 elf_frob_symbol (symp, puntp);
24430}
24431#endif
404ff6b5 24432
c19d1205 24433/* MD interface: Finalization. */
a737bd4d 24434
c19d1205
ZW
24435void
24436arm_cleanup (void)
24437{
24438 literal_pool * pool;
a737bd4d 24439
e07e6e58
NC
24440 /* Ensure that all the IT blocks are properly closed. */
24441 check_it_blocks_finished ();
24442
c19d1205
ZW
24443 for (pool = list_of_pools; pool; pool = pool->next)
24444 {
5f4273c7 24445 /* Put it at the end of the relevant section. */
c19d1205
ZW
24446 subseg_set (pool->section, pool->sub_section);
24447#ifdef OBJ_ELF
24448 arm_elf_change_section ();
24449#endif
24450 s_ltorg (0);
24451 }
404ff6b5
AH
24452}
24453
cd000bff
DJ
24454#ifdef OBJ_ELF
24455/* Remove any excess mapping symbols generated for alignment frags in
24456 SEC. We may have created a mapping symbol before a zero byte
24457 alignment; remove it if there's a mapping symbol after the
24458 alignment. */
24459static void
24460check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24461 void *dummy ATTRIBUTE_UNUSED)
24462{
24463 segment_info_type *seginfo = seg_info (sec);
24464 fragS *fragp;
24465
24466 if (seginfo == NULL || seginfo->frchainP == NULL)
24467 return;
24468
24469 for (fragp = seginfo->frchainP->frch_root;
24470 fragp != NULL;
24471 fragp = fragp->fr_next)
24472 {
24473 symbolS *sym = fragp->tc_frag_data.last_map;
24474 fragS *next = fragp->fr_next;
24475
24476 /* Variable-sized frags have been converted to fixed size by
24477 this point. But if this was variable-sized to start with,
24478 there will be a fixed-size frag after it. So don't handle
24479 next == NULL. */
24480 if (sym == NULL || next == NULL)
24481 continue;
24482
24483 if (S_GET_VALUE (sym) < next->fr_address)
24484 /* Not at the end of this frag. */
24485 continue;
24486 know (S_GET_VALUE (sym) == next->fr_address);
24487
24488 do
24489 {
24490 if (next->tc_frag_data.first_map != NULL)
24491 {
24492 /* Next frag starts with a mapping symbol. Discard this
24493 one. */
24494 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24495 break;
24496 }
24497
24498 if (next->fr_next == NULL)
24499 {
24500 /* This mapping symbol is at the end of the section. Discard
24501 it. */
24502 know (next->fr_fix == 0 && next->fr_var == 0);
24503 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24504 break;
24505 }
24506
24507 /* As long as we have empty frags without any mapping symbols,
24508 keep looking. */
24509 /* If the next frag is non-empty and does not start with a
24510 mapping symbol, then this mapping symbol is required. */
24511 if (next->fr_address != next->fr_next->fr_address)
24512 break;
24513
24514 next = next->fr_next;
24515 }
24516 while (next != NULL);
24517 }
24518}
24519#endif
24520
c19d1205
ZW
24521/* Adjust the symbol table. This marks Thumb symbols as distinct from
24522 ARM ones. */
404ff6b5 24523
c19d1205
ZW
24524void
24525arm_adjust_symtab (void)
404ff6b5 24526{
c19d1205
ZW
24527#ifdef OBJ_COFF
24528 symbolS * sym;
404ff6b5 24529
c19d1205
ZW
24530 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24531 {
24532 if (ARM_IS_THUMB (sym))
24533 {
24534 if (THUMB_IS_FUNC (sym))
24535 {
24536 /* Mark the symbol as a Thumb function. */
24537 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24538 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24539 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24540
c19d1205
ZW
24541 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24542 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24543 else
24544 as_bad (_("%s: unexpected function type: %d"),
24545 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24546 }
24547 else switch (S_GET_STORAGE_CLASS (sym))
24548 {
24549 case C_EXT:
24550 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24551 break;
24552 case C_STAT:
24553 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24554 break;
24555 case C_LABEL:
24556 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24557 break;
24558 default:
24559 /* Do nothing. */
24560 break;
24561 }
24562 }
a737bd4d 24563
c19d1205
ZW
24564 if (ARM_IS_INTERWORK (sym))
24565 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24566 }
c19d1205
ZW
24567#endif
24568#ifdef OBJ_ELF
24569 symbolS * sym;
24570 char bind;
404ff6b5 24571
c19d1205 24572 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24573 {
c19d1205
ZW
24574 if (ARM_IS_THUMB (sym))
24575 {
24576 elf_symbol_type * elf_sym;
404ff6b5 24577
c19d1205
ZW
24578 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24579 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24580
b0796911
PB
24581 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24582 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24583 {
24584 /* If it's a .thumb_func, declare it as so,
24585 otherwise tag label as .code 16. */
24586 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
24587 elf_sym->internal_elf_sym.st_target_internal
24588 = ST_BRANCH_TO_THUMB;
3ba67470 24589 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24590 elf_sym->internal_elf_sym.st_info =
24591 ELF_ST_INFO (bind, STT_ARM_16BIT);
24592 }
24593 }
24594 }
cd000bff
DJ
24595
24596 /* Remove any overlapping mapping symbols generated by alignment frags. */
24597 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24598 /* Now do generic ELF adjustments. */
24599 elf_adjust_symtab ();
c19d1205 24600#endif
404ff6b5
AH
24601}
24602
c19d1205 24603/* MD interface: Initialization. */
404ff6b5 24604
a737bd4d 24605static void
c19d1205 24606set_constant_flonums (void)
a737bd4d 24607{
c19d1205 24608 int i;
404ff6b5 24609
c19d1205
ZW
24610 for (i = 0; i < NUM_FLOAT_VALS; i++)
24611 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24612 abort ();
a737bd4d 24613}
404ff6b5 24614
3e9e4fcf
JB
24615/* Auto-select Thumb mode if it's the only available instruction set for the
24616 given architecture. */
24617
24618static void
24619autoselect_thumb_from_cpu_variant (void)
24620{
24621 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24622 opcode_select (16);
24623}
24624
c19d1205
ZW
24625void
24626md_begin (void)
a737bd4d 24627{
c19d1205
ZW
24628 unsigned mach;
24629 unsigned int i;
404ff6b5 24630
c19d1205
ZW
24631 if ( (arm_ops_hsh = hash_new ()) == NULL
24632 || (arm_cond_hsh = hash_new ()) == NULL
24633 || (arm_shift_hsh = hash_new ()) == NULL
24634 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24635 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24636 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24637 || (arm_reloc_hsh = hash_new ()) == NULL
24638 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24639 as_fatal (_("virtual memory exhausted"));
24640
24641 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24642 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24643 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24644 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24645 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24646 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24647 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24648 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24649 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24650 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24651 (void *) (v7m_psrs + i));
c19d1205 24652 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24653 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24654 for (i = 0;
24655 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24656 i++)
d3ce72d0 24657 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24658 (void *) (barrier_opt_names + i));
c19d1205 24659#ifdef OBJ_ELF
3da1d841
NC
24660 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24661 {
24662 struct reloc_entry * entry = reloc_names + i;
24663
24664 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24665 /* This makes encode_branch() use the EABI versions of this relocation. */
24666 entry->reloc = BFD_RELOC_UNUSED;
24667
24668 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24669 }
c19d1205
ZW
24670#endif
24671
24672 set_constant_flonums ();
404ff6b5 24673
c19d1205
ZW
24674 /* Set the cpu variant based on the command-line options. We prefer
24675 -mcpu= over -march= if both are set (as for GCC); and we prefer
24676 -mfpu= over any other way of setting the floating point unit.
24677 Use of legacy options with new options are faulted. */
e74cfd16 24678 if (legacy_cpu)
404ff6b5 24679 {
e74cfd16 24680 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24681 as_bad (_("use of old and new-style options to set CPU type"));
24682
24683 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24684 }
e74cfd16 24685 else if (!mcpu_cpu_opt)
c19d1205 24686 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24687
e74cfd16 24688 if (legacy_fpu)
c19d1205 24689 {
e74cfd16 24690 if (mfpu_opt)
c19d1205 24691 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24692
24693 mfpu_opt = legacy_fpu;
24694 }
e74cfd16 24695 else if (!mfpu_opt)
03b1477f 24696 {
45eb4c1b
NS
24697#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24698 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24699 /* Some environments specify a default FPU. If they don't, infer it
24700 from the processor. */
e74cfd16 24701 if (mcpu_fpu_opt)
03b1477f
RE
24702 mfpu_opt = mcpu_fpu_opt;
24703 else
24704 mfpu_opt = march_fpu_opt;
39c2da32 24705#else
e74cfd16 24706 mfpu_opt = &fpu_default;
39c2da32 24707#endif
03b1477f
RE
24708 }
24709
e74cfd16 24710 if (!mfpu_opt)
03b1477f 24711 {
493cb6ef 24712 if (mcpu_cpu_opt != NULL)
e74cfd16 24713 mfpu_opt = &fpu_default;
493cb6ef 24714 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24715 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24716 else
e74cfd16 24717 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24718 }
24719
ee065d83 24720#ifdef CPU_DEFAULT
e74cfd16 24721 if (!mcpu_cpu_opt)
ee065d83 24722 {
e74cfd16
PB
24723 mcpu_cpu_opt = &cpu_default;
24724 selected_cpu = cpu_default;
ee065d83 24725 }
73f43896
NC
24726 else if (no_cpu_selected ())
24727 selected_cpu = cpu_default;
e74cfd16
PB
24728#else
24729 if (mcpu_cpu_opt)
24730 selected_cpu = *mcpu_cpu_opt;
ee065d83 24731 else
e74cfd16 24732 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24733#endif
03b1477f 24734
e74cfd16 24735 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24736
3e9e4fcf
JB
24737 autoselect_thumb_from_cpu_variant ();
24738
e74cfd16 24739 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24740
f17c130b 24741#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24742 {
7cc69913
NC
24743 unsigned int flags = 0;
24744
24745#if defined OBJ_ELF
24746 flags = meabi_flags;
d507cf36
PB
24747
24748 switch (meabi_flags)
33a392fb 24749 {
d507cf36 24750 case EF_ARM_EABI_UNKNOWN:
7cc69913 24751#endif
d507cf36
PB
24752 /* Set the flags in the private structure. */
24753 if (uses_apcs_26) flags |= F_APCS26;
24754 if (support_interwork) flags |= F_INTERWORK;
24755 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24756 if (pic_code) flags |= F_PIC;
e74cfd16 24757 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24758 flags |= F_SOFT_FLOAT;
24759
d507cf36
PB
24760 switch (mfloat_abi_opt)
24761 {
24762 case ARM_FLOAT_ABI_SOFT:
24763 case ARM_FLOAT_ABI_SOFTFP:
24764 flags |= F_SOFT_FLOAT;
24765 break;
33a392fb 24766
d507cf36
PB
24767 case ARM_FLOAT_ABI_HARD:
24768 if (flags & F_SOFT_FLOAT)
24769 as_bad (_("hard-float conflicts with specified fpu"));
24770 break;
24771 }
03b1477f 24772
e74cfd16
PB
24773 /* Using pure-endian doubles (even if soft-float). */
24774 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24775 flags |= F_VFP_FLOAT;
f17c130b 24776
fde78edd 24777#if defined OBJ_ELF
e74cfd16 24778 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24779 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24780 break;
24781
8cb51566 24782 case EF_ARM_EABI_VER4:
3a4a14e9 24783 case EF_ARM_EABI_VER5:
c19d1205 24784 /* No additional flags to set. */
d507cf36
PB
24785 break;
24786
24787 default:
24788 abort ();
24789 }
7cc69913 24790#endif
b99bd4ef
NC
24791 bfd_set_private_flags (stdoutput, flags);
24792
24793 /* We have run out flags in the COFF header to encode the
24794 status of ATPCS support, so instead we create a dummy,
c19d1205 24795 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24796 if (atpcs)
24797 {
24798 asection * sec;
24799
24800 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24801
24802 if (sec != NULL)
24803 {
24804 bfd_set_section_flags
24805 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24806 bfd_set_section_size (stdoutput, sec, 0);
24807 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24808 }
24809 }
7cc69913 24810 }
f17c130b 24811#endif
b99bd4ef
NC
24812
24813 /* Record the CPU type as well. */
2d447fca
JM
24814 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24815 mach = bfd_mach_arm_iWMMXt2;
24816 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24817 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24818 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24819 mach = bfd_mach_arm_XScale;
e74cfd16 24820 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24821 mach = bfd_mach_arm_ep9312;
e74cfd16 24822 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24823 mach = bfd_mach_arm_5TE;
e74cfd16 24824 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24825 {
e74cfd16 24826 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24827 mach = bfd_mach_arm_5T;
24828 else
24829 mach = bfd_mach_arm_5;
24830 }
e74cfd16 24831 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24832 {
e74cfd16 24833 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24834 mach = bfd_mach_arm_4T;
24835 else
24836 mach = bfd_mach_arm_4;
24837 }
e74cfd16 24838 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24839 mach = bfd_mach_arm_3M;
e74cfd16
PB
24840 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24841 mach = bfd_mach_arm_3;
24842 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24843 mach = bfd_mach_arm_2a;
24844 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24845 mach = bfd_mach_arm_2;
24846 else
24847 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24848
24849 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24850}
24851
c19d1205 24852/* Command line processing. */
b99bd4ef 24853
c19d1205
ZW
24854/* md_parse_option
24855 Invocation line includes a switch not recognized by the base assembler.
24856 See if it's a processor-specific option.
b99bd4ef 24857
c19d1205
ZW
24858 This routine is somewhat complicated by the need for backwards
24859 compatibility (since older releases of gcc can't be changed).
24860 The new options try to make the interface as compatible as
24861 possible with GCC.
b99bd4ef 24862
c19d1205 24863 New options (supported) are:
b99bd4ef 24864
c19d1205
ZW
24865 -mcpu=<cpu name> Assemble for selected processor
24866 -march=<architecture name> Assemble for selected architecture
24867 -mfpu=<fpu architecture> Assemble for selected FPU.
24868 -EB/-mbig-endian Big-endian
24869 -EL/-mlittle-endian Little-endian
24870 -k Generate PIC code
24871 -mthumb Start in Thumb mode
24872 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24873
278df34e 24874 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24875 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24876
c19d1205 24877 For now we will also provide support for:
b99bd4ef 24878
c19d1205
ZW
24879 -mapcs-32 32-bit Program counter
24880 -mapcs-26 26-bit Program counter
24881 -macps-float Floats passed in FP registers
24882 -mapcs-reentrant Reentrant code
24883 -matpcs
24884 (sometime these will probably be replaced with -mapcs=<list of options>
24885 and -matpcs=<list of options>)
b99bd4ef 24886
c19d1205
ZW
24887 The remaining options are only supported for back-wards compatibility.
24888 Cpu variants, the arm part is optional:
24889 -m[arm]1 Currently not supported.
24890 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24891 -m[arm]3 Arm 3 processor
24892 -m[arm]6[xx], Arm 6 processors
24893 -m[arm]7[xx][t][[d]m] Arm 7 processors
24894 -m[arm]8[10] Arm 8 processors
24895 -m[arm]9[20][tdmi] Arm 9 processors
24896 -mstrongarm[110[0]] StrongARM processors
24897 -mxscale XScale processors
24898 -m[arm]v[2345[t[e]]] Arm architectures
24899 -mall All (except the ARM1)
24900 FP variants:
24901 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24902 -mfpe-old (No float load/store multiples)
24903 -mvfpxd VFP Single precision
24904 -mvfp All VFP
24905 -mno-fpu Disable all floating point instructions
b99bd4ef 24906
c19d1205
ZW
24907 The following CPU names are recognized:
24908 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24909 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24910 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24911 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24912 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24913 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24914 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24915
c19d1205 24916 */
b99bd4ef 24917
c19d1205 24918const char * md_shortopts = "m:k";
b99bd4ef 24919
c19d1205
ZW
24920#ifdef ARM_BI_ENDIAN
24921#define OPTION_EB (OPTION_MD_BASE + 0)
24922#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24923#else
c19d1205
ZW
24924#if TARGET_BYTES_BIG_ENDIAN
24925#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 24926#else
c19d1205
ZW
24927#define OPTION_EL (OPTION_MD_BASE + 1)
24928#endif
b99bd4ef 24929#endif
845b51d6 24930#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 24931
c19d1205 24932struct option md_longopts[] =
b99bd4ef 24933{
c19d1205
ZW
24934#ifdef OPTION_EB
24935 {"EB", no_argument, NULL, OPTION_EB},
24936#endif
24937#ifdef OPTION_EL
24938 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 24939#endif
845b51d6 24940 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
24941 {NULL, no_argument, NULL, 0}
24942};
b99bd4ef 24943
8b2d793c 24944
c19d1205 24945size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 24946
c19d1205 24947struct arm_option_table
b99bd4ef 24948{
e0471c16
TS
24949 const char *option; /* Option name to match. */
24950 const char *help; /* Help information. */
c19d1205
ZW
24951 int *var; /* Variable to change. */
24952 int value; /* What to change it to. */
e0471c16 24953 const char *deprecated; /* If non-null, print this message. */
c19d1205 24954};
b99bd4ef 24955
c19d1205
ZW
24956struct arm_option_table arm_opts[] =
24957{
24958 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24959 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24960 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24961 &support_interwork, 1, NULL},
24962 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24963 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24964 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24965 1, NULL},
24966 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24967 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24968 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24969 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24970 NULL},
b99bd4ef 24971
c19d1205
ZW
24972 /* These are recognized by the assembler, but have no affect on code. */
24973 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24974 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
24975
24976 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24977 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24978 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
24979 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24980 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
24981 {NULL, NULL, NULL, 0, NULL}
24982};
24983
24984struct arm_legacy_option_table
24985{
e0471c16 24986 const char *option; /* Option name to match. */
e74cfd16
PB
24987 const arm_feature_set **var; /* Variable to change. */
24988 const arm_feature_set value; /* What to change it to. */
e0471c16 24989 const char *deprecated; /* If non-null, print this message. */
e74cfd16 24990};
b99bd4ef 24991
e74cfd16
PB
24992const struct arm_legacy_option_table arm_legacy_opts[] =
24993{
c19d1205
ZW
24994 /* DON'T add any new processors to this list -- we want the whole list
24995 to go away... Add them to the processors table instead. */
e74cfd16
PB
24996 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24997 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24998 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24999 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25000 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25001 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25002 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25003 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25004 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25005 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25006 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25007 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25008 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25009 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25010 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25011 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25012 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25013 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25014 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25015 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25016 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25017 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25018 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25019 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25020 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25021 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25022 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25023 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25024 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25025 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25026 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25027 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25028 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25029 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25030 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25031 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25032 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25033 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25034 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25035 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25036 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25037 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25038 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25039 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25040 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25041 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25042 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25043 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25044 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25045 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25046 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25047 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25048 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25049 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25050 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25051 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25052 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25053 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25054 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25055 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25056 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25057 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25058 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25059 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25060 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25061 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25062 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25063 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25064 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25065 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25066 N_("use -mcpu=strongarm110")},
e74cfd16 25067 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25068 N_("use -mcpu=strongarm1100")},
e74cfd16 25069 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25070 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25071 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25072 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25073 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25074
c19d1205 25075 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25076 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25077 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25078 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25079 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25080 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25081 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25082 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25083 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25084 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25085 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25086 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25087 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25088 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25089 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25090 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25091 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25092 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25093 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25094
c19d1205 25095 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25096 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25097 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25098 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25099 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25100 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25101
e74cfd16 25102 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25103};
7ed4c4c5 25104
c19d1205 25105struct arm_cpu_option_table
7ed4c4c5 25106{
e0471c16 25107 const char *name;
f3bad469 25108 size_t name_len;
e74cfd16 25109 const arm_feature_set value;
c19d1205
ZW
25110 /* For some CPUs we assume an FPU unless the user explicitly sets
25111 -mfpu=... */
e74cfd16 25112 const arm_feature_set default_fpu;
ee065d83
PB
25113 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25114 case. */
25115 const char *canonical_name;
c19d1205 25116};
7ed4c4c5 25117
c19d1205
ZW
25118/* This list should, at a minimum, contain all the cpu names
25119 recognized by GCC. */
f3bad469 25120#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25121static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25122{
f3bad469
MGD
25123 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25124 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25125 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25126 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25127 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25128 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25129 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25130 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25131 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25132 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25133 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25134 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25135 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25136 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25137 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25138 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25139 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25140 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25141 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25142 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25143 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25144 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25145 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25146 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25147 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25148 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25149 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25150 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25151 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25152 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25153 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25154 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25155 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25156 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25157 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25158 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25159 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25160 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25161 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25162 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25163 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25164 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25165 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25166 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25167 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25168 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25169 /* For V5 or later processors we default to using VFP; but the user
25170 should really set the FPU type explicitly. */
f3bad469
MGD
25171 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25172 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25173 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25174 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25175 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25176 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25177 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25178 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25179 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25180 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25181 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25182 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25183 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25184 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25185 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25186 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25187 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25188 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25189 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25190 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25191 "ARM1026EJ-S"),
25192 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25193 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25194 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25195 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25196 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25197 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25198 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25199 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25200 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25201 "ARM1136JF-S"),
25202 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25203 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25204 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25205 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25206 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25207 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25208 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25209 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25210 FPU_NONE, "Cortex-A5"),
c9fb6e58 25211 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25212 "Cortex-A7"),
25213 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25214 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25215 | FPU_NEON_EXT_V1),
f3bad469
MGD
25216 "Cortex-A8"),
25217 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25218 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25219 | FPU_NEON_EXT_V1),
f3bad469 25220 "Cortex-A9"),
c9fb6e58 25221 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25222 "Cortex-A12"),
c9fb6e58 25223 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25224 "Cortex-A15"),
d7adf960
KT
25225 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25226 "Cortex-A17"),
6735952f
KT
25227 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25228 "Cortex-A32"),
43cdc0a8
RR
25229 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25230 "Cortex-A35"),
92eb40d9 25231 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25232 "Cortex-A53"),
92eb40d9 25233 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25234 "Cortex-A57"),
b19f47ad
JW
25235 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25236 "Cortex-A72"),
f3bad469
MGD
25237 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25238 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25239 "Cortex-R4F"),
25240 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25241 FPU_NONE, "Cortex-R5"),
70a8bc5b 25242 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25243 FPU_ARCH_VFP_V3D16,
25244 "Cortex-R7"),
5f474010
TP
25245 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25246 FPU_ARCH_VFP_V3D16,
25247 "Cortex-R8"),
a715796b 25248 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25249 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25250 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25251 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25252 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25253 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
25254 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25255 "Samsung " \
25256 "Exynos M1"),
6b21c2bf
JW
25257 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25258 "Qualcomm "
25259 "QDF24XX"),
25260
c19d1205 25261 /* ??? XSCALE is really an architecture. */
f3bad469 25262 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25263 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25264 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25265 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25266 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25267 /* Maverick */
823d2571 25268 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25269 FPU_ARCH_MAVERICK, "ARM920T"),
25270 /* Marvell processors. */
ff8646ee
TP
25271 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25272 | ARM_EXT_SEC,
25273 ARM_EXT2_V6T2_V8M),
477330fc 25274 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25275 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25276 | ARM_EXT_SEC,
25277 ARM_EXT2_V6T2_V8M),
4347085a 25278 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25279 /* APM X-Gene family. */
25280 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25281 "APM X-Gene 1"),
25282 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25283 "APM X-Gene 2"),
da4339ed 25284
f3bad469 25285 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25286};
f3bad469 25287#undef ARM_CPU_OPT
7ed4c4c5 25288
c19d1205 25289struct arm_arch_option_table
7ed4c4c5 25290{
e0471c16 25291 const char *name;
f3bad469 25292 size_t name_len;
e74cfd16
PB
25293 const arm_feature_set value;
25294 const arm_feature_set default_fpu;
c19d1205 25295};
7ed4c4c5 25296
c19d1205
ZW
25297/* This list should, at a minimum, contain all the architecture names
25298 recognized by GCC. */
f3bad469 25299#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25300static const struct arm_arch_option_table arm_archs[] =
c19d1205 25301{
f3bad469
MGD
25302 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25303 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25304 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25305 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25306 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25307 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25308 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25309 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25310 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25311 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25312 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25313 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25314 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25315 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25316 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25317 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25318 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25319 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25320 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25321 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25322 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25323 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25324 kept to preserve existing behaviour. */
25325 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25326 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25327 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25328 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25329 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25330 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25331 kept to preserve existing behaviour. */
25332 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25333 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25334 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25335 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25336 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25337 /* The official spelling of the ARMv7 profile variants is the dashed form.
25338 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25339 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25340 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25341 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25342 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25343 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25344 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25345 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25346 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25347 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25348 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25349 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25350 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25351 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
25352 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25353 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25354 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25355 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25356};
f3bad469 25357#undef ARM_ARCH_OPT
7ed4c4c5 25358
69133863
MGD
25359/* ISA extensions in the co-processor and main instruction set space. */
25360struct arm_option_extension_value_table
c19d1205 25361{
e0471c16 25362 const char *name;
f3bad469 25363 size_t name_len;
5a70a223
JB
25364 const arm_feature_set merge_value;
25365 const arm_feature_set clear_value;
69133863 25366 const arm_feature_set allowed_archs;
c19d1205 25367};
7ed4c4c5 25368
69133863
MGD
25369/* The following table must be in alphabetical order with a NULL last entry.
25370 */
5a70a223 25371#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 25372static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25373{
823d2571
TG
25374 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25375 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25376 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25377 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25378 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
25379 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25380 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25381 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25382 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25383 ARM_ARCH_V8_2A),
823d2571
TG
25384 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25385 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25386 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
25387 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
25388 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
25389 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
25390 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
25391 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
25392 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
25393 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25394 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25395 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
823d2571
TG
25396 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25397 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25398 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25399 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25400 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25401 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25402 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25403 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25404 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25405 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25406 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25407 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
643afb90
MW
25408 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25409 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25410 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25411 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25412 | ARM_EXT_DIV),
25413 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25414 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25415 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
25416 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 25417 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 25418};
f3bad469 25419#undef ARM_EXT_OPT
69133863
MGD
25420
25421/* ISA floating-point and Advanced SIMD extensions. */
25422struct arm_option_fpu_value_table
25423{
e0471c16 25424 const char *name;
69133863 25425 const arm_feature_set value;
c19d1205 25426};
7ed4c4c5 25427
c19d1205
ZW
25428/* This list should, at a minimum, contain all the fpu names
25429 recognized by GCC. */
69133863 25430static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25431{
25432 {"softfpa", FPU_NONE},
25433 {"fpe", FPU_ARCH_FPE},
25434 {"fpe2", FPU_ARCH_FPE},
25435 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25436 {"fpa", FPU_ARCH_FPA},
25437 {"fpa10", FPU_ARCH_FPA},
25438 {"fpa11", FPU_ARCH_FPA},
25439 {"arm7500fe", FPU_ARCH_FPA},
25440 {"softvfp", FPU_ARCH_VFP},
25441 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25442 {"vfp", FPU_ARCH_VFP_V2},
25443 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25444 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25445 {"vfp10", FPU_ARCH_VFP_V2},
25446 {"vfp10-r0", FPU_ARCH_VFP_V1},
25447 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25448 {"vfpv2", FPU_ARCH_VFP_V2},
25449 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25450 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25451 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25452 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25453 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25454 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25455 {"arm1020t", FPU_ARCH_VFP_V1},
25456 {"arm1020e", FPU_ARCH_VFP_V2},
25457 {"arm1136jfs", FPU_ARCH_VFP_V2},
25458 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25459 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25460 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25461 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25462 {"vfpv4", FPU_ARCH_VFP_V4},
25463 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25464 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25465 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25466 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25467 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25468 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25469 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25470 {"crypto-neon-fp-armv8",
25471 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25472 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25473 {"crypto-neon-fp-armv8.1",
25474 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25475 {NULL, ARM_ARCH_NONE}
25476};
25477
25478struct arm_option_value_table
25479{
e0471c16 25480 const char *name;
e74cfd16 25481 long value;
c19d1205 25482};
7ed4c4c5 25483
e74cfd16 25484static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25485{
25486 {"hard", ARM_FLOAT_ABI_HARD},
25487 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25488 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25489 {NULL, 0}
c19d1205 25490};
7ed4c4c5 25491
c19d1205 25492#ifdef OBJ_ELF
3a4a14e9 25493/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25494static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25495{
25496 {"gnu", EF_ARM_EABI_UNKNOWN},
25497 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25498 {"5", EF_ARM_EABI_VER5},
e74cfd16 25499 {NULL, 0}
c19d1205
ZW
25500};
25501#endif
7ed4c4c5 25502
c19d1205
ZW
25503struct arm_long_option_table
25504{
e0471c16
TS
25505 const char * option; /* Substring to match. */
25506 const char * help; /* Help information. */
c19d1205 25507 int (* func) (char * subopt); /* Function to decode sub-option. */
e0471c16 25508 const char * deprecated; /* If non-null, print this message. */
c19d1205 25509};
7ed4c4c5 25510
c921be7d 25511static bfd_boolean
f3bad469 25512arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 25513{
21d799b5
NC
25514 arm_feature_set *ext_set = (arm_feature_set *)
25515 xmalloc (sizeof (arm_feature_set));
e74cfd16 25516
69133863 25517 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25518 extensions being added before being removed. We achieve this by having
25519 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25520 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25521 or removing it (0) and only allowing it to change in the order
69133863
MGD
25522 -1 -> 1 -> 0. */
25523 const struct arm_option_extension_value_table * opt = NULL;
25524 int adding_value = -1;
25525
e74cfd16
PB
25526 /* Copy the feature set, so that we can modify it. */
25527 *ext_set = **opt_p;
25528 *opt_p = ext_set;
25529
c19d1205 25530 while (str != NULL && *str != 0)
7ed4c4c5 25531 {
f3bad469
MGD
25532 char *ext;
25533 size_t len;
7ed4c4c5 25534
c19d1205
ZW
25535 if (*str != '+')
25536 {
25537 as_bad (_("invalid architectural extension"));
c921be7d 25538 return FALSE;
c19d1205 25539 }
7ed4c4c5 25540
c19d1205
ZW
25541 str++;
25542 ext = strchr (str, '+');
7ed4c4c5 25543
c19d1205 25544 if (ext != NULL)
f3bad469 25545 len = ext - str;
c19d1205 25546 else
f3bad469 25547 len = strlen (str);
7ed4c4c5 25548
f3bad469 25549 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25550 {
25551 if (adding_value != 0)
25552 {
25553 adding_value = 0;
25554 opt = arm_extensions;
25555 }
25556
f3bad469 25557 len -= 2;
69133863
MGD
25558 str += 2;
25559 }
f3bad469 25560 else if (len > 0)
69133863
MGD
25561 {
25562 if (adding_value == -1)
25563 {
25564 adding_value = 1;
25565 opt = arm_extensions;
25566 }
25567 else if (adding_value != 1)
25568 {
25569 as_bad (_("must specify extensions to add before specifying "
25570 "those to remove"));
25571 return FALSE;
25572 }
25573 }
25574
f3bad469 25575 if (len == 0)
c19d1205
ZW
25576 {
25577 as_bad (_("missing architectural extension"));
c921be7d 25578 return FALSE;
c19d1205 25579 }
7ed4c4c5 25580
69133863
MGD
25581 gas_assert (adding_value != -1);
25582 gas_assert (opt != NULL);
25583
25584 /* Scan over the options table trying to find an exact match. */
25585 for (; opt->name != NULL; opt++)
f3bad469 25586 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25587 {
69133863
MGD
25588 /* Check we can apply the extension to this architecture. */
25589 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
25590 {
25591 as_bad (_("extension does not apply to the base architecture"));
25592 return FALSE;
25593 }
25594
25595 /* Add or remove the extension. */
25596 if (adding_value)
5a70a223 25597 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25598 else
5a70a223 25599 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25600
c19d1205
ZW
25601 break;
25602 }
7ed4c4c5 25603
c19d1205
ZW
25604 if (opt->name == NULL)
25605 {
69133863
MGD
25606 /* Did we fail to find an extension because it wasn't specified in
25607 alphabetical order, or because it does not exist? */
25608
25609 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25610 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25611 break;
25612
25613 if (opt->name == NULL)
25614 as_bad (_("unknown architectural extension `%s'"), str);
25615 else
25616 as_bad (_("architectural extensions must be specified in "
25617 "alphabetical order"));
25618
c921be7d 25619 return FALSE;
c19d1205 25620 }
69133863
MGD
25621 else
25622 {
25623 /* We should skip the extension we've just matched the next time
25624 round. */
25625 opt++;
25626 }
7ed4c4c5 25627
c19d1205
ZW
25628 str = ext;
25629 };
7ed4c4c5 25630
c921be7d 25631 return TRUE;
c19d1205 25632}
7ed4c4c5 25633
c921be7d 25634static bfd_boolean
f3bad469 25635arm_parse_cpu (char *str)
7ed4c4c5 25636{
f3bad469
MGD
25637 const struct arm_cpu_option_table *opt;
25638 char *ext = strchr (str, '+');
25639 size_t len;
7ed4c4c5 25640
c19d1205 25641 if (ext != NULL)
f3bad469 25642 len = ext - str;
7ed4c4c5 25643 else
f3bad469 25644 len = strlen (str);
7ed4c4c5 25645
f3bad469 25646 if (len == 0)
7ed4c4c5 25647 {
c19d1205 25648 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25649 return FALSE;
7ed4c4c5
NC
25650 }
25651
c19d1205 25652 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25653 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25654 {
e74cfd16
PB
25655 mcpu_cpu_opt = &opt->value;
25656 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25657 if (opt->canonical_name)
ef8e6722
JW
25658 {
25659 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25660 strcpy (selected_cpu_name, opt->canonical_name);
25661 }
ee065d83
PB
25662 else
25663 {
f3bad469 25664 size_t i;
c921be7d 25665
ef8e6722
JW
25666 if (len >= sizeof selected_cpu_name)
25667 len = (sizeof selected_cpu_name) - 1;
25668
f3bad469 25669 for (i = 0; i < len; i++)
ee065d83
PB
25670 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25671 selected_cpu_name[i] = 0;
25672 }
7ed4c4c5 25673
c19d1205
ZW
25674 if (ext != NULL)
25675 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25676
c921be7d 25677 return TRUE;
c19d1205 25678 }
7ed4c4c5 25679
c19d1205 25680 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25681 return FALSE;
7ed4c4c5
NC
25682}
25683
c921be7d 25684static bfd_boolean
f3bad469 25685arm_parse_arch (char *str)
7ed4c4c5 25686{
e74cfd16 25687 const struct arm_arch_option_table *opt;
c19d1205 25688 char *ext = strchr (str, '+');
f3bad469 25689 size_t len;
7ed4c4c5 25690
c19d1205 25691 if (ext != NULL)
f3bad469 25692 len = ext - str;
7ed4c4c5 25693 else
f3bad469 25694 len = strlen (str);
7ed4c4c5 25695
f3bad469 25696 if (len == 0)
7ed4c4c5 25697 {
c19d1205 25698 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25699 return FALSE;
7ed4c4c5
NC
25700 }
25701
c19d1205 25702 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25703 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25704 {
e74cfd16
PB
25705 march_cpu_opt = &opt->value;
25706 march_fpu_opt = &opt->default_fpu;
5f4273c7 25707 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25708
c19d1205
ZW
25709 if (ext != NULL)
25710 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25711
c921be7d 25712 return TRUE;
c19d1205
ZW
25713 }
25714
25715 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25716 return FALSE;
7ed4c4c5 25717}
eb043451 25718
c921be7d 25719static bfd_boolean
c19d1205
ZW
25720arm_parse_fpu (char * str)
25721{
69133863 25722 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25723
c19d1205
ZW
25724 for (opt = arm_fpus; opt->name != NULL; opt++)
25725 if (streq (opt->name, str))
25726 {
e74cfd16 25727 mfpu_opt = &opt->value;
c921be7d 25728 return TRUE;
c19d1205 25729 }
b99bd4ef 25730
c19d1205 25731 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25732 return FALSE;
c19d1205
ZW
25733}
25734
c921be7d 25735static bfd_boolean
c19d1205 25736arm_parse_float_abi (char * str)
b99bd4ef 25737{
e74cfd16 25738 const struct arm_option_value_table * opt;
b99bd4ef 25739
c19d1205
ZW
25740 for (opt = arm_float_abis; opt->name != NULL; opt++)
25741 if (streq (opt->name, str))
25742 {
25743 mfloat_abi_opt = opt->value;
c921be7d 25744 return TRUE;
c19d1205 25745 }
cc8a6dd0 25746
c19d1205 25747 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25748 return FALSE;
c19d1205 25749}
b99bd4ef 25750
c19d1205 25751#ifdef OBJ_ELF
c921be7d 25752static bfd_boolean
c19d1205
ZW
25753arm_parse_eabi (char * str)
25754{
e74cfd16 25755 const struct arm_option_value_table *opt;
cc8a6dd0 25756
c19d1205
ZW
25757 for (opt = arm_eabis; opt->name != NULL; opt++)
25758 if (streq (opt->name, str))
25759 {
25760 meabi_flags = opt->value;
c921be7d 25761 return TRUE;
c19d1205
ZW
25762 }
25763 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25764 return FALSE;
c19d1205
ZW
25765}
25766#endif
cc8a6dd0 25767
c921be7d 25768static bfd_boolean
e07e6e58
NC
25769arm_parse_it_mode (char * str)
25770{
c921be7d 25771 bfd_boolean ret = TRUE;
e07e6e58
NC
25772
25773 if (streq ("arm", str))
25774 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25775 else if (streq ("thumb", str))
25776 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25777 else if (streq ("always", str))
25778 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25779 else if (streq ("never", str))
25780 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25781 else
25782 {
25783 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25784 "arm, thumb, always, or never."), str);
c921be7d 25785 ret = FALSE;
e07e6e58
NC
25786 }
25787
25788 return ret;
25789}
25790
2e6976a8
DG
25791static bfd_boolean
25792arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25793{
25794 codecomposer_syntax = TRUE;
25795 arm_comment_chars[0] = ';';
25796 arm_line_separator_chars[0] = 0;
25797 return TRUE;
25798}
25799
c19d1205
ZW
25800struct arm_long_option_table arm_long_opts[] =
25801{
25802 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25803 arm_parse_cpu, NULL},
25804 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25805 arm_parse_arch, NULL},
25806 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25807 arm_parse_fpu, NULL},
25808 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25809 arm_parse_float_abi, NULL},
25810#ifdef OBJ_ELF
7fac0536 25811 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25812 arm_parse_eabi, NULL},
25813#endif
e07e6e58
NC
25814 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25815 arm_parse_it_mode, NULL},
2e6976a8
DG
25816 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25817 arm_ccs_mode, NULL},
c19d1205
ZW
25818 {NULL, NULL, 0, NULL}
25819};
cc8a6dd0 25820
c19d1205
ZW
25821int
25822md_parse_option (int c, char * arg)
25823{
25824 struct arm_option_table *opt;
e74cfd16 25825 const struct arm_legacy_option_table *fopt;
c19d1205 25826 struct arm_long_option_table *lopt;
b99bd4ef 25827
c19d1205 25828 switch (c)
b99bd4ef 25829 {
c19d1205
ZW
25830#ifdef OPTION_EB
25831 case OPTION_EB:
25832 target_big_endian = 1;
25833 break;
25834#endif
cc8a6dd0 25835
c19d1205
ZW
25836#ifdef OPTION_EL
25837 case OPTION_EL:
25838 target_big_endian = 0;
25839 break;
25840#endif
b99bd4ef 25841
845b51d6
PB
25842 case OPTION_FIX_V4BX:
25843 fix_v4bx = TRUE;
25844 break;
25845
c19d1205
ZW
25846 case 'a':
25847 /* Listing option. Just ignore these, we don't support additional
25848 ones. */
25849 return 0;
b99bd4ef 25850
c19d1205
ZW
25851 default:
25852 for (opt = arm_opts; opt->option != NULL; opt++)
25853 {
25854 if (c == opt->option[0]
25855 && ((arg == NULL && opt->option[1] == 0)
25856 || streq (arg, opt->option + 1)))
25857 {
c19d1205 25858 /* If the option is deprecated, tell the user. */
278df34e 25859 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25860 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25861 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25862
c19d1205
ZW
25863 if (opt->var != NULL)
25864 *opt->var = opt->value;
cc8a6dd0 25865
c19d1205
ZW
25866 return 1;
25867 }
25868 }
b99bd4ef 25869
e74cfd16
PB
25870 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25871 {
25872 if (c == fopt->option[0]
25873 && ((arg == NULL && fopt->option[1] == 0)
25874 || streq (arg, fopt->option + 1)))
25875 {
e74cfd16 25876 /* If the option is deprecated, tell the user. */
278df34e 25877 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25878 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25879 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25880
25881 if (fopt->var != NULL)
25882 *fopt->var = &fopt->value;
25883
25884 return 1;
25885 }
25886 }
25887
c19d1205
ZW
25888 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25889 {
25890 /* These options are expected to have an argument. */
25891 if (c == lopt->option[0]
25892 && arg != NULL
25893 && strncmp (arg, lopt->option + 1,
25894 strlen (lopt->option + 1)) == 0)
25895 {
c19d1205 25896 /* If the option is deprecated, tell the user. */
278df34e 25897 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25898 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25899 _(lopt->deprecated));
b99bd4ef 25900
c19d1205
ZW
25901 /* Call the sup-option parser. */
25902 return lopt->func (arg + strlen (lopt->option) - 1);
25903 }
25904 }
a737bd4d 25905
c19d1205
ZW
25906 return 0;
25907 }
a394c00f 25908
c19d1205
ZW
25909 return 1;
25910}
a394c00f 25911
c19d1205
ZW
25912void
25913md_show_usage (FILE * fp)
a394c00f 25914{
c19d1205
ZW
25915 struct arm_option_table *opt;
25916 struct arm_long_option_table *lopt;
a394c00f 25917
c19d1205 25918 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25919
c19d1205
ZW
25920 for (opt = arm_opts; opt->option != NULL; opt++)
25921 if (opt->help != NULL)
25922 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25923
c19d1205
ZW
25924 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25925 if (lopt->help != NULL)
25926 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 25927
c19d1205
ZW
25928#ifdef OPTION_EB
25929 fprintf (fp, _("\
25930 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
25931#endif
25932
c19d1205
ZW
25933#ifdef OPTION_EL
25934 fprintf (fp, _("\
25935 -EL assemble code for a little-endian cpu\n"));
a737bd4d 25936#endif
845b51d6
PB
25937
25938 fprintf (fp, _("\
25939 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 25940}
ee065d83
PB
25941
25942
25943#ifdef OBJ_ELF
62b3e311
PB
25944typedef struct
25945{
25946 int val;
25947 arm_feature_set flags;
25948} cpu_arch_ver_table;
25949
4ed7ed8d
TP
25950/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
25951 must be sorted least features first but some reordering is needed, eg. for
25952 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
25953static const cpu_arch_ver_table cpu_arch_ver[] =
25954{
25955 {1, ARM_ARCH_V4},
25956 {2, ARM_ARCH_V4T},
25957 {3, ARM_ARCH_V5},
ee3c0378 25958 {3, ARM_ARCH_V5T},
62b3e311
PB
25959 {4, ARM_ARCH_V5TE},
25960 {5, ARM_ARCH_V5TEJ},
25961 {6, ARM_ARCH_V6},
7e806470 25962 {9, ARM_ARCH_V6K},
f4c65163 25963 {7, ARM_ARCH_V6Z},
91e22acd 25964 {11, ARM_ARCH_V6M},
b2a5fbdc 25965 {12, ARM_ARCH_V6SM},
7e806470 25966 {8, ARM_ARCH_V6T2},
c9fb6e58 25967 {10, ARM_ARCH_V7VE},
62b3e311
PB
25968 {10, ARM_ARCH_V7R},
25969 {10, ARM_ARCH_V7M},
bca38921 25970 {14, ARM_ARCH_V8A},
ff8646ee 25971 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 25972 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
25973 {0, ARM_ARCH_NONE}
25974};
25975
ee3c0378
AS
25976/* Set an attribute if it has not already been set by the user. */
25977static void
25978aeabi_set_attribute_int (int tag, int value)
25979{
25980 if (tag < 1
25981 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25982 || !attributes_set_explicitly[tag])
25983 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25984}
25985
25986static void
25987aeabi_set_attribute_string (int tag, const char *value)
25988{
25989 if (tag < 1
25990 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25991 || !attributes_set_explicitly[tag])
25992 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25993}
25994
ee065d83 25995/* Set the public EABI object attributes. */
3cfdb781 25996void
ee065d83
PB
25997aeabi_set_public_attributes (void)
25998{
25999 int arch;
69239280 26000 char profile;
90ec0d68 26001 int virt_sec = 0;
bca38921 26002 int fp16_optional = 0;
e74cfd16 26003 arm_feature_set flags;
62b3e311 26004 arm_feature_set tmp;
ff8646ee 26005 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26006 const cpu_arch_ver_table *p;
ee065d83
PB
26007
26008 /* Choose the architecture based on the capabilities of the requested cpu
26009 (if any) and/or the instructions actually used. */
e74cfd16
PB
26010 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26011 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26012 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26013
26014 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26015 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26016
26017 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26018 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26019
7f78eb34
JW
26020 selected_cpu = flags;
26021
ddd7f988 26022 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26023 if (object_arch)
26024 {
26025 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26026 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26027 }
26028
251665fc
MGD
26029 /* We need to make sure that the attributes do not identify us as v6S-M
26030 when the only v6S-M feature in use is the Operating System Extensions. */
26031 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26032 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26033 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26034
62b3e311
PB
26035 tmp = flags;
26036 arch = 0;
26037 for (p = cpu_arch_ver; p->val; p++)
26038 {
26039 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26040 {
26041 arch = p->val;
26042 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26043 }
26044 }
ee065d83 26045
9e3c6df6
PB
26046 /* The table lookup above finds the last architecture to contribute
26047 a new feature. Unfortunately, Tag13 is a subset of the union of
26048 v6T2 and v7-M, so it is never seen as contributing a new feature.
26049 We can not search for the last entry which is entirely used,
26050 because if no CPU is specified we build up only those flags
26051 actually used. Perhaps we should separate out the specified
26052 and implicit cases. Avoid taking this path for -march=all by
26053 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26054 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26055 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26056 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26057 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
4ed7ed8d
TP
26058 arch = TAG_CPU_ARCH_V7E_M;
26059
ff8646ee
TP
26060 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26061 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
26062 arch = TAG_CPU_ARCH_V8M_MAIN;
26063
4ed7ed8d
TP
26064 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26065 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26066 ARMv8-M, -march=all must be detected as ARMv8-A. */
26067 if (arch == TAG_CPU_ARCH_V8M_MAIN
26068 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
26069 arch = TAG_CPU_ARCH_V8;
9e3c6df6 26070
ee065d83
PB
26071 /* Tag_CPU_name. */
26072 if (selected_cpu_name[0])
26073 {
91d6fa6a 26074 char *q;
ee065d83 26075
91d6fa6a
NC
26076 q = selected_cpu_name;
26077 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26078 {
26079 int i;
5f4273c7 26080
91d6fa6a
NC
26081 q += 4;
26082 for (i = 0; q[i]; i++)
26083 q[i] = TOUPPER (q[i]);
ee065d83 26084 }
91d6fa6a 26085 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26086 }
62f3b8c8 26087
ee065d83 26088 /* Tag_CPU_arch. */
ee3c0378 26089 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26090
62b3e311 26091 /* Tag_CPU_arch_profile. */
10c9892b 26092 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26093 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26094 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
26095 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)))
69239280 26096 profile = 'A';
62b3e311 26097 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26098 profile = 'R';
7e806470 26099 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26100 profile = 'M';
26101 else
26102 profile = '\0';
26103
26104 if (profile != '\0')
26105 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26106
ee065d83 26107 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26108 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26109 || arch == 0)
26110 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26111
ee065d83 26112 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26113 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26114 || arch == 0)
4ed7ed8d
TP
26115 {
26116 int thumb_isa_use;
26117
26118 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26119 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
26120 thumb_isa_use = 3;
26121 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26122 thumb_isa_use = 2;
26123 else
26124 thumb_isa_use = 1;
26125 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26126 }
62f3b8c8 26127
ee065d83 26128 /* Tag_VFP_arch. */
a715796b
TG
26129 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26130 aeabi_set_attribute_int (Tag_VFP_arch,
26131 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26132 ? 7 : 8);
bca38921 26133 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26134 aeabi_set_attribute_int (Tag_VFP_arch,
26135 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26136 ? 5 : 6);
26137 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26138 {
26139 fp16_optional = 1;
26140 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26141 }
ada65aa3 26142 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26143 {
26144 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26145 fp16_optional = 1;
26146 }
ee3c0378
AS
26147 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26148 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26149 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26150 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26151 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26152
4547cb56
NC
26153 /* Tag_ABI_HardFP_use. */
26154 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26155 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26156 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26157
ee065d83 26158 /* Tag_WMMX_arch. */
ee3c0378
AS
26159 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26160 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26161 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26162 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26163
ee3c0378 26164 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26165 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26166 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26167 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26168 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26169 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26170 {
26171 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26172 {
26173 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26174 }
26175 else
26176 {
26177 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26178 fp16_optional = 1;
26179 }
26180 }
fa94de6b 26181
ee3c0378 26182 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26183 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26184 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26185
69239280
MGD
26186 /* Tag_DIV_use.
26187
26188 We set Tag_DIV_use to two when integer divide instructions have been used
26189 in ARM state, or when Thumb integer divide instructions have been used,
26190 but we have no architecture profile set, nor have we any ARM instructions.
26191
4ed7ed8d
TP
26192 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26193 by the base architecture.
bca38921 26194
69239280 26195 For new architectures we will have to check these tests. */
ff8646ee
TP
26196 gas_assert (arch <= TAG_CPU_ARCH_V8
26197 || (arch >= TAG_CPU_ARCH_V8M_BASE
26198 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26199 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26200 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26201 aeabi_set_attribute_int (Tag_DIV_use, 0);
26202 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26203 || (profile == '\0'
26204 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26205 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26206 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26207
26208 /* Tag_MP_extension_use. */
26209 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26210 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26211
26212 /* Tag Virtualization_use. */
26213 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26214 virt_sec |= 1;
26215 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26216 virt_sec |= 2;
26217 if (virt_sec != 0)
26218 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26219}
26220
104d59d1 26221/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26222void
26223arm_md_end (void)
26224{
ee065d83
PB
26225 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26226 return;
26227
26228 aeabi_set_public_attributes ();
ee065d83 26229}
8463be01 26230#endif /* OBJ_ELF */
ee065d83
PB
26231
26232
26233/* Parse a .cpu directive. */
26234
26235static void
26236s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26237{
e74cfd16 26238 const struct arm_cpu_option_table *opt;
ee065d83
PB
26239 char *name;
26240 char saved_char;
26241
26242 name = input_line_pointer;
5f4273c7 26243 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26244 input_line_pointer++;
26245 saved_char = *input_line_pointer;
26246 *input_line_pointer = 0;
26247
26248 /* Skip the first "all" entry. */
26249 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26250 if (streq (opt->name, name))
26251 {
e74cfd16
PB
26252 mcpu_cpu_opt = &opt->value;
26253 selected_cpu = opt->value;
ee065d83 26254 if (opt->canonical_name)
5f4273c7 26255 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26256 else
26257 {
26258 int i;
26259 for (i = 0; opt->name[i]; i++)
26260 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26261
ee065d83
PB
26262 selected_cpu_name[i] = 0;
26263 }
e74cfd16 26264 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26265 *input_line_pointer = saved_char;
26266 demand_empty_rest_of_line ();
26267 return;
26268 }
26269 as_bad (_("unknown cpu `%s'"), name);
26270 *input_line_pointer = saved_char;
26271 ignore_rest_of_line ();
26272}
26273
26274
26275/* Parse a .arch directive. */
26276
26277static void
26278s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26279{
e74cfd16 26280 const struct arm_arch_option_table *opt;
ee065d83
PB
26281 char saved_char;
26282 char *name;
26283
26284 name = input_line_pointer;
5f4273c7 26285 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26286 input_line_pointer++;
26287 saved_char = *input_line_pointer;
26288 *input_line_pointer = 0;
26289
26290 /* Skip the first "all" entry. */
26291 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26292 if (streq (opt->name, name))
26293 {
e74cfd16
PB
26294 mcpu_cpu_opt = &opt->value;
26295 selected_cpu = opt->value;
5f4273c7 26296 strcpy (selected_cpu_name, opt->name);
e74cfd16 26297 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26298 *input_line_pointer = saved_char;
26299 demand_empty_rest_of_line ();
26300 return;
26301 }
26302
26303 as_bad (_("unknown architecture `%s'\n"), name);
26304 *input_line_pointer = saved_char;
26305 ignore_rest_of_line ();
26306}
26307
26308
7a1d4c38
PB
26309/* Parse a .object_arch directive. */
26310
26311static void
26312s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26313{
26314 const struct arm_arch_option_table *opt;
26315 char saved_char;
26316 char *name;
26317
26318 name = input_line_pointer;
5f4273c7 26319 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26320 input_line_pointer++;
26321 saved_char = *input_line_pointer;
26322 *input_line_pointer = 0;
26323
26324 /* Skip the first "all" entry. */
26325 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26326 if (streq (opt->name, name))
26327 {
26328 object_arch = &opt->value;
26329 *input_line_pointer = saved_char;
26330 demand_empty_rest_of_line ();
26331 return;
26332 }
26333
26334 as_bad (_("unknown architecture `%s'\n"), name);
26335 *input_line_pointer = saved_char;
26336 ignore_rest_of_line ();
26337}
26338
69133863
MGD
26339/* Parse a .arch_extension directive. */
26340
26341static void
26342s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26343{
26344 const struct arm_option_extension_value_table *opt;
26345 char saved_char;
26346 char *name;
26347 int adding_value = 1;
26348
26349 name = input_line_pointer;
26350 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26351 input_line_pointer++;
26352 saved_char = *input_line_pointer;
26353 *input_line_pointer = 0;
26354
26355 if (strlen (name) >= 2
26356 && strncmp (name, "no", 2) == 0)
26357 {
26358 adding_value = 0;
26359 name += 2;
26360 }
26361
26362 for (opt = arm_extensions; opt->name != NULL; opt++)
26363 if (streq (opt->name, name))
26364 {
26365 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
26366 {
26367 as_bad (_("architectural extension `%s' is not allowed for the "
26368 "current base architecture"), name);
26369 break;
26370 }
26371
26372 if (adding_value)
5a70a223
JB
26373 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26374 opt->merge_value);
69133863 26375 else
5a70a223 26376 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26377
26378 mcpu_cpu_opt = &selected_cpu;
26379 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26380 *input_line_pointer = saved_char;
26381 demand_empty_rest_of_line ();
26382 return;
26383 }
26384
26385 if (opt->name == NULL)
e673710a 26386 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26387
26388 *input_line_pointer = saved_char;
26389 ignore_rest_of_line ();
26390}
26391
ee065d83
PB
26392/* Parse a .fpu directive. */
26393
26394static void
26395s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26396{
69133863 26397 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26398 char saved_char;
26399 char *name;
26400
26401 name = input_line_pointer;
5f4273c7 26402 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26403 input_line_pointer++;
26404 saved_char = *input_line_pointer;
26405 *input_line_pointer = 0;
5f4273c7 26406
ee065d83
PB
26407 for (opt = arm_fpus; opt->name != NULL; opt++)
26408 if (streq (opt->name, name))
26409 {
e74cfd16
PB
26410 mfpu_opt = &opt->value;
26411 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26412 *input_line_pointer = saved_char;
26413 demand_empty_rest_of_line ();
26414 return;
26415 }
26416
26417 as_bad (_("unknown floating point format `%s'\n"), name);
26418 *input_line_pointer = saved_char;
26419 ignore_rest_of_line ();
26420}
ee065d83 26421
794ba86a 26422/* Copy symbol information. */
f31fef98 26423
794ba86a
DJ
26424void
26425arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26426{
26427 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26428}
e04befd0 26429
f31fef98 26430#ifdef OBJ_ELF
e04befd0
AS
26431/* Given a symbolic attribute NAME, return the proper integer value.
26432 Returns -1 if the attribute is not known. */
f31fef98 26433
e04befd0
AS
26434int
26435arm_convert_symbolic_attribute (const char *name)
26436{
f31fef98
NC
26437 static const struct
26438 {
26439 const char * name;
26440 const int tag;
26441 }
26442 attribute_table[] =
26443 {
26444 /* When you modify this table you should
26445 also modify the list in doc/c-arm.texi. */
e04befd0 26446#define T(tag) {#tag, tag}
f31fef98
NC
26447 T (Tag_CPU_raw_name),
26448 T (Tag_CPU_name),
26449 T (Tag_CPU_arch),
26450 T (Tag_CPU_arch_profile),
26451 T (Tag_ARM_ISA_use),
26452 T (Tag_THUMB_ISA_use),
75375b3e 26453 T (Tag_FP_arch),
f31fef98
NC
26454 T (Tag_VFP_arch),
26455 T (Tag_WMMX_arch),
26456 T (Tag_Advanced_SIMD_arch),
26457 T (Tag_PCS_config),
26458 T (Tag_ABI_PCS_R9_use),
26459 T (Tag_ABI_PCS_RW_data),
26460 T (Tag_ABI_PCS_RO_data),
26461 T (Tag_ABI_PCS_GOT_use),
26462 T (Tag_ABI_PCS_wchar_t),
26463 T (Tag_ABI_FP_rounding),
26464 T (Tag_ABI_FP_denormal),
26465 T (Tag_ABI_FP_exceptions),
26466 T (Tag_ABI_FP_user_exceptions),
26467 T (Tag_ABI_FP_number_model),
75375b3e 26468 T (Tag_ABI_align_needed),
f31fef98 26469 T (Tag_ABI_align8_needed),
75375b3e 26470 T (Tag_ABI_align_preserved),
f31fef98
NC
26471 T (Tag_ABI_align8_preserved),
26472 T (Tag_ABI_enum_size),
26473 T (Tag_ABI_HardFP_use),
26474 T (Tag_ABI_VFP_args),
26475 T (Tag_ABI_WMMX_args),
26476 T (Tag_ABI_optimization_goals),
26477 T (Tag_ABI_FP_optimization_goals),
26478 T (Tag_compatibility),
26479 T (Tag_CPU_unaligned_access),
75375b3e 26480 T (Tag_FP_HP_extension),
f31fef98
NC
26481 T (Tag_VFP_HP_extension),
26482 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26483 T (Tag_MPextension_use),
26484 T (Tag_DIV_use),
f31fef98
NC
26485 T (Tag_nodefaults),
26486 T (Tag_also_compatible_with),
26487 T (Tag_conformance),
26488 T (Tag_T2EE_use),
26489 T (Tag_Virtualization_use),
cd21e546 26490 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26491#undef T
f31fef98 26492 };
e04befd0
AS
26493 unsigned int i;
26494
26495 if (name == NULL)
26496 return -1;
26497
f31fef98 26498 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26499 if (streq (name, attribute_table[i].name))
e04befd0
AS
26500 return attribute_table[i].tag;
26501
26502 return -1;
26503}
267bf995
RR
26504
26505
93ef582d
NC
26506/* Apply sym value for relocations only in the case that they are for
26507 local symbols in the same segment as the fixup and you have the
26508 respective architectural feature for blx and simple switches. */
267bf995 26509int
93ef582d 26510arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26511{
26512 if (fixP->fx_addsy
26513 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26514 /* PR 17444: If the local symbol is in a different section then a reloc
26515 will always be generated for it, so applying the symbol value now
26516 will result in a double offset being stored in the relocation. */
26517 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26518 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26519 {
26520 switch (fixP->fx_r_type)
26521 {
26522 case BFD_RELOC_ARM_PCREL_BLX:
26523 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26524 if (ARM_IS_FUNC (fixP->fx_addsy))
26525 return 1;
26526 break;
26527
26528 case BFD_RELOC_ARM_PCREL_CALL:
26529 case BFD_RELOC_THUMB_PCREL_BLX:
26530 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26531 return 1;
267bf995
RR
26532 break;
26533
26534 default:
26535 break;
26536 }
26537
26538 }
26539 return 0;
26540}
f31fef98 26541#endif /* OBJ_ELF */
This page took 7.990082 seconds and 4 git commands to generate.