]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Test load conversion with symbol versioning for x86
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
6f2750fe 2 Copyright (C) 1994-2016 Free Software Foundation, Inc.
b99bd4ef
NC
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
ec2655a6 13 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
b99bd4ef 25
42a68e18 26#include "as.h"
5287ad62 27#include <limits.h>
037e8744 28#include <stdarg.h>
c19d1205 29#define NO_RELOC 0
3882b010 30#include "safe-ctype.h"
b99bd4ef
NC
31#include "subsegs.h"
32#include "obstack.h"
3da1d841 33#include "libiberty.h"
f263249b
RE
34#include "opcode/arm.h"
35
b99bd4ef
NC
36#ifdef OBJ_ELF
37#include "elf/arm.h"
a394c00f 38#include "dw2gencfi.h"
b99bd4ef
NC
39#endif
40
f0927246
NC
41#include "dwarf2dbg.h"
42
7ed4c4c5
NC
43#ifdef OBJ_ELF
44/* Must be at least the size of the largest unwind opcode (currently two). */
45#define ARM_OPCODE_CHUNK_SIZE 8
46
47/* This structure holds the unwinding state. */
48
49static struct
50{
c19d1205
ZW
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
7ed4c4c5 55 /* The segment containing the function. */
c19d1205
ZW
56 segT saved_seg;
57 subsegT saved_subseg;
7ed4c4c5
NC
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
c19d1205
ZW
60 int opcode_count;
61 int opcode_alloc;
7ed4c4c5 62 /* The number of bytes pushed to the stack. */
c19d1205 63 offsetT frame_size;
7ed4c4c5
NC
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
c19d1205 67 offsetT pending_offset;
7ed4c4c5 68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
7ed4c4c5 72 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 73 unsigned fp_used:1;
7ed4c4c5 74 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 75 unsigned sp_restored:1;
7ed4c4c5
NC
76} unwind;
77
8b1ad454
NC
78#endif /* OBJ_ELF */
79
4962c51a
MS
80/* Results from operand parsing worker functions. */
81
82typedef enum
83{
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87} parse_operand_result;
88
33a392fb
PB
89enum arm_float_abi
90{
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94};
95
c19d1205 96/* Types of processor to assemble for. */
b99bd4ef 97#ifndef CPU_DEFAULT
8a59fff3 98/* The code that was here used to select a default CPU depending on compiler
fa94de6b 99 pre-defines which were only present when doing native builds, thus
8a59fff3
MGD
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
b99bd4ef
NC
104#endif
105
106#ifndef FPU_DEFAULT
c820d418
MM
107# ifdef TE_LINUX
108# define FPU_DEFAULT FPU_ARCH_FPA
109# elif defined (TE_NetBSD)
110# ifdef OBJ_ELF
111# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112# else
113 /* Legacy a.out format. */
114# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115# endif
4e7fd91e
PB
116# elif defined (TE_VXWORKS)
117# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
118# else
119 /* For backwards compatibility, default to FPA. */
120# define FPU_DEFAULT FPU_ARCH_FPA
121# endif
122#endif /* ifndef FPU_DEFAULT */
b99bd4ef 123
c19d1205 124#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 125
e74cfd16
PB
126static arm_feature_set cpu_variant;
127static arm_feature_set arm_arch_used;
128static arm_feature_set thumb_arch_used;
b99bd4ef 129
b99bd4ef 130/* Flags stored in private area of BFD structure. */
c19d1205
ZW
131static int uses_apcs_26 = FALSE;
132static int atpcs = FALSE;
b34976b6
AM
133static int support_interwork = FALSE;
134static int uses_apcs_float = FALSE;
c19d1205 135static int pic_code = FALSE;
845b51d6 136static int fix_v4bx = FALSE;
278df34e
NS
137/* Warn on using deprecated features. */
138static int warn_on_deprecated = TRUE;
139
2e6976a8
DG
140/* Understand CodeComposer Studio assembly syntax. */
141bfd_boolean codecomposer_syntax = FALSE;
03b1477f
RE
142
143/* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
e74cfd16
PB
146static const arm_feature_set *legacy_cpu = NULL;
147static const arm_feature_set *legacy_fpu = NULL;
148
149static const arm_feature_set *mcpu_cpu_opt = NULL;
150static const arm_feature_set *mcpu_fpu_opt = NULL;
151static const arm_feature_set *march_cpu_opt = NULL;
152static const arm_feature_set *march_fpu_opt = NULL;
153static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 154static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
155
156/* Constants for known architecture features. */
157static const arm_feature_set fpu_default = FPU_DEFAULT;
158static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
160static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
162static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167#ifdef CPU_DEFAULT
168static const arm_feature_set cpu_default = CPU_DEFAULT;
169#endif
170
823d2571
TG
171static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
172static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
173static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
174static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
175static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
176static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
177static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
178static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 179static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
180 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
181static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
182static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
183static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
184static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
185static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
186static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
187static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
188static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
189static const arm_feature_set arm_ext_v6_notm =
190 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
191static const arm_feature_set arm_ext_v6_dsp =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
193static const arm_feature_set arm_ext_barrier =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
195static const arm_feature_set arm_ext_msr =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
197static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
198static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
199static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
200static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
201static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
202static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 203static const arm_feature_set arm_ext_m =
4ed7ed8d 204 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, ARM_EXT2_V8M);
823d2571
TG
205static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
206static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
207static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
208static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
209static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 210static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 211static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
ff8646ee
TP
212static const arm_feature_set arm_ext_v6t2_v8m =
213 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
214/* Instructions shared between ARMv8-A and ARMv8-M. */
215static const arm_feature_set arm_ext_atomics =
216 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
105bde57
MW
217static const arm_feature_set arm_ext_v8_2 =
218 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
b8ec4e87
JW
219/* FP16 instructions. */
220static const arm_feature_set arm_ext_fp16 =
221 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
e74cfd16
PB
222
223static const arm_feature_set arm_arch_any = ARM_ANY;
823d2571 224static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
225static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
226static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 227static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 228
2d447fca 229static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 230 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 231static const arm_feature_set arm_cext_iwmmxt =
823d2571 232 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 233static const arm_feature_set arm_cext_xscale =
823d2571 234 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 235static const arm_feature_set arm_cext_maverick =
823d2571
TG
236 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
237static const arm_feature_set fpu_fpa_ext_v1 =
238 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
239static const arm_feature_set fpu_fpa_ext_v2 =
240 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 241static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
242 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
243static const arm_feature_set fpu_vfp_ext_v1 =
244 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
245static const arm_feature_set fpu_vfp_ext_v2 =
246 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
247static const arm_feature_set fpu_vfp_ext_v3xd =
248 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
249static const arm_feature_set fpu_vfp_ext_v3 =
250 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 251static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
252 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
253static const arm_feature_set fpu_neon_ext_v1 =
254 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 255static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571
TG
256 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
257static const arm_feature_set fpu_vfp_fp16 =
258 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
259static const arm_feature_set fpu_neon_ext_fma =
260 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
261static const arm_feature_set fpu_vfp_ext_fma =
262 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 263static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 264 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 265static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 266 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 267static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 268 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 269static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 270 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 271static const arm_feature_set crc_ext_armv8 =
823d2571 272 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 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")
a9f02af8 790#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 791
c921be7d
NC
792static struct hash_control * arm_ops_hsh;
793static struct hash_control * arm_cond_hsh;
794static struct hash_control * arm_shift_hsh;
795static struct hash_control * arm_psr_hsh;
796static struct hash_control * arm_v7m_psr_hsh;
797static struct hash_control * arm_reg_hsh;
798static struct hash_control * arm_reloc_hsh;
799static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 800
b99bd4ef
NC
801/* Stuff needed to resolve the label ambiguity
802 As:
803 ...
804 label: <insn>
805 may differ from:
806 ...
807 label:
5f4273c7 808 <insn> */
b99bd4ef
NC
809
810symbolS * last_label_seen;
b34976b6 811static int label_is_thumb_function_name = FALSE;
e07e6e58 812
3d0c9500
NC
813/* Literal pool structure. Held on a per-section
814 and per-sub-section basis. */
a737bd4d 815
c19d1205 816#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 817typedef struct literal_pool
b99bd4ef 818{
c921be7d
NC
819 expressionS literals [MAX_LITERAL_POOL_SIZE];
820 unsigned int next_free_entry;
821 unsigned int id;
822 symbolS * symbol;
823 segT section;
824 subsegT sub_section;
a8040cf2
NC
825#ifdef OBJ_ELF
826 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
827#endif
c921be7d 828 struct literal_pool * next;
8335d6aa 829 unsigned int alignment;
3d0c9500 830} literal_pool;
b99bd4ef 831
3d0c9500
NC
832/* Pointer to a linked list of literal pools. */
833literal_pool * list_of_pools = NULL;
e27ec89e 834
2e6976a8
DG
835typedef enum asmfunc_states
836{
837 OUTSIDE_ASMFUNC,
838 WAITING_ASMFUNC_NAME,
839 WAITING_ENDASMFUNC
840} asmfunc_states;
841
842static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
843
e07e6e58
NC
844#ifdef OBJ_ELF
845# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
846#else
847static struct current_it now_it;
848#endif
849
850static inline int
851now_it_compatible (int cond)
852{
853 return (cond & ~1) == (now_it.cc & ~1);
854}
855
856static inline int
857conditional_insn (void)
858{
859 return inst.cond != COND_ALWAYS;
860}
861
862static int in_it_block (void);
863
864static int handle_it_state (void);
865
866static void force_automatic_it_block_close (void);
867
c921be7d
NC
868static void it_fsm_post_encode (void);
869
e07e6e58
NC
870#define set_it_insn_type(type) \
871 do \
872 { \
873 inst.it_insn_type = type; \
874 if (handle_it_state () == FAIL) \
477330fc 875 return; \
e07e6e58
NC
876 } \
877 while (0)
878
c921be7d
NC
879#define set_it_insn_type_nonvoid(type, failret) \
880 do \
881 { \
882 inst.it_insn_type = type; \
883 if (handle_it_state () == FAIL) \
477330fc 884 return failret; \
c921be7d
NC
885 } \
886 while(0)
887
e07e6e58
NC
888#define set_it_insn_type_last() \
889 do \
890 { \
891 if (inst.cond == COND_ALWAYS) \
477330fc 892 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 893 else \
477330fc 894 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
895 } \
896 while (0)
897
c19d1205 898/* Pure syntax. */
b99bd4ef 899
c19d1205
ZW
900/* This array holds the chars that always start a comment. If the
901 pre-processor is disabled, these aren't very useful. */
2e6976a8 902char arm_comment_chars[] = "@";
3d0c9500 903
c19d1205
ZW
904/* This array holds the chars that only start a comment at the beginning of
905 a line. If the line seems to have the form '# 123 filename'
906 .line and .file directives will appear in the pre-processed output. */
907/* Note that input_file.c hand checks for '#' at the beginning of the
908 first line of the input file. This is because the compiler outputs
909 #NO_APP at the beginning of its output. */
910/* Also note that comments like this one will always work. */
911const char line_comment_chars[] = "#";
3d0c9500 912
2e6976a8 913char arm_line_separator_chars[] = ";";
b99bd4ef 914
c19d1205
ZW
915/* Chars that can be used to separate mant
916 from exp in floating point numbers. */
917const char EXP_CHARS[] = "eE";
3d0c9500 918
c19d1205
ZW
919/* Chars that mean this number is a floating point constant. */
920/* As in 0f12.456 */
921/* or 0d1.2345e12 */
b99bd4ef 922
c19d1205 923const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 924
c19d1205
ZW
925/* Prefix characters that indicate the start of an immediate
926 value. */
927#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 928
c19d1205
ZW
929/* Separator character handling. */
930
931#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
932
933static inline int
934skip_past_char (char ** str, char c)
935{
8ab8155f
NC
936 /* PR gas/14987: Allow for whitespace before the expected character. */
937 skip_whitespace (*str);
427d0db6 938
c19d1205
ZW
939 if (**str == c)
940 {
941 (*str)++;
942 return SUCCESS;
3d0c9500 943 }
c19d1205
ZW
944 else
945 return FAIL;
946}
c921be7d 947
c19d1205 948#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 949
c19d1205
ZW
950/* Arithmetic expressions (possibly involving symbols). */
951
952/* Return TRUE if anything in the expression is a bignum. */
953
954static int
955walk_no_bignums (symbolS * sp)
956{
957 if (symbol_get_value_expression (sp)->X_op == O_big)
958 return 1;
959
960 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 961 {
c19d1205
ZW
962 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
963 || (symbol_get_value_expression (sp)->X_op_symbol
964 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
965 }
966
c19d1205 967 return 0;
3d0c9500
NC
968}
969
c19d1205
ZW
970static int in_my_get_expression = 0;
971
972/* Third argument to my_get_expression. */
973#define GE_NO_PREFIX 0
974#define GE_IMM_PREFIX 1
975#define GE_OPT_PREFIX 2
5287ad62
JB
976/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
977 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
978#define GE_OPT_PREFIX_BIG 3
a737bd4d 979
b99bd4ef 980static int
c19d1205 981my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 982{
c19d1205
ZW
983 char * save_in;
984 segT seg;
b99bd4ef 985
c19d1205
ZW
986 /* In unified syntax, all prefixes are optional. */
987 if (unified_syntax)
5287ad62 988 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 989 : GE_OPT_PREFIX;
b99bd4ef 990
c19d1205 991 switch (prefix_mode)
b99bd4ef 992 {
c19d1205
ZW
993 case GE_NO_PREFIX: break;
994 case GE_IMM_PREFIX:
995 if (!is_immediate_prefix (**str))
996 {
997 inst.error = _("immediate expression requires a # prefix");
998 return FAIL;
999 }
1000 (*str)++;
1001 break;
1002 case GE_OPT_PREFIX:
5287ad62 1003 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1004 if (is_immediate_prefix (**str))
1005 (*str)++;
1006 break;
1007 default: abort ();
1008 }
b99bd4ef 1009
c19d1205 1010 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1011
c19d1205
ZW
1012 save_in = input_line_pointer;
1013 input_line_pointer = *str;
1014 in_my_get_expression = 1;
1015 seg = expression (ep);
1016 in_my_get_expression = 0;
1017
f86adc07 1018 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1019 {
f86adc07 1020 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1021 *str = input_line_pointer;
1022 input_line_pointer = save_in;
1023 if (inst.error == NULL)
f86adc07
NS
1024 inst.error = (ep->X_op == O_absent
1025 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1026 return 1;
1027 }
b99bd4ef 1028
c19d1205
ZW
1029#ifdef OBJ_AOUT
1030 if (seg != absolute_section
1031 && seg != text_section
1032 && seg != data_section
1033 && seg != bss_section
1034 && seg != undefined_section)
1035 {
1036 inst.error = _("bad segment");
1037 *str = input_line_pointer;
1038 input_line_pointer = save_in;
1039 return 1;
b99bd4ef 1040 }
87975d2a
AM
1041#else
1042 (void) seg;
c19d1205 1043#endif
b99bd4ef 1044
c19d1205
ZW
1045 /* Get rid of any bignums now, so that we don't generate an error for which
1046 we can't establish a line number later on. Big numbers are never valid
1047 in instructions, which is where this routine is always called. */
5287ad62
JB
1048 if (prefix_mode != GE_OPT_PREFIX_BIG
1049 && (ep->X_op == O_big
477330fc 1050 || (ep->X_add_symbol
5287ad62 1051 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1052 || (ep->X_op_symbol
5287ad62 1053 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1054 {
1055 inst.error = _("invalid constant");
1056 *str = input_line_pointer;
1057 input_line_pointer = save_in;
1058 return 1;
1059 }
b99bd4ef 1060
c19d1205
ZW
1061 *str = input_line_pointer;
1062 input_line_pointer = save_in;
1063 return 0;
b99bd4ef
NC
1064}
1065
c19d1205
ZW
1066/* Turn a string in input_line_pointer into a floating point constant
1067 of type TYPE, and store the appropriate bytes in *LITP. The number
1068 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1069 returned, or NULL on OK.
b99bd4ef 1070
c19d1205
ZW
1071 Note that fp constants aren't represent in the normal way on the ARM.
1072 In big endian mode, things are as expected. However, in little endian
1073 mode fp constants are big-endian word-wise, and little-endian byte-wise
1074 within the words. For example, (double) 1.1 in big endian mode is
1075 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1076 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1077
c19d1205 1078 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1079
6d4af3c2 1080const char *
c19d1205
ZW
1081md_atof (int type, char * litP, int * sizeP)
1082{
1083 int prec;
1084 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1085 char *t;
1086 int i;
b99bd4ef 1087
c19d1205
ZW
1088 switch (type)
1089 {
1090 case 'f':
1091 case 'F':
1092 case 's':
1093 case 'S':
1094 prec = 2;
1095 break;
b99bd4ef 1096
c19d1205
ZW
1097 case 'd':
1098 case 'D':
1099 case 'r':
1100 case 'R':
1101 prec = 4;
1102 break;
b99bd4ef 1103
c19d1205
ZW
1104 case 'x':
1105 case 'X':
499ac353 1106 prec = 5;
c19d1205 1107 break;
b99bd4ef 1108
c19d1205
ZW
1109 case 'p':
1110 case 'P':
499ac353 1111 prec = 5;
c19d1205 1112 break;
a737bd4d 1113
c19d1205
ZW
1114 default:
1115 *sizeP = 0;
499ac353 1116 return _("Unrecognized or unsupported floating point constant");
c19d1205 1117 }
b99bd4ef 1118
c19d1205
ZW
1119 t = atof_ieee (input_line_pointer, type, words);
1120 if (t)
1121 input_line_pointer = t;
499ac353 1122 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1123
c19d1205
ZW
1124 if (target_big_endian)
1125 {
1126 for (i = 0; i < prec; i++)
1127 {
499ac353
NC
1128 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1129 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1130 }
1131 }
1132 else
1133 {
e74cfd16 1134 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1135 for (i = prec - 1; i >= 0; i--)
1136 {
499ac353
NC
1137 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1138 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1139 }
1140 else
1141 /* For a 4 byte float the order of elements in `words' is 1 0.
1142 For an 8 byte float the order is 1 0 3 2. */
1143 for (i = 0; i < prec; i += 2)
1144 {
499ac353
NC
1145 md_number_to_chars (litP, (valueT) words[i + 1],
1146 sizeof (LITTLENUM_TYPE));
1147 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1148 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1149 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1150 }
1151 }
b99bd4ef 1152
499ac353 1153 return NULL;
c19d1205 1154}
b99bd4ef 1155
c19d1205
ZW
1156/* We handle all bad expressions here, so that we can report the faulty
1157 instruction in the error message. */
1158void
91d6fa6a 1159md_operand (expressionS * exp)
c19d1205
ZW
1160{
1161 if (in_my_get_expression)
91d6fa6a 1162 exp->X_op = O_illegal;
b99bd4ef
NC
1163}
1164
c19d1205 1165/* Immediate values. */
b99bd4ef 1166
c19d1205
ZW
1167/* Generic immediate-value read function for use in directives.
1168 Accepts anything that 'expression' can fold to a constant.
1169 *val receives the number. */
1170#ifdef OBJ_ELF
1171static int
1172immediate_for_directive (int *val)
b99bd4ef 1173{
c19d1205
ZW
1174 expressionS exp;
1175 exp.X_op = O_illegal;
b99bd4ef 1176
c19d1205
ZW
1177 if (is_immediate_prefix (*input_line_pointer))
1178 {
1179 input_line_pointer++;
1180 expression (&exp);
1181 }
b99bd4ef 1182
c19d1205
ZW
1183 if (exp.X_op != O_constant)
1184 {
1185 as_bad (_("expected #constant"));
1186 ignore_rest_of_line ();
1187 return FAIL;
1188 }
1189 *val = exp.X_add_number;
1190 return SUCCESS;
b99bd4ef 1191}
c19d1205 1192#endif
b99bd4ef 1193
c19d1205 1194/* Register parsing. */
b99bd4ef 1195
c19d1205
ZW
1196/* Generic register parser. CCP points to what should be the
1197 beginning of a register name. If it is indeed a valid register
1198 name, advance CCP over it and return the reg_entry structure;
1199 otherwise return NULL. Does not issue diagnostics. */
1200
1201static struct reg_entry *
1202arm_reg_parse_multi (char **ccp)
b99bd4ef 1203{
c19d1205
ZW
1204 char *start = *ccp;
1205 char *p;
1206 struct reg_entry *reg;
b99bd4ef 1207
477330fc
RM
1208 skip_whitespace (start);
1209
c19d1205
ZW
1210#ifdef REGISTER_PREFIX
1211 if (*start != REGISTER_PREFIX)
01cfc07f 1212 return NULL;
c19d1205
ZW
1213 start++;
1214#endif
1215#ifdef OPTIONAL_REGISTER_PREFIX
1216 if (*start == OPTIONAL_REGISTER_PREFIX)
1217 start++;
1218#endif
b99bd4ef 1219
c19d1205
ZW
1220 p = start;
1221 if (!ISALPHA (*p) || !is_name_beginner (*p))
1222 return NULL;
b99bd4ef 1223
c19d1205
ZW
1224 do
1225 p++;
1226 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1227
1228 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1229
1230 if (!reg)
1231 return NULL;
1232
1233 *ccp = p;
1234 return reg;
b99bd4ef
NC
1235}
1236
1237static int
dcbf9037 1238arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1239 enum arm_reg_type type)
b99bd4ef 1240{
c19d1205
ZW
1241 /* Alternative syntaxes are accepted for a few register classes. */
1242 switch (type)
1243 {
1244 case REG_TYPE_MVF:
1245 case REG_TYPE_MVD:
1246 case REG_TYPE_MVFX:
1247 case REG_TYPE_MVDX:
1248 /* Generic coprocessor register names are allowed for these. */
79134647 1249 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1250 return reg->number;
1251 break;
69b97547 1252
c19d1205
ZW
1253 case REG_TYPE_CP:
1254 /* For backward compatibility, a bare number is valid here. */
1255 {
1256 unsigned long processor = strtoul (start, ccp, 10);
1257 if (*ccp != start && processor <= 15)
1258 return processor;
1259 }
6057a28f 1260
c19d1205
ZW
1261 case REG_TYPE_MMXWC:
1262 /* WC includes WCG. ??? I'm not sure this is true for all
1263 instructions that take WC registers. */
79134647 1264 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1265 return reg->number;
6057a28f 1266 break;
c19d1205 1267
6057a28f 1268 default:
c19d1205 1269 break;
6057a28f
NC
1270 }
1271
dcbf9037
JB
1272 return FAIL;
1273}
1274
1275/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1276 return value is the register number or FAIL. */
1277
1278static int
1279arm_reg_parse (char **ccp, enum arm_reg_type type)
1280{
1281 char *start = *ccp;
1282 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1283 int ret;
1284
1285 /* Do not allow a scalar (reg+index) to parse as a register. */
1286 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1287 return FAIL;
1288
1289 if (reg && reg->type == type)
1290 return reg->number;
1291
1292 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1293 return ret;
1294
c19d1205
ZW
1295 *ccp = start;
1296 return FAIL;
1297}
69b97547 1298
dcbf9037
JB
1299/* Parse a Neon type specifier. *STR should point at the leading '.'
1300 character. Does no verification at this stage that the type fits the opcode
1301 properly. E.g.,
1302
1303 .i32.i32.s16
1304 .s32.f32
1305 .u16
1306
1307 Can all be legally parsed by this function.
1308
1309 Fills in neon_type struct pointer with parsed information, and updates STR
1310 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1311 type, FAIL if not. */
1312
1313static int
1314parse_neon_type (struct neon_type *type, char **str)
1315{
1316 char *ptr = *str;
1317
1318 if (type)
1319 type->elems = 0;
1320
1321 while (type->elems < NEON_MAX_TYPE_ELS)
1322 {
1323 enum neon_el_type thistype = NT_untyped;
1324 unsigned thissize = -1u;
1325
1326 if (*ptr != '.')
1327 break;
1328
1329 ptr++;
1330
1331 /* Just a size without an explicit type. */
1332 if (ISDIGIT (*ptr))
1333 goto parsesize;
1334
1335 switch (TOLOWER (*ptr))
1336 {
1337 case 'i': thistype = NT_integer; break;
1338 case 'f': thistype = NT_float; break;
1339 case 'p': thistype = NT_poly; break;
1340 case 's': thistype = NT_signed; break;
1341 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1342 case 'd':
1343 thistype = NT_float;
1344 thissize = 64;
1345 ptr++;
1346 goto done;
dcbf9037
JB
1347 default:
1348 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1349 return FAIL;
1350 }
1351
1352 ptr++;
1353
1354 /* .f is an abbreviation for .f32. */
1355 if (thistype == NT_float && !ISDIGIT (*ptr))
1356 thissize = 32;
1357 else
1358 {
1359 parsesize:
1360 thissize = strtoul (ptr, &ptr, 10);
1361
1362 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1363 && thissize != 64)
1364 {
1365 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1366 return FAIL;
1367 }
1368 }
1369
037e8744 1370 done:
dcbf9037 1371 if (type)
477330fc
RM
1372 {
1373 type->el[type->elems].type = thistype;
dcbf9037
JB
1374 type->el[type->elems].size = thissize;
1375 type->elems++;
1376 }
1377 }
1378
1379 /* Empty/missing type is not a successful parse. */
1380 if (type->elems == 0)
1381 return FAIL;
1382
1383 *str = ptr;
1384
1385 return SUCCESS;
1386}
1387
1388/* Errors may be set multiple times during parsing or bit encoding
1389 (particularly in the Neon bits), but usually the earliest error which is set
1390 will be the most meaningful. Avoid overwriting it with later (cascading)
1391 errors by calling this function. */
1392
1393static void
1394first_error (const char *err)
1395{
1396 if (!inst.error)
1397 inst.error = err;
1398}
1399
1400/* Parse a single type, e.g. ".s32", leading period included. */
1401static int
1402parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1403{
1404 char *str = *ccp;
1405 struct neon_type optype;
1406
1407 if (*str == '.')
1408 {
1409 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1410 {
1411 if (optype.elems == 1)
1412 *vectype = optype.el[0];
1413 else
1414 {
1415 first_error (_("only one type should be specified for operand"));
1416 return FAIL;
1417 }
1418 }
dcbf9037 1419 else
477330fc
RM
1420 {
1421 first_error (_("vector type expected"));
1422 return FAIL;
1423 }
dcbf9037
JB
1424 }
1425 else
1426 return FAIL;
5f4273c7 1427
dcbf9037 1428 *ccp = str;
5f4273c7 1429
dcbf9037
JB
1430 return SUCCESS;
1431}
1432
1433/* Special meanings for indices (which have a range of 0-7), which will fit into
1434 a 4-bit integer. */
1435
1436#define NEON_ALL_LANES 15
1437#define NEON_INTERLEAVE_LANES 14
1438
1439/* Parse either a register or a scalar, with an optional type. Return the
1440 register number, and optionally fill in the actual type of the register
1441 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1442 type/index information in *TYPEINFO. */
1443
1444static int
1445parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1446 enum arm_reg_type *rtype,
1447 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1448{
1449 char *str = *ccp;
1450 struct reg_entry *reg = arm_reg_parse_multi (&str);
1451 struct neon_typed_alias atype;
1452 struct neon_type_el parsetype;
1453
1454 atype.defined = 0;
1455 atype.index = -1;
1456 atype.eltype.type = NT_invtype;
1457 atype.eltype.size = -1;
1458
1459 /* Try alternate syntax for some types of register. Note these are mutually
1460 exclusive with the Neon syntax extensions. */
1461 if (reg == NULL)
1462 {
1463 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1464 if (altreg != FAIL)
477330fc 1465 *ccp = str;
dcbf9037 1466 if (typeinfo)
477330fc 1467 *typeinfo = atype;
dcbf9037
JB
1468 return altreg;
1469 }
1470
037e8744
JB
1471 /* Undo polymorphism when a set of register types may be accepted. */
1472 if ((type == REG_TYPE_NDQ
1473 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1474 || (type == REG_TYPE_VFSD
477330fc 1475 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1476 || (type == REG_TYPE_NSDQ
477330fc
RM
1477 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1478 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1479 || (type == REG_TYPE_MMXWC
1480 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1481 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1482
1483 if (type != reg->type)
1484 return FAIL;
1485
1486 if (reg->neon)
1487 atype = *reg->neon;
5f4273c7 1488
dcbf9037
JB
1489 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1490 {
1491 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1492 {
1493 first_error (_("can't redefine type for operand"));
1494 return FAIL;
1495 }
dcbf9037
JB
1496 atype.defined |= NTA_HASTYPE;
1497 atype.eltype = parsetype;
1498 }
5f4273c7 1499
dcbf9037
JB
1500 if (skip_past_char (&str, '[') == SUCCESS)
1501 {
1502 if (type != REG_TYPE_VFD)
477330fc
RM
1503 {
1504 first_error (_("only D registers may be indexed"));
1505 return FAIL;
1506 }
5f4273c7 1507
dcbf9037 1508 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1509 {
1510 first_error (_("can't change index for operand"));
1511 return FAIL;
1512 }
dcbf9037
JB
1513
1514 atype.defined |= NTA_HASINDEX;
1515
1516 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1517 atype.index = NEON_ALL_LANES;
dcbf9037 1518 else
477330fc
RM
1519 {
1520 expressionS exp;
dcbf9037 1521
477330fc 1522 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1523
477330fc
RM
1524 if (exp.X_op != O_constant)
1525 {
1526 first_error (_("constant expression required"));
1527 return FAIL;
1528 }
dcbf9037 1529
477330fc
RM
1530 if (skip_past_char (&str, ']') == FAIL)
1531 return FAIL;
dcbf9037 1532
477330fc
RM
1533 atype.index = exp.X_add_number;
1534 }
dcbf9037 1535 }
5f4273c7 1536
dcbf9037
JB
1537 if (typeinfo)
1538 *typeinfo = atype;
5f4273c7 1539
dcbf9037
JB
1540 if (rtype)
1541 *rtype = type;
5f4273c7 1542
dcbf9037 1543 *ccp = str;
5f4273c7 1544
dcbf9037
JB
1545 return reg->number;
1546}
1547
1548/* Like arm_reg_parse, but allow allow the following extra features:
1549 - If RTYPE is non-zero, return the (possibly restricted) type of the
1550 register (e.g. Neon double or quad reg when either has been requested).
1551 - If this is a Neon vector type with additional type information, fill
1552 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1553 This function will fault on encountering a scalar. */
dcbf9037
JB
1554
1555static int
1556arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1557 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1558{
1559 struct neon_typed_alias atype;
1560 char *str = *ccp;
1561 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1562
1563 if (reg == FAIL)
1564 return FAIL;
1565
0855e32b
NS
1566 /* Do not allow regname(... to parse as a register. */
1567 if (*str == '(')
1568 return FAIL;
1569
dcbf9037
JB
1570 /* Do not allow a scalar (reg+index) to parse as a register. */
1571 if ((atype.defined & NTA_HASINDEX) != 0)
1572 {
1573 first_error (_("register operand expected, but got scalar"));
1574 return FAIL;
1575 }
1576
1577 if (vectype)
1578 *vectype = atype.eltype;
1579
1580 *ccp = str;
1581
1582 return reg;
1583}
1584
1585#define NEON_SCALAR_REG(X) ((X) >> 4)
1586#define NEON_SCALAR_INDEX(X) ((X) & 15)
1587
5287ad62
JB
1588/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1589 have enough information to be able to do a good job bounds-checking. So, we
1590 just do easy checks here, and do further checks later. */
1591
1592static int
dcbf9037 1593parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1594{
dcbf9037 1595 int reg;
5287ad62 1596 char *str = *ccp;
dcbf9037 1597 struct neon_typed_alias atype;
5f4273c7 1598
dcbf9037 1599 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1600
dcbf9037 1601 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1602 return FAIL;
5f4273c7 1603
dcbf9037 1604 if (atype.index == NEON_ALL_LANES)
5287ad62 1605 {
dcbf9037 1606 first_error (_("scalar must have an index"));
5287ad62
JB
1607 return FAIL;
1608 }
dcbf9037 1609 else if (atype.index >= 64 / elsize)
5287ad62 1610 {
dcbf9037 1611 first_error (_("scalar index out of range"));
5287ad62
JB
1612 return FAIL;
1613 }
5f4273c7 1614
dcbf9037
JB
1615 if (type)
1616 *type = atype.eltype;
5f4273c7 1617
5287ad62 1618 *ccp = str;
5f4273c7 1619
dcbf9037 1620 return reg * 16 + atype.index;
5287ad62
JB
1621}
1622
c19d1205 1623/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1624
c19d1205
ZW
1625static long
1626parse_reg_list (char ** strp)
1627{
1628 char * str = * strp;
1629 long range = 0;
1630 int another_range;
a737bd4d 1631
c19d1205
ZW
1632 /* We come back here if we get ranges concatenated by '+' or '|'. */
1633 do
6057a28f 1634 {
477330fc
RM
1635 skip_whitespace (str);
1636
c19d1205 1637 another_range = 0;
a737bd4d 1638
c19d1205
ZW
1639 if (*str == '{')
1640 {
1641 int in_range = 0;
1642 int cur_reg = -1;
a737bd4d 1643
c19d1205
ZW
1644 str++;
1645 do
1646 {
1647 int reg;
6057a28f 1648
dcbf9037 1649 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1650 {
dcbf9037 1651 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1652 return FAIL;
1653 }
a737bd4d 1654
c19d1205
ZW
1655 if (in_range)
1656 {
1657 int i;
a737bd4d 1658
c19d1205
ZW
1659 if (reg <= cur_reg)
1660 {
dcbf9037 1661 first_error (_("bad range in register list"));
c19d1205
ZW
1662 return FAIL;
1663 }
40a18ebd 1664
c19d1205
ZW
1665 for (i = cur_reg + 1; i < reg; i++)
1666 {
1667 if (range & (1 << i))
1668 as_tsktsk
1669 (_("Warning: duplicated register (r%d) in register list"),
1670 i);
1671 else
1672 range |= 1 << i;
1673 }
1674 in_range = 0;
1675 }
a737bd4d 1676
c19d1205
ZW
1677 if (range & (1 << reg))
1678 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1679 reg);
1680 else if (reg <= cur_reg)
1681 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1682
c19d1205
ZW
1683 range |= 1 << reg;
1684 cur_reg = reg;
1685 }
1686 while (skip_past_comma (&str) != FAIL
1687 || (in_range = 1, *str++ == '-'));
1688 str--;
a737bd4d 1689
d996d970 1690 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1691 {
dcbf9037 1692 first_error (_("missing `}'"));
c19d1205
ZW
1693 return FAIL;
1694 }
1695 }
1696 else
1697 {
91d6fa6a 1698 expressionS exp;
40a18ebd 1699
91d6fa6a 1700 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1701 return FAIL;
40a18ebd 1702
91d6fa6a 1703 if (exp.X_op == O_constant)
c19d1205 1704 {
91d6fa6a
NC
1705 if (exp.X_add_number
1706 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1707 {
1708 inst.error = _("invalid register mask");
1709 return FAIL;
1710 }
a737bd4d 1711
91d6fa6a 1712 if ((range & exp.X_add_number) != 0)
c19d1205 1713 {
91d6fa6a 1714 int regno = range & exp.X_add_number;
a737bd4d 1715
c19d1205
ZW
1716 regno &= -regno;
1717 regno = (1 << regno) - 1;
1718 as_tsktsk
1719 (_("Warning: duplicated register (r%d) in register list"),
1720 regno);
1721 }
a737bd4d 1722
91d6fa6a 1723 range |= exp.X_add_number;
c19d1205
ZW
1724 }
1725 else
1726 {
1727 if (inst.reloc.type != 0)
1728 {
1729 inst.error = _("expression too complex");
1730 return FAIL;
1731 }
a737bd4d 1732
91d6fa6a 1733 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1734 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1735 inst.reloc.pc_rel = 0;
1736 }
1737 }
a737bd4d 1738
c19d1205
ZW
1739 if (*str == '|' || *str == '+')
1740 {
1741 str++;
1742 another_range = 1;
1743 }
a737bd4d 1744 }
c19d1205 1745 while (another_range);
a737bd4d 1746
c19d1205
ZW
1747 *strp = str;
1748 return range;
a737bd4d
NC
1749}
1750
5287ad62
JB
1751/* Types of registers in a list. */
1752
1753enum reg_list_els
1754{
1755 REGLIST_VFP_S,
1756 REGLIST_VFP_D,
1757 REGLIST_NEON_D
1758};
1759
c19d1205
ZW
1760/* Parse a VFP register list. If the string is invalid return FAIL.
1761 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1762 register. Parses registers of type ETYPE.
1763 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1764 - Q registers can be used to specify pairs of D registers
1765 - { } can be omitted from around a singleton register list
477330fc
RM
1766 FIXME: This is not implemented, as it would require backtracking in
1767 some cases, e.g.:
1768 vtbl.8 d3,d4,d5
1769 This could be done (the meaning isn't really ambiguous), but doesn't
1770 fit in well with the current parsing framework.
dcbf9037
JB
1771 - 32 D registers may be used (also true for VFPv3).
1772 FIXME: Types are ignored in these register lists, which is probably a
1773 bug. */
6057a28f 1774
c19d1205 1775static int
037e8744 1776parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1777{
037e8744 1778 char *str = *ccp;
c19d1205
ZW
1779 int base_reg;
1780 int new_base;
21d799b5 1781 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1782 int max_regs = 0;
c19d1205
ZW
1783 int count = 0;
1784 int warned = 0;
1785 unsigned long mask = 0;
a737bd4d 1786 int i;
6057a28f 1787
477330fc 1788 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1789 {
1790 inst.error = _("expecting {");
1791 return FAIL;
1792 }
6057a28f 1793
5287ad62 1794 switch (etype)
c19d1205 1795 {
5287ad62 1796 case REGLIST_VFP_S:
c19d1205
ZW
1797 regtype = REG_TYPE_VFS;
1798 max_regs = 32;
5287ad62 1799 break;
5f4273c7 1800
5287ad62
JB
1801 case REGLIST_VFP_D:
1802 regtype = REG_TYPE_VFD;
b7fc2769 1803 break;
5f4273c7 1804
b7fc2769
JB
1805 case REGLIST_NEON_D:
1806 regtype = REG_TYPE_NDQ;
1807 break;
1808 }
1809
1810 if (etype != REGLIST_VFP_S)
1811 {
b1cc4aeb
PB
1812 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1813 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1814 {
1815 max_regs = 32;
1816 if (thumb_mode)
1817 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1818 fpu_vfp_ext_d32);
1819 else
1820 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1821 fpu_vfp_ext_d32);
1822 }
5287ad62 1823 else
477330fc 1824 max_regs = 16;
c19d1205 1825 }
6057a28f 1826
c19d1205 1827 base_reg = max_regs;
a737bd4d 1828
c19d1205
ZW
1829 do
1830 {
5287ad62 1831 int setmask = 1, addregs = 1;
dcbf9037 1832
037e8744 1833 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1834
c19d1205 1835 if (new_base == FAIL)
a737bd4d 1836 {
dcbf9037 1837 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1838 return FAIL;
1839 }
5f4273c7 1840
b7fc2769 1841 if (new_base >= max_regs)
477330fc
RM
1842 {
1843 first_error (_("register out of range in list"));
1844 return FAIL;
1845 }
5f4273c7 1846
5287ad62
JB
1847 /* Note: a value of 2 * n is returned for the register Q<n>. */
1848 if (regtype == REG_TYPE_NQ)
477330fc
RM
1849 {
1850 setmask = 3;
1851 addregs = 2;
1852 }
5287ad62 1853
c19d1205
ZW
1854 if (new_base < base_reg)
1855 base_reg = new_base;
a737bd4d 1856
5287ad62 1857 if (mask & (setmask << new_base))
c19d1205 1858 {
dcbf9037 1859 first_error (_("invalid register list"));
c19d1205 1860 return FAIL;
a737bd4d 1861 }
a737bd4d 1862
c19d1205
ZW
1863 if ((mask >> new_base) != 0 && ! warned)
1864 {
1865 as_tsktsk (_("register list not in ascending order"));
1866 warned = 1;
1867 }
0bbf2aa4 1868
5287ad62
JB
1869 mask |= setmask << new_base;
1870 count += addregs;
0bbf2aa4 1871
037e8744 1872 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1873 {
1874 int high_range;
0bbf2aa4 1875
037e8744 1876 str++;
0bbf2aa4 1877
037e8744 1878 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1879 == FAIL)
c19d1205
ZW
1880 {
1881 inst.error = gettext (reg_expected_msgs[regtype]);
1882 return FAIL;
1883 }
0bbf2aa4 1884
477330fc
RM
1885 if (high_range >= max_regs)
1886 {
1887 first_error (_("register out of range in list"));
1888 return FAIL;
1889 }
b7fc2769 1890
477330fc
RM
1891 if (regtype == REG_TYPE_NQ)
1892 high_range = high_range + 1;
5287ad62 1893
c19d1205
ZW
1894 if (high_range <= new_base)
1895 {
1896 inst.error = _("register range not in ascending order");
1897 return FAIL;
1898 }
0bbf2aa4 1899
5287ad62 1900 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1901 {
5287ad62 1902 if (mask & (setmask << new_base))
0bbf2aa4 1903 {
c19d1205
ZW
1904 inst.error = _("invalid register list");
1905 return FAIL;
0bbf2aa4 1906 }
c19d1205 1907
5287ad62
JB
1908 mask |= setmask << new_base;
1909 count += addregs;
0bbf2aa4 1910 }
0bbf2aa4 1911 }
0bbf2aa4 1912 }
037e8744 1913 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1914
037e8744 1915 str++;
0bbf2aa4 1916
c19d1205
ZW
1917 /* Sanity check -- should have raised a parse error above. */
1918 if (count == 0 || count > max_regs)
1919 abort ();
1920
1921 *pbase = base_reg;
1922
1923 /* Final test -- the registers must be consecutive. */
1924 mask >>= base_reg;
1925 for (i = 0; i < count; i++)
1926 {
1927 if ((mask & (1u << i)) == 0)
1928 {
1929 inst.error = _("non-contiguous register range");
1930 return FAIL;
1931 }
1932 }
1933
037e8744
JB
1934 *ccp = str;
1935
c19d1205 1936 return count;
b99bd4ef
NC
1937}
1938
dcbf9037
JB
1939/* True if two alias types are the same. */
1940
c921be7d 1941static bfd_boolean
dcbf9037
JB
1942neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1943{
1944 if (!a && !b)
c921be7d 1945 return TRUE;
5f4273c7 1946
dcbf9037 1947 if (!a || !b)
c921be7d 1948 return FALSE;
dcbf9037
JB
1949
1950 if (a->defined != b->defined)
c921be7d 1951 return FALSE;
5f4273c7 1952
dcbf9037
JB
1953 if ((a->defined & NTA_HASTYPE) != 0
1954 && (a->eltype.type != b->eltype.type
477330fc 1955 || a->eltype.size != b->eltype.size))
c921be7d 1956 return FALSE;
dcbf9037
JB
1957
1958 if ((a->defined & NTA_HASINDEX) != 0
1959 && (a->index != b->index))
c921be7d 1960 return FALSE;
5f4273c7 1961
c921be7d 1962 return TRUE;
dcbf9037
JB
1963}
1964
5287ad62
JB
1965/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1966 The base register is put in *PBASE.
dcbf9037 1967 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1968 the return value.
1969 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1970 Bits [6:5] encode the list length (minus one).
1971 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1972
5287ad62 1973#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1974#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1975#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1976
1977static int
dcbf9037 1978parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1979 struct neon_type_el *eltype)
5287ad62
JB
1980{
1981 char *ptr = *str;
1982 int base_reg = -1;
1983 int reg_incr = -1;
1984 int count = 0;
1985 int lane = -1;
1986 int leading_brace = 0;
1987 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1988 const char *const incr_error = _("register stride must be 1 or 2");
1989 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1990 struct neon_typed_alias firsttype;
5f4273c7 1991
5287ad62
JB
1992 if (skip_past_char (&ptr, '{') == SUCCESS)
1993 leading_brace = 1;
5f4273c7 1994
5287ad62
JB
1995 do
1996 {
dcbf9037
JB
1997 struct neon_typed_alias atype;
1998 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1999
5287ad62 2000 if (getreg == FAIL)
477330fc
RM
2001 {
2002 first_error (_(reg_expected_msgs[rtype]));
2003 return FAIL;
2004 }
5f4273c7 2005
5287ad62 2006 if (base_reg == -1)
477330fc
RM
2007 {
2008 base_reg = getreg;
2009 if (rtype == REG_TYPE_NQ)
2010 {
2011 reg_incr = 1;
2012 }
2013 firsttype = atype;
2014 }
5287ad62 2015 else if (reg_incr == -1)
477330fc
RM
2016 {
2017 reg_incr = getreg - base_reg;
2018 if (reg_incr < 1 || reg_incr > 2)
2019 {
2020 first_error (_(incr_error));
2021 return FAIL;
2022 }
2023 }
5287ad62 2024 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2025 {
2026 first_error (_(incr_error));
2027 return FAIL;
2028 }
dcbf9037 2029
c921be7d 2030 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2031 {
2032 first_error (_(type_error));
2033 return FAIL;
2034 }
5f4273c7 2035
5287ad62 2036 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2037 modes. */
5287ad62 2038 if (ptr[0] == '-')
477330fc
RM
2039 {
2040 struct neon_typed_alias htype;
2041 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2042 if (lane == -1)
2043 lane = NEON_INTERLEAVE_LANES;
2044 else if (lane != NEON_INTERLEAVE_LANES)
2045 {
2046 first_error (_(type_error));
2047 return FAIL;
2048 }
2049 if (reg_incr == -1)
2050 reg_incr = 1;
2051 else if (reg_incr != 1)
2052 {
2053 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2054 return FAIL;
2055 }
2056 ptr++;
2057 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2058 if (hireg == FAIL)
2059 {
2060 first_error (_(reg_expected_msgs[rtype]));
2061 return FAIL;
2062 }
2063 if (! neon_alias_types_same (&htype, &firsttype))
2064 {
2065 first_error (_(type_error));
2066 return FAIL;
2067 }
2068 count += hireg + dregs - getreg;
2069 continue;
2070 }
5f4273c7 2071
5287ad62
JB
2072 /* If we're using Q registers, we can't use [] or [n] syntax. */
2073 if (rtype == REG_TYPE_NQ)
477330fc
RM
2074 {
2075 count += 2;
2076 continue;
2077 }
5f4273c7 2078
dcbf9037 2079 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2080 {
2081 if (lane == -1)
2082 lane = atype.index;
2083 else if (lane != atype.index)
2084 {
2085 first_error (_(type_error));
2086 return FAIL;
2087 }
2088 }
5287ad62 2089 else if (lane == -1)
477330fc 2090 lane = NEON_INTERLEAVE_LANES;
5287ad62 2091 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2092 {
2093 first_error (_(type_error));
2094 return FAIL;
2095 }
5287ad62
JB
2096 count++;
2097 }
2098 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2099
5287ad62
JB
2100 /* No lane set by [x]. We must be interleaving structures. */
2101 if (lane == -1)
2102 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2103
5287ad62
JB
2104 /* Sanity check. */
2105 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2106 || (count > 1 && reg_incr == -1))
2107 {
dcbf9037 2108 first_error (_("error parsing element/structure list"));
5287ad62
JB
2109 return FAIL;
2110 }
2111
2112 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2113 {
dcbf9037 2114 first_error (_("expected }"));
5287ad62
JB
2115 return FAIL;
2116 }
5f4273c7 2117
5287ad62
JB
2118 if (reg_incr == -1)
2119 reg_incr = 1;
2120
dcbf9037
JB
2121 if (eltype)
2122 *eltype = firsttype.eltype;
2123
5287ad62
JB
2124 *pbase = base_reg;
2125 *str = ptr;
5f4273c7 2126
5287ad62
JB
2127 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2128}
2129
c19d1205
ZW
2130/* Parse an explicit relocation suffix on an expression. This is
2131 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2132 arm_reloc_hsh contains no entries, so this function can only
2133 succeed if there is no () after the word. Returns -1 on error,
2134 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2135
c19d1205
ZW
2136static int
2137parse_reloc (char **str)
b99bd4ef 2138{
c19d1205
ZW
2139 struct reloc_entry *r;
2140 char *p, *q;
b99bd4ef 2141
c19d1205
ZW
2142 if (**str != '(')
2143 return BFD_RELOC_UNUSED;
b99bd4ef 2144
c19d1205
ZW
2145 p = *str + 1;
2146 q = p;
2147
2148 while (*q && *q != ')' && *q != ',')
2149 q++;
2150 if (*q != ')')
2151 return -1;
2152
21d799b5
NC
2153 if ((r = (struct reloc_entry *)
2154 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2155 return -1;
2156
2157 *str = q + 1;
2158 return r->reloc;
b99bd4ef
NC
2159}
2160
c19d1205
ZW
2161/* Directives: register aliases. */
2162
dcbf9037 2163static struct reg_entry *
90ec0d68 2164insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2165{
d3ce72d0 2166 struct reg_entry *new_reg;
c19d1205 2167 const char *name;
b99bd4ef 2168
d3ce72d0 2169 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2170 {
d3ce72d0 2171 if (new_reg->builtin)
c19d1205 2172 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2173
c19d1205
ZW
2174 /* Only warn about a redefinition if it's not defined as the
2175 same register. */
d3ce72d0 2176 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2177 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2178
d929913e 2179 return NULL;
c19d1205 2180 }
b99bd4ef 2181
c19d1205 2182 name = xstrdup (str);
325801bd 2183 new_reg = XNEW (struct reg_entry);
b99bd4ef 2184
d3ce72d0
NC
2185 new_reg->name = name;
2186 new_reg->number = number;
2187 new_reg->type = type;
2188 new_reg->builtin = FALSE;
2189 new_reg->neon = NULL;
b99bd4ef 2190
d3ce72d0 2191 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2192 abort ();
5f4273c7 2193
d3ce72d0 2194 return new_reg;
dcbf9037
JB
2195}
2196
2197static void
2198insert_neon_reg_alias (char *str, int number, int type,
477330fc 2199 struct neon_typed_alias *atype)
dcbf9037
JB
2200{
2201 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2202
dcbf9037
JB
2203 if (!reg)
2204 {
2205 first_error (_("attempt to redefine typed alias"));
2206 return;
2207 }
5f4273c7 2208
dcbf9037
JB
2209 if (atype)
2210 {
325801bd 2211 reg->neon = XNEW (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
e1fa0163 2257 nbuf = xmalloc (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)
e1fa0163
NC
2281 {
2282 free (nbuf);
2283 return TRUE;
2284 }
d929913e 2285 }
c19d1205 2286
d929913e
NC
2287 for (p = nbuf; *p; p++)
2288 *p = TOLOWER (*p);
c19d1205 2289
d929913e
NC
2290 if (strncmp (nbuf, newname, nlen))
2291 insert_reg_alias (nbuf, old->number, old->type);
2292 }
c19d1205 2293
e1fa0163 2294 free (nbuf);
d929913e 2295 return TRUE;
b99bd4ef
NC
2296}
2297
dcbf9037
JB
2298/* Create a Neon typed/indexed register alias using directives, e.g.:
2299 X .dn d5.s32[1]
2300 Y .qn 6.s16
2301 Z .dn d7
2302 T .dn Z[0]
2303 These typed registers can be used instead of the types specified after the
2304 Neon mnemonic, so long as all operands given have types. Types can also be
2305 specified directly, e.g.:
5f4273c7 2306 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2307
c921be7d 2308static bfd_boolean
dcbf9037
JB
2309create_neon_reg_alias (char *newname, char *p)
2310{
2311 enum arm_reg_type basetype;
2312 struct reg_entry *basereg;
2313 struct reg_entry mybasereg;
2314 struct neon_type ntype;
2315 struct neon_typed_alias typeinfo;
12d6b0b7 2316 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2317 int namelen;
5f4273c7 2318
dcbf9037
JB
2319 typeinfo.defined = 0;
2320 typeinfo.eltype.type = NT_invtype;
2321 typeinfo.eltype.size = -1;
2322 typeinfo.index = -1;
5f4273c7 2323
dcbf9037 2324 nameend = p;
5f4273c7 2325
dcbf9037
JB
2326 if (strncmp (p, " .dn ", 5) == 0)
2327 basetype = REG_TYPE_VFD;
2328 else if (strncmp (p, " .qn ", 5) == 0)
2329 basetype = REG_TYPE_NQ;
2330 else
c921be7d 2331 return FALSE;
5f4273c7 2332
dcbf9037 2333 p += 5;
5f4273c7 2334
dcbf9037 2335 if (*p == '\0')
c921be7d 2336 return FALSE;
5f4273c7 2337
dcbf9037
JB
2338 basereg = arm_reg_parse_multi (&p);
2339
2340 if (basereg && basereg->type != basetype)
2341 {
2342 as_bad (_("bad type for register"));
c921be7d 2343 return FALSE;
dcbf9037
JB
2344 }
2345
2346 if (basereg == NULL)
2347 {
2348 expressionS exp;
2349 /* Try parsing as an integer. */
2350 my_get_expression (&exp, &p, GE_NO_PREFIX);
2351 if (exp.X_op != O_constant)
477330fc
RM
2352 {
2353 as_bad (_("expression must be constant"));
2354 return FALSE;
2355 }
dcbf9037
JB
2356 basereg = &mybasereg;
2357 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2358 : exp.X_add_number;
dcbf9037
JB
2359 basereg->neon = 0;
2360 }
2361
2362 if (basereg->neon)
2363 typeinfo = *basereg->neon;
2364
2365 if (parse_neon_type (&ntype, &p) == SUCCESS)
2366 {
2367 /* We got a type. */
2368 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2369 {
2370 as_bad (_("can't redefine the type of a register alias"));
2371 return FALSE;
2372 }
5f4273c7 2373
dcbf9037
JB
2374 typeinfo.defined |= NTA_HASTYPE;
2375 if (ntype.elems != 1)
477330fc
RM
2376 {
2377 as_bad (_("you must specify a single type only"));
2378 return FALSE;
2379 }
dcbf9037
JB
2380 typeinfo.eltype = ntype.el[0];
2381 }
5f4273c7 2382
dcbf9037
JB
2383 if (skip_past_char (&p, '[') == SUCCESS)
2384 {
2385 expressionS exp;
2386 /* We got a scalar index. */
5f4273c7 2387
dcbf9037 2388 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2389 {
2390 as_bad (_("can't redefine the index of a scalar alias"));
2391 return FALSE;
2392 }
5f4273c7 2393
dcbf9037 2394 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2395
dcbf9037 2396 if (exp.X_op != O_constant)
477330fc
RM
2397 {
2398 as_bad (_("scalar index must be constant"));
2399 return FALSE;
2400 }
5f4273c7 2401
dcbf9037
JB
2402 typeinfo.defined |= NTA_HASINDEX;
2403 typeinfo.index = exp.X_add_number;
5f4273c7 2404
dcbf9037 2405 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2406 {
2407 as_bad (_("expecting ]"));
2408 return FALSE;
2409 }
dcbf9037
JB
2410 }
2411
15735687
NS
2412 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2413 the desired alias name, and p points to its end. If not, then
2414 the desired alias name is in the global original_case_string. */
2415#ifdef TC_CASE_SENSITIVE
dcbf9037 2416 namelen = nameend - newname;
15735687
NS
2417#else
2418 newname = original_case_string;
2419 namelen = strlen (newname);
2420#endif
2421
e1fa0163 2422 namebuf = xmalloc (namelen + 1);
dcbf9037
JB
2423 strncpy (namebuf, newname, namelen);
2424 namebuf[namelen] = '\0';
5f4273c7 2425
dcbf9037 2426 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2427 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2428
dcbf9037
JB
2429 /* Insert name in all uppercase. */
2430 for (p = namebuf; *p; p++)
2431 *p = TOUPPER (*p);
5f4273c7 2432
dcbf9037
JB
2433 if (strncmp (namebuf, newname, namelen))
2434 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2435 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2436
dcbf9037
JB
2437 /* Insert name in all lowercase. */
2438 for (p = namebuf; *p; p++)
2439 *p = TOLOWER (*p);
5f4273c7 2440
dcbf9037
JB
2441 if (strncmp (namebuf, newname, namelen))
2442 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2443 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2444
e1fa0163 2445 free (namebuf);
c921be7d 2446 return TRUE;
dcbf9037
JB
2447}
2448
c19d1205
ZW
2449/* Should never be called, as .req goes between the alias and the
2450 register name, not at the beginning of the line. */
c921be7d 2451
b99bd4ef 2452static void
c19d1205 2453s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2454{
c19d1205
ZW
2455 as_bad (_("invalid syntax for .req directive"));
2456}
b99bd4ef 2457
dcbf9037
JB
2458static void
2459s_dn (int a ATTRIBUTE_UNUSED)
2460{
2461 as_bad (_("invalid syntax for .dn directive"));
2462}
2463
2464static void
2465s_qn (int a ATTRIBUTE_UNUSED)
2466{
2467 as_bad (_("invalid syntax for .qn directive"));
2468}
2469
c19d1205
ZW
2470/* The .unreq directive deletes an alias which was previously defined
2471 by .req. For example:
b99bd4ef 2472
c19d1205
ZW
2473 my_alias .req r11
2474 .unreq my_alias */
b99bd4ef
NC
2475
2476static void
c19d1205 2477s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2478{
c19d1205
ZW
2479 char * name;
2480 char saved_char;
b99bd4ef 2481
c19d1205
ZW
2482 name = input_line_pointer;
2483
2484 while (*input_line_pointer != 0
2485 && *input_line_pointer != ' '
2486 && *input_line_pointer != '\n')
2487 ++input_line_pointer;
2488
2489 saved_char = *input_line_pointer;
2490 *input_line_pointer = 0;
2491
2492 if (!*name)
2493 as_bad (_("invalid syntax for .unreq directive"));
2494 else
2495 {
21d799b5 2496 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2497 name);
c19d1205
ZW
2498
2499 if (!reg)
2500 as_bad (_("unknown register alias '%s'"), name);
2501 else if (reg->builtin)
a1727c1a 2502 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2503 name);
2504 else
2505 {
d929913e
NC
2506 char * p;
2507 char * nbuf;
2508
db0bc284 2509 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2510 free ((char *) reg->name);
477330fc
RM
2511 if (reg->neon)
2512 free (reg->neon);
c19d1205 2513 free (reg);
d929913e
NC
2514
2515 /* Also locate the all upper case and all lower case versions.
2516 Do not complain if we cannot find one or the other as it
2517 was probably deleted above. */
5f4273c7 2518
d929913e
NC
2519 nbuf = strdup (name);
2520 for (p = nbuf; *p; p++)
2521 *p = TOUPPER (*p);
21d799b5 2522 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2523 if (reg)
2524 {
db0bc284 2525 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2526 free ((char *) reg->name);
2527 if (reg->neon)
2528 free (reg->neon);
2529 free (reg);
2530 }
2531
2532 for (p = nbuf; *p; p++)
2533 *p = TOLOWER (*p);
21d799b5 2534 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2535 if (reg)
2536 {
db0bc284 2537 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2538 free ((char *) reg->name);
2539 if (reg->neon)
2540 free (reg->neon);
2541 free (reg);
2542 }
2543
2544 free (nbuf);
c19d1205
ZW
2545 }
2546 }
b99bd4ef 2547
c19d1205 2548 *input_line_pointer = saved_char;
b99bd4ef
NC
2549 demand_empty_rest_of_line ();
2550}
2551
c19d1205
ZW
2552/* Directives: Instruction set selection. */
2553
2554#ifdef OBJ_ELF
2555/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2556 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2557 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2558 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2559
cd000bff
DJ
2560/* Create a new mapping symbol for the transition to STATE. */
2561
2562static void
2563make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2564{
a737bd4d 2565 symbolS * symbolP;
c19d1205
ZW
2566 const char * symname;
2567 int type;
b99bd4ef 2568
c19d1205 2569 switch (state)
b99bd4ef 2570 {
c19d1205
ZW
2571 case MAP_DATA:
2572 symname = "$d";
2573 type = BSF_NO_FLAGS;
2574 break;
2575 case MAP_ARM:
2576 symname = "$a";
2577 type = BSF_NO_FLAGS;
2578 break;
2579 case MAP_THUMB:
2580 symname = "$t";
2581 type = BSF_NO_FLAGS;
2582 break;
c19d1205
ZW
2583 default:
2584 abort ();
2585 }
2586
cd000bff 2587 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2588 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2589
2590 switch (state)
2591 {
2592 case MAP_ARM:
2593 THUMB_SET_FUNC (symbolP, 0);
2594 ARM_SET_THUMB (symbolP, 0);
2595 ARM_SET_INTERWORK (symbolP, support_interwork);
2596 break;
2597
2598 case MAP_THUMB:
2599 THUMB_SET_FUNC (symbolP, 1);
2600 ARM_SET_THUMB (symbolP, 1);
2601 ARM_SET_INTERWORK (symbolP, support_interwork);
2602 break;
2603
2604 case MAP_DATA:
2605 default:
cd000bff
DJ
2606 break;
2607 }
2608
2609 /* Save the mapping symbols for future reference. Also check that
2610 we do not place two mapping symbols at the same offset within a
2611 frag. We'll handle overlap between frags in
2de7820f
JZ
2612 check_mapping_symbols.
2613
2614 If .fill or other data filling directive generates zero sized data,
2615 the mapping symbol for the following code will have the same value
2616 as the one generated for the data filling directive. In this case,
2617 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2618 if (value == 0)
2619 {
2de7820f
JZ
2620 if (frag->tc_frag_data.first_map != NULL)
2621 {
2622 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2623 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2624 }
cd000bff
DJ
2625 frag->tc_frag_data.first_map = symbolP;
2626 }
2627 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2628 {
2629 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2630 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2631 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2632 }
cd000bff
DJ
2633 frag->tc_frag_data.last_map = symbolP;
2634}
2635
2636/* We must sometimes convert a region marked as code to data during
2637 code alignment, if an odd number of bytes have to be padded. The
2638 code mapping symbol is pushed to an aligned address. */
2639
2640static void
2641insert_data_mapping_symbol (enum mstate state,
2642 valueT value, fragS *frag, offsetT bytes)
2643{
2644 /* If there was already a mapping symbol, remove it. */
2645 if (frag->tc_frag_data.last_map != NULL
2646 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2647 {
2648 symbolS *symp = frag->tc_frag_data.last_map;
2649
2650 if (value == 0)
2651 {
2652 know (frag->tc_frag_data.first_map == symp);
2653 frag->tc_frag_data.first_map = NULL;
2654 }
2655 frag->tc_frag_data.last_map = NULL;
2656 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2657 }
cd000bff
DJ
2658
2659 make_mapping_symbol (MAP_DATA, value, frag);
2660 make_mapping_symbol (state, value + bytes, frag);
2661}
2662
2663static void mapping_state_2 (enum mstate state, int max_chars);
2664
2665/* Set the mapping state to STATE. Only call this when about to
2666 emit some STATE bytes to the file. */
2667
4e9aaefb 2668#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2669void
2670mapping_state (enum mstate state)
2671{
940b5ce0
DJ
2672 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2673
cd000bff
DJ
2674 if (mapstate == state)
2675 /* The mapping symbol has already been emitted.
2676 There is nothing else to do. */
2677 return;
49c62a33
NC
2678
2679 if (state == MAP_ARM || state == MAP_THUMB)
2680 /* PR gas/12931
2681 All ARM instructions require 4-byte alignment.
2682 (Almost) all Thumb instructions require 2-byte alignment.
2683
2684 When emitting instructions into any section, mark the section
2685 appropriately.
2686
2687 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2688 but themselves require 2-byte alignment; this applies to some
2689 PC- relative forms. However, these cases will invovle implicit
2690 literal pool generation or an explicit .align >=2, both of
2691 which will cause the section to me marked with sufficient
2692 alignment. Thus, we don't handle those cases here. */
2693 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2694
2695 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2696 /* This case will be evaluated later. */
cd000bff 2697 return;
cd000bff
DJ
2698
2699 mapping_state_2 (state, 0);
cd000bff
DJ
2700}
2701
2702/* Same as mapping_state, but MAX_CHARS bytes have already been
2703 allocated. Put the mapping symbol that far back. */
2704
2705static void
2706mapping_state_2 (enum mstate state, int max_chars)
2707{
940b5ce0
DJ
2708 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2709
2710 if (!SEG_NORMAL (now_seg))
2711 return;
2712
cd000bff
DJ
2713 if (mapstate == state)
2714 /* The mapping symbol has already been emitted.
2715 There is nothing else to do. */
2716 return;
2717
4e9aaefb
SA
2718 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2719 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2720 {
2721 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2722 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2723
2724 if (add_symbol)
2725 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2726 }
2727
cd000bff
DJ
2728 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2729 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2730}
4e9aaefb 2731#undef TRANSITION
c19d1205 2732#else
d3106081
NS
2733#define mapping_state(x) ((void)0)
2734#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2735#endif
2736
2737/* Find the real, Thumb encoded start of a Thumb function. */
2738
4343666d 2739#ifdef OBJ_COFF
c19d1205
ZW
2740static symbolS *
2741find_real_start (symbolS * symbolP)
2742{
2743 char * real_start;
2744 const char * name = S_GET_NAME (symbolP);
2745 symbolS * new_target;
2746
2747 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2748#define STUB_NAME ".real_start_of"
2749
2750 if (name == NULL)
2751 abort ();
2752
37f6032b
ZW
2753 /* The compiler may generate BL instructions to local labels because
2754 it needs to perform a branch to a far away location. These labels
2755 do not have a corresponding ".real_start_of" label. We check
2756 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2757 the ".real_start_of" convention for nonlocal branches. */
2758 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2759 return symbolP;
2760
e1fa0163 2761 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2762 new_target = symbol_find (real_start);
e1fa0163 2763 free (real_start);
c19d1205
ZW
2764
2765 if (new_target == NULL)
2766 {
bd3ba5d1 2767 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2768 new_target = symbolP;
2769 }
2770
c19d1205
ZW
2771 return new_target;
2772}
4343666d 2773#endif
c19d1205
ZW
2774
2775static void
2776opcode_select (int width)
2777{
2778 switch (width)
2779 {
2780 case 16:
2781 if (! thumb_mode)
2782 {
e74cfd16 2783 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2784 as_bad (_("selected processor does not support THUMB opcodes"));
2785
2786 thumb_mode = 1;
2787 /* No need to force the alignment, since we will have been
2788 coming from ARM mode, which is word-aligned. */
2789 record_alignment (now_seg, 1);
2790 }
c19d1205
ZW
2791 break;
2792
2793 case 32:
2794 if (thumb_mode)
2795 {
e74cfd16 2796 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2797 as_bad (_("selected processor does not support ARM opcodes"));
2798
2799 thumb_mode = 0;
2800
2801 if (!need_pass_2)
2802 frag_align (2, 0, 0);
2803
2804 record_alignment (now_seg, 1);
2805 }
c19d1205
ZW
2806 break;
2807
2808 default:
2809 as_bad (_("invalid instruction size selected (%d)"), width);
2810 }
2811}
2812
2813static void
2814s_arm (int ignore ATTRIBUTE_UNUSED)
2815{
2816 opcode_select (32);
2817 demand_empty_rest_of_line ();
2818}
2819
2820static void
2821s_thumb (int ignore ATTRIBUTE_UNUSED)
2822{
2823 opcode_select (16);
2824 demand_empty_rest_of_line ();
2825}
2826
2827static void
2828s_code (int unused ATTRIBUTE_UNUSED)
2829{
2830 int temp;
2831
2832 temp = get_absolute_expression ();
2833 switch (temp)
2834 {
2835 case 16:
2836 case 32:
2837 opcode_select (temp);
2838 break;
2839
2840 default:
2841 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2842 }
2843}
2844
2845static void
2846s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2847{
2848 /* If we are not already in thumb mode go into it, EVEN if
2849 the target processor does not support thumb instructions.
2850 This is used by gcc/config/arm/lib1funcs.asm for example
2851 to compile interworking support functions even if the
2852 target processor should not support interworking. */
2853 if (! thumb_mode)
2854 {
2855 thumb_mode = 2;
2856 record_alignment (now_seg, 1);
2857 }
2858
2859 demand_empty_rest_of_line ();
2860}
2861
2862static void
2863s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2864{
2865 s_thumb (0);
2866
2867 /* The following label is the name/address of the start of a Thumb function.
2868 We need to know this for the interworking support. */
2869 label_is_thumb_function_name = TRUE;
2870}
2871
2872/* Perform a .set directive, but also mark the alias as
2873 being a thumb function. */
2874
2875static void
2876s_thumb_set (int equiv)
2877{
2878 /* XXX the following is a duplicate of the code for s_set() in read.c
2879 We cannot just call that code as we need to get at the symbol that
2880 is created. */
2881 char * name;
2882 char delim;
2883 char * end_name;
2884 symbolS * symbolP;
2885
2886 /* Especial apologies for the random logic:
2887 This just grew, and could be parsed much more simply!
2888 Dean - in haste. */
d02603dc 2889 delim = get_symbol_name (& name);
c19d1205 2890 end_name = input_line_pointer;
d02603dc 2891 (void) restore_line_pointer (delim);
c19d1205
ZW
2892
2893 if (*input_line_pointer != ',')
2894 {
2895 *end_name = 0;
2896 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2897 *end_name = delim;
2898 ignore_rest_of_line ();
2899 return;
2900 }
2901
2902 input_line_pointer++;
2903 *end_name = 0;
2904
2905 if (name[0] == '.' && name[1] == '\0')
2906 {
2907 /* XXX - this should not happen to .thumb_set. */
2908 abort ();
2909 }
2910
2911 if ((symbolP = symbol_find (name)) == NULL
2912 && (symbolP = md_undefined_symbol (name)) == NULL)
2913 {
2914#ifndef NO_LISTING
2915 /* When doing symbol listings, play games with dummy fragments living
2916 outside the normal fragment chain to record the file and line info
c19d1205 2917 for this symbol. */
b99bd4ef
NC
2918 if (listing & LISTING_SYMBOLS)
2919 {
2920 extern struct list_info_struct * listing_tail;
21d799b5 2921 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2922
2923 memset (dummy_frag, 0, sizeof (fragS));
2924 dummy_frag->fr_type = rs_fill;
2925 dummy_frag->line = listing_tail;
2926 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2927 dummy_frag->fr_symbol = symbolP;
2928 }
2929 else
2930#endif
2931 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2932
2933#ifdef OBJ_COFF
2934 /* "set" symbols are local unless otherwise specified. */
2935 SF_SET_LOCAL (symbolP);
2936#endif /* OBJ_COFF */
2937 } /* Make a new symbol. */
2938
2939 symbol_table_insert (symbolP);
2940
2941 * end_name = delim;
2942
2943 if (equiv
2944 && S_IS_DEFINED (symbolP)
2945 && S_GET_SEGMENT (symbolP) != reg_section)
2946 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2947
2948 pseudo_set (symbolP);
2949
2950 demand_empty_rest_of_line ();
2951
c19d1205 2952 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2953
2954 THUMB_SET_FUNC (symbolP, 1);
2955 ARM_SET_THUMB (symbolP, 1);
2956#if defined OBJ_ELF || defined OBJ_COFF
2957 ARM_SET_INTERWORK (symbolP, support_interwork);
2958#endif
2959}
2960
c19d1205 2961/* Directives: Mode selection. */
b99bd4ef 2962
c19d1205
ZW
2963/* .syntax [unified|divided] - choose the new unified syntax
2964 (same for Arm and Thumb encoding, modulo slight differences in what
2965 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2966static void
c19d1205 2967s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2968{
c19d1205
ZW
2969 char *name, delim;
2970
d02603dc 2971 delim = get_symbol_name (& name);
c19d1205
ZW
2972
2973 if (!strcasecmp (name, "unified"))
2974 unified_syntax = TRUE;
2975 else if (!strcasecmp (name, "divided"))
2976 unified_syntax = FALSE;
2977 else
2978 {
2979 as_bad (_("unrecognized syntax mode \"%s\""), name);
2980 return;
2981 }
d02603dc 2982 (void) restore_line_pointer (delim);
b99bd4ef
NC
2983 demand_empty_rest_of_line ();
2984}
2985
c19d1205
ZW
2986/* Directives: sectioning and alignment. */
2987
c19d1205
ZW
2988static void
2989s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2990{
c19d1205
ZW
2991 /* We don't support putting frags in the BSS segment, we fake it by
2992 marking in_bss, then looking at s_skip for clues. */
2993 subseg_set (bss_section, 0);
2994 demand_empty_rest_of_line ();
cd000bff
DJ
2995
2996#ifdef md_elf_section_change_hook
2997 md_elf_section_change_hook ();
2998#endif
c19d1205 2999}
b99bd4ef 3000
c19d1205
ZW
3001static void
3002s_even (int ignore ATTRIBUTE_UNUSED)
3003{
3004 /* Never make frag if expect extra pass. */
3005 if (!need_pass_2)
3006 frag_align (1, 0, 0);
b99bd4ef 3007
c19d1205 3008 record_alignment (now_seg, 1);
b99bd4ef 3009
c19d1205 3010 demand_empty_rest_of_line ();
b99bd4ef
NC
3011}
3012
2e6976a8
DG
3013/* Directives: CodeComposer Studio. */
3014
3015/* .ref (for CodeComposer Studio syntax only). */
3016static void
3017s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3018{
3019 if (codecomposer_syntax)
3020 ignore_rest_of_line ();
3021 else
3022 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3023}
3024
3025/* If name is not NULL, then it is used for marking the beginning of a
3026 function, wherease if it is NULL then it means the function end. */
3027static void
3028asmfunc_debug (const char * name)
3029{
3030 static const char * last_name = NULL;
3031
3032 if (name != NULL)
3033 {
3034 gas_assert (last_name == NULL);
3035 last_name = name;
3036
3037 if (debug_type == DEBUG_STABS)
3038 stabs_generate_asm_func (name, name);
3039 }
3040 else
3041 {
3042 gas_assert (last_name != NULL);
3043
3044 if (debug_type == DEBUG_STABS)
3045 stabs_generate_asm_endfunc (last_name, last_name);
3046
3047 last_name = NULL;
3048 }
3049}
3050
3051static void
3052s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3053{
3054 if (codecomposer_syntax)
3055 {
3056 switch (asmfunc_state)
3057 {
3058 case OUTSIDE_ASMFUNC:
3059 asmfunc_state = WAITING_ASMFUNC_NAME;
3060 break;
3061
3062 case WAITING_ASMFUNC_NAME:
3063 as_bad (_(".asmfunc repeated."));
3064 break;
3065
3066 case WAITING_ENDASMFUNC:
3067 as_bad (_(".asmfunc without function."));
3068 break;
3069 }
3070 demand_empty_rest_of_line ();
3071 }
3072 else
3073 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3074}
3075
3076static void
3077s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3078{
3079 if (codecomposer_syntax)
3080 {
3081 switch (asmfunc_state)
3082 {
3083 case OUTSIDE_ASMFUNC:
3084 as_bad (_(".endasmfunc without a .asmfunc."));
3085 break;
3086
3087 case WAITING_ASMFUNC_NAME:
3088 as_bad (_(".endasmfunc without function."));
3089 break;
3090
3091 case WAITING_ENDASMFUNC:
3092 asmfunc_state = OUTSIDE_ASMFUNC;
3093 asmfunc_debug (NULL);
3094 break;
3095 }
3096 demand_empty_rest_of_line ();
3097 }
3098 else
3099 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3100}
3101
3102static void
3103s_ccs_def (int name)
3104{
3105 if (codecomposer_syntax)
3106 s_globl (name);
3107 else
3108 as_bad (_(".def pseudo-op only available with -mccs flag."));
3109}
3110
c19d1205 3111/* Directives: Literal pools. */
a737bd4d 3112
c19d1205
ZW
3113static literal_pool *
3114find_literal_pool (void)
a737bd4d 3115{
c19d1205 3116 literal_pool * pool;
a737bd4d 3117
c19d1205 3118 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3119 {
c19d1205
ZW
3120 if (pool->section == now_seg
3121 && pool->sub_section == now_subseg)
3122 break;
a737bd4d
NC
3123 }
3124
c19d1205 3125 return pool;
a737bd4d
NC
3126}
3127
c19d1205
ZW
3128static literal_pool *
3129find_or_make_literal_pool (void)
a737bd4d 3130{
c19d1205
ZW
3131 /* Next literal pool ID number. */
3132 static unsigned int latest_pool_num = 1;
3133 literal_pool * pool;
a737bd4d 3134
c19d1205 3135 pool = find_literal_pool ();
a737bd4d 3136
c19d1205 3137 if (pool == NULL)
a737bd4d 3138 {
c19d1205 3139 /* Create a new pool. */
325801bd 3140 pool = XNEW (literal_pool);
c19d1205
ZW
3141 if (! pool)
3142 return NULL;
a737bd4d 3143
c19d1205
ZW
3144 pool->next_free_entry = 0;
3145 pool->section = now_seg;
3146 pool->sub_section = now_subseg;
3147 pool->next = list_of_pools;
3148 pool->symbol = NULL;
8335d6aa 3149 pool->alignment = 2;
c19d1205
ZW
3150
3151 /* Add it to the list. */
3152 list_of_pools = pool;
a737bd4d 3153 }
a737bd4d 3154
c19d1205
ZW
3155 /* New pools, and emptied pools, will have a NULL symbol. */
3156 if (pool->symbol == NULL)
a737bd4d 3157 {
c19d1205
ZW
3158 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3159 (valueT) 0, &zero_address_frag);
3160 pool->id = latest_pool_num ++;
a737bd4d
NC
3161 }
3162
c19d1205
ZW
3163 /* Done. */
3164 return pool;
a737bd4d
NC
3165}
3166
c19d1205 3167/* Add the literal in the global 'inst'
5f4273c7 3168 structure to the relevant literal pool. */
b99bd4ef
NC
3169
3170static int
8335d6aa 3171add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3172{
8335d6aa
JW
3173#define PADDING_SLOT 0x1
3174#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3175 literal_pool * pool;
8335d6aa
JW
3176 unsigned int entry, pool_size = 0;
3177 bfd_boolean padding_slot_p = FALSE;
e56c722b 3178 unsigned imm1 = 0;
8335d6aa
JW
3179 unsigned imm2 = 0;
3180
3181 if (nbytes == 8)
3182 {
3183 imm1 = inst.operands[1].imm;
3184 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3185 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3186 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3187 if (target_big_endian)
3188 {
3189 imm1 = imm2;
3190 imm2 = inst.operands[1].imm;
3191 }
3192 }
b99bd4ef 3193
c19d1205
ZW
3194 pool = find_or_make_literal_pool ();
3195
3196 /* Check if this literal value is already in the pool. */
3197 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3198 {
8335d6aa
JW
3199 if (nbytes == 4)
3200 {
3201 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3202 && (inst.reloc.exp.X_op == O_constant)
3203 && (pool->literals[entry].X_add_number
3204 == inst.reloc.exp.X_add_number)
3205 && (pool->literals[entry].X_md == nbytes)
3206 && (pool->literals[entry].X_unsigned
3207 == inst.reloc.exp.X_unsigned))
3208 break;
3209
3210 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3211 && (inst.reloc.exp.X_op == O_symbol)
3212 && (pool->literals[entry].X_add_number
3213 == inst.reloc.exp.X_add_number)
3214 && (pool->literals[entry].X_add_symbol
3215 == inst.reloc.exp.X_add_symbol)
3216 && (pool->literals[entry].X_op_symbol
3217 == inst.reloc.exp.X_op_symbol)
3218 && (pool->literals[entry].X_md == nbytes))
3219 break;
3220 }
3221 else if ((nbytes == 8)
3222 && !(pool_size & 0x7)
3223 && ((entry + 1) != pool->next_free_entry)
3224 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3225 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3226 && (pool->literals[entry].X_unsigned
3227 == inst.reloc.exp.X_unsigned)
3228 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3229 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3230 && (pool->literals[entry + 1].X_unsigned
3231 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3232 break;
3233
8335d6aa
JW
3234 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3235 if (padding_slot_p && (nbytes == 4))
c19d1205 3236 break;
8335d6aa
JW
3237
3238 pool_size += 4;
b99bd4ef
NC
3239 }
3240
c19d1205
ZW
3241 /* Do we need to create a new entry? */
3242 if (entry == pool->next_free_entry)
3243 {
3244 if (entry >= MAX_LITERAL_POOL_SIZE)
3245 {
3246 inst.error = _("literal pool overflow");
3247 return FAIL;
3248 }
3249
8335d6aa
JW
3250 if (nbytes == 8)
3251 {
3252 /* For 8-byte entries, we align to an 8-byte boundary,
3253 and split it into two 4-byte entries, because on 32-bit
3254 host, 8-byte constants are treated as big num, thus
3255 saved in "generic_bignum" which will be overwritten
3256 by later assignments.
3257
3258 We also need to make sure there is enough space for
3259 the split.
3260
3261 We also check to make sure the literal operand is a
3262 constant number. */
19f2f6a9
JW
3263 if (!(inst.reloc.exp.X_op == O_constant
3264 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3265 {
3266 inst.error = _("invalid type for literal pool");
3267 return FAIL;
3268 }
3269 else if (pool_size & 0x7)
3270 {
3271 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3272 {
3273 inst.error = _("literal pool overflow");
3274 return FAIL;
3275 }
3276
3277 pool->literals[entry] = inst.reloc.exp;
3278 pool->literals[entry].X_add_number = 0;
3279 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3280 pool->next_free_entry += 1;
3281 pool_size += 4;
3282 }
3283 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3284 {
3285 inst.error = _("literal pool overflow");
3286 return FAIL;
3287 }
3288
3289 pool->literals[entry] = inst.reloc.exp;
3290 pool->literals[entry].X_op = O_constant;
3291 pool->literals[entry].X_add_number = imm1;
3292 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3293 pool->literals[entry++].X_md = 4;
3294 pool->literals[entry] = inst.reloc.exp;
3295 pool->literals[entry].X_op = O_constant;
3296 pool->literals[entry].X_add_number = imm2;
3297 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3298 pool->literals[entry].X_md = 4;
3299 pool->alignment = 3;
3300 pool->next_free_entry += 1;
3301 }
3302 else
3303 {
3304 pool->literals[entry] = inst.reloc.exp;
3305 pool->literals[entry].X_md = 4;
3306 }
3307
a8040cf2
NC
3308#ifdef OBJ_ELF
3309 /* PR ld/12974: Record the location of the first source line to reference
3310 this entry in the literal pool. If it turns out during linking that the
3311 symbol does not exist we will be able to give an accurate line number for
3312 the (first use of the) missing reference. */
3313 if (debug_type == DEBUG_DWARF2)
3314 dwarf2_where (pool->locs + entry);
3315#endif
c19d1205
ZW
3316 pool->next_free_entry += 1;
3317 }
8335d6aa
JW
3318 else if (padding_slot_p)
3319 {
3320 pool->literals[entry] = inst.reloc.exp;
3321 pool->literals[entry].X_md = nbytes;
3322 }
b99bd4ef 3323
c19d1205 3324 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3325 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3326 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3327
c19d1205 3328 return SUCCESS;
b99bd4ef
NC
3329}
3330
2e6976a8 3331bfd_boolean
2e57ce7b 3332tc_start_label_without_colon (void)
2e6976a8
DG
3333{
3334 bfd_boolean ret = TRUE;
3335
3336 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3337 {
2e57ce7b 3338 const char *label = input_line_pointer;
2e6976a8
DG
3339
3340 while (!is_end_of_line[(int) label[-1]])
3341 --label;
3342
3343 if (*label == '.')
3344 {
3345 as_bad (_("Invalid label '%s'"), label);
3346 ret = FALSE;
3347 }
3348
3349 asmfunc_debug (label);
3350
3351 asmfunc_state = WAITING_ENDASMFUNC;
3352 }
3353
3354 return ret;
3355}
3356
c19d1205
ZW
3357/* Can't use symbol_new here, so have to create a symbol and then at
3358 a later date assign it a value. Thats what these functions do. */
e16bb312 3359
c19d1205
ZW
3360static void
3361symbol_locate (symbolS * symbolP,
3362 const char * name, /* It is copied, the caller can modify. */
3363 segT segment, /* Segment identifier (SEG_<something>). */
3364 valueT valu, /* Symbol value. */
3365 fragS * frag) /* Associated fragment. */
3366{
e57e6ddc 3367 size_t name_length;
c19d1205 3368 char * preserved_copy_of_name;
e16bb312 3369
c19d1205
ZW
3370 name_length = strlen (name) + 1; /* +1 for \0. */
3371 obstack_grow (&notes, name, name_length);
21d799b5 3372 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3373
c19d1205
ZW
3374#ifdef tc_canonicalize_symbol_name
3375 preserved_copy_of_name =
3376 tc_canonicalize_symbol_name (preserved_copy_of_name);
3377#endif
b99bd4ef 3378
c19d1205 3379 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3380
c19d1205
ZW
3381 S_SET_SEGMENT (symbolP, segment);
3382 S_SET_VALUE (symbolP, valu);
3383 symbol_clear_list_pointers (symbolP);
b99bd4ef 3384
c19d1205 3385 symbol_set_frag (symbolP, frag);
b99bd4ef 3386
c19d1205
ZW
3387 /* Link to end of symbol chain. */
3388 {
3389 extern int symbol_table_frozen;
b99bd4ef 3390
c19d1205
ZW
3391 if (symbol_table_frozen)
3392 abort ();
3393 }
b99bd4ef 3394
c19d1205 3395 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3396
c19d1205 3397 obj_symbol_new_hook (symbolP);
b99bd4ef 3398
c19d1205
ZW
3399#ifdef tc_symbol_new_hook
3400 tc_symbol_new_hook (symbolP);
3401#endif
3402
3403#ifdef DEBUG_SYMS
3404 verify_symbol_chain (symbol_rootP, symbol_lastP);
3405#endif /* DEBUG_SYMS */
b99bd4ef
NC
3406}
3407
c19d1205
ZW
3408static void
3409s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3410{
c19d1205
ZW
3411 unsigned int entry;
3412 literal_pool * pool;
3413 char sym_name[20];
b99bd4ef 3414
c19d1205
ZW
3415 pool = find_literal_pool ();
3416 if (pool == NULL
3417 || pool->symbol == NULL
3418 || pool->next_free_entry == 0)
3419 return;
b99bd4ef 3420
c19d1205
ZW
3421 /* Align pool as you have word accesses.
3422 Only make a frag if we have to. */
3423 if (!need_pass_2)
8335d6aa 3424 frag_align (pool->alignment, 0, 0);
b99bd4ef 3425
c19d1205 3426 record_alignment (now_seg, 2);
b99bd4ef 3427
aaca88ef 3428#ifdef OBJ_ELF
47fc6e36
WN
3429 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3430 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3431#endif
c19d1205 3432 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3433
c19d1205
ZW
3434 symbol_locate (pool->symbol, sym_name, now_seg,
3435 (valueT) frag_now_fix (), frag_now);
3436 symbol_table_insert (pool->symbol);
b99bd4ef 3437
c19d1205 3438 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3439
c19d1205
ZW
3440#if defined OBJ_COFF || defined OBJ_ELF
3441 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3442#endif
6c43fab6 3443
c19d1205 3444 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3445 {
3446#ifdef OBJ_ELF
3447 if (debug_type == DEBUG_DWARF2)
3448 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3449#endif
3450 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3451 emit_expr (&(pool->literals[entry]),
3452 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3453 }
b99bd4ef 3454
c19d1205
ZW
3455 /* Mark the pool as empty. */
3456 pool->next_free_entry = 0;
3457 pool->symbol = NULL;
b99bd4ef
NC
3458}
3459
c19d1205
ZW
3460#ifdef OBJ_ELF
3461/* Forward declarations for functions below, in the MD interface
3462 section. */
3463static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3464static valueT create_unwind_entry (int);
3465static void start_unwind_section (const segT, int);
3466static void add_unwind_opcode (valueT, int);
3467static void flush_pending_unwind (void);
b99bd4ef 3468
c19d1205 3469/* Directives: Data. */
b99bd4ef 3470
c19d1205
ZW
3471static void
3472s_arm_elf_cons (int nbytes)
3473{
3474 expressionS exp;
b99bd4ef 3475
c19d1205
ZW
3476#ifdef md_flush_pending_output
3477 md_flush_pending_output ();
3478#endif
b99bd4ef 3479
c19d1205 3480 if (is_it_end_of_statement ())
b99bd4ef 3481 {
c19d1205
ZW
3482 demand_empty_rest_of_line ();
3483 return;
b99bd4ef
NC
3484 }
3485
c19d1205
ZW
3486#ifdef md_cons_align
3487 md_cons_align (nbytes);
3488#endif
b99bd4ef 3489
c19d1205
ZW
3490 mapping_state (MAP_DATA);
3491 do
b99bd4ef 3492 {
c19d1205
ZW
3493 int reloc;
3494 char *base = input_line_pointer;
b99bd4ef 3495
c19d1205 3496 expression (& exp);
b99bd4ef 3497
c19d1205
ZW
3498 if (exp.X_op != O_symbol)
3499 emit_expr (&exp, (unsigned int) nbytes);
3500 else
3501 {
3502 char *before_reloc = input_line_pointer;
3503 reloc = parse_reloc (&input_line_pointer);
3504 if (reloc == -1)
3505 {
3506 as_bad (_("unrecognized relocation suffix"));
3507 ignore_rest_of_line ();
3508 return;
3509 }
3510 else if (reloc == BFD_RELOC_UNUSED)
3511 emit_expr (&exp, (unsigned int) nbytes);
3512 else
3513 {
21d799b5 3514 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3515 bfd_reloc_type_lookup (stdoutput,
3516 (bfd_reloc_code_real_type) reloc);
c19d1205 3517 int size = bfd_get_reloc_size (howto);
b99bd4ef 3518
2fc8bdac
ZW
3519 if (reloc == BFD_RELOC_ARM_PLT32)
3520 {
3521 as_bad (_("(plt) is only valid on branch targets"));
3522 reloc = BFD_RELOC_UNUSED;
3523 size = 0;
3524 }
3525
c19d1205 3526 if (size > nbytes)
2fc8bdac 3527 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3528 howto->name, nbytes);
3529 else
3530 {
3531 /* We've parsed an expression stopping at O_symbol.
3532 But there may be more expression left now that we
3533 have parsed the relocation marker. Parse it again.
3534 XXX Surely there is a cleaner way to do this. */
3535 char *p = input_line_pointer;
3536 int offset;
325801bd 3537 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3538
c19d1205
ZW
3539 memcpy (save_buf, base, input_line_pointer - base);
3540 memmove (base + (input_line_pointer - before_reloc),
3541 base, before_reloc - base);
3542
3543 input_line_pointer = base + (input_line_pointer-before_reloc);
3544 expression (&exp);
3545 memcpy (base, save_buf, p - base);
3546
3547 offset = nbytes - size;
4b1a927e
AM
3548 p = frag_more (nbytes);
3549 memset (p, 0, nbytes);
c19d1205 3550 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3551 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3552 free (save_buf);
c19d1205
ZW
3553 }
3554 }
3555 }
b99bd4ef 3556 }
c19d1205 3557 while (*input_line_pointer++ == ',');
b99bd4ef 3558
c19d1205
ZW
3559 /* Put terminator back into stream. */
3560 input_line_pointer --;
3561 demand_empty_rest_of_line ();
b99bd4ef
NC
3562}
3563
c921be7d
NC
3564/* Emit an expression containing a 32-bit thumb instruction.
3565 Implementation based on put_thumb32_insn. */
3566
3567static void
3568emit_thumb32_expr (expressionS * exp)
3569{
3570 expressionS exp_high = *exp;
3571
3572 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3573 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3574 exp->X_add_number &= 0xffff;
3575 emit_expr (exp, (unsigned int) THUMB_SIZE);
3576}
3577
3578/* Guess the instruction size based on the opcode. */
3579
3580static int
3581thumb_insn_size (int opcode)
3582{
3583 if ((unsigned int) opcode < 0xe800u)
3584 return 2;
3585 else if ((unsigned int) opcode >= 0xe8000000u)
3586 return 4;
3587 else
3588 return 0;
3589}
3590
3591static bfd_boolean
3592emit_insn (expressionS *exp, int nbytes)
3593{
3594 int size = 0;
3595
3596 if (exp->X_op == O_constant)
3597 {
3598 size = nbytes;
3599
3600 if (size == 0)
3601 size = thumb_insn_size (exp->X_add_number);
3602
3603 if (size != 0)
3604 {
3605 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3606 {
3607 as_bad (_(".inst.n operand too big. "\
3608 "Use .inst.w instead"));
3609 size = 0;
3610 }
3611 else
3612 {
3613 if (now_it.state == AUTOMATIC_IT_BLOCK)
3614 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3615 else
3616 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3617
3618 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3619 emit_thumb32_expr (exp);
3620 else
3621 emit_expr (exp, (unsigned int) size);
3622
3623 it_fsm_post_encode ();
3624 }
3625 }
3626 else
3627 as_bad (_("cannot determine Thumb instruction size. " \
3628 "Use .inst.n/.inst.w instead"));
3629 }
3630 else
3631 as_bad (_("constant expression required"));
3632
3633 return (size != 0);
3634}
3635
3636/* Like s_arm_elf_cons but do not use md_cons_align and
3637 set the mapping state to MAP_ARM/MAP_THUMB. */
3638
3639static void
3640s_arm_elf_inst (int nbytes)
3641{
3642 if (is_it_end_of_statement ())
3643 {
3644 demand_empty_rest_of_line ();
3645 return;
3646 }
3647
3648 /* Calling mapping_state () here will not change ARM/THUMB,
3649 but will ensure not to be in DATA state. */
3650
3651 if (thumb_mode)
3652 mapping_state (MAP_THUMB);
3653 else
3654 {
3655 if (nbytes != 0)
3656 {
3657 as_bad (_("width suffixes are invalid in ARM mode"));
3658 ignore_rest_of_line ();
3659 return;
3660 }
3661
3662 nbytes = 4;
3663
3664 mapping_state (MAP_ARM);
3665 }
3666
3667 do
3668 {
3669 expressionS exp;
3670
3671 expression (& exp);
3672
3673 if (! emit_insn (& exp, nbytes))
3674 {
3675 ignore_rest_of_line ();
3676 return;
3677 }
3678 }
3679 while (*input_line_pointer++ == ',');
3680
3681 /* Put terminator back into stream. */
3682 input_line_pointer --;
3683 demand_empty_rest_of_line ();
3684}
b99bd4ef 3685
c19d1205 3686/* Parse a .rel31 directive. */
b99bd4ef 3687
c19d1205
ZW
3688static void
3689s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3690{
3691 expressionS exp;
3692 char *p;
3693 valueT highbit;
b99bd4ef 3694
c19d1205
ZW
3695 highbit = 0;
3696 if (*input_line_pointer == '1')
3697 highbit = 0x80000000;
3698 else if (*input_line_pointer != '0')
3699 as_bad (_("expected 0 or 1"));
b99bd4ef 3700
c19d1205
ZW
3701 input_line_pointer++;
3702 if (*input_line_pointer != ',')
3703 as_bad (_("missing comma"));
3704 input_line_pointer++;
b99bd4ef 3705
c19d1205
ZW
3706#ifdef md_flush_pending_output
3707 md_flush_pending_output ();
3708#endif
b99bd4ef 3709
c19d1205
ZW
3710#ifdef md_cons_align
3711 md_cons_align (4);
3712#endif
b99bd4ef 3713
c19d1205 3714 mapping_state (MAP_DATA);
b99bd4ef 3715
c19d1205 3716 expression (&exp);
b99bd4ef 3717
c19d1205
ZW
3718 p = frag_more (4);
3719 md_number_to_chars (p, highbit, 4);
3720 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3721 BFD_RELOC_ARM_PREL31);
b99bd4ef 3722
c19d1205 3723 demand_empty_rest_of_line ();
b99bd4ef
NC
3724}
3725
c19d1205 3726/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3727
c19d1205 3728/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3729
c19d1205
ZW
3730static void
3731s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3732{
3733 demand_empty_rest_of_line ();
921e5f0a
PB
3734 if (unwind.proc_start)
3735 {
c921be7d 3736 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3737 return;
3738 }
3739
c19d1205
ZW
3740 /* Mark the start of the function. */
3741 unwind.proc_start = expr_build_dot ();
b99bd4ef 3742
c19d1205
ZW
3743 /* Reset the rest of the unwind info. */
3744 unwind.opcode_count = 0;
3745 unwind.table_entry = NULL;
3746 unwind.personality_routine = NULL;
3747 unwind.personality_index = -1;
3748 unwind.frame_size = 0;
3749 unwind.fp_offset = 0;
fdfde340 3750 unwind.fp_reg = REG_SP;
c19d1205
ZW
3751 unwind.fp_used = 0;
3752 unwind.sp_restored = 0;
3753}
b99bd4ef 3754
b99bd4ef 3755
c19d1205
ZW
3756/* Parse a handlerdata directive. Creates the exception handling table entry
3757 for the function. */
b99bd4ef 3758
c19d1205
ZW
3759static void
3760s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3761{
3762 demand_empty_rest_of_line ();
921e5f0a 3763 if (!unwind.proc_start)
c921be7d 3764 as_bad (MISSING_FNSTART);
921e5f0a 3765
c19d1205 3766 if (unwind.table_entry)
6decc662 3767 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3768
c19d1205
ZW
3769 create_unwind_entry (1);
3770}
a737bd4d 3771
c19d1205 3772/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3773
c19d1205
ZW
3774static void
3775s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3776{
3777 long where;
3778 char *ptr;
3779 valueT val;
940b5ce0 3780 unsigned int marked_pr_dependency;
f02232aa 3781
c19d1205 3782 demand_empty_rest_of_line ();
f02232aa 3783
921e5f0a
PB
3784 if (!unwind.proc_start)
3785 {
c921be7d 3786 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3787 return;
3788 }
3789
c19d1205
ZW
3790 /* Add eh table entry. */
3791 if (unwind.table_entry == NULL)
3792 val = create_unwind_entry (0);
3793 else
3794 val = 0;
f02232aa 3795
c19d1205
ZW
3796 /* Add index table entry. This is two words. */
3797 start_unwind_section (unwind.saved_seg, 1);
3798 frag_align (2, 0, 0);
3799 record_alignment (now_seg, 2);
b99bd4ef 3800
c19d1205 3801 ptr = frag_more (8);
5011093d 3802 memset (ptr, 0, 8);
c19d1205 3803 where = frag_now_fix () - 8;
f02232aa 3804
c19d1205
ZW
3805 /* Self relative offset of the function start. */
3806 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3807 BFD_RELOC_ARM_PREL31);
f02232aa 3808
c19d1205
ZW
3809 /* Indicate dependency on EHABI-defined personality routines to the
3810 linker, if it hasn't been done already. */
940b5ce0
DJ
3811 marked_pr_dependency
3812 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3813 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3814 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3815 {
5f4273c7
NC
3816 static const char *const name[] =
3817 {
3818 "__aeabi_unwind_cpp_pr0",
3819 "__aeabi_unwind_cpp_pr1",
3820 "__aeabi_unwind_cpp_pr2"
3821 };
c19d1205
ZW
3822 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3823 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3824 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3825 |= 1 << unwind.personality_index;
c19d1205 3826 }
f02232aa 3827
c19d1205
ZW
3828 if (val)
3829 /* Inline exception table entry. */
3830 md_number_to_chars (ptr + 4, val, 4);
3831 else
3832 /* Self relative offset of the table entry. */
3833 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3834 BFD_RELOC_ARM_PREL31);
f02232aa 3835
c19d1205
ZW
3836 /* Restore the original section. */
3837 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3838
3839 unwind.proc_start = NULL;
c19d1205 3840}
f02232aa 3841
f02232aa 3842
c19d1205 3843/* Parse an unwind_cantunwind directive. */
b99bd4ef 3844
c19d1205
ZW
3845static void
3846s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3847{
3848 demand_empty_rest_of_line ();
921e5f0a 3849 if (!unwind.proc_start)
c921be7d 3850 as_bad (MISSING_FNSTART);
921e5f0a 3851
c19d1205
ZW
3852 if (unwind.personality_routine || unwind.personality_index != -1)
3853 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3854
c19d1205
ZW
3855 unwind.personality_index = -2;
3856}
b99bd4ef 3857
b99bd4ef 3858
c19d1205 3859/* Parse a personalityindex directive. */
b99bd4ef 3860
c19d1205
ZW
3861static void
3862s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3863{
3864 expressionS exp;
b99bd4ef 3865
921e5f0a 3866 if (!unwind.proc_start)
c921be7d 3867 as_bad (MISSING_FNSTART);
921e5f0a 3868
c19d1205
ZW
3869 if (unwind.personality_routine || unwind.personality_index != -1)
3870 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3871
c19d1205 3872 expression (&exp);
b99bd4ef 3873
c19d1205
ZW
3874 if (exp.X_op != O_constant
3875 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3876 {
c19d1205
ZW
3877 as_bad (_("bad personality routine number"));
3878 ignore_rest_of_line ();
3879 return;
b99bd4ef
NC
3880 }
3881
c19d1205 3882 unwind.personality_index = exp.X_add_number;
b99bd4ef 3883
c19d1205
ZW
3884 demand_empty_rest_of_line ();
3885}
e16bb312 3886
e16bb312 3887
c19d1205 3888/* Parse a personality directive. */
e16bb312 3889
c19d1205
ZW
3890static void
3891s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3892{
3893 char *name, *p, c;
a737bd4d 3894
921e5f0a 3895 if (!unwind.proc_start)
c921be7d 3896 as_bad (MISSING_FNSTART);
921e5f0a 3897
c19d1205
ZW
3898 if (unwind.personality_routine || unwind.personality_index != -1)
3899 as_bad (_("duplicate .personality directive"));
a737bd4d 3900
d02603dc 3901 c = get_symbol_name (& name);
c19d1205 3902 p = input_line_pointer;
d02603dc
NC
3903 if (c == '"')
3904 ++ input_line_pointer;
c19d1205
ZW
3905 unwind.personality_routine = symbol_find_or_make (name);
3906 *p = c;
3907 demand_empty_rest_of_line ();
3908}
e16bb312 3909
e16bb312 3910
c19d1205 3911/* Parse a directive saving core registers. */
e16bb312 3912
c19d1205
ZW
3913static void
3914s_arm_unwind_save_core (void)
e16bb312 3915{
c19d1205
ZW
3916 valueT op;
3917 long range;
3918 int n;
e16bb312 3919
c19d1205
ZW
3920 range = parse_reg_list (&input_line_pointer);
3921 if (range == FAIL)
e16bb312 3922 {
c19d1205
ZW
3923 as_bad (_("expected register list"));
3924 ignore_rest_of_line ();
3925 return;
3926 }
e16bb312 3927
c19d1205 3928 demand_empty_rest_of_line ();
e16bb312 3929
c19d1205
ZW
3930 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3931 into .unwind_save {..., sp...}. We aren't bothered about the value of
3932 ip because it is clobbered by calls. */
3933 if (unwind.sp_restored && unwind.fp_reg == 12
3934 && (range & 0x3000) == 0x1000)
3935 {
3936 unwind.opcode_count--;
3937 unwind.sp_restored = 0;
3938 range = (range | 0x2000) & ~0x1000;
3939 unwind.pending_offset = 0;
3940 }
e16bb312 3941
01ae4198
DJ
3942 /* Pop r4-r15. */
3943 if (range & 0xfff0)
c19d1205 3944 {
01ae4198
DJ
3945 /* See if we can use the short opcodes. These pop a block of up to 8
3946 registers starting with r4, plus maybe r14. */
3947 for (n = 0; n < 8; n++)
3948 {
3949 /* Break at the first non-saved register. */
3950 if ((range & (1 << (n + 4))) == 0)
3951 break;
3952 }
3953 /* See if there are any other bits set. */
3954 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3955 {
3956 /* Use the long form. */
3957 op = 0x8000 | ((range >> 4) & 0xfff);
3958 add_unwind_opcode (op, 2);
3959 }
0dd132b6 3960 else
01ae4198
DJ
3961 {
3962 /* Use the short form. */
3963 if (range & 0x4000)
3964 op = 0xa8; /* Pop r14. */
3965 else
3966 op = 0xa0; /* Do not pop r14. */
3967 op |= (n - 1);
3968 add_unwind_opcode (op, 1);
3969 }
c19d1205 3970 }
0dd132b6 3971
c19d1205
ZW
3972 /* Pop r0-r3. */
3973 if (range & 0xf)
3974 {
3975 op = 0xb100 | (range & 0xf);
3976 add_unwind_opcode (op, 2);
0dd132b6
NC
3977 }
3978
c19d1205
ZW
3979 /* Record the number of bytes pushed. */
3980 for (n = 0; n < 16; n++)
3981 {
3982 if (range & (1 << n))
3983 unwind.frame_size += 4;
3984 }
0dd132b6
NC
3985}
3986
c19d1205
ZW
3987
3988/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3989
3990static void
c19d1205 3991s_arm_unwind_save_fpa (int reg)
b99bd4ef 3992{
c19d1205
ZW
3993 expressionS exp;
3994 int num_regs;
3995 valueT op;
b99bd4ef 3996
c19d1205
ZW
3997 /* Get Number of registers to transfer. */
3998 if (skip_past_comma (&input_line_pointer) != FAIL)
3999 expression (&exp);
4000 else
4001 exp.X_op = O_illegal;
b99bd4ef 4002
c19d1205 4003 if (exp.X_op != O_constant)
b99bd4ef 4004 {
c19d1205
ZW
4005 as_bad (_("expected , <constant>"));
4006 ignore_rest_of_line ();
b99bd4ef
NC
4007 return;
4008 }
4009
c19d1205
ZW
4010 num_regs = exp.X_add_number;
4011
4012 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4013 {
c19d1205
ZW
4014 as_bad (_("number of registers must be in the range [1:4]"));
4015 ignore_rest_of_line ();
b99bd4ef
NC
4016 return;
4017 }
4018
c19d1205 4019 demand_empty_rest_of_line ();
b99bd4ef 4020
c19d1205
ZW
4021 if (reg == 4)
4022 {
4023 /* Short form. */
4024 op = 0xb4 | (num_regs - 1);
4025 add_unwind_opcode (op, 1);
4026 }
b99bd4ef
NC
4027 else
4028 {
c19d1205
ZW
4029 /* Long form. */
4030 op = 0xc800 | (reg << 4) | (num_regs - 1);
4031 add_unwind_opcode (op, 2);
b99bd4ef 4032 }
c19d1205 4033 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4034}
4035
c19d1205 4036
fa073d69
MS
4037/* Parse a directive saving VFP registers for ARMv6 and above. */
4038
4039static void
4040s_arm_unwind_save_vfp_armv6 (void)
4041{
4042 int count;
4043 unsigned int start;
4044 valueT op;
4045 int num_vfpv3_regs = 0;
4046 int num_regs_below_16;
4047
4048 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4049 if (count == FAIL)
4050 {
4051 as_bad (_("expected register list"));
4052 ignore_rest_of_line ();
4053 return;
4054 }
4055
4056 demand_empty_rest_of_line ();
4057
4058 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4059 than FSTMX/FLDMX-style ones). */
4060
4061 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4062 if (start >= 16)
4063 num_vfpv3_regs = count;
4064 else if (start + count > 16)
4065 num_vfpv3_regs = start + count - 16;
4066
4067 if (num_vfpv3_regs > 0)
4068 {
4069 int start_offset = start > 16 ? start - 16 : 0;
4070 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4071 add_unwind_opcode (op, 2);
4072 }
4073
4074 /* Generate opcode for registers numbered in the range 0 .. 15. */
4075 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4076 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4077 if (num_regs_below_16 > 0)
4078 {
4079 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4080 add_unwind_opcode (op, 2);
4081 }
4082
4083 unwind.frame_size += count * 8;
4084}
4085
4086
4087/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4088
4089static void
c19d1205 4090s_arm_unwind_save_vfp (void)
b99bd4ef 4091{
c19d1205 4092 int count;
ca3f61f7 4093 unsigned int reg;
c19d1205 4094 valueT op;
b99bd4ef 4095
5287ad62 4096 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4097 if (count == FAIL)
b99bd4ef 4098 {
c19d1205
ZW
4099 as_bad (_("expected register list"));
4100 ignore_rest_of_line ();
b99bd4ef
NC
4101 return;
4102 }
4103
c19d1205 4104 demand_empty_rest_of_line ();
b99bd4ef 4105
c19d1205 4106 if (reg == 8)
b99bd4ef 4107 {
c19d1205
ZW
4108 /* Short form. */
4109 op = 0xb8 | (count - 1);
4110 add_unwind_opcode (op, 1);
b99bd4ef 4111 }
c19d1205 4112 else
b99bd4ef 4113 {
c19d1205
ZW
4114 /* Long form. */
4115 op = 0xb300 | (reg << 4) | (count - 1);
4116 add_unwind_opcode (op, 2);
b99bd4ef 4117 }
c19d1205
ZW
4118 unwind.frame_size += count * 8 + 4;
4119}
b99bd4ef 4120
b99bd4ef 4121
c19d1205
ZW
4122/* Parse a directive saving iWMMXt data registers. */
4123
4124static void
4125s_arm_unwind_save_mmxwr (void)
4126{
4127 int reg;
4128 int hi_reg;
4129 int i;
4130 unsigned mask = 0;
4131 valueT op;
b99bd4ef 4132
c19d1205
ZW
4133 if (*input_line_pointer == '{')
4134 input_line_pointer++;
b99bd4ef 4135
c19d1205 4136 do
b99bd4ef 4137 {
dcbf9037 4138 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4139
c19d1205 4140 if (reg == FAIL)
b99bd4ef 4141 {
9b7132d3 4142 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4143 goto error;
b99bd4ef
NC
4144 }
4145
c19d1205
ZW
4146 if (mask >> reg)
4147 as_tsktsk (_("register list not in ascending order"));
4148 mask |= 1 << reg;
b99bd4ef 4149
c19d1205
ZW
4150 if (*input_line_pointer == '-')
4151 {
4152 input_line_pointer++;
dcbf9037 4153 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4154 if (hi_reg == FAIL)
4155 {
9b7132d3 4156 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4157 goto error;
4158 }
4159 else if (reg >= hi_reg)
4160 {
4161 as_bad (_("bad register range"));
4162 goto error;
4163 }
4164 for (; reg < hi_reg; reg++)
4165 mask |= 1 << reg;
4166 }
4167 }
4168 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4169
d996d970 4170 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4171
c19d1205 4172 demand_empty_rest_of_line ();
b99bd4ef 4173
708587a4 4174 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4175 the list. */
4176 flush_pending_unwind ();
b99bd4ef 4177
c19d1205 4178 for (i = 0; i < 16; i++)
b99bd4ef 4179 {
c19d1205
ZW
4180 if (mask & (1 << i))
4181 unwind.frame_size += 8;
b99bd4ef
NC
4182 }
4183
c19d1205
ZW
4184 /* Attempt to combine with a previous opcode. We do this because gcc
4185 likes to output separate unwind directives for a single block of
4186 registers. */
4187 if (unwind.opcode_count > 0)
b99bd4ef 4188 {
c19d1205
ZW
4189 i = unwind.opcodes[unwind.opcode_count - 1];
4190 if ((i & 0xf8) == 0xc0)
4191 {
4192 i &= 7;
4193 /* Only merge if the blocks are contiguous. */
4194 if (i < 6)
4195 {
4196 if ((mask & 0xfe00) == (1 << 9))
4197 {
4198 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4199 unwind.opcode_count--;
4200 }
4201 }
4202 else if (i == 6 && unwind.opcode_count >= 2)
4203 {
4204 i = unwind.opcodes[unwind.opcode_count - 2];
4205 reg = i >> 4;
4206 i &= 0xf;
b99bd4ef 4207
c19d1205
ZW
4208 op = 0xffff << (reg - 1);
4209 if (reg > 0
87a1fd79 4210 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4211 {
4212 op = (1 << (reg + i + 1)) - 1;
4213 op &= ~((1 << reg) - 1);
4214 mask |= op;
4215 unwind.opcode_count -= 2;
4216 }
4217 }
4218 }
b99bd4ef
NC
4219 }
4220
c19d1205
ZW
4221 hi_reg = 15;
4222 /* We want to generate opcodes in the order the registers have been
4223 saved, ie. descending order. */
4224 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4225 {
c19d1205
ZW
4226 /* Save registers in blocks. */
4227 if (reg < 0
4228 || !(mask & (1 << reg)))
4229 {
4230 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4231 preceding block. */
c19d1205
ZW
4232 if (reg != hi_reg)
4233 {
4234 if (reg == 9)
4235 {
4236 /* Short form. */
4237 op = 0xc0 | (hi_reg - 10);
4238 add_unwind_opcode (op, 1);
4239 }
4240 else
4241 {
4242 /* Long form. */
4243 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4244 add_unwind_opcode (op, 2);
4245 }
4246 }
4247 hi_reg = reg - 1;
4248 }
b99bd4ef
NC
4249 }
4250
c19d1205
ZW
4251 return;
4252error:
4253 ignore_rest_of_line ();
b99bd4ef
NC
4254}
4255
4256static void
c19d1205 4257s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4258{
c19d1205
ZW
4259 int reg;
4260 int hi_reg;
4261 unsigned mask = 0;
4262 valueT op;
b99bd4ef 4263
c19d1205
ZW
4264 if (*input_line_pointer == '{')
4265 input_line_pointer++;
b99bd4ef 4266
477330fc
RM
4267 skip_whitespace (input_line_pointer);
4268
c19d1205 4269 do
b99bd4ef 4270 {
dcbf9037 4271 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4272
c19d1205
ZW
4273 if (reg == FAIL)
4274 {
9b7132d3 4275 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4276 goto error;
4277 }
b99bd4ef 4278
c19d1205
ZW
4279 reg -= 8;
4280 if (mask >> reg)
4281 as_tsktsk (_("register list not in ascending order"));
4282 mask |= 1 << reg;
b99bd4ef 4283
c19d1205
ZW
4284 if (*input_line_pointer == '-')
4285 {
4286 input_line_pointer++;
dcbf9037 4287 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4288 if (hi_reg == FAIL)
4289 {
9b7132d3 4290 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4291 goto error;
4292 }
4293 else if (reg >= hi_reg)
4294 {
4295 as_bad (_("bad register range"));
4296 goto error;
4297 }
4298 for (; reg < hi_reg; reg++)
4299 mask |= 1 << reg;
4300 }
b99bd4ef 4301 }
c19d1205 4302 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4303
d996d970 4304 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4305
c19d1205
ZW
4306 demand_empty_rest_of_line ();
4307
708587a4 4308 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4309 the list. */
4310 flush_pending_unwind ();
b99bd4ef 4311
c19d1205 4312 for (reg = 0; reg < 16; reg++)
b99bd4ef 4313 {
c19d1205
ZW
4314 if (mask & (1 << reg))
4315 unwind.frame_size += 4;
b99bd4ef 4316 }
c19d1205
ZW
4317 op = 0xc700 | mask;
4318 add_unwind_opcode (op, 2);
4319 return;
4320error:
4321 ignore_rest_of_line ();
b99bd4ef
NC
4322}
4323
c19d1205 4324
fa073d69
MS
4325/* Parse an unwind_save directive.
4326 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4327
b99bd4ef 4328static void
fa073d69 4329s_arm_unwind_save (int arch_v6)
b99bd4ef 4330{
c19d1205
ZW
4331 char *peek;
4332 struct reg_entry *reg;
4333 bfd_boolean had_brace = FALSE;
b99bd4ef 4334
921e5f0a 4335 if (!unwind.proc_start)
c921be7d 4336 as_bad (MISSING_FNSTART);
921e5f0a 4337
c19d1205
ZW
4338 /* Figure out what sort of save we have. */
4339 peek = input_line_pointer;
b99bd4ef 4340
c19d1205 4341 if (*peek == '{')
b99bd4ef 4342 {
c19d1205
ZW
4343 had_brace = TRUE;
4344 peek++;
b99bd4ef
NC
4345 }
4346
c19d1205 4347 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4348
c19d1205 4349 if (!reg)
b99bd4ef 4350 {
c19d1205
ZW
4351 as_bad (_("register expected"));
4352 ignore_rest_of_line ();
b99bd4ef
NC
4353 return;
4354 }
4355
c19d1205 4356 switch (reg->type)
b99bd4ef 4357 {
c19d1205
ZW
4358 case REG_TYPE_FN:
4359 if (had_brace)
4360 {
4361 as_bad (_("FPA .unwind_save does not take a register list"));
4362 ignore_rest_of_line ();
4363 return;
4364 }
93ac2687 4365 input_line_pointer = peek;
c19d1205 4366 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4367 return;
c19d1205 4368
1f5afe1c
NC
4369 case REG_TYPE_RN:
4370 s_arm_unwind_save_core ();
4371 return;
4372
fa073d69
MS
4373 case REG_TYPE_VFD:
4374 if (arch_v6)
477330fc 4375 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4376 else
477330fc 4377 s_arm_unwind_save_vfp ();
fa073d69 4378 return;
1f5afe1c
NC
4379
4380 case REG_TYPE_MMXWR:
4381 s_arm_unwind_save_mmxwr ();
4382 return;
4383
4384 case REG_TYPE_MMXWCG:
4385 s_arm_unwind_save_mmxwcg ();
4386 return;
c19d1205
ZW
4387
4388 default:
4389 as_bad (_(".unwind_save does not support this kind of register"));
4390 ignore_rest_of_line ();
b99bd4ef 4391 }
c19d1205 4392}
b99bd4ef 4393
b99bd4ef 4394
c19d1205
ZW
4395/* Parse an unwind_movsp directive. */
4396
4397static void
4398s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4399{
4400 int reg;
4401 valueT op;
4fa3602b 4402 int offset;
c19d1205 4403
921e5f0a 4404 if (!unwind.proc_start)
c921be7d 4405 as_bad (MISSING_FNSTART);
921e5f0a 4406
dcbf9037 4407 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4408 if (reg == FAIL)
b99bd4ef 4409 {
9b7132d3 4410 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4411 ignore_rest_of_line ();
b99bd4ef
NC
4412 return;
4413 }
4fa3602b
PB
4414
4415 /* Optional constant. */
4416 if (skip_past_comma (&input_line_pointer) != FAIL)
4417 {
4418 if (immediate_for_directive (&offset) == FAIL)
4419 return;
4420 }
4421 else
4422 offset = 0;
4423
c19d1205 4424 demand_empty_rest_of_line ();
b99bd4ef 4425
c19d1205 4426 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4427 {
c19d1205 4428 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4429 return;
4430 }
4431
c19d1205
ZW
4432 if (unwind.fp_reg != REG_SP)
4433 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4434
c19d1205
ZW
4435 /* Generate opcode to restore the value. */
4436 op = 0x90 | reg;
4437 add_unwind_opcode (op, 1);
4438
4439 /* Record the information for later. */
4440 unwind.fp_reg = reg;
4fa3602b 4441 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4442 unwind.sp_restored = 1;
b05fe5cf
ZW
4443}
4444
c19d1205
ZW
4445/* Parse an unwind_pad directive. */
4446
b05fe5cf 4447static void
c19d1205 4448s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4449{
c19d1205 4450 int offset;
b05fe5cf 4451
921e5f0a 4452 if (!unwind.proc_start)
c921be7d 4453 as_bad (MISSING_FNSTART);
921e5f0a 4454
c19d1205
ZW
4455 if (immediate_for_directive (&offset) == FAIL)
4456 return;
b99bd4ef 4457
c19d1205
ZW
4458 if (offset & 3)
4459 {
4460 as_bad (_("stack increment must be multiple of 4"));
4461 ignore_rest_of_line ();
4462 return;
4463 }
b99bd4ef 4464
c19d1205
ZW
4465 /* Don't generate any opcodes, just record the details for later. */
4466 unwind.frame_size += offset;
4467 unwind.pending_offset += offset;
4468
4469 demand_empty_rest_of_line ();
4470}
4471
4472/* Parse an unwind_setfp directive. */
4473
4474static void
4475s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4476{
c19d1205
ZW
4477 int sp_reg;
4478 int fp_reg;
4479 int offset;
4480
921e5f0a 4481 if (!unwind.proc_start)
c921be7d 4482 as_bad (MISSING_FNSTART);
921e5f0a 4483
dcbf9037 4484 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4485 if (skip_past_comma (&input_line_pointer) == FAIL)
4486 sp_reg = FAIL;
4487 else
dcbf9037 4488 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4489
c19d1205
ZW
4490 if (fp_reg == FAIL || sp_reg == FAIL)
4491 {
4492 as_bad (_("expected <reg>, <reg>"));
4493 ignore_rest_of_line ();
4494 return;
4495 }
b99bd4ef 4496
c19d1205
ZW
4497 /* Optional constant. */
4498 if (skip_past_comma (&input_line_pointer) != FAIL)
4499 {
4500 if (immediate_for_directive (&offset) == FAIL)
4501 return;
4502 }
4503 else
4504 offset = 0;
a737bd4d 4505
c19d1205 4506 demand_empty_rest_of_line ();
a737bd4d 4507
fdfde340 4508 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4509 {
c19d1205
ZW
4510 as_bad (_("register must be either sp or set by a previous"
4511 "unwind_movsp directive"));
4512 return;
a737bd4d
NC
4513 }
4514
c19d1205
ZW
4515 /* Don't generate any opcodes, just record the information for later. */
4516 unwind.fp_reg = fp_reg;
4517 unwind.fp_used = 1;
fdfde340 4518 if (sp_reg == REG_SP)
c19d1205
ZW
4519 unwind.fp_offset = unwind.frame_size - offset;
4520 else
4521 unwind.fp_offset -= offset;
a737bd4d
NC
4522}
4523
c19d1205
ZW
4524/* Parse an unwind_raw directive. */
4525
4526static void
4527s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4528{
c19d1205 4529 expressionS exp;
708587a4 4530 /* This is an arbitrary limit. */
c19d1205
ZW
4531 unsigned char op[16];
4532 int count;
a737bd4d 4533
921e5f0a 4534 if (!unwind.proc_start)
c921be7d 4535 as_bad (MISSING_FNSTART);
921e5f0a 4536
c19d1205
ZW
4537 expression (&exp);
4538 if (exp.X_op == O_constant
4539 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4540 {
c19d1205
ZW
4541 unwind.frame_size += exp.X_add_number;
4542 expression (&exp);
4543 }
4544 else
4545 exp.X_op = O_illegal;
a737bd4d 4546
c19d1205
ZW
4547 if (exp.X_op != O_constant)
4548 {
4549 as_bad (_("expected <offset>, <opcode>"));
4550 ignore_rest_of_line ();
4551 return;
4552 }
a737bd4d 4553
c19d1205 4554 count = 0;
a737bd4d 4555
c19d1205
ZW
4556 /* Parse the opcode. */
4557 for (;;)
4558 {
4559 if (count >= 16)
4560 {
4561 as_bad (_("unwind opcode too long"));
4562 ignore_rest_of_line ();
a737bd4d 4563 }
c19d1205 4564 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4565 {
c19d1205
ZW
4566 as_bad (_("invalid unwind opcode"));
4567 ignore_rest_of_line ();
4568 return;
a737bd4d 4569 }
c19d1205 4570 op[count++] = exp.X_add_number;
a737bd4d 4571
c19d1205
ZW
4572 /* Parse the next byte. */
4573 if (skip_past_comma (&input_line_pointer) == FAIL)
4574 break;
a737bd4d 4575
c19d1205
ZW
4576 expression (&exp);
4577 }
b99bd4ef 4578
c19d1205
ZW
4579 /* Add the opcode bytes in reverse order. */
4580 while (count--)
4581 add_unwind_opcode (op[count], 1);
b99bd4ef 4582
c19d1205 4583 demand_empty_rest_of_line ();
b99bd4ef 4584}
ee065d83
PB
4585
4586
4587/* Parse a .eabi_attribute directive. */
4588
4589static void
4590s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4591{
0420f52b 4592 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4593
4594 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4595 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4596}
4597
0855e32b
NS
4598/* Emit a tls fix for the symbol. */
4599
4600static void
4601s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4602{
4603 char *p;
4604 expressionS exp;
4605#ifdef md_flush_pending_output
4606 md_flush_pending_output ();
4607#endif
4608
4609#ifdef md_cons_align
4610 md_cons_align (4);
4611#endif
4612
4613 /* Since we're just labelling the code, there's no need to define a
4614 mapping symbol. */
4615 expression (&exp);
4616 p = obstack_next_free (&frchain_now->frch_obstack);
4617 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4618 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4619 : BFD_RELOC_ARM_TLS_DESCSEQ);
4620}
cdf9ccec 4621#endif /* OBJ_ELF */
0855e32b 4622
ee065d83 4623static void s_arm_arch (int);
7a1d4c38 4624static void s_arm_object_arch (int);
ee065d83
PB
4625static void s_arm_cpu (int);
4626static void s_arm_fpu (int);
69133863 4627static void s_arm_arch_extension (int);
b99bd4ef 4628
f0927246
NC
4629#ifdef TE_PE
4630
4631static void
5f4273c7 4632pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4633{
4634 expressionS exp;
4635
4636 do
4637 {
4638 expression (&exp);
4639 if (exp.X_op == O_symbol)
4640 exp.X_op = O_secrel;
4641
4642 emit_expr (&exp, 4);
4643 }
4644 while (*input_line_pointer++ == ',');
4645
4646 input_line_pointer--;
4647 demand_empty_rest_of_line ();
4648}
4649#endif /* TE_PE */
4650
c19d1205
ZW
4651/* This table describes all the machine specific pseudo-ops the assembler
4652 has to support. The fields are:
4653 pseudo-op name without dot
4654 function to call to execute this pseudo-op
4655 Integer arg to pass to the function. */
b99bd4ef 4656
c19d1205 4657const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4658{
c19d1205
ZW
4659 /* Never called because '.req' does not start a line. */
4660 { "req", s_req, 0 },
dcbf9037
JB
4661 /* Following two are likewise never called. */
4662 { "dn", s_dn, 0 },
4663 { "qn", s_qn, 0 },
c19d1205
ZW
4664 { "unreq", s_unreq, 0 },
4665 { "bss", s_bss, 0 },
db2ed2e0 4666 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4667 { "arm", s_arm, 0 },
4668 { "thumb", s_thumb, 0 },
4669 { "code", s_code, 0 },
4670 { "force_thumb", s_force_thumb, 0 },
4671 { "thumb_func", s_thumb_func, 0 },
4672 { "thumb_set", s_thumb_set, 0 },
4673 { "even", s_even, 0 },
4674 { "ltorg", s_ltorg, 0 },
4675 { "pool", s_ltorg, 0 },
4676 { "syntax", s_syntax, 0 },
8463be01
PB
4677 { "cpu", s_arm_cpu, 0 },
4678 { "arch", s_arm_arch, 0 },
7a1d4c38 4679 { "object_arch", s_arm_object_arch, 0 },
8463be01 4680 { "fpu", s_arm_fpu, 0 },
69133863 4681 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4682#ifdef OBJ_ELF
c921be7d
NC
4683 { "word", s_arm_elf_cons, 4 },
4684 { "long", s_arm_elf_cons, 4 },
4685 { "inst.n", s_arm_elf_inst, 2 },
4686 { "inst.w", s_arm_elf_inst, 4 },
4687 { "inst", s_arm_elf_inst, 0 },
4688 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4689 { "fnstart", s_arm_unwind_fnstart, 0 },
4690 { "fnend", s_arm_unwind_fnend, 0 },
4691 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4692 { "personality", s_arm_unwind_personality, 0 },
4693 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4694 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4695 { "save", s_arm_unwind_save, 0 },
fa073d69 4696 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4697 { "movsp", s_arm_unwind_movsp, 0 },
4698 { "pad", s_arm_unwind_pad, 0 },
4699 { "setfp", s_arm_unwind_setfp, 0 },
4700 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4701 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4702 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4703#else
4704 { "word", cons, 4},
f0927246
NC
4705
4706 /* These are used for dwarf. */
4707 {"2byte", cons, 2},
4708 {"4byte", cons, 4},
4709 {"8byte", cons, 8},
4710 /* These are used for dwarf2. */
4711 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4712 { "loc", dwarf2_directive_loc, 0 },
4713 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4714#endif
4715 { "extend", float_cons, 'x' },
4716 { "ldouble", float_cons, 'x' },
4717 { "packed", float_cons, 'p' },
f0927246
NC
4718#ifdef TE_PE
4719 {"secrel32", pe_directive_secrel, 0},
4720#endif
2e6976a8
DG
4721
4722 /* These are for compatibility with CodeComposer Studio. */
4723 {"ref", s_ccs_ref, 0},
4724 {"def", s_ccs_def, 0},
4725 {"asmfunc", s_ccs_asmfunc, 0},
4726 {"endasmfunc", s_ccs_endasmfunc, 0},
4727
c19d1205
ZW
4728 { 0, 0, 0 }
4729};
4730\f
4731/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4732
c19d1205
ZW
4733/* Generic immediate-value read function for use in insn parsing.
4734 STR points to the beginning of the immediate (the leading #);
4735 VAL receives the value; if the value is outside [MIN, MAX]
4736 issue an error. PREFIX_OPT is true if the immediate prefix is
4737 optional. */
b99bd4ef 4738
c19d1205
ZW
4739static int
4740parse_immediate (char **str, int *val, int min, int max,
4741 bfd_boolean prefix_opt)
4742{
4743 expressionS exp;
4744 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4745 if (exp.X_op != O_constant)
b99bd4ef 4746 {
c19d1205
ZW
4747 inst.error = _("constant expression required");
4748 return FAIL;
4749 }
b99bd4ef 4750
c19d1205
ZW
4751 if (exp.X_add_number < min || exp.X_add_number > max)
4752 {
4753 inst.error = _("immediate value out of range");
4754 return FAIL;
4755 }
b99bd4ef 4756
c19d1205
ZW
4757 *val = exp.X_add_number;
4758 return SUCCESS;
4759}
b99bd4ef 4760
5287ad62 4761/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4762 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4763 instructions. Puts the result directly in inst.operands[i]. */
4764
4765static int
8335d6aa
JW
4766parse_big_immediate (char **str, int i, expressionS *in_exp,
4767 bfd_boolean allow_symbol_p)
5287ad62
JB
4768{
4769 expressionS exp;
8335d6aa 4770 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4771 char *ptr = *str;
4772
8335d6aa 4773 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4774
8335d6aa 4775 if (exp_p->X_op == O_constant)
036dc3f7 4776 {
8335d6aa 4777 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4778 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4779 O_constant. We have to be careful not to break compilation for
4780 32-bit X_add_number, though. */
8335d6aa 4781 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4782 {
8335d6aa
JW
4783 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4784 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4785 & 0xffffffff);
036dc3f7
PB
4786 inst.operands[i].regisimm = 1;
4787 }
4788 }
8335d6aa
JW
4789 else if (exp_p->X_op == O_big
4790 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4791 {
4792 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4793
5287ad62 4794 /* Bignums have their least significant bits in
477330fc
RM
4795 generic_bignum[0]. Make sure we put 32 bits in imm and
4796 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4797 gas_assert (parts != 0);
95b75c01
NC
4798
4799 /* Make sure that the number is not too big.
4800 PR 11972: Bignums can now be sign-extended to the
4801 size of a .octa so check that the out of range bits
4802 are all zero or all one. */
8335d6aa 4803 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4804 {
4805 LITTLENUM_TYPE m = -1;
4806
4807 if (generic_bignum[parts * 2] != 0
4808 && generic_bignum[parts * 2] != m)
4809 return FAIL;
4810
8335d6aa 4811 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4812 if (generic_bignum[j] != generic_bignum[j-1])
4813 return FAIL;
4814 }
4815
5287ad62
JB
4816 inst.operands[i].imm = 0;
4817 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4818 inst.operands[i].imm |= generic_bignum[idx]
4819 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4820 inst.operands[i].reg = 0;
4821 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4822 inst.operands[i].reg |= generic_bignum[idx]
4823 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4824 inst.operands[i].regisimm = 1;
4825 }
8335d6aa 4826 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4827 return FAIL;
5f4273c7 4828
5287ad62
JB
4829 *str = ptr;
4830
4831 return SUCCESS;
4832}
4833
c19d1205
ZW
4834/* Returns the pseudo-register number of an FPA immediate constant,
4835 or FAIL if there isn't a valid constant here. */
b99bd4ef 4836
c19d1205
ZW
4837static int
4838parse_fpa_immediate (char ** str)
4839{
4840 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4841 char * save_in;
4842 expressionS exp;
4843 int i;
4844 int j;
b99bd4ef 4845
c19d1205
ZW
4846 /* First try and match exact strings, this is to guarantee
4847 that some formats will work even for cross assembly. */
b99bd4ef 4848
c19d1205
ZW
4849 for (i = 0; fp_const[i]; i++)
4850 {
4851 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4852 {
c19d1205 4853 char *start = *str;
b99bd4ef 4854
c19d1205
ZW
4855 *str += strlen (fp_const[i]);
4856 if (is_end_of_line[(unsigned char) **str])
4857 return i + 8;
4858 *str = start;
4859 }
4860 }
b99bd4ef 4861
c19d1205
ZW
4862 /* Just because we didn't get a match doesn't mean that the constant
4863 isn't valid, just that it is in a format that we don't
4864 automatically recognize. Try parsing it with the standard
4865 expression routines. */
b99bd4ef 4866
c19d1205 4867 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4868
c19d1205
ZW
4869 /* Look for a raw floating point number. */
4870 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4871 && is_end_of_line[(unsigned char) *save_in])
4872 {
4873 for (i = 0; i < NUM_FLOAT_VALS; i++)
4874 {
4875 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4876 {
c19d1205
ZW
4877 if (words[j] != fp_values[i][j])
4878 break;
b99bd4ef
NC
4879 }
4880
c19d1205 4881 if (j == MAX_LITTLENUMS)
b99bd4ef 4882 {
c19d1205
ZW
4883 *str = save_in;
4884 return i + 8;
b99bd4ef
NC
4885 }
4886 }
4887 }
b99bd4ef 4888
c19d1205
ZW
4889 /* Try and parse a more complex expression, this will probably fail
4890 unless the code uses a floating point prefix (eg "0f"). */
4891 save_in = input_line_pointer;
4892 input_line_pointer = *str;
4893 if (expression (&exp) == absolute_section
4894 && exp.X_op == O_big
4895 && exp.X_add_number < 0)
4896 {
4897 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4898 Ditto for 15. */
ba592044
AM
4899#define X_PRECISION 5
4900#define E_PRECISION 15L
4901 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4902 {
4903 for (i = 0; i < NUM_FLOAT_VALS; i++)
4904 {
4905 for (j = 0; j < MAX_LITTLENUMS; j++)
4906 {
4907 if (words[j] != fp_values[i][j])
4908 break;
4909 }
b99bd4ef 4910
c19d1205
ZW
4911 if (j == MAX_LITTLENUMS)
4912 {
4913 *str = input_line_pointer;
4914 input_line_pointer = save_in;
4915 return i + 8;
4916 }
4917 }
4918 }
b99bd4ef
NC
4919 }
4920
c19d1205
ZW
4921 *str = input_line_pointer;
4922 input_line_pointer = save_in;
4923 inst.error = _("invalid FPA immediate expression");
4924 return FAIL;
b99bd4ef
NC
4925}
4926
136da414
JB
4927/* Returns 1 if a number has "quarter-precision" float format
4928 0baBbbbbbc defgh000 00000000 00000000. */
4929
4930static int
4931is_quarter_float (unsigned imm)
4932{
4933 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4934 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4935}
4936
aacf0b33
KT
4937
4938/* Detect the presence of a floating point or integer zero constant,
4939 i.e. #0.0 or #0. */
4940
4941static bfd_boolean
4942parse_ifimm_zero (char **in)
4943{
4944 int error_code;
4945
4946 if (!is_immediate_prefix (**in))
4947 return FALSE;
4948
4949 ++*in;
0900a05b
JW
4950
4951 /* Accept #0x0 as a synonym for #0. */
4952 if (strncmp (*in, "0x", 2) == 0)
4953 {
4954 int val;
4955 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4956 return FALSE;
4957 return TRUE;
4958 }
4959
aacf0b33
KT
4960 error_code = atof_generic (in, ".", EXP_CHARS,
4961 &generic_floating_point_number);
4962
4963 if (!error_code
4964 && generic_floating_point_number.sign == '+'
4965 && (generic_floating_point_number.low
4966 > generic_floating_point_number.leader))
4967 return TRUE;
4968
4969 return FALSE;
4970}
4971
136da414
JB
4972/* Parse an 8-bit "quarter-precision" floating point number of the form:
4973 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4974 The zero and minus-zero cases need special handling, since they can't be
4975 encoded in the "quarter-precision" float format, but can nonetheless be
4976 loaded as integer constants. */
136da414
JB
4977
4978static unsigned
4979parse_qfloat_immediate (char **ccp, int *immed)
4980{
4981 char *str = *ccp;
c96612cc 4982 char *fpnum;
136da414 4983 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4984 int found_fpchar = 0;
5f4273c7 4985
136da414 4986 skip_past_char (&str, '#');
5f4273c7 4987
c96612cc
JB
4988 /* We must not accidentally parse an integer as a floating-point number. Make
4989 sure that the value we parse is not an integer by checking for special
4990 characters '.' or 'e'.
4991 FIXME: This is a horrible hack, but doing better is tricky because type
4992 information isn't in a very usable state at parse time. */
4993 fpnum = str;
4994 skip_whitespace (fpnum);
4995
4996 if (strncmp (fpnum, "0x", 2) == 0)
4997 return FAIL;
4998 else
4999 {
5000 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5001 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5002 {
5003 found_fpchar = 1;
5004 break;
5005 }
c96612cc
JB
5006
5007 if (!found_fpchar)
477330fc 5008 return FAIL;
c96612cc 5009 }
5f4273c7 5010
136da414
JB
5011 if ((str = atof_ieee (str, 's', words)) != NULL)
5012 {
5013 unsigned fpword = 0;
5014 int i;
5f4273c7 5015
136da414
JB
5016 /* Our FP word must be 32 bits (single-precision FP). */
5017 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5018 {
5019 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5020 fpword |= words[i];
5021 }
5f4273c7 5022
c96612cc 5023 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5024 *immed = fpword;
136da414 5025 else
477330fc 5026 return FAIL;
136da414
JB
5027
5028 *ccp = str;
5f4273c7 5029
136da414
JB
5030 return SUCCESS;
5031 }
5f4273c7 5032
136da414
JB
5033 return FAIL;
5034}
5035
c19d1205
ZW
5036/* Shift operands. */
5037enum shift_kind
b99bd4ef 5038{
c19d1205
ZW
5039 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5040};
b99bd4ef 5041
c19d1205
ZW
5042struct asm_shift_name
5043{
5044 const char *name;
5045 enum shift_kind kind;
5046};
b99bd4ef 5047
c19d1205
ZW
5048/* Third argument to parse_shift. */
5049enum parse_shift_mode
5050{
5051 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5052 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5053 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5054 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5055 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5056};
b99bd4ef 5057
c19d1205
ZW
5058/* Parse a <shift> specifier on an ARM data processing instruction.
5059 This has three forms:
b99bd4ef 5060
c19d1205
ZW
5061 (LSL|LSR|ASL|ASR|ROR) Rs
5062 (LSL|LSR|ASL|ASR|ROR) #imm
5063 RRX
b99bd4ef 5064
c19d1205
ZW
5065 Note that ASL is assimilated to LSL in the instruction encoding, and
5066 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5067
c19d1205
ZW
5068static int
5069parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5070{
c19d1205
ZW
5071 const struct asm_shift_name *shift_name;
5072 enum shift_kind shift;
5073 char *s = *str;
5074 char *p = s;
5075 int reg;
b99bd4ef 5076
c19d1205
ZW
5077 for (p = *str; ISALPHA (*p); p++)
5078 ;
b99bd4ef 5079
c19d1205 5080 if (p == *str)
b99bd4ef 5081 {
c19d1205
ZW
5082 inst.error = _("shift expression expected");
5083 return FAIL;
b99bd4ef
NC
5084 }
5085
21d799b5 5086 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5087 p - *str);
c19d1205
ZW
5088
5089 if (shift_name == NULL)
b99bd4ef 5090 {
c19d1205
ZW
5091 inst.error = _("shift expression expected");
5092 return FAIL;
b99bd4ef
NC
5093 }
5094
c19d1205 5095 shift = shift_name->kind;
b99bd4ef 5096
c19d1205
ZW
5097 switch (mode)
5098 {
5099 case NO_SHIFT_RESTRICT:
5100 case SHIFT_IMMEDIATE: break;
b99bd4ef 5101
c19d1205
ZW
5102 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5103 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5104 {
5105 inst.error = _("'LSL' or 'ASR' required");
5106 return FAIL;
5107 }
5108 break;
b99bd4ef 5109
c19d1205
ZW
5110 case SHIFT_LSL_IMMEDIATE:
5111 if (shift != SHIFT_LSL)
5112 {
5113 inst.error = _("'LSL' required");
5114 return FAIL;
5115 }
5116 break;
b99bd4ef 5117
c19d1205
ZW
5118 case SHIFT_ASR_IMMEDIATE:
5119 if (shift != SHIFT_ASR)
5120 {
5121 inst.error = _("'ASR' required");
5122 return FAIL;
5123 }
5124 break;
b99bd4ef 5125
c19d1205
ZW
5126 default: abort ();
5127 }
b99bd4ef 5128
c19d1205
ZW
5129 if (shift != SHIFT_RRX)
5130 {
5131 /* Whitespace can appear here if the next thing is a bare digit. */
5132 skip_whitespace (p);
b99bd4ef 5133
c19d1205 5134 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5135 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5136 {
5137 inst.operands[i].imm = reg;
5138 inst.operands[i].immisreg = 1;
5139 }
5140 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5141 return FAIL;
5142 }
5143 inst.operands[i].shift_kind = shift;
5144 inst.operands[i].shifted = 1;
5145 *str = p;
5146 return SUCCESS;
b99bd4ef
NC
5147}
5148
c19d1205 5149/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5150
c19d1205
ZW
5151 #<immediate>
5152 #<immediate>, <rotate>
5153 <Rm>
5154 <Rm>, <shift>
b99bd4ef 5155
c19d1205
ZW
5156 where <shift> is defined by parse_shift above, and <rotate> is a
5157 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5158 is deferred to md_apply_fix. */
b99bd4ef 5159
c19d1205
ZW
5160static int
5161parse_shifter_operand (char **str, int i)
5162{
5163 int value;
91d6fa6a 5164 expressionS exp;
b99bd4ef 5165
dcbf9037 5166 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5167 {
5168 inst.operands[i].reg = value;
5169 inst.operands[i].isreg = 1;
b99bd4ef 5170
c19d1205
ZW
5171 /* parse_shift will override this if appropriate */
5172 inst.reloc.exp.X_op = O_constant;
5173 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5174
c19d1205
ZW
5175 if (skip_past_comma (str) == FAIL)
5176 return SUCCESS;
b99bd4ef 5177
c19d1205
ZW
5178 /* Shift operation on register. */
5179 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5180 }
5181
c19d1205
ZW
5182 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5183 return FAIL;
b99bd4ef 5184
c19d1205 5185 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5186 {
c19d1205 5187 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5188 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5189 return FAIL;
b99bd4ef 5190
91d6fa6a 5191 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5192 {
5193 inst.error = _("constant expression expected");
5194 return FAIL;
5195 }
b99bd4ef 5196
91d6fa6a 5197 value = exp.X_add_number;
c19d1205
ZW
5198 if (value < 0 || value > 30 || value % 2 != 0)
5199 {
5200 inst.error = _("invalid rotation");
5201 return FAIL;
5202 }
5203 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5204 {
5205 inst.error = _("invalid constant");
5206 return FAIL;
5207 }
09d92015 5208
a415b1cd
JB
5209 /* Encode as specified. */
5210 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5211 return SUCCESS;
09d92015
MM
5212 }
5213
c19d1205
ZW
5214 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5215 inst.reloc.pc_rel = 0;
5216 return SUCCESS;
09d92015
MM
5217}
5218
4962c51a
MS
5219/* Group relocation information. Each entry in the table contains the
5220 textual name of the relocation as may appear in assembler source
5221 and must end with a colon.
5222 Along with this textual name are the relocation codes to be used if
5223 the corresponding instruction is an ALU instruction (ADD or SUB only),
5224 an LDR, an LDRS, or an LDC. */
5225
5226struct group_reloc_table_entry
5227{
5228 const char *name;
5229 int alu_code;
5230 int ldr_code;
5231 int ldrs_code;
5232 int ldc_code;
5233};
5234
5235typedef enum
5236{
5237 /* Varieties of non-ALU group relocation. */
5238
5239 GROUP_LDR,
5240 GROUP_LDRS,
5241 GROUP_LDC
5242} group_reloc_type;
5243
5244static struct group_reloc_table_entry group_reloc_table[] =
5245 { /* Program counter relative: */
5246 { "pc_g0_nc",
5247 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5248 0, /* LDR */
5249 0, /* LDRS */
5250 0 }, /* LDC */
5251 { "pc_g0",
5252 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5253 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5254 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5255 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5256 { "pc_g1_nc",
5257 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5258 0, /* LDR */
5259 0, /* LDRS */
5260 0 }, /* LDC */
5261 { "pc_g1",
5262 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5263 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5264 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5265 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5266 { "pc_g2",
5267 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5268 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5269 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5270 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5271 /* Section base relative */
5272 { "sb_g0_nc",
5273 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5274 0, /* LDR */
5275 0, /* LDRS */
5276 0 }, /* LDC */
5277 { "sb_g0",
5278 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5279 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5280 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5281 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5282 { "sb_g1_nc",
5283 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5284 0, /* LDR */
5285 0, /* LDRS */
5286 0 }, /* LDC */
5287 { "sb_g1",
5288 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5289 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5290 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5291 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5292 { "sb_g2",
5293 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5294 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5295 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5296 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5297 /* Absolute thumb alu relocations. */
5298 { "lower0_7",
5299 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5300 0, /* LDR. */
5301 0, /* LDRS. */
5302 0 }, /* LDC. */
5303 { "lower8_15",
5304 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5305 0, /* LDR. */
5306 0, /* LDRS. */
5307 0 }, /* LDC. */
5308 { "upper0_7",
5309 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5310 0, /* LDR. */
5311 0, /* LDRS. */
5312 0 }, /* LDC. */
5313 { "upper8_15",
5314 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5315 0, /* LDR. */
5316 0, /* LDRS. */
5317 0 } }; /* LDC. */
4962c51a
MS
5318
5319/* Given the address of a pointer pointing to the textual name of a group
5320 relocation as may appear in assembler source, attempt to find its details
5321 in group_reloc_table. The pointer will be updated to the character after
5322 the trailing colon. On failure, FAIL will be returned; SUCCESS
5323 otherwise. On success, *entry will be updated to point at the relevant
5324 group_reloc_table entry. */
5325
5326static int
5327find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5328{
5329 unsigned int i;
5330 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5331 {
5332 int length = strlen (group_reloc_table[i].name);
5333
5f4273c7
NC
5334 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5335 && (*str)[length] == ':')
477330fc
RM
5336 {
5337 *out = &group_reloc_table[i];
5338 *str += (length + 1);
5339 return SUCCESS;
5340 }
4962c51a
MS
5341 }
5342
5343 return FAIL;
5344}
5345
5346/* Parse a <shifter_operand> for an ARM data processing instruction
5347 (as for parse_shifter_operand) where group relocations are allowed:
5348
5349 #<immediate>
5350 #<immediate>, <rotate>
5351 #:<group_reloc>:<expression>
5352 <Rm>
5353 <Rm>, <shift>
5354
5355 where <group_reloc> is one of the strings defined in group_reloc_table.
5356 The hashes are optional.
5357
5358 Everything else is as for parse_shifter_operand. */
5359
5360static parse_operand_result
5361parse_shifter_operand_group_reloc (char **str, int i)
5362{
5363 /* Determine if we have the sequence of characters #: or just :
5364 coming next. If we do, then we check for a group relocation.
5365 If we don't, punt the whole lot to parse_shifter_operand. */
5366
5367 if (((*str)[0] == '#' && (*str)[1] == ':')
5368 || (*str)[0] == ':')
5369 {
5370 struct group_reloc_table_entry *entry;
5371
5372 if ((*str)[0] == '#')
477330fc 5373 (*str) += 2;
4962c51a 5374 else
477330fc 5375 (*str)++;
4962c51a
MS
5376
5377 /* Try to parse a group relocation. Anything else is an error. */
5378 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5379 {
5380 inst.error = _("unknown group relocation");
5381 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5382 }
4962c51a
MS
5383
5384 /* We now have the group relocation table entry corresponding to
477330fc 5385 the name in the assembler source. Next, we parse the expression. */
4962c51a 5386 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5387 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5388
5389 /* Record the relocation type (always the ALU variant here). */
21d799b5 5390 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5391 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5392
5393 return PARSE_OPERAND_SUCCESS;
5394 }
5395 else
5396 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5397 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5398
5399 /* Never reached. */
5400}
5401
8e560766
MGD
5402/* Parse a Neon alignment expression. Information is written to
5403 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5404
8e560766
MGD
5405 align .imm = align << 8, .immisalign=1, .preind=0 */
5406static parse_operand_result
5407parse_neon_alignment (char **str, int i)
5408{
5409 char *p = *str;
5410 expressionS exp;
5411
5412 my_get_expression (&exp, &p, GE_NO_PREFIX);
5413
5414 if (exp.X_op != O_constant)
5415 {
5416 inst.error = _("alignment must be constant");
5417 return PARSE_OPERAND_FAIL;
5418 }
5419
5420 inst.operands[i].imm = exp.X_add_number << 8;
5421 inst.operands[i].immisalign = 1;
5422 /* Alignments are not pre-indexes. */
5423 inst.operands[i].preind = 0;
5424
5425 *str = p;
5426 return PARSE_OPERAND_SUCCESS;
5427}
5428
c19d1205
ZW
5429/* Parse all forms of an ARM address expression. Information is written
5430 to inst.operands[i] and/or inst.reloc.
09d92015 5431
c19d1205 5432 Preindexed addressing (.preind=1):
09d92015 5433
c19d1205
ZW
5434 [Rn, #offset] .reg=Rn .reloc.exp=offset
5435 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5436 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5437 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5438
c19d1205 5439 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5440
c19d1205 5441 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5442
c19d1205
ZW
5443 [Rn], #offset .reg=Rn .reloc.exp=offset
5444 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5445 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5446 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5447
c19d1205 5448 Unindexed addressing (.preind=0, .postind=0):
09d92015 5449
c19d1205 5450 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5451
c19d1205 5452 Other:
09d92015 5453
c19d1205
ZW
5454 [Rn]{!} shorthand for [Rn,#0]{!}
5455 =immediate .isreg=0 .reloc.exp=immediate
5456 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5457
c19d1205
ZW
5458 It is the caller's responsibility to check for addressing modes not
5459 supported by the instruction, and to set inst.reloc.type. */
5460
4962c51a
MS
5461static parse_operand_result
5462parse_address_main (char **str, int i, int group_relocations,
477330fc 5463 group_reloc_type group_type)
09d92015 5464{
c19d1205
ZW
5465 char *p = *str;
5466 int reg;
09d92015 5467
c19d1205 5468 if (skip_past_char (&p, '[') == FAIL)
09d92015 5469 {
c19d1205
ZW
5470 if (skip_past_char (&p, '=') == FAIL)
5471 {
974da60d 5472 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5473 inst.reloc.pc_rel = 1;
5474 inst.operands[i].reg = REG_PC;
5475 inst.operands[i].isreg = 1;
5476 inst.operands[i].preind = 1;
09d92015 5477
8335d6aa
JW
5478 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5479 return PARSE_OPERAND_FAIL;
5480 }
5481 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5482 /*allow_symbol_p=*/TRUE))
4962c51a 5483 return PARSE_OPERAND_FAIL;
09d92015 5484
c19d1205 5485 *str = p;
4962c51a 5486 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5487 }
5488
8ab8155f
NC
5489 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5490 skip_whitespace (p);
5491
dcbf9037 5492 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5493 {
c19d1205 5494 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5495 return PARSE_OPERAND_FAIL;
09d92015 5496 }
c19d1205
ZW
5497 inst.operands[i].reg = reg;
5498 inst.operands[i].isreg = 1;
09d92015 5499
c19d1205 5500 if (skip_past_comma (&p) == SUCCESS)
09d92015 5501 {
c19d1205 5502 inst.operands[i].preind = 1;
09d92015 5503
c19d1205
ZW
5504 if (*p == '+') p++;
5505 else if (*p == '-') p++, inst.operands[i].negative = 1;
5506
dcbf9037 5507 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5508 {
c19d1205
ZW
5509 inst.operands[i].imm = reg;
5510 inst.operands[i].immisreg = 1;
5511
5512 if (skip_past_comma (&p) == SUCCESS)
5513 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5514 return PARSE_OPERAND_FAIL;
c19d1205 5515 }
5287ad62 5516 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5517 {
5518 /* FIXME: '@' should be used here, but it's filtered out by generic
5519 code before we get to see it here. This may be subject to
5520 change. */
5521 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5522
8e560766
MGD
5523 if (result != PARSE_OPERAND_SUCCESS)
5524 return result;
5525 }
c19d1205
ZW
5526 else
5527 {
5528 if (inst.operands[i].negative)
5529 {
5530 inst.operands[i].negative = 0;
5531 p--;
5532 }
4962c51a 5533
5f4273c7
NC
5534 if (group_relocations
5535 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5536 {
5537 struct group_reloc_table_entry *entry;
5538
477330fc
RM
5539 /* Skip over the #: or : sequence. */
5540 if (*p == '#')
5541 p += 2;
5542 else
5543 p++;
4962c51a
MS
5544
5545 /* Try to parse a group relocation. Anything else is an
477330fc 5546 error. */
4962c51a
MS
5547 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5548 {
5549 inst.error = _("unknown group relocation");
5550 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5551 }
5552
5553 /* We now have the group relocation table entry corresponding to
5554 the name in the assembler source. Next, we parse the
477330fc 5555 expression. */
4962c51a
MS
5556 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5557 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5558
5559 /* Record the relocation type. */
477330fc
RM
5560 switch (group_type)
5561 {
5562 case GROUP_LDR:
5563 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5564 break;
4962c51a 5565
477330fc
RM
5566 case GROUP_LDRS:
5567 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5568 break;
4962c51a 5569
477330fc
RM
5570 case GROUP_LDC:
5571 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5572 break;
4962c51a 5573
477330fc
RM
5574 default:
5575 gas_assert (0);
5576 }
4962c51a 5577
477330fc 5578 if (inst.reloc.type == 0)
4962c51a
MS
5579 {
5580 inst.error = _("this group relocation is not allowed on this instruction");
5581 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5582 }
477330fc
RM
5583 }
5584 else
26d97720
NS
5585 {
5586 char *q = p;
5587 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5588 return PARSE_OPERAND_FAIL;
5589 /* If the offset is 0, find out if it's a +0 or -0. */
5590 if (inst.reloc.exp.X_op == O_constant
5591 && inst.reloc.exp.X_add_number == 0)
5592 {
5593 skip_whitespace (q);
5594 if (*q == '#')
5595 {
5596 q++;
5597 skip_whitespace (q);
5598 }
5599 if (*q == '-')
5600 inst.operands[i].negative = 1;
5601 }
5602 }
09d92015
MM
5603 }
5604 }
8e560766
MGD
5605 else if (skip_past_char (&p, ':') == SUCCESS)
5606 {
5607 /* FIXME: '@' should be used here, but it's filtered out by generic code
5608 before we get to see it here. This may be subject to change. */
5609 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5610
8e560766
MGD
5611 if (result != PARSE_OPERAND_SUCCESS)
5612 return result;
5613 }
09d92015 5614
c19d1205 5615 if (skip_past_char (&p, ']') == FAIL)
09d92015 5616 {
c19d1205 5617 inst.error = _("']' expected");
4962c51a 5618 return PARSE_OPERAND_FAIL;
09d92015
MM
5619 }
5620
c19d1205
ZW
5621 if (skip_past_char (&p, '!') == SUCCESS)
5622 inst.operands[i].writeback = 1;
09d92015 5623
c19d1205 5624 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5625 {
c19d1205
ZW
5626 if (skip_past_char (&p, '{') == SUCCESS)
5627 {
5628 /* [Rn], {expr} - unindexed, with option */
5629 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5630 0, 255, TRUE) == FAIL)
4962c51a 5631 return PARSE_OPERAND_FAIL;
09d92015 5632
c19d1205
ZW
5633 if (skip_past_char (&p, '}') == FAIL)
5634 {
5635 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5636 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5637 }
5638 if (inst.operands[i].preind)
5639 {
5640 inst.error = _("cannot combine index with option");
4962c51a 5641 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5642 }
5643 *str = p;
4962c51a 5644 return PARSE_OPERAND_SUCCESS;
09d92015 5645 }
c19d1205
ZW
5646 else
5647 {
5648 inst.operands[i].postind = 1;
5649 inst.operands[i].writeback = 1;
09d92015 5650
c19d1205
ZW
5651 if (inst.operands[i].preind)
5652 {
5653 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5654 return PARSE_OPERAND_FAIL;
c19d1205 5655 }
09d92015 5656
c19d1205
ZW
5657 if (*p == '+') p++;
5658 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5659
dcbf9037 5660 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5661 {
477330fc
RM
5662 /* We might be using the immediate for alignment already. If we
5663 are, OR the register number into the low-order bits. */
5664 if (inst.operands[i].immisalign)
5665 inst.operands[i].imm |= reg;
5666 else
5667 inst.operands[i].imm = reg;
c19d1205 5668 inst.operands[i].immisreg = 1;
a737bd4d 5669
c19d1205
ZW
5670 if (skip_past_comma (&p) == SUCCESS)
5671 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5672 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5673 }
5674 else
5675 {
26d97720 5676 char *q = p;
c19d1205
ZW
5677 if (inst.operands[i].negative)
5678 {
5679 inst.operands[i].negative = 0;
5680 p--;
5681 }
5682 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5683 return PARSE_OPERAND_FAIL;
26d97720
NS
5684 /* If the offset is 0, find out if it's a +0 or -0. */
5685 if (inst.reloc.exp.X_op == O_constant
5686 && inst.reloc.exp.X_add_number == 0)
5687 {
5688 skip_whitespace (q);
5689 if (*q == '#')
5690 {
5691 q++;
5692 skip_whitespace (q);
5693 }
5694 if (*q == '-')
5695 inst.operands[i].negative = 1;
5696 }
c19d1205
ZW
5697 }
5698 }
a737bd4d
NC
5699 }
5700
c19d1205
ZW
5701 /* If at this point neither .preind nor .postind is set, we have a
5702 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5703 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5704 {
5705 inst.operands[i].preind = 1;
5706 inst.reloc.exp.X_op = O_constant;
5707 inst.reloc.exp.X_add_number = 0;
5708 }
5709 *str = p;
4962c51a
MS
5710 return PARSE_OPERAND_SUCCESS;
5711}
5712
5713static int
5714parse_address (char **str, int i)
5715{
21d799b5 5716 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5717 ? SUCCESS : FAIL;
4962c51a
MS
5718}
5719
5720static parse_operand_result
5721parse_address_group_reloc (char **str, int i, group_reloc_type type)
5722{
5723 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5724}
5725
b6895b4f
PB
5726/* Parse an operand for a MOVW or MOVT instruction. */
5727static int
5728parse_half (char **str)
5729{
5730 char * p;
5f4273c7 5731
b6895b4f
PB
5732 p = *str;
5733 skip_past_char (&p, '#');
5f4273c7 5734 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5735 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5736 else if (strncasecmp (p, ":upper16:", 9) == 0)
5737 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5738
5739 if (inst.reloc.type != BFD_RELOC_UNUSED)
5740 {
5741 p += 9;
5f4273c7 5742 skip_whitespace (p);
b6895b4f
PB
5743 }
5744
5745 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5746 return FAIL;
5747
5748 if (inst.reloc.type == BFD_RELOC_UNUSED)
5749 {
5750 if (inst.reloc.exp.X_op != O_constant)
5751 {
5752 inst.error = _("constant expression expected");
5753 return FAIL;
5754 }
5755 if (inst.reloc.exp.X_add_number < 0
5756 || inst.reloc.exp.X_add_number > 0xffff)
5757 {
5758 inst.error = _("immediate value out of range");
5759 return FAIL;
5760 }
5761 }
5762 *str = p;
5763 return SUCCESS;
5764}
5765
c19d1205 5766/* Miscellaneous. */
a737bd4d 5767
c19d1205
ZW
5768/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5769 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5770static int
d2cd1205 5771parse_psr (char **str, bfd_boolean lhs)
09d92015 5772{
c19d1205
ZW
5773 char *p;
5774 unsigned long psr_field;
62b3e311
PB
5775 const struct asm_psr *psr;
5776 char *start;
d2cd1205 5777 bfd_boolean is_apsr = FALSE;
ac7f631b 5778 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5779
a4482bb6
NC
5780 /* PR gas/12698: If the user has specified -march=all then m_profile will
5781 be TRUE, but we want to ignore it in this case as we are building for any
5782 CPU type, including non-m variants. */
823d2571 5783 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5784 m_profile = FALSE;
5785
c19d1205
ZW
5786 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5787 feature for ease of use and backwards compatibility. */
5788 p = *str;
62b3e311 5789 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5790 {
5791 if (m_profile)
5792 goto unsupported_psr;
fa94de6b 5793
d2cd1205
JB
5794 psr_field = SPSR_BIT;
5795 }
5796 else if (strncasecmp (p, "CPSR", 4) == 0)
5797 {
5798 if (m_profile)
5799 goto unsupported_psr;
5800
5801 psr_field = 0;
5802 }
5803 else if (strncasecmp (p, "APSR", 4) == 0)
5804 {
5805 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5806 and ARMv7-R architecture CPUs. */
5807 is_apsr = TRUE;
5808 psr_field = 0;
5809 }
5810 else if (m_profile)
62b3e311
PB
5811 {
5812 start = p;
5813 do
5814 p++;
5815 while (ISALNUM (*p) || *p == '_');
5816
d2cd1205
JB
5817 if (strncasecmp (start, "iapsr", 5) == 0
5818 || strncasecmp (start, "eapsr", 5) == 0
5819 || strncasecmp (start, "xpsr", 4) == 0
5820 || strncasecmp (start, "psr", 3) == 0)
5821 p = start + strcspn (start, "rR") + 1;
5822
21d799b5 5823 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5824 p - start);
d2cd1205 5825
62b3e311
PB
5826 if (!psr)
5827 return FAIL;
09d92015 5828
d2cd1205
JB
5829 /* If APSR is being written, a bitfield may be specified. Note that
5830 APSR itself is handled above. */
5831 if (psr->field <= 3)
5832 {
5833 psr_field = psr->field;
5834 is_apsr = TRUE;
5835 goto check_suffix;
5836 }
5837
62b3e311 5838 *str = p;
d2cd1205
JB
5839 /* M-profile MSR instructions have the mask field set to "10", except
5840 *PSR variants which modify APSR, which may use a different mask (and
5841 have been handled already). Do that by setting the PSR_f field
5842 here. */
5843 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5844 }
d2cd1205
JB
5845 else
5846 goto unsupported_psr;
09d92015 5847
62b3e311 5848 p += 4;
d2cd1205 5849check_suffix:
c19d1205
ZW
5850 if (*p == '_')
5851 {
5852 /* A suffix follows. */
c19d1205
ZW
5853 p++;
5854 start = p;
a737bd4d 5855
c19d1205
ZW
5856 do
5857 p++;
5858 while (ISALNUM (*p) || *p == '_');
a737bd4d 5859
d2cd1205
JB
5860 if (is_apsr)
5861 {
5862 /* APSR uses a notation for bits, rather than fields. */
5863 unsigned int nzcvq_bits = 0;
5864 unsigned int g_bit = 0;
5865 char *bit;
fa94de6b 5866
d2cd1205
JB
5867 for (bit = start; bit != p; bit++)
5868 {
5869 switch (TOLOWER (*bit))
477330fc 5870 {
d2cd1205
JB
5871 case 'n':
5872 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5873 break;
5874
5875 case 'z':
5876 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5877 break;
5878
5879 case 'c':
5880 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5881 break;
5882
5883 case 'v':
5884 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5885 break;
fa94de6b 5886
d2cd1205
JB
5887 case 'q':
5888 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5889 break;
fa94de6b 5890
d2cd1205
JB
5891 case 'g':
5892 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5893 break;
fa94de6b 5894
d2cd1205
JB
5895 default:
5896 inst.error = _("unexpected bit specified after APSR");
5897 return FAIL;
5898 }
5899 }
fa94de6b 5900
d2cd1205
JB
5901 if (nzcvq_bits == 0x1f)
5902 psr_field |= PSR_f;
fa94de6b 5903
d2cd1205
JB
5904 if (g_bit == 0x1)
5905 {
5906 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5907 {
d2cd1205
JB
5908 inst.error = _("selected processor does not "
5909 "support DSP extension");
5910 return FAIL;
5911 }
5912
5913 psr_field |= PSR_s;
5914 }
fa94de6b 5915
d2cd1205
JB
5916 if ((nzcvq_bits & 0x20) != 0
5917 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5918 || (g_bit & 0x2) != 0)
5919 {
5920 inst.error = _("bad bitmask specified after APSR");
5921 return FAIL;
5922 }
5923 }
5924 else
477330fc 5925 {
d2cd1205 5926 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5927 p - start);
d2cd1205 5928 if (!psr)
477330fc 5929 goto error;
a737bd4d 5930
d2cd1205
JB
5931 psr_field |= psr->field;
5932 }
a737bd4d 5933 }
c19d1205 5934 else
a737bd4d 5935 {
c19d1205
ZW
5936 if (ISALNUM (*p))
5937 goto error; /* Garbage after "[CS]PSR". */
5938
d2cd1205 5939 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5940 is deprecated, but allow it anyway. */
d2cd1205
JB
5941 if (is_apsr && lhs)
5942 {
5943 psr_field |= PSR_f;
5944 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5945 "deprecated"));
5946 }
5947 else if (!m_profile)
5948 /* These bits are never right for M-profile devices: don't set them
5949 (only code paths which read/write APSR reach here). */
5950 psr_field |= (PSR_c | PSR_f);
a737bd4d 5951 }
c19d1205
ZW
5952 *str = p;
5953 return psr_field;
a737bd4d 5954
d2cd1205
JB
5955 unsupported_psr:
5956 inst.error = _("selected processor does not support requested special "
5957 "purpose register");
5958 return FAIL;
5959
c19d1205
ZW
5960 error:
5961 inst.error = _("flag for {c}psr instruction expected");
5962 return FAIL;
a737bd4d
NC
5963}
5964
c19d1205
ZW
5965/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5966 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5967
c19d1205
ZW
5968static int
5969parse_cps_flags (char **str)
a737bd4d 5970{
c19d1205
ZW
5971 int val = 0;
5972 int saw_a_flag = 0;
5973 char *s = *str;
a737bd4d 5974
c19d1205
ZW
5975 for (;;)
5976 switch (*s++)
5977 {
5978 case '\0': case ',':
5979 goto done;
a737bd4d 5980
c19d1205
ZW
5981 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5982 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5983 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5984
c19d1205
ZW
5985 default:
5986 inst.error = _("unrecognized CPS flag");
5987 return FAIL;
5988 }
a737bd4d 5989
c19d1205
ZW
5990 done:
5991 if (saw_a_flag == 0)
a737bd4d 5992 {
c19d1205
ZW
5993 inst.error = _("missing CPS flags");
5994 return FAIL;
a737bd4d 5995 }
a737bd4d 5996
c19d1205
ZW
5997 *str = s - 1;
5998 return val;
a737bd4d
NC
5999}
6000
c19d1205
ZW
6001/* Parse an endian specifier ("BE" or "LE", case insensitive);
6002 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6003
6004static int
c19d1205 6005parse_endian_specifier (char **str)
a737bd4d 6006{
c19d1205
ZW
6007 int little_endian;
6008 char *s = *str;
a737bd4d 6009
c19d1205
ZW
6010 if (strncasecmp (s, "BE", 2))
6011 little_endian = 0;
6012 else if (strncasecmp (s, "LE", 2))
6013 little_endian = 1;
6014 else
a737bd4d 6015 {
c19d1205 6016 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6017 return FAIL;
6018 }
6019
c19d1205 6020 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6021 {
c19d1205 6022 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6023 return FAIL;
6024 }
6025
c19d1205
ZW
6026 *str = s + 2;
6027 return little_endian;
6028}
a737bd4d 6029
c19d1205
ZW
6030/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6031 value suitable for poking into the rotate field of an sxt or sxta
6032 instruction, or FAIL on error. */
6033
6034static int
6035parse_ror (char **str)
6036{
6037 int rot;
6038 char *s = *str;
6039
6040 if (strncasecmp (s, "ROR", 3) == 0)
6041 s += 3;
6042 else
a737bd4d 6043 {
c19d1205 6044 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6045 return FAIL;
6046 }
c19d1205
ZW
6047
6048 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6049 return FAIL;
6050
6051 switch (rot)
a737bd4d 6052 {
c19d1205
ZW
6053 case 0: *str = s; return 0x0;
6054 case 8: *str = s; return 0x1;
6055 case 16: *str = s; return 0x2;
6056 case 24: *str = s; return 0x3;
6057
6058 default:
6059 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6060 return FAIL;
6061 }
c19d1205 6062}
a737bd4d 6063
c19d1205
ZW
6064/* Parse a conditional code (from conds[] below). The value returned is in the
6065 range 0 .. 14, or FAIL. */
6066static int
6067parse_cond (char **str)
6068{
c462b453 6069 char *q;
c19d1205 6070 const struct asm_cond *c;
c462b453
PB
6071 int n;
6072 /* Condition codes are always 2 characters, so matching up to
6073 3 characters is sufficient. */
6074 char cond[3];
a737bd4d 6075
c462b453
PB
6076 q = *str;
6077 n = 0;
6078 while (ISALPHA (*q) && n < 3)
6079 {
e07e6e58 6080 cond[n] = TOLOWER (*q);
c462b453
PB
6081 q++;
6082 n++;
6083 }
a737bd4d 6084
21d799b5 6085 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6086 if (!c)
a737bd4d 6087 {
c19d1205 6088 inst.error = _("condition required");
a737bd4d
NC
6089 return FAIL;
6090 }
6091
c19d1205
ZW
6092 *str = q;
6093 return c->value;
6094}
6095
643afb90
MW
6096/* Record a use of the given feature. */
6097static void
6098record_feature_use (const arm_feature_set *feature)
6099{
6100 if (thumb_mode)
6101 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6102 else
6103 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6104}
6105
e797f7e0
MGD
6106/* If the given feature available in the selected CPU, mark it as used.
6107 Returns TRUE iff feature is available. */
6108static bfd_boolean
6109mark_feature_used (const arm_feature_set *feature)
6110{
6111 /* Ensure the option is valid on the current architecture. */
6112 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6113 return FALSE;
6114
6115 /* Add the appropriate architecture feature for the barrier option used.
6116 */
643afb90 6117 record_feature_use (feature);
e797f7e0
MGD
6118
6119 return TRUE;
6120}
6121
62b3e311
PB
6122/* Parse an option for a barrier instruction. Returns the encoding for the
6123 option, or FAIL. */
6124static int
6125parse_barrier (char **str)
6126{
6127 char *p, *q;
6128 const struct asm_barrier_opt *o;
6129
6130 p = q = *str;
6131 while (ISALPHA (*q))
6132 q++;
6133
21d799b5 6134 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6135 q - p);
62b3e311
PB
6136 if (!o)
6137 return FAIL;
6138
e797f7e0
MGD
6139 if (!mark_feature_used (&o->arch))
6140 return FAIL;
6141
62b3e311
PB
6142 *str = q;
6143 return o->value;
6144}
6145
92e90b6e
PB
6146/* Parse the operands of a table branch instruction. Similar to a memory
6147 operand. */
6148static int
6149parse_tb (char **str)
6150{
6151 char * p = *str;
6152 int reg;
6153
6154 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6155 {
6156 inst.error = _("'[' expected");
6157 return FAIL;
6158 }
92e90b6e 6159
dcbf9037 6160 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6161 {
6162 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6163 return FAIL;
6164 }
6165 inst.operands[0].reg = reg;
6166
6167 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6168 {
6169 inst.error = _("',' expected");
6170 return FAIL;
6171 }
5f4273c7 6172
dcbf9037 6173 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6174 {
6175 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6176 return FAIL;
6177 }
6178 inst.operands[0].imm = reg;
6179
6180 if (skip_past_comma (&p) == SUCCESS)
6181 {
6182 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6183 return FAIL;
6184 if (inst.reloc.exp.X_add_number != 1)
6185 {
6186 inst.error = _("invalid shift");
6187 return FAIL;
6188 }
6189 inst.operands[0].shifted = 1;
6190 }
6191
6192 if (skip_past_char (&p, ']') == FAIL)
6193 {
6194 inst.error = _("']' expected");
6195 return FAIL;
6196 }
6197 *str = p;
6198 return SUCCESS;
6199}
6200
5287ad62
JB
6201/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6202 information on the types the operands can take and how they are encoded.
037e8744
JB
6203 Up to four operands may be read; this function handles setting the
6204 ".present" field for each read operand itself.
5287ad62
JB
6205 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6206 else returns FAIL. */
6207
6208static int
6209parse_neon_mov (char **str, int *which_operand)
6210{
6211 int i = *which_operand, val;
6212 enum arm_reg_type rtype;
6213 char *ptr = *str;
dcbf9037 6214 struct neon_type_el optype;
5f4273c7 6215
dcbf9037 6216 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6217 {
6218 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6219 inst.operands[i].reg = val;
6220 inst.operands[i].isscalar = 1;
dcbf9037 6221 inst.operands[i].vectype = optype;
5287ad62
JB
6222 inst.operands[i++].present = 1;
6223
6224 if (skip_past_comma (&ptr) == FAIL)
477330fc 6225 goto wanted_comma;
5f4273c7 6226
dcbf9037 6227 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6228 goto wanted_arm;
5f4273c7 6229
5287ad62
JB
6230 inst.operands[i].reg = val;
6231 inst.operands[i].isreg = 1;
6232 inst.operands[i].present = 1;
6233 }
037e8744 6234 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6235 != FAIL)
5287ad62
JB
6236 {
6237 /* Cases 0, 1, 2, 3, 5 (D only). */
6238 if (skip_past_comma (&ptr) == FAIL)
477330fc 6239 goto wanted_comma;
5f4273c7 6240
5287ad62
JB
6241 inst.operands[i].reg = val;
6242 inst.operands[i].isreg = 1;
6243 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6244 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6245 inst.operands[i].isvec = 1;
dcbf9037 6246 inst.operands[i].vectype = optype;
5287ad62
JB
6247 inst.operands[i++].present = 1;
6248
dcbf9037 6249 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6250 {
6251 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6252 Case 13: VMOV <Sd>, <Rm> */
6253 inst.operands[i].reg = val;
6254 inst.operands[i].isreg = 1;
6255 inst.operands[i].present = 1;
6256
6257 if (rtype == REG_TYPE_NQ)
6258 {
6259 first_error (_("can't use Neon quad register here"));
6260 return FAIL;
6261 }
6262 else if (rtype != REG_TYPE_VFS)
6263 {
6264 i++;
6265 if (skip_past_comma (&ptr) == FAIL)
6266 goto wanted_comma;
6267 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6268 goto wanted_arm;
6269 inst.operands[i].reg = val;
6270 inst.operands[i].isreg = 1;
6271 inst.operands[i].present = 1;
6272 }
6273 }
037e8744 6274 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6275 &optype)) != FAIL)
6276 {
6277 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6278 Case 1: VMOV<c><q> <Dd>, <Dm>
6279 Case 8: VMOV.F32 <Sd>, <Sm>
6280 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6281
6282 inst.operands[i].reg = val;
6283 inst.operands[i].isreg = 1;
6284 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6285 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6286 inst.operands[i].isvec = 1;
6287 inst.operands[i].vectype = optype;
6288 inst.operands[i].present = 1;
6289
6290 if (skip_past_comma (&ptr) == SUCCESS)
6291 {
6292 /* Case 15. */
6293 i++;
6294
6295 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6296 goto wanted_arm;
6297
6298 inst.operands[i].reg = val;
6299 inst.operands[i].isreg = 1;
6300 inst.operands[i++].present = 1;
6301
6302 if (skip_past_comma (&ptr) == FAIL)
6303 goto wanted_comma;
6304
6305 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6306 goto wanted_arm;
6307
6308 inst.operands[i].reg = val;
6309 inst.operands[i].isreg = 1;
6310 inst.operands[i].present = 1;
6311 }
6312 }
4641781c 6313 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6314 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6315 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6316 Case 10: VMOV.F32 <Sd>, #<imm>
6317 Case 11: VMOV.F64 <Dd>, #<imm> */
6318 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6319 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6320 == SUCCESS)
477330fc
RM
6321 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6322 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6323 ;
5287ad62 6324 else
477330fc
RM
6325 {
6326 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6327 return FAIL;
6328 }
5287ad62 6329 }
dcbf9037 6330 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6331 {
6332 /* Cases 6, 7. */
6333 inst.operands[i].reg = val;
6334 inst.operands[i].isreg = 1;
6335 inst.operands[i++].present = 1;
5f4273c7 6336
5287ad62 6337 if (skip_past_comma (&ptr) == FAIL)
477330fc 6338 goto wanted_comma;
5f4273c7 6339
dcbf9037 6340 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6341 {
6342 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6343 inst.operands[i].reg = val;
6344 inst.operands[i].isscalar = 1;
6345 inst.operands[i].present = 1;
6346 inst.operands[i].vectype = optype;
6347 }
dcbf9037 6348 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6349 {
6350 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6351 inst.operands[i].reg = val;
6352 inst.operands[i].isreg = 1;
6353 inst.operands[i++].present = 1;
6354
6355 if (skip_past_comma (&ptr) == FAIL)
6356 goto wanted_comma;
6357
6358 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6359 == FAIL)
6360 {
6361 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6362 return FAIL;
6363 }
6364
6365 inst.operands[i].reg = val;
6366 inst.operands[i].isreg = 1;
6367 inst.operands[i].isvec = 1;
6368 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6369 inst.operands[i].vectype = optype;
6370 inst.operands[i].present = 1;
6371
6372 if (rtype == REG_TYPE_VFS)
6373 {
6374 /* Case 14. */
6375 i++;
6376 if (skip_past_comma (&ptr) == FAIL)
6377 goto wanted_comma;
6378 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6379 &optype)) == FAIL)
6380 {
6381 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6382 return FAIL;
6383 }
6384 inst.operands[i].reg = val;
6385 inst.operands[i].isreg = 1;
6386 inst.operands[i].isvec = 1;
6387 inst.operands[i].issingle = 1;
6388 inst.operands[i].vectype = optype;
6389 inst.operands[i].present = 1;
6390 }
6391 }
037e8744 6392 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6393 != FAIL)
6394 {
6395 /* Case 13. */
6396 inst.operands[i].reg = val;
6397 inst.operands[i].isreg = 1;
6398 inst.operands[i].isvec = 1;
6399 inst.operands[i].issingle = 1;
6400 inst.operands[i].vectype = optype;
6401 inst.operands[i].present = 1;
6402 }
5287ad62
JB
6403 }
6404 else
6405 {
dcbf9037 6406 first_error (_("parse error"));
5287ad62
JB
6407 return FAIL;
6408 }
6409
6410 /* Successfully parsed the operands. Update args. */
6411 *which_operand = i;
6412 *str = ptr;
6413 return SUCCESS;
6414
5f4273c7 6415 wanted_comma:
dcbf9037 6416 first_error (_("expected comma"));
5287ad62 6417 return FAIL;
5f4273c7
NC
6418
6419 wanted_arm:
dcbf9037 6420 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6421 return FAIL;
5287ad62
JB
6422}
6423
5be8be5d
DG
6424/* Use this macro when the operand constraints are different
6425 for ARM and THUMB (e.g. ldrd). */
6426#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6427 ((arm_operand) | ((thumb_operand) << 16))
6428
c19d1205
ZW
6429/* Matcher codes for parse_operands. */
6430enum operand_parse_code
6431{
6432 OP_stop, /* end of line */
6433
6434 OP_RR, /* ARM register */
6435 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6436 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6437 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6438 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6439 optional trailing ! */
c19d1205
ZW
6440 OP_RRw, /* ARM register, not r15, optional trailing ! */
6441 OP_RCP, /* Coprocessor number */
6442 OP_RCN, /* Coprocessor register */
6443 OP_RF, /* FPA register */
6444 OP_RVS, /* VFP single precision register */
5287ad62
JB
6445 OP_RVD, /* VFP double precision register (0..15) */
6446 OP_RND, /* Neon double precision register (0..31) */
6447 OP_RNQ, /* Neon quad precision register */
037e8744 6448 OP_RVSD, /* VFP single or double precision register */
5287ad62 6449 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6450 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6451 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6452 OP_RVC, /* VFP control register */
6453 OP_RMF, /* Maverick F register */
6454 OP_RMD, /* Maverick D register */
6455 OP_RMFX, /* Maverick FX register */
6456 OP_RMDX, /* Maverick DX register */
6457 OP_RMAX, /* Maverick AX register */
6458 OP_RMDS, /* Maverick DSPSC register */
6459 OP_RIWR, /* iWMMXt wR register */
6460 OP_RIWC, /* iWMMXt wC register */
6461 OP_RIWG, /* iWMMXt wCG register */
6462 OP_RXA, /* XScale accumulator register */
6463
6464 OP_REGLST, /* ARM register list */
6465 OP_VRSLST, /* VFP single-precision register list */
6466 OP_VRDLST, /* VFP double-precision register list */
037e8744 6467 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6468 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6469 OP_NSTRLST, /* Neon element/structure list */
6470
5287ad62 6471 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6472 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6473 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6474 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6475 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6476 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6477 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6478 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6479 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6480 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6481 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6482
6483 OP_I0, /* immediate zero */
c19d1205
ZW
6484 OP_I7, /* immediate value 0 .. 7 */
6485 OP_I15, /* 0 .. 15 */
6486 OP_I16, /* 1 .. 16 */
5287ad62 6487 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6488 OP_I31, /* 0 .. 31 */
6489 OP_I31w, /* 0 .. 31, optional trailing ! */
6490 OP_I32, /* 1 .. 32 */
5287ad62
JB
6491 OP_I32z, /* 0 .. 32 */
6492 OP_I63, /* 0 .. 63 */
c19d1205 6493 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6494 OP_I64, /* 1 .. 64 */
6495 OP_I64z, /* 0 .. 64 */
c19d1205 6496 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6497
6498 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6499 OP_I7b, /* 0 .. 7 */
6500 OP_I15b, /* 0 .. 15 */
6501 OP_I31b, /* 0 .. 31 */
6502
6503 OP_SH, /* shifter operand */
4962c51a 6504 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6505 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6506 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6507 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6508 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6509 OP_EXP, /* arbitrary expression */
6510 OP_EXPi, /* same, with optional immediate prefix */
6511 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6512 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6513
6514 OP_CPSF, /* CPS flags */
6515 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6516 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6517 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6518 OP_COND, /* conditional code */
92e90b6e 6519 OP_TB, /* Table branch. */
c19d1205 6520
037e8744
JB
6521 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6522
c19d1205
ZW
6523 OP_RRnpc_I0, /* ARM register or literal 0 */
6524 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6525 OP_RR_EXi, /* ARM register or expression with imm prefix */
6526 OP_RF_IF, /* FPA register or immediate */
6527 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6528 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6529
6530 /* Optional operands. */
6531 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6532 OP_oI31b, /* 0 .. 31 */
5287ad62 6533 OP_oI32b, /* 1 .. 32 */
5f1af56b 6534 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6535 OP_oIffffb, /* 0 .. 65535 */
6536 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6537
6538 OP_oRR, /* ARM register */
6539 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6540 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6541 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6542 OP_oRND, /* Optional Neon double precision register */
6543 OP_oRNQ, /* Optional Neon quad precision register */
6544 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6545 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6546 OP_oSHll, /* LSL immediate */
6547 OP_oSHar, /* ASR immediate */
6548 OP_oSHllar, /* LSL or ASR immediate */
6549 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6550 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6551
5be8be5d
DG
6552 /* Some pre-defined mixed (ARM/THUMB) operands. */
6553 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6554 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6555 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6556
c19d1205
ZW
6557 OP_FIRST_OPTIONAL = OP_oI7b
6558};
a737bd4d 6559
c19d1205
ZW
6560/* Generic instruction operand parser. This does no encoding and no
6561 semantic validation; it merely squirrels values away in the inst
6562 structure. Returns SUCCESS or FAIL depending on whether the
6563 specified grammar matched. */
6564static int
5be8be5d 6565parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6566{
5be8be5d 6567 unsigned const int *upat = pattern;
c19d1205
ZW
6568 char *backtrack_pos = 0;
6569 const char *backtrack_error = 0;
99aad254 6570 int i, val = 0, backtrack_index = 0;
5287ad62 6571 enum arm_reg_type rtype;
4962c51a 6572 parse_operand_result result;
5be8be5d 6573 unsigned int op_parse_code;
c19d1205 6574
e07e6e58
NC
6575#define po_char_or_fail(chr) \
6576 do \
6577 { \
6578 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6579 goto bad_args; \
e07e6e58
NC
6580 } \
6581 while (0)
c19d1205 6582
e07e6e58
NC
6583#define po_reg_or_fail(regtype) \
6584 do \
dcbf9037 6585 { \
e07e6e58 6586 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6587 & inst.operands[i].vectype); \
e07e6e58 6588 if (val == FAIL) \
477330fc
RM
6589 { \
6590 first_error (_(reg_expected_msgs[regtype])); \
6591 goto failure; \
6592 } \
e07e6e58
NC
6593 inst.operands[i].reg = val; \
6594 inst.operands[i].isreg = 1; \
6595 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6596 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6597 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6598 || rtype == REG_TYPE_VFD \
6599 || rtype == REG_TYPE_NQ); \
dcbf9037 6600 } \
e07e6e58
NC
6601 while (0)
6602
6603#define po_reg_or_goto(regtype, label) \
6604 do \
6605 { \
6606 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6607 & inst.operands[i].vectype); \
6608 if (val == FAIL) \
6609 goto label; \
dcbf9037 6610 \
e07e6e58
NC
6611 inst.operands[i].reg = val; \
6612 inst.operands[i].isreg = 1; \
6613 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6614 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6615 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6616 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6617 || rtype == REG_TYPE_NQ); \
6618 } \
6619 while (0)
6620
6621#define po_imm_or_fail(min, max, popt) \
6622 do \
6623 { \
6624 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6625 goto failure; \
6626 inst.operands[i].imm = val; \
6627 } \
6628 while (0)
6629
6630#define po_scalar_or_goto(elsz, label) \
6631 do \
6632 { \
6633 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6634 if (val == FAIL) \
6635 goto label; \
6636 inst.operands[i].reg = val; \
6637 inst.operands[i].isscalar = 1; \
6638 } \
6639 while (0)
6640
6641#define po_misc_or_fail(expr) \
6642 do \
6643 { \
6644 if (expr) \
6645 goto failure; \
6646 } \
6647 while (0)
6648
6649#define po_misc_or_fail_no_backtrack(expr) \
6650 do \
6651 { \
6652 result = expr; \
6653 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6654 backtrack_pos = 0; \
6655 if (result != PARSE_OPERAND_SUCCESS) \
6656 goto failure; \
6657 } \
6658 while (0)
4962c51a 6659
52e7f43d
RE
6660#define po_barrier_or_imm(str) \
6661 do \
6662 { \
6663 val = parse_barrier (&str); \
ccb84d65
JB
6664 if (val == FAIL && ! ISALPHA (*str)) \
6665 goto immediate; \
6666 if (val == FAIL \
6667 /* ISB can only take SY as an option. */ \
6668 || ((inst.instruction & 0xf0) == 0x60 \
6669 && val != 0xf)) \
52e7f43d 6670 { \
ccb84d65
JB
6671 inst.error = _("invalid barrier type"); \
6672 backtrack_pos = 0; \
6673 goto failure; \
52e7f43d
RE
6674 } \
6675 } \
6676 while (0)
6677
c19d1205
ZW
6678 skip_whitespace (str);
6679
6680 for (i = 0; upat[i] != OP_stop; i++)
6681 {
5be8be5d
DG
6682 op_parse_code = upat[i];
6683 if (op_parse_code >= 1<<16)
6684 op_parse_code = thumb ? (op_parse_code >> 16)
6685 : (op_parse_code & ((1<<16)-1));
6686
6687 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6688 {
6689 /* Remember where we are in case we need to backtrack. */
9c2799c2 6690 gas_assert (!backtrack_pos);
c19d1205
ZW
6691 backtrack_pos = str;
6692 backtrack_error = inst.error;
6693 backtrack_index = i;
6694 }
6695
b6702015 6696 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6697 po_char_or_fail (',');
6698
5be8be5d 6699 switch (op_parse_code)
c19d1205
ZW
6700 {
6701 /* Registers */
6702 case OP_oRRnpc:
5be8be5d 6703 case OP_oRRnpcsp:
c19d1205 6704 case OP_RRnpc:
5be8be5d 6705 case OP_RRnpcsp:
c19d1205
ZW
6706 case OP_oRR:
6707 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6708 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6709 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6710 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6711 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6712 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6713 case OP_oRND:
5287ad62 6714 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6715 case OP_RVC:
6716 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6717 break;
6718 /* Also accept generic coprocessor regs for unknown registers. */
6719 coproc_reg:
6720 po_reg_or_fail (REG_TYPE_CN);
6721 break;
c19d1205
ZW
6722 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6723 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6724 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6725 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6726 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6727 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6728 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6729 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6730 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6731 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6732 case OP_oRNQ:
5287ad62 6733 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6734 case OP_oRNDQ:
5287ad62 6735 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6736 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6737 case OP_oRNSDQ:
6738 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6739
6740 /* Neon scalar. Using an element size of 8 means that some invalid
6741 scalars are accepted here, so deal with those in later code. */
6742 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6743
6744 case OP_RNDQ_I0:
6745 {
6746 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6747 break;
6748 try_imm0:
6749 po_imm_or_fail (0, 0, TRUE);
6750 }
6751 break;
6752
6753 case OP_RVSD_I0:
6754 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6755 break;
6756
aacf0b33
KT
6757 case OP_RSVD_FI0:
6758 {
6759 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6760 break;
6761 try_ifimm0:
6762 if (parse_ifimm_zero (&str))
6763 inst.operands[i].imm = 0;
6764 else
6765 {
6766 inst.error
6767 = _("only floating point zero is allowed as immediate value");
6768 goto failure;
6769 }
6770 }
6771 break;
6772
477330fc
RM
6773 case OP_RR_RNSC:
6774 {
6775 po_scalar_or_goto (8, try_rr);
6776 break;
6777 try_rr:
6778 po_reg_or_fail (REG_TYPE_RN);
6779 }
6780 break;
6781
6782 case OP_RNSDQ_RNSC:
6783 {
6784 po_scalar_or_goto (8, try_nsdq);
6785 break;
6786 try_nsdq:
6787 po_reg_or_fail (REG_TYPE_NSDQ);
6788 }
6789 break;
6790
6791 case OP_RNDQ_RNSC:
6792 {
6793 po_scalar_or_goto (8, try_ndq);
6794 break;
6795 try_ndq:
6796 po_reg_or_fail (REG_TYPE_NDQ);
6797 }
6798 break;
6799
6800 case OP_RND_RNSC:
6801 {
6802 po_scalar_or_goto (8, try_vfd);
6803 break;
6804 try_vfd:
6805 po_reg_or_fail (REG_TYPE_VFD);
6806 }
6807 break;
6808
6809 case OP_VMOV:
6810 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6811 not careful then bad things might happen. */
6812 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6813 break;
6814
6815 case OP_RNDQ_Ibig:
6816 {
6817 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6818 break;
6819 try_immbig:
6820 /* There's a possibility of getting a 64-bit immediate here, so
6821 we need special handling. */
8335d6aa
JW
6822 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6823 == FAIL)
477330fc
RM
6824 {
6825 inst.error = _("immediate value is out of range");
6826 goto failure;
6827 }
6828 }
6829 break;
6830
6831 case OP_RNDQ_I63b:
6832 {
6833 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6834 break;
6835 try_shimm:
6836 po_imm_or_fail (0, 63, TRUE);
6837 }
6838 break;
c19d1205
ZW
6839
6840 case OP_RRnpcb:
6841 po_char_or_fail ('[');
6842 po_reg_or_fail (REG_TYPE_RN);
6843 po_char_or_fail (']');
6844 break;
a737bd4d 6845
55881a11 6846 case OP_RRnpctw:
c19d1205 6847 case OP_RRw:
b6702015 6848 case OP_oRRw:
c19d1205
ZW
6849 po_reg_or_fail (REG_TYPE_RN);
6850 if (skip_past_char (&str, '!') == SUCCESS)
6851 inst.operands[i].writeback = 1;
6852 break;
6853
6854 /* Immediates */
6855 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6856 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6857 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6858 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6859 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6860 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6861 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6862 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6863 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6864 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6865 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6866 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6867
6868 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6869 case OP_oI7b:
6870 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6871 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6872 case OP_oI31b:
6873 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6874 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6875 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6876 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6877
6878 /* Immediate variants */
6879 case OP_oI255c:
6880 po_char_or_fail ('{');
6881 po_imm_or_fail (0, 255, TRUE);
6882 po_char_or_fail ('}');
6883 break;
6884
6885 case OP_I31w:
6886 /* The expression parser chokes on a trailing !, so we have
6887 to find it first and zap it. */
6888 {
6889 char *s = str;
6890 while (*s && *s != ',')
6891 s++;
6892 if (s[-1] == '!')
6893 {
6894 s[-1] = '\0';
6895 inst.operands[i].writeback = 1;
6896 }
6897 po_imm_or_fail (0, 31, TRUE);
6898 if (str == s - 1)
6899 str = s;
6900 }
6901 break;
6902
6903 /* Expressions */
6904 case OP_EXPi: EXPi:
6905 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6906 GE_OPT_PREFIX));
6907 break;
6908
6909 case OP_EXP:
6910 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6911 GE_NO_PREFIX));
6912 break;
6913
6914 case OP_EXPr: EXPr:
6915 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6916 GE_NO_PREFIX));
6917 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6918 {
c19d1205
ZW
6919 val = parse_reloc (&str);
6920 if (val == -1)
6921 {
6922 inst.error = _("unrecognized relocation suffix");
6923 goto failure;
6924 }
6925 else if (val != BFD_RELOC_UNUSED)
6926 {
6927 inst.operands[i].imm = val;
6928 inst.operands[i].hasreloc = 1;
6929 }
a737bd4d 6930 }
c19d1205 6931 break;
a737bd4d 6932
b6895b4f
PB
6933 /* Operand for MOVW or MOVT. */
6934 case OP_HALF:
6935 po_misc_or_fail (parse_half (&str));
6936 break;
6937
e07e6e58 6938 /* Register or expression. */
c19d1205
ZW
6939 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6940 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6941
e07e6e58 6942 /* Register or immediate. */
c19d1205
ZW
6943 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6944 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6945
c19d1205
ZW
6946 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6947 IF:
6948 if (!is_immediate_prefix (*str))
6949 goto bad_args;
6950 str++;
6951 val = parse_fpa_immediate (&str);
6952 if (val == FAIL)
6953 goto failure;
6954 /* FPA immediates are encoded as registers 8-15.
6955 parse_fpa_immediate has already applied the offset. */
6956 inst.operands[i].reg = val;
6957 inst.operands[i].isreg = 1;
6958 break;
09d92015 6959
2d447fca
JM
6960 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6961 I32z: po_imm_or_fail (0, 32, FALSE); break;
6962
e07e6e58 6963 /* Two kinds of register. */
c19d1205
ZW
6964 case OP_RIWR_RIWC:
6965 {
6966 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6967 if (!rege
6968 || (rege->type != REG_TYPE_MMXWR
6969 && rege->type != REG_TYPE_MMXWC
6970 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6971 {
6972 inst.error = _("iWMMXt data or control register expected");
6973 goto failure;
6974 }
6975 inst.operands[i].reg = rege->number;
6976 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6977 }
6978 break;
09d92015 6979
41adaa5c
JM
6980 case OP_RIWC_RIWG:
6981 {
6982 struct reg_entry *rege = arm_reg_parse_multi (&str);
6983 if (!rege
6984 || (rege->type != REG_TYPE_MMXWC
6985 && rege->type != REG_TYPE_MMXWCG))
6986 {
6987 inst.error = _("iWMMXt control register expected");
6988 goto failure;
6989 }
6990 inst.operands[i].reg = rege->number;
6991 inst.operands[i].isreg = 1;
6992 }
6993 break;
6994
c19d1205
ZW
6995 /* Misc */
6996 case OP_CPSF: val = parse_cps_flags (&str); break;
6997 case OP_ENDI: val = parse_endian_specifier (&str); break;
6998 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6999 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7000 case OP_oBARRIER_I15:
7001 po_barrier_or_imm (str); break;
7002 immediate:
7003 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7004 goto failure;
52e7f43d 7005 break;
c19d1205 7006
fa94de6b 7007 case OP_wPSR:
d2cd1205 7008 case OP_rPSR:
90ec0d68
MGD
7009 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7010 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7011 {
7012 inst.error = _("Banked registers are not available with this "
7013 "architecture.");
7014 goto failure;
7015 }
7016 break;
d2cd1205
JB
7017 try_psr:
7018 val = parse_psr (&str, op_parse_code == OP_wPSR);
7019 break;
037e8744 7020
477330fc
RM
7021 case OP_APSR_RR:
7022 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7023 break;
7024 try_apsr:
7025 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7026 instruction). */
7027 if (strncasecmp (str, "APSR_", 5) == 0)
7028 {
7029 unsigned found = 0;
7030 str += 5;
7031 while (found < 15)
7032 switch (*str++)
7033 {
7034 case 'c': found = (found & 1) ? 16 : found | 1; break;
7035 case 'n': found = (found & 2) ? 16 : found | 2; break;
7036 case 'z': found = (found & 4) ? 16 : found | 4; break;
7037 case 'v': found = (found & 8) ? 16 : found | 8; break;
7038 default: found = 16;
7039 }
7040 if (found != 15)
7041 goto failure;
7042 inst.operands[i].isvec = 1;
f7c21dc7
NC
7043 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7044 inst.operands[i].reg = REG_PC;
477330fc
RM
7045 }
7046 else
7047 goto failure;
7048 break;
037e8744 7049
92e90b6e
PB
7050 case OP_TB:
7051 po_misc_or_fail (parse_tb (&str));
7052 break;
7053
e07e6e58 7054 /* Register lists. */
c19d1205
ZW
7055 case OP_REGLST:
7056 val = parse_reg_list (&str);
7057 if (*str == '^')
7058 {
5e0d7f77 7059 inst.operands[i].writeback = 1;
c19d1205
ZW
7060 str++;
7061 }
7062 break;
09d92015 7063
c19d1205 7064 case OP_VRSLST:
5287ad62 7065 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7066 break;
09d92015 7067
c19d1205 7068 case OP_VRDLST:
5287ad62 7069 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7070 break;
a737bd4d 7071
477330fc
RM
7072 case OP_VRSDLST:
7073 /* Allow Q registers too. */
7074 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7075 REGLIST_NEON_D);
7076 if (val == FAIL)
7077 {
7078 inst.error = NULL;
7079 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7080 REGLIST_VFP_S);
7081 inst.operands[i].issingle = 1;
7082 }
7083 break;
7084
7085 case OP_NRDLST:
7086 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7087 REGLIST_NEON_D);
7088 break;
5287ad62
JB
7089
7090 case OP_NSTRLST:
477330fc
RM
7091 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7092 &inst.operands[i].vectype);
7093 break;
5287ad62 7094
c19d1205
ZW
7095 /* Addressing modes */
7096 case OP_ADDR:
7097 po_misc_or_fail (parse_address (&str, i));
7098 break;
09d92015 7099
4962c51a
MS
7100 case OP_ADDRGLDR:
7101 po_misc_or_fail_no_backtrack (
477330fc 7102 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7103 break;
7104
7105 case OP_ADDRGLDRS:
7106 po_misc_or_fail_no_backtrack (
477330fc 7107 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7108 break;
7109
7110 case OP_ADDRGLDC:
7111 po_misc_or_fail_no_backtrack (
477330fc 7112 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7113 break;
7114
c19d1205
ZW
7115 case OP_SH:
7116 po_misc_or_fail (parse_shifter_operand (&str, i));
7117 break;
09d92015 7118
4962c51a
MS
7119 case OP_SHG:
7120 po_misc_or_fail_no_backtrack (
477330fc 7121 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7122 break;
7123
c19d1205
ZW
7124 case OP_oSHll:
7125 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7126 break;
09d92015 7127
c19d1205
ZW
7128 case OP_oSHar:
7129 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7130 break;
09d92015 7131
c19d1205
ZW
7132 case OP_oSHllar:
7133 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7134 break;
09d92015 7135
c19d1205 7136 default:
5be8be5d 7137 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7138 }
09d92015 7139
c19d1205
ZW
7140 /* Various value-based sanity checks and shared operations. We
7141 do not signal immediate failures for the register constraints;
7142 this allows a syntax error to take precedence. */
5be8be5d 7143 switch (op_parse_code)
c19d1205
ZW
7144 {
7145 case OP_oRRnpc:
7146 case OP_RRnpc:
7147 case OP_RRnpcb:
7148 case OP_RRw:
b6702015 7149 case OP_oRRw:
c19d1205
ZW
7150 case OP_RRnpc_I0:
7151 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7152 inst.error = BAD_PC;
7153 break;
09d92015 7154
5be8be5d
DG
7155 case OP_oRRnpcsp:
7156 case OP_RRnpcsp:
7157 if (inst.operands[i].isreg)
7158 {
7159 if (inst.operands[i].reg == REG_PC)
7160 inst.error = BAD_PC;
7161 else if (inst.operands[i].reg == REG_SP)
7162 inst.error = BAD_SP;
7163 }
7164 break;
7165
55881a11 7166 case OP_RRnpctw:
fa94de6b
RM
7167 if (inst.operands[i].isreg
7168 && inst.operands[i].reg == REG_PC
55881a11
MGD
7169 && (inst.operands[i].writeback || thumb))
7170 inst.error = BAD_PC;
7171 break;
7172
c19d1205
ZW
7173 case OP_CPSF:
7174 case OP_ENDI:
7175 case OP_oROR:
d2cd1205
JB
7176 case OP_wPSR:
7177 case OP_rPSR:
c19d1205 7178 case OP_COND:
52e7f43d 7179 case OP_oBARRIER_I15:
c19d1205
ZW
7180 case OP_REGLST:
7181 case OP_VRSLST:
7182 case OP_VRDLST:
477330fc
RM
7183 case OP_VRSDLST:
7184 case OP_NRDLST:
7185 case OP_NSTRLST:
c19d1205
ZW
7186 if (val == FAIL)
7187 goto failure;
7188 inst.operands[i].imm = val;
7189 break;
a737bd4d 7190
c19d1205
ZW
7191 default:
7192 break;
7193 }
09d92015 7194
c19d1205
ZW
7195 /* If we get here, this operand was successfully parsed. */
7196 inst.operands[i].present = 1;
7197 continue;
09d92015 7198
c19d1205 7199 bad_args:
09d92015 7200 inst.error = BAD_ARGS;
c19d1205
ZW
7201
7202 failure:
7203 if (!backtrack_pos)
d252fdde
PB
7204 {
7205 /* The parse routine should already have set inst.error, but set a
5f4273c7 7206 default here just in case. */
d252fdde
PB
7207 if (!inst.error)
7208 inst.error = _("syntax error");
7209 return FAIL;
7210 }
c19d1205
ZW
7211
7212 /* Do not backtrack over a trailing optional argument that
7213 absorbed some text. We will only fail again, with the
7214 'garbage following instruction' error message, which is
7215 probably less helpful than the current one. */
7216 if (backtrack_index == i && backtrack_pos != str
7217 && upat[i+1] == OP_stop)
d252fdde
PB
7218 {
7219 if (!inst.error)
7220 inst.error = _("syntax error");
7221 return FAIL;
7222 }
c19d1205
ZW
7223
7224 /* Try again, skipping the optional argument at backtrack_pos. */
7225 str = backtrack_pos;
7226 inst.error = backtrack_error;
7227 inst.operands[backtrack_index].present = 0;
7228 i = backtrack_index;
7229 backtrack_pos = 0;
09d92015 7230 }
09d92015 7231
c19d1205
ZW
7232 /* Check that we have parsed all the arguments. */
7233 if (*str != '\0' && !inst.error)
7234 inst.error = _("garbage following instruction");
09d92015 7235
c19d1205 7236 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7237}
7238
c19d1205
ZW
7239#undef po_char_or_fail
7240#undef po_reg_or_fail
7241#undef po_reg_or_goto
7242#undef po_imm_or_fail
5287ad62 7243#undef po_scalar_or_fail
52e7f43d 7244#undef po_barrier_or_imm
e07e6e58 7245
c19d1205 7246/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7247#define constraint(expr, err) \
7248 do \
c19d1205 7249 { \
e07e6e58
NC
7250 if (expr) \
7251 { \
7252 inst.error = err; \
7253 return; \
7254 } \
c19d1205 7255 } \
e07e6e58 7256 while (0)
c19d1205 7257
fdfde340
JM
7258/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7259 instructions are unpredictable if these registers are used. This
7260 is the BadReg predicate in ARM's Thumb-2 documentation. */
7261#define reject_bad_reg(reg) \
7262 do \
7263 if (reg == REG_SP || reg == REG_PC) \
7264 { \
7265 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7266 return; \
7267 } \
7268 while (0)
7269
94206790
MM
7270/* If REG is R13 (the stack pointer), warn that its use is
7271 deprecated. */
7272#define warn_deprecated_sp(reg) \
7273 do \
7274 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7275 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7276 while (0)
7277
c19d1205
ZW
7278/* Functions for operand encoding. ARM, then Thumb. */
7279
d840c081 7280#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7281
9db2f6b4
RL
7282/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7283
7284 The only binary encoding difference is the Coprocessor number. Coprocessor
7285 9 is used for half-precision calculations or conversions. The format of the
7286 instruction is the same as the equivalent Coprocessor 10 instuction that
7287 exists for Single-Precision operation. */
7288
7289static void
7290do_scalar_fp16_v82_encode (void)
7291{
7292 if (inst.cond != COND_ALWAYS)
7293 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7294 " the behaviour is UNPREDICTABLE"));
7295 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7296 _(BAD_FP16));
7297
7298 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7299 mark_feature_used (&arm_ext_fp16);
7300}
7301
c19d1205
ZW
7302/* If VAL can be encoded in the immediate field of an ARM instruction,
7303 return the encoded form. Otherwise, return FAIL. */
7304
7305static unsigned int
7306encode_arm_immediate (unsigned int val)
09d92015 7307{
c19d1205
ZW
7308 unsigned int a, i;
7309
4f1d6205
L
7310 if (val <= 0xff)
7311 return val;
7312
7313 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7314 if ((a = rotate_left (val, i)) <= 0xff)
7315 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7316
7317 return FAIL;
09d92015
MM
7318}
7319
c19d1205
ZW
7320/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7321 return the encoded form. Otherwise, return FAIL. */
7322static unsigned int
7323encode_thumb32_immediate (unsigned int val)
09d92015 7324{
c19d1205 7325 unsigned int a, i;
09d92015 7326
9c3c69f2 7327 if (val <= 0xff)
c19d1205 7328 return val;
a737bd4d 7329
9c3c69f2 7330 for (i = 1; i <= 24; i++)
09d92015 7331 {
9c3c69f2
PB
7332 a = val >> i;
7333 if ((val & ~(0xff << i)) == 0)
7334 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7335 }
a737bd4d 7336
c19d1205
ZW
7337 a = val & 0xff;
7338 if (val == ((a << 16) | a))
7339 return 0x100 | a;
7340 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7341 return 0x300 | a;
09d92015 7342
c19d1205
ZW
7343 a = val & 0xff00;
7344 if (val == ((a << 16) | a))
7345 return 0x200 | (a >> 8);
a737bd4d 7346
c19d1205 7347 return FAIL;
09d92015 7348}
5287ad62 7349/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7350
7351static void
5287ad62
JB
7352encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7353{
7354 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7355 && reg > 15)
7356 {
b1cc4aeb 7357 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7358 {
7359 if (thumb_mode)
7360 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7361 fpu_vfp_ext_d32);
7362 else
7363 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7364 fpu_vfp_ext_d32);
7365 }
5287ad62 7366 else
477330fc
RM
7367 {
7368 first_error (_("D register out of range for selected VFP version"));
7369 return;
7370 }
5287ad62
JB
7371 }
7372
c19d1205 7373 switch (pos)
09d92015 7374 {
c19d1205
ZW
7375 case VFP_REG_Sd:
7376 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7377 break;
7378
7379 case VFP_REG_Sn:
7380 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7381 break;
7382
7383 case VFP_REG_Sm:
7384 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7385 break;
7386
5287ad62
JB
7387 case VFP_REG_Dd:
7388 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7389 break;
5f4273c7 7390
5287ad62
JB
7391 case VFP_REG_Dn:
7392 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7393 break;
5f4273c7 7394
5287ad62
JB
7395 case VFP_REG_Dm:
7396 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7397 break;
7398
c19d1205
ZW
7399 default:
7400 abort ();
09d92015 7401 }
09d92015
MM
7402}
7403
c19d1205 7404/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7405 if any, is handled by md_apply_fix. */
09d92015 7406static void
c19d1205 7407encode_arm_shift (int i)
09d92015 7408{
c19d1205
ZW
7409 if (inst.operands[i].shift_kind == SHIFT_RRX)
7410 inst.instruction |= SHIFT_ROR << 5;
7411 else
09d92015 7412 {
c19d1205
ZW
7413 inst.instruction |= inst.operands[i].shift_kind << 5;
7414 if (inst.operands[i].immisreg)
7415 {
7416 inst.instruction |= SHIFT_BY_REG;
7417 inst.instruction |= inst.operands[i].imm << 8;
7418 }
7419 else
7420 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7421 }
c19d1205 7422}
09d92015 7423
c19d1205
ZW
7424static void
7425encode_arm_shifter_operand (int i)
7426{
7427 if (inst.operands[i].isreg)
09d92015 7428 {
c19d1205
ZW
7429 inst.instruction |= inst.operands[i].reg;
7430 encode_arm_shift (i);
09d92015 7431 }
c19d1205 7432 else
a415b1cd
JB
7433 {
7434 inst.instruction |= INST_IMMEDIATE;
7435 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7436 inst.instruction |= inst.operands[i].imm;
7437 }
09d92015
MM
7438}
7439
c19d1205 7440/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7441static void
c19d1205 7442encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7443{
2b2f5df9
NC
7444 /* PR 14260:
7445 Generate an error if the operand is not a register. */
7446 constraint (!inst.operands[i].isreg,
7447 _("Instruction does not support =N addresses"));
7448
c19d1205 7449 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7450
c19d1205 7451 if (inst.operands[i].preind)
09d92015 7452 {
c19d1205
ZW
7453 if (is_t)
7454 {
7455 inst.error = _("instruction does not accept preindexed addressing");
7456 return;
7457 }
7458 inst.instruction |= PRE_INDEX;
7459 if (inst.operands[i].writeback)
7460 inst.instruction |= WRITE_BACK;
09d92015 7461
c19d1205
ZW
7462 }
7463 else if (inst.operands[i].postind)
7464 {
9c2799c2 7465 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7466 if (is_t)
7467 inst.instruction |= WRITE_BACK;
7468 }
7469 else /* unindexed - only for coprocessor */
09d92015 7470 {
c19d1205 7471 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7472 return;
7473 }
7474
c19d1205
ZW
7475 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7476 && (((inst.instruction & 0x000f0000) >> 16)
7477 == ((inst.instruction & 0x0000f000) >> 12)))
7478 as_warn ((inst.instruction & LOAD_BIT)
7479 ? _("destination register same as write-back base")
7480 : _("source register same as write-back base"));
09d92015
MM
7481}
7482
c19d1205
ZW
7483/* inst.operands[i] was set up by parse_address. Encode it into an
7484 ARM-format mode 2 load or store instruction. If is_t is true,
7485 reject forms that cannot be used with a T instruction (i.e. not
7486 post-indexed). */
a737bd4d 7487static void
c19d1205 7488encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7489{
5be8be5d
DG
7490 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7491
c19d1205 7492 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7493
c19d1205 7494 if (inst.operands[i].immisreg)
09d92015 7495 {
5be8be5d
DG
7496 constraint ((inst.operands[i].imm == REG_PC
7497 || (is_pc && inst.operands[i].writeback)),
7498 BAD_PC_ADDRESSING);
c19d1205
ZW
7499 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7500 inst.instruction |= inst.operands[i].imm;
7501 if (!inst.operands[i].negative)
7502 inst.instruction |= INDEX_UP;
7503 if (inst.operands[i].shifted)
7504 {
7505 if (inst.operands[i].shift_kind == SHIFT_RRX)
7506 inst.instruction |= SHIFT_ROR << 5;
7507 else
7508 {
7509 inst.instruction |= inst.operands[i].shift_kind << 5;
7510 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7511 }
7512 }
09d92015 7513 }
c19d1205 7514 else /* immediate offset in inst.reloc */
09d92015 7515 {
5be8be5d
DG
7516 if (is_pc && !inst.reloc.pc_rel)
7517 {
7518 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7519
7520 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7521 cannot use PC in addressing.
7522 PC cannot be used in writeback addressing, either. */
7523 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7524 BAD_PC_ADDRESSING);
23a10334 7525
dc5ec521 7526 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7527 if (warn_on_deprecated
7528 && !is_load
7529 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7530 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7531 }
7532
c19d1205 7533 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7534 {
7535 /* Prefer + for zero encoded value. */
7536 if (!inst.operands[i].negative)
7537 inst.instruction |= INDEX_UP;
7538 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7539 }
09d92015 7540 }
09d92015
MM
7541}
7542
c19d1205
ZW
7543/* inst.operands[i] was set up by parse_address. Encode it into an
7544 ARM-format mode 3 load or store instruction. Reject forms that
7545 cannot be used with such instructions. If is_t is true, reject
7546 forms that cannot be used with a T instruction (i.e. not
7547 post-indexed). */
7548static void
7549encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7550{
c19d1205 7551 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7552 {
c19d1205
ZW
7553 inst.error = _("instruction does not accept scaled register index");
7554 return;
09d92015 7555 }
a737bd4d 7556
c19d1205 7557 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7558
c19d1205
ZW
7559 if (inst.operands[i].immisreg)
7560 {
5be8be5d 7561 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7562 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7563 BAD_PC_ADDRESSING);
eb9f3f00
JB
7564 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7565 BAD_PC_WRITEBACK);
c19d1205
ZW
7566 inst.instruction |= inst.operands[i].imm;
7567 if (!inst.operands[i].negative)
7568 inst.instruction |= INDEX_UP;
7569 }
7570 else /* immediate offset in inst.reloc */
7571 {
5be8be5d
DG
7572 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7573 && inst.operands[i].writeback),
7574 BAD_PC_WRITEBACK);
c19d1205
ZW
7575 inst.instruction |= HWOFFSET_IMM;
7576 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7577 {
7578 /* Prefer + for zero encoded value. */
7579 if (!inst.operands[i].negative)
7580 inst.instruction |= INDEX_UP;
7581
7582 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7583 }
c19d1205 7584 }
a737bd4d
NC
7585}
7586
8335d6aa
JW
7587/* Write immediate bits [7:0] to the following locations:
7588
7589 |28/24|23 19|18 16|15 4|3 0|
7590 | 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|
7591
7592 This function is used by VMOV/VMVN/VORR/VBIC. */
7593
7594static void
7595neon_write_immbits (unsigned immbits)
7596{
7597 inst.instruction |= immbits & 0xf;
7598 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7599 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7600}
7601
7602/* Invert low-order SIZE bits of XHI:XLO. */
7603
7604static void
7605neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7606{
7607 unsigned immlo = xlo ? *xlo : 0;
7608 unsigned immhi = xhi ? *xhi : 0;
7609
7610 switch (size)
7611 {
7612 case 8:
7613 immlo = (~immlo) & 0xff;
7614 break;
7615
7616 case 16:
7617 immlo = (~immlo) & 0xffff;
7618 break;
7619
7620 case 64:
7621 immhi = (~immhi) & 0xffffffff;
7622 /* fall through. */
7623
7624 case 32:
7625 immlo = (~immlo) & 0xffffffff;
7626 break;
7627
7628 default:
7629 abort ();
7630 }
7631
7632 if (xlo)
7633 *xlo = immlo;
7634
7635 if (xhi)
7636 *xhi = immhi;
7637}
7638
7639/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7640 A, B, C, D. */
09d92015 7641
c19d1205 7642static int
8335d6aa 7643neon_bits_same_in_bytes (unsigned imm)
09d92015 7644{
8335d6aa
JW
7645 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7646 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7647 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7648 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7649}
a737bd4d 7650
8335d6aa 7651/* For immediate of above form, return 0bABCD. */
09d92015 7652
8335d6aa
JW
7653static unsigned
7654neon_squash_bits (unsigned imm)
7655{
7656 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7657 | ((imm & 0x01000000) >> 21);
7658}
7659
7660/* Compress quarter-float representation to 0b...000 abcdefgh. */
7661
7662static unsigned
7663neon_qfloat_bits (unsigned imm)
7664{
7665 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7666}
7667
7668/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7669 the instruction. *OP is passed as the initial value of the op field, and
7670 may be set to a different value depending on the constant (i.e.
7671 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7672 MVN). If the immediate looks like a repeated pattern then also
7673 try smaller element sizes. */
7674
7675static int
7676neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7677 unsigned *immbits, int *op, int size,
7678 enum neon_el_type type)
7679{
7680 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7681 float. */
7682 if (type == NT_float && !float_p)
7683 return FAIL;
7684
7685 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7686 {
8335d6aa
JW
7687 if (size != 32 || *op == 1)
7688 return FAIL;
7689 *immbits = neon_qfloat_bits (immlo);
7690 return 0xf;
7691 }
7692
7693 if (size == 64)
7694 {
7695 if (neon_bits_same_in_bytes (immhi)
7696 && neon_bits_same_in_bytes (immlo))
c19d1205 7697 {
8335d6aa
JW
7698 if (*op == 1)
7699 return FAIL;
7700 *immbits = (neon_squash_bits (immhi) << 4)
7701 | neon_squash_bits (immlo);
7702 *op = 1;
7703 return 0xe;
c19d1205 7704 }
a737bd4d 7705
8335d6aa
JW
7706 if (immhi != immlo)
7707 return FAIL;
7708 }
a737bd4d 7709
8335d6aa 7710 if (size >= 32)
09d92015 7711 {
8335d6aa 7712 if (immlo == (immlo & 0x000000ff))
c19d1205 7713 {
8335d6aa
JW
7714 *immbits = immlo;
7715 return 0x0;
c19d1205 7716 }
8335d6aa 7717 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7718 {
8335d6aa
JW
7719 *immbits = immlo >> 8;
7720 return 0x2;
c19d1205 7721 }
8335d6aa
JW
7722 else if (immlo == (immlo & 0x00ff0000))
7723 {
7724 *immbits = immlo >> 16;
7725 return 0x4;
7726 }
7727 else if (immlo == (immlo & 0xff000000))
7728 {
7729 *immbits = immlo >> 24;
7730 return 0x6;
7731 }
7732 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7733 {
7734 *immbits = (immlo >> 8) & 0xff;
7735 return 0xc;
7736 }
7737 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7738 {
7739 *immbits = (immlo >> 16) & 0xff;
7740 return 0xd;
7741 }
7742
7743 if ((immlo & 0xffff) != (immlo >> 16))
7744 return FAIL;
7745 immlo &= 0xffff;
09d92015 7746 }
a737bd4d 7747
8335d6aa 7748 if (size >= 16)
4962c51a 7749 {
8335d6aa
JW
7750 if (immlo == (immlo & 0x000000ff))
7751 {
7752 *immbits = immlo;
7753 return 0x8;
7754 }
7755 else if (immlo == (immlo & 0x0000ff00))
7756 {
7757 *immbits = immlo >> 8;
7758 return 0xa;
7759 }
7760
7761 if ((immlo & 0xff) != (immlo >> 8))
7762 return FAIL;
7763 immlo &= 0xff;
4962c51a
MS
7764 }
7765
8335d6aa
JW
7766 if (immlo == (immlo & 0x000000ff))
7767 {
7768 /* Don't allow MVN with 8-bit immediate. */
7769 if (*op == 1)
7770 return FAIL;
7771 *immbits = immlo;
7772 return 0xe;
7773 }
26d97720 7774
8335d6aa 7775 return FAIL;
c19d1205 7776}
a737bd4d 7777
5fc177c8 7778#if defined BFD_HOST_64_BIT
ba592044
AM
7779/* Returns TRUE if double precision value V may be cast
7780 to single precision without loss of accuracy. */
7781
7782static bfd_boolean
5fc177c8 7783is_double_a_single (bfd_int64_t v)
ba592044 7784{
5fc177c8 7785 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7786 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7787
7788 return (exp == 0 || exp == 0x7FF
7789 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7790 && (mantissa & 0x1FFFFFFFl) == 0;
7791}
7792
3739860c 7793/* Returns a double precision value casted to single precision
ba592044
AM
7794 (ignoring the least significant bits in exponent and mantissa). */
7795
7796static int
5fc177c8 7797double_to_single (bfd_int64_t v)
ba592044
AM
7798{
7799 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7800 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7801 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7802
7803 if (exp == 0x7FF)
7804 exp = 0xFF;
7805 else
7806 {
7807 exp = exp - 1023 + 127;
7808 if (exp >= 0xFF)
7809 {
7810 /* Infinity. */
7811 exp = 0x7F;
7812 mantissa = 0;
7813 }
7814 else if (exp < 0)
7815 {
7816 /* No denormalized numbers. */
7817 exp = 0;
7818 mantissa = 0;
7819 }
7820 }
7821 mantissa >>= 29;
7822 return (sign << 31) | (exp << 23) | mantissa;
7823}
5fc177c8 7824#endif /* BFD_HOST_64_BIT */
ba592044 7825
8335d6aa
JW
7826enum lit_type
7827{
7828 CONST_THUMB,
7829 CONST_ARM,
7830 CONST_VEC
7831};
7832
ba592044
AM
7833static void do_vfp_nsyn_opcode (const char *);
7834
c19d1205
ZW
7835/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7836 Determine whether it can be performed with a move instruction; if
7837 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7838 return TRUE; if it can't, convert inst.instruction to a literal-pool
7839 load and return FALSE. If this is not a valid thing to do in the
7840 current context, set inst.error and return TRUE.
a737bd4d 7841
c19d1205
ZW
7842 inst.operands[i] describes the destination register. */
7843
c921be7d 7844static bfd_boolean
8335d6aa 7845move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7846{
53365c0d 7847 unsigned long tbit;
8335d6aa
JW
7848 bfd_boolean thumb_p = (t == CONST_THUMB);
7849 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7850
7851 if (thumb_p)
7852 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7853 else
7854 tbit = LOAD_BIT;
7855
7856 if ((inst.instruction & tbit) == 0)
09d92015 7857 {
c19d1205 7858 inst.error = _("invalid pseudo operation");
c921be7d 7859 return TRUE;
09d92015 7860 }
ba592044 7861
8335d6aa
JW
7862 if (inst.reloc.exp.X_op != O_constant
7863 && inst.reloc.exp.X_op != O_symbol
7864 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7865 {
7866 inst.error = _("constant expression expected");
c921be7d 7867 return TRUE;
09d92015 7868 }
ba592044
AM
7869
7870 if (inst.reloc.exp.X_op == O_constant
7871 || inst.reloc.exp.X_op == O_big)
8335d6aa 7872 {
5fc177c8
NC
7873#if defined BFD_HOST_64_BIT
7874 bfd_int64_t v;
7875#else
ba592044 7876 offsetT v;
5fc177c8 7877#endif
ba592044 7878 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7879 {
ba592044
AM
7880 LITTLENUM_TYPE w[X_PRECISION];
7881 LITTLENUM_TYPE * l;
7882
7883 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7884 {
ba592044
AM
7885 gen_to_words (w, X_PRECISION, E_PRECISION);
7886 l = w;
7887 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7888 }
ba592044
AM
7889 else
7890 l = generic_bignum;
3739860c 7891
5fc177c8
NC
7892#if defined BFD_HOST_64_BIT
7893 v =
7894 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7895 << LITTLENUM_NUMBER_OF_BITS)
7896 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7897 << LITTLENUM_NUMBER_OF_BITS)
7898 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7899 << LITTLENUM_NUMBER_OF_BITS)
7900 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7901#else
ba592044
AM
7902 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7903 | (l[0] & LITTLENUM_MASK);
5fc177c8 7904#endif
8335d6aa 7905 }
ba592044
AM
7906 else
7907 v = inst.reloc.exp.X_add_number;
7908
7909 if (!inst.operands[i].issingle)
8335d6aa 7910 {
12569877 7911 if (thumb_p)
8335d6aa 7912 {
2c32be70
CM
7913 /* This can be encoded only for a low register. */
7914 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7915 {
7916 /* This can be done with a mov(1) instruction. */
7917 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7918 inst.instruction |= v;
7919 return TRUE;
7920 }
12569877 7921
ff8646ee
TP
7922 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7923 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7924 {
fc289b0a
TP
7925 /* Check if on thumb2 it can be done with a mov.w, mvn or
7926 movw instruction. */
12569877
AM
7927 unsigned int newimm;
7928 bfd_boolean isNegated;
7929
7930 newimm = encode_thumb32_immediate (v);
7931 if (newimm != (unsigned int) FAIL)
7932 isNegated = FALSE;
7933 else
7934 {
582cfe03 7935 newimm = encode_thumb32_immediate (~v);
12569877
AM
7936 if (newimm != (unsigned int) FAIL)
7937 isNegated = TRUE;
7938 }
7939
fc289b0a
TP
7940 /* The number can be loaded with a mov.w or mvn
7941 instruction. */
ff8646ee
TP
7942 if (newimm != (unsigned int) FAIL
7943 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7944 {
fc289b0a 7945 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7946 | (inst.operands[i].reg << 8));
fc289b0a 7947 /* Change to MOVN. */
582cfe03 7948 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7949 inst.instruction |= (newimm & 0x800) << 15;
7950 inst.instruction |= (newimm & 0x700) << 4;
7951 inst.instruction |= (newimm & 0x0ff);
7952 return TRUE;
7953 }
fc289b0a 7954 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
7955 else if ((v & ~0xFFFF) == 0
7956 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 7957 {
582cfe03 7958 int imm = v & 0xFFFF;
12569877 7959
582cfe03 7960 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7961 inst.instruction |= (inst.operands[i].reg << 8);
7962 inst.instruction |= (imm & 0xf000) << 4;
7963 inst.instruction |= (imm & 0x0800) << 15;
7964 inst.instruction |= (imm & 0x0700) << 4;
7965 inst.instruction |= (imm & 0x00ff);
7966 return TRUE;
7967 }
7968 }
8335d6aa 7969 }
12569877 7970 else if (arm_p)
ba592044
AM
7971 {
7972 int value = encode_arm_immediate (v);
12569877 7973
ba592044
AM
7974 if (value != FAIL)
7975 {
7976 /* This can be done with a mov instruction. */
7977 inst.instruction &= LITERAL_MASK;
7978 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7979 inst.instruction |= value & 0xfff;
7980 return TRUE;
7981 }
8335d6aa 7982
ba592044
AM
7983 value = encode_arm_immediate (~ v);
7984 if (value != FAIL)
7985 {
7986 /* This can be done with a mvn instruction. */
7987 inst.instruction &= LITERAL_MASK;
7988 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7989 inst.instruction |= value & 0xfff;
7990 return TRUE;
7991 }
7992 }
7993 else if (t == CONST_VEC)
8335d6aa 7994 {
ba592044
AM
7995 int op = 0;
7996 unsigned immbits = 0;
7997 unsigned immlo = inst.operands[1].imm;
7998 unsigned immhi = inst.operands[1].regisimm
7999 ? inst.operands[1].reg
8000 : inst.reloc.exp.X_unsigned
8001 ? 0
8002 : ((bfd_int64_t)((int) immlo)) >> 32;
8003 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8004 &op, 64, NT_invtype);
8005
8006 if (cmode == FAIL)
8007 {
8008 neon_invert_size (&immlo, &immhi, 64);
8009 op = !op;
8010 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8011 &op, 64, NT_invtype);
8012 }
8013
8014 if (cmode != FAIL)
8015 {
8016 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8017 | (1 << 23)
8018 | (cmode << 8)
8019 | (op << 5)
8020 | (1 << 4);
8021
8022 /* Fill other bits in vmov encoding for both thumb and arm. */
8023 if (thumb_mode)
eff0bc54 8024 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8025 else
eff0bc54 8026 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8027 neon_write_immbits (immbits);
8028 return TRUE;
8029 }
8335d6aa
JW
8030 }
8031 }
8335d6aa 8032
ba592044
AM
8033 if (t == CONST_VEC)
8034 {
8035 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8036 if (inst.operands[i].issingle
8037 && is_quarter_float (inst.operands[1].imm)
8038 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8039 {
ba592044
AM
8040 inst.operands[1].imm =
8041 neon_qfloat_bits (v);
8042 do_vfp_nsyn_opcode ("fconsts");
8043 return TRUE;
8335d6aa 8044 }
5fc177c8
NC
8045
8046 /* If our host does not support a 64-bit type then we cannot perform
8047 the following optimization. This mean that there will be a
8048 discrepancy between the output produced by an assembler built for
8049 a 32-bit-only host and the output produced from a 64-bit host, but
8050 this cannot be helped. */
8051#if defined BFD_HOST_64_BIT
ba592044
AM
8052 else if (!inst.operands[1].issingle
8053 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8054 {
ba592044
AM
8055 if (is_double_a_single (v)
8056 && is_quarter_float (double_to_single (v)))
8057 {
8058 inst.operands[1].imm =
8059 neon_qfloat_bits (double_to_single (v));
8060 do_vfp_nsyn_opcode ("fconstd");
8061 return TRUE;
8062 }
8335d6aa 8063 }
5fc177c8 8064#endif
8335d6aa
JW
8065 }
8066 }
8067
8068 if (add_to_lit_pool ((!inst.operands[i].isvec
8069 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8070 return TRUE;
8071
8072 inst.operands[1].reg = REG_PC;
8073 inst.operands[1].isreg = 1;
8074 inst.operands[1].preind = 1;
8075 inst.reloc.pc_rel = 1;
8076 inst.reloc.type = (thumb_p
8077 ? BFD_RELOC_ARM_THUMB_OFFSET
8078 : (mode_3
8079 ? BFD_RELOC_ARM_HWLITERAL
8080 : BFD_RELOC_ARM_LITERAL));
8081 return FALSE;
8082}
8083
8084/* inst.operands[i] was set up by parse_address. Encode it into an
8085 ARM-format instruction. Reject all forms which cannot be encoded
8086 into a coprocessor load/store instruction. If wb_ok is false,
8087 reject use of writeback; if unind_ok is false, reject use of
8088 unindexed addressing. If reloc_override is not 0, use it instead
8089 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8090 (in which case it is preserved). */
8091
8092static int
8093encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8094{
8095 if (!inst.operands[i].isreg)
8096 {
99b2a2dd
NC
8097 /* PR 18256 */
8098 if (! inst.operands[0].isvec)
8099 {
8100 inst.error = _("invalid co-processor operand");
8101 return FAIL;
8102 }
8335d6aa
JW
8103 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8104 return SUCCESS;
8105 }
8106
8107 inst.instruction |= inst.operands[i].reg << 16;
8108
8109 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8110
8111 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8112 {
8113 gas_assert (!inst.operands[i].writeback);
8114 if (!unind_ok)
8115 {
8116 inst.error = _("instruction does not support unindexed addressing");
8117 return FAIL;
8118 }
8119 inst.instruction |= inst.operands[i].imm;
8120 inst.instruction |= INDEX_UP;
8121 return SUCCESS;
8122 }
8123
8124 if (inst.operands[i].preind)
8125 inst.instruction |= PRE_INDEX;
8126
8127 if (inst.operands[i].writeback)
09d92015 8128 {
8335d6aa 8129 if (inst.operands[i].reg == REG_PC)
c19d1205 8130 {
8335d6aa
JW
8131 inst.error = _("pc may not be used with write-back");
8132 return FAIL;
c19d1205 8133 }
8335d6aa 8134 if (!wb_ok)
c19d1205 8135 {
8335d6aa
JW
8136 inst.error = _("instruction does not support writeback");
8137 return FAIL;
c19d1205 8138 }
8335d6aa 8139 inst.instruction |= WRITE_BACK;
09d92015
MM
8140 }
8141
8335d6aa
JW
8142 if (reloc_override)
8143 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8144 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8145 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8146 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8147 {
8335d6aa
JW
8148 if (thumb_mode)
8149 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8150 else
8151 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8152 }
8335d6aa
JW
8153
8154 /* Prefer + for zero encoded value. */
8155 if (!inst.operands[i].negative)
8156 inst.instruction |= INDEX_UP;
8157
8158 return SUCCESS;
09d92015
MM
8159}
8160
5f4273c7 8161/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8162 First some generics; their names are taken from the conventional
8163 bit positions for register arguments in ARM format instructions. */
09d92015 8164
a737bd4d 8165static void
c19d1205 8166do_noargs (void)
09d92015 8167{
c19d1205 8168}
a737bd4d 8169
c19d1205
ZW
8170static void
8171do_rd (void)
8172{
8173 inst.instruction |= inst.operands[0].reg << 12;
8174}
a737bd4d 8175
c19d1205
ZW
8176static void
8177do_rd_rm (void)
8178{
8179 inst.instruction |= inst.operands[0].reg << 12;
8180 inst.instruction |= inst.operands[1].reg;
8181}
09d92015 8182
9eb6c0f1
MGD
8183static void
8184do_rm_rn (void)
8185{
8186 inst.instruction |= inst.operands[0].reg;
8187 inst.instruction |= inst.operands[1].reg << 16;
8188}
8189
c19d1205
ZW
8190static void
8191do_rd_rn (void)
8192{
8193 inst.instruction |= inst.operands[0].reg << 12;
8194 inst.instruction |= inst.operands[1].reg << 16;
8195}
a737bd4d 8196
c19d1205
ZW
8197static void
8198do_rn_rd (void)
8199{
8200 inst.instruction |= inst.operands[0].reg << 16;
8201 inst.instruction |= inst.operands[1].reg << 12;
8202}
09d92015 8203
4ed7ed8d
TP
8204static void
8205do_tt (void)
8206{
8207 inst.instruction |= inst.operands[0].reg << 8;
8208 inst.instruction |= inst.operands[1].reg << 16;
8209}
8210
59d09be6
MGD
8211static bfd_boolean
8212check_obsolete (const arm_feature_set *feature, const char *msg)
8213{
8214 if (ARM_CPU_IS_ANY (cpu_variant))
8215 {
5c3696f8 8216 as_tsktsk ("%s", msg);
59d09be6
MGD
8217 return TRUE;
8218 }
8219 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8220 {
8221 as_bad ("%s", msg);
8222 return TRUE;
8223 }
8224
8225 return FALSE;
8226}
8227
c19d1205
ZW
8228static void
8229do_rd_rm_rn (void)
8230{
9a64e435 8231 unsigned Rn = inst.operands[2].reg;
708587a4 8232 /* Enforce restrictions on SWP instruction. */
9a64e435 8233 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8234 {
8235 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8236 _("Rn must not overlap other operands"));
8237
59d09be6
MGD
8238 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8239 */
8240 if (!check_obsolete (&arm_ext_v8,
8241 _("swp{b} use is obsoleted for ARMv8 and later"))
8242 && warn_on_deprecated
8243 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8244 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8245 }
59d09be6 8246
c19d1205
ZW
8247 inst.instruction |= inst.operands[0].reg << 12;
8248 inst.instruction |= inst.operands[1].reg;
9a64e435 8249 inst.instruction |= Rn << 16;
c19d1205 8250}
09d92015 8251
c19d1205
ZW
8252static void
8253do_rd_rn_rm (void)
8254{
8255 inst.instruction |= inst.operands[0].reg << 12;
8256 inst.instruction |= inst.operands[1].reg << 16;
8257 inst.instruction |= inst.operands[2].reg;
8258}
a737bd4d 8259
c19d1205
ZW
8260static void
8261do_rm_rd_rn (void)
8262{
5be8be5d
DG
8263 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8264 constraint (((inst.reloc.exp.X_op != O_constant
8265 && inst.reloc.exp.X_op != O_illegal)
8266 || inst.reloc.exp.X_add_number != 0),
8267 BAD_ADDR_MODE);
c19d1205
ZW
8268 inst.instruction |= inst.operands[0].reg;
8269 inst.instruction |= inst.operands[1].reg << 12;
8270 inst.instruction |= inst.operands[2].reg << 16;
8271}
09d92015 8272
c19d1205
ZW
8273static void
8274do_imm0 (void)
8275{
8276 inst.instruction |= inst.operands[0].imm;
8277}
09d92015 8278
c19d1205
ZW
8279static void
8280do_rd_cpaddr (void)
8281{
8282 inst.instruction |= inst.operands[0].reg << 12;
8283 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8284}
a737bd4d 8285
c19d1205
ZW
8286/* ARM instructions, in alphabetical order by function name (except
8287 that wrapper functions appear immediately after the function they
8288 wrap). */
09d92015 8289
c19d1205
ZW
8290/* This is a pseudo-op of the form "adr rd, label" to be converted
8291 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8292
8293static void
c19d1205 8294do_adr (void)
09d92015 8295{
c19d1205 8296 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8297
c19d1205
ZW
8298 /* Frag hacking will turn this into a sub instruction if the offset turns
8299 out to be negative. */
8300 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8301 inst.reloc.pc_rel = 1;
2fc8bdac 8302 inst.reloc.exp.X_add_number -= 8;
c19d1205 8303}
b99bd4ef 8304
c19d1205
ZW
8305/* This is a pseudo-op of the form "adrl rd, label" to be converted
8306 into a relative address of the form:
8307 add rd, pc, #low(label-.-8)"
8308 add rd, rd, #high(label-.-8)" */
b99bd4ef 8309
c19d1205
ZW
8310static void
8311do_adrl (void)
8312{
8313 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8314
c19d1205
ZW
8315 /* Frag hacking will turn this into a sub instruction if the offset turns
8316 out to be negative. */
8317 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8318 inst.reloc.pc_rel = 1;
8319 inst.size = INSN_SIZE * 2;
2fc8bdac 8320 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8321}
8322
b99bd4ef 8323static void
c19d1205 8324do_arit (void)
b99bd4ef 8325{
a9f02af8
MG
8326 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8327 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8328 THUMB1_RELOC_ONLY);
c19d1205
ZW
8329 if (!inst.operands[1].present)
8330 inst.operands[1].reg = inst.operands[0].reg;
8331 inst.instruction |= inst.operands[0].reg << 12;
8332 inst.instruction |= inst.operands[1].reg << 16;
8333 encode_arm_shifter_operand (2);
8334}
b99bd4ef 8335
62b3e311
PB
8336static void
8337do_barrier (void)
8338{
8339 if (inst.operands[0].present)
ccb84d65 8340 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8341 else
8342 inst.instruction |= 0xf;
8343}
8344
c19d1205
ZW
8345static void
8346do_bfc (void)
8347{
8348 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8349 constraint (msb > 32, _("bit-field extends past end of register"));
8350 /* The instruction encoding stores the LSB and MSB,
8351 not the LSB and width. */
8352 inst.instruction |= inst.operands[0].reg << 12;
8353 inst.instruction |= inst.operands[1].imm << 7;
8354 inst.instruction |= (msb - 1) << 16;
8355}
b99bd4ef 8356
c19d1205
ZW
8357static void
8358do_bfi (void)
8359{
8360 unsigned int msb;
b99bd4ef 8361
c19d1205
ZW
8362 /* #0 in second position is alternative syntax for bfc, which is
8363 the same instruction but with REG_PC in the Rm field. */
8364 if (!inst.operands[1].isreg)
8365 inst.operands[1].reg = REG_PC;
b99bd4ef 8366
c19d1205
ZW
8367 msb = inst.operands[2].imm + inst.operands[3].imm;
8368 constraint (msb > 32, _("bit-field extends past end of register"));
8369 /* The instruction encoding stores the LSB and MSB,
8370 not the LSB and width. */
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 |= (msb - 1) << 16;
b99bd4ef
NC
8375}
8376
b99bd4ef 8377static void
c19d1205 8378do_bfx (void)
b99bd4ef 8379{
c19d1205
ZW
8380 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8381 _("bit-field extends past end of register"));
8382 inst.instruction |= inst.operands[0].reg << 12;
8383 inst.instruction |= inst.operands[1].reg;
8384 inst.instruction |= inst.operands[2].imm << 7;
8385 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8386}
09d92015 8387
c19d1205
ZW
8388/* ARM V5 breakpoint instruction (argument parse)
8389 BKPT <16 bit unsigned immediate>
8390 Instruction is not conditional.
8391 The bit pattern given in insns[] has the COND_ALWAYS condition,
8392 and it is an error if the caller tried to override that. */
b99bd4ef 8393
c19d1205
ZW
8394static void
8395do_bkpt (void)
8396{
8397 /* Top 12 of 16 bits to bits 19:8. */
8398 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8399
c19d1205
ZW
8400 /* Bottom 4 of 16 bits to bits 3:0. */
8401 inst.instruction |= inst.operands[0].imm & 0xf;
8402}
09d92015 8403
c19d1205
ZW
8404static void
8405encode_branch (int default_reloc)
8406{
8407 if (inst.operands[0].hasreloc)
8408 {
0855e32b
NS
8409 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8410 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8411 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8412 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8413 ? BFD_RELOC_ARM_PLT32
8414 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8415 }
b99bd4ef 8416 else
9ae92b05 8417 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8418 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8419}
8420
b99bd4ef 8421static void
c19d1205 8422do_branch (void)
b99bd4ef 8423{
39b41c9c
PB
8424#ifdef OBJ_ELF
8425 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8426 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8427 else
8428#endif
8429 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8430}
8431
8432static void
8433do_bl (void)
8434{
8435#ifdef OBJ_ELF
8436 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8437 {
8438 if (inst.cond == COND_ALWAYS)
8439 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8440 else
8441 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8442 }
8443 else
8444#endif
8445 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8446}
b99bd4ef 8447
c19d1205
ZW
8448/* ARM V5 branch-link-exchange instruction (argument parse)
8449 BLX <target_addr> ie BLX(1)
8450 BLX{<condition>} <Rm> ie BLX(2)
8451 Unfortunately, there are two different opcodes for this mnemonic.
8452 So, the insns[].value is not used, and the code here zaps values
8453 into inst.instruction.
8454 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8455
c19d1205
ZW
8456static void
8457do_blx (void)
8458{
8459 if (inst.operands[0].isreg)
b99bd4ef 8460 {
c19d1205
ZW
8461 /* Arg is a register; the opcode provided by insns[] is correct.
8462 It is not illegal to do "blx pc", just useless. */
8463 if (inst.operands[0].reg == REG_PC)
8464 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8465
c19d1205
ZW
8466 inst.instruction |= inst.operands[0].reg;
8467 }
8468 else
b99bd4ef 8469 {
c19d1205 8470 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8471 conditionally, and the opcode must be adjusted.
8472 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8473 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8474 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8475 inst.instruction = 0xfa000000;
267bf995 8476 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8477 }
c19d1205
ZW
8478}
8479
8480static void
8481do_bx (void)
8482{
845b51d6
PB
8483 bfd_boolean want_reloc;
8484
c19d1205
ZW
8485 if (inst.operands[0].reg == REG_PC)
8486 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8487
c19d1205 8488 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8489 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8490 it is for ARMv4t or earlier. */
8491 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8492 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8493 want_reloc = TRUE;
8494
5ad34203 8495#ifdef OBJ_ELF
845b51d6 8496 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8497#endif
584206db 8498 want_reloc = FALSE;
845b51d6
PB
8499
8500 if (want_reloc)
8501 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8502}
8503
c19d1205
ZW
8504
8505/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8506
8507static void
c19d1205 8508do_bxj (void)
a737bd4d 8509{
c19d1205
ZW
8510 if (inst.operands[0].reg == REG_PC)
8511 as_tsktsk (_("use of r15 in bxj is not really useful"));
8512
8513 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8514}
8515
c19d1205
ZW
8516/* Co-processor data operation:
8517 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8518 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8519static void
8520do_cdp (void)
8521{
8522 inst.instruction |= inst.operands[0].reg << 8;
8523 inst.instruction |= inst.operands[1].imm << 20;
8524 inst.instruction |= inst.operands[2].reg << 12;
8525 inst.instruction |= inst.operands[3].reg << 16;
8526 inst.instruction |= inst.operands[4].reg;
8527 inst.instruction |= inst.operands[5].imm << 5;
8528}
a737bd4d
NC
8529
8530static void
c19d1205 8531do_cmp (void)
a737bd4d 8532{
c19d1205
ZW
8533 inst.instruction |= inst.operands[0].reg << 16;
8534 encode_arm_shifter_operand (1);
a737bd4d
NC
8535}
8536
c19d1205
ZW
8537/* Transfer between coprocessor and ARM registers.
8538 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8539 MRC2
8540 MCR{cond}
8541 MCR2
8542
8543 No special properties. */
09d92015 8544
dcbd0d71
MGD
8545struct deprecated_coproc_regs_s
8546{
8547 unsigned cp;
8548 int opc1;
8549 unsigned crn;
8550 unsigned crm;
8551 int opc2;
8552 arm_feature_set deprecated;
8553 arm_feature_set obsoleted;
8554 const char *dep_msg;
8555 const char *obs_msg;
8556};
8557
8558#define DEPR_ACCESS_V8 \
8559 N_("This coprocessor register access is deprecated in ARMv8")
8560
8561/* Table of all deprecated coprocessor registers. */
8562static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8563{
8564 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8565 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8566 DEPR_ACCESS_V8, NULL},
8567 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8568 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8569 DEPR_ACCESS_V8, NULL},
8570 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8571 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8572 DEPR_ACCESS_V8, NULL},
8573 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8574 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8575 DEPR_ACCESS_V8, NULL},
8576 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8577 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8578 DEPR_ACCESS_V8, NULL},
8579};
8580
8581#undef DEPR_ACCESS_V8
8582
8583static const size_t deprecated_coproc_reg_count =
8584 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8585
09d92015 8586static void
c19d1205 8587do_co_reg (void)
09d92015 8588{
fdfde340 8589 unsigned Rd;
dcbd0d71 8590 size_t i;
fdfde340
JM
8591
8592 Rd = inst.operands[2].reg;
8593 if (thumb_mode)
8594 {
8595 if (inst.instruction == 0xee000010
8596 || inst.instruction == 0xfe000010)
8597 /* MCR, MCR2 */
8598 reject_bad_reg (Rd);
8599 else
8600 /* MRC, MRC2 */
8601 constraint (Rd == REG_SP, BAD_SP);
8602 }
8603 else
8604 {
8605 /* MCR */
8606 if (inst.instruction == 0xe000010)
8607 constraint (Rd == REG_PC, BAD_PC);
8608 }
8609
dcbd0d71
MGD
8610 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8611 {
8612 const struct deprecated_coproc_regs_s *r =
8613 deprecated_coproc_regs + i;
8614
8615 if (inst.operands[0].reg == r->cp
8616 && inst.operands[1].imm == r->opc1
8617 && inst.operands[3].reg == r->crn
8618 && inst.operands[4].reg == r->crm
8619 && inst.operands[5].imm == r->opc2)
8620 {
b10bf8c5 8621 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8622 && warn_on_deprecated
dcbd0d71 8623 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8624 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8625 }
8626 }
fdfde340 8627
c19d1205
ZW
8628 inst.instruction |= inst.operands[0].reg << 8;
8629 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8630 inst.instruction |= Rd << 12;
c19d1205
ZW
8631 inst.instruction |= inst.operands[3].reg << 16;
8632 inst.instruction |= inst.operands[4].reg;
8633 inst.instruction |= inst.operands[5].imm << 5;
8634}
09d92015 8635
c19d1205
ZW
8636/* Transfer between coprocessor register and pair of ARM registers.
8637 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8638 MCRR2
8639 MRRC{cond}
8640 MRRC2
b99bd4ef 8641
c19d1205 8642 Two XScale instructions are special cases of these:
09d92015 8643
c19d1205
ZW
8644 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8645 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8646
5f4273c7 8647 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8648
c19d1205
ZW
8649static void
8650do_co_reg2c (void)
8651{
fdfde340
JM
8652 unsigned Rd, Rn;
8653
8654 Rd = inst.operands[2].reg;
8655 Rn = inst.operands[3].reg;
8656
8657 if (thumb_mode)
8658 {
8659 reject_bad_reg (Rd);
8660 reject_bad_reg (Rn);
8661 }
8662 else
8663 {
8664 constraint (Rd == REG_PC, BAD_PC);
8665 constraint (Rn == REG_PC, BAD_PC);
8666 }
8667
c19d1205
ZW
8668 inst.instruction |= inst.operands[0].reg << 8;
8669 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8670 inst.instruction |= Rd << 12;
8671 inst.instruction |= Rn << 16;
c19d1205 8672 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8673}
8674
c19d1205
ZW
8675static void
8676do_cpsi (void)
8677{
8678 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8679 if (inst.operands[1].present)
8680 {
8681 inst.instruction |= CPSI_MMOD;
8682 inst.instruction |= inst.operands[1].imm;
8683 }
c19d1205 8684}
b99bd4ef 8685
62b3e311
PB
8686static void
8687do_dbg (void)
8688{
8689 inst.instruction |= inst.operands[0].imm;
8690}
8691
eea54501
MGD
8692static void
8693do_div (void)
8694{
8695 unsigned Rd, Rn, Rm;
8696
8697 Rd = inst.operands[0].reg;
8698 Rn = (inst.operands[1].present
8699 ? inst.operands[1].reg : Rd);
8700 Rm = inst.operands[2].reg;
8701
8702 constraint ((Rd == REG_PC), BAD_PC);
8703 constraint ((Rn == REG_PC), BAD_PC);
8704 constraint ((Rm == REG_PC), BAD_PC);
8705
8706 inst.instruction |= Rd << 16;
8707 inst.instruction |= Rn << 0;
8708 inst.instruction |= Rm << 8;
8709}
8710
b99bd4ef 8711static void
c19d1205 8712do_it (void)
b99bd4ef 8713{
c19d1205 8714 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8715 process it to do the validation as if in
8716 thumb mode, just in case the code gets
8717 assembled for thumb using the unified syntax. */
8718
c19d1205 8719 inst.size = 0;
e07e6e58
NC
8720 if (unified_syntax)
8721 {
8722 set_it_insn_type (IT_INSN);
8723 now_it.mask = (inst.instruction & 0xf) | 0x10;
8724 now_it.cc = inst.operands[0].imm;
8725 }
09d92015 8726}
b99bd4ef 8727
6530b175
NC
8728/* If there is only one register in the register list,
8729 then return its register number. Otherwise return -1. */
8730static int
8731only_one_reg_in_list (int range)
8732{
8733 int i = ffs (range) - 1;
8734 return (i > 15 || range != (1 << i)) ? -1 : i;
8735}
8736
09d92015 8737static void
6530b175 8738encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8739{
c19d1205
ZW
8740 int base_reg = inst.operands[0].reg;
8741 int range = inst.operands[1].imm;
6530b175 8742 int one_reg;
ea6ef066 8743
c19d1205
ZW
8744 inst.instruction |= base_reg << 16;
8745 inst.instruction |= range;
ea6ef066 8746
c19d1205
ZW
8747 if (inst.operands[1].writeback)
8748 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8749
c19d1205 8750 if (inst.operands[0].writeback)
ea6ef066 8751 {
c19d1205
ZW
8752 inst.instruction |= WRITE_BACK;
8753 /* Check for unpredictable uses of writeback. */
8754 if (inst.instruction & LOAD_BIT)
09d92015 8755 {
c19d1205
ZW
8756 /* Not allowed in LDM type 2. */
8757 if ((inst.instruction & LDM_TYPE_2_OR_3)
8758 && ((range & (1 << REG_PC)) == 0))
8759 as_warn (_("writeback of base register is UNPREDICTABLE"));
8760 /* Only allowed if base reg not in list for other types. */
8761 else if (range & (1 << base_reg))
8762 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8763 }
8764 else /* STM. */
8765 {
8766 /* Not allowed for type 2. */
8767 if (inst.instruction & LDM_TYPE_2_OR_3)
8768 as_warn (_("writeback of base register is UNPREDICTABLE"));
8769 /* Only allowed if base reg not in list, or first in list. */
8770 else if ((range & (1 << base_reg))
8771 && (range & ((1 << base_reg) - 1)))
8772 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8773 }
ea6ef066 8774 }
6530b175
NC
8775
8776 /* If PUSH/POP has only one register, then use the A2 encoding. */
8777 one_reg = only_one_reg_in_list (range);
8778 if (from_push_pop_mnem && one_reg >= 0)
8779 {
8780 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8781
8782 inst.instruction &= A_COND_MASK;
8783 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8784 inst.instruction |= one_reg << 12;
8785 }
8786}
8787
8788static void
8789do_ldmstm (void)
8790{
8791 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8792}
8793
c19d1205
ZW
8794/* ARMv5TE load-consecutive (argument parse)
8795 Mode is like LDRH.
8796
8797 LDRccD R, mode
8798 STRccD R, mode. */
8799
a737bd4d 8800static void
c19d1205 8801do_ldrd (void)
a737bd4d 8802{
c19d1205 8803 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8804 _("first transfer register must be even"));
c19d1205
ZW
8805 constraint (inst.operands[1].present
8806 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8807 _("can only transfer two consecutive registers"));
c19d1205
ZW
8808 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8809 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8810
c19d1205
ZW
8811 if (!inst.operands[1].present)
8812 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8813
c56791bb
RE
8814 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8815 register and the first register written; we have to diagnose
8816 overlap between the base and the second register written here. */
ea6ef066 8817
c56791bb
RE
8818 if (inst.operands[2].reg == inst.operands[1].reg
8819 && (inst.operands[2].writeback || inst.operands[2].postind))
8820 as_warn (_("base register written back, and overlaps "
8821 "second transfer register"));
b05fe5cf 8822
c56791bb
RE
8823 if (!(inst.instruction & V4_STR_BIT))
8824 {
c19d1205 8825 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8826 destination (even if not write-back). */
8827 if (inst.operands[2].immisreg
8828 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8829 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8830 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8831 }
c19d1205
ZW
8832 inst.instruction |= inst.operands[0].reg << 12;
8833 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8834}
8835
8836static void
c19d1205 8837do_ldrex (void)
b05fe5cf 8838{
c19d1205
ZW
8839 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8840 || inst.operands[1].postind || inst.operands[1].writeback
8841 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8842 || inst.operands[1].negative
8843 /* This can arise if the programmer has written
8844 strex rN, rM, foo
8845 or if they have mistakenly used a register name as the last
8846 operand, eg:
8847 strex rN, rM, rX
8848 It is very difficult to distinguish between these two cases
8849 because "rX" might actually be a label. ie the register
8850 name has been occluded by a symbol of the same name. So we
8851 just generate a general 'bad addressing mode' type error
8852 message and leave it up to the programmer to discover the
8853 true cause and fix their mistake. */
8854 || (inst.operands[1].reg == REG_PC),
8855 BAD_ADDR_MODE);
b05fe5cf 8856
c19d1205
ZW
8857 constraint (inst.reloc.exp.X_op != O_constant
8858 || inst.reloc.exp.X_add_number != 0,
8859 _("offset must be zero in ARM encoding"));
b05fe5cf 8860
5be8be5d
DG
8861 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8862
c19d1205
ZW
8863 inst.instruction |= inst.operands[0].reg << 12;
8864 inst.instruction |= inst.operands[1].reg << 16;
8865 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8866}
8867
8868static void
c19d1205 8869do_ldrexd (void)
b05fe5cf 8870{
c19d1205
ZW
8871 constraint (inst.operands[0].reg % 2 != 0,
8872 _("even register required"));
8873 constraint (inst.operands[1].present
8874 && inst.operands[1].reg != inst.operands[0].reg + 1,
8875 _("can only load two consecutive registers"));
8876 /* If op 1 were present and equal to PC, this function wouldn't
8877 have been called in the first place. */
8878 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8879
c19d1205
ZW
8880 inst.instruction |= inst.operands[0].reg << 12;
8881 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8882}
8883
1be5fd2e
NC
8884/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8885 which is not a multiple of four is UNPREDICTABLE. */
8886static void
8887check_ldr_r15_aligned (void)
8888{
8889 constraint (!(inst.operands[1].immisreg)
8890 && (inst.operands[0].reg == REG_PC
8891 && inst.operands[1].reg == REG_PC
8892 && (inst.reloc.exp.X_add_number & 0x3)),
8893 _("ldr to register 15 must be 4-byte alligned"));
8894}
8895
b05fe5cf 8896static void
c19d1205 8897do_ldst (void)
b05fe5cf 8898{
c19d1205
ZW
8899 inst.instruction |= inst.operands[0].reg << 12;
8900 if (!inst.operands[1].isreg)
8335d6aa 8901 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8902 return;
c19d1205 8903 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8904 check_ldr_r15_aligned ();
b05fe5cf
ZW
8905}
8906
8907static void
c19d1205 8908do_ldstt (void)
b05fe5cf 8909{
c19d1205
ZW
8910 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8911 reject [Rn,...]. */
8912 if (inst.operands[1].preind)
b05fe5cf 8913 {
bd3ba5d1
NC
8914 constraint (inst.reloc.exp.X_op != O_constant
8915 || inst.reloc.exp.X_add_number != 0,
c19d1205 8916 _("this instruction requires a post-indexed address"));
b05fe5cf 8917
c19d1205
ZW
8918 inst.operands[1].preind = 0;
8919 inst.operands[1].postind = 1;
8920 inst.operands[1].writeback = 1;
b05fe5cf 8921 }
c19d1205
ZW
8922 inst.instruction |= inst.operands[0].reg << 12;
8923 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8924}
b05fe5cf 8925
c19d1205 8926/* Halfword and signed-byte load/store operations. */
b05fe5cf 8927
c19d1205
ZW
8928static void
8929do_ldstv4 (void)
8930{
ff4a8d2b 8931 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8932 inst.instruction |= inst.operands[0].reg << 12;
8933 if (!inst.operands[1].isreg)
8335d6aa 8934 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8935 return;
c19d1205 8936 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8937}
8938
8939static void
c19d1205 8940do_ldsttv4 (void)
b05fe5cf 8941{
c19d1205
ZW
8942 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8943 reject [Rn,...]. */
8944 if (inst.operands[1].preind)
b05fe5cf 8945 {
bd3ba5d1
NC
8946 constraint (inst.reloc.exp.X_op != O_constant
8947 || inst.reloc.exp.X_add_number != 0,
c19d1205 8948 _("this instruction requires a post-indexed address"));
b05fe5cf 8949
c19d1205
ZW
8950 inst.operands[1].preind = 0;
8951 inst.operands[1].postind = 1;
8952 inst.operands[1].writeback = 1;
b05fe5cf 8953 }
c19d1205
ZW
8954 inst.instruction |= inst.operands[0].reg << 12;
8955 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8956}
b05fe5cf 8957
c19d1205
ZW
8958/* Co-processor register load/store.
8959 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8960static void
8961do_lstc (void)
8962{
8963 inst.instruction |= inst.operands[0].reg << 8;
8964 inst.instruction |= inst.operands[1].reg << 12;
8965 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8966}
8967
b05fe5cf 8968static void
c19d1205 8969do_mlas (void)
b05fe5cf 8970{
8fb9d7b9 8971 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8972 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8973 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8974 && !(inst.instruction & 0x00400000))
8fb9d7b9 8975 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8976
c19d1205
ZW
8977 inst.instruction |= inst.operands[0].reg << 16;
8978 inst.instruction |= inst.operands[1].reg;
8979 inst.instruction |= inst.operands[2].reg << 8;
8980 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8981}
b05fe5cf 8982
c19d1205
ZW
8983static void
8984do_mov (void)
8985{
a9f02af8
MG
8986 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8987 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8988 THUMB1_RELOC_ONLY);
c19d1205
ZW
8989 inst.instruction |= inst.operands[0].reg << 12;
8990 encode_arm_shifter_operand (1);
8991}
b05fe5cf 8992
c19d1205
ZW
8993/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8994static void
8995do_mov16 (void)
8996{
b6895b4f
PB
8997 bfd_vma imm;
8998 bfd_boolean top;
8999
9000 top = (inst.instruction & 0x00400000) != 0;
9001 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
9002 _(":lower16: not allowed this instruction"));
9003 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
9004 _(":upper16: not allowed instruction"));
c19d1205 9005 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9006 if (inst.reloc.type == BFD_RELOC_UNUSED)
9007 {
9008 imm = inst.reloc.exp.X_add_number;
9009 /* The value is in two pieces: 0:11, 16:19. */
9010 inst.instruction |= (imm & 0x00000fff);
9011 inst.instruction |= (imm & 0x0000f000) << 4;
9012 }
b05fe5cf 9013}
b99bd4ef 9014
037e8744
JB
9015static int
9016do_vfp_nsyn_mrs (void)
9017{
9018 if (inst.operands[0].isvec)
9019 {
9020 if (inst.operands[1].reg != 1)
477330fc 9021 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9022 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9023 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9024 do_vfp_nsyn_opcode ("fmstat");
9025 }
9026 else if (inst.operands[1].isvec)
9027 do_vfp_nsyn_opcode ("fmrx");
9028 else
9029 return FAIL;
5f4273c7 9030
037e8744
JB
9031 return SUCCESS;
9032}
9033
9034static int
9035do_vfp_nsyn_msr (void)
9036{
9037 if (inst.operands[0].isvec)
9038 do_vfp_nsyn_opcode ("fmxr");
9039 else
9040 return FAIL;
9041
9042 return SUCCESS;
9043}
9044
f7c21dc7
NC
9045static void
9046do_vmrs (void)
9047{
9048 unsigned Rt = inst.operands[0].reg;
fa94de6b 9049
16d02dc9 9050 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9051 {
9052 inst.error = BAD_SP;
9053 return;
9054 }
9055
9056 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9057 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9058 {
9059 inst.error = BAD_PC;
9060 return;
9061 }
9062
16d02dc9
JB
9063 /* If we get through parsing the register name, we just insert the number
9064 generated into the instruction without further validation. */
9065 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9066 inst.instruction |= (Rt << 12);
9067}
9068
9069static void
9070do_vmsr (void)
9071{
9072 unsigned Rt = inst.operands[1].reg;
fa94de6b 9073
f7c21dc7
NC
9074 if (thumb_mode)
9075 reject_bad_reg (Rt);
9076 else if (Rt == REG_PC)
9077 {
9078 inst.error = BAD_PC;
9079 return;
9080 }
9081
16d02dc9
JB
9082 /* If we get through parsing the register name, we just insert the number
9083 generated into the instruction without further validation. */
9084 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9085 inst.instruction |= (Rt << 12);
9086}
9087
b99bd4ef 9088static void
c19d1205 9089do_mrs (void)
b99bd4ef 9090{
90ec0d68
MGD
9091 unsigned br;
9092
037e8744
JB
9093 if (do_vfp_nsyn_mrs () == SUCCESS)
9094 return;
9095
ff4a8d2b 9096 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9097 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9098
9099 if (inst.operands[1].isreg)
9100 {
9101 br = inst.operands[1].reg;
9102 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9103 as_bad (_("bad register for mrs"));
9104 }
9105 else
9106 {
9107 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9108 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9109 != (PSR_c|PSR_f),
d2cd1205 9110 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9111 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9112 }
9113
9114 inst.instruction |= br;
c19d1205 9115}
b99bd4ef 9116
c19d1205
ZW
9117/* Two possible forms:
9118 "{C|S}PSR_<field>, Rm",
9119 "{C|S}PSR_f, #expression". */
b99bd4ef 9120
c19d1205
ZW
9121static void
9122do_msr (void)
9123{
037e8744
JB
9124 if (do_vfp_nsyn_msr () == SUCCESS)
9125 return;
9126
c19d1205
ZW
9127 inst.instruction |= inst.operands[0].imm;
9128 if (inst.operands[1].isreg)
9129 inst.instruction |= inst.operands[1].reg;
9130 else
b99bd4ef 9131 {
c19d1205
ZW
9132 inst.instruction |= INST_IMMEDIATE;
9133 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9134 inst.reloc.pc_rel = 0;
b99bd4ef 9135 }
b99bd4ef
NC
9136}
9137
c19d1205
ZW
9138static void
9139do_mul (void)
a737bd4d 9140{
ff4a8d2b
NC
9141 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9142
c19d1205
ZW
9143 if (!inst.operands[2].present)
9144 inst.operands[2].reg = inst.operands[0].reg;
9145 inst.instruction |= inst.operands[0].reg << 16;
9146 inst.instruction |= inst.operands[1].reg;
9147 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9148
8fb9d7b9
MS
9149 if (inst.operands[0].reg == inst.operands[1].reg
9150 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9151 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9152}
9153
c19d1205
ZW
9154/* Long Multiply Parser
9155 UMULL RdLo, RdHi, Rm, Rs
9156 SMULL RdLo, RdHi, Rm, Rs
9157 UMLAL RdLo, RdHi, Rm, Rs
9158 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9159
9160static void
c19d1205 9161do_mull (void)
b99bd4ef 9162{
c19d1205
ZW
9163 inst.instruction |= inst.operands[0].reg << 12;
9164 inst.instruction |= inst.operands[1].reg << 16;
9165 inst.instruction |= inst.operands[2].reg;
9166 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9167
682b27ad
PB
9168 /* rdhi and rdlo must be different. */
9169 if (inst.operands[0].reg == inst.operands[1].reg)
9170 as_tsktsk (_("rdhi and rdlo must be different"));
9171
9172 /* rdhi, rdlo and rm must all be different before armv6. */
9173 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9174 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9175 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9176 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9177}
b99bd4ef 9178
c19d1205
ZW
9179static void
9180do_nop (void)
9181{
e7495e45
NS
9182 if (inst.operands[0].present
9183 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9184 {
9185 /* Architectural NOP hints are CPSR sets with no bits selected. */
9186 inst.instruction &= 0xf0000000;
e7495e45
NS
9187 inst.instruction |= 0x0320f000;
9188 if (inst.operands[0].present)
9189 inst.instruction |= inst.operands[0].imm;
c19d1205 9190 }
b99bd4ef
NC
9191}
9192
c19d1205
ZW
9193/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9194 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9195 Condition defaults to COND_ALWAYS.
9196 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9197
9198static void
c19d1205 9199do_pkhbt (void)
b99bd4ef 9200{
c19d1205
ZW
9201 inst.instruction |= inst.operands[0].reg << 12;
9202 inst.instruction |= inst.operands[1].reg << 16;
9203 inst.instruction |= inst.operands[2].reg;
9204 if (inst.operands[3].present)
9205 encode_arm_shift (3);
9206}
b99bd4ef 9207
c19d1205 9208/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9209
c19d1205
ZW
9210static void
9211do_pkhtb (void)
9212{
9213 if (!inst.operands[3].present)
b99bd4ef 9214 {
c19d1205
ZW
9215 /* If the shift specifier is omitted, turn the instruction
9216 into pkhbt rd, rm, rn. */
9217 inst.instruction &= 0xfff00010;
9218 inst.instruction |= inst.operands[0].reg << 12;
9219 inst.instruction |= inst.operands[1].reg;
9220 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9221 }
9222 else
9223 {
c19d1205
ZW
9224 inst.instruction |= inst.operands[0].reg << 12;
9225 inst.instruction |= inst.operands[1].reg << 16;
9226 inst.instruction |= inst.operands[2].reg;
9227 encode_arm_shift (3);
b99bd4ef
NC
9228 }
9229}
9230
c19d1205 9231/* ARMv5TE: Preload-Cache
60e5ef9f 9232 MP Extensions: Preload for write
c19d1205 9233
60e5ef9f 9234 PLD(W) <addr_mode>
c19d1205
ZW
9235
9236 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9237
9238static void
c19d1205 9239do_pld (void)
b99bd4ef 9240{
c19d1205
ZW
9241 constraint (!inst.operands[0].isreg,
9242 _("'[' expected after PLD mnemonic"));
9243 constraint (inst.operands[0].postind,
9244 _("post-indexed expression used in preload instruction"));
9245 constraint (inst.operands[0].writeback,
9246 _("writeback used in preload instruction"));
9247 constraint (!inst.operands[0].preind,
9248 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9249 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9250}
b99bd4ef 9251
62b3e311
PB
9252/* ARMv7: PLI <addr_mode> */
9253static void
9254do_pli (void)
9255{
9256 constraint (!inst.operands[0].isreg,
9257 _("'[' expected after PLI mnemonic"));
9258 constraint (inst.operands[0].postind,
9259 _("post-indexed expression used in preload instruction"));
9260 constraint (inst.operands[0].writeback,
9261 _("writeback used in preload instruction"));
9262 constraint (!inst.operands[0].preind,
9263 _("unindexed addressing used in preload instruction"));
9264 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9265 inst.instruction &= ~PRE_INDEX;
9266}
9267
c19d1205
ZW
9268static void
9269do_push_pop (void)
9270{
5e0d7f77
MP
9271 constraint (inst.operands[0].writeback,
9272 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9273 inst.operands[1] = inst.operands[0];
9274 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9275 inst.operands[0].isreg = 1;
9276 inst.operands[0].writeback = 1;
9277 inst.operands[0].reg = REG_SP;
6530b175 9278 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9279}
b99bd4ef 9280
c19d1205
ZW
9281/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9282 word at the specified address and the following word
9283 respectively.
9284 Unconditionally executed.
9285 Error if Rn is R15. */
b99bd4ef 9286
c19d1205
ZW
9287static void
9288do_rfe (void)
9289{
9290 inst.instruction |= inst.operands[0].reg << 16;
9291 if (inst.operands[0].writeback)
9292 inst.instruction |= WRITE_BACK;
9293}
b99bd4ef 9294
c19d1205 9295/* ARM V6 ssat (argument parse). */
b99bd4ef 9296
c19d1205
ZW
9297static void
9298do_ssat (void)
9299{
9300 inst.instruction |= inst.operands[0].reg << 12;
9301 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9302 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9303
c19d1205
ZW
9304 if (inst.operands[3].present)
9305 encode_arm_shift (3);
b99bd4ef
NC
9306}
9307
c19d1205 9308/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9309
9310static void
c19d1205 9311do_usat (void)
b99bd4ef 9312{
c19d1205
ZW
9313 inst.instruction |= inst.operands[0].reg << 12;
9314 inst.instruction |= inst.operands[1].imm << 16;
9315 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9316
c19d1205
ZW
9317 if (inst.operands[3].present)
9318 encode_arm_shift (3);
b99bd4ef
NC
9319}
9320
c19d1205 9321/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9322
9323static void
c19d1205 9324do_ssat16 (void)
09d92015 9325{
c19d1205
ZW
9326 inst.instruction |= inst.operands[0].reg << 12;
9327 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9328 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9329}
9330
c19d1205
ZW
9331static void
9332do_usat16 (void)
a737bd4d 9333{
c19d1205
ZW
9334 inst.instruction |= inst.operands[0].reg << 12;
9335 inst.instruction |= inst.operands[1].imm << 16;
9336 inst.instruction |= inst.operands[2].reg;
9337}
a737bd4d 9338
c19d1205
ZW
9339/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9340 preserving the other bits.
a737bd4d 9341
c19d1205
ZW
9342 setend <endian_specifier>, where <endian_specifier> is either
9343 BE or LE. */
a737bd4d 9344
c19d1205
ZW
9345static void
9346do_setend (void)
9347{
12e37cbc
MGD
9348 if (warn_on_deprecated
9349 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9350 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9351
c19d1205
ZW
9352 if (inst.operands[0].imm)
9353 inst.instruction |= 0x200;
a737bd4d
NC
9354}
9355
9356static void
c19d1205 9357do_shift (void)
a737bd4d 9358{
c19d1205
ZW
9359 unsigned int Rm = (inst.operands[1].present
9360 ? inst.operands[1].reg
9361 : inst.operands[0].reg);
a737bd4d 9362
c19d1205
ZW
9363 inst.instruction |= inst.operands[0].reg << 12;
9364 inst.instruction |= Rm;
9365 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9366 {
c19d1205
ZW
9367 inst.instruction |= inst.operands[2].reg << 8;
9368 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9369 /* PR 12854: Error on extraneous shifts. */
9370 constraint (inst.operands[2].shifted,
9371 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9372 }
9373 else
c19d1205 9374 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9375}
9376
09d92015 9377static void
3eb17e6b 9378do_smc (void)
09d92015 9379{
3eb17e6b 9380 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9381 inst.reloc.pc_rel = 0;
09d92015
MM
9382}
9383
90ec0d68
MGD
9384static void
9385do_hvc (void)
9386{
9387 inst.reloc.type = BFD_RELOC_ARM_HVC;
9388 inst.reloc.pc_rel = 0;
9389}
9390
09d92015 9391static void
c19d1205 9392do_swi (void)
09d92015 9393{
c19d1205
ZW
9394 inst.reloc.type = BFD_RELOC_ARM_SWI;
9395 inst.reloc.pc_rel = 0;
09d92015
MM
9396}
9397
ddfded2f
MW
9398static void
9399do_setpan (void)
9400{
9401 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9402 _("selected processor does not support SETPAN instruction"));
9403
9404 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9405}
9406
9407static void
9408do_t_setpan (void)
9409{
9410 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9411 _("selected processor does not support SETPAN instruction"));
9412
9413 inst.instruction |= (inst.operands[0].imm << 3);
9414}
9415
c19d1205
ZW
9416/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9417 SMLAxy{cond} Rd,Rm,Rs,Rn
9418 SMLAWy{cond} Rd,Rm,Rs,Rn
9419 Error if any register is R15. */
e16bb312 9420
c19d1205
ZW
9421static void
9422do_smla (void)
e16bb312 9423{
c19d1205
ZW
9424 inst.instruction |= inst.operands[0].reg << 16;
9425 inst.instruction |= inst.operands[1].reg;
9426 inst.instruction |= inst.operands[2].reg << 8;
9427 inst.instruction |= inst.operands[3].reg << 12;
9428}
a737bd4d 9429
c19d1205
ZW
9430/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9431 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9432 Error if any register is R15.
9433 Warning if Rdlo == Rdhi. */
a737bd4d 9434
c19d1205
ZW
9435static void
9436do_smlal (void)
9437{
9438 inst.instruction |= inst.operands[0].reg << 12;
9439 inst.instruction |= inst.operands[1].reg << 16;
9440 inst.instruction |= inst.operands[2].reg;
9441 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9442
c19d1205
ZW
9443 if (inst.operands[0].reg == inst.operands[1].reg)
9444 as_tsktsk (_("rdhi and rdlo must be different"));
9445}
a737bd4d 9446
c19d1205
ZW
9447/* ARM V5E (El Segundo) signed-multiply (argument parse)
9448 SMULxy{cond} Rd,Rm,Rs
9449 Error if any register is R15. */
a737bd4d 9450
c19d1205
ZW
9451static void
9452do_smul (void)
9453{
9454 inst.instruction |= inst.operands[0].reg << 16;
9455 inst.instruction |= inst.operands[1].reg;
9456 inst.instruction |= inst.operands[2].reg << 8;
9457}
a737bd4d 9458
b6702015
PB
9459/* ARM V6 srs (argument parse). The variable fields in the encoding are
9460 the same for both ARM and Thumb-2. */
a737bd4d 9461
c19d1205
ZW
9462static void
9463do_srs (void)
9464{
b6702015
PB
9465 int reg;
9466
9467 if (inst.operands[0].present)
9468 {
9469 reg = inst.operands[0].reg;
fdfde340 9470 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9471 }
9472 else
fdfde340 9473 reg = REG_SP;
b6702015
PB
9474
9475 inst.instruction |= reg << 16;
9476 inst.instruction |= inst.operands[1].imm;
9477 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9478 inst.instruction |= WRITE_BACK;
9479}
a737bd4d 9480
c19d1205 9481/* ARM V6 strex (argument parse). */
a737bd4d 9482
c19d1205
ZW
9483static void
9484do_strex (void)
9485{
9486 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9487 || inst.operands[2].postind || inst.operands[2].writeback
9488 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9489 || inst.operands[2].negative
9490 /* See comment in do_ldrex(). */
9491 || (inst.operands[2].reg == REG_PC),
9492 BAD_ADDR_MODE);
a737bd4d 9493
c19d1205
ZW
9494 constraint (inst.operands[0].reg == inst.operands[1].reg
9495 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9496
c19d1205
ZW
9497 constraint (inst.reloc.exp.X_op != O_constant
9498 || inst.reloc.exp.X_add_number != 0,
9499 _("offset must be zero in ARM encoding"));
a737bd4d 9500
c19d1205
ZW
9501 inst.instruction |= inst.operands[0].reg << 12;
9502 inst.instruction |= inst.operands[1].reg;
9503 inst.instruction |= inst.operands[2].reg << 16;
9504 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9505}
9506
877807f8
NC
9507static void
9508do_t_strexbh (void)
9509{
9510 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9511 || inst.operands[2].postind || inst.operands[2].writeback
9512 || inst.operands[2].immisreg || inst.operands[2].shifted
9513 || inst.operands[2].negative,
9514 BAD_ADDR_MODE);
9515
9516 constraint (inst.operands[0].reg == inst.operands[1].reg
9517 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9518
9519 do_rm_rd_rn ();
9520}
9521
e16bb312 9522static void
c19d1205 9523do_strexd (void)
e16bb312 9524{
c19d1205
ZW
9525 constraint (inst.operands[1].reg % 2 != 0,
9526 _("even register required"));
9527 constraint (inst.operands[2].present
9528 && inst.operands[2].reg != inst.operands[1].reg + 1,
9529 _("can only store two consecutive registers"));
9530 /* If op 2 were present and equal to PC, this function wouldn't
9531 have been called in the first place. */
9532 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9533
c19d1205
ZW
9534 constraint (inst.operands[0].reg == inst.operands[1].reg
9535 || inst.operands[0].reg == inst.operands[1].reg + 1
9536 || inst.operands[0].reg == inst.operands[3].reg,
9537 BAD_OVERLAP);
e16bb312 9538
c19d1205
ZW
9539 inst.instruction |= inst.operands[0].reg << 12;
9540 inst.instruction |= inst.operands[1].reg;
9541 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9542}
9543
9eb6c0f1
MGD
9544/* ARM V8 STRL. */
9545static void
4b8c8c02 9546do_stlex (void)
9eb6c0f1
MGD
9547{
9548 constraint (inst.operands[0].reg == inst.operands[1].reg
9549 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9550
9551 do_rd_rm_rn ();
9552}
9553
9554static void
4b8c8c02 9555do_t_stlex (void)
9eb6c0f1
MGD
9556{
9557 constraint (inst.operands[0].reg == inst.operands[1].reg
9558 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9559
9560 do_rm_rd_rn ();
9561}
9562
c19d1205
ZW
9563/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9564 extends it to 32-bits, and adds the result to a value in another
9565 register. You can specify a rotation by 0, 8, 16, or 24 bits
9566 before extracting the 16-bit value.
9567 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9568 Condition defaults to COND_ALWAYS.
9569 Error if any register uses R15. */
9570
e16bb312 9571static void
c19d1205 9572do_sxtah (void)
e16bb312 9573{
c19d1205
ZW
9574 inst.instruction |= inst.operands[0].reg << 12;
9575 inst.instruction |= inst.operands[1].reg << 16;
9576 inst.instruction |= inst.operands[2].reg;
9577 inst.instruction |= inst.operands[3].imm << 10;
9578}
e16bb312 9579
c19d1205 9580/* ARM V6 SXTH.
e16bb312 9581
c19d1205
ZW
9582 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9583 Condition defaults to COND_ALWAYS.
9584 Error if any register uses R15. */
e16bb312
NC
9585
9586static void
c19d1205 9587do_sxth (void)
e16bb312 9588{
c19d1205
ZW
9589 inst.instruction |= inst.operands[0].reg << 12;
9590 inst.instruction |= inst.operands[1].reg;
9591 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9592}
c19d1205
ZW
9593\f
9594/* VFP instructions. In a logical order: SP variant first, monad
9595 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9596
9597static void
c19d1205 9598do_vfp_sp_monadic (void)
e16bb312 9599{
5287ad62
JB
9600 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9601 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9602}
9603
9604static void
c19d1205 9605do_vfp_sp_dyadic (void)
e16bb312 9606{
5287ad62
JB
9607 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9608 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9609 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9610}
9611
9612static void
c19d1205 9613do_vfp_sp_compare_z (void)
e16bb312 9614{
5287ad62 9615 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9616}
9617
9618static void
c19d1205 9619do_vfp_dp_sp_cvt (void)
e16bb312 9620{
5287ad62
JB
9621 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9622 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9623}
9624
9625static void
c19d1205 9626do_vfp_sp_dp_cvt (void)
e16bb312 9627{
5287ad62
JB
9628 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9629 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9630}
9631
9632static void
c19d1205 9633do_vfp_reg_from_sp (void)
e16bb312 9634{
c19d1205 9635 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9636 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9637}
9638
9639static void
c19d1205 9640do_vfp_reg2_from_sp2 (void)
e16bb312 9641{
c19d1205
ZW
9642 constraint (inst.operands[2].imm != 2,
9643 _("only two consecutive VFP SP registers allowed here"));
9644 inst.instruction |= inst.operands[0].reg << 12;
9645 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9646 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9647}
9648
9649static void
c19d1205 9650do_vfp_sp_from_reg (void)
e16bb312 9651{
5287ad62 9652 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9653 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9654}
9655
9656static void
c19d1205 9657do_vfp_sp2_from_reg2 (void)
e16bb312 9658{
c19d1205
ZW
9659 constraint (inst.operands[0].imm != 2,
9660 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9661 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9662 inst.instruction |= inst.operands[1].reg << 12;
9663 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9664}
9665
9666static void
c19d1205 9667do_vfp_sp_ldst (void)
e16bb312 9668{
5287ad62 9669 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9670 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9671}
9672
9673static void
c19d1205 9674do_vfp_dp_ldst (void)
e16bb312 9675{
5287ad62 9676 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9677 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9678}
9679
c19d1205 9680
e16bb312 9681static void
c19d1205 9682vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9683{
c19d1205
ZW
9684 if (inst.operands[0].writeback)
9685 inst.instruction |= WRITE_BACK;
9686 else
9687 constraint (ldstm_type != VFP_LDSTMIA,
9688 _("this addressing mode requires base-register writeback"));
9689 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9690 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9691 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9692}
9693
9694static void
c19d1205 9695vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9696{
c19d1205 9697 int count;
e16bb312 9698
c19d1205
ZW
9699 if (inst.operands[0].writeback)
9700 inst.instruction |= WRITE_BACK;
9701 else
9702 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9703 _("this addressing mode requires base-register writeback"));
e16bb312 9704
c19d1205 9705 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9706 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9707
c19d1205
ZW
9708 count = inst.operands[1].imm << 1;
9709 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9710 count += 1;
e16bb312 9711
c19d1205 9712 inst.instruction |= count;
e16bb312
NC
9713}
9714
9715static void
c19d1205 9716do_vfp_sp_ldstmia (void)
e16bb312 9717{
c19d1205 9718 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9719}
9720
9721static void
c19d1205 9722do_vfp_sp_ldstmdb (void)
e16bb312 9723{
c19d1205 9724 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9725}
9726
9727static void
c19d1205 9728do_vfp_dp_ldstmia (void)
e16bb312 9729{
c19d1205 9730 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9731}
9732
9733static void
c19d1205 9734do_vfp_dp_ldstmdb (void)
e16bb312 9735{
c19d1205 9736 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9737}
9738
9739static void
c19d1205 9740do_vfp_xp_ldstmia (void)
e16bb312 9741{
c19d1205
ZW
9742 vfp_dp_ldstm (VFP_LDSTMIAX);
9743}
e16bb312 9744
c19d1205
ZW
9745static void
9746do_vfp_xp_ldstmdb (void)
9747{
9748 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9749}
5287ad62
JB
9750
9751static void
9752do_vfp_dp_rd_rm (void)
9753{
9754 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9755 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9756}
9757
9758static void
9759do_vfp_dp_rn_rd (void)
9760{
9761 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9762 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9763}
9764
9765static void
9766do_vfp_dp_rd_rn (void)
9767{
9768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9769 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9770}
9771
9772static void
9773do_vfp_dp_rd_rn_rm (void)
9774{
9775 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9777 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9778}
9779
9780static void
9781do_vfp_dp_rd (void)
9782{
9783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9784}
9785
9786static void
9787do_vfp_dp_rm_rd_rn (void)
9788{
9789 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9790 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9791 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9792}
9793
9794/* VFPv3 instructions. */
9795static void
9796do_vfp_sp_const (void)
9797{
9798 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9799 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9800 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9801}
9802
9803static void
9804do_vfp_dp_const (void)
9805{
9806 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9807 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9808 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9809}
9810
9811static void
9812vfp_conv (int srcsize)
9813{
5f1af56b
MGD
9814 int immbits = srcsize - inst.operands[1].imm;
9815
fa94de6b
RM
9816 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9817 {
5f1af56b 9818 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9819 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9820 inst.error = _("immediate value out of range, expected range [0, 16]");
9821 return;
9822 }
fa94de6b 9823 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9824 {
9825 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9826 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9827 inst.error = _("immediate value out of range, expected range [1, 32]");
9828 return;
9829 }
9830
5287ad62
JB
9831 inst.instruction |= (immbits & 1) << 5;
9832 inst.instruction |= (immbits >> 1);
9833}
9834
9835static void
9836do_vfp_sp_conv_16 (void)
9837{
9838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9839 vfp_conv (16);
9840}
9841
9842static void
9843do_vfp_dp_conv_16 (void)
9844{
9845 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9846 vfp_conv (16);
9847}
9848
9849static void
9850do_vfp_sp_conv_32 (void)
9851{
9852 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9853 vfp_conv (32);
9854}
9855
9856static void
9857do_vfp_dp_conv_32 (void)
9858{
9859 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9860 vfp_conv (32);
9861}
c19d1205
ZW
9862\f
9863/* FPA instructions. Also in a logical order. */
e16bb312 9864
c19d1205
ZW
9865static void
9866do_fpa_cmp (void)
9867{
9868 inst.instruction |= inst.operands[0].reg << 16;
9869 inst.instruction |= inst.operands[1].reg;
9870}
b99bd4ef
NC
9871
9872static void
c19d1205 9873do_fpa_ldmstm (void)
b99bd4ef 9874{
c19d1205
ZW
9875 inst.instruction |= inst.operands[0].reg << 12;
9876 switch (inst.operands[1].imm)
9877 {
9878 case 1: inst.instruction |= CP_T_X; break;
9879 case 2: inst.instruction |= CP_T_Y; break;
9880 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9881 case 4: break;
9882 default: abort ();
9883 }
b99bd4ef 9884
c19d1205
ZW
9885 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9886 {
9887 /* The instruction specified "ea" or "fd", so we can only accept
9888 [Rn]{!}. The instruction does not really support stacking or
9889 unstacking, so we have to emulate these by setting appropriate
9890 bits and offsets. */
9891 constraint (inst.reloc.exp.X_op != O_constant
9892 || inst.reloc.exp.X_add_number != 0,
9893 _("this instruction does not support indexing"));
b99bd4ef 9894
c19d1205
ZW
9895 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9896 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9897
c19d1205
ZW
9898 if (!(inst.instruction & INDEX_UP))
9899 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9900
c19d1205
ZW
9901 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9902 {
9903 inst.operands[2].preind = 0;
9904 inst.operands[2].postind = 1;
9905 }
9906 }
b99bd4ef 9907
c19d1205 9908 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9909}
c19d1205
ZW
9910\f
9911/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9912
c19d1205
ZW
9913static void
9914do_iwmmxt_tandorc (void)
9915{
9916 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9917}
b99bd4ef 9918
c19d1205
ZW
9919static void
9920do_iwmmxt_textrc (void)
9921{
9922 inst.instruction |= inst.operands[0].reg << 12;
9923 inst.instruction |= inst.operands[1].imm;
9924}
b99bd4ef
NC
9925
9926static void
c19d1205 9927do_iwmmxt_textrm (void)
b99bd4ef 9928{
c19d1205
ZW
9929 inst.instruction |= inst.operands[0].reg << 12;
9930 inst.instruction |= inst.operands[1].reg << 16;
9931 inst.instruction |= inst.operands[2].imm;
9932}
b99bd4ef 9933
c19d1205
ZW
9934static void
9935do_iwmmxt_tinsr (void)
9936{
9937 inst.instruction |= inst.operands[0].reg << 16;
9938 inst.instruction |= inst.operands[1].reg << 12;
9939 inst.instruction |= inst.operands[2].imm;
9940}
b99bd4ef 9941
c19d1205
ZW
9942static void
9943do_iwmmxt_tmia (void)
9944{
9945 inst.instruction |= inst.operands[0].reg << 5;
9946 inst.instruction |= inst.operands[1].reg;
9947 inst.instruction |= inst.operands[2].reg << 12;
9948}
b99bd4ef 9949
c19d1205
ZW
9950static void
9951do_iwmmxt_waligni (void)
9952{
9953 inst.instruction |= inst.operands[0].reg << 12;
9954 inst.instruction |= inst.operands[1].reg << 16;
9955 inst.instruction |= inst.operands[2].reg;
9956 inst.instruction |= inst.operands[3].imm << 20;
9957}
b99bd4ef 9958
2d447fca
JM
9959static void
9960do_iwmmxt_wmerge (void)
9961{
9962 inst.instruction |= inst.operands[0].reg << 12;
9963 inst.instruction |= inst.operands[1].reg << 16;
9964 inst.instruction |= inst.operands[2].reg;
9965 inst.instruction |= inst.operands[3].imm << 21;
9966}
9967
c19d1205
ZW
9968static void
9969do_iwmmxt_wmov (void)
9970{
9971 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9972 inst.instruction |= inst.operands[0].reg << 12;
9973 inst.instruction |= inst.operands[1].reg << 16;
9974 inst.instruction |= inst.operands[1].reg;
9975}
b99bd4ef 9976
c19d1205
ZW
9977static void
9978do_iwmmxt_wldstbh (void)
9979{
8f06b2d8 9980 int reloc;
c19d1205 9981 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9982 if (thumb_mode)
9983 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9984 else
9985 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9986 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9987}
9988
c19d1205
ZW
9989static void
9990do_iwmmxt_wldstw (void)
9991{
9992 /* RIWR_RIWC clears .isreg for a control register. */
9993 if (!inst.operands[0].isreg)
9994 {
9995 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9996 inst.instruction |= 0xf0000000;
9997 }
b99bd4ef 9998
c19d1205
ZW
9999 inst.instruction |= inst.operands[0].reg << 12;
10000 encode_arm_cp_address (1, TRUE, TRUE, 0);
10001}
b99bd4ef
NC
10002
10003static void
c19d1205 10004do_iwmmxt_wldstd (void)
b99bd4ef 10005{
c19d1205 10006 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10007 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10008 && inst.operands[1].immisreg)
10009 {
10010 inst.instruction &= ~0x1a000ff;
eff0bc54 10011 inst.instruction |= (0xfU << 28);
2d447fca
JM
10012 if (inst.operands[1].preind)
10013 inst.instruction |= PRE_INDEX;
10014 if (!inst.operands[1].negative)
10015 inst.instruction |= INDEX_UP;
10016 if (inst.operands[1].writeback)
10017 inst.instruction |= WRITE_BACK;
10018 inst.instruction |= inst.operands[1].reg << 16;
10019 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10020 inst.instruction |= inst.operands[1].imm;
10021 }
10022 else
10023 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10024}
b99bd4ef 10025
c19d1205
ZW
10026static void
10027do_iwmmxt_wshufh (void)
10028{
10029 inst.instruction |= inst.operands[0].reg << 12;
10030 inst.instruction |= inst.operands[1].reg << 16;
10031 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10032 inst.instruction |= (inst.operands[2].imm & 0x0f);
10033}
b99bd4ef 10034
c19d1205
ZW
10035static void
10036do_iwmmxt_wzero (void)
10037{
10038 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10039 inst.instruction |= inst.operands[0].reg;
10040 inst.instruction |= inst.operands[0].reg << 12;
10041 inst.instruction |= inst.operands[0].reg << 16;
10042}
2d447fca
JM
10043
10044static void
10045do_iwmmxt_wrwrwr_or_imm5 (void)
10046{
10047 if (inst.operands[2].isreg)
10048 do_rd_rn_rm ();
10049 else {
10050 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10051 _("immediate operand requires iWMMXt2"));
10052 do_rd_rn ();
10053 if (inst.operands[2].imm == 0)
10054 {
10055 switch ((inst.instruction >> 20) & 0xf)
10056 {
10057 case 4:
10058 case 5:
10059 case 6:
5f4273c7 10060 case 7:
2d447fca
JM
10061 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10062 inst.operands[2].imm = 16;
10063 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10064 break;
10065 case 8:
10066 case 9:
10067 case 10:
10068 case 11:
10069 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10070 inst.operands[2].imm = 32;
10071 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10072 break;
10073 case 12:
10074 case 13:
10075 case 14:
10076 case 15:
10077 {
10078 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10079 unsigned long wrn;
10080 wrn = (inst.instruction >> 16) & 0xf;
10081 inst.instruction &= 0xff0fff0f;
10082 inst.instruction |= wrn;
10083 /* Bail out here; the instruction is now assembled. */
10084 return;
10085 }
10086 }
10087 }
10088 /* Map 32 -> 0, etc. */
10089 inst.operands[2].imm &= 0x1f;
eff0bc54 10090 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10091 }
10092}
c19d1205
ZW
10093\f
10094/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10095 operations first, then control, shift, and load/store. */
b99bd4ef 10096
c19d1205 10097/* Insns like "foo X,Y,Z". */
b99bd4ef 10098
c19d1205
ZW
10099static void
10100do_mav_triple (void)
10101{
10102 inst.instruction |= inst.operands[0].reg << 16;
10103 inst.instruction |= inst.operands[1].reg;
10104 inst.instruction |= inst.operands[2].reg << 12;
10105}
b99bd4ef 10106
c19d1205
ZW
10107/* Insns like "foo W,X,Y,Z".
10108 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10109
c19d1205
ZW
10110static void
10111do_mav_quad (void)
10112{
10113 inst.instruction |= inst.operands[0].reg << 5;
10114 inst.instruction |= inst.operands[1].reg << 12;
10115 inst.instruction |= inst.operands[2].reg << 16;
10116 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10117}
10118
c19d1205
ZW
10119/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10120static void
10121do_mav_dspsc (void)
a737bd4d 10122{
c19d1205
ZW
10123 inst.instruction |= inst.operands[1].reg << 12;
10124}
a737bd4d 10125
c19d1205
ZW
10126/* Maverick shift immediate instructions.
10127 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10128 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10129
c19d1205
ZW
10130static void
10131do_mav_shift (void)
10132{
10133 int imm = inst.operands[2].imm;
a737bd4d 10134
c19d1205
ZW
10135 inst.instruction |= inst.operands[0].reg << 12;
10136 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10137
c19d1205
ZW
10138 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10139 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10140 Bit 4 should be 0. */
10141 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10142
c19d1205
ZW
10143 inst.instruction |= imm;
10144}
10145\f
10146/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10147
c19d1205
ZW
10148/* Xscale multiply-accumulate (argument parse)
10149 MIAcc acc0,Rm,Rs
10150 MIAPHcc acc0,Rm,Rs
10151 MIAxycc acc0,Rm,Rs. */
a737bd4d 10152
c19d1205
ZW
10153static void
10154do_xsc_mia (void)
10155{
10156 inst.instruction |= inst.operands[1].reg;
10157 inst.instruction |= inst.operands[2].reg << 12;
10158}
a737bd4d 10159
c19d1205 10160/* Xscale move-accumulator-register (argument parse)
a737bd4d 10161
c19d1205 10162 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10163
c19d1205
ZW
10164static void
10165do_xsc_mar (void)
10166{
10167 inst.instruction |= inst.operands[1].reg << 12;
10168 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10169}
10170
c19d1205 10171/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10172
c19d1205 10173 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10174
10175static void
c19d1205 10176do_xsc_mra (void)
b99bd4ef 10177{
c19d1205
ZW
10178 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10179 inst.instruction |= inst.operands[0].reg << 12;
10180 inst.instruction |= inst.operands[1].reg << 16;
10181}
10182\f
10183/* Encoding functions relevant only to Thumb. */
b99bd4ef 10184
c19d1205
ZW
10185/* inst.operands[i] is a shifted-register operand; encode
10186 it into inst.instruction in the format used by Thumb32. */
10187
10188static void
10189encode_thumb32_shifted_operand (int i)
10190{
10191 unsigned int value = inst.reloc.exp.X_add_number;
10192 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10193
9c3c69f2
PB
10194 constraint (inst.operands[i].immisreg,
10195 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10196 inst.instruction |= inst.operands[i].reg;
10197 if (shift == SHIFT_RRX)
10198 inst.instruction |= SHIFT_ROR << 4;
10199 else
b99bd4ef 10200 {
c19d1205
ZW
10201 constraint (inst.reloc.exp.X_op != O_constant,
10202 _("expression too complex"));
10203
10204 constraint (value > 32
10205 || (value == 32 && (shift == SHIFT_LSL
10206 || shift == SHIFT_ROR)),
10207 _("shift expression is too large"));
10208
10209 if (value == 0)
10210 shift = SHIFT_LSL;
10211 else if (value == 32)
10212 value = 0;
10213
10214 inst.instruction |= shift << 4;
10215 inst.instruction |= (value & 0x1c) << 10;
10216 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10217 }
c19d1205 10218}
b99bd4ef 10219
b99bd4ef 10220
c19d1205
ZW
10221/* inst.operands[i] was set up by parse_address. Encode it into a
10222 Thumb32 format load or store instruction. Reject forms that cannot
10223 be used with such instructions. If is_t is true, reject forms that
10224 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10225 that cannot be used with a D instruction. If it is a store insn,
10226 reject PC in Rn. */
b99bd4ef 10227
c19d1205
ZW
10228static void
10229encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10230{
5be8be5d 10231 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10232
10233 constraint (!inst.operands[i].isreg,
53365c0d 10234 _("Instruction does not support =N addresses"));
b99bd4ef 10235
c19d1205
ZW
10236 inst.instruction |= inst.operands[i].reg << 16;
10237 if (inst.operands[i].immisreg)
b99bd4ef 10238 {
5be8be5d 10239 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10240 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10241 constraint (inst.operands[i].negative,
10242 _("Thumb does not support negative register indexing"));
10243 constraint (inst.operands[i].postind,
10244 _("Thumb does not support register post-indexing"));
10245 constraint (inst.operands[i].writeback,
10246 _("Thumb does not support register indexing with writeback"));
10247 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10248 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10249
f40d1643 10250 inst.instruction |= inst.operands[i].imm;
c19d1205 10251 if (inst.operands[i].shifted)
b99bd4ef 10252 {
c19d1205
ZW
10253 constraint (inst.reloc.exp.X_op != O_constant,
10254 _("expression too complex"));
9c3c69f2
PB
10255 constraint (inst.reloc.exp.X_add_number < 0
10256 || inst.reloc.exp.X_add_number > 3,
c19d1205 10257 _("shift out of range"));
9c3c69f2 10258 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10259 }
10260 inst.reloc.type = BFD_RELOC_UNUSED;
10261 }
10262 else if (inst.operands[i].preind)
10263 {
5be8be5d 10264 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10265 constraint (is_t && inst.operands[i].writeback,
c19d1205 10266 _("cannot use writeback with this instruction"));
4755303e
WN
10267 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10268 BAD_PC_ADDRESSING);
c19d1205
ZW
10269
10270 if (is_d)
10271 {
10272 inst.instruction |= 0x01000000;
10273 if (inst.operands[i].writeback)
10274 inst.instruction |= 0x00200000;
b99bd4ef 10275 }
c19d1205 10276 else
b99bd4ef 10277 {
c19d1205
ZW
10278 inst.instruction |= 0x00000c00;
10279 if (inst.operands[i].writeback)
10280 inst.instruction |= 0x00000100;
b99bd4ef 10281 }
c19d1205 10282 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10283 }
c19d1205 10284 else if (inst.operands[i].postind)
b99bd4ef 10285 {
9c2799c2 10286 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10287 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10288 constraint (is_t, _("cannot use post-indexing with this instruction"));
10289
10290 if (is_d)
10291 inst.instruction |= 0x00200000;
10292 else
10293 inst.instruction |= 0x00000900;
10294 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10295 }
10296 else /* unindexed - only for coprocessor */
10297 inst.error = _("instruction does not accept unindexed addressing");
10298}
10299
10300/* Table of Thumb instructions which exist in both 16- and 32-bit
10301 encodings (the latter only in post-V6T2 cores). The index is the
10302 value used in the insns table below. When there is more than one
10303 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10304 holds variant (1).
10305 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10306#define T16_32_TAB \
21d799b5
NC
10307 X(_adc, 4140, eb400000), \
10308 X(_adcs, 4140, eb500000), \
10309 X(_add, 1c00, eb000000), \
10310 X(_adds, 1c00, eb100000), \
10311 X(_addi, 0000, f1000000), \
10312 X(_addis, 0000, f1100000), \
10313 X(_add_pc,000f, f20f0000), \
10314 X(_add_sp,000d, f10d0000), \
10315 X(_adr, 000f, f20f0000), \
10316 X(_and, 4000, ea000000), \
10317 X(_ands, 4000, ea100000), \
10318 X(_asr, 1000, fa40f000), \
10319 X(_asrs, 1000, fa50f000), \
10320 X(_b, e000, f000b000), \
10321 X(_bcond, d000, f0008000), \
10322 X(_bic, 4380, ea200000), \
10323 X(_bics, 4380, ea300000), \
10324 X(_cmn, 42c0, eb100f00), \
10325 X(_cmp, 2800, ebb00f00), \
10326 X(_cpsie, b660, f3af8400), \
10327 X(_cpsid, b670, f3af8600), \
10328 X(_cpy, 4600, ea4f0000), \
10329 X(_dec_sp,80dd, f1ad0d00), \
10330 X(_eor, 4040, ea800000), \
10331 X(_eors, 4040, ea900000), \
10332 X(_inc_sp,00dd, f10d0d00), \
10333 X(_ldmia, c800, e8900000), \
10334 X(_ldr, 6800, f8500000), \
10335 X(_ldrb, 7800, f8100000), \
10336 X(_ldrh, 8800, f8300000), \
10337 X(_ldrsb, 5600, f9100000), \
10338 X(_ldrsh, 5e00, f9300000), \
10339 X(_ldr_pc,4800, f85f0000), \
10340 X(_ldr_pc2,4800, f85f0000), \
10341 X(_ldr_sp,9800, f85d0000), \
10342 X(_lsl, 0000, fa00f000), \
10343 X(_lsls, 0000, fa10f000), \
10344 X(_lsr, 0800, fa20f000), \
10345 X(_lsrs, 0800, fa30f000), \
10346 X(_mov, 2000, ea4f0000), \
10347 X(_movs, 2000, ea5f0000), \
10348 X(_mul, 4340, fb00f000), \
10349 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10350 X(_mvn, 43c0, ea6f0000), \
10351 X(_mvns, 43c0, ea7f0000), \
10352 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10353 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10354 X(_orr, 4300, ea400000), \
10355 X(_orrs, 4300, ea500000), \
10356 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10357 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10358 X(_rev, ba00, fa90f080), \
10359 X(_rev16, ba40, fa90f090), \
10360 X(_revsh, bac0, fa90f0b0), \
10361 X(_ror, 41c0, fa60f000), \
10362 X(_rors, 41c0, fa70f000), \
10363 X(_sbc, 4180, eb600000), \
10364 X(_sbcs, 4180, eb700000), \
10365 X(_stmia, c000, e8800000), \
10366 X(_str, 6000, f8400000), \
10367 X(_strb, 7000, f8000000), \
10368 X(_strh, 8000, f8200000), \
10369 X(_str_sp,9000, f84d0000), \
10370 X(_sub, 1e00, eba00000), \
10371 X(_subs, 1e00, ebb00000), \
10372 X(_subi, 8000, f1a00000), \
10373 X(_subis, 8000, f1b00000), \
10374 X(_sxtb, b240, fa4ff080), \
10375 X(_sxth, b200, fa0ff080), \
10376 X(_tst, 4200, ea100f00), \
10377 X(_uxtb, b2c0, fa5ff080), \
10378 X(_uxth, b280, fa1ff080), \
10379 X(_nop, bf00, f3af8000), \
10380 X(_yield, bf10, f3af8001), \
10381 X(_wfe, bf20, f3af8002), \
10382 X(_wfi, bf30, f3af8003), \
53c4b28b 10383 X(_sev, bf40, f3af8004), \
74db7efb
NC
10384 X(_sevl, bf50, f3af8005), \
10385 X(_udf, de00, f7f0a000)
c19d1205
ZW
10386
10387/* To catch errors in encoding functions, the codes are all offset by
10388 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10389 as 16-bit instructions. */
21d799b5 10390#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10391enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10392#undef X
10393
10394#define X(a,b,c) 0x##b
10395static const unsigned short thumb_op16[] = { T16_32_TAB };
10396#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10397#undef X
10398
10399#define X(a,b,c) 0x##c
10400static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10401#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10402#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10403#undef X
10404#undef T16_32_TAB
10405
10406/* Thumb instruction encoders, in alphabetical order. */
10407
92e90b6e 10408/* ADDW or SUBW. */
c921be7d 10409
92e90b6e
PB
10410static void
10411do_t_add_sub_w (void)
10412{
10413 int Rd, Rn;
10414
10415 Rd = inst.operands[0].reg;
10416 Rn = inst.operands[1].reg;
10417
539d4391
NC
10418 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10419 is the SP-{plus,minus}-immediate form of the instruction. */
10420 if (Rn == REG_SP)
10421 constraint (Rd == REG_PC, BAD_PC);
10422 else
10423 reject_bad_reg (Rd);
fdfde340 10424
92e90b6e
PB
10425 inst.instruction |= (Rn << 16) | (Rd << 8);
10426 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10427}
10428
c19d1205
ZW
10429/* Parse an add or subtract instruction. We get here with inst.instruction
10430 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10431
10432static void
10433do_t_add_sub (void)
10434{
10435 int Rd, Rs, Rn;
10436
10437 Rd = inst.operands[0].reg;
10438 Rs = (inst.operands[1].present
10439 ? inst.operands[1].reg /* Rd, Rs, foo */
10440 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10441
e07e6e58
NC
10442 if (Rd == REG_PC)
10443 set_it_insn_type_last ();
10444
c19d1205
ZW
10445 if (unified_syntax)
10446 {
0110f2b8
PB
10447 bfd_boolean flags;
10448 bfd_boolean narrow;
10449 int opcode;
10450
10451 flags = (inst.instruction == T_MNEM_adds
10452 || inst.instruction == T_MNEM_subs);
10453 if (flags)
e07e6e58 10454 narrow = !in_it_block ();
0110f2b8 10455 else
e07e6e58 10456 narrow = in_it_block ();
c19d1205 10457 if (!inst.operands[2].isreg)
b99bd4ef 10458 {
16805f35
PB
10459 int add;
10460
fdfde340
JM
10461 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10462
16805f35
PB
10463 add = (inst.instruction == T_MNEM_add
10464 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10465 opcode = 0;
10466 if (inst.size_req != 4)
10467 {
0110f2b8 10468 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10469 appropriate. */
0110f2b8
PB
10470 if (Rd == REG_SP && Rs == REG_SP && !flags)
10471 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10472 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10473 opcode = T_MNEM_add_sp;
10474 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10475 opcode = T_MNEM_add_pc;
10476 else if (Rd <= 7 && Rs <= 7 && narrow)
10477 {
10478 if (flags)
10479 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10480 else
10481 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10482 }
10483 if (opcode)
10484 {
10485 inst.instruction = THUMB_OP16(opcode);
10486 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10487 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10488 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10489 {
10490 if (inst.size_req == 2)
10491 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10492 else
10493 inst.relax = opcode;
10494 }
0110f2b8
PB
10495 }
10496 else
10497 constraint (inst.size_req == 2, BAD_HIREG);
10498 }
10499 if (inst.size_req == 4
10500 || (inst.size_req != 2 && !opcode))
10501 {
a9f02af8
MG
10502 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10503 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10504 THUMB1_RELOC_ONLY);
efd81785
PB
10505 if (Rd == REG_PC)
10506 {
fdfde340 10507 constraint (add, BAD_PC);
efd81785
PB
10508 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10509 _("only SUBS PC, LR, #const allowed"));
10510 constraint (inst.reloc.exp.X_op != O_constant,
10511 _("expression too complex"));
10512 constraint (inst.reloc.exp.X_add_number < 0
10513 || inst.reloc.exp.X_add_number > 0xff,
10514 _("immediate value out of range"));
10515 inst.instruction = T2_SUBS_PC_LR
10516 | inst.reloc.exp.X_add_number;
10517 inst.reloc.type = BFD_RELOC_UNUSED;
10518 return;
10519 }
10520 else if (Rs == REG_PC)
16805f35
PB
10521 {
10522 /* Always use addw/subw. */
10523 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10524 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10525 }
10526 else
10527 {
10528 inst.instruction = THUMB_OP32 (inst.instruction);
10529 inst.instruction = (inst.instruction & 0xe1ffffff)
10530 | 0x10000000;
10531 if (flags)
10532 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10533 else
10534 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10535 }
dc4503c6
PB
10536 inst.instruction |= Rd << 8;
10537 inst.instruction |= Rs << 16;
0110f2b8 10538 }
b99bd4ef 10539 }
c19d1205
ZW
10540 else
10541 {
5f4cb198
NC
10542 unsigned int value = inst.reloc.exp.X_add_number;
10543 unsigned int shift = inst.operands[2].shift_kind;
10544
c19d1205
ZW
10545 Rn = inst.operands[2].reg;
10546 /* See if we can do this with a 16-bit instruction. */
10547 if (!inst.operands[2].shifted && inst.size_req != 4)
10548 {
e27ec89e
PB
10549 if (Rd > 7 || Rs > 7 || Rn > 7)
10550 narrow = FALSE;
10551
10552 if (narrow)
c19d1205 10553 {
e27ec89e
PB
10554 inst.instruction = ((inst.instruction == T_MNEM_adds
10555 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10556 ? T_OPCODE_ADD_R3
10557 : T_OPCODE_SUB_R3);
10558 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10559 return;
10560 }
b99bd4ef 10561
7e806470 10562 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10563 {
7e806470
PB
10564 /* Thumb-1 cores (except v6-M) require at least one high
10565 register in a narrow non flag setting add. */
10566 if (Rd > 7 || Rn > 7
10567 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10568 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10569 {
7e806470
PB
10570 if (Rd == Rn)
10571 {
10572 Rn = Rs;
10573 Rs = Rd;
10574 }
c19d1205
ZW
10575 inst.instruction = T_OPCODE_ADD_HI;
10576 inst.instruction |= (Rd & 8) << 4;
10577 inst.instruction |= (Rd & 7);
10578 inst.instruction |= Rn << 3;
10579 return;
10580 }
c19d1205
ZW
10581 }
10582 }
c921be7d 10583
fdfde340
JM
10584 constraint (Rd == REG_PC, BAD_PC);
10585 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10586 constraint (Rs == REG_PC, BAD_PC);
10587 reject_bad_reg (Rn);
10588
c19d1205
ZW
10589 /* If we get here, it can't be done in 16 bits. */
10590 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10591 _("shift must be constant"));
10592 inst.instruction = THUMB_OP32 (inst.instruction);
10593 inst.instruction |= Rd << 8;
10594 inst.instruction |= Rs << 16;
5f4cb198
NC
10595 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10596 _("shift value over 3 not allowed in thumb mode"));
10597 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10598 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10599 encode_thumb32_shifted_operand (2);
10600 }
10601 }
10602 else
10603 {
10604 constraint (inst.instruction == T_MNEM_adds
10605 || inst.instruction == T_MNEM_subs,
10606 BAD_THUMB32);
b99bd4ef 10607
c19d1205 10608 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10609 {
c19d1205
ZW
10610 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10611 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10612 BAD_HIREG);
10613
10614 inst.instruction = (inst.instruction == T_MNEM_add
10615 ? 0x0000 : 0x8000);
10616 inst.instruction |= (Rd << 4) | Rs;
10617 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10618 return;
10619 }
10620
c19d1205
ZW
10621 Rn = inst.operands[2].reg;
10622 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10623
c19d1205
ZW
10624 /* We now have Rd, Rs, and Rn set to registers. */
10625 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10626 {
c19d1205
ZW
10627 /* Can't do this for SUB. */
10628 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10629 inst.instruction = T_OPCODE_ADD_HI;
10630 inst.instruction |= (Rd & 8) << 4;
10631 inst.instruction |= (Rd & 7);
10632 if (Rs == Rd)
10633 inst.instruction |= Rn << 3;
10634 else if (Rn == Rd)
10635 inst.instruction |= Rs << 3;
10636 else
10637 constraint (1, _("dest must overlap one source register"));
10638 }
10639 else
10640 {
10641 inst.instruction = (inst.instruction == T_MNEM_add
10642 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10643 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10644 }
b99bd4ef 10645 }
b99bd4ef
NC
10646}
10647
c19d1205
ZW
10648static void
10649do_t_adr (void)
10650{
fdfde340
JM
10651 unsigned Rd;
10652
10653 Rd = inst.operands[0].reg;
10654 reject_bad_reg (Rd);
10655
10656 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10657 {
10658 /* Defer to section relaxation. */
10659 inst.relax = inst.instruction;
10660 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10661 inst.instruction |= Rd << 4;
0110f2b8
PB
10662 }
10663 else if (unified_syntax && inst.size_req != 2)
e9f89963 10664 {
0110f2b8 10665 /* Generate a 32-bit opcode. */
e9f89963 10666 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10667 inst.instruction |= Rd << 8;
e9f89963
PB
10668 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10669 inst.reloc.pc_rel = 1;
10670 }
10671 else
10672 {
0110f2b8 10673 /* Generate a 16-bit opcode. */
e9f89963
PB
10674 inst.instruction = THUMB_OP16 (inst.instruction);
10675 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10676 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10677 inst.reloc.pc_rel = 1;
b99bd4ef 10678
fdfde340 10679 inst.instruction |= Rd << 4;
e9f89963 10680 }
c19d1205 10681}
b99bd4ef 10682
c19d1205
ZW
10683/* Arithmetic instructions for which there is just one 16-bit
10684 instruction encoding, and it allows only two low registers.
10685 For maximal compatibility with ARM syntax, we allow three register
10686 operands even when Thumb-32 instructions are not available, as long
10687 as the first two are identical. For instance, both "sbc r0,r1" and
10688 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10689static void
c19d1205 10690do_t_arit3 (void)
b99bd4ef 10691{
c19d1205 10692 int Rd, Rs, Rn;
b99bd4ef 10693
c19d1205
ZW
10694 Rd = inst.operands[0].reg;
10695 Rs = (inst.operands[1].present
10696 ? inst.operands[1].reg /* Rd, Rs, foo */
10697 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10698 Rn = inst.operands[2].reg;
b99bd4ef 10699
fdfde340
JM
10700 reject_bad_reg (Rd);
10701 reject_bad_reg (Rs);
10702 if (inst.operands[2].isreg)
10703 reject_bad_reg (Rn);
10704
c19d1205 10705 if (unified_syntax)
b99bd4ef 10706 {
c19d1205
ZW
10707 if (!inst.operands[2].isreg)
10708 {
10709 /* For an immediate, we always generate a 32-bit opcode;
10710 section relaxation will shrink it later if possible. */
10711 inst.instruction = THUMB_OP32 (inst.instruction);
10712 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10713 inst.instruction |= Rd << 8;
10714 inst.instruction |= Rs << 16;
10715 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10716 }
10717 else
10718 {
e27ec89e
PB
10719 bfd_boolean narrow;
10720
c19d1205 10721 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10722 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10723 narrow = !in_it_block ();
e27ec89e 10724 else
e07e6e58 10725 narrow = in_it_block ();
e27ec89e
PB
10726
10727 if (Rd > 7 || Rn > 7 || Rs > 7)
10728 narrow = FALSE;
10729 if (inst.operands[2].shifted)
10730 narrow = FALSE;
10731 if (inst.size_req == 4)
10732 narrow = FALSE;
10733
10734 if (narrow
c19d1205
ZW
10735 && Rd == Rs)
10736 {
10737 inst.instruction = THUMB_OP16 (inst.instruction);
10738 inst.instruction |= Rd;
10739 inst.instruction |= Rn << 3;
10740 return;
10741 }
b99bd4ef 10742
c19d1205
ZW
10743 /* If we get here, it can't be done in 16 bits. */
10744 constraint (inst.operands[2].shifted
10745 && inst.operands[2].immisreg,
10746 _("shift must be constant"));
10747 inst.instruction = THUMB_OP32 (inst.instruction);
10748 inst.instruction |= Rd << 8;
10749 inst.instruction |= Rs << 16;
10750 encode_thumb32_shifted_operand (2);
10751 }
a737bd4d 10752 }
c19d1205 10753 else
b99bd4ef 10754 {
c19d1205
ZW
10755 /* On its face this is a lie - the instruction does set the
10756 flags. However, the only supported mnemonic in this mode
10757 says it doesn't. */
10758 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10759
c19d1205
ZW
10760 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10761 _("unshifted register required"));
10762 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10763 constraint (Rd != Rs,
10764 _("dest and source1 must be the same register"));
a737bd4d 10765
c19d1205
ZW
10766 inst.instruction = THUMB_OP16 (inst.instruction);
10767 inst.instruction |= Rd;
10768 inst.instruction |= Rn << 3;
b99bd4ef 10769 }
a737bd4d 10770}
b99bd4ef 10771
c19d1205
ZW
10772/* Similarly, but for instructions where the arithmetic operation is
10773 commutative, so we can allow either of them to be different from
10774 the destination operand in a 16-bit instruction. For instance, all
10775 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10776 accepted. */
10777static void
10778do_t_arit3c (void)
a737bd4d 10779{
c19d1205 10780 int Rd, Rs, Rn;
b99bd4ef 10781
c19d1205
ZW
10782 Rd = inst.operands[0].reg;
10783 Rs = (inst.operands[1].present
10784 ? inst.operands[1].reg /* Rd, Rs, foo */
10785 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10786 Rn = inst.operands[2].reg;
c921be7d 10787
fdfde340
JM
10788 reject_bad_reg (Rd);
10789 reject_bad_reg (Rs);
10790 if (inst.operands[2].isreg)
10791 reject_bad_reg (Rn);
a737bd4d 10792
c19d1205 10793 if (unified_syntax)
a737bd4d 10794 {
c19d1205 10795 if (!inst.operands[2].isreg)
b99bd4ef 10796 {
c19d1205
ZW
10797 /* For an immediate, we always generate a 32-bit opcode;
10798 section relaxation will shrink it later if possible. */
10799 inst.instruction = THUMB_OP32 (inst.instruction);
10800 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10801 inst.instruction |= Rd << 8;
10802 inst.instruction |= Rs << 16;
10803 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10804 }
c19d1205 10805 else
a737bd4d 10806 {
e27ec89e
PB
10807 bfd_boolean narrow;
10808
c19d1205 10809 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10810 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10811 narrow = !in_it_block ();
e27ec89e 10812 else
e07e6e58 10813 narrow = in_it_block ();
e27ec89e
PB
10814
10815 if (Rd > 7 || Rn > 7 || Rs > 7)
10816 narrow = FALSE;
10817 if (inst.operands[2].shifted)
10818 narrow = FALSE;
10819 if (inst.size_req == 4)
10820 narrow = FALSE;
10821
10822 if (narrow)
a737bd4d 10823 {
c19d1205 10824 if (Rd == Rs)
a737bd4d 10825 {
c19d1205
ZW
10826 inst.instruction = THUMB_OP16 (inst.instruction);
10827 inst.instruction |= Rd;
10828 inst.instruction |= Rn << 3;
10829 return;
a737bd4d 10830 }
c19d1205 10831 if (Rd == Rn)
a737bd4d 10832 {
c19d1205
ZW
10833 inst.instruction = THUMB_OP16 (inst.instruction);
10834 inst.instruction |= Rd;
10835 inst.instruction |= Rs << 3;
10836 return;
a737bd4d
NC
10837 }
10838 }
c19d1205
ZW
10839
10840 /* If we get here, it can't be done in 16 bits. */
10841 constraint (inst.operands[2].shifted
10842 && inst.operands[2].immisreg,
10843 _("shift must be constant"));
10844 inst.instruction = THUMB_OP32 (inst.instruction);
10845 inst.instruction |= Rd << 8;
10846 inst.instruction |= Rs << 16;
10847 encode_thumb32_shifted_operand (2);
a737bd4d 10848 }
b99bd4ef 10849 }
c19d1205
ZW
10850 else
10851 {
10852 /* On its face this is a lie - the instruction does set the
10853 flags. However, the only supported mnemonic in this mode
10854 says it doesn't. */
10855 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10856
c19d1205
ZW
10857 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10858 _("unshifted register required"));
10859 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10860
10861 inst.instruction = THUMB_OP16 (inst.instruction);
10862 inst.instruction |= Rd;
10863
10864 if (Rd == Rs)
10865 inst.instruction |= Rn << 3;
10866 else if (Rd == Rn)
10867 inst.instruction |= Rs << 3;
10868 else
10869 constraint (1, _("dest must overlap one source register"));
10870 }
a737bd4d
NC
10871}
10872
c19d1205
ZW
10873static void
10874do_t_bfc (void)
a737bd4d 10875{
fdfde340 10876 unsigned Rd;
c19d1205
ZW
10877 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10878 constraint (msb > 32, _("bit-field extends past end of register"));
10879 /* The instruction encoding stores the LSB and MSB,
10880 not the LSB and width. */
fdfde340
JM
10881 Rd = inst.operands[0].reg;
10882 reject_bad_reg (Rd);
10883 inst.instruction |= Rd << 8;
c19d1205
ZW
10884 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10885 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10886 inst.instruction |= msb - 1;
b99bd4ef
NC
10887}
10888
c19d1205
ZW
10889static void
10890do_t_bfi (void)
b99bd4ef 10891{
fdfde340 10892 int Rd, Rn;
c19d1205 10893 unsigned int msb;
b99bd4ef 10894
fdfde340
JM
10895 Rd = inst.operands[0].reg;
10896 reject_bad_reg (Rd);
10897
c19d1205
ZW
10898 /* #0 in second position is alternative syntax for bfc, which is
10899 the same instruction but with REG_PC in the Rm field. */
10900 if (!inst.operands[1].isreg)
fdfde340
JM
10901 Rn = REG_PC;
10902 else
10903 {
10904 Rn = inst.operands[1].reg;
10905 reject_bad_reg (Rn);
10906 }
b99bd4ef 10907
c19d1205
ZW
10908 msb = inst.operands[2].imm + inst.operands[3].imm;
10909 constraint (msb > 32, _("bit-field extends past end of register"));
10910 /* The instruction encoding stores the LSB and MSB,
10911 not the LSB and width. */
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 |= msb - 1;
b99bd4ef
NC
10917}
10918
c19d1205
ZW
10919static void
10920do_t_bfx (void)
b99bd4ef 10921{
fdfde340
JM
10922 unsigned Rd, Rn;
10923
10924 Rd = inst.operands[0].reg;
10925 Rn = inst.operands[1].reg;
10926
10927 reject_bad_reg (Rd);
10928 reject_bad_reg (Rn);
10929
c19d1205
ZW
10930 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10931 _("bit-field extends past end of register"));
fdfde340
JM
10932 inst.instruction |= Rd << 8;
10933 inst.instruction |= Rn << 16;
c19d1205
ZW
10934 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10935 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10936 inst.instruction |= inst.operands[3].imm - 1;
10937}
b99bd4ef 10938
c19d1205
ZW
10939/* ARM V5 Thumb BLX (argument parse)
10940 BLX <target_addr> which is BLX(1)
10941 BLX <Rm> which is BLX(2)
10942 Unfortunately, there are two different opcodes for this mnemonic.
10943 So, the insns[].value is not used, and the code here zaps values
10944 into inst.instruction.
b99bd4ef 10945
c19d1205
ZW
10946 ??? How to take advantage of the additional two bits of displacement
10947 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10948
c19d1205
ZW
10949static void
10950do_t_blx (void)
10951{
e07e6e58
NC
10952 set_it_insn_type_last ();
10953
c19d1205 10954 if (inst.operands[0].isreg)
fdfde340
JM
10955 {
10956 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10957 /* We have a register, so this is BLX(2). */
10958 inst.instruction |= inst.operands[0].reg << 3;
10959 }
b99bd4ef
NC
10960 else
10961 {
c19d1205 10962 /* No register. This must be BLX(1). */
2fc8bdac 10963 inst.instruction = 0xf000e800;
0855e32b 10964 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10965 }
10966}
10967
c19d1205
ZW
10968static void
10969do_t_branch (void)
b99bd4ef 10970{
0110f2b8 10971 int opcode;
dfa9f0d5 10972 int cond;
2fe88214 10973 bfd_reloc_code_real_type reloc;
dfa9f0d5 10974
e07e6e58
NC
10975 cond = inst.cond;
10976 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10977
10978 if (in_it_block ())
dfa9f0d5
PB
10979 {
10980 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10981 branches. */
dfa9f0d5 10982 cond = COND_ALWAYS;
dfa9f0d5
PB
10983 }
10984 else
10985 cond = inst.cond;
10986
10987 if (cond != COND_ALWAYS)
0110f2b8
PB
10988 opcode = T_MNEM_bcond;
10989 else
10990 opcode = inst.instruction;
10991
12d6b0b7
RS
10992 if (unified_syntax
10993 && (inst.size_req == 4
10960bfb
PB
10994 || (inst.size_req != 2
10995 && (inst.operands[0].hasreloc
10996 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10997 {
0110f2b8 10998 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10999 if (cond == COND_ALWAYS)
9ae92b05 11000 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11001 else
11002 {
ff8646ee
TP
11003 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11004 _("selected architecture does not support "
11005 "wide conditional branch instruction"));
11006
9c2799c2 11007 gas_assert (cond != 0xF);
dfa9f0d5 11008 inst.instruction |= cond << 22;
9ae92b05 11009 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11010 }
11011 }
b99bd4ef
NC
11012 else
11013 {
0110f2b8 11014 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11015 if (cond == COND_ALWAYS)
9ae92b05 11016 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11017 else
b99bd4ef 11018 {
dfa9f0d5 11019 inst.instruction |= cond << 8;
9ae92b05 11020 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11021 }
0110f2b8
PB
11022 /* Allow section relaxation. */
11023 if (unified_syntax && inst.size_req != 2)
11024 inst.relax = opcode;
b99bd4ef 11025 }
9ae92b05 11026 inst.reloc.type = reloc;
c19d1205 11027 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11028}
11029
8884b720 11030/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11031 between the two is the maximum immediate allowed - which is passed in
8884b720 11032 RANGE. */
b99bd4ef 11033static void
8884b720 11034do_t_bkpt_hlt1 (int range)
b99bd4ef 11035{
dfa9f0d5
PB
11036 constraint (inst.cond != COND_ALWAYS,
11037 _("instruction is always unconditional"));
c19d1205 11038 if (inst.operands[0].present)
b99bd4ef 11039 {
8884b720 11040 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11041 _("immediate value out of range"));
11042 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11043 }
8884b720
MGD
11044
11045 set_it_insn_type (NEUTRAL_IT_INSN);
11046}
11047
11048static void
11049do_t_hlt (void)
11050{
11051 do_t_bkpt_hlt1 (63);
11052}
11053
11054static void
11055do_t_bkpt (void)
11056{
11057 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11058}
11059
11060static void
c19d1205 11061do_t_branch23 (void)
b99bd4ef 11062{
e07e6e58 11063 set_it_insn_type_last ();
0855e32b 11064 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11065
0855e32b
NS
11066 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11067 this file. We used to simply ignore the PLT reloc type here --
11068 the branch encoding is now needed to deal with TLSCALL relocs.
11069 So if we see a PLT reloc now, put it back to how it used to be to
11070 keep the preexisting behaviour. */
11071 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11072 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11073
4343666d 11074#if defined(OBJ_COFF)
c19d1205
ZW
11075 /* If the destination of the branch is a defined symbol which does not have
11076 the THUMB_FUNC attribute, then we must be calling a function which has
11077 the (interfacearm) attribute. We look for the Thumb entry point to that
11078 function and change the branch to refer to that function instead. */
11079 if ( inst.reloc.exp.X_op == O_symbol
11080 && inst.reloc.exp.X_add_symbol != NULL
11081 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11082 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11083 inst.reloc.exp.X_add_symbol =
11084 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11085#endif
90e4755a
RE
11086}
11087
11088static void
c19d1205 11089do_t_bx (void)
90e4755a 11090{
e07e6e58 11091 set_it_insn_type_last ();
c19d1205
ZW
11092 inst.instruction |= inst.operands[0].reg << 3;
11093 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11094 should cause the alignment to be checked once it is known. This is
11095 because BX PC only works if the instruction is word aligned. */
11096}
90e4755a 11097
c19d1205
ZW
11098static void
11099do_t_bxj (void)
11100{
fdfde340 11101 int Rm;
90e4755a 11102
e07e6e58 11103 set_it_insn_type_last ();
fdfde340
JM
11104 Rm = inst.operands[0].reg;
11105 reject_bad_reg (Rm);
11106 inst.instruction |= Rm << 16;
90e4755a
RE
11107}
11108
11109static void
c19d1205 11110do_t_clz (void)
90e4755a 11111{
fdfde340
JM
11112 unsigned Rd;
11113 unsigned Rm;
11114
11115 Rd = inst.operands[0].reg;
11116 Rm = inst.operands[1].reg;
11117
11118 reject_bad_reg (Rd);
11119 reject_bad_reg (Rm);
11120
11121 inst.instruction |= Rd << 8;
11122 inst.instruction |= Rm << 16;
11123 inst.instruction |= Rm;
c19d1205 11124}
90e4755a 11125
dfa9f0d5
PB
11126static void
11127do_t_cps (void)
11128{
e07e6e58 11129 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11130 inst.instruction |= inst.operands[0].imm;
11131}
11132
c19d1205
ZW
11133static void
11134do_t_cpsi (void)
11135{
e07e6e58 11136 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11137 if (unified_syntax
62b3e311
PB
11138 && (inst.operands[1].present || inst.size_req == 4)
11139 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11140 {
c19d1205
ZW
11141 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11142 inst.instruction = 0xf3af8000;
11143 inst.instruction |= imod << 9;
11144 inst.instruction |= inst.operands[0].imm << 5;
11145 if (inst.operands[1].present)
11146 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11147 }
c19d1205 11148 else
90e4755a 11149 {
62b3e311
PB
11150 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11151 && (inst.operands[0].imm & 4),
11152 _("selected processor does not support 'A' form "
11153 "of this instruction"));
11154 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11155 _("Thumb does not support the 2-argument "
11156 "form of this instruction"));
11157 inst.instruction |= inst.operands[0].imm;
90e4755a 11158 }
90e4755a
RE
11159}
11160
c19d1205
ZW
11161/* THUMB CPY instruction (argument parse). */
11162
90e4755a 11163static void
c19d1205 11164do_t_cpy (void)
90e4755a 11165{
c19d1205 11166 if (inst.size_req == 4)
90e4755a 11167 {
c19d1205
ZW
11168 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11169 inst.instruction |= inst.operands[0].reg << 8;
11170 inst.instruction |= inst.operands[1].reg;
90e4755a 11171 }
c19d1205 11172 else
90e4755a 11173 {
c19d1205
ZW
11174 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11175 inst.instruction |= (inst.operands[0].reg & 0x7);
11176 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11177 }
90e4755a
RE
11178}
11179
90e4755a 11180static void
25fe350b 11181do_t_cbz (void)
90e4755a 11182{
e07e6e58 11183 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11184 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11185 inst.instruction |= inst.operands[0].reg;
11186 inst.reloc.pc_rel = 1;
11187 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11188}
90e4755a 11189
62b3e311
PB
11190static void
11191do_t_dbg (void)
11192{
11193 inst.instruction |= inst.operands[0].imm;
11194}
11195
11196static void
11197do_t_div (void)
11198{
fdfde340
JM
11199 unsigned Rd, Rn, Rm;
11200
11201 Rd = inst.operands[0].reg;
11202 Rn = (inst.operands[1].present
11203 ? inst.operands[1].reg : Rd);
11204 Rm = inst.operands[2].reg;
11205
11206 reject_bad_reg (Rd);
11207 reject_bad_reg (Rn);
11208 reject_bad_reg (Rm);
11209
11210 inst.instruction |= Rd << 8;
11211 inst.instruction |= Rn << 16;
11212 inst.instruction |= Rm;
62b3e311
PB
11213}
11214
c19d1205
ZW
11215static void
11216do_t_hint (void)
11217{
11218 if (unified_syntax && inst.size_req == 4)
11219 inst.instruction = THUMB_OP32 (inst.instruction);
11220 else
11221 inst.instruction = THUMB_OP16 (inst.instruction);
11222}
90e4755a 11223
c19d1205
ZW
11224static void
11225do_t_it (void)
11226{
11227 unsigned int cond = inst.operands[0].imm;
e27ec89e 11228
e07e6e58
NC
11229 set_it_insn_type (IT_INSN);
11230 now_it.mask = (inst.instruction & 0xf) | 0x10;
11231 now_it.cc = cond;
5a01bb1d 11232 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11233
11234 /* If the condition is a negative condition, invert the mask. */
c19d1205 11235 if ((cond & 0x1) == 0x0)
90e4755a 11236 {
c19d1205 11237 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11238
c19d1205 11239 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11240 {
11241 /* No conversion needed. */
11242 now_it.block_length = 1;
11243 }
c19d1205 11244 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11245 {
11246 mask ^= 0x8;
11247 now_it.block_length = 2;
11248 }
e27ec89e 11249 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11250 {
11251 mask ^= 0xC;
11252 now_it.block_length = 3;
11253 }
c19d1205 11254 else
5a01bb1d
MGD
11255 {
11256 mask ^= 0xE;
11257 now_it.block_length = 4;
11258 }
90e4755a 11259
e27ec89e
PB
11260 inst.instruction &= 0xfff0;
11261 inst.instruction |= mask;
c19d1205 11262 }
90e4755a 11263
c19d1205
ZW
11264 inst.instruction |= cond << 4;
11265}
90e4755a 11266
3c707909
PB
11267/* Helper function used for both push/pop and ldm/stm. */
11268static void
11269encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11270{
11271 bfd_boolean load;
11272
11273 load = (inst.instruction & (1 << 20)) != 0;
11274
11275 if (mask & (1 << 13))
11276 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11277
11278 if ((mask & (1 << base)) != 0
11279 && writeback)
11280 inst.error = _("having the base register in the register list when "
11281 "using write back is UNPREDICTABLE");
11282
3c707909
PB
11283 if (load)
11284 {
e07e6e58 11285 if (mask & (1 << 15))
477330fc
RM
11286 {
11287 if (mask & (1 << 14))
11288 inst.error = _("LR and PC should not both be in register list");
11289 else
11290 set_it_insn_type_last ();
11291 }
3c707909
PB
11292 }
11293 else
11294 {
11295 if (mask & (1 << 15))
11296 inst.error = _("PC not allowed in register list");
3c707909
PB
11297 }
11298
11299 if ((mask & (mask - 1)) == 0)
11300 {
11301 /* Single register transfers implemented as str/ldr. */
11302 if (writeback)
11303 {
11304 if (inst.instruction & (1 << 23))
11305 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11306 else
11307 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11308 }
11309 else
11310 {
11311 if (inst.instruction & (1 << 23))
11312 inst.instruction = 0x00800000; /* ia -> [base] */
11313 else
11314 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11315 }
11316
11317 inst.instruction |= 0xf8400000;
11318 if (load)
11319 inst.instruction |= 0x00100000;
11320
5f4273c7 11321 mask = ffs (mask) - 1;
3c707909
PB
11322 mask <<= 12;
11323 }
11324 else if (writeback)
11325 inst.instruction |= WRITE_BACK;
11326
11327 inst.instruction |= mask;
11328 inst.instruction |= base << 16;
11329}
11330
c19d1205
ZW
11331static void
11332do_t_ldmstm (void)
11333{
11334 /* This really doesn't seem worth it. */
11335 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11336 _("expression too complex"));
11337 constraint (inst.operands[1].writeback,
11338 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11339
c19d1205
ZW
11340 if (unified_syntax)
11341 {
3c707909
PB
11342 bfd_boolean narrow;
11343 unsigned mask;
11344
11345 narrow = FALSE;
c19d1205
ZW
11346 /* See if we can use a 16-bit instruction. */
11347 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11348 && inst.size_req != 4
3c707909 11349 && !(inst.operands[1].imm & ~0xff))
90e4755a 11350 {
3c707909 11351 mask = 1 << inst.operands[0].reg;
90e4755a 11352
eab4f823 11353 if (inst.operands[0].reg <= 7)
90e4755a 11354 {
3c707909 11355 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11356 ? inst.operands[0].writeback
11357 : (inst.operands[0].writeback
11358 == !(inst.operands[1].imm & mask)))
477330fc 11359 {
eab4f823
MGD
11360 if (inst.instruction == T_MNEM_stmia
11361 && (inst.operands[1].imm & mask)
11362 && (inst.operands[1].imm & (mask - 1)))
11363 as_warn (_("value stored for r%d is UNKNOWN"),
11364 inst.operands[0].reg);
3c707909 11365
eab4f823
MGD
11366 inst.instruction = THUMB_OP16 (inst.instruction);
11367 inst.instruction |= inst.operands[0].reg << 8;
11368 inst.instruction |= inst.operands[1].imm;
11369 narrow = TRUE;
11370 }
11371 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11372 {
11373 /* This means 1 register in reg list one of 3 situations:
11374 1. Instruction is stmia, but without writeback.
11375 2. lmdia without writeback, but with Rn not in
477330fc 11376 reglist.
eab4f823
MGD
11377 3. ldmia with writeback, but with Rn in reglist.
11378 Case 3 is UNPREDICTABLE behaviour, so we handle
11379 case 1 and 2 which can be converted into a 16-bit
11380 str or ldr. The SP cases are handled below. */
11381 unsigned long opcode;
11382 /* First, record an error for Case 3. */
11383 if (inst.operands[1].imm & mask
11384 && inst.operands[0].writeback)
fa94de6b 11385 inst.error =
eab4f823
MGD
11386 _("having the base register in the register list when "
11387 "using write back is UNPREDICTABLE");
fa94de6b
RM
11388
11389 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11390 : T_MNEM_ldr);
11391 inst.instruction = THUMB_OP16 (opcode);
11392 inst.instruction |= inst.operands[0].reg << 3;
11393 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11394 narrow = TRUE;
11395 }
90e4755a 11396 }
eab4f823 11397 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11398 {
eab4f823
MGD
11399 if (inst.operands[0].writeback)
11400 {
fa94de6b 11401 inst.instruction =
eab4f823 11402 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11403 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11404 inst.instruction |= inst.operands[1].imm;
477330fc 11405 narrow = TRUE;
eab4f823
MGD
11406 }
11407 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11408 {
fa94de6b 11409 inst.instruction =
eab4f823 11410 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11411 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11412 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11413 narrow = TRUE;
eab4f823 11414 }
90e4755a 11415 }
3c707909
PB
11416 }
11417
11418 if (!narrow)
11419 {
c19d1205
ZW
11420 if (inst.instruction < 0xffff)
11421 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11422
5f4273c7
NC
11423 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11424 inst.operands[0].writeback);
90e4755a
RE
11425 }
11426 }
c19d1205 11427 else
90e4755a 11428 {
c19d1205
ZW
11429 constraint (inst.operands[0].reg > 7
11430 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11431 constraint (inst.instruction != T_MNEM_ldmia
11432 && inst.instruction != T_MNEM_stmia,
11433 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11434 if (inst.instruction == T_MNEM_stmia)
f03698e6 11435 {
c19d1205
ZW
11436 if (!inst.operands[0].writeback)
11437 as_warn (_("this instruction will write back the base register"));
11438 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11439 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11440 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11441 inst.operands[0].reg);
f03698e6 11442 }
c19d1205 11443 else
90e4755a 11444 {
c19d1205
ZW
11445 if (!inst.operands[0].writeback
11446 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11447 as_warn (_("this instruction will write back the base register"));
11448 else if (inst.operands[0].writeback
11449 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11450 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11451 }
11452
c19d1205
ZW
11453 inst.instruction = THUMB_OP16 (inst.instruction);
11454 inst.instruction |= inst.operands[0].reg << 8;
11455 inst.instruction |= inst.operands[1].imm;
11456 }
11457}
e28cd48c 11458
c19d1205
ZW
11459static void
11460do_t_ldrex (void)
11461{
11462 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11463 || inst.operands[1].postind || inst.operands[1].writeback
11464 || inst.operands[1].immisreg || inst.operands[1].shifted
11465 || inst.operands[1].negative,
01cfc07f 11466 BAD_ADDR_MODE);
e28cd48c 11467
5be8be5d
DG
11468 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11469
c19d1205
ZW
11470 inst.instruction |= inst.operands[0].reg << 12;
11471 inst.instruction |= inst.operands[1].reg << 16;
11472 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11473}
e28cd48c 11474
c19d1205
ZW
11475static void
11476do_t_ldrexd (void)
11477{
11478 if (!inst.operands[1].present)
1cac9012 11479 {
c19d1205
ZW
11480 constraint (inst.operands[0].reg == REG_LR,
11481 _("r14 not allowed as first register "
11482 "when second register is omitted"));
11483 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11484 }
c19d1205
ZW
11485 constraint (inst.operands[0].reg == inst.operands[1].reg,
11486 BAD_OVERLAP);
b99bd4ef 11487
c19d1205
ZW
11488 inst.instruction |= inst.operands[0].reg << 12;
11489 inst.instruction |= inst.operands[1].reg << 8;
11490 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11491}
11492
11493static void
c19d1205 11494do_t_ldst (void)
b99bd4ef 11495{
0110f2b8
PB
11496 unsigned long opcode;
11497 int Rn;
11498
e07e6e58
NC
11499 if (inst.operands[0].isreg
11500 && !inst.operands[0].preind
11501 && inst.operands[0].reg == REG_PC)
11502 set_it_insn_type_last ();
11503
0110f2b8 11504 opcode = inst.instruction;
c19d1205 11505 if (unified_syntax)
b99bd4ef 11506 {
53365c0d
PB
11507 if (!inst.operands[1].isreg)
11508 {
11509 if (opcode <= 0xffff)
11510 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11511 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11512 return;
11513 }
0110f2b8
PB
11514 if (inst.operands[1].isreg
11515 && !inst.operands[1].writeback
c19d1205
ZW
11516 && !inst.operands[1].shifted && !inst.operands[1].postind
11517 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11518 && opcode <= 0xffff
11519 && inst.size_req != 4)
c19d1205 11520 {
0110f2b8
PB
11521 /* Insn may have a 16-bit form. */
11522 Rn = inst.operands[1].reg;
11523 if (inst.operands[1].immisreg)
11524 {
11525 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11526 /* [Rn, Rik] */
0110f2b8
PB
11527 if (Rn <= 7 && inst.operands[1].imm <= 7)
11528 goto op16;
5be8be5d
DG
11529 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11530 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11531 }
11532 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11533 && opcode != T_MNEM_ldrsb)
11534 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11535 || (Rn == REG_SP && opcode == T_MNEM_str))
11536 {
11537 /* [Rn, #const] */
11538 if (Rn > 7)
11539 {
11540 if (Rn == REG_PC)
11541 {
11542 if (inst.reloc.pc_rel)
11543 opcode = T_MNEM_ldr_pc2;
11544 else
11545 opcode = T_MNEM_ldr_pc;
11546 }
11547 else
11548 {
11549 if (opcode == T_MNEM_ldr)
11550 opcode = T_MNEM_ldr_sp;
11551 else
11552 opcode = T_MNEM_str_sp;
11553 }
11554 inst.instruction = inst.operands[0].reg << 8;
11555 }
11556 else
11557 {
11558 inst.instruction = inst.operands[0].reg;
11559 inst.instruction |= inst.operands[1].reg << 3;
11560 }
11561 inst.instruction |= THUMB_OP16 (opcode);
11562 if (inst.size_req == 2)
11563 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11564 else
11565 inst.relax = opcode;
11566 return;
11567 }
c19d1205 11568 }
0110f2b8 11569 /* Definitely a 32-bit variant. */
5be8be5d 11570
8d67f500
NC
11571 /* Warning for Erratum 752419. */
11572 if (opcode == T_MNEM_ldr
11573 && inst.operands[0].reg == REG_SP
11574 && inst.operands[1].writeback == 1
11575 && !inst.operands[1].immisreg)
11576 {
11577 if (no_cpu_selected ()
11578 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11579 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11580 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11581 as_warn (_("This instruction may be unpredictable "
11582 "if executed on M-profile cores "
11583 "with interrupts enabled."));
11584 }
11585
5be8be5d 11586 /* Do some validations regarding addressing modes. */
1be5fd2e 11587 if (inst.operands[1].immisreg)
5be8be5d
DG
11588 reject_bad_reg (inst.operands[1].imm);
11589
1be5fd2e
NC
11590 constraint (inst.operands[1].writeback == 1
11591 && inst.operands[0].reg == inst.operands[1].reg,
11592 BAD_OVERLAP);
11593
0110f2b8 11594 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11595 inst.instruction |= inst.operands[0].reg << 12;
11596 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11597 check_ldr_r15_aligned ();
b99bd4ef
NC
11598 return;
11599 }
11600
c19d1205
ZW
11601 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11602
11603 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11604 {
c19d1205
ZW
11605 /* Only [Rn,Rm] is acceptable. */
11606 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11607 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11608 || inst.operands[1].postind || inst.operands[1].shifted
11609 || inst.operands[1].negative,
11610 _("Thumb does not support this addressing mode"));
11611 inst.instruction = THUMB_OP16 (inst.instruction);
11612 goto op16;
b99bd4ef 11613 }
5f4273c7 11614
c19d1205
ZW
11615 inst.instruction = THUMB_OP16 (inst.instruction);
11616 if (!inst.operands[1].isreg)
8335d6aa 11617 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11618 return;
b99bd4ef 11619
c19d1205
ZW
11620 constraint (!inst.operands[1].preind
11621 || inst.operands[1].shifted
11622 || inst.operands[1].writeback,
11623 _("Thumb does not support this addressing mode"));
11624 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11625 {
c19d1205
ZW
11626 constraint (inst.instruction & 0x0600,
11627 _("byte or halfword not valid for base register"));
11628 constraint (inst.operands[1].reg == REG_PC
11629 && !(inst.instruction & THUMB_LOAD_BIT),
11630 _("r15 based store not allowed"));
11631 constraint (inst.operands[1].immisreg,
11632 _("invalid base register for register offset"));
b99bd4ef 11633
c19d1205
ZW
11634 if (inst.operands[1].reg == REG_PC)
11635 inst.instruction = T_OPCODE_LDR_PC;
11636 else if (inst.instruction & THUMB_LOAD_BIT)
11637 inst.instruction = T_OPCODE_LDR_SP;
11638 else
11639 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11640
c19d1205
ZW
11641 inst.instruction |= inst.operands[0].reg << 8;
11642 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11643 return;
11644 }
90e4755a 11645
c19d1205
ZW
11646 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11647 if (!inst.operands[1].immisreg)
11648 {
11649 /* Immediate offset. */
11650 inst.instruction |= inst.operands[0].reg;
11651 inst.instruction |= inst.operands[1].reg << 3;
11652 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11653 return;
11654 }
90e4755a 11655
c19d1205
ZW
11656 /* Register offset. */
11657 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11658 constraint (inst.operands[1].negative,
11659 _("Thumb does not support this addressing mode"));
90e4755a 11660
c19d1205
ZW
11661 op16:
11662 switch (inst.instruction)
11663 {
11664 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11665 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11666 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11667 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11668 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11669 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11670 case 0x5600 /* ldrsb */:
11671 case 0x5e00 /* ldrsh */: break;
11672 default: abort ();
11673 }
90e4755a 11674
c19d1205
ZW
11675 inst.instruction |= inst.operands[0].reg;
11676 inst.instruction |= inst.operands[1].reg << 3;
11677 inst.instruction |= inst.operands[1].imm << 6;
11678}
90e4755a 11679
c19d1205
ZW
11680static void
11681do_t_ldstd (void)
11682{
11683 if (!inst.operands[1].present)
b99bd4ef 11684 {
c19d1205
ZW
11685 inst.operands[1].reg = inst.operands[0].reg + 1;
11686 constraint (inst.operands[0].reg == REG_LR,
11687 _("r14 not allowed here"));
bd340a04 11688 constraint (inst.operands[0].reg == REG_R12,
477330fc 11689 _("r12 not allowed here"));
b99bd4ef 11690 }
bd340a04
MGD
11691
11692 if (inst.operands[2].writeback
11693 && (inst.operands[0].reg == inst.operands[2].reg
11694 || inst.operands[1].reg == inst.operands[2].reg))
11695 as_warn (_("base register written back, and overlaps "
477330fc 11696 "one of transfer registers"));
bd340a04 11697
c19d1205
ZW
11698 inst.instruction |= inst.operands[0].reg << 12;
11699 inst.instruction |= inst.operands[1].reg << 8;
11700 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11701}
11702
c19d1205
ZW
11703static void
11704do_t_ldstt (void)
11705{
11706 inst.instruction |= inst.operands[0].reg << 12;
11707 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11708}
a737bd4d 11709
b99bd4ef 11710static void
c19d1205 11711do_t_mla (void)
b99bd4ef 11712{
fdfde340 11713 unsigned Rd, Rn, Rm, Ra;
c921be7d 11714
fdfde340
JM
11715 Rd = inst.operands[0].reg;
11716 Rn = inst.operands[1].reg;
11717 Rm = inst.operands[2].reg;
11718 Ra = inst.operands[3].reg;
11719
11720 reject_bad_reg (Rd);
11721 reject_bad_reg (Rn);
11722 reject_bad_reg (Rm);
11723 reject_bad_reg (Ra);
11724
11725 inst.instruction |= Rd << 8;
11726 inst.instruction |= Rn << 16;
11727 inst.instruction |= Rm;
11728 inst.instruction |= Ra << 12;
c19d1205 11729}
b99bd4ef 11730
c19d1205
ZW
11731static void
11732do_t_mlal (void)
11733{
fdfde340
JM
11734 unsigned RdLo, RdHi, Rn, Rm;
11735
11736 RdLo = inst.operands[0].reg;
11737 RdHi = inst.operands[1].reg;
11738 Rn = inst.operands[2].reg;
11739 Rm = inst.operands[3].reg;
11740
11741 reject_bad_reg (RdLo);
11742 reject_bad_reg (RdHi);
11743 reject_bad_reg (Rn);
11744 reject_bad_reg (Rm);
11745
11746 inst.instruction |= RdLo << 12;
11747 inst.instruction |= RdHi << 8;
11748 inst.instruction |= Rn << 16;
11749 inst.instruction |= Rm;
c19d1205 11750}
b99bd4ef 11751
c19d1205
ZW
11752static void
11753do_t_mov_cmp (void)
11754{
fdfde340
JM
11755 unsigned Rn, Rm;
11756
11757 Rn = inst.operands[0].reg;
11758 Rm = inst.operands[1].reg;
11759
e07e6e58
NC
11760 if (Rn == REG_PC)
11761 set_it_insn_type_last ();
11762
c19d1205 11763 if (unified_syntax)
b99bd4ef 11764 {
c19d1205
ZW
11765 int r0off = (inst.instruction == T_MNEM_mov
11766 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11767 unsigned long opcode;
3d388997
PB
11768 bfd_boolean narrow;
11769 bfd_boolean low_regs;
11770
fdfde340 11771 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11772 opcode = inst.instruction;
e07e6e58 11773 if (in_it_block ())
0110f2b8 11774 narrow = opcode != T_MNEM_movs;
3d388997 11775 else
0110f2b8 11776 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11777 if (inst.size_req == 4
11778 || inst.operands[1].shifted)
11779 narrow = FALSE;
11780
efd81785
PB
11781 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11782 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11783 && !inst.operands[1].shifted
fdfde340
JM
11784 && Rn == REG_PC
11785 && Rm == REG_LR)
efd81785
PB
11786 {
11787 inst.instruction = T2_SUBS_PC_LR;
11788 return;
11789 }
11790
fdfde340
JM
11791 if (opcode == T_MNEM_cmp)
11792 {
11793 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11794 if (narrow)
11795 {
11796 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11797 but valid. */
11798 warn_deprecated_sp (Rm);
11799 /* R15 was documented as a valid choice for Rm in ARMv6,
11800 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11801 tools reject R15, so we do too. */
11802 constraint (Rm == REG_PC, BAD_PC);
11803 }
11804 else
11805 reject_bad_reg (Rm);
fdfde340
JM
11806 }
11807 else if (opcode == T_MNEM_mov
11808 || opcode == T_MNEM_movs)
11809 {
11810 if (inst.operands[1].isreg)
11811 {
11812 if (opcode == T_MNEM_movs)
11813 {
11814 reject_bad_reg (Rn);
11815 reject_bad_reg (Rm);
11816 }
76fa04a4
MGD
11817 else if (narrow)
11818 {
11819 /* This is mov.n. */
11820 if ((Rn == REG_SP || Rn == REG_PC)
11821 && (Rm == REG_SP || Rm == REG_PC))
11822 {
5c3696f8 11823 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11824 "deprecated when r%u is the destination "
11825 "register."), Rm, Rn);
11826 }
11827 }
11828 else
11829 {
11830 /* This is mov.w. */
11831 constraint (Rn == REG_PC, BAD_PC);
11832 constraint (Rm == REG_PC, BAD_PC);
11833 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11834 }
fdfde340
JM
11835 }
11836 else
11837 reject_bad_reg (Rn);
11838 }
11839
c19d1205
ZW
11840 if (!inst.operands[1].isreg)
11841 {
0110f2b8 11842 /* Immediate operand. */
e07e6e58 11843 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11844 narrow = 0;
11845 if (low_regs && narrow)
11846 {
11847 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11848 inst.instruction |= Rn << 8;
a9f02af8
MG
11849 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11850 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11851 {
a9f02af8 11852 if (inst.size_req == 2)
72d98d16 11853 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11854 else
11855 inst.relax = opcode;
72d98d16 11856 }
0110f2b8
PB
11857 }
11858 else
11859 {
a9f02af8
MG
11860 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11861 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11862 THUMB1_RELOC_ONLY);
11863
0110f2b8
PB
11864 inst.instruction = THUMB_OP32 (inst.instruction);
11865 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11866 inst.instruction |= Rn << r0off;
0110f2b8
PB
11867 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11868 }
c19d1205 11869 }
728ca7c9
PB
11870 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11871 && (inst.instruction == T_MNEM_mov
11872 || inst.instruction == T_MNEM_movs))
11873 {
11874 /* Register shifts are encoded as separate shift instructions. */
11875 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11876
e07e6e58 11877 if (in_it_block ())
728ca7c9
PB
11878 narrow = !flags;
11879 else
11880 narrow = flags;
11881
11882 if (inst.size_req == 4)
11883 narrow = FALSE;
11884
11885 if (!low_regs || inst.operands[1].imm > 7)
11886 narrow = FALSE;
11887
fdfde340 11888 if (Rn != Rm)
728ca7c9
PB
11889 narrow = FALSE;
11890
11891 switch (inst.operands[1].shift_kind)
11892 {
11893 case SHIFT_LSL:
11894 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11895 break;
11896 case SHIFT_ASR:
11897 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11898 break;
11899 case SHIFT_LSR:
11900 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11901 break;
11902 case SHIFT_ROR:
11903 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11904 break;
11905 default:
5f4273c7 11906 abort ();
728ca7c9
PB
11907 }
11908
11909 inst.instruction = opcode;
11910 if (narrow)
11911 {
fdfde340 11912 inst.instruction |= Rn;
728ca7c9
PB
11913 inst.instruction |= inst.operands[1].imm << 3;
11914 }
11915 else
11916 {
11917 if (flags)
11918 inst.instruction |= CONDS_BIT;
11919
fdfde340
JM
11920 inst.instruction |= Rn << 8;
11921 inst.instruction |= Rm << 16;
728ca7c9
PB
11922 inst.instruction |= inst.operands[1].imm;
11923 }
11924 }
3d388997 11925 else if (!narrow)
c19d1205 11926 {
728ca7c9
PB
11927 /* Some mov with immediate shift have narrow variants.
11928 Register shifts are handled above. */
11929 if (low_regs && inst.operands[1].shifted
11930 && (inst.instruction == T_MNEM_mov
11931 || inst.instruction == T_MNEM_movs))
11932 {
e07e6e58 11933 if (in_it_block ())
728ca7c9
PB
11934 narrow = (inst.instruction == T_MNEM_mov);
11935 else
11936 narrow = (inst.instruction == T_MNEM_movs);
11937 }
11938
11939 if (narrow)
11940 {
11941 switch (inst.operands[1].shift_kind)
11942 {
11943 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11944 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11945 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11946 default: narrow = FALSE; break;
11947 }
11948 }
11949
11950 if (narrow)
11951 {
fdfde340
JM
11952 inst.instruction |= Rn;
11953 inst.instruction |= Rm << 3;
728ca7c9
PB
11954 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11955 }
11956 else
11957 {
11958 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11959 inst.instruction |= Rn << r0off;
728ca7c9
PB
11960 encode_thumb32_shifted_operand (1);
11961 }
c19d1205
ZW
11962 }
11963 else
11964 switch (inst.instruction)
11965 {
11966 case T_MNEM_mov:
837b3435 11967 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11968 results. Don't allow this. */
11969 if (low_regs)
11970 {
11971 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11972 "MOV Rd, Rs with two low registers is not "
11973 "permitted on this architecture");
fa94de6b 11974 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11975 arm_ext_v6);
11976 }
11977
c19d1205 11978 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11979 inst.instruction |= (Rn & 0x8) << 4;
11980 inst.instruction |= (Rn & 0x7);
11981 inst.instruction |= Rm << 3;
c19d1205 11982 break;
b99bd4ef 11983
c19d1205
ZW
11984 case T_MNEM_movs:
11985 /* We know we have low registers at this point.
941a8a52
MGD
11986 Generate LSLS Rd, Rs, #0. */
11987 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11988 inst.instruction |= Rn;
11989 inst.instruction |= Rm << 3;
c19d1205
ZW
11990 break;
11991
11992 case T_MNEM_cmp:
3d388997 11993 if (low_regs)
c19d1205
ZW
11994 {
11995 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11996 inst.instruction |= Rn;
11997 inst.instruction |= Rm << 3;
c19d1205
ZW
11998 }
11999 else
12000 {
12001 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12002 inst.instruction |= (Rn & 0x8) << 4;
12003 inst.instruction |= (Rn & 0x7);
12004 inst.instruction |= Rm << 3;
c19d1205
ZW
12005 }
12006 break;
12007 }
b99bd4ef
NC
12008 return;
12009 }
12010
c19d1205 12011 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12012
12013 /* PR 10443: Do not silently ignore shifted operands. */
12014 constraint (inst.operands[1].shifted,
12015 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12016
c19d1205 12017 if (inst.operands[1].isreg)
b99bd4ef 12018 {
fdfde340 12019 if (Rn < 8 && Rm < 8)
b99bd4ef 12020 {
c19d1205
ZW
12021 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12022 since a MOV instruction produces unpredictable results. */
12023 if (inst.instruction == T_OPCODE_MOV_I8)
12024 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12025 else
c19d1205 12026 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12027
fdfde340
JM
12028 inst.instruction |= Rn;
12029 inst.instruction |= Rm << 3;
b99bd4ef
NC
12030 }
12031 else
12032 {
c19d1205
ZW
12033 if (inst.instruction == T_OPCODE_MOV_I8)
12034 inst.instruction = T_OPCODE_MOV_HR;
12035 else
12036 inst.instruction = T_OPCODE_CMP_HR;
12037 do_t_cpy ();
b99bd4ef
NC
12038 }
12039 }
c19d1205 12040 else
b99bd4ef 12041 {
fdfde340 12042 constraint (Rn > 7,
c19d1205 12043 _("only lo regs allowed with immediate"));
fdfde340 12044 inst.instruction |= Rn << 8;
c19d1205
ZW
12045 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12046 }
12047}
b99bd4ef 12048
c19d1205
ZW
12049static void
12050do_t_mov16 (void)
12051{
fdfde340 12052 unsigned Rd;
b6895b4f
PB
12053 bfd_vma imm;
12054 bfd_boolean top;
12055
12056 top = (inst.instruction & 0x00800000) != 0;
12057 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12058 {
12059 constraint (top, _(":lower16: not allowed this instruction"));
12060 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12061 }
12062 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12063 {
12064 constraint (!top, _(":upper16: not allowed this instruction"));
12065 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12066 }
12067
fdfde340
JM
12068 Rd = inst.operands[0].reg;
12069 reject_bad_reg (Rd);
12070
12071 inst.instruction |= Rd << 8;
b6895b4f
PB
12072 if (inst.reloc.type == BFD_RELOC_UNUSED)
12073 {
12074 imm = inst.reloc.exp.X_add_number;
12075 inst.instruction |= (imm & 0xf000) << 4;
12076 inst.instruction |= (imm & 0x0800) << 15;
12077 inst.instruction |= (imm & 0x0700) << 4;
12078 inst.instruction |= (imm & 0x00ff);
12079 }
c19d1205 12080}
b99bd4ef 12081
c19d1205
ZW
12082static void
12083do_t_mvn_tst (void)
12084{
fdfde340 12085 unsigned Rn, Rm;
c921be7d 12086
fdfde340
JM
12087 Rn = inst.operands[0].reg;
12088 Rm = inst.operands[1].reg;
12089
12090 if (inst.instruction == T_MNEM_cmp
12091 || inst.instruction == T_MNEM_cmn)
12092 constraint (Rn == REG_PC, BAD_PC);
12093 else
12094 reject_bad_reg (Rn);
12095 reject_bad_reg (Rm);
12096
c19d1205
ZW
12097 if (unified_syntax)
12098 {
12099 int r0off = (inst.instruction == T_MNEM_mvn
12100 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12101 bfd_boolean narrow;
12102
12103 if (inst.size_req == 4
12104 || inst.instruction > 0xffff
12105 || inst.operands[1].shifted
fdfde340 12106 || Rn > 7 || Rm > 7)
3d388997 12107 narrow = FALSE;
fe8b4cc3
KT
12108 else if (inst.instruction == T_MNEM_cmn
12109 || inst.instruction == T_MNEM_tst)
3d388997
PB
12110 narrow = TRUE;
12111 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12112 narrow = !in_it_block ();
3d388997 12113 else
e07e6e58 12114 narrow = in_it_block ();
3d388997 12115
c19d1205 12116 if (!inst.operands[1].isreg)
b99bd4ef 12117 {
c19d1205
ZW
12118 /* For an immediate, we always generate a 32-bit opcode;
12119 section relaxation will shrink it later if possible. */
12120 if (inst.instruction < 0xffff)
12121 inst.instruction = THUMB_OP32 (inst.instruction);
12122 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12123 inst.instruction |= Rn << r0off;
c19d1205 12124 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12125 }
c19d1205 12126 else
b99bd4ef 12127 {
c19d1205 12128 /* See if we can do this with a 16-bit instruction. */
3d388997 12129 if (narrow)
b99bd4ef 12130 {
c19d1205 12131 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12132 inst.instruction |= Rn;
12133 inst.instruction |= Rm << 3;
b99bd4ef 12134 }
c19d1205 12135 else
b99bd4ef 12136 {
c19d1205
ZW
12137 constraint (inst.operands[1].shifted
12138 && inst.operands[1].immisreg,
12139 _("shift must be constant"));
12140 if (inst.instruction < 0xffff)
12141 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12142 inst.instruction |= Rn << r0off;
c19d1205 12143 encode_thumb32_shifted_operand (1);
b99bd4ef 12144 }
b99bd4ef
NC
12145 }
12146 }
12147 else
12148 {
c19d1205
ZW
12149 constraint (inst.instruction > 0xffff
12150 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12151 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12152 _("unshifted register required"));
fdfde340 12153 constraint (Rn > 7 || Rm > 7,
c19d1205 12154 BAD_HIREG);
b99bd4ef 12155
c19d1205 12156 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12157 inst.instruction |= Rn;
12158 inst.instruction |= Rm << 3;
b99bd4ef 12159 }
b99bd4ef
NC
12160}
12161
b05fe5cf 12162static void
c19d1205 12163do_t_mrs (void)
b05fe5cf 12164{
fdfde340 12165 unsigned Rd;
037e8744
JB
12166
12167 if (do_vfp_nsyn_mrs () == SUCCESS)
12168 return;
12169
90ec0d68
MGD
12170 Rd = inst.operands[0].reg;
12171 reject_bad_reg (Rd);
12172 inst.instruction |= Rd << 8;
12173
12174 if (inst.operands[1].isreg)
62b3e311 12175 {
90ec0d68
MGD
12176 unsigned br = inst.operands[1].reg;
12177 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12178 as_bad (_("bad register for mrs"));
12179
12180 inst.instruction |= br & (0xf << 16);
12181 inst.instruction |= (br & 0x300) >> 4;
12182 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12183 }
12184 else
12185 {
90ec0d68 12186 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12187
d2cd1205 12188 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12189 {
12190 /* PR gas/12698: The constraint is only applied for m_profile.
12191 If the user has specified -march=all, we want to ignore it as
12192 we are building for any CPU type, including non-m variants. */
823d2571
TG
12193 bfd_boolean m_profile =
12194 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12195 constraint ((flags != 0) && m_profile, _("selected processor does "
12196 "not support requested special purpose register"));
12197 }
90ec0d68 12198 else
d2cd1205
JB
12199 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12200 devices). */
12201 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12202 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12203
90ec0d68
MGD
12204 inst.instruction |= (flags & SPSR_BIT) >> 2;
12205 inst.instruction |= inst.operands[1].imm & 0xff;
12206 inst.instruction |= 0xf0000;
12207 }
c19d1205 12208}
b05fe5cf 12209
c19d1205
ZW
12210static void
12211do_t_msr (void)
12212{
62b3e311 12213 int flags;
fdfde340 12214 unsigned Rn;
62b3e311 12215
037e8744
JB
12216 if (do_vfp_nsyn_msr () == SUCCESS)
12217 return;
12218
c19d1205
ZW
12219 constraint (!inst.operands[1].isreg,
12220 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12221
12222 if (inst.operands[0].isreg)
12223 flags = (int)(inst.operands[0].reg);
12224 else
12225 flags = inst.operands[0].imm;
12226
d2cd1205 12227 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12228 {
d2cd1205
JB
12229 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12230
1a43faaf 12231 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12232 If the user has specified -march=all, we want to ignore it as
12233 we are building for any CPU type, including non-m variants. */
823d2571
TG
12234 bfd_boolean m_profile =
12235 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12236 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12237 && (bits & ~(PSR_s | PSR_f)) != 0)
12238 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12239 && bits != PSR_f)) && m_profile,
12240 _("selected processor does not support requested special "
12241 "purpose register"));
62b3e311
PB
12242 }
12243 else
d2cd1205
JB
12244 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12245 "requested special purpose register"));
c921be7d 12246
fdfde340
JM
12247 Rn = inst.operands[1].reg;
12248 reject_bad_reg (Rn);
12249
62b3e311 12250 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12251 inst.instruction |= (flags & 0xf0000) >> 8;
12252 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12253 inst.instruction |= (flags & 0xff);
fdfde340 12254 inst.instruction |= Rn << 16;
c19d1205 12255}
b05fe5cf 12256
c19d1205
ZW
12257static void
12258do_t_mul (void)
12259{
17828f45 12260 bfd_boolean narrow;
fdfde340 12261 unsigned Rd, Rn, Rm;
17828f45 12262
c19d1205
ZW
12263 if (!inst.operands[2].present)
12264 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12265
fdfde340
JM
12266 Rd = inst.operands[0].reg;
12267 Rn = inst.operands[1].reg;
12268 Rm = inst.operands[2].reg;
12269
17828f45 12270 if (unified_syntax)
b05fe5cf 12271 {
17828f45 12272 if (inst.size_req == 4
fdfde340
JM
12273 || (Rd != Rn
12274 && Rd != Rm)
12275 || Rn > 7
12276 || Rm > 7)
17828f45
JM
12277 narrow = FALSE;
12278 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12279 narrow = !in_it_block ();
17828f45 12280 else
e07e6e58 12281 narrow = in_it_block ();
b05fe5cf 12282 }
c19d1205 12283 else
b05fe5cf 12284 {
17828f45 12285 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12286 constraint (Rn > 7 || Rm > 7,
c19d1205 12287 BAD_HIREG);
17828f45
JM
12288 narrow = TRUE;
12289 }
b05fe5cf 12290
17828f45
JM
12291 if (narrow)
12292 {
12293 /* 16-bit MULS/Conditional MUL. */
c19d1205 12294 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12295 inst.instruction |= Rd;
b05fe5cf 12296
fdfde340
JM
12297 if (Rd == Rn)
12298 inst.instruction |= Rm << 3;
12299 else if (Rd == Rm)
12300 inst.instruction |= Rn << 3;
c19d1205
ZW
12301 else
12302 constraint (1, _("dest must overlap one source register"));
12303 }
17828f45
JM
12304 else
12305 {
e07e6e58
NC
12306 constraint (inst.instruction != T_MNEM_mul,
12307 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12308 /* 32-bit MUL. */
12309 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12310 inst.instruction |= Rd << 8;
12311 inst.instruction |= Rn << 16;
12312 inst.instruction |= Rm << 0;
12313
12314 reject_bad_reg (Rd);
12315 reject_bad_reg (Rn);
12316 reject_bad_reg (Rm);
17828f45 12317 }
c19d1205 12318}
b05fe5cf 12319
c19d1205
ZW
12320static void
12321do_t_mull (void)
12322{
fdfde340 12323 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12324
fdfde340
JM
12325 RdLo = inst.operands[0].reg;
12326 RdHi = inst.operands[1].reg;
12327 Rn = inst.operands[2].reg;
12328 Rm = inst.operands[3].reg;
12329
12330 reject_bad_reg (RdLo);
12331 reject_bad_reg (RdHi);
12332 reject_bad_reg (Rn);
12333 reject_bad_reg (Rm);
12334
12335 inst.instruction |= RdLo << 12;
12336 inst.instruction |= RdHi << 8;
12337 inst.instruction |= Rn << 16;
12338 inst.instruction |= Rm;
12339
12340 if (RdLo == RdHi)
c19d1205
ZW
12341 as_tsktsk (_("rdhi and rdlo must be different"));
12342}
b05fe5cf 12343
c19d1205
ZW
12344static void
12345do_t_nop (void)
12346{
e07e6e58
NC
12347 set_it_insn_type (NEUTRAL_IT_INSN);
12348
c19d1205
ZW
12349 if (unified_syntax)
12350 {
12351 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12352 {
c19d1205
ZW
12353 inst.instruction = THUMB_OP32 (inst.instruction);
12354 inst.instruction |= inst.operands[0].imm;
12355 }
12356 else
12357 {
bc2d1808
NC
12358 /* PR9722: Check for Thumb2 availability before
12359 generating a thumb2 nop instruction. */
afa62d5e 12360 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12361 {
12362 inst.instruction = THUMB_OP16 (inst.instruction);
12363 inst.instruction |= inst.operands[0].imm << 4;
12364 }
12365 else
12366 inst.instruction = 0x46c0;
c19d1205
ZW
12367 }
12368 }
12369 else
12370 {
12371 constraint (inst.operands[0].present,
12372 _("Thumb does not support NOP with hints"));
12373 inst.instruction = 0x46c0;
12374 }
12375}
b05fe5cf 12376
c19d1205
ZW
12377static void
12378do_t_neg (void)
12379{
12380 if (unified_syntax)
12381 {
3d388997
PB
12382 bfd_boolean narrow;
12383
12384 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12385 narrow = !in_it_block ();
3d388997 12386 else
e07e6e58 12387 narrow = in_it_block ();
3d388997
PB
12388 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12389 narrow = FALSE;
12390 if (inst.size_req == 4)
12391 narrow = FALSE;
12392
12393 if (!narrow)
c19d1205
ZW
12394 {
12395 inst.instruction = THUMB_OP32 (inst.instruction);
12396 inst.instruction |= inst.operands[0].reg << 8;
12397 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12398 }
12399 else
12400 {
c19d1205
ZW
12401 inst.instruction = THUMB_OP16 (inst.instruction);
12402 inst.instruction |= inst.operands[0].reg;
12403 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12404 }
12405 }
12406 else
12407 {
c19d1205
ZW
12408 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12409 BAD_HIREG);
12410 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12411
12412 inst.instruction = THUMB_OP16 (inst.instruction);
12413 inst.instruction |= inst.operands[0].reg;
12414 inst.instruction |= inst.operands[1].reg << 3;
12415 }
12416}
12417
1c444d06
JM
12418static void
12419do_t_orn (void)
12420{
12421 unsigned Rd, Rn;
12422
12423 Rd = inst.operands[0].reg;
12424 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12425
fdfde340
JM
12426 reject_bad_reg (Rd);
12427 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12428 reject_bad_reg (Rn);
12429
1c444d06
JM
12430 inst.instruction |= Rd << 8;
12431 inst.instruction |= Rn << 16;
12432
12433 if (!inst.operands[2].isreg)
12434 {
12435 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12436 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12437 }
12438 else
12439 {
12440 unsigned Rm;
12441
12442 Rm = inst.operands[2].reg;
fdfde340 12443 reject_bad_reg (Rm);
1c444d06
JM
12444
12445 constraint (inst.operands[2].shifted
12446 && inst.operands[2].immisreg,
12447 _("shift must be constant"));
12448 encode_thumb32_shifted_operand (2);
12449 }
12450}
12451
c19d1205
ZW
12452static void
12453do_t_pkhbt (void)
12454{
fdfde340
JM
12455 unsigned Rd, Rn, Rm;
12456
12457 Rd = inst.operands[0].reg;
12458 Rn = inst.operands[1].reg;
12459 Rm = inst.operands[2].reg;
12460
12461 reject_bad_reg (Rd);
12462 reject_bad_reg (Rn);
12463 reject_bad_reg (Rm);
12464
12465 inst.instruction |= Rd << 8;
12466 inst.instruction |= Rn << 16;
12467 inst.instruction |= Rm;
c19d1205
ZW
12468 if (inst.operands[3].present)
12469 {
12470 unsigned int val = inst.reloc.exp.X_add_number;
12471 constraint (inst.reloc.exp.X_op != O_constant,
12472 _("expression too complex"));
12473 inst.instruction |= (val & 0x1c) << 10;
12474 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12475 }
c19d1205 12476}
b05fe5cf 12477
c19d1205
ZW
12478static void
12479do_t_pkhtb (void)
12480{
12481 if (!inst.operands[3].present)
1ef52f49
NC
12482 {
12483 unsigned Rtmp;
12484
12485 inst.instruction &= ~0x00000020;
12486
12487 /* PR 10168. Swap the Rm and Rn registers. */
12488 Rtmp = inst.operands[1].reg;
12489 inst.operands[1].reg = inst.operands[2].reg;
12490 inst.operands[2].reg = Rtmp;
12491 }
c19d1205 12492 do_t_pkhbt ();
b05fe5cf
ZW
12493}
12494
c19d1205
ZW
12495static void
12496do_t_pld (void)
12497{
fdfde340
JM
12498 if (inst.operands[0].immisreg)
12499 reject_bad_reg (inst.operands[0].imm);
12500
c19d1205
ZW
12501 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12502}
b05fe5cf 12503
c19d1205
ZW
12504static void
12505do_t_push_pop (void)
b99bd4ef 12506{
e9f89963 12507 unsigned mask;
5f4273c7 12508
c19d1205
ZW
12509 constraint (inst.operands[0].writeback,
12510 _("push/pop do not support {reglist}^"));
12511 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12512 _("expression too complex"));
b99bd4ef 12513
e9f89963 12514 mask = inst.operands[0].imm;
d3bfe16e 12515 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12516 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12517 else if (inst.size_req != 4
c6025a80 12518 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12519 ? REG_LR : REG_PC)))
b99bd4ef 12520 {
c19d1205
ZW
12521 inst.instruction = THUMB_OP16 (inst.instruction);
12522 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12523 inst.instruction |= mask & 0xff;
c19d1205
ZW
12524 }
12525 else if (unified_syntax)
12526 {
3c707909 12527 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12528 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12529 }
12530 else
12531 {
12532 inst.error = _("invalid register list to push/pop instruction");
12533 return;
12534 }
c19d1205 12535}
b99bd4ef 12536
c19d1205
ZW
12537static void
12538do_t_rbit (void)
12539{
fdfde340
JM
12540 unsigned Rd, Rm;
12541
12542 Rd = inst.operands[0].reg;
12543 Rm = inst.operands[1].reg;
12544
12545 reject_bad_reg (Rd);
12546 reject_bad_reg (Rm);
12547
12548 inst.instruction |= Rd << 8;
12549 inst.instruction |= Rm << 16;
12550 inst.instruction |= Rm;
c19d1205 12551}
b99bd4ef 12552
c19d1205
ZW
12553static void
12554do_t_rev (void)
12555{
fdfde340
JM
12556 unsigned Rd, Rm;
12557
12558 Rd = inst.operands[0].reg;
12559 Rm = inst.operands[1].reg;
12560
12561 reject_bad_reg (Rd);
12562 reject_bad_reg (Rm);
12563
12564 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12565 && inst.size_req != 4)
12566 {
12567 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12568 inst.instruction |= Rd;
12569 inst.instruction |= Rm << 3;
c19d1205
ZW
12570 }
12571 else if (unified_syntax)
12572 {
12573 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12574 inst.instruction |= Rd << 8;
12575 inst.instruction |= Rm << 16;
12576 inst.instruction |= Rm;
c19d1205
ZW
12577 }
12578 else
12579 inst.error = BAD_HIREG;
12580}
b99bd4ef 12581
1c444d06
JM
12582static void
12583do_t_rrx (void)
12584{
12585 unsigned Rd, Rm;
12586
12587 Rd = inst.operands[0].reg;
12588 Rm = inst.operands[1].reg;
12589
fdfde340
JM
12590 reject_bad_reg (Rd);
12591 reject_bad_reg (Rm);
c921be7d 12592
1c444d06
JM
12593 inst.instruction |= Rd << 8;
12594 inst.instruction |= Rm;
12595}
12596
c19d1205
ZW
12597static void
12598do_t_rsb (void)
12599{
fdfde340 12600 unsigned Rd, Rs;
b99bd4ef 12601
c19d1205
ZW
12602 Rd = inst.operands[0].reg;
12603 Rs = (inst.operands[1].present
12604 ? inst.operands[1].reg /* Rd, Rs, foo */
12605 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12606
fdfde340
JM
12607 reject_bad_reg (Rd);
12608 reject_bad_reg (Rs);
12609 if (inst.operands[2].isreg)
12610 reject_bad_reg (inst.operands[2].reg);
12611
c19d1205
ZW
12612 inst.instruction |= Rd << 8;
12613 inst.instruction |= Rs << 16;
12614 if (!inst.operands[2].isreg)
12615 {
026d3abb
PB
12616 bfd_boolean narrow;
12617
12618 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12619 narrow = !in_it_block ();
026d3abb 12620 else
e07e6e58 12621 narrow = in_it_block ();
026d3abb
PB
12622
12623 if (Rd > 7 || Rs > 7)
12624 narrow = FALSE;
12625
12626 if (inst.size_req == 4 || !unified_syntax)
12627 narrow = FALSE;
12628
12629 if (inst.reloc.exp.X_op != O_constant
12630 || inst.reloc.exp.X_add_number != 0)
12631 narrow = FALSE;
12632
12633 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12634 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12635 if (narrow)
12636 {
12637 inst.reloc.type = BFD_RELOC_UNUSED;
12638 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12639 inst.instruction |= Rs << 3;
12640 inst.instruction |= Rd;
12641 }
12642 else
12643 {
12644 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12645 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12646 }
c19d1205
ZW
12647 }
12648 else
12649 encode_thumb32_shifted_operand (2);
12650}
b99bd4ef 12651
c19d1205
ZW
12652static void
12653do_t_setend (void)
12654{
12e37cbc
MGD
12655 if (warn_on_deprecated
12656 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12657 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12658
e07e6e58 12659 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12660 if (inst.operands[0].imm)
12661 inst.instruction |= 0x8;
12662}
b99bd4ef 12663
c19d1205
ZW
12664static void
12665do_t_shift (void)
12666{
12667 if (!inst.operands[1].present)
12668 inst.operands[1].reg = inst.operands[0].reg;
12669
12670 if (unified_syntax)
12671 {
3d388997
PB
12672 bfd_boolean narrow;
12673 int shift_kind;
12674
12675 switch (inst.instruction)
12676 {
12677 case T_MNEM_asr:
12678 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12679 case T_MNEM_lsl:
12680 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12681 case T_MNEM_lsr:
12682 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12683 case T_MNEM_ror:
12684 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12685 default: abort ();
12686 }
12687
12688 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12689 narrow = !in_it_block ();
3d388997 12690 else
e07e6e58 12691 narrow = in_it_block ();
3d388997
PB
12692 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12693 narrow = FALSE;
12694 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12695 narrow = FALSE;
12696 if (inst.operands[2].isreg
12697 && (inst.operands[1].reg != inst.operands[0].reg
12698 || inst.operands[2].reg > 7))
12699 narrow = FALSE;
12700 if (inst.size_req == 4)
12701 narrow = FALSE;
12702
fdfde340
JM
12703 reject_bad_reg (inst.operands[0].reg);
12704 reject_bad_reg (inst.operands[1].reg);
c921be7d 12705
3d388997 12706 if (!narrow)
c19d1205
ZW
12707 {
12708 if (inst.operands[2].isreg)
b99bd4ef 12709 {
fdfde340 12710 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12711 inst.instruction = THUMB_OP32 (inst.instruction);
12712 inst.instruction |= inst.operands[0].reg << 8;
12713 inst.instruction |= inst.operands[1].reg << 16;
12714 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12715
12716 /* PR 12854: Error on extraneous shifts. */
12717 constraint (inst.operands[2].shifted,
12718 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12719 }
12720 else
12721 {
12722 inst.operands[1].shifted = 1;
3d388997 12723 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12724 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12725 ? T_MNEM_movs : T_MNEM_mov);
12726 inst.instruction |= inst.operands[0].reg << 8;
12727 encode_thumb32_shifted_operand (1);
12728 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12729 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12730 }
12731 }
12732 else
12733 {
c19d1205 12734 if (inst.operands[2].isreg)
b99bd4ef 12735 {
3d388997 12736 switch (shift_kind)
b99bd4ef 12737 {
3d388997
PB
12738 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12739 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12740 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12741 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12742 default: abort ();
b99bd4ef 12743 }
5f4273c7 12744
c19d1205
ZW
12745 inst.instruction |= inst.operands[0].reg;
12746 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12747
12748 /* PR 12854: Error on extraneous shifts. */
12749 constraint (inst.operands[2].shifted,
12750 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12751 }
12752 else
12753 {
3d388997 12754 switch (shift_kind)
b99bd4ef 12755 {
3d388997
PB
12756 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12757 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12758 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12759 default: abort ();
b99bd4ef 12760 }
c19d1205
ZW
12761 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12762 inst.instruction |= inst.operands[0].reg;
12763 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12764 }
12765 }
c19d1205
ZW
12766 }
12767 else
12768 {
12769 constraint (inst.operands[0].reg > 7
12770 || inst.operands[1].reg > 7, BAD_HIREG);
12771 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12772
c19d1205
ZW
12773 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12774 {
12775 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12776 constraint (inst.operands[0].reg != inst.operands[1].reg,
12777 _("source1 and dest must be same register"));
b99bd4ef 12778
c19d1205
ZW
12779 switch (inst.instruction)
12780 {
12781 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12782 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12783 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12784 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12785 default: abort ();
12786 }
5f4273c7 12787
c19d1205
ZW
12788 inst.instruction |= inst.operands[0].reg;
12789 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12790
12791 /* PR 12854: Error on extraneous shifts. */
12792 constraint (inst.operands[2].shifted,
12793 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12794 }
12795 else
b99bd4ef 12796 {
c19d1205
ZW
12797 switch (inst.instruction)
12798 {
12799 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12800 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12801 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12802 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12803 default: abort ();
12804 }
12805 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12806 inst.instruction |= inst.operands[0].reg;
12807 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12808 }
12809 }
b99bd4ef
NC
12810}
12811
12812static void
c19d1205 12813do_t_simd (void)
b99bd4ef 12814{
fdfde340
JM
12815 unsigned Rd, Rn, Rm;
12816
12817 Rd = inst.operands[0].reg;
12818 Rn = inst.operands[1].reg;
12819 Rm = inst.operands[2].reg;
12820
12821 reject_bad_reg (Rd);
12822 reject_bad_reg (Rn);
12823 reject_bad_reg (Rm);
12824
12825 inst.instruction |= Rd << 8;
12826 inst.instruction |= Rn << 16;
12827 inst.instruction |= Rm;
c19d1205 12828}
b99bd4ef 12829
03ee1b7f
NC
12830static void
12831do_t_simd2 (void)
12832{
12833 unsigned Rd, Rn, Rm;
12834
12835 Rd = inst.operands[0].reg;
12836 Rm = inst.operands[1].reg;
12837 Rn = inst.operands[2].reg;
12838
12839 reject_bad_reg (Rd);
12840 reject_bad_reg (Rn);
12841 reject_bad_reg (Rm);
12842
12843 inst.instruction |= Rd << 8;
12844 inst.instruction |= Rn << 16;
12845 inst.instruction |= Rm;
12846}
12847
c19d1205 12848static void
3eb17e6b 12849do_t_smc (void)
c19d1205
ZW
12850{
12851 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12853 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12854 constraint (inst.reloc.exp.X_op != O_constant,
12855 _("expression too complex"));
12856 inst.reloc.type = BFD_RELOC_UNUSED;
12857 inst.instruction |= (value & 0xf000) >> 12;
12858 inst.instruction |= (value & 0x0ff0);
12859 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12860 /* PR gas/15623: SMC instructions must be last in an IT block. */
12861 set_it_insn_type_last ();
c19d1205 12862}
b99bd4ef 12863
90ec0d68
MGD
12864static void
12865do_t_hvc (void)
12866{
12867 unsigned int value = inst.reloc.exp.X_add_number;
12868
12869 inst.reloc.type = BFD_RELOC_UNUSED;
12870 inst.instruction |= (value & 0x0fff);
12871 inst.instruction |= (value & 0xf000) << 4;
12872}
12873
c19d1205 12874static void
3a21c15a 12875do_t_ssat_usat (int bias)
c19d1205 12876{
fdfde340
JM
12877 unsigned Rd, Rn;
12878
12879 Rd = inst.operands[0].reg;
12880 Rn = inst.operands[2].reg;
12881
12882 reject_bad_reg (Rd);
12883 reject_bad_reg (Rn);
12884
12885 inst.instruction |= Rd << 8;
3a21c15a 12886 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12887 inst.instruction |= Rn << 16;
b99bd4ef 12888
c19d1205 12889 if (inst.operands[3].present)
b99bd4ef 12890 {
3a21c15a
NC
12891 offsetT shift_amount = inst.reloc.exp.X_add_number;
12892
12893 inst.reloc.type = BFD_RELOC_UNUSED;
12894
c19d1205
ZW
12895 constraint (inst.reloc.exp.X_op != O_constant,
12896 _("expression too complex"));
b99bd4ef 12897
3a21c15a 12898 if (shift_amount != 0)
6189168b 12899 {
3a21c15a
NC
12900 constraint (shift_amount > 31,
12901 _("shift expression is too large"));
12902
c19d1205 12903 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12904 inst.instruction |= 0x00200000; /* sh bit. */
12905
12906 inst.instruction |= (shift_amount & 0x1c) << 10;
12907 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12908 }
12909 }
b99bd4ef 12910}
c921be7d 12911
3a21c15a
NC
12912static void
12913do_t_ssat (void)
12914{
12915 do_t_ssat_usat (1);
12916}
b99bd4ef 12917
0dd132b6 12918static void
c19d1205 12919do_t_ssat16 (void)
0dd132b6 12920{
fdfde340
JM
12921 unsigned Rd, Rn;
12922
12923 Rd = inst.operands[0].reg;
12924 Rn = inst.operands[2].reg;
12925
12926 reject_bad_reg (Rd);
12927 reject_bad_reg (Rn);
12928
12929 inst.instruction |= Rd << 8;
c19d1205 12930 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12931 inst.instruction |= Rn << 16;
c19d1205 12932}
0dd132b6 12933
c19d1205
ZW
12934static void
12935do_t_strex (void)
12936{
12937 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12938 || inst.operands[2].postind || inst.operands[2].writeback
12939 || inst.operands[2].immisreg || inst.operands[2].shifted
12940 || inst.operands[2].negative,
01cfc07f 12941 BAD_ADDR_MODE);
0dd132b6 12942
5be8be5d
DG
12943 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12944
c19d1205
ZW
12945 inst.instruction |= inst.operands[0].reg << 8;
12946 inst.instruction |= inst.operands[1].reg << 12;
12947 inst.instruction |= inst.operands[2].reg << 16;
12948 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12949}
12950
b99bd4ef 12951static void
c19d1205 12952do_t_strexd (void)
b99bd4ef 12953{
c19d1205
ZW
12954 if (!inst.operands[2].present)
12955 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12956
c19d1205
ZW
12957 constraint (inst.operands[0].reg == inst.operands[1].reg
12958 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12959 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12960 BAD_OVERLAP);
b99bd4ef 12961
c19d1205
ZW
12962 inst.instruction |= inst.operands[0].reg;
12963 inst.instruction |= inst.operands[1].reg << 12;
12964 inst.instruction |= inst.operands[2].reg << 8;
12965 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12966}
12967
12968static void
c19d1205 12969do_t_sxtah (void)
b99bd4ef 12970{
fdfde340
JM
12971 unsigned Rd, Rn, Rm;
12972
12973 Rd = inst.operands[0].reg;
12974 Rn = inst.operands[1].reg;
12975 Rm = inst.operands[2].reg;
12976
12977 reject_bad_reg (Rd);
12978 reject_bad_reg (Rn);
12979 reject_bad_reg (Rm);
12980
12981 inst.instruction |= Rd << 8;
12982 inst.instruction |= Rn << 16;
12983 inst.instruction |= Rm;
c19d1205
ZW
12984 inst.instruction |= inst.operands[3].imm << 4;
12985}
b99bd4ef 12986
c19d1205
ZW
12987static void
12988do_t_sxth (void)
12989{
fdfde340
JM
12990 unsigned Rd, Rm;
12991
12992 Rd = inst.operands[0].reg;
12993 Rm = inst.operands[1].reg;
12994
12995 reject_bad_reg (Rd);
12996 reject_bad_reg (Rm);
c921be7d
NC
12997
12998 if (inst.instruction <= 0xffff
12999 && inst.size_req != 4
fdfde340 13000 && Rd <= 7 && Rm <= 7
c19d1205 13001 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13002 {
c19d1205 13003 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13004 inst.instruction |= Rd;
13005 inst.instruction |= Rm << 3;
b99bd4ef 13006 }
c19d1205 13007 else if (unified_syntax)
b99bd4ef 13008 {
c19d1205
ZW
13009 if (inst.instruction <= 0xffff)
13010 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13011 inst.instruction |= Rd << 8;
13012 inst.instruction |= Rm;
c19d1205 13013 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13014 }
c19d1205 13015 else
b99bd4ef 13016 {
c19d1205
ZW
13017 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13018 _("Thumb encoding does not support rotation"));
13019 constraint (1, BAD_HIREG);
b99bd4ef 13020 }
c19d1205 13021}
b99bd4ef 13022
c19d1205
ZW
13023static void
13024do_t_swi (void)
13025{
b2a5fbdc
MGD
13026 /* We have to do the following check manually as ARM_EXT_OS only applies
13027 to ARM_EXT_V6M. */
13028 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13029 {
ac7f631b
NC
13030 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
13031 /* This only applies to the v6m howver, not later architectures. */
13032 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13033 as_bad (_("SVC is not permitted on this architecture"));
13034 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13035 }
13036
c19d1205
ZW
13037 inst.reloc.type = BFD_RELOC_ARM_SWI;
13038}
b99bd4ef 13039
92e90b6e
PB
13040static void
13041do_t_tb (void)
13042{
fdfde340 13043 unsigned Rn, Rm;
92e90b6e
PB
13044 int half;
13045
13046 half = (inst.instruction & 0x10) != 0;
e07e6e58 13047 set_it_insn_type_last ();
dfa9f0d5
PB
13048 constraint (inst.operands[0].immisreg,
13049 _("instruction requires register index"));
fdfde340
JM
13050
13051 Rn = inst.operands[0].reg;
13052 Rm = inst.operands[0].imm;
c921be7d 13053
fdfde340
JM
13054 constraint (Rn == REG_SP, BAD_SP);
13055 reject_bad_reg (Rm);
13056
92e90b6e
PB
13057 constraint (!half && inst.operands[0].shifted,
13058 _("instruction does not allow shifted index"));
fdfde340 13059 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13060}
13061
74db7efb
NC
13062static void
13063do_t_udf (void)
13064{
13065 if (!inst.operands[0].present)
13066 inst.operands[0].imm = 0;
13067
13068 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13069 {
13070 constraint (inst.size_req == 2,
13071 _("immediate value out of range"));
13072 inst.instruction = THUMB_OP32 (inst.instruction);
13073 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13074 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13075 }
13076 else
13077 {
13078 inst.instruction = THUMB_OP16 (inst.instruction);
13079 inst.instruction |= inst.operands[0].imm;
13080 }
13081
13082 set_it_insn_type (NEUTRAL_IT_INSN);
13083}
13084
13085
c19d1205
ZW
13086static void
13087do_t_usat (void)
13088{
3a21c15a 13089 do_t_ssat_usat (0);
b99bd4ef
NC
13090}
13091
13092static void
c19d1205 13093do_t_usat16 (void)
b99bd4ef 13094{
fdfde340
JM
13095 unsigned Rd, Rn;
13096
13097 Rd = inst.operands[0].reg;
13098 Rn = inst.operands[2].reg;
13099
13100 reject_bad_reg (Rd);
13101 reject_bad_reg (Rn);
13102
13103 inst.instruction |= Rd << 8;
c19d1205 13104 inst.instruction |= inst.operands[1].imm;
fdfde340 13105 inst.instruction |= Rn << 16;
b99bd4ef 13106}
c19d1205 13107
5287ad62 13108/* Neon instruction encoder helpers. */
5f4273c7 13109
5287ad62 13110/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13111
5287ad62
JB
13112/* An "invalid" code for the following tables. */
13113#define N_INV -1u
13114
13115struct neon_tab_entry
b99bd4ef 13116{
5287ad62
JB
13117 unsigned integer;
13118 unsigned float_or_poly;
13119 unsigned scalar_or_imm;
13120};
5f4273c7 13121
5287ad62
JB
13122/* Map overloaded Neon opcodes to their respective encodings. */
13123#define NEON_ENC_TAB \
13124 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13125 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13126 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13127 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13128 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13129 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13130 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13131 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13132 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13133 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13134 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13135 /* Register variants of the following two instructions are encoded as
e07e6e58 13136 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13137 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13138 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13139 X(vfma, N_INV, 0x0000c10, N_INV), \
13140 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13141 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13142 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13143 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13144 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13145 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13146 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13147 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13148 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13149 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13150 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13151 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13152 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13153 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13154 X(vshl, 0x0000400, N_INV, 0x0800510), \
13155 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13156 X(vand, 0x0000110, N_INV, 0x0800030), \
13157 X(vbic, 0x0100110, N_INV, 0x0800030), \
13158 X(veor, 0x1000110, N_INV, N_INV), \
13159 X(vorn, 0x0300110, N_INV, 0x0800010), \
13160 X(vorr, 0x0200110, N_INV, 0x0800010), \
13161 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13162 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13163 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13164 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13165 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13166 X(vst1, 0x0000000, 0x0800000, N_INV), \
13167 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13168 X(vst2, 0x0000100, 0x0800100, N_INV), \
13169 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13170 X(vst3, 0x0000200, 0x0800200, N_INV), \
13171 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13172 X(vst4, 0x0000300, 0x0800300, N_INV), \
13173 X(vmovn, 0x1b20200, N_INV, N_INV), \
13174 X(vtrn, 0x1b20080, N_INV, N_INV), \
13175 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13176 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13177 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13178 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13179 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13180 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13181 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13182 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13183 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13184 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13185 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13186 X(vseleq, 0xe000a00, N_INV, N_INV), \
13187 X(vselvs, 0xe100a00, N_INV, N_INV), \
13188 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13189 X(vselgt, 0xe300a00, N_INV, N_INV), \
13190 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13191 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13192 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13193 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13194 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13195 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13196 X(sha3op, 0x2000c00, N_INV, N_INV), \
13197 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13198 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13199
13200enum neon_opc
13201{
13202#define X(OPC,I,F,S) N_MNEM_##OPC
13203NEON_ENC_TAB
13204#undef X
13205};
b99bd4ef 13206
5287ad62
JB
13207static const struct neon_tab_entry neon_enc_tab[] =
13208{
13209#define X(OPC,I,F,S) { (I), (F), (S) }
13210NEON_ENC_TAB
13211#undef X
13212};
b99bd4ef 13213
88714cb8
DG
13214/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13215#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13216#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13217#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13218#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13219#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13220#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13221#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13222#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13223#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13224#define NEON_ENC_SINGLE_(X) \
037e8744 13225 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13226#define NEON_ENC_DOUBLE_(X) \
037e8744 13227 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13228#define NEON_ENC_FPV8_(X) \
13229 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13230
88714cb8
DG
13231#define NEON_ENCODE(type, inst) \
13232 do \
13233 { \
13234 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13235 inst.is_neon = 1; \
13236 } \
13237 while (0)
13238
13239#define check_neon_suffixes \
13240 do \
13241 { \
13242 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13243 { \
13244 as_bad (_("invalid neon suffix for non neon instruction")); \
13245 return; \
13246 } \
13247 } \
13248 while (0)
13249
037e8744
JB
13250/* Define shapes for instruction operands. The following mnemonic characters
13251 are used in this table:
5287ad62 13252
037e8744 13253 F - VFP S<n> register
5287ad62
JB
13254 D - Neon D<n> register
13255 Q - Neon Q<n> register
13256 I - Immediate
13257 S - Scalar
13258 R - ARM register
13259 L - D<n> register list
5f4273c7 13260
037e8744
JB
13261 This table is used to generate various data:
13262 - enumerations of the form NS_DDR to be used as arguments to
13263 neon_select_shape.
13264 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13265 - a table used to drive neon_select_shape. */
b99bd4ef 13266
037e8744
JB
13267#define NEON_SHAPE_DEF \
13268 X(3, (D, D, D), DOUBLE), \
13269 X(3, (Q, Q, Q), QUAD), \
13270 X(3, (D, D, I), DOUBLE), \
13271 X(3, (Q, Q, I), QUAD), \
13272 X(3, (D, D, S), DOUBLE), \
13273 X(3, (Q, Q, S), QUAD), \
13274 X(2, (D, D), DOUBLE), \
13275 X(2, (Q, Q), QUAD), \
13276 X(2, (D, S), DOUBLE), \
13277 X(2, (Q, S), QUAD), \
13278 X(2, (D, R), DOUBLE), \
13279 X(2, (Q, R), QUAD), \
13280 X(2, (D, I), DOUBLE), \
13281 X(2, (Q, I), QUAD), \
13282 X(3, (D, L, D), DOUBLE), \
13283 X(2, (D, Q), MIXED), \
13284 X(2, (Q, D), MIXED), \
13285 X(3, (D, Q, I), MIXED), \
13286 X(3, (Q, D, I), MIXED), \
13287 X(3, (Q, D, D), MIXED), \
13288 X(3, (D, Q, Q), MIXED), \
13289 X(3, (Q, Q, D), MIXED), \
13290 X(3, (Q, D, S), MIXED), \
13291 X(3, (D, Q, S), MIXED), \
13292 X(4, (D, D, D, I), DOUBLE), \
13293 X(4, (Q, Q, Q, I), QUAD), \
13294 X(2, (F, F), SINGLE), \
13295 X(3, (F, F, F), SINGLE), \
13296 X(2, (F, I), SINGLE), \
13297 X(2, (F, D), MIXED), \
13298 X(2, (D, F), MIXED), \
13299 X(3, (F, F, I), MIXED), \
13300 X(4, (R, R, F, F), SINGLE), \
13301 X(4, (F, F, R, R), SINGLE), \
13302 X(3, (D, R, R), DOUBLE), \
13303 X(3, (R, R, D), DOUBLE), \
13304 X(2, (S, R), SINGLE), \
13305 X(2, (R, S), SINGLE), \
13306 X(2, (F, R), SINGLE), \
d54af2d0
RL
13307 X(2, (R, F), SINGLE), \
13308/* Half float shape supported so far. */\
13309 X (2, (H, D), MIXED), \
13310 X (2, (D, H), MIXED), \
13311 X (2, (H, F), MIXED), \
13312 X (2, (F, H), MIXED), \
13313 X (2, (H, H), HALF), \
13314 X (2, (H, R), HALF), \
13315 X (2, (R, H), HALF), \
13316 X (2, (H, I), HALF), \
13317 X (3, (H, H, H), HALF), \
13318 X (3, (H, F, I), MIXED), \
13319 X (3, (F, H, I), MIXED)
037e8744
JB
13320
13321#define S2(A,B) NS_##A##B
13322#define S3(A,B,C) NS_##A##B##C
13323#define S4(A,B,C,D) NS_##A##B##C##D
13324
13325#define X(N, L, C) S##N L
13326
5287ad62
JB
13327enum neon_shape
13328{
037e8744
JB
13329 NEON_SHAPE_DEF,
13330 NS_NULL
5287ad62 13331};
b99bd4ef 13332
037e8744
JB
13333#undef X
13334#undef S2
13335#undef S3
13336#undef S4
13337
13338enum neon_shape_class
13339{
d54af2d0 13340 SC_HALF,
037e8744
JB
13341 SC_SINGLE,
13342 SC_DOUBLE,
13343 SC_QUAD,
13344 SC_MIXED
13345};
13346
13347#define X(N, L, C) SC_##C
13348
13349static enum neon_shape_class neon_shape_class[] =
13350{
13351 NEON_SHAPE_DEF
13352};
13353
13354#undef X
13355
13356enum neon_shape_el
13357{
d54af2d0 13358 SE_H,
037e8744
JB
13359 SE_F,
13360 SE_D,
13361 SE_Q,
13362 SE_I,
13363 SE_S,
13364 SE_R,
13365 SE_L
13366};
13367
13368/* Register widths of above. */
13369static unsigned neon_shape_el_size[] =
13370{
d54af2d0 13371 16,
037e8744
JB
13372 32,
13373 64,
13374 128,
13375 0,
13376 32,
13377 32,
13378 0
13379};
13380
13381struct neon_shape_info
13382{
13383 unsigned els;
13384 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13385};
13386
13387#define S2(A,B) { SE_##A, SE_##B }
13388#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13389#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13390
13391#define X(N, L, C) { N, S##N L }
13392
13393static struct neon_shape_info neon_shape_tab[] =
13394{
13395 NEON_SHAPE_DEF
13396};
13397
13398#undef X
13399#undef S2
13400#undef S3
13401#undef S4
13402
5287ad62
JB
13403/* Bit masks used in type checking given instructions.
13404 'N_EQK' means the type must be the same as (or based on in some way) the key
13405 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13406 set, various other bits can be set as well in order to modify the meaning of
13407 the type constraint. */
13408
13409enum neon_type_mask
13410{
8e79c3df
CM
13411 N_S8 = 0x0000001,
13412 N_S16 = 0x0000002,
13413 N_S32 = 0x0000004,
13414 N_S64 = 0x0000008,
13415 N_U8 = 0x0000010,
13416 N_U16 = 0x0000020,
13417 N_U32 = 0x0000040,
13418 N_U64 = 0x0000080,
13419 N_I8 = 0x0000100,
13420 N_I16 = 0x0000200,
13421 N_I32 = 0x0000400,
13422 N_I64 = 0x0000800,
13423 N_8 = 0x0001000,
13424 N_16 = 0x0002000,
13425 N_32 = 0x0004000,
13426 N_64 = 0x0008000,
13427 N_P8 = 0x0010000,
13428 N_P16 = 0x0020000,
13429 N_F16 = 0x0040000,
13430 N_F32 = 0x0080000,
13431 N_F64 = 0x0100000,
4f51b4bd 13432 N_P64 = 0x0200000,
c921be7d
NC
13433 N_KEY = 0x1000000, /* Key element (main type specifier). */
13434 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13435 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13436 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13437 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13438 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13439 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13440 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13441 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13442 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13443 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13444 N_UTYP = 0,
4f51b4bd 13445 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13446};
13447
dcbf9037
JB
13448#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13449
5287ad62
JB
13450#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13451#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13452#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13453#define N_S_32 (N_S8 | N_S16 | N_S32)
13454#define N_F_16_32 (N_F16 | N_F32)
13455#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13456#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13457#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13458#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13459
13460/* Pass this as the first type argument to neon_check_type to ignore types
13461 altogether. */
13462#define N_IGNORE_TYPE (N_KEY | N_EQK)
13463
037e8744
JB
13464/* Select a "shape" for the current instruction (describing register types or
13465 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13466 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13467 function of operand parsing, so this function doesn't need to be called.
13468 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13469
13470static enum neon_shape
037e8744 13471neon_select_shape (enum neon_shape shape, ...)
5287ad62 13472{
037e8744
JB
13473 va_list ap;
13474 enum neon_shape first_shape = shape;
5287ad62
JB
13475
13476 /* Fix missing optional operands. FIXME: we don't know at this point how
13477 many arguments we should have, so this makes the assumption that we have
13478 > 1. This is true of all current Neon opcodes, I think, but may not be
13479 true in the future. */
13480 if (!inst.operands[1].present)
13481 inst.operands[1] = inst.operands[0];
13482
037e8744 13483 va_start (ap, shape);
5f4273c7 13484
21d799b5 13485 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13486 {
13487 unsigned j;
13488 int matches = 1;
13489
13490 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13491 {
13492 if (!inst.operands[j].present)
13493 {
13494 matches = 0;
13495 break;
13496 }
13497
13498 switch (neon_shape_tab[shape].el[j])
13499 {
d54af2d0
RL
13500 /* If a .f16, .16, .u16, .s16 type specifier is given over
13501 a VFP single precision register operand, it's essentially
13502 means only half of the register is used.
13503
13504 If the type specifier is given after the mnemonics, the
13505 information is stored in inst.vectype. If the type specifier
13506 is given after register operand, the information is stored
13507 in inst.operands[].vectype.
13508
13509 When there is only one type specifier, and all the register
13510 operands are the same type of hardware register, the type
13511 specifier applies to all register operands.
13512
13513 If no type specifier is given, the shape is inferred from
13514 operand information.
13515
13516 for example:
13517 vadd.f16 s0, s1, s2: NS_HHH
13518 vabs.f16 s0, s1: NS_HH
13519 vmov.f16 s0, r1: NS_HR
13520 vmov.f16 r0, s1: NS_RH
13521 vcvt.f16 r0, s1: NS_RH
13522 vcvt.f16.s32 s2, s2, #29: NS_HFI
13523 vcvt.f16.s32 s2, s2: NS_HF
13524 */
13525 case SE_H:
13526 if (!(inst.operands[j].isreg
13527 && inst.operands[j].isvec
13528 && inst.operands[j].issingle
13529 && !inst.operands[j].isquad
13530 && ((inst.vectype.elems == 1
13531 && inst.vectype.el[0].size == 16)
13532 || (inst.vectype.elems > 1
13533 && inst.vectype.el[j].size == 16)
13534 || (inst.vectype.elems == 0
13535 && inst.operands[j].vectype.type != NT_invtype
13536 && inst.operands[j].vectype.size == 16))))
13537 matches = 0;
13538 break;
13539
477330fc
RM
13540 case SE_F:
13541 if (!(inst.operands[j].isreg
13542 && inst.operands[j].isvec
13543 && inst.operands[j].issingle
d54af2d0
RL
13544 && !inst.operands[j].isquad
13545 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13546 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13547 || (inst.vectype.elems == 0
13548 && (inst.operands[j].vectype.size == 32
13549 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13550 matches = 0;
13551 break;
13552
13553 case SE_D:
13554 if (!(inst.operands[j].isreg
13555 && inst.operands[j].isvec
13556 && !inst.operands[j].isquad
13557 && !inst.operands[j].issingle))
13558 matches = 0;
13559 break;
13560
13561 case SE_R:
13562 if (!(inst.operands[j].isreg
13563 && !inst.operands[j].isvec))
13564 matches = 0;
13565 break;
13566
13567 case SE_Q:
13568 if (!(inst.operands[j].isreg
13569 && inst.operands[j].isvec
13570 && inst.operands[j].isquad
13571 && !inst.operands[j].issingle))
13572 matches = 0;
13573 break;
13574
13575 case SE_I:
13576 if (!(!inst.operands[j].isreg
13577 && !inst.operands[j].isscalar))
13578 matches = 0;
13579 break;
13580
13581 case SE_S:
13582 if (!(!inst.operands[j].isreg
13583 && inst.operands[j].isscalar))
13584 matches = 0;
13585 break;
13586
13587 case SE_L:
13588 break;
13589 }
3fde54a2
JZ
13590 if (!matches)
13591 break;
477330fc 13592 }
ad6cec43
MGD
13593 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13594 /* We've matched all the entries in the shape table, and we don't
13595 have any left over operands which have not been matched. */
477330fc 13596 break;
037e8744 13597 }
5f4273c7 13598
037e8744 13599 va_end (ap);
5287ad62 13600
037e8744
JB
13601 if (shape == NS_NULL && first_shape != NS_NULL)
13602 first_error (_("invalid instruction shape"));
5287ad62 13603
037e8744
JB
13604 return shape;
13605}
5287ad62 13606
037e8744
JB
13607/* True if SHAPE is predominantly a quadword operation (most of the time, this
13608 means the Q bit should be set). */
13609
13610static int
13611neon_quad (enum neon_shape shape)
13612{
13613 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13614}
037e8744 13615
5287ad62
JB
13616static void
13617neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13618 unsigned *g_size)
5287ad62
JB
13619{
13620 /* Allow modification to be made to types which are constrained to be
13621 based on the key element, based on bits set alongside N_EQK. */
13622 if ((typebits & N_EQK) != 0)
13623 {
13624 if ((typebits & N_HLF) != 0)
13625 *g_size /= 2;
13626 else if ((typebits & N_DBL) != 0)
13627 *g_size *= 2;
13628 if ((typebits & N_SGN) != 0)
13629 *g_type = NT_signed;
13630 else if ((typebits & N_UNS) != 0)
477330fc 13631 *g_type = NT_unsigned;
5287ad62 13632 else if ((typebits & N_INT) != 0)
477330fc 13633 *g_type = NT_integer;
5287ad62 13634 else if ((typebits & N_FLT) != 0)
477330fc 13635 *g_type = NT_float;
dcbf9037 13636 else if ((typebits & N_SIZ) != 0)
477330fc 13637 *g_type = NT_untyped;
5287ad62
JB
13638 }
13639}
5f4273c7 13640
5287ad62
JB
13641/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13642 operand type, i.e. the single type specified in a Neon instruction when it
13643 is the only one given. */
13644
13645static struct neon_type_el
13646neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13647{
13648 struct neon_type_el dest = *key;
5f4273c7 13649
9c2799c2 13650 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13651
5287ad62
JB
13652 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13653
13654 return dest;
13655}
13656
13657/* Convert Neon type and size into compact bitmask representation. */
13658
13659static enum neon_type_mask
13660type_chk_of_el_type (enum neon_el_type type, unsigned size)
13661{
13662 switch (type)
13663 {
13664 case NT_untyped:
13665 switch (size)
477330fc
RM
13666 {
13667 case 8: return N_8;
13668 case 16: return N_16;
13669 case 32: return N_32;
13670 case 64: return N_64;
13671 default: ;
13672 }
5287ad62
JB
13673 break;
13674
13675 case NT_integer:
13676 switch (size)
477330fc
RM
13677 {
13678 case 8: return N_I8;
13679 case 16: return N_I16;
13680 case 32: return N_I32;
13681 case 64: return N_I64;
13682 default: ;
13683 }
5287ad62
JB
13684 break;
13685
13686 case NT_float:
037e8744 13687 switch (size)
477330fc 13688 {
8e79c3df 13689 case 16: return N_F16;
477330fc
RM
13690 case 32: return N_F32;
13691 case 64: return N_F64;
13692 default: ;
13693 }
5287ad62
JB
13694 break;
13695
13696 case NT_poly:
13697 switch (size)
477330fc
RM
13698 {
13699 case 8: return N_P8;
13700 case 16: return N_P16;
4f51b4bd 13701 case 64: return N_P64;
477330fc
RM
13702 default: ;
13703 }
5287ad62
JB
13704 break;
13705
13706 case NT_signed:
13707 switch (size)
477330fc
RM
13708 {
13709 case 8: return N_S8;
13710 case 16: return N_S16;
13711 case 32: return N_S32;
13712 case 64: return N_S64;
13713 default: ;
13714 }
5287ad62
JB
13715 break;
13716
13717 case NT_unsigned:
13718 switch (size)
477330fc
RM
13719 {
13720 case 8: return N_U8;
13721 case 16: return N_U16;
13722 case 32: return N_U32;
13723 case 64: return N_U64;
13724 default: ;
13725 }
5287ad62
JB
13726 break;
13727
13728 default: ;
13729 }
5f4273c7 13730
5287ad62
JB
13731 return N_UTYP;
13732}
13733
13734/* Convert compact Neon bitmask type representation to a type and size. Only
13735 handles the case where a single bit is set in the mask. */
13736
dcbf9037 13737static int
5287ad62 13738el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13739 enum neon_type_mask mask)
5287ad62 13740{
dcbf9037
JB
13741 if ((mask & N_EQK) != 0)
13742 return FAIL;
13743
5287ad62
JB
13744 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13745 *size = 8;
c70a8987 13746 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13747 *size = 16;
dcbf9037 13748 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13749 *size = 32;
4f51b4bd 13750 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13751 *size = 64;
dcbf9037
JB
13752 else
13753 return FAIL;
13754
5287ad62
JB
13755 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13756 *type = NT_signed;
dcbf9037 13757 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13758 *type = NT_unsigned;
dcbf9037 13759 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13760 *type = NT_integer;
dcbf9037 13761 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13762 *type = NT_untyped;
4f51b4bd 13763 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13764 *type = NT_poly;
d54af2d0 13765 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13766 *type = NT_float;
dcbf9037
JB
13767 else
13768 return FAIL;
5f4273c7 13769
dcbf9037 13770 return SUCCESS;
5287ad62
JB
13771}
13772
13773/* Modify a bitmask of allowed types. This is only needed for type
13774 relaxation. */
13775
13776static unsigned
13777modify_types_allowed (unsigned allowed, unsigned mods)
13778{
13779 unsigned size;
13780 enum neon_el_type type;
13781 unsigned destmask;
13782 int i;
5f4273c7 13783
5287ad62 13784 destmask = 0;
5f4273c7 13785
5287ad62
JB
13786 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13787 {
21d799b5 13788 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13789 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13790 {
13791 neon_modify_type_size (mods, &type, &size);
13792 destmask |= type_chk_of_el_type (type, size);
13793 }
5287ad62 13794 }
5f4273c7 13795
5287ad62
JB
13796 return destmask;
13797}
13798
13799/* Check type and return type classification.
13800 The manual states (paraphrase): If one datatype is given, it indicates the
13801 type given in:
13802 - the second operand, if there is one
13803 - the operand, if there is no second operand
13804 - the result, if there are no operands.
13805 This isn't quite good enough though, so we use a concept of a "key" datatype
13806 which is set on a per-instruction basis, which is the one which matters when
13807 only one data type is written.
13808 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13809 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13810
13811static struct neon_type_el
13812neon_check_type (unsigned els, enum neon_shape ns, ...)
13813{
13814 va_list ap;
13815 unsigned i, pass, key_el = 0;
13816 unsigned types[NEON_MAX_TYPE_ELS];
13817 enum neon_el_type k_type = NT_invtype;
13818 unsigned k_size = -1u;
13819 struct neon_type_el badtype = {NT_invtype, -1};
13820 unsigned key_allowed = 0;
13821
13822 /* Optional registers in Neon instructions are always (not) in operand 1.
13823 Fill in the missing operand here, if it was omitted. */
13824 if (els > 1 && !inst.operands[1].present)
13825 inst.operands[1] = inst.operands[0];
13826
13827 /* Suck up all the varargs. */
13828 va_start (ap, ns);
13829 for (i = 0; i < els; i++)
13830 {
13831 unsigned thisarg = va_arg (ap, unsigned);
13832 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13833 {
13834 va_end (ap);
13835 return badtype;
13836 }
5287ad62
JB
13837 types[i] = thisarg;
13838 if ((thisarg & N_KEY) != 0)
477330fc 13839 key_el = i;
5287ad62
JB
13840 }
13841 va_end (ap);
13842
dcbf9037
JB
13843 if (inst.vectype.elems > 0)
13844 for (i = 0; i < els; i++)
13845 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13846 {
13847 first_error (_("types specified in both the mnemonic and operands"));
13848 return badtype;
13849 }
dcbf9037 13850
5287ad62
JB
13851 /* Duplicate inst.vectype elements here as necessary.
13852 FIXME: No idea if this is exactly the same as the ARM assembler,
13853 particularly when an insn takes one register and one non-register
13854 operand. */
13855 if (inst.vectype.elems == 1 && els > 1)
13856 {
13857 unsigned j;
13858 inst.vectype.elems = els;
13859 inst.vectype.el[key_el] = inst.vectype.el[0];
13860 for (j = 0; j < els; j++)
477330fc
RM
13861 if (j != key_el)
13862 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13863 types[j]);
dcbf9037
JB
13864 }
13865 else if (inst.vectype.elems == 0 && els > 0)
13866 {
13867 unsigned j;
13868 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13869 after each operand. We allow some flexibility here; as long as the
13870 "key" operand has a type, we can infer the others. */
dcbf9037 13871 for (j = 0; j < els; j++)
477330fc
RM
13872 if (inst.operands[j].vectype.type != NT_invtype)
13873 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13874
13875 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13876 {
13877 for (j = 0; j < els; j++)
13878 if (inst.operands[j].vectype.type == NT_invtype)
13879 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13880 types[j]);
13881 }
dcbf9037 13882 else
477330fc
RM
13883 {
13884 first_error (_("operand types can't be inferred"));
13885 return badtype;
13886 }
5287ad62
JB
13887 }
13888 else if (inst.vectype.elems != els)
13889 {
dcbf9037 13890 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13891 return badtype;
13892 }
13893
13894 for (pass = 0; pass < 2; pass++)
13895 {
13896 for (i = 0; i < els; i++)
477330fc
RM
13897 {
13898 unsigned thisarg = types[i];
13899 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13900 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13901 enum neon_el_type g_type = inst.vectype.el[i].type;
13902 unsigned g_size = inst.vectype.el[i].size;
13903
13904 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13905 integer types if sign-specific variants are unavailable. */
477330fc 13906 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13907 && (types_allowed & N_SU_ALL) == 0)
13908 g_type = NT_integer;
13909
477330fc 13910 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13911 them. Some instructions only care about signs for some element
13912 sizes, so handle that properly. */
477330fc 13913 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13914 && ((g_size == 8 && (types_allowed & N_8) != 0)
13915 || (g_size == 16 && (types_allowed & N_16) != 0)
13916 || (g_size == 32 && (types_allowed & N_32) != 0)
13917 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13918 g_type = NT_untyped;
13919
477330fc
RM
13920 if (pass == 0)
13921 {
13922 if ((thisarg & N_KEY) != 0)
13923 {
13924 k_type = g_type;
13925 k_size = g_size;
13926 key_allowed = thisarg & ~N_KEY;
cc933301
JW
13927
13928 /* Check architecture constraint on FP16 extension. */
13929 if (k_size == 16
13930 && k_type == NT_float
13931 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13932 {
13933 inst.error = _(BAD_FP16);
13934 return badtype;
13935 }
477330fc
RM
13936 }
13937 }
13938 else
13939 {
13940 if ((thisarg & N_VFP) != 0)
13941 {
13942 enum neon_shape_el regshape;
13943 unsigned regwidth, match;
99b253c5
NC
13944
13945 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13946 if (ns == NS_NULL)
13947 {
13948 first_error (_("invalid instruction shape"));
13949 return badtype;
13950 }
477330fc
RM
13951 regshape = neon_shape_tab[ns].el[i];
13952 regwidth = neon_shape_el_size[regshape];
13953
13954 /* In VFP mode, operands must match register widths. If we
13955 have a key operand, use its width, else use the width of
13956 the current operand. */
13957 if (k_size != -1u)
13958 match = k_size;
13959 else
13960 match = g_size;
13961
9db2f6b4
RL
13962 /* FP16 will use a single precision register. */
13963 if (regwidth == 32 && match == 16)
13964 {
13965 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13966 match = regwidth;
13967 else
13968 {
13969 inst.error = _(BAD_FP16);
13970 return badtype;
13971 }
13972 }
13973
477330fc
RM
13974 if (regwidth != match)
13975 {
13976 first_error (_("operand size must match register width"));
13977 return badtype;
13978 }
13979 }
13980
13981 if ((thisarg & N_EQK) == 0)
13982 {
13983 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13984
13985 if ((given_type & types_allowed) == 0)
13986 {
13987 first_error (_("bad type in Neon instruction"));
13988 return badtype;
13989 }
13990 }
13991 else
13992 {
13993 enum neon_el_type mod_k_type = k_type;
13994 unsigned mod_k_size = k_size;
13995 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13996 if (g_type != mod_k_type || g_size != mod_k_size)
13997 {
13998 first_error (_("inconsistent types in Neon instruction"));
13999 return badtype;
14000 }
14001 }
14002 }
14003 }
5287ad62
JB
14004 }
14005
14006 return inst.vectype.el[key_el];
14007}
14008
037e8744 14009/* Neon-style VFP instruction forwarding. */
5287ad62 14010
037e8744
JB
14011/* Thumb VFP instructions have 0xE in the condition field. */
14012
14013static void
14014do_vfp_cond_or_thumb (void)
5287ad62 14015{
88714cb8
DG
14016 inst.is_neon = 1;
14017
5287ad62 14018 if (thumb_mode)
037e8744 14019 inst.instruction |= 0xe0000000;
5287ad62 14020 else
037e8744 14021 inst.instruction |= inst.cond << 28;
5287ad62
JB
14022}
14023
037e8744
JB
14024/* Look up and encode a simple mnemonic, for use as a helper function for the
14025 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14026 etc. It is assumed that operand parsing has already been done, and that the
14027 operands are in the form expected by the given opcode (this isn't necessarily
14028 the same as the form in which they were parsed, hence some massaging must
14029 take place before this function is called).
14030 Checks current arch version against that in the looked-up opcode. */
5287ad62 14031
037e8744
JB
14032static void
14033do_vfp_nsyn_opcode (const char *opname)
5287ad62 14034{
037e8744 14035 const struct asm_opcode *opcode;
5f4273c7 14036
21d799b5 14037 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14038
037e8744
JB
14039 if (!opcode)
14040 abort ();
5287ad62 14041
037e8744 14042 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14043 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14044 _(BAD_FPU));
5287ad62 14045
88714cb8
DG
14046 inst.is_neon = 1;
14047
037e8744
JB
14048 if (thumb_mode)
14049 {
14050 inst.instruction = opcode->tvalue;
14051 opcode->tencode ();
14052 }
14053 else
14054 {
14055 inst.instruction = (inst.cond << 28) | opcode->avalue;
14056 opcode->aencode ();
14057 }
14058}
5287ad62
JB
14059
14060static void
037e8744 14061do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14062{
037e8744
JB
14063 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14064
9db2f6b4 14065 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14066 {
14067 if (is_add)
477330fc 14068 do_vfp_nsyn_opcode ("fadds");
037e8744 14069 else
477330fc 14070 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14071
14072 /* ARMv8.2 fp16 instruction. */
14073 if (rs == NS_HHH)
14074 do_scalar_fp16_v82_encode ();
037e8744
JB
14075 }
14076 else
14077 {
14078 if (is_add)
477330fc 14079 do_vfp_nsyn_opcode ("faddd");
037e8744 14080 else
477330fc 14081 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14082 }
14083}
14084
14085/* Check operand types to see if this is a VFP instruction, and if so call
14086 PFN (). */
14087
14088static int
14089try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14090{
14091 enum neon_shape rs;
14092 struct neon_type_el et;
14093
14094 switch (args)
14095 {
14096 case 2:
9db2f6b4
RL
14097 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14098 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14099 break;
5f4273c7 14100
037e8744 14101 case 3:
9db2f6b4
RL
14102 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14103 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14104 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14105 break;
14106
14107 default:
14108 abort ();
14109 }
14110
14111 if (et.type != NT_invtype)
14112 {
14113 pfn (rs);
14114 return SUCCESS;
14115 }
037e8744 14116
99b253c5 14117 inst.error = NULL;
037e8744
JB
14118 return FAIL;
14119}
14120
14121static void
14122do_vfp_nsyn_mla_mls (enum neon_shape rs)
14123{
14124 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14125
9db2f6b4 14126 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14127 {
14128 if (is_mla)
477330fc 14129 do_vfp_nsyn_opcode ("fmacs");
037e8744 14130 else
477330fc 14131 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14132
14133 /* ARMv8.2 fp16 instruction. */
14134 if (rs == NS_HHH)
14135 do_scalar_fp16_v82_encode ();
037e8744
JB
14136 }
14137 else
14138 {
14139 if (is_mla)
477330fc 14140 do_vfp_nsyn_opcode ("fmacd");
037e8744 14141 else
477330fc 14142 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14143 }
14144}
14145
62f3b8c8
PB
14146static void
14147do_vfp_nsyn_fma_fms (enum neon_shape rs)
14148{
14149 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14150
9db2f6b4 14151 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14152 {
14153 if (is_fma)
477330fc 14154 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14155 else
477330fc 14156 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14157
14158 /* ARMv8.2 fp16 instruction. */
14159 if (rs == NS_HHH)
14160 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14161 }
14162 else
14163 {
14164 if (is_fma)
477330fc 14165 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14166 else
477330fc 14167 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14168 }
14169}
14170
037e8744
JB
14171static void
14172do_vfp_nsyn_mul (enum neon_shape rs)
14173{
9db2f6b4
RL
14174 if (rs == NS_FFF || rs == NS_HHH)
14175 {
14176 do_vfp_nsyn_opcode ("fmuls");
14177
14178 /* ARMv8.2 fp16 instruction. */
14179 if (rs == NS_HHH)
14180 do_scalar_fp16_v82_encode ();
14181 }
037e8744
JB
14182 else
14183 do_vfp_nsyn_opcode ("fmuld");
14184}
14185
14186static void
14187do_vfp_nsyn_abs_neg (enum neon_shape rs)
14188{
14189 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14190 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14191
9db2f6b4 14192 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14193 {
14194 if (is_neg)
477330fc 14195 do_vfp_nsyn_opcode ("fnegs");
037e8744 14196 else
477330fc 14197 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14198
14199 /* ARMv8.2 fp16 instruction. */
14200 if (rs == NS_HH)
14201 do_scalar_fp16_v82_encode ();
037e8744
JB
14202 }
14203 else
14204 {
14205 if (is_neg)
477330fc 14206 do_vfp_nsyn_opcode ("fnegd");
037e8744 14207 else
477330fc 14208 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14209 }
14210}
14211
14212/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14213 insns belong to Neon, and are handled elsewhere. */
14214
14215static void
14216do_vfp_nsyn_ldm_stm (int is_dbmode)
14217{
14218 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14219 if (is_ldm)
14220 {
14221 if (is_dbmode)
477330fc 14222 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14223 else
477330fc 14224 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14225 }
14226 else
14227 {
14228 if (is_dbmode)
477330fc 14229 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14230 else
477330fc 14231 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14232 }
14233}
14234
037e8744
JB
14235static void
14236do_vfp_nsyn_sqrt (void)
14237{
9db2f6b4
RL
14238 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14239 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14240
9db2f6b4
RL
14241 if (rs == NS_FF || rs == NS_HH)
14242 {
14243 do_vfp_nsyn_opcode ("fsqrts");
14244
14245 /* ARMv8.2 fp16 instruction. */
14246 if (rs == NS_HH)
14247 do_scalar_fp16_v82_encode ();
14248 }
037e8744
JB
14249 else
14250 do_vfp_nsyn_opcode ("fsqrtd");
14251}
14252
14253static void
14254do_vfp_nsyn_div (void)
14255{
9db2f6b4 14256 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14257 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14258 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14259
9db2f6b4
RL
14260 if (rs == NS_FFF || rs == NS_HHH)
14261 {
14262 do_vfp_nsyn_opcode ("fdivs");
14263
14264 /* ARMv8.2 fp16 instruction. */
14265 if (rs == NS_HHH)
14266 do_scalar_fp16_v82_encode ();
14267 }
037e8744
JB
14268 else
14269 do_vfp_nsyn_opcode ("fdivd");
14270}
14271
14272static void
14273do_vfp_nsyn_nmul (void)
14274{
9db2f6b4 14275 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14276 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14277 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14278
9db2f6b4 14279 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14280 {
88714cb8 14281 NEON_ENCODE (SINGLE, inst);
037e8744 14282 do_vfp_sp_dyadic ();
9db2f6b4
RL
14283
14284 /* ARMv8.2 fp16 instruction. */
14285 if (rs == NS_HHH)
14286 do_scalar_fp16_v82_encode ();
037e8744
JB
14287 }
14288 else
14289 {
88714cb8 14290 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14291 do_vfp_dp_rd_rn_rm ();
14292 }
14293 do_vfp_cond_or_thumb ();
9db2f6b4 14294
037e8744
JB
14295}
14296
14297static void
14298do_vfp_nsyn_cmp (void)
14299{
9db2f6b4 14300 enum neon_shape rs;
037e8744
JB
14301 if (inst.operands[1].isreg)
14302 {
9db2f6b4
RL
14303 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14304 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14305
9db2f6b4 14306 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14307 {
14308 NEON_ENCODE (SINGLE, inst);
14309 do_vfp_sp_monadic ();
14310 }
037e8744 14311 else
477330fc
RM
14312 {
14313 NEON_ENCODE (DOUBLE, inst);
14314 do_vfp_dp_rd_rm ();
14315 }
037e8744
JB
14316 }
14317 else
14318 {
9db2f6b4
RL
14319 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14320 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14321
14322 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14323 {
14324 case N_MNEM_vcmp:
14325 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14326 break;
14327 case N_MNEM_vcmpe:
14328 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14329 break;
14330 default:
14331 abort ();
14332 }
5f4273c7 14333
9db2f6b4 14334 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14335 {
14336 NEON_ENCODE (SINGLE, inst);
14337 do_vfp_sp_compare_z ();
14338 }
037e8744 14339 else
477330fc
RM
14340 {
14341 NEON_ENCODE (DOUBLE, inst);
14342 do_vfp_dp_rd ();
14343 }
037e8744
JB
14344 }
14345 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14346
14347 /* ARMv8.2 fp16 instruction. */
14348 if (rs == NS_HI || rs == NS_HH)
14349 do_scalar_fp16_v82_encode ();
037e8744
JB
14350}
14351
14352static void
14353nsyn_insert_sp (void)
14354{
14355 inst.operands[1] = inst.operands[0];
14356 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14357 inst.operands[0].reg = REG_SP;
037e8744
JB
14358 inst.operands[0].isreg = 1;
14359 inst.operands[0].writeback = 1;
14360 inst.operands[0].present = 1;
14361}
14362
14363static void
14364do_vfp_nsyn_push (void)
14365{
14366 nsyn_insert_sp ();
14367 if (inst.operands[1].issingle)
14368 do_vfp_nsyn_opcode ("fstmdbs");
14369 else
14370 do_vfp_nsyn_opcode ("fstmdbd");
14371}
14372
14373static void
14374do_vfp_nsyn_pop (void)
14375{
14376 nsyn_insert_sp ();
14377 if (inst.operands[1].issingle)
22b5b651 14378 do_vfp_nsyn_opcode ("fldmias");
037e8744 14379 else
22b5b651 14380 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14381}
14382
14383/* Fix up Neon data-processing instructions, ORing in the correct bits for
14384 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14385
88714cb8
DG
14386static void
14387neon_dp_fixup (struct arm_it* insn)
037e8744 14388{
88714cb8
DG
14389 unsigned int i = insn->instruction;
14390 insn->is_neon = 1;
14391
037e8744
JB
14392 if (thumb_mode)
14393 {
14394 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14395 if (i & (1 << 24))
477330fc 14396 i |= 1 << 28;
5f4273c7 14397
037e8744 14398 i &= ~(1 << 24);
5f4273c7 14399
037e8744
JB
14400 i |= 0xef000000;
14401 }
14402 else
14403 i |= 0xf2000000;
5f4273c7 14404
88714cb8 14405 insn->instruction = i;
037e8744
JB
14406}
14407
14408/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14409 (0, 1, 2, 3). */
14410
14411static unsigned
14412neon_logbits (unsigned x)
14413{
14414 return ffs (x) - 4;
14415}
14416
14417#define LOW4(R) ((R) & 0xf)
14418#define HI1(R) (((R) >> 4) & 1)
14419
14420/* Encode insns with bit pattern:
14421
14422 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14423 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14424
037e8744
JB
14425 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14426 different meaning for some instruction. */
14427
14428static void
14429neon_three_same (int isquad, int ubit, int size)
14430{
14431 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14432 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14433 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14434 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14435 inst.instruction |= LOW4 (inst.operands[2].reg);
14436 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14437 inst.instruction |= (isquad != 0) << 6;
14438 inst.instruction |= (ubit != 0) << 24;
14439 if (size != -1)
14440 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14441
88714cb8 14442 neon_dp_fixup (&inst);
037e8744
JB
14443}
14444
14445/* Encode instructions of the form:
14446
14447 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14448 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14449
14450 Don't write size if SIZE == -1. */
14451
14452static void
14453neon_two_same (int qbit, int ubit, int size)
14454{
14455 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14456 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14457 inst.instruction |= LOW4 (inst.operands[1].reg);
14458 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14459 inst.instruction |= (qbit != 0) << 6;
14460 inst.instruction |= (ubit != 0) << 24;
14461
14462 if (size != -1)
14463 inst.instruction |= neon_logbits (size) << 18;
14464
88714cb8 14465 neon_dp_fixup (&inst);
5287ad62
JB
14466}
14467
14468/* Neon instruction encoders, in approximate order of appearance. */
14469
14470static void
14471do_neon_dyadic_i_su (void)
14472{
037e8744 14473 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14474 struct neon_type_el et = neon_check_type (3, rs,
14475 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14476 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14477}
14478
14479static void
14480do_neon_dyadic_i64_su (void)
14481{
037e8744 14482 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14483 struct neon_type_el et = neon_check_type (3, rs,
14484 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14485 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14486}
14487
14488static void
14489neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14490 unsigned immbits)
5287ad62
JB
14491{
14492 unsigned size = et.size >> 3;
14493 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14494 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14495 inst.instruction |= LOW4 (inst.operands[1].reg);
14496 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14497 inst.instruction |= (isquad != 0) << 6;
14498 inst.instruction |= immbits << 16;
14499 inst.instruction |= (size >> 3) << 7;
14500 inst.instruction |= (size & 0x7) << 19;
14501 if (write_ubit)
14502 inst.instruction |= (uval != 0) << 24;
14503
88714cb8 14504 neon_dp_fixup (&inst);
5287ad62
JB
14505}
14506
14507static void
14508do_neon_shl_imm (void)
14509{
14510 if (!inst.operands[2].isreg)
14511 {
037e8744 14512 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14513 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14514 int imm = inst.operands[2].imm;
14515
14516 constraint (imm < 0 || (unsigned)imm >= et.size,
14517 _("immediate out of range for shift"));
88714cb8 14518 NEON_ENCODE (IMMED, inst);
cb3b1e65 14519 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14520 }
14521 else
14522 {
037e8744 14523 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14524 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14525 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14526 unsigned int tmp;
14527
14528 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14529 vshl.xx Dd, Dm, Dn
14530 whereas other 3-register operations encoded by neon_three_same have
14531 syntax like:
14532 vadd.xx Dd, Dn, Dm
14533 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14534 here. */
627907b7
JB
14535 tmp = inst.operands[2].reg;
14536 inst.operands[2].reg = inst.operands[1].reg;
14537 inst.operands[1].reg = tmp;
88714cb8 14538 NEON_ENCODE (INTEGER, inst);
037e8744 14539 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14540 }
14541}
14542
14543static void
14544do_neon_qshl_imm (void)
14545{
14546 if (!inst.operands[2].isreg)
14547 {
037e8744 14548 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14549 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14550 int imm = inst.operands[2].imm;
627907b7 14551
cb3b1e65
JB
14552 constraint (imm < 0 || (unsigned)imm >= et.size,
14553 _("immediate out of range for shift"));
88714cb8 14554 NEON_ENCODE (IMMED, inst);
cb3b1e65 14555 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14556 }
14557 else
14558 {
037e8744 14559 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14560 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14561 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14562 unsigned int tmp;
14563
14564 /* See note in do_neon_shl_imm. */
14565 tmp = inst.operands[2].reg;
14566 inst.operands[2].reg = inst.operands[1].reg;
14567 inst.operands[1].reg = tmp;
88714cb8 14568 NEON_ENCODE (INTEGER, inst);
037e8744 14569 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14570 }
14571}
14572
627907b7
JB
14573static void
14574do_neon_rshl (void)
14575{
14576 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14577 struct neon_type_el et = neon_check_type (3, rs,
14578 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14579 unsigned int tmp;
14580
14581 tmp = inst.operands[2].reg;
14582 inst.operands[2].reg = inst.operands[1].reg;
14583 inst.operands[1].reg = tmp;
14584 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14585}
14586
5287ad62
JB
14587static int
14588neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14589{
036dc3f7
PB
14590 /* Handle .I8 pseudo-instructions. */
14591 if (size == 8)
5287ad62 14592 {
5287ad62 14593 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14594 FIXME is this the intended semantics? There doesn't seem much point in
14595 accepting .I8 if so. */
5287ad62
JB
14596 immediate |= immediate << 8;
14597 size = 16;
036dc3f7
PB
14598 }
14599
14600 if (size >= 32)
14601 {
14602 if (immediate == (immediate & 0x000000ff))
14603 {
14604 *immbits = immediate;
14605 return 0x1;
14606 }
14607 else if (immediate == (immediate & 0x0000ff00))
14608 {
14609 *immbits = immediate >> 8;
14610 return 0x3;
14611 }
14612 else if (immediate == (immediate & 0x00ff0000))
14613 {
14614 *immbits = immediate >> 16;
14615 return 0x5;
14616 }
14617 else if (immediate == (immediate & 0xff000000))
14618 {
14619 *immbits = immediate >> 24;
14620 return 0x7;
14621 }
14622 if ((immediate & 0xffff) != (immediate >> 16))
14623 goto bad_immediate;
14624 immediate &= 0xffff;
5287ad62
JB
14625 }
14626
14627 if (immediate == (immediate & 0x000000ff))
14628 {
14629 *immbits = immediate;
036dc3f7 14630 return 0x9;
5287ad62
JB
14631 }
14632 else if (immediate == (immediate & 0x0000ff00))
14633 {
14634 *immbits = immediate >> 8;
036dc3f7 14635 return 0xb;
5287ad62
JB
14636 }
14637
14638 bad_immediate:
dcbf9037 14639 first_error (_("immediate value out of range"));
5287ad62
JB
14640 return FAIL;
14641}
14642
5287ad62
JB
14643static void
14644do_neon_logic (void)
14645{
14646 if (inst.operands[2].present && inst.operands[2].isreg)
14647 {
037e8744 14648 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14649 neon_check_type (3, rs, N_IGNORE_TYPE);
14650 /* U bit and size field were set as part of the bitmask. */
88714cb8 14651 NEON_ENCODE (INTEGER, inst);
037e8744 14652 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14653 }
14654 else
14655 {
4316f0d2
DG
14656 const int three_ops_form = (inst.operands[2].present
14657 && !inst.operands[2].isreg);
14658 const int immoperand = (three_ops_form ? 2 : 1);
14659 enum neon_shape rs = (three_ops_form
14660 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14661 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14662 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14663 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14664 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14665 unsigned immbits;
14666 int cmode;
5f4273c7 14667
5287ad62 14668 if (et.type == NT_invtype)
477330fc 14669 return;
5f4273c7 14670
4316f0d2
DG
14671 if (three_ops_form)
14672 constraint (inst.operands[0].reg != inst.operands[1].reg,
14673 _("first and second operands shall be the same register"));
14674
88714cb8 14675 NEON_ENCODE (IMMED, inst);
5287ad62 14676
4316f0d2 14677 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14678 if (et.size == 64)
14679 {
14680 /* .i64 is a pseudo-op, so the immediate must be a repeating
14681 pattern. */
4316f0d2
DG
14682 if (immbits != (inst.operands[immoperand].regisimm ?
14683 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14684 {
14685 /* Set immbits to an invalid constant. */
14686 immbits = 0xdeadbeef;
14687 }
14688 }
14689
5287ad62 14690 switch (opcode)
477330fc
RM
14691 {
14692 case N_MNEM_vbic:
14693 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14694 break;
14695
14696 case N_MNEM_vorr:
14697 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14698 break;
14699
14700 case N_MNEM_vand:
14701 /* Pseudo-instruction for VBIC. */
14702 neon_invert_size (&immbits, 0, et.size);
14703 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14704 break;
14705
14706 case N_MNEM_vorn:
14707 /* Pseudo-instruction for VORR. */
14708 neon_invert_size (&immbits, 0, et.size);
14709 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14710 break;
14711
14712 default:
14713 abort ();
14714 }
5287ad62
JB
14715
14716 if (cmode == FAIL)
477330fc 14717 return;
5287ad62 14718
037e8744 14719 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14720 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14721 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14722 inst.instruction |= cmode << 8;
14723 neon_write_immbits (immbits);
5f4273c7 14724
88714cb8 14725 neon_dp_fixup (&inst);
5287ad62
JB
14726 }
14727}
14728
14729static void
14730do_neon_bitfield (void)
14731{
037e8744 14732 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14733 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14734 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14735}
14736
14737static void
dcbf9037 14738neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14739 unsigned destbits)
5287ad62 14740{
037e8744 14741 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14742 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14743 types | N_KEY);
5287ad62
JB
14744 if (et.type == NT_float)
14745 {
88714cb8 14746 NEON_ENCODE (FLOAT, inst);
cc933301 14747 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14748 }
14749 else
14750 {
88714cb8 14751 NEON_ENCODE (INTEGER, inst);
037e8744 14752 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14753 }
14754}
14755
14756static void
14757do_neon_dyadic_if_su (void)
14758{
dcbf9037 14759 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14760}
14761
14762static void
14763do_neon_dyadic_if_su_d (void)
14764{
14765 /* This version only allow D registers, but that constraint is enforced during
14766 operand parsing so we don't need to do anything extra here. */
dcbf9037 14767 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14768}
14769
5287ad62
JB
14770static void
14771do_neon_dyadic_if_i_d (void)
14772{
428e3f1f
PB
14773 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14774 affected if we specify unsigned args. */
14775 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14776}
14777
037e8744
JB
14778enum vfp_or_neon_is_neon_bits
14779{
14780 NEON_CHECK_CC = 1,
73924fbc
MGD
14781 NEON_CHECK_ARCH = 2,
14782 NEON_CHECK_ARCH8 = 4
037e8744
JB
14783};
14784
14785/* Call this function if an instruction which may have belonged to the VFP or
14786 Neon instruction sets, but turned out to be a Neon instruction (due to the
14787 operand types involved, etc.). We have to check and/or fix-up a couple of
14788 things:
14789
14790 - Make sure the user hasn't attempted to make a Neon instruction
14791 conditional.
14792 - Alter the value in the condition code field if necessary.
14793 - Make sure that the arch supports Neon instructions.
14794
14795 Which of these operations take place depends on bits from enum
14796 vfp_or_neon_is_neon_bits.
14797
14798 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14799 current instruction's condition is COND_ALWAYS, the condition field is
14800 changed to inst.uncond_value. This is necessary because instructions shared
14801 between VFP and Neon may be conditional for the VFP variants only, and the
14802 unconditional Neon version must have, e.g., 0xF in the condition field. */
14803
14804static int
14805vfp_or_neon_is_neon (unsigned check)
14806{
14807 /* Conditions are always legal in Thumb mode (IT blocks). */
14808 if (!thumb_mode && (check & NEON_CHECK_CC))
14809 {
14810 if (inst.cond != COND_ALWAYS)
477330fc
RM
14811 {
14812 first_error (_(BAD_COND));
14813 return FAIL;
14814 }
037e8744 14815 if (inst.uncond_value != -1)
477330fc 14816 inst.instruction |= inst.uncond_value << 28;
037e8744 14817 }
5f4273c7 14818
037e8744 14819 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14820 && !mark_feature_used (&fpu_neon_ext_v1))
14821 {
14822 first_error (_(BAD_FPU));
14823 return FAIL;
14824 }
14825
14826 if ((check & NEON_CHECK_ARCH8)
14827 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14828 {
14829 first_error (_(BAD_FPU));
14830 return FAIL;
14831 }
5f4273c7 14832
037e8744
JB
14833 return SUCCESS;
14834}
14835
5287ad62
JB
14836static void
14837do_neon_addsub_if_i (void)
14838{
037e8744
JB
14839 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14840 return;
14841
14842 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14843 return;
14844
5287ad62
JB
14845 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14846 affected if we specify unsigned args. */
dcbf9037 14847 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14848}
14849
14850/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14851 result to be:
14852 V<op> A,B (A is operand 0, B is operand 2)
14853 to mean:
14854 V<op> A,B,A
14855 not:
14856 V<op> A,B,B
14857 so handle that case specially. */
14858
14859static void
14860neon_exchange_operands (void)
14861{
5287ad62
JB
14862 if (inst.operands[1].present)
14863 {
e1fa0163
NC
14864 void *scratch = xmalloc (sizeof (inst.operands[0]));
14865
5287ad62
JB
14866 /* Swap operands[1] and operands[2]. */
14867 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14868 inst.operands[1] = inst.operands[2];
14869 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14870 free (scratch);
5287ad62
JB
14871 }
14872 else
14873 {
14874 inst.operands[1] = inst.operands[2];
14875 inst.operands[2] = inst.operands[0];
14876 }
14877}
14878
14879static void
14880neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14881{
14882 if (inst.operands[2].isreg)
14883 {
14884 if (invert)
477330fc 14885 neon_exchange_operands ();
dcbf9037 14886 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14887 }
14888 else
14889 {
037e8744 14890 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14891 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14892 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14893
88714cb8 14894 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14895 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14896 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14897 inst.instruction |= LOW4 (inst.operands[1].reg);
14898 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14899 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14900 inst.instruction |= (et.type == NT_float) << 10;
14901 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14902
88714cb8 14903 neon_dp_fixup (&inst);
5287ad62
JB
14904 }
14905}
14906
14907static void
14908do_neon_cmp (void)
14909{
cc933301 14910 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
14911}
14912
14913static void
14914do_neon_cmp_inv (void)
14915{
cc933301 14916 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
14917}
14918
14919static void
14920do_neon_ceq (void)
14921{
14922 neon_compare (N_IF_32, N_IF_32, FALSE);
14923}
14924
14925/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14926 scalars, which are encoded in 5 bits, M : Rm.
14927 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14928 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14929 index in M. */
14930
14931static unsigned
14932neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14933{
dcbf9037
JB
14934 unsigned regno = NEON_SCALAR_REG (scalar);
14935 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14936
14937 switch (elsize)
14938 {
14939 case 16:
14940 if (regno > 7 || elno > 3)
477330fc 14941 goto bad_scalar;
5287ad62 14942 return regno | (elno << 3);
5f4273c7 14943
5287ad62
JB
14944 case 32:
14945 if (regno > 15 || elno > 1)
477330fc 14946 goto bad_scalar;
5287ad62
JB
14947 return regno | (elno << 4);
14948
14949 default:
14950 bad_scalar:
dcbf9037 14951 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14952 }
14953
14954 return 0;
14955}
14956
14957/* Encode multiply / multiply-accumulate scalar instructions. */
14958
14959static void
14960neon_mul_mac (struct neon_type_el et, int ubit)
14961{
dcbf9037
JB
14962 unsigned scalar;
14963
14964 /* Give a more helpful error message if we have an invalid type. */
14965 if (et.type == NT_invtype)
14966 return;
5f4273c7 14967
dcbf9037 14968 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14969 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14970 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14971 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14972 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14973 inst.instruction |= LOW4 (scalar);
14974 inst.instruction |= HI1 (scalar) << 5;
14975 inst.instruction |= (et.type == NT_float) << 8;
14976 inst.instruction |= neon_logbits (et.size) << 20;
14977 inst.instruction |= (ubit != 0) << 24;
14978
88714cb8 14979 neon_dp_fixup (&inst);
5287ad62
JB
14980}
14981
14982static void
14983do_neon_mac_maybe_scalar (void)
14984{
037e8744
JB
14985 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14986 return;
14987
14988 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14989 return;
14990
5287ad62
JB
14991 if (inst.operands[2].isscalar)
14992 {
037e8744 14993 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14994 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 14995 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 14996 NEON_ENCODE (SCALAR, inst);
037e8744 14997 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14998 }
14999 else
428e3f1f
PB
15000 {
15001 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15002 affected if we specify unsigned args. */
15003 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15004 }
5287ad62
JB
15005}
15006
62f3b8c8
PB
15007static void
15008do_neon_fmac (void)
15009{
15010 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15011 return;
15012
15013 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15014 return;
15015
15016 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15017}
15018
5287ad62
JB
15019static void
15020do_neon_tst (void)
15021{
037e8744 15022 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15023 struct neon_type_el et = neon_check_type (3, rs,
15024 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15025 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15026}
15027
15028/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15029 same types as the MAC equivalents. The polynomial type for this instruction
15030 is encoded the same as the integer type. */
15031
15032static void
15033do_neon_mul (void)
15034{
037e8744
JB
15035 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15036 return;
15037
15038 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15039 return;
15040
5287ad62
JB
15041 if (inst.operands[2].isscalar)
15042 do_neon_mac_maybe_scalar ();
15043 else
cc933301 15044 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15045}
15046
15047static void
15048do_neon_qdmulh (void)
15049{
15050 if (inst.operands[2].isscalar)
15051 {
037e8744 15052 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15053 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15054 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15055 NEON_ENCODE (SCALAR, inst);
037e8744 15056 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15057 }
15058 else
15059 {
037e8744 15060 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15061 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15062 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15063 NEON_ENCODE (INTEGER, inst);
5287ad62 15064 /* The U bit (rounding) comes from bit mask. */
037e8744 15065 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15066 }
15067}
15068
643afb90
MW
15069static void
15070do_neon_qrdmlah (void)
15071{
15072 /* Check we're on the correct architecture. */
15073 if (!mark_feature_used (&fpu_neon_ext_armv8))
15074 inst.error =
15075 _("instruction form not available on this architecture.");
15076 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15077 {
15078 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15079 record_feature_use (&fpu_neon_ext_v8_1);
15080 }
15081
15082 if (inst.operands[2].isscalar)
15083 {
15084 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15085 struct neon_type_el et = neon_check_type (3, rs,
15086 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15087 NEON_ENCODE (SCALAR, inst);
15088 neon_mul_mac (et, neon_quad (rs));
15089 }
15090 else
15091 {
15092 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15093 struct neon_type_el et = neon_check_type (3, rs,
15094 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15095 NEON_ENCODE (INTEGER, inst);
15096 /* The U bit (rounding) comes from bit mask. */
15097 neon_three_same (neon_quad (rs), 0, et.size);
15098 }
15099}
15100
5287ad62
JB
15101static void
15102do_neon_fcmp_absolute (void)
15103{
037e8744 15104 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15105 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15106 N_F_16_32 | N_KEY);
5287ad62 15107 /* Size field comes from bit mask. */
cc933301 15108 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15109}
15110
15111static void
15112do_neon_fcmp_absolute_inv (void)
15113{
15114 neon_exchange_operands ();
15115 do_neon_fcmp_absolute ();
15116}
15117
15118static void
15119do_neon_step (void)
15120{
037e8744 15121 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15122 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15123 N_F_16_32 | N_KEY);
15124 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15125}
15126
15127static void
15128do_neon_abs_neg (void)
15129{
037e8744
JB
15130 enum neon_shape rs;
15131 struct neon_type_el et;
5f4273c7 15132
037e8744
JB
15133 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15134 return;
15135
15136 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15137 return;
15138
15139 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15140 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15141
5287ad62
JB
15142 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15143 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15144 inst.instruction |= LOW4 (inst.operands[1].reg);
15145 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15146 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15147 inst.instruction |= (et.type == NT_float) << 10;
15148 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15149
88714cb8 15150 neon_dp_fixup (&inst);
5287ad62
JB
15151}
15152
15153static void
15154do_neon_sli (void)
15155{
037e8744 15156 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15157 struct neon_type_el et = neon_check_type (2, rs,
15158 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15159 int imm = inst.operands[2].imm;
15160 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15161 _("immediate out of range for insert"));
037e8744 15162 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15163}
15164
15165static void
15166do_neon_sri (void)
15167{
037e8744 15168 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15169 struct neon_type_el et = neon_check_type (2, rs,
15170 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15171 int imm = inst.operands[2].imm;
15172 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15173 _("immediate out of range for insert"));
037e8744 15174 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15175}
15176
15177static void
15178do_neon_qshlu_imm (void)
15179{
037e8744 15180 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15181 struct neon_type_el et = neon_check_type (2, rs,
15182 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15183 int imm = inst.operands[2].imm;
15184 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15185 _("immediate out of range for shift"));
5287ad62
JB
15186 /* Only encodes the 'U present' variant of the instruction.
15187 In this case, signed types have OP (bit 8) set to 0.
15188 Unsigned types have OP set to 1. */
15189 inst.instruction |= (et.type == NT_unsigned) << 8;
15190 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15191 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15192}
15193
15194static void
15195do_neon_qmovn (void)
15196{
15197 struct neon_type_el et = neon_check_type (2, NS_DQ,
15198 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15199 /* Saturating move where operands can be signed or unsigned, and the
15200 destination has the same signedness. */
88714cb8 15201 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15202 if (et.type == NT_unsigned)
15203 inst.instruction |= 0xc0;
15204 else
15205 inst.instruction |= 0x80;
15206 neon_two_same (0, 1, et.size / 2);
15207}
15208
15209static void
15210do_neon_qmovun (void)
15211{
15212 struct neon_type_el et = neon_check_type (2, NS_DQ,
15213 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15214 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15215 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15216 neon_two_same (0, 1, et.size / 2);
15217}
15218
15219static void
15220do_neon_rshift_sat_narrow (void)
15221{
15222 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15223 or unsigned. If operands are unsigned, results must also be unsigned. */
15224 struct neon_type_el et = neon_check_type (2, NS_DQI,
15225 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15226 int imm = inst.operands[2].imm;
15227 /* This gets the bounds check, size encoding and immediate bits calculation
15228 right. */
15229 et.size /= 2;
5f4273c7 15230
5287ad62
JB
15231 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15232 VQMOVN.I<size> <Dd>, <Qm>. */
15233 if (imm == 0)
15234 {
15235 inst.operands[2].present = 0;
15236 inst.instruction = N_MNEM_vqmovn;
15237 do_neon_qmovn ();
15238 return;
15239 }
5f4273c7 15240
5287ad62 15241 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15242 _("immediate out of range"));
5287ad62
JB
15243 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15244}
15245
15246static void
15247do_neon_rshift_sat_narrow_u (void)
15248{
15249 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15250 or unsigned. If operands are unsigned, results must also be unsigned. */
15251 struct neon_type_el et = neon_check_type (2, NS_DQI,
15252 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15253 int imm = inst.operands[2].imm;
15254 /* This gets the bounds check, size encoding and immediate bits calculation
15255 right. */
15256 et.size /= 2;
15257
15258 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15259 VQMOVUN.I<size> <Dd>, <Qm>. */
15260 if (imm == 0)
15261 {
15262 inst.operands[2].present = 0;
15263 inst.instruction = N_MNEM_vqmovun;
15264 do_neon_qmovun ();
15265 return;
15266 }
15267
15268 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15269 _("immediate out of range"));
5287ad62
JB
15270 /* FIXME: The manual is kind of unclear about what value U should have in
15271 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15272 must be 1. */
15273 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15274}
15275
15276static void
15277do_neon_movn (void)
15278{
15279 struct neon_type_el et = neon_check_type (2, NS_DQ,
15280 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15281 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15282 neon_two_same (0, 1, et.size / 2);
15283}
15284
15285static void
15286do_neon_rshift_narrow (void)
15287{
15288 struct neon_type_el et = neon_check_type (2, NS_DQI,
15289 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15290 int imm = inst.operands[2].imm;
15291 /* This gets the bounds check, size encoding and immediate bits calculation
15292 right. */
15293 et.size /= 2;
5f4273c7 15294
5287ad62
JB
15295 /* If immediate is zero then we are a pseudo-instruction for
15296 VMOVN.I<size> <Dd>, <Qm> */
15297 if (imm == 0)
15298 {
15299 inst.operands[2].present = 0;
15300 inst.instruction = N_MNEM_vmovn;
15301 do_neon_movn ();
15302 return;
15303 }
5f4273c7 15304
5287ad62 15305 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15306 _("immediate out of range for narrowing operation"));
5287ad62
JB
15307 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15308}
15309
15310static void
15311do_neon_shll (void)
15312{
15313 /* FIXME: Type checking when lengthening. */
15314 struct neon_type_el et = neon_check_type (2, NS_QDI,
15315 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15316 unsigned imm = inst.operands[2].imm;
15317
15318 if (imm == et.size)
15319 {
15320 /* Maximum shift variant. */
88714cb8 15321 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15322 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15323 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15324 inst.instruction |= LOW4 (inst.operands[1].reg);
15325 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15326 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15327
88714cb8 15328 neon_dp_fixup (&inst);
5287ad62
JB
15329 }
15330 else
15331 {
15332 /* A more-specific type check for non-max versions. */
15333 et = neon_check_type (2, NS_QDI,
477330fc 15334 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15335 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15336 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15337 }
15338}
15339
037e8744 15340/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15341 the current instruction is. */
15342
6b9a8b67
MGD
15343#define CVT_FLAVOUR_VAR \
15344 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15345 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15346 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15347 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15348 /* Half-precision conversions. */ \
cc933301
JW
15349 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15350 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15351 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15352 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15353 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15354 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15355 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15356 Compared with single/double precision variants, only the co-processor \
15357 field is different, so the encoding flow is reused here. */ \
15358 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15359 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15360 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15361 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15362 /* VFP instructions. */ \
15363 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15364 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15365 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15366 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15367 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15368 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15369 /* VFP instructions with bitshift. */ \
15370 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15371 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15372 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15373 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15374 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15375 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15376 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15377 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15378
15379#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15380 neon_cvt_flavour_##C,
15381
15382/* The different types of conversions we can do. */
15383enum neon_cvt_flavour
15384{
15385 CVT_FLAVOUR_VAR
15386 neon_cvt_flavour_invalid,
15387 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15388};
15389
15390#undef CVT_VAR
15391
15392static enum neon_cvt_flavour
15393get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15394{
6b9a8b67
MGD
15395#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15396 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15397 if (et.type != NT_invtype) \
15398 { \
15399 inst.error = NULL; \
15400 return (neon_cvt_flavour_##C); \
5287ad62 15401 }
6b9a8b67 15402
5287ad62 15403 struct neon_type_el et;
037e8744 15404 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15405 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15406 /* The instruction versions which take an immediate take one register
15407 argument, which is extended to the width of the full register. Thus the
15408 "source" and "destination" registers must have the same width. Hack that
15409 here by making the size equal to the key (wider, in this case) operand. */
15410 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15411
6b9a8b67
MGD
15412 CVT_FLAVOUR_VAR;
15413
15414 return neon_cvt_flavour_invalid;
5287ad62
JB
15415#undef CVT_VAR
15416}
15417
7e8e6784
MGD
15418enum neon_cvt_mode
15419{
15420 neon_cvt_mode_a,
15421 neon_cvt_mode_n,
15422 neon_cvt_mode_p,
15423 neon_cvt_mode_m,
15424 neon_cvt_mode_z,
30bdf752
MGD
15425 neon_cvt_mode_x,
15426 neon_cvt_mode_r
7e8e6784
MGD
15427};
15428
037e8744
JB
15429/* Neon-syntax VFP conversions. */
15430
5287ad62 15431static void
6b9a8b67 15432do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15433{
037e8744 15434 const char *opname = 0;
5f4273c7 15435
d54af2d0
RL
15436 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15437 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15438 {
037e8744
JB
15439 /* Conversions with immediate bitshift. */
15440 const char *enc[] =
477330fc 15441 {
6b9a8b67
MGD
15442#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15443 CVT_FLAVOUR_VAR
15444 NULL
15445#undef CVT_VAR
477330fc 15446 };
037e8744 15447
6b9a8b67 15448 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15449 {
15450 opname = enc[flavour];
15451 constraint (inst.operands[0].reg != inst.operands[1].reg,
15452 _("operands 0 and 1 must be the same register"));
15453 inst.operands[1] = inst.operands[2];
15454 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15455 }
5287ad62
JB
15456 }
15457 else
15458 {
037e8744
JB
15459 /* Conversions without bitshift. */
15460 const char *enc[] =
477330fc 15461 {
6b9a8b67
MGD
15462#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15463 CVT_FLAVOUR_VAR
15464 NULL
15465#undef CVT_VAR
477330fc 15466 };
037e8744 15467
6b9a8b67 15468 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15469 opname = enc[flavour];
037e8744
JB
15470 }
15471
15472 if (opname)
15473 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15474
15475 /* ARMv8.2 fp16 VCVT instruction. */
15476 if (flavour == neon_cvt_flavour_s32_f16
15477 || flavour == neon_cvt_flavour_u32_f16
15478 || flavour == neon_cvt_flavour_f16_u32
15479 || flavour == neon_cvt_flavour_f16_s32)
15480 do_scalar_fp16_v82_encode ();
037e8744
JB
15481}
15482
15483static void
15484do_vfp_nsyn_cvtz (void)
15485{
d54af2d0 15486 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15487 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15488 const char *enc[] =
15489 {
6b9a8b67
MGD
15490#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15491 CVT_FLAVOUR_VAR
15492 NULL
15493#undef CVT_VAR
037e8744
JB
15494 };
15495
6b9a8b67 15496 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15497 do_vfp_nsyn_opcode (enc[flavour]);
15498}
f31fef98 15499
037e8744 15500static void
bacebabc 15501do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15502 enum neon_cvt_mode mode)
15503{
15504 int sz, op;
15505 int rm;
15506
a715796b
TG
15507 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15508 D register operands. */
15509 if (flavour == neon_cvt_flavour_s32_f64
15510 || flavour == neon_cvt_flavour_u32_f64)
15511 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15512 _(BAD_FPU));
15513
9db2f6b4
RL
15514 if (flavour == neon_cvt_flavour_s32_f16
15515 || flavour == neon_cvt_flavour_u32_f16)
15516 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15517 _(BAD_FP16));
15518
7e8e6784
MGD
15519 set_it_insn_type (OUTSIDE_IT_INSN);
15520
15521 switch (flavour)
15522 {
15523 case neon_cvt_flavour_s32_f64:
15524 sz = 1;
827f64ff 15525 op = 1;
7e8e6784
MGD
15526 break;
15527 case neon_cvt_flavour_s32_f32:
15528 sz = 0;
15529 op = 1;
15530 break;
9db2f6b4
RL
15531 case neon_cvt_flavour_s32_f16:
15532 sz = 0;
15533 op = 1;
15534 break;
7e8e6784
MGD
15535 case neon_cvt_flavour_u32_f64:
15536 sz = 1;
15537 op = 0;
15538 break;
15539 case neon_cvt_flavour_u32_f32:
15540 sz = 0;
15541 op = 0;
15542 break;
9db2f6b4
RL
15543 case neon_cvt_flavour_u32_f16:
15544 sz = 0;
15545 op = 0;
15546 break;
7e8e6784
MGD
15547 default:
15548 first_error (_("invalid instruction shape"));
15549 return;
15550 }
15551
15552 switch (mode)
15553 {
15554 case neon_cvt_mode_a: rm = 0; break;
15555 case neon_cvt_mode_n: rm = 1; break;
15556 case neon_cvt_mode_p: rm = 2; break;
15557 case neon_cvt_mode_m: rm = 3; break;
15558 default: first_error (_("invalid rounding mode")); return;
15559 }
15560
15561 NEON_ENCODE (FPV8, inst);
15562 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15563 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15564 inst.instruction |= sz << 8;
9db2f6b4
RL
15565
15566 /* ARMv8.2 fp16 VCVT instruction. */
15567 if (flavour == neon_cvt_flavour_s32_f16
15568 ||flavour == neon_cvt_flavour_u32_f16)
15569 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15570 inst.instruction |= op << 7;
15571 inst.instruction |= rm << 16;
15572 inst.instruction |= 0xf0000000;
15573 inst.is_neon = TRUE;
15574}
15575
15576static void
15577do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15578{
15579 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15580 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15581 NS_FH, NS_HF, NS_FHI, NS_HFI,
15582 NS_NULL);
6b9a8b67 15583 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15584
cc933301
JW
15585 if (flavour == neon_cvt_flavour_invalid)
15586 return;
15587
e3e535bc 15588 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15589 if (mode == neon_cvt_mode_z
e3e535bc 15590 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15591 && (flavour == neon_cvt_flavour_s16_f16
15592 || flavour == neon_cvt_flavour_u16_f16
15593 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15594 || flavour == neon_cvt_flavour_u32_f32
15595 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15596 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15597 && (rs == NS_FD || rs == NS_FF))
15598 {
15599 do_vfp_nsyn_cvtz ();
15600 return;
15601 }
15602
9db2f6b4
RL
15603 /* ARMv8.2 fp16 VCVT conversions. */
15604 if (mode == neon_cvt_mode_z
15605 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15606 && (flavour == neon_cvt_flavour_s32_f16
15607 || flavour == neon_cvt_flavour_u32_f16)
15608 && (rs == NS_FH))
15609 {
15610 do_vfp_nsyn_cvtz ();
15611 do_scalar_fp16_v82_encode ();
15612 return;
15613 }
15614
037e8744 15615 /* VFP rather than Neon conversions. */
6b9a8b67 15616 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15617 {
7e8e6784
MGD
15618 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15619 do_vfp_nsyn_cvt (rs, flavour);
15620 else
15621 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15622
037e8744
JB
15623 return;
15624 }
15625
15626 switch (rs)
15627 {
15628 case NS_DDI:
15629 case NS_QQI:
15630 {
477330fc 15631 unsigned immbits;
cc933301
JW
15632 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15633 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15634
477330fc
RM
15635 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15636 return;
037e8744 15637
477330fc
RM
15638 /* Fixed-point conversion with #0 immediate is encoded as an
15639 integer conversion. */
15640 if (inst.operands[2].present && inst.operands[2].imm == 0)
15641 goto int_encode;
477330fc
RM
15642 NEON_ENCODE (IMMED, inst);
15643 if (flavour != neon_cvt_flavour_invalid)
15644 inst.instruction |= enctab[flavour];
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 |= 1 << 21;
cc933301
JW
15651 if (flavour < neon_cvt_flavour_s16_f16)
15652 {
15653 inst.instruction |= 1 << 21;
15654 immbits = 32 - inst.operands[2].imm;
15655 inst.instruction |= immbits << 16;
15656 }
15657 else
15658 {
15659 inst.instruction |= 3 << 20;
15660 immbits = 16 - inst.operands[2].imm;
15661 inst.instruction |= immbits << 16;
15662 inst.instruction &= ~(1 << 9);
15663 }
477330fc
RM
15664
15665 neon_dp_fixup (&inst);
037e8744
JB
15666 }
15667 break;
15668
15669 case NS_DD:
15670 case NS_QQ:
7e8e6784
MGD
15671 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15672 {
15673 NEON_ENCODE (FLOAT, inst);
15674 set_it_insn_type (OUTSIDE_IT_INSN);
15675
15676 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15677 return;
15678
15679 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15680 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15681 inst.instruction |= LOW4 (inst.operands[1].reg);
15682 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15683 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15684 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15685 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15686 inst.instruction |= mode << 8;
cc933301
JW
15687 if (flavour == neon_cvt_flavour_u16_f16
15688 || flavour == neon_cvt_flavour_s16_f16)
15689 /* Mask off the original size bits and reencode them. */
15690 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15691
7e8e6784
MGD
15692 if (thumb_mode)
15693 inst.instruction |= 0xfc000000;
15694 else
15695 inst.instruction |= 0xf0000000;
15696 }
15697 else
15698 {
037e8744 15699 int_encode:
7e8e6784 15700 {
cc933301
JW
15701 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15702 0x100, 0x180, 0x0, 0x080};
037e8744 15703
7e8e6784 15704 NEON_ENCODE (INTEGER, inst);
037e8744 15705
7e8e6784
MGD
15706 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15707 return;
037e8744 15708
7e8e6784
MGD
15709 if (flavour != neon_cvt_flavour_invalid)
15710 inst.instruction |= enctab[flavour];
037e8744 15711
7e8e6784
MGD
15712 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15713 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15714 inst.instruction |= LOW4 (inst.operands[1].reg);
15715 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15716 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15717 if (flavour >= neon_cvt_flavour_s16_f16
15718 && flavour <= neon_cvt_flavour_f16_u16)
15719 /* Half precision. */
15720 inst.instruction |= 1 << 18;
15721 else
15722 inst.instruction |= 2 << 18;
037e8744 15723
7e8e6784
MGD
15724 neon_dp_fixup (&inst);
15725 }
15726 }
15727 break;
037e8744 15728
8e79c3df
CM
15729 /* Half-precision conversions for Advanced SIMD -- neon. */
15730 case NS_QD:
15731 case NS_DQ:
15732
15733 if ((rs == NS_DQ)
15734 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15735 {
15736 as_bad (_("operand size must match register width"));
15737 break;
15738 }
15739
15740 if ((rs == NS_QD)
15741 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15742 {
15743 as_bad (_("operand size must match register width"));
15744 break;
15745 }
15746
15747 if (rs == NS_DQ)
477330fc 15748 inst.instruction = 0x3b60600;
8e79c3df
CM
15749 else
15750 inst.instruction = 0x3b60700;
15751
15752 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15753 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15754 inst.instruction |= LOW4 (inst.operands[1].reg);
15755 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15756 neon_dp_fixup (&inst);
8e79c3df
CM
15757 break;
15758
037e8744
JB
15759 default:
15760 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15761 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15762 do_vfp_nsyn_cvt (rs, flavour);
15763 else
15764 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15765 }
5287ad62
JB
15766}
15767
e3e535bc
NC
15768static void
15769do_neon_cvtr (void)
15770{
7e8e6784 15771 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15772}
15773
15774static void
15775do_neon_cvt (void)
15776{
7e8e6784
MGD
15777 do_neon_cvt_1 (neon_cvt_mode_z);
15778}
15779
15780static void
15781do_neon_cvta (void)
15782{
15783 do_neon_cvt_1 (neon_cvt_mode_a);
15784}
15785
15786static void
15787do_neon_cvtn (void)
15788{
15789 do_neon_cvt_1 (neon_cvt_mode_n);
15790}
15791
15792static void
15793do_neon_cvtp (void)
15794{
15795 do_neon_cvt_1 (neon_cvt_mode_p);
15796}
15797
15798static void
15799do_neon_cvtm (void)
15800{
15801 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15802}
15803
8e79c3df 15804static void
c70a8987 15805do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15806{
c70a8987
MGD
15807 if (is_double)
15808 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15809
c70a8987
MGD
15810 encode_arm_vfp_reg (inst.operands[0].reg,
15811 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15812 encode_arm_vfp_reg (inst.operands[1].reg,
15813 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15814 inst.instruction |= to ? 0x10000 : 0;
15815 inst.instruction |= t ? 0x80 : 0;
15816 inst.instruction |= is_double ? 0x100 : 0;
15817 do_vfp_cond_or_thumb ();
15818}
8e79c3df 15819
c70a8987
MGD
15820static void
15821do_neon_cvttb_1 (bfd_boolean t)
15822{
d54af2d0
RL
15823 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15824 NS_DF, NS_DH, NS_NULL);
8e79c3df 15825
c70a8987
MGD
15826 if (rs == NS_NULL)
15827 return;
15828 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15829 {
15830 inst.error = NULL;
15831 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15832 }
15833 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15834 {
15835 inst.error = NULL;
15836 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15837 }
15838 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15839 {
a715796b
TG
15840 /* The VCVTB and VCVTT instructions with D-register operands
15841 don't work for SP only targets. */
15842 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15843 _(BAD_FPU));
15844
c70a8987
MGD
15845 inst.error = NULL;
15846 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15847 }
15848 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15849 {
a715796b
TG
15850 /* The VCVTB and VCVTT instructions with D-register operands
15851 don't work for SP only targets. */
15852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15853 _(BAD_FPU));
15854
c70a8987
MGD
15855 inst.error = NULL;
15856 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15857 }
15858 else
15859 return;
15860}
15861
15862static void
15863do_neon_cvtb (void)
15864{
15865 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15866}
15867
15868
15869static void
15870do_neon_cvtt (void)
15871{
c70a8987 15872 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15873}
15874
5287ad62
JB
15875static void
15876neon_move_immediate (void)
15877{
037e8744
JB
15878 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15879 struct neon_type_el et = neon_check_type (2, rs,
15880 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15881 unsigned immlo, immhi = 0, immbits;
c96612cc 15882 int op, cmode, float_p;
5287ad62 15883
037e8744 15884 constraint (et.type == NT_invtype,
477330fc 15885 _("operand size must be specified for immediate VMOV"));
037e8744 15886
5287ad62
JB
15887 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15888 op = (inst.instruction & (1 << 5)) != 0;
15889
15890 immlo = inst.operands[1].imm;
15891 if (inst.operands[1].regisimm)
15892 immhi = inst.operands[1].reg;
15893
15894 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15895 _("immediate has bits set outside the operand size"));
5287ad62 15896
c96612cc
JB
15897 float_p = inst.operands[1].immisfloat;
15898
15899 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15900 et.size, et.type)) == FAIL)
5287ad62
JB
15901 {
15902 /* Invert relevant bits only. */
15903 neon_invert_size (&immlo, &immhi, et.size);
15904 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15905 with one or the other; those cases are caught by
15906 neon_cmode_for_move_imm. */
5287ad62 15907 op = !op;
c96612cc
JB
15908 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15909 &op, et.size, et.type)) == FAIL)
477330fc
RM
15910 {
15911 first_error (_("immediate out of range"));
15912 return;
15913 }
5287ad62
JB
15914 }
15915
15916 inst.instruction &= ~(1 << 5);
15917 inst.instruction |= op << 5;
15918
15919 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15920 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15921 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15922 inst.instruction |= cmode << 8;
15923
15924 neon_write_immbits (immbits);
15925}
15926
15927static void
15928do_neon_mvn (void)
15929{
15930 if (inst.operands[1].isreg)
15931 {
037e8744 15932 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15933
88714cb8 15934 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15935 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15936 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15937 inst.instruction |= LOW4 (inst.operands[1].reg);
15938 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15939 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15940 }
15941 else
15942 {
88714cb8 15943 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15944 neon_move_immediate ();
15945 }
15946
88714cb8 15947 neon_dp_fixup (&inst);
5287ad62
JB
15948}
15949
15950/* Encode instructions of form:
15951
15952 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15953 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15954
15955static void
15956neon_mixed_length (struct neon_type_el et, unsigned size)
15957{
15958 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15959 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15960 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15961 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15962 inst.instruction |= LOW4 (inst.operands[2].reg);
15963 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15964 inst.instruction |= (et.type == NT_unsigned) << 24;
15965 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15966
88714cb8 15967 neon_dp_fixup (&inst);
5287ad62
JB
15968}
15969
15970static void
15971do_neon_dyadic_long (void)
15972{
15973 /* FIXME: Type checking for lengthening op. */
15974 struct neon_type_el et = neon_check_type (3, NS_QDD,
15975 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15976 neon_mixed_length (et, et.size);
15977}
15978
15979static void
15980do_neon_abal (void)
15981{
15982 struct neon_type_el et = neon_check_type (3, NS_QDD,
15983 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15984 neon_mixed_length (et, et.size);
15985}
15986
15987static void
15988neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15989{
15990 if (inst.operands[2].isscalar)
15991 {
dcbf9037 15992 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15993 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15994 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15995 neon_mul_mac (et, et.type == NT_unsigned);
15996 }
15997 else
15998 {
15999 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16000 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16001 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16002 neon_mixed_length (et, et.size);
16003 }
16004}
16005
16006static void
16007do_neon_mac_maybe_scalar_long (void)
16008{
16009 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16010}
16011
16012static void
16013do_neon_dyadic_wide (void)
16014{
16015 struct neon_type_el et = neon_check_type (3, NS_QQD,
16016 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16017 neon_mixed_length (et, et.size);
16018}
16019
16020static void
16021do_neon_dyadic_narrow (void)
16022{
16023 struct neon_type_el et = neon_check_type (3, NS_QDD,
16024 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16025 /* Operand sign is unimportant, and the U bit is part of the opcode,
16026 so force the operand type to integer. */
16027 et.type = NT_integer;
5287ad62
JB
16028 neon_mixed_length (et, et.size / 2);
16029}
16030
16031static void
16032do_neon_mul_sat_scalar_long (void)
16033{
16034 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16035}
16036
16037static void
16038do_neon_vmull (void)
16039{
16040 if (inst.operands[2].isscalar)
16041 do_neon_mac_maybe_scalar_long ();
16042 else
16043 {
16044 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16045 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16046
5287ad62 16047 if (et.type == NT_poly)
477330fc 16048 NEON_ENCODE (POLY, inst);
5287ad62 16049 else
477330fc 16050 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16051
16052 /* For polynomial encoding the U bit must be zero, and the size must
16053 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16054 obviously, as 0b10). */
16055 if (et.size == 64)
16056 {
16057 /* Check we're on the correct architecture. */
16058 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16059 inst.error =
16060 _("Instruction form not available on this architecture.");
16061
16062 et.size = 32;
16063 }
16064
5287ad62
JB
16065 neon_mixed_length (et, et.size);
16066 }
16067}
16068
16069static void
16070do_neon_ext (void)
16071{
037e8744 16072 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16073 struct neon_type_el et = neon_check_type (3, rs,
16074 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16075 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16076
16077 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16078 _("shift out of range"));
5287ad62
JB
16079 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16080 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16081 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16082 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16083 inst.instruction |= LOW4 (inst.operands[2].reg);
16084 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16085 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16086 inst.instruction |= imm << 8;
5f4273c7 16087
88714cb8 16088 neon_dp_fixup (&inst);
5287ad62
JB
16089}
16090
16091static void
16092do_neon_rev (void)
16093{
037e8744 16094 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16095 struct neon_type_el et = neon_check_type (2, rs,
16096 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16097 unsigned op = (inst.instruction >> 7) & 3;
16098 /* N (width of reversed regions) is encoded as part of the bitmask. We
16099 extract it here to check the elements to be reversed are smaller.
16100 Otherwise we'd get a reserved instruction. */
16101 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16102 gas_assert (elsize != 0);
5287ad62 16103 constraint (et.size >= elsize,
477330fc 16104 _("elements must be smaller than reversal region"));
037e8744 16105 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16106}
16107
16108static void
16109do_neon_dup (void)
16110{
16111 if (inst.operands[1].isscalar)
16112 {
037e8744 16113 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16114 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16115 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16116 unsigned sizebits = et.size >> 3;
dcbf9037 16117 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16118 int logsize = neon_logbits (et.size);
dcbf9037 16119 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16120
16121 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16122 return;
037e8744 16123
88714cb8 16124 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16125 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16126 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16127 inst.instruction |= LOW4 (dm);
16128 inst.instruction |= HI1 (dm) << 5;
037e8744 16129 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16130 inst.instruction |= x << 17;
16131 inst.instruction |= sizebits << 16;
5f4273c7 16132
88714cb8 16133 neon_dp_fixup (&inst);
5287ad62
JB
16134 }
16135 else
16136 {
037e8744
JB
16137 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16138 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16139 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16140 /* Duplicate ARM register to lanes of vector. */
88714cb8 16141 NEON_ENCODE (ARMREG, inst);
5287ad62 16142 switch (et.size)
477330fc
RM
16143 {
16144 case 8: inst.instruction |= 0x400000; break;
16145 case 16: inst.instruction |= 0x000020; break;
16146 case 32: inst.instruction |= 0x000000; break;
16147 default: break;
16148 }
5287ad62
JB
16149 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16150 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16151 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16152 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16153 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16154 variants, except for the condition field. */
037e8744 16155 do_vfp_cond_or_thumb ();
5287ad62
JB
16156 }
16157}
16158
16159/* VMOV has particularly many variations. It can be one of:
16160 0. VMOV<c><q> <Qd>, <Qm>
16161 1. VMOV<c><q> <Dd>, <Dm>
16162 (Register operations, which are VORR with Rm = Rn.)
16163 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16164 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16165 (Immediate loads.)
16166 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16167 (ARM register to scalar.)
16168 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16169 (Two ARM registers to vector.)
16170 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16171 (Scalar to ARM register.)
16172 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16173 (Vector to two ARM registers.)
037e8744
JB
16174 8. VMOV.F32 <Sd>, <Sm>
16175 9. VMOV.F64 <Dd>, <Dm>
16176 (VFP register moves.)
16177 10. VMOV.F32 <Sd>, #imm
16178 11. VMOV.F64 <Dd>, #imm
16179 (VFP float immediate load.)
16180 12. VMOV <Rd>, <Sm>
16181 (VFP single to ARM reg.)
16182 13. VMOV <Sd>, <Rm>
16183 (ARM reg to VFP single.)
16184 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16185 (Two ARM regs to two VFP singles.)
16186 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16187 (Two VFP singles to two ARM regs.)
5f4273c7 16188
037e8744
JB
16189 These cases can be disambiguated using neon_select_shape, except cases 1/9
16190 and 3/11 which depend on the operand type too.
5f4273c7 16191
5287ad62 16192 All the encoded bits are hardcoded by this function.
5f4273c7 16193
b7fc2769
JB
16194 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16195 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16196
5287ad62 16197 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16198 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16199
16200static void
16201do_neon_mov (void)
16202{
037e8744 16203 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16204 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16205 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16206 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16207 struct neon_type_el et;
16208 const char *ldconst = 0;
5287ad62 16209
037e8744 16210 switch (rs)
5287ad62 16211 {
037e8744
JB
16212 case NS_DD: /* case 1/9. */
16213 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16214 /* It is not an error here if no type is given. */
16215 inst.error = NULL;
16216 if (et.type == NT_float && et.size == 64)
477330fc
RM
16217 {
16218 do_vfp_nsyn_opcode ("fcpyd");
16219 break;
16220 }
037e8744 16221 /* fall through. */
5287ad62 16222
037e8744
JB
16223 case NS_QQ: /* case 0/1. */
16224 {
477330fc
RM
16225 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16226 return;
16227 /* The architecture manual I have doesn't explicitly state which
16228 value the U bit should have for register->register moves, but
16229 the equivalent VORR instruction has U = 0, so do that. */
16230 inst.instruction = 0x0200110;
16231 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16232 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16233 inst.instruction |= LOW4 (inst.operands[1].reg);
16234 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16235 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16236 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16237 inst.instruction |= neon_quad (rs) << 6;
16238
16239 neon_dp_fixup (&inst);
037e8744
JB
16240 }
16241 break;
5f4273c7 16242
037e8744
JB
16243 case NS_DI: /* case 3/11. */
16244 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16245 inst.error = NULL;
16246 if (et.type == NT_float && et.size == 64)
477330fc
RM
16247 {
16248 /* case 11 (fconstd). */
16249 ldconst = "fconstd";
16250 goto encode_fconstd;
16251 }
037e8744
JB
16252 /* fall through. */
16253
16254 case NS_QI: /* case 2/3. */
16255 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16256 return;
037e8744
JB
16257 inst.instruction = 0x0800010;
16258 neon_move_immediate ();
88714cb8 16259 neon_dp_fixup (&inst);
5287ad62 16260 break;
5f4273c7 16261
037e8744
JB
16262 case NS_SR: /* case 4. */
16263 {
477330fc
RM
16264 unsigned bcdebits = 0;
16265 int logsize;
16266 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16267 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16268
05ac0ffb
JB
16269 /* .<size> is optional here, defaulting to .32. */
16270 if (inst.vectype.elems == 0
16271 && inst.operands[0].vectype.type == NT_invtype
16272 && inst.operands[1].vectype.type == NT_invtype)
16273 {
16274 inst.vectype.el[0].type = NT_untyped;
16275 inst.vectype.el[0].size = 32;
16276 inst.vectype.elems = 1;
16277 }
16278
477330fc
RM
16279 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16280 logsize = neon_logbits (et.size);
16281
16282 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16283 _(BAD_FPU));
16284 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16285 && et.size != 32, _(BAD_FPU));
16286 constraint (et.type == NT_invtype, _("bad type for scalar"));
16287 constraint (x >= 64 / et.size, _("scalar index out of range"));
16288
16289 switch (et.size)
16290 {
16291 case 8: bcdebits = 0x8; break;
16292 case 16: bcdebits = 0x1; break;
16293 case 32: bcdebits = 0x0; break;
16294 default: ;
16295 }
16296
16297 bcdebits |= x << logsize;
16298
16299 inst.instruction = 0xe000b10;
16300 do_vfp_cond_or_thumb ();
16301 inst.instruction |= LOW4 (dn) << 16;
16302 inst.instruction |= HI1 (dn) << 7;
16303 inst.instruction |= inst.operands[1].reg << 12;
16304 inst.instruction |= (bcdebits & 3) << 5;
16305 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16306 }
16307 break;
5f4273c7 16308
037e8744 16309 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16310 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16311 _(BAD_FPU));
b7fc2769 16312
037e8744
JB
16313 inst.instruction = 0xc400b10;
16314 do_vfp_cond_or_thumb ();
16315 inst.instruction |= LOW4 (inst.operands[0].reg);
16316 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16317 inst.instruction |= inst.operands[1].reg << 12;
16318 inst.instruction |= inst.operands[2].reg << 16;
16319 break;
5f4273c7 16320
037e8744
JB
16321 case NS_RS: /* case 6. */
16322 {
477330fc
RM
16323 unsigned logsize;
16324 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16325 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16326 unsigned abcdebits = 0;
037e8744 16327
05ac0ffb
JB
16328 /* .<dt> is optional here, defaulting to .32. */
16329 if (inst.vectype.elems == 0
16330 && inst.operands[0].vectype.type == NT_invtype
16331 && inst.operands[1].vectype.type == NT_invtype)
16332 {
16333 inst.vectype.el[0].type = NT_untyped;
16334 inst.vectype.el[0].size = 32;
16335 inst.vectype.elems = 1;
16336 }
16337
91d6fa6a
NC
16338 et = neon_check_type (2, NS_NULL,
16339 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16340 logsize = neon_logbits (et.size);
16341
16342 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16343 _(BAD_FPU));
16344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16345 && et.size != 32, _(BAD_FPU));
16346 constraint (et.type == NT_invtype, _("bad type for scalar"));
16347 constraint (x >= 64 / et.size, _("scalar index out of range"));
16348
16349 switch (et.size)
16350 {
16351 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16352 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16353 case 32: abcdebits = 0x00; break;
16354 default: ;
16355 }
16356
16357 abcdebits |= x << logsize;
16358 inst.instruction = 0xe100b10;
16359 do_vfp_cond_or_thumb ();
16360 inst.instruction |= LOW4 (dn) << 16;
16361 inst.instruction |= HI1 (dn) << 7;
16362 inst.instruction |= inst.operands[0].reg << 12;
16363 inst.instruction |= (abcdebits & 3) << 5;
16364 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16365 }
16366 break;
5f4273c7 16367
037e8744
JB
16368 case NS_RRD: /* case 7 (fmrrd). */
16369 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16370 _(BAD_FPU));
037e8744
JB
16371
16372 inst.instruction = 0xc500b10;
16373 do_vfp_cond_or_thumb ();
16374 inst.instruction |= inst.operands[0].reg << 12;
16375 inst.instruction |= inst.operands[1].reg << 16;
16376 inst.instruction |= LOW4 (inst.operands[2].reg);
16377 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16378 break;
5f4273c7 16379
037e8744
JB
16380 case NS_FF: /* case 8 (fcpys). */
16381 do_vfp_nsyn_opcode ("fcpys");
16382 break;
5f4273c7 16383
9db2f6b4 16384 case NS_HI:
037e8744
JB
16385 case NS_FI: /* case 10 (fconsts). */
16386 ldconst = "fconsts";
16387 encode_fconstd:
16388 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16389 {
16390 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16391 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16392
16393 /* ARMv8.2 fp16 vmov.f16 instruction. */
16394 if (rs == NS_HI)
16395 do_scalar_fp16_v82_encode ();
477330fc 16396 }
5287ad62 16397 else
477330fc 16398 first_error (_("immediate out of range"));
037e8744 16399 break;
5f4273c7 16400
9db2f6b4 16401 case NS_RH:
037e8744
JB
16402 case NS_RF: /* case 12 (fmrs). */
16403 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16404 /* ARMv8.2 fp16 vmov.f16 instruction. */
16405 if (rs == NS_RH)
16406 do_scalar_fp16_v82_encode ();
037e8744 16407 break;
5f4273c7 16408
9db2f6b4 16409 case NS_HR:
037e8744
JB
16410 case NS_FR: /* case 13 (fmsr). */
16411 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16412 /* ARMv8.2 fp16 vmov.f16 instruction. */
16413 if (rs == NS_HR)
16414 do_scalar_fp16_v82_encode ();
037e8744 16415 break;
5f4273c7 16416
037e8744
JB
16417 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16418 (one of which is a list), but we have parsed four. Do some fiddling to
16419 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16420 expect. */
16421 case NS_RRFF: /* case 14 (fmrrs). */
16422 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16423 _("VFP registers must be adjacent"));
037e8744
JB
16424 inst.operands[2].imm = 2;
16425 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16426 do_vfp_nsyn_opcode ("fmrrs");
16427 break;
5f4273c7 16428
037e8744
JB
16429 case NS_FFRR: /* case 15 (fmsrr). */
16430 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16431 _("VFP registers must be adjacent"));
037e8744
JB
16432 inst.operands[1] = inst.operands[2];
16433 inst.operands[2] = inst.operands[3];
16434 inst.operands[0].imm = 2;
16435 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16436 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16437 break;
5f4273c7 16438
4c261dff
NC
16439 case NS_NULL:
16440 /* neon_select_shape has determined that the instruction
16441 shape is wrong and has already set the error message. */
16442 break;
16443
5287ad62
JB
16444 default:
16445 abort ();
16446 }
16447}
16448
16449static void
16450do_neon_rshift_round_imm (void)
16451{
037e8744 16452 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16453 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16454 int imm = inst.operands[2].imm;
16455
16456 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16457 if (imm == 0)
16458 {
16459 inst.operands[2].present = 0;
16460 do_neon_mov ();
16461 return;
16462 }
16463
16464 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16465 _("immediate out of range for shift"));
037e8744 16466 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16467 et.size - imm);
5287ad62
JB
16468}
16469
9db2f6b4
RL
16470static void
16471do_neon_movhf (void)
16472{
16473 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16474 constraint (rs != NS_HH, _("invalid suffix"));
16475
16476 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16477 _(BAD_FPU));
16478
16479 do_vfp_sp_monadic ();
16480
16481 inst.is_neon = 1;
16482 inst.instruction |= 0xf0000000;
16483}
16484
5287ad62
JB
16485static void
16486do_neon_movl (void)
16487{
16488 struct neon_type_el et = neon_check_type (2, NS_QD,
16489 N_EQK | N_DBL, N_SU_32 | N_KEY);
16490 unsigned sizebits = et.size >> 3;
16491 inst.instruction |= sizebits << 19;
16492 neon_two_same (0, et.type == NT_unsigned, -1);
16493}
16494
16495static void
16496do_neon_trn (void)
16497{
037e8744 16498 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16499 struct neon_type_el et = neon_check_type (2, rs,
16500 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16501 NEON_ENCODE (INTEGER, inst);
037e8744 16502 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16503}
16504
16505static void
16506do_neon_zip_uzp (void)
16507{
037e8744 16508 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16509 struct neon_type_el et = neon_check_type (2, rs,
16510 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16511 if (rs == NS_DD && et.size == 32)
16512 {
16513 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16514 inst.instruction = N_MNEM_vtrn;
16515 do_neon_trn ();
16516 return;
16517 }
037e8744 16518 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16519}
16520
16521static void
16522do_neon_sat_abs_neg (void)
16523{
037e8744 16524 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16525 struct neon_type_el et = neon_check_type (2, rs,
16526 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16527 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16528}
16529
16530static void
16531do_neon_pair_long (void)
16532{
037e8744 16533 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16534 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16535 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16536 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16537 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16538}
16539
16540static void
16541do_neon_recip_est (void)
16542{
037e8744 16543 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16544 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16545 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16546 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16547 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16548}
16549
16550static void
16551do_neon_cls (void)
16552{
037e8744 16553 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16554 struct neon_type_el et = neon_check_type (2, rs,
16555 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16556 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16557}
16558
16559static void
16560do_neon_clz (void)
16561{
037e8744 16562 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16563 struct neon_type_el et = neon_check_type (2, rs,
16564 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16565 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16566}
16567
16568static void
16569do_neon_cnt (void)
16570{
037e8744 16571 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16572 struct neon_type_el et = neon_check_type (2, rs,
16573 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16574 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16575}
16576
16577static void
16578do_neon_swp (void)
16579{
037e8744
JB
16580 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16581 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16582}
16583
16584static void
16585do_neon_tbl_tbx (void)
16586{
16587 unsigned listlenbits;
dcbf9037 16588 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16589
5287ad62
JB
16590 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16591 {
dcbf9037 16592 first_error (_("bad list length for table lookup"));
5287ad62
JB
16593 return;
16594 }
5f4273c7 16595
5287ad62
JB
16596 listlenbits = inst.operands[1].imm - 1;
16597 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16598 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16599 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16600 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16601 inst.instruction |= LOW4 (inst.operands[2].reg);
16602 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16603 inst.instruction |= listlenbits << 8;
5f4273c7 16604
88714cb8 16605 neon_dp_fixup (&inst);
5287ad62
JB
16606}
16607
16608static void
16609do_neon_ldm_stm (void)
16610{
16611 /* P, U and L bits are part of bitmask. */
16612 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16613 unsigned offsetbits = inst.operands[1].imm * 2;
16614
037e8744
JB
16615 if (inst.operands[1].issingle)
16616 {
16617 do_vfp_nsyn_ldm_stm (is_dbmode);
16618 return;
16619 }
16620
5287ad62 16621 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16622 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16623
16624 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16625 _("register list must contain at least 1 and at most 16 "
16626 "registers"));
5287ad62
JB
16627
16628 inst.instruction |= inst.operands[0].reg << 16;
16629 inst.instruction |= inst.operands[0].writeback << 21;
16630 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16631 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16632
16633 inst.instruction |= offsetbits;
5f4273c7 16634
037e8744 16635 do_vfp_cond_or_thumb ();
5287ad62
JB
16636}
16637
16638static void
16639do_neon_ldr_str (void)
16640{
5287ad62 16641 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16642
6844b2c2
MGD
16643 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16644 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16645 if (!is_ldr
6844b2c2 16646 && inst.operands[1].reg == REG_PC
ba86b375 16647 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16648 {
94dcf8bf 16649 if (thumb_mode)
6844b2c2 16650 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16651 else if (warn_on_deprecated)
5c3696f8 16652 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16653 }
16654
037e8744
JB
16655 if (inst.operands[0].issingle)
16656 {
cd2f129f 16657 if (is_ldr)
477330fc 16658 do_vfp_nsyn_opcode ("flds");
cd2f129f 16659 else
477330fc 16660 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16661
16662 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16663 if (inst.vectype.el[0].size == 16)
16664 do_scalar_fp16_v82_encode ();
5287ad62
JB
16665 }
16666 else
5287ad62 16667 {
cd2f129f 16668 if (is_ldr)
477330fc 16669 do_vfp_nsyn_opcode ("fldd");
5287ad62 16670 else
477330fc 16671 do_vfp_nsyn_opcode ("fstd");
5287ad62 16672 }
5287ad62
JB
16673}
16674
16675/* "interleave" version also handles non-interleaving register VLD1/VST1
16676 instructions. */
16677
16678static void
16679do_neon_ld_st_interleave (void)
16680{
037e8744 16681 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16682 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16683 unsigned alignbits = 0;
16684 unsigned idx;
16685 /* The bits in this table go:
16686 0: register stride of one (0) or two (1)
16687 1,2: register list length, minus one (1, 2, 3, 4).
16688 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16689 We use -1 for invalid entries. */
16690 const int typetable[] =
16691 {
16692 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16693 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16694 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16695 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16696 };
16697 int typebits;
16698
dcbf9037
JB
16699 if (et.type == NT_invtype)
16700 return;
16701
5287ad62
JB
16702 if (inst.operands[1].immisalign)
16703 switch (inst.operands[1].imm >> 8)
16704 {
16705 case 64: alignbits = 1; break;
16706 case 128:
477330fc 16707 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16708 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16709 goto bad_alignment;
16710 alignbits = 2;
16711 break;
5287ad62 16712 case 256:
477330fc
RM
16713 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16714 goto bad_alignment;
16715 alignbits = 3;
16716 break;
5287ad62
JB
16717 default:
16718 bad_alignment:
477330fc
RM
16719 first_error (_("bad alignment"));
16720 return;
5287ad62
JB
16721 }
16722
16723 inst.instruction |= alignbits << 4;
16724 inst.instruction |= neon_logbits (et.size) << 6;
16725
16726 /* Bits [4:6] of the immediate in a list specifier encode register stride
16727 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16728 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16729 up the right value for "type" in a table based on this value and the given
16730 list style, then stick it back. */
16731 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16732 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16733
16734 typebits = typetable[idx];
5f4273c7 16735
5287ad62 16736 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16737 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16738 _("bad element type for instruction"));
5287ad62
JB
16739
16740 inst.instruction &= ~0xf00;
16741 inst.instruction |= typebits << 8;
16742}
16743
16744/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16745 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16746 otherwise. The variable arguments are a list of pairs of legal (size, align)
16747 values, terminated with -1. */
16748
16749static int
aa8a0863 16750neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16751{
16752 va_list ap;
16753 int result = FAIL, thissize, thisalign;
5f4273c7 16754
5287ad62
JB
16755 if (!inst.operands[1].immisalign)
16756 {
aa8a0863 16757 *do_alignment = 0;
5287ad62
JB
16758 return SUCCESS;
16759 }
5f4273c7 16760
aa8a0863 16761 va_start (ap, do_alignment);
5287ad62
JB
16762
16763 do
16764 {
16765 thissize = va_arg (ap, int);
16766 if (thissize == -1)
477330fc 16767 break;
5287ad62
JB
16768 thisalign = va_arg (ap, int);
16769
16770 if (size == thissize && align == thisalign)
477330fc 16771 result = SUCCESS;
5287ad62
JB
16772 }
16773 while (result != SUCCESS);
16774
16775 va_end (ap);
16776
16777 if (result == SUCCESS)
aa8a0863 16778 *do_alignment = 1;
5287ad62 16779 else
dcbf9037 16780 first_error (_("unsupported alignment for instruction"));
5f4273c7 16781
5287ad62
JB
16782 return result;
16783}
16784
16785static void
16786do_neon_ld_st_lane (void)
16787{
037e8744 16788 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16789 int align_good, do_alignment = 0;
5287ad62
JB
16790 int logsize = neon_logbits (et.size);
16791 int align = inst.operands[1].imm >> 8;
16792 int n = (inst.instruction >> 8) & 3;
16793 int max_el = 64 / et.size;
5f4273c7 16794
dcbf9037
JB
16795 if (et.type == NT_invtype)
16796 return;
5f4273c7 16797
5287ad62 16798 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16799 _("bad list length"));
5287ad62 16800 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16801 _("scalar index out of range"));
5287ad62 16802 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16803 && et.size == 8,
16804 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16805
5287ad62
JB
16806 switch (n)
16807 {
16808 case 0: /* VLD1 / VST1. */
aa8a0863 16809 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16810 32, 32, -1);
5287ad62 16811 if (align_good == FAIL)
477330fc 16812 return;
aa8a0863 16813 if (do_alignment)
477330fc
RM
16814 {
16815 unsigned alignbits = 0;
16816 switch (et.size)
16817 {
16818 case 16: alignbits = 0x1; break;
16819 case 32: alignbits = 0x3; break;
16820 default: ;
16821 }
16822 inst.instruction |= alignbits << 4;
16823 }
5287ad62
JB
16824 break;
16825
16826 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16827 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16828 16, 32, 32, 64, -1);
5287ad62 16829 if (align_good == FAIL)
477330fc 16830 return;
aa8a0863 16831 if (do_alignment)
477330fc 16832 inst.instruction |= 1 << 4;
5287ad62
JB
16833 break;
16834
16835 case 2: /* VLD3 / VST3. */
16836 constraint (inst.operands[1].immisalign,
477330fc 16837 _("can't use alignment with this instruction"));
5287ad62
JB
16838 break;
16839
16840 case 3: /* VLD4 / VST4. */
aa8a0863 16841 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16842 16, 64, 32, 64, 32, 128, -1);
5287ad62 16843 if (align_good == FAIL)
477330fc 16844 return;
aa8a0863 16845 if (do_alignment)
477330fc
RM
16846 {
16847 unsigned alignbits = 0;
16848 switch (et.size)
16849 {
16850 case 8: alignbits = 0x1; break;
16851 case 16: alignbits = 0x1; break;
16852 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16853 default: ;
16854 }
16855 inst.instruction |= alignbits << 4;
16856 }
5287ad62
JB
16857 break;
16858
16859 default: ;
16860 }
16861
16862 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16863 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16864 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16865
5287ad62
JB
16866 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16867 inst.instruction |= logsize << 10;
16868}
16869
16870/* Encode single n-element structure to all lanes VLD<n> instructions. */
16871
16872static void
16873do_neon_ld_dup (void)
16874{
037e8744 16875 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16876 int align_good, do_alignment = 0;
5287ad62 16877
dcbf9037
JB
16878 if (et.type == NT_invtype)
16879 return;
16880
5287ad62
JB
16881 switch ((inst.instruction >> 8) & 3)
16882 {
16883 case 0: /* VLD1. */
9c2799c2 16884 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16885 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16886 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16887 if (align_good == FAIL)
477330fc 16888 return;
5287ad62 16889 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16890 {
16891 case 1: break;
16892 case 2: inst.instruction |= 1 << 5; break;
16893 default: first_error (_("bad list length")); return;
16894 }
5287ad62
JB
16895 inst.instruction |= neon_logbits (et.size) << 6;
16896 break;
16897
16898 case 1: /* VLD2. */
16899 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16900 &do_alignment, 8, 16, 16, 32, 32, 64,
16901 -1);
5287ad62 16902 if (align_good == FAIL)
477330fc 16903 return;
5287ad62 16904 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16905 _("bad list length"));
5287ad62 16906 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16907 inst.instruction |= 1 << 5;
5287ad62
JB
16908 inst.instruction |= neon_logbits (et.size) << 6;
16909 break;
16910
16911 case 2: /* VLD3. */
16912 constraint (inst.operands[1].immisalign,
477330fc 16913 _("can't use alignment with this instruction"));
5287ad62 16914 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16915 _("bad list length"));
5287ad62 16916 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16917 inst.instruction |= 1 << 5;
5287ad62
JB
16918 inst.instruction |= neon_logbits (et.size) << 6;
16919 break;
16920
16921 case 3: /* VLD4. */
16922 {
477330fc 16923 int align = inst.operands[1].imm >> 8;
aa8a0863 16924 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
16925 16, 64, 32, 64, 32, 128, -1);
16926 if (align_good == FAIL)
16927 return;
16928 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16929 _("bad list length"));
16930 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16931 inst.instruction |= 1 << 5;
16932 if (et.size == 32 && align == 128)
16933 inst.instruction |= 0x3 << 6;
16934 else
16935 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16936 }
16937 break;
16938
16939 default: ;
16940 }
16941
aa8a0863 16942 inst.instruction |= do_alignment << 4;
5287ad62
JB
16943}
16944
16945/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16946 apart from bits [11:4]. */
16947
16948static void
16949do_neon_ldx_stx (void)
16950{
b1a769ed
DG
16951 if (inst.operands[1].isreg)
16952 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16953
5287ad62
JB
16954 switch (NEON_LANE (inst.operands[0].imm))
16955 {
16956 case NEON_INTERLEAVE_LANES:
88714cb8 16957 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16958 do_neon_ld_st_interleave ();
16959 break;
5f4273c7 16960
5287ad62 16961 case NEON_ALL_LANES:
88714cb8 16962 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16963 if (inst.instruction == N_INV)
16964 {
16965 first_error ("only loads support such operands");
16966 break;
16967 }
5287ad62
JB
16968 do_neon_ld_dup ();
16969 break;
5f4273c7 16970
5287ad62 16971 default:
88714cb8 16972 NEON_ENCODE (LANE, inst);
5287ad62
JB
16973 do_neon_ld_st_lane ();
16974 }
16975
16976 /* L bit comes from bit mask. */
16977 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16978 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16979 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16980
5287ad62
JB
16981 if (inst.operands[1].postind)
16982 {
16983 int postreg = inst.operands[1].imm & 0xf;
16984 constraint (!inst.operands[1].immisreg,
477330fc 16985 _("post-index must be a register"));
5287ad62 16986 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16987 _("bad register for post-index"));
5287ad62
JB
16988 inst.instruction |= postreg;
16989 }
4f2374c7 16990 else
5287ad62 16991 {
4f2374c7
WN
16992 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16993 constraint (inst.reloc.exp.X_op != O_constant
16994 || inst.reloc.exp.X_add_number != 0,
16995 BAD_ADDR_MODE);
16996
16997 if (inst.operands[1].writeback)
16998 {
16999 inst.instruction |= 0xd;
17000 }
17001 else
17002 inst.instruction |= 0xf;
5287ad62 17003 }
5f4273c7 17004
5287ad62
JB
17005 if (thumb_mode)
17006 inst.instruction |= 0xf9000000;
17007 else
17008 inst.instruction |= 0xf4000000;
17009}
33399f07
MGD
17010
17011/* FP v8. */
17012static void
17013do_vfp_nsyn_fpv8 (enum neon_shape rs)
17014{
a715796b
TG
17015 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17016 D register operands. */
17017 if (neon_shape_class[rs] == SC_DOUBLE)
17018 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17019 _(BAD_FPU));
17020
33399f07
MGD
17021 NEON_ENCODE (FPV8, inst);
17022
9db2f6b4
RL
17023 if (rs == NS_FFF || rs == NS_HHH)
17024 {
17025 do_vfp_sp_dyadic ();
17026
17027 /* ARMv8.2 fp16 instruction. */
17028 if (rs == NS_HHH)
17029 do_scalar_fp16_v82_encode ();
17030 }
33399f07
MGD
17031 else
17032 do_vfp_dp_rd_rn_rm ();
17033
17034 if (rs == NS_DDD)
17035 inst.instruction |= 0x100;
17036
17037 inst.instruction |= 0xf0000000;
17038}
17039
17040static void
17041do_vsel (void)
17042{
17043 set_it_insn_type (OUTSIDE_IT_INSN);
17044
17045 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17046 first_error (_("invalid instruction shape"));
17047}
17048
73924fbc
MGD
17049static void
17050do_vmaxnm (void)
17051{
17052 set_it_insn_type (OUTSIDE_IT_INSN);
17053
17054 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17055 return;
17056
17057 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17058 return;
17059
cc933301 17060 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17061}
17062
30bdf752
MGD
17063static void
17064do_vrint_1 (enum neon_cvt_mode mode)
17065{
9db2f6b4 17066 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17067 struct neon_type_el et;
17068
17069 if (rs == NS_NULL)
17070 return;
17071
a715796b
TG
17072 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17073 D register operands. */
17074 if (neon_shape_class[rs] == SC_DOUBLE)
17075 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17076 _(BAD_FPU));
17077
9db2f6b4
RL
17078 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17079 | N_VFP);
30bdf752
MGD
17080 if (et.type != NT_invtype)
17081 {
17082 /* VFP encodings. */
17083 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17084 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17085 set_it_insn_type (OUTSIDE_IT_INSN);
17086
17087 NEON_ENCODE (FPV8, inst);
9db2f6b4 17088 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17089 do_vfp_sp_monadic ();
17090 else
17091 do_vfp_dp_rd_rm ();
17092
17093 switch (mode)
17094 {
17095 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17096 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17097 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17098 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17099 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17100 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17101 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17102 default: abort ();
17103 }
17104
17105 inst.instruction |= (rs == NS_DD) << 8;
17106 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17107
17108 /* ARMv8.2 fp16 vrint instruction. */
17109 if (rs == NS_HH)
17110 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17111 }
17112 else
17113 {
17114 /* Neon encodings (or something broken...). */
17115 inst.error = NULL;
cc933301 17116 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17117
17118 if (et.type == NT_invtype)
17119 return;
17120
17121 set_it_insn_type (OUTSIDE_IT_INSN);
17122 NEON_ENCODE (FLOAT, inst);
17123
17124 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17125 return;
17126
17127 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17128 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17129 inst.instruction |= LOW4 (inst.operands[1].reg);
17130 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17131 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17132 /* Mask off the original size bits and reencode them. */
17133 inst.instruction = ((inst.instruction & 0xfff3ffff)
17134 | neon_logbits (et.size) << 18);
17135
30bdf752
MGD
17136 switch (mode)
17137 {
17138 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17139 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17140 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17141 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17142 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17143 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17144 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17145 default: abort ();
17146 }
17147
17148 if (thumb_mode)
17149 inst.instruction |= 0xfc000000;
17150 else
17151 inst.instruction |= 0xf0000000;
17152 }
17153}
17154
17155static void
17156do_vrintx (void)
17157{
17158 do_vrint_1 (neon_cvt_mode_x);
17159}
17160
17161static void
17162do_vrintz (void)
17163{
17164 do_vrint_1 (neon_cvt_mode_z);
17165}
17166
17167static void
17168do_vrintr (void)
17169{
17170 do_vrint_1 (neon_cvt_mode_r);
17171}
17172
17173static void
17174do_vrinta (void)
17175{
17176 do_vrint_1 (neon_cvt_mode_a);
17177}
17178
17179static void
17180do_vrintn (void)
17181{
17182 do_vrint_1 (neon_cvt_mode_n);
17183}
17184
17185static void
17186do_vrintp (void)
17187{
17188 do_vrint_1 (neon_cvt_mode_p);
17189}
17190
17191static void
17192do_vrintm (void)
17193{
17194 do_vrint_1 (neon_cvt_mode_m);
17195}
17196
91ff7894
MGD
17197/* Crypto v1 instructions. */
17198static void
17199do_crypto_2op_1 (unsigned elttype, int op)
17200{
17201 set_it_insn_type (OUTSIDE_IT_INSN);
17202
17203 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17204 == NT_invtype)
17205 return;
17206
17207 inst.error = NULL;
17208
17209 NEON_ENCODE (INTEGER, inst);
17210 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17211 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17212 inst.instruction |= LOW4 (inst.operands[1].reg);
17213 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17214 if (op != -1)
17215 inst.instruction |= op << 6;
17216
17217 if (thumb_mode)
17218 inst.instruction |= 0xfc000000;
17219 else
17220 inst.instruction |= 0xf0000000;
17221}
17222
48adcd8e
MGD
17223static void
17224do_crypto_3op_1 (int u, int op)
17225{
17226 set_it_insn_type (OUTSIDE_IT_INSN);
17227
17228 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17229 N_32 | N_UNT | N_KEY).type == NT_invtype)
17230 return;
17231
17232 inst.error = NULL;
17233
17234 NEON_ENCODE (INTEGER, inst);
17235 neon_three_same (1, u, 8 << op);
17236}
17237
91ff7894
MGD
17238static void
17239do_aese (void)
17240{
17241 do_crypto_2op_1 (N_8, 0);
17242}
17243
17244static void
17245do_aesd (void)
17246{
17247 do_crypto_2op_1 (N_8, 1);
17248}
17249
17250static void
17251do_aesmc (void)
17252{
17253 do_crypto_2op_1 (N_8, 2);
17254}
17255
17256static void
17257do_aesimc (void)
17258{
17259 do_crypto_2op_1 (N_8, 3);
17260}
17261
48adcd8e
MGD
17262static void
17263do_sha1c (void)
17264{
17265 do_crypto_3op_1 (0, 0);
17266}
17267
17268static void
17269do_sha1p (void)
17270{
17271 do_crypto_3op_1 (0, 1);
17272}
17273
17274static void
17275do_sha1m (void)
17276{
17277 do_crypto_3op_1 (0, 2);
17278}
17279
17280static void
17281do_sha1su0 (void)
17282{
17283 do_crypto_3op_1 (0, 3);
17284}
91ff7894 17285
48adcd8e
MGD
17286static void
17287do_sha256h (void)
17288{
17289 do_crypto_3op_1 (1, 0);
17290}
17291
17292static void
17293do_sha256h2 (void)
17294{
17295 do_crypto_3op_1 (1, 1);
17296}
17297
17298static void
17299do_sha256su1 (void)
17300{
17301 do_crypto_3op_1 (1, 2);
17302}
3c9017d2
MGD
17303
17304static void
17305do_sha1h (void)
17306{
17307 do_crypto_2op_1 (N_32, -1);
17308}
17309
17310static void
17311do_sha1su1 (void)
17312{
17313 do_crypto_2op_1 (N_32, 0);
17314}
17315
17316static void
17317do_sha256su0 (void)
17318{
17319 do_crypto_2op_1 (N_32, 1);
17320}
dd5181d5
KT
17321
17322static void
17323do_crc32_1 (unsigned int poly, unsigned int sz)
17324{
17325 unsigned int Rd = inst.operands[0].reg;
17326 unsigned int Rn = inst.operands[1].reg;
17327 unsigned int Rm = inst.operands[2].reg;
17328
17329 set_it_insn_type (OUTSIDE_IT_INSN);
17330 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17331 inst.instruction |= LOW4 (Rn) << 16;
17332 inst.instruction |= LOW4 (Rm);
17333 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17334 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17335
17336 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17337 as_warn (UNPRED_REG ("r15"));
17338 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17339 as_warn (UNPRED_REG ("r13"));
17340}
17341
17342static void
17343do_crc32b (void)
17344{
17345 do_crc32_1 (0, 0);
17346}
17347
17348static void
17349do_crc32h (void)
17350{
17351 do_crc32_1 (0, 1);
17352}
17353
17354static void
17355do_crc32w (void)
17356{
17357 do_crc32_1 (0, 2);
17358}
17359
17360static void
17361do_crc32cb (void)
17362{
17363 do_crc32_1 (1, 0);
17364}
17365
17366static void
17367do_crc32ch (void)
17368{
17369 do_crc32_1 (1, 1);
17370}
17371
17372static void
17373do_crc32cw (void)
17374{
17375 do_crc32_1 (1, 2);
17376}
17377
5287ad62
JB
17378\f
17379/* Overall per-instruction processing. */
17380
17381/* We need to be able to fix up arbitrary expressions in some statements.
17382 This is so that we can handle symbols that are an arbitrary distance from
17383 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17384 which returns part of an address in a form which will be valid for
17385 a data instruction. We do this by pushing the expression into a symbol
17386 in the expr_section, and creating a fix for that. */
17387
17388static void
17389fix_new_arm (fragS * frag,
17390 int where,
17391 short int size,
17392 expressionS * exp,
17393 int pc_rel,
17394 int reloc)
17395{
17396 fixS * new_fix;
17397
17398 switch (exp->X_op)
17399 {
17400 case O_constant:
6e7ce2cd
PB
17401 if (pc_rel)
17402 {
17403 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17404 refer to in the object file. Unfortunately for us, gas's
17405 generic expression parsing will already have folded out
17406 any use of .set foo/.type foo %function that may have
17407 been used to set type information of the target location,
17408 that's being specified symbolically. We have to presume
17409 the user knows what they are doing. */
6e7ce2cd
PB
17410 char name[16 + 8];
17411 symbolS *symbol;
17412
17413 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17414
17415 symbol = symbol_find_or_make (name);
17416 S_SET_SEGMENT (symbol, absolute_section);
17417 symbol_set_frag (symbol, &zero_address_frag);
17418 S_SET_VALUE (symbol, exp->X_add_number);
17419 exp->X_op = O_symbol;
17420 exp->X_add_symbol = symbol;
17421 exp->X_add_number = 0;
17422 }
17423 /* FALLTHROUGH */
5287ad62
JB
17424 case O_symbol:
17425 case O_add:
17426 case O_subtract:
21d799b5 17427 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17428 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17429 break;
17430
17431 default:
21d799b5 17432 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17433 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17434 break;
17435 }
17436
17437 /* Mark whether the fix is to a THUMB instruction, or an ARM
17438 instruction. */
17439 new_fix->tc_fix_data = thumb_mode;
17440}
17441
17442/* Create a frg for an instruction requiring relaxation. */
17443static void
17444output_relax_insn (void)
17445{
17446 char * to;
17447 symbolS *sym;
0110f2b8
PB
17448 int offset;
17449
6e1cb1a6
PB
17450 /* The size of the instruction is unknown, so tie the debug info to the
17451 start of the instruction. */
17452 dwarf2_emit_insn (0);
6e1cb1a6 17453
0110f2b8
PB
17454 switch (inst.reloc.exp.X_op)
17455 {
17456 case O_symbol:
17457 sym = inst.reloc.exp.X_add_symbol;
17458 offset = inst.reloc.exp.X_add_number;
17459 break;
17460 case O_constant:
17461 sym = NULL;
17462 offset = inst.reloc.exp.X_add_number;
17463 break;
17464 default:
17465 sym = make_expr_symbol (&inst.reloc.exp);
17466 offset = 0;
17467 break;
17468 }
17469 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17470 inst.relax, sym, offset, NULL/*offset, opcode*/);
17471 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17472}
17473
17474/* Write a 32-bit thumb instruction to buf. */
17475static void
17476put_thumb32_insn (char * buf, unsigned long insn)
17477{
17478 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17479 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17480}
17481
b99bd4ef 17482static void
c19d1205 17483output_inst (const char * str)
b99bd4ef 17484{
c19d1205 17485 char * to = NULL;
b99bd4ef 17486
c19d1205 17487 if (inst.error)
b99bd4ef 17488 {
c19d1205 17489 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17490 return;
17491 }
5f4273c7
NC
17492 if (inst.relax)
17493 {
17494 output_relax_insn ();
0110f2b8 17495 return;
5f4273c7 17496 }
c19d1205
ZW
17497 if (inst.size == 0)
17498 return;
b99bd4ef 17499
c19d1205 17500 to = frag_more (inst.size);
8dc2430f
NC
17501 /* PR 9814: Record the thumb mode into the current frag so that we know
17502 what type of NOP padding to use, if necessary. We override any previous
17503 setting so that if the mode has changed then the NOPS that we use will
17504 match the encoding of the last instruction in the frag. */
cd000bff 17505 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17506
17507 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17508 {
9c2799c2 17509 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17510 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17511 }
c19d1205 17512 else if (inst.size > INSN_SIZE)
b99bd4ef 17513 {
9c2799c2 17514 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17515 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17516 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17517 }
c19d1205
ZW
17518 else
17519 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17520
c19d1205
ZW
17521 if (inst.reloc.type != BFD_RELOC_UNUSED)
17522 fix_new_arm (frag_now, to - frag_now->fr_literal,
17523 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17524 inst.reloc.type);
b99bd4ef 17525
c19d1205 17526 dwarf2_emit_insn (inst.size);
c19d1205 17527}
b99bd4ef 17528
e07e6e58
NC
17529static char *
17530output_it_inst (int cond, int mask, char * to)
17531{
17532 unsigned long instruction = 0xbf00;
17533
17534 mask &= 0xf;
17535 instruction |= mask;
17536 instruction |= cond << 4;
17537
17538 if (to == NULL)
17539 {
17540 to = frag_more (2);
17541#ifdef OBJ_ELF
17542 dwarf2_emit_insn (2);
17543#endif
17544 }
17545
17546 md_number_to_chars (to, instruction, 2);
17547
17548 return to;
17549}
17550
c19d1205
ZW
17551/* Tag values used in struct asm_opcode's tag field. */
17552enum opcode_tag
17553{
17554 OT_unconditional, /* Instruction cannot be conditionalized.
17555 The ARM condition field is still 0xE. */
17556 OT_unconditionalF, /* Instruction cannot be conditionalized
17557 and carries 0xF in its ARM condition field. */
17558 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17559 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17560 suffix, others place 0xF where the condition field
17561 would be. */
c19d1205
ZW
17562 OT_cinfix3, /* Instruction takes a conditional infix,
17563 beginning at character index 3. (In
17564 unified mode, it becomes a suffix.) */
088fa78e
KH
17565 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17566 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17567 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17568 character index 3, even in unified mode. Used for
17569 legacy instructions where suffix and infix forms
17570 may be ambiguous. */
c19d1205 17571 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17572 suffix or an infix at character index 3. */
c19d1205
ZW
17573 OT_odd_infix_unc, /* This is the unconditional variant of an
17574 instruction that takes a conditional infix
17575 at an unusual position. In unified mode,
17576 this variant will accept a suffix. */
17577 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17578 are the conditional variants of instructions that
17579 take conditional infixes in unusual positions.
17580 The infix appears at character index
17581 (tag - OT_odd_infix_0). These are not accepted
17582 in unified mode. */
17583};
b99bd4ef 17584
c19d1205
ZW
17585/* Subroutine of md_assemble, responsible for looking up the primary
17586 opcode from the mnemonic the user wrote. STR points to the
17587 beginning of the mnemonic.
17588
17589 This is not simply a hash table lookup, because of conditional
17590 variants. Most instructions have conditional variants, which are
17591 expressed with a _conditional affix_ to the mnemonic. If we were
17592 to encode each conditional variant as a literal string in the opcode
17593 table, it would have approximately 20,000 entries.
17594
17595 Most mnemonics take this affix as a suffix, and in unified syntax,
17596 'most' is upgraded to 'all'. However, in the divided syntax, some
17597 instructions take the affix as an infix, notably the s-variants of
17598 the arithmetic instructions. Of those instructions, all but six
17599 have the infix appear after the third character of the mnemonic.
17600
17601 Accordingly, the algorithm for looking up primary opcodes given
17602 an identifier is:
17603
17604 1. Look up the identifier in the opcode table.
17605 If we find a match, go to step U.
17606
17607 2. Look up the last two characters of the identifier in the
17608 conditions table. If we find a match, look up the first N-2
17609 characters of the identifier in the opcode table. If we
17610 find a match, go to step CE.
17611
17612 3. Look up the fourth and fifth characters of the identifier in
17613 the conditions table. If we find a match, extract those
17614 characters from the identifier, and look up the remaining
17615 characters in the opcode table. If we find a match, go
17616 to step CM.
17617
17618 4. Fail.
17619
17620 U. Examine the tag field of the opcode structure, in case this is
17621 one of the six instructions with its conditional infix in an
17622 unusual place. If it is, the tag tells us where to find the
17623 infix; look it up in the conditions table and set inst.cond
17624 accordingly. Otherwise, this is an unconditional instruction.
17625 Again set inst.cond accordingly. Return the opcode structure.
17626
17627 CE. Examine the tag field to make sure this is an instruction that
17628 should receive a conditional suffix. If it is not, fail.
17629 Otherwise, set inst.cond from the suffix we already looked up,
17630 and return the opcode structure.
17631
17632 CM. Examine the tag field to make sure this is an instruction that
17633 should receive a conditional infix after the third character.
17634 If it is not, fail. Otherwise, undo the edits to the current
17635 line of input and proceed as for case CE. */
17636
17637static const struct asm_opcode *
17638opcode_lookup (char **str)
17639{
17640 char *end, *base;
17641 char *affix;
17642 const struct asm_opcode *opcode;
17643 const struct asm_cond *cond;
e3cb604e 17644 char save[2];
c19d1205
ZW
17645
17646 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17647 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17648 for (base = end = *str; *end != '\0'; end++)
721a8186 17649 if (*end == ' ' || *end == '.')
c19d1205 17650 break;
b99bd4ef 17651
c19d1205 17652 if (end == base)
c921be7d 17653 return NULL;
b99bd4ef 17654
5287ad62 17655 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17656 if (end[0] == '.')
b99bd4ef 17657 {
5287ad62 17658 int offset = 2;
5f4273c7 17659
267d2029 17660 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17661 use. */
267d2029 17662 if (unified_syntax && end[1] == 'w')
c19d1205 17663 inst.size_req = 4;
267d2029 17664 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17665 inst.size_req = 2;
17666 else
477330fc 17667 offset = 0;
5287ad62
JB
17668
17669 inst.vectype.elems = 0;
17670
17671 *str = end + offset;
b99bd4ef 17672
5f4273c7 17673 if (end[offset] == '.')
5287ad62 17674 {
267d2029 17675 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17676 non-unified ARM syntax mode). */
17677 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17678 return NULL;
477330fc 17679 }
5287ad62 17680 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17681 return NULL;
b99bd4ef 17682 }
c19d1205
ZW
17683 else
17684 *str = end;
b99bd4ef 17685
c19d1205 17686 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17687 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17688 end - base);
c19d1205 17689 if (opcode)
b99bd4ef 17690 {
c19d1205
ZW
17691 /* step U */
17692 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17693 {
c19d1205
ZW
17694 inst.cond = COND_ALWAYS;
17695 return opcode;
b99bd4ef 17696 }
b99bd4ef 17697
278df34e 17698 if (warn_on_deprecated && unified_syntax)
5c3696f8 17699 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17700 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17701 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17702 gas_assert (cond);
b99bd4ef 17703
c19d1205
ZW
17704 inst.cond = cond->value;
17705 return opcode;
17706 }
b99bd4ef 17707
c19d1205
ZW
17708 /* Cannot have a conditional suffix on a mnemonic of less than two
17709 characters. */
17710 if (end - base < 3)
c921be7d 17711 return NULL;
b99bd4ef 17712
c19d1205
ZW
17713 /* Look for suffixed mnemonic. */
17714 affix = end - 2;
21d799b5
NC
17715 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17716 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17717 affix - base);
c19d1205
ZW
17718 if (opcode && cond)
17719 {
17720 /* step CE */
17721 switch (opcode->tag)
17722 {
e3cb604e
PB
17723 case OT_cinfix3_legacy:
17724 /* Ignore conditional suffixes matched on infix only mnemonics. */
17725 break;
17726
c19d1205 17727 case OT_cinfix3:
088fa78e 17728 case OT_cinfix3_deprecated:
c19d1205
ZW
17729 case OT_odd_infix_unc:
17730 if (!unified_syntax)
e3cb604e 17731 return 0;
c19d1205
ZW
17732 /* else fall through */
17733
17734 case OT_csuffix:
477330fc 17735 case OT_csuffixF:
c19d1205
ZW
17736 case OT_csuf_or_in3:
17737 inst.cond = cond->value;
17738 return opcode;
17739
17740 case OT_unconditional:
17741 case OT_unconditionalF:
dfa9f0d5 17742 if (thumb_mode)
c921be7d 17743 inst.cond = cond->value;
dfa9f0d5
PB
17744 else
17745 {
c921be7d 17746 /* Delayed diagnostic. */
dfa9f0d5
PB
17747 inst.error = BAD_COND;
17748 inst.cond = COND_ALWAYS;
17749 }
c19d1205 17750 return opcode;
b99bd4ef 17751
c19d1205 17752 default:
c921be7d 17753 return NULL;
c19d1205
ZW
17754 }
17755 }
b99bd4ef 17756
c19d1205
ZW
17757 /* Cannot have a usual-position infix on a mnemonic of less than
17758 six characters (five would be a suffix). */
17759 if (end - base < 6)
c921be7d 17760 return NULL;
b99bd4ef 17761
c19d1205
ZW
17762 /* Look for infixed mnemonic in the usual position. */
17763 affix = base + 3;
21d799b5 17764 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17765 if (!cond)
c921be7d 17766 return NULL;
e3cb604e
PB
17767
17768 memcpy (save, affix, 2);
17769 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17770 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17771 (end - base) - 2);
e3cb604e
PB
17772 memmove (affix + 2, affix, (end - affix) - 2);
17773 memcpy (affix, save, 2);
17774
088fa78e
KH
17775 if (opcode
17776 && (opcode->tag == OT_cinfix3
17777 || opcode->tag == OT_cinfix3_deprecated
17778 || opcode->tag == OT_csuf_or_in3
17779 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17780 {
c921be7d 17781 /* Step CM. */
278df34e 17782 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17783 && (opcode->tag == OT_cinfix3
17784 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17785 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17786
17787 inst.cond = cond->value;
17788 return opcode;
b99bd4ef
NC
17789 }
17790
c921be7d 17791 return NULL;
b99bd4ef
NC
17792}
17793
e07e6e58
NC
17794/* This function generates an initial IT instruction, leaving its block
17795 virtually open for the new instructions. Eventually,
17796 the mask will be updated by now_it_add_mask () each time
17797 a new instruction needs to be included in the IT block.
17798 Finally, the block is closed with close_automatic_it_block ().
17799 The block closure can be requested either from md_assemble (),
17800 a tencode (), or due to a label hook. */
17801
17802static void
17803new_automatic_it_block (int cond)
17804{
17805 now_it.state = AUTOMATIC_IT_BLOCK;
17806 now_it.mask = 0x18;
17807 now_it.cc = cond;
17808 now_it.block_length = 1;
cd000bff 17809 mapping_state (MAP_THUMB);
e07e6e58 17810 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17811 now_it.warn_deprecated = FALSE;
17812 now_it.insn_cond = TRUE;
e07e6e58
NC
17813}
17814
17815/* Close an automatic IT block.
17816 See comments in new_automatic_it_block (). */
17817
17818static void
17819close_automatic_it_block (void)
17820{
17821 now_it.mask = 0x10;
17822 now_it.block_length = 0;
17823}
17824
17825/* Update the mask of the current automatically-generated IT
17826 instruction. See comments in new_automatic_it_block (). */
17827
17828static void
17829now_it_add_mask (int cond)
17830{
17831#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17832#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17833 | ((bitvalue) << (nbit)))
e07e6e58 17834 const int resulting_bit = (cond & 1);
c921be7d 17835
e07e6e58
NC
17836 now_it.mask &= 0xf;
17837 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17838 resulting_bit,
17839 (5 - now_it.block_length));
e07e6e58 17840 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17841 1,
17842 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17843 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17844
17845#undef CLEAR_BIT
17846#undef SET_BIT_VALUE
e07e6e58
NC
17847}
17848
17849/* The IT blocks handling machinery is accessed through the these functions:
17850 it_fsm_pre_encode () from md_assemble ()
17851 set_it_insn_type () optional, from the tencode functions
17852 set_it_insn_type_last () ditto
17853 in_it_block () ditto
17854 it_fsm_post_encode () from md_assemble ()
17855 force_automatic_it_block_close () from label habdling functions
17856
17857 Rationale:
17858 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17859 initializing the IT insn type with a generic initial value depending
17860 on the inst.condition.
e07e6e58 17861 2) During the tencode function, two things may happen:
477330fc
RM
17862 a) The tencode function overrides the IT insn type by
17863 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17864 b) The tencode function queries the IT block state by
17865 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17866
17867 Both set_it_insn_type and in_it_block run the internal FSM state
17868 handling function (handle_it_state), because: a) setting the IT insn
17869 type may incur in an invalid state (exiting the function),
17870 and b) querying the state requires the FSM to be updated.
17871 Specifically we want to avoid creating an IT block for conditional
17872 branches, so it_fsm_pre_encode is actually a guess and we can't
17873 determine whether an IT block is required until the tencode () routine
17874 has decided what type of instruction this actually it.
17875 Because of this, if set_it_insn_type and in_it_block have to be used,
17876 set_it_insn_type has to be called first.
17877
17878 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17879 determines the insn IT type depending on the inst.cond code.
17880 When a tencode () routine encodes an instruction that can be
17881 either outside an IT block, or, in the case of being inside, has to be
17882 the last one, set_it_insn_type_last () will determine the proper
17883 IT instruction type based on the inst.cond code. Otherwise,
17884 set_it_insn_type can be called for overriding that logic or
17885 for covering other cases.
17886
17887 Calling handle_it_state () may not transition the IT block state to
17888 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17889 still queried. Instead, if the FSM determines that the state should
17890 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17891 after the tencode () function: that's what it_fsm_post_encode () does.
17892
17893 Since in_it_block () calls the state handling function to get an
17894 updated state, an error may occur (due to invalid insns combination).
17895 In that case, inst.error is set.
17896 Therefore, inst.error has to be checked after the execution of
17897 the tencode () routine.
e07e6e58
NC
17898
17899 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17900 any pending state change (if any) that didn't take place in
17901 handle_it_state () as explained above. */
e07e6e58
NC
17902
17903static void
17904it_fsm_pre_encode (void)
17905{
17906 if (inst.cond != COND_ALWAYS)
17907 inst.it_insn_type = INSIDE_IT_INSN;
17908 else
17909 inst.it_insn_type = OUTSIDE_IT_INSN;
17910
17911 now_it.state_handled = 0;
17912}
17913
17914/* IT state FSM handling function. */
17915
17916static int
17917handle_it_state (void)
17918{
17919 now_it.state_handled = 1;
5a01bb1d 17920 now_it.insn_cond = FALSE;
e07e6e58
NC
17921
17922 switch (now_it.state)
17923 {
17924 case OUTSIDE_IT_BLOCK:
17925 switch (inst.it_insn_type)
17926 {
17927 case OUTSIDE_IT_INSN:
17928 break;
17929
17930 case INSIDE_IT_INSN:
17931 case INSIDE_IT_LAST_INSN:
17932 if (thumb_mode == 0)
17933 {
c921be7d 17934 if (unified_syntax
e07e6e58
NC
17935 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17936 as_tsktsk (_("Warning: conditional outside an IT block"\
17937 " for Thumb."));
17938 }
17939 else
17940 {
17941 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 17942 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
17943 {
17944 /* Automatically generate the IT instruction. */
17945 new_automatic_it_block (inst.cond);
17946 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17947 close_automatic_it_block ();
17948 }
17949 else
17950 {
17951 inst.error = BAD_OUT_IT;
17952 return FAIL;
17953 }
17954 }
17955 break;
17956
17957 case IF_INSIDE_IT_LAST_INSN:
17958 case NEUTRAL_IT_INSN:
17959 break;
17960
17961 case IT_INSN:
17962 now_it.state = MANUAL_IT_BLOCK;
17963 now_it.block_length = 0;
17964 break;
17965 }
17966 break;
17967
17968 case AUTOMATIC_IT_BLOCK:
17969 /* Three things may happen now:
17970 a) We should increment current it block size;
17971 b) We should close current it block (closing insn or 4 insns);
17972 c) We should close current it block and start a new one (due
17973 to incompatible conditions or
17974 4 insns-length block reached). */
17975
17976 switch (inst.it_insn_type)
17977 {
17978 case OUTSIDE_IT_INSN:
17979 /* The closure of the block shall happen immediatelly,
17980 so any in_it_block () call reports the block as closed. */
17981 force_automatic_it_block_close ();
17982 break;
17983
17984 case INSIDE_IT_INSN:
17985 case INSIDE_IT_LAST_INSN:
17986 case IF_INSIDE_IT_LAST_INSN:
17987 now_it.block_length++;
17988
17989 if (now_it.block_length > 4
17990 || !now_it_compatible (inst.cond))
17991 {
17992 force_automatic_it_block_close ();
17993 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17994 new_automatic_it_block (inst.cond);
17995 }
17996 else
17997 {
5a01bb1d 17998 now_it.insn_cond = TRUE;
e07e6e58
NC
17999 now_it_add_mask (inst.cond);
18000 }
18001
18002 if (now_it.state == AUTOMATIC_IT_BLOCK
18003 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18004 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18005 close_automatic_it_block ();
18006 break;
18007
18008 case NEUTRAL_IT_INSN:
18009 now_it.block_length++;
5a01bb1d 18010 now_it.insn_cond = TRUE;
e07e6e58
NC
18011
18012 if (now_it.block_length > 4)
18013 force_automatic_it_block_close ();
18014 else
18015 now_it_add_mask (now_it.cc & 1);
18016 break;
18017
18018 case IT_INSN:
18019 close_automatic_it_block ();
18020 now_it.state = MANUAL_IT_BLOCK;
18021 break;
18022 }
18023 break;
18024
18025 case MANUAL_IT_BLOCK:
18026 {
18027 /* Check conditional suffixes. */
18028 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18029 int is_last;
18030 now_it.mask <<= 1;
18031 now_it.mask &= 0x1f;
18032 is_last = (now_it.mask == 0x10);
5a01bb1d 18033 now_it.insn_cond = TRUE;
e07e6e58
NC
18034
18035 switch (inst.it_insn_type)
18036 {
18037 case OUTSIDE_IT_INSN:
18038 inst.error = BAD_NOT_IT;
18039 return FAIL;
18040
18041 case INSIDE_IT_INSN:
18042 if (cond != inst.cond)
18043 {
18044 inst.error = BAD_IT_COND;
18045 return FAIL;
18046 }
18047 break;
18048
18049 case INSIDE_IT_LAST_INSN:
18050 case IF_INSIDE_IT_LAST_INSN:
18051 if (cond != inst.cond)
18052 {
18053 inst.error = BAD_IT_COND;
18054 return FAIL;
18055 }
18056 if (!is_last)
18057 {
18058 inst.error = BAD_BRANCH;
18059 return FAIL;
18060 }
18061 break;
18062
18063 case NEUTRAL_IT_INSN:
18064 /* The BKPT instruction is unconditional even in an IT block. */
18065 break;
18066
18067 case IT_INSN:
18068 inst.error = BAD_IT_IT;
18069 return FAIL;
18070 }
18071 }
18072 break;
18073 }
18074
18075 return SUCCESS;
18076}
18077
5a01bb1d
MGD
18078struct depr_insn_mask
18079{
18080 unsigned long pattern;
18081 unsigned long mask;
18082 const char* description;
18083};
18084
18085/* List of 16-bit instruction patterns deprecated in an IT block in
18086 ARMv8. */
18087static const struct depr_insn_mask depr_it_insns[] = {
18088 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18089 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18090 { 0xa000, 0xb800, N_("ADR") },
18091 { 0x4800, 0xf800, N_("Literal loads") },
18092 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18093 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18094 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18095 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18096 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18097 { 0, 0, NULL }
18098};
18099
e07e6e58
NC
18100static void
18101it_fsm_post_encode (void)
18102{
18103 int is_last;
18104
18105 if (!now_it.state_handled)
18106 handle_it_state ();
18107
5a01bb1d
MGD
18108 if (now_it.insn_cond
18109 && !now_it.warn_deprecated
18110 && warn_on_deprecated
18111 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18112 {
18113 if (inst.instruction >= 0x10000)
18114 {
5c3696f8 18115 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18116 "deprecated in ARMv8"));
18117 now_it.warn_deprecated = TRUE;
18118 }
18119 else
18120 {
18121 const struct depr_insn_mask *p = depr_it_insns;
18122
18123 while (p->mask != 0)
18124 {
18125 if ((inst.instruction & p->mask) == p->pattern)
18126 {
5c3696f8 18127 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18128 "of the following class are deprecated in ARMv8: "
18129 "%s"), p->description);
18130 now_it.warn_deprecated = TRUE;
18131 break;
18132 }
18133
18134 ++p;
18135 }
18136 }
18137
18138 if (now_it.block_length > 1)
18139 {
5c3696f8 18140 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18141 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18142 now_it.warn_deprecated = TRUE;
18143 }
18144 }
18145
e07e6e58
NC
18146 is_last = (now_it.mask == 0x10);
18147 if (is_last)
18148 {
18149 now_it.state = OUTSIDE_IT_BLOCK;
18150 now_it.mask = 0;
18151 }
18152}
18153
18154static void
18155force_automatic_it_block_close (void)
18156{
18157 if (now_it.state == AUTOMATIC_IT_BLOCK)
18158 {
18159 close_automatic_it_block ();
18160 now_it.state = OUTSIDE_IT_BLOCK;
18161 now_it.mask = 0;
18162 }
18163}
18164
18165static int
18166in_it_block (void)
18167{
18168 if (!now_it.state_handled)
18169 handle_it_state ();
18170
18171 return now_it.state != OUTSIDE_IT_BLOCK;
18172}
18173
ff8646ee
TP
18174/* Whether OPCODE only has T32 encoding. Since this function is only used by
18175 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18176 here, hence the "known" in the function name. */
fc289b0a
TP
18177
18178static bfd_boolean
ff8646ee 18179known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18180{
18181 /* Original Thumb-1 wide instruction. */
18182 if (opcode->tencode == do_t_blx
18183 || opcode->tencode == do_t_branch23
18184 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18185 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18186 return TRUE;
18187
ff8646ee
TP
18188 /* Wide-only instruction added to ARMv8-M. */
18189 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m)
18190 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18191 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18192 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18193 return TRUE;
18194
18195 return FALSE;
18196}
18197
18198/* Whether wide instruction variant can be used if available for a valid OPCODE
18199 in ARCH. */
18200
18201static bfd_boolean
18202t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18203{
18204 if (known_t32_only_insn (opcode))
18205 return TRUE;
18206
18207 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18208 of variant T3 of B.W is checked in do_t_branch. */
18209 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18210 && opcode->tencode == do_t_branch)
18211 return TRUE;
18212
18213 /* Wide instruction variants of all instructions with narrow *and* wide
18214 variants become available with ARMv6t2. Other opcodes are either
18215 narrow-only or wide-only and are thus available if OPCODE is valid. */
18216 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18217 return TRUE;
18218
18219 /* OPCODE with narrow only instruction variant or wide variant not
18220 available. */
fc289b0a
TP
18221 return FALSE;
18222}
18223
c19d1205
ZW
18224void
18225md_assemble (char *str)
b99bd4ef 18226{
c19d1205
ZW
18227 char *p = str;
18228 const struct asm_opcode * opcode;
b99bd4ef 18229
c19d1205
ZW
18230 /* Align the previous label if needed. */
18231 if (last_label_seen != NULL)
b99bd4ef 18232 {
c19d1205
ZW
18233 symbol_set_frag (last_label_seen, frag_now);
18234 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18235 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18236 }
18237
c19d1205
ZW
18238 memset (&inst, '\0', sizeof (inst));
18239 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18240
c19d1205
ZW
18241 opcode = opcode_lookup (&p);
18242 if (!opcode)
b99bd4ef 18243 {
c19d1205 18244 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18245 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18246 if (! create_register_alias (str, p)
477330fc 18247 && ! create_neon_reg_alias (str, p))
c19d1205 18248 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18249
b99bd4ef
NC
18250 return;
18251 }
18252
278df34e 18253 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18254 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18255
037e8744
JB
18256 /* The value which unconditional instructions should have in place of the
18257 condition field. */
18258 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18259
c19d1205 18260 if (thumb_mode)
b99bd4ef 18261 {
e74cfd16 18262 arm_feature_set variant;
8f06b2d8
PB
18263
18264 variant = cpu_variant;
18265 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18266 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18267 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18268 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18269 if (!opcode->tvariant
18270 || (thumb_mode == 1
18271 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18272 {
84b52b66 18273 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18274 return;
18275 }
c19d1205
ZW
18276 if (inst.cond != COND_ALWAYS && !unified_syntax
18277 && opcode->tencode != do_t_branch)
b99bd4ef 18278 {
c19d1205 18279 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18280 return;
18281 }
18282
fc289b0a
TP
18283 /* Two things are addressed here:
18284 1) Implicit require narrow instructions on Thumb-1.
18285 This avoids relaxation accidentally introducing Thumb-2
18286 instructions.
18287 2) Reject wide instructions in non Thumb-2 cores.
18288
18289 Only instructions with narrow and wide variants need to be handled
18290 but selecting all non wide-only instructions is easier. */
18291 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18292 && !t32_insn_ok (variant, opcode))
076d447c 18293 {
fc289b0a
TP
18294 if (inst.size_req == 0)
18295 inst.size_req = 2;
18296 else if (inst.size_req == 4)
752d5da4 18297 {
ff8646ee
TP
18298 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18299 as_bad (_("selected processor does not support 32bit wide "
18300 "variant of instruction `%s'"), str);
18301 else
18302 as_bad (_("selected processor does not support `%s' in "
18303 "Thumb-2 mode"), str);
fc289b0a 18304 return;
752d5da4 18305 }
076d447c
PB
18306 }
18307
c19d1205
ZW
18308 inst.instruction = opcode->tvalue;
18309
5be8be5d 18310 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18311 {
18312 /* Prepare the it_insn_type for those encodings that don't set
18313 it. */
18314 it_fsm_pre_encode ();
c19d1205 18315
477330fc 18316 opcode->tencode ();
e07e6e58 18317
477330fc
RM
18318 it_fsm_post_encode ();
18319 }
e27ec89e 18320
0110f2b8 18321 if (!(inst.error || inst.relax))
b99bd4ef 18322 {
9c2799c2 18323 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18324 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18325 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18326 {
c19d1205 18327 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18328 return;
18329 }
18330 }
076d447c
PB
18331
18332 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18333 instruction. */
9c2799c2 18334 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18335
e74cfd16
PB
18336 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18337 *opcode->tvariant);
ee065d83 18338 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18339 set those bits when Thumb-2 32-bit instructions are seen. The impact
18340 of relaxable instructions will be considered later after we finish all
18341 relaxation. */
ff8646ee
TP
18342 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18343 variant = arm_arch_none;
18344 else
18345 variant = cpu_variant;
18346 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18347 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18348 arm_ext_v6t2);
cd000bff 18349
88714cb8
DG
18350 check_neon_suffixes;
18351
cd000bff 18352 if (!inst.error)
c877a2f2
NC
18353 {
18354 mapping_state (MAP_THUMB);
18355 }
c19d1205 18356 }
3e9e4fcf 18357 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18358 {
845b51d6
PB
18359 bfd_boolean is_bx;
18360
18361 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18362 is_bx = (opcode->aencode == do_bx);
18363
c19d1205 18364 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18365 if (!(is_bx && fix_v4bx)
18366 && !(opcode->avariant &&
18367 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18368 {
84b52b66 18369 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18370 return;
b99bd4ef 18371 }
c19d1205 18372 if (inst.size_req)
b99bd4ef 18373 {
c19d1205
ZW
18374 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18375 return;
b99bd4ef
NC
18376 }
18377
c19d1205
ZW
18378 inst.instruction = opcode->avalue;
18379 if (opcode->tag == OT_unconditionalF)
eff0bc54 18380 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18381 else
18382 inst.instruction |= inst.cond << 28;
18383 inst.size = INSN_SIZE;
5be8be5d 18384 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18385 {
18386 it_fsm_pre_encode ();
18387 opcode->aencode ();
18388 it_fsm_post_encode ();
18389 }
ee065d83 18390 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18391 on a hypothetical non-thumb v5 core. */
845b51d6 18392 if (is_bx)
e74cfd16 18393 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18394 else
e74cfd16
PB
18395 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18396 *opcode->avariant);
88714cb8
DG
18397
18398 check_neon_suffixes;
18399
cd000bff 18400 if (!inst.error)
c877a2f2
NC
18401 {
18402 mapping_state (MAP_ARM);
18403 }
b99bd4ef 18404 }
3e9e4fcf
JB
18405 else
18406 {
18407 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18408 "-- `%s'"), str);
18409 return;
18410 }
c19d1205
ZW
18411 output_inst (str);
18412}
b99bd4ef 18413
e07e6e58
NC
18414static void
18415check_it_blocks_finished (void)
18416{
18417#ifdef OBJ_ELF
18418 asection *sect;
18419
18420 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18421 if (seg_info (sect)->tc_segment_info_data.current_it.state
18422 == MANUAL_IT_BLOCK)
18423 {
18424 as_warn (_("section '%s' finished with an open IT block."),
18425 sect->name);
18426 }
18427#else
18428 if (now_it.state == MANUAL_IT_BLOCK)
18429 as_warn (_("file finished with an open IT block."));
18430#endif
18431}
18432
c19d1205
ZW
18433/* Various frobbings of labels and their addresses. */
18434
18435void
18436arm_start_line_hook (void)
18437{
18438 last_label_seen = NULL;
b99bd4ef
NC
18439}
18440
c19d1205
ZW
18441void
18442arm_frob_label (symbolS * sym)
b99bd4ef 18443{
c19d1205 18444 last_label_seen = sym;
b99bd4ef 18445
c19d1205 18446 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18447
c19d1205
ZW
18448#if defined OBJ_COFF || defined OBJ_ELF
18449 ARM_SET_INTERWORK (sym, support_interwork);
18450#endif
b99bd4ef 18451
e07e6e58
NC
18452 force_automatic_it_block_close ();
18453
5f4273c7 18454 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18455 as Thumb functions. This is because these labels, whilst
18456 they exist inside Thumb code, are not the entry points for
18457 possible ARM->Thumb calls. Also, these labels can be used
18458 as part of a computed goto or switch statement. eg gcc
18459 can generate code that looks like this:
b99bd4ef 18460
c19d1205
ZW
18461 ldr r2, [pc, .Laaa]
18462 lsl r3, r3, #2
18463 ldr r2, [r3, r2]
18464 mov pc, r2
b99bd4ef 18465
c19d1205
ZW
18466 .Lbbb: .word .Lxxx
18467 .Lccc: .word .Lyyy
18468 ..etc...
18469 .Laaa: .word Lbbb
b99bd4ef 18470
c19d1205
ZW
18471 The first instruction loads the address of the jump table.
18472 The second instruction converts a table index into a byte offset.
18473 The third instruction gets the jump address out of the table.
18474 The fourth instruction performs the jump.
b99bd4ef 18475
c19d1205
ZW
18476 If the address stored at .Laaa is that of a symbol which has the
18477 Thumb_Func bit set, then the linker will arrange for this address
18478 to have the bottom bit set, which in turn would mean that the
18479 address computation performed by the third instruction would end
18480 up with the bottom bit set. Since the ARM is capable of unaligned
18481 word loads, the instruction would then load the incorrect address
18482 out of the jump table, and chaos would ensue. */
18483 if (label_is_thumb_function_name
18484 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18485 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18486 {
c19d1205
ZW
18487 /* When the address of a Thumb function is taken the bottom
18488 bit of that address should be set. This will allow
18489 interworking between Arm and Thumb functions to work
18490 correctly. */
b99bd4ef 18491
c19d1205 18492 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18493
c19d1205 18494 label_is_thumb_function_name = FALSE;
b99bd4ef 18495 }
07a53e5c 18496
07a53e5c 18497 dwarf2_emit_label (sym);
b99bd4ef
NC
18498}
18499
c921be7d 18500bfd_boolean
c19d1205 18501arm_data_in_code (void)
b99bd4ef 18502{
c19d1205 18503 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18504 {
c19d1205
ZW
18505 *input_line_pointer = '/';
18506 input_line_pointer += 5;
18507 *input_line_pointer = 0;
c921be7d 18508 return TRUE;
b99bd4ef
NC
18509 }
18510
c921be7d 18511 return FALSE;
b99bd4ef
NC
18512}
18513
c19d1205
ZW
18514char *
18515arm_canonicalize_symbol_name (char * name)
b99bd4ef 18516{
c19d1205 18517 int len;
b99bd4ef 18518
c19d1205
ZW
18519 if (thumb_mode && (len = strlen (name)) > 5
18520 && streq (name + len - 5, "/data"))
18521 *(name + len - 5) = 0;
b99bd4ef 18522
c19d1205 18523 return name;
b99bd4ef 18524}
c19d1205
ZW
18525\f
18526/* Table of all register names defined by default. The user can
18527 define additional names with .req. Note that all register names
18528 should appear in both upper and lowercase variants. Some registers
18529 also have mixed-case names. */
b99bd4ef 18530
dcbf9037 18531#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18532#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18533#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18534#define REGSET(p,t) \
18535 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18536 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18537 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18538 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18539#define REGSETH(p,t) \
18540 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18541 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18542 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18543 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18544#define REGSET2(p,t) \
18545 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18546 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18547 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18548 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18549#define SPLRBANK(base,bank,t) \
18550 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18551 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18552 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18553 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18554 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18555 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18556
c19d1205 18557static const struct reg_entry reg_names[] =
7ed4c4c5 18558{
c19d1205
ZW
18559 /* ARM integer registers. */
18560 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18561
c19d1205
ZW
18562 /* ATPCS synonyms. */
18563 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18564 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18565 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18566
c19d1205
ZW
18567 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18568 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18569 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18570
c19d1205
ZW
18571 /* Well-known aliases. */
18572 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18573 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18574
18575 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18576 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18577
18578 /* Coprocessor numbers. */
18579 REGSET(p, CP), REGSET(P, CP),
18580
18581 /* Coprocessor register numbers. The "cr" variants are for backward
18582 compatibility. */
18583 REGSET(c, CN), REGSET(C, CN),
18584 REGSET(cr, CN), REGSET(CR, CN),
18585
90ec0d68
MGD
18586 /* ARM banked registers. */
18587 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18588 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18589 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18590 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18591 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18592 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18593 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18594
18595 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18596 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18597 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18598 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18599 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18600 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18601 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18602 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18603
18604 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18605 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18606 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18607 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18608 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18609 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18610 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18611 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18612 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18613
c19d1205
ZW
18614 /* FPA registers. */
18615 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18616 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18617
18618 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18619 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18620
18621 /* VFP SP registers. */
5287ad62
JB
18622 REGSET(s,VFS), REGSET(S,VFS),
18623 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18624
18625 /* VFP DP Registers. */
5287ad62
JB
18626 REGSET(d,VFD), REGSET(D,VFD),
18627 /* Extra Neon DP registers. */
18628 REGSETH(d,VFD), REGSETH(D,VFD),
18629
18630 /* Neon QP registers. */
18631 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18632
18633 /* VFP control registers. */
18634 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18635 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18636 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18637 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18638 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18639 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18640
18641 /* Maverick DSP coprocessor registers. */
18642 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18643 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18644
18645 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18646 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18647 REGDEF(dspsc,0,DSPSC),
18648
18649 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18650 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18651 REGDEF(DSPSC,0,DSPSC),
18652
18653 /* iWMMXt data registers - p0, c0-15. */
18654 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18655
18656 /* iWMMXt control registers - p1, c0-3. */
18657 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18658 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18659 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18660 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18661
18662 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18663 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18664 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18665 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18666 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18667
18668 /* XScale accumulator registers. */
18669 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18670};
18671#undef REGDEF
18672#undef REGNUM
18673#undef REGSET
7ed4c4c5 18674
c19d1205
ZW
18675/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18676 within psr_required_here. */
18677static const struct asm_psr psrs[] =
18678{
18679 /* Backward compatibility notation. Note that "all" is no longer
18680 truly all possible PSR bits. */
18681 {"all", PSR_c | PSR_f},
18682 {"flg", PSR_f},
18683 {"ctl", PSR_c},
18684
18685 /* Individual flags. */
18686 {"f", PSR_f},
18687 {"c", PSR_c},
18688 {"x", PSR_x},
18689 {"s", PSR_s},
59b42a0d 18690
c19d1205
ZW
18691 /* Combinations of flags. */
18692 {"fs", PSR_f | PSR_s},
18693 {"fx", PSR_f | PSR_x},
18694 {"fc", PSR_f | PSR_c},
18695 {"sf", PSR_s | PSR_f},
18696 {"sx", PSR_s | PSR_x},
18697 {"sc", PSR_s | PSR_c},
18698 {"xf", PSR_x | PSR_f},
18699 {"xs", PSR_x | PSR_s},
18700 {"xc", PSR_x | PSR_c},
18701 {"cf", PSR_c | PSR_f},
18702 {"cs", PSR_c | PSR_s},
18703 {"cx", PSR_c | PSR_x},
18704 {"fsx", PSR_f | PSR_s | PSR_x},
18705 {"fsc", PSR_f | PSR_s | PSR_c},
18706 {"fxs", PSR_f | PSR_x | PSR_s},
18707 {"fxc", PSR_f | PSR_x | PSR_c},
18708 {"fcs", PSR_f | PSR_c | PSR_s},
18709 {"fcx", PSR_f | PSR_c | PSR_x},
18710 {"sfx", PSR_s | PSR_f | PSR_x},
18711 {"sfc", PSR_s | PSR_f | PSR_c},
18712 {"sxf", PSR_s | PSR_x | PSR_f},
18713 {"sxc", PSR_s | PSR_x | PSR_c},
18714 {"scf", PSR_s | PSR_c | PSR_f},
18715 {"scx", PSR_s | PSR_c | PSR_x},
18716 {"xfs", PSR_x | PSR_f | PSR_s},
18717 {"xfc", PSR_x | PSR_f | PSR_c},
18718 {"xsf", PSR_x | PSR_s | PSR_f},
18719 {"xsc", PSR_x | PSR_s | PSR_c},
18720 {"xcf", PSR_x | PSR_c | PSR_f},
18721 {"xcs", PSR_x | PSR_c | PSR_s},
18722 {"cfs", PSR_c | PSR_f | PSR_s},
18723 {"cfx", PSR_c | PSR_f | PSR_x},
18724 {"csf", PSR_c | PSR_s | PSR_f},
18725 {"csx", PSR_c | PSR_s | PSR_x},
18726 {"cxf", PSR_c | PSR_x | PSR_f},
18727 {"cxs", PSR_c | PSR_x | PSR_s},
18728 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18729 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18730 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18731 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18732 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18733 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18734 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18735 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18736 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18737 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18738 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18739 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18740 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18741 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18742 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18743 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18744 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18745 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18746 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18747 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18748 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18749 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18750 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18751 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18752};
18753
62b3e311
PB
18754/* Table of V7M psr names. */
18755static const struct asm_psr v7m_psrs[] =
18756{
2b744c99
PB
18757 {"apsr", 0 }, {"APSR", 0 },
18758 {"iapsr", 1 }, {"IAPSR", 1 },
18759 {"eapsr", 2 }, {"EAPSR", 2 },
18760 {"psr", 3 }, {"PSR", 3 },
18761 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18762 {"ipsr", 5 }, {"IPSR", 5 },
18763 {"epsr", 6 }, {"EPSR", 6 },
18764 {"iepsr", 7 }, {"IEPSR", 7 },
18765 {"msp", 8 }, {"MSP", 8 },
18766 {"psp", 9 }, {"PSP", 9 },
18767 {"primask", 16}, {"PRIMASK", 16},
18768 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18769 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18770 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18771 {"faultmask", 19}, {"FAULTMASK", 19},
18772 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18773};
18774
c19d1205
ZW
18775/* Table of all shift-in-operand names. */
18776static const struct asm_shift_name shift_names [] =
b99bd4ef 18777{
c19d1205
ZW
18778 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18779 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18780 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18781 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18782 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18783 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18784};
b99bd4ef 18785
c19d1205
ZW
18786/* Table of all explicit relocation names. */
18787#ifdef OBJ_ELF
18788static struct reloc_entry reloc_names[] =
18789{
18790 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18791 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18792 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18793 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18794 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18795 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18796 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18797 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18798 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18799 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18800 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18801 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18802 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18803 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18804 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18805 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18806 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18807 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18808};
18809#endif
b99bd4ef 18810
c19d1205
ZW
18811/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18812static const struct asm_cond conds[] =
18813{
18814 {"eq", 0x0},
18815 {"ne", 0x1},
18816 {"cs", 0x2}, {"hs", 0x2},
18817 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18818 {"mi", 0x4},
18819 {"pl", 0x5},
18820 {"vs", 0x6},
18821 {"vc", 0x7},
18822 {"hi", 0x8},
18823 {"ls", 0x9},
18824 {"ge", 0xa},
18825 {"lt", 0xb},
18826 {"gt", 0xc},
18827 {"le", 0xd},
18828 {"al", 0xe}
18829};
bfae80f2 18830
e797f7e0 18831#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18832 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18833 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18834
62b3e311
PB
18835static struct asm_barrier_opt barrier_opt_names[] =
18836{
e797f7e0
MGD
18837 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18838 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18839 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18840 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18841 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18842 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18843 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18844 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18845 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18846 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18847 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18848 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18849 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18850 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18851 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18852 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18853};
18854
e797f7e0
MGD
18855#undef UL_BARRIER
18856
c19d1205
ZW
18857/* Table of ARM-format instructions. */
18858
18859/* Macros for gluing together operand strings. N.B. In all cases
18860 other than OPS0, the trailing OP_stop comes from default
18861 zero-initialization of the unspecified elements of the array. */
18862#define OPS0() { OP_stop, }
18863#define OPS1(a) { OP_##a, }
18864#define OPS2(a,b) { OP_##a,OP_##b, }
18865#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18866#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18867#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18868#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18869
5be8be5d
DG
18870/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18871 This is useful when mixing operands for ARM and THUMB, i.e. using the
18872 MIX_ARM_THUMB_OPERANDS macro.
18873 In order to use these macros, prefix the number of operands with _
18874 e.g. _3. */
18875#define OPS_1(a) { a, }
18876#define OPS_2(a,b) { a,b, }
18877#define OPS_3(a,b,c) { a,b,c, }
18878#define OPS_4(a,b,c,d) { a,b,c,d, }
18879#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18880#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18881
c19d1205
ZW
18882/* These macros abstract out the exact format of the mnemonic table and
18883 save some repeated characters. */
18884
18885/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18886#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18887 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18888 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18889
18890/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18891 a T_MNEM_xyz enumerator. */
18892#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18893 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18894#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18895 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18896
18897/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18898 infix after the third character. */
18899#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18900 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18901 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18902#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18903 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18904 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18905#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18906 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18907#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18908 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18909#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18910 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18911#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18912 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18913
c19d1205 18914/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18915 field is still 0xE. Many of the Thumb variants can be executed
18916 conditionally, so this is checked separately. */
c19d1205 18917#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18918 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18919 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18920
dd5181d5
KT
18921/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18922 Used by mnemonics that have very minimal differences in the encoding for
18923 ARM and Thumb variants and can be handled in a common function. */
18924#define TUEc(mnem, op, top, nops, ops, en) \
18925 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18926 THUMB_VARIANT, do_##en, do_##en }
18927
c19d1205
ZW
18928/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18929 condition code field. */
18930#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18931 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18932 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18933
18934/* ARM-only variants of all the above. */
6a86118a 18935#define CE(mnem, op, nops, ops, ae) \
21d799b5 18936 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18937
18938#define C3(mnem, op, nops, ops, ae) \
18939 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18940
e3cb604e
PB
18941/* Legacy mnemonics that always have conditional infix after the third
18942 character. */
18943#define CL(mnem, op, nops, ops, ae) \
21d799b5 18944 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18945 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18946
8f06b2d8
PB
18947/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18948#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18949 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18950
e3cb604e
PB
18951/* Legacy coprocessor instructions where conditional infix and conditional
18952 suffix are ambiguous. For consistency this includes all FPA instructions,
18953 not just the potentially ambiguous ones. */
18954#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18955 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18956 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18957
18958/* Coprocessor, takes either a suffix or a position-3 infix
18959 (for an FPA corner case). */
18960#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18961 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18962 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18963
6a86118a 18964#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18965 { m1 #m2 m3, OPS##nops ops, \
18966 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18967 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18968
18969#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18970 xCM_ (m1, , m2, op, nops, ops, ae), \
18971 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18972 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18973 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18974 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18975 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18976 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18977 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18978 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18979 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18980 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18981 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18982 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18983 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18984 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18985 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18986 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18987 xCM_ (m1, le, m2, op, nops, ops, ae), \
18988 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18989
18990#define UE(mnem, op, nops, ops, ae) \
18991 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18992
18993#define UF(mnem, op, nops, ops, ae) \
18994 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18995
5287ad62
JB
18996/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18997 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18998 use the same encoding function for each. */
18999#define NUF(mnem, op, nops, ops, enc) \
19000 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19001 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19002
19003/* Neon data processing, version which indirects through neon_enc_tab for
19004 the various overloaded versions of opcodes. */
19005#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19006 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19007 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19008
19009/* Neon insn with conditional suffix for the ARM version, non-overloaded
19010 version. */
037e8744
JB
19011#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19012 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19013 THUMB_VARIANT, do_##enc, do_##enc }
19014
037e8744 19015#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19016 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19017
19018#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19019 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19020
5287ad62 19021/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19022#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19023 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19024 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19025
037e8744 19026#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19027 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19028
19029#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19030 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19031
c19d1205
ZW
19032#define do_0 0
19033
c19d1205 19034static const struct asm_opcode insns[] =
bfae80f2 19035{
74db7efb
NC
19036#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19037#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19038 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19039 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19040 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19041 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19042 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19043 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19044 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19045 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19046 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19047 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19048 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19049 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19050 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19051 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19052 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19053 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19054
19055 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19056 for setting PSR flag bits. They are obsolete in V6 and do not
19057 have Thumb equivalents. */
21d799b5
NC
19058 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19059 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19060 CL("tstp", 110f000, 2, (RR, SH), cmp),
19061 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19062 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19063 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19064 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19065 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19066 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19067
19068 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19069 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19070 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19071 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19072
19073 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19074 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19075 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19076 OP_RRnpc),
19077 OP_ADDRGLDR),ldst, t_ldst),
19078 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19079
19080 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19081 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19082 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19083 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19084 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19085 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19086
19087 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19088 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19089 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19090 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19091
c19d1205 19092 /* Pseudo ops. */
21d799b5 19093 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19094 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19095 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19096 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19097
19098 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19099 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19100 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19101 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19102 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19103 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19104 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19105 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19106 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19107 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19108 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19109 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19110 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19111
16a4cf17 19112 /* These may simplify to neg. */
21d799b5
NC
19113 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19114 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19115
c921be7d
NC
19116#undef THUMB_VARIANT
19117#define THUMB_VARIANT & arm_ext_v6
19118
21d799b5 19119 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19120
19121 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19122#undef THUMB_VARIANT
19123#define THUMB_VARIANT & arm_ext_v6t2
19124
21d799b5
NC
19125 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19126 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19127 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19128
5be8be5d
DG
19129 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19130 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19131 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19132 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19133
21d799b5
NC
19134 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19135 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19136
21d799b5
NC
19137 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19138 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19139
19140 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19141 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19142 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19143
19144 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19145 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19146 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19147 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19148 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19149 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19150 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19151 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19152
c921be7d
NC
19153#undef ARM_VARIANT
19154#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19155#undef THUMB_VARIANT
19156#define THUMB_VARIANT & arm_ext_v4t
19157
21d799b5
NC
19158 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19159 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19160
c921be7d
NC
19161#undef THUMB_VARIANT
19162#define THUMB_VARIANT & arm_ext_v6t2
19163
21d799b5 19164 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19165 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19166
19167 /* Generic coprocessor instructions. */
21d799b5
NC
19168 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19169 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19170 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19171 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19172 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19173 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19174 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19175
c921be7d
NC
19176#undef ARM_VARIANT
19177#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19178
21d799b5 19179 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19180 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19181
c921be7d
NC
19182#undef ARM_VARIANT
19183#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19184#undef THUMB_VARIANT
19185#define THUMB_VARIANT & arm_ext_msr
19186
d2cd1205
JB
19187 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19188 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19189
c921be7d
NC
19190#undef ARM_VARIANT
19191#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19192#undef THUMB_VARIANT
19193#define THUMB_VARIANT & arm_ext_v6t2
19194
21d799b5
NC
19195 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19196 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19197 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19198 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19199 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19200 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19201 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19202 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19203
c921be7d
NC
19204#undef ARM_VARIANT
19205#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19206#undef THUMB_VARIANT
19207#define THUMB_VARIANT & arm_ext_v4t
19208
5be8be5d
DG
19209 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19210 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19211 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19212 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19213 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19214 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19215
c921be7d
NC
19216#undef ARM_VARIANT
19217#define ARM_VARIANT & arm_ext_v4t_5
19218
c19d1205
ZW
19219 /* ARM Architecture 4T. */
19220 /* Note: bx (and blx) are required on V5, even if the processor does
19221 not support Thumb. */
21d799b5 19222 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19223
c921be7d
NC
19224#undef ARM_VARIANT
19225#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19226#undef THUMB_VARIANT
19227#define THUMB_VARIANT & arm_ext_v5t
19228
c19d1205
ZW
19229 /* Note: blx has 2 variants; the .value coded here is for
19230 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19231 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19232 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19233
c921be7d
NC
19234#undef THUMB_VARIANT
19235#define THUMB_VARIANT & arm_ext_v6t2
19236
21d799b5
NC
19237 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19238 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19239 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19240 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19241 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19242 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19243 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19244 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19245
c921be7d 19246#undef ARM_VARIANT
74db7efb
NC
19247#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19248#undef THUMB_VARIANT
19249#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19250
21d799b5
NC
19251 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19252 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19253 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19254 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19255
21d799b5
NC
19256 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19257 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19258
21d799b5
NC
19259 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19260 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19261 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19262 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19263
21d799b5
NC
19264 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19265 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19266 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19267 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19268
21d799b5
NC
19269 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19270 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19271
03ee1b7f
NC
19272 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19273 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19274 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19275 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19276
c921be7d 19277#undef ARM_VARIANT
74db7efb
NC
19278#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19279#undef THUMB_VARIANT
19280#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19281
21d799b5 19282 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19283 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19284 ldrd, t_ldstd),
19285 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19286 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19287
21d799b5
NC
19288 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19289 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19290
c921be7d
NC
19291#undef ARM_VARIANT
19292#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19293
21d799b5 19294 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19295
c921be7d
NC
19296#undef ARM_VARIANT
19297#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19298#undef THUMB_VARIANT
19299#define THUMB_VARIANT & arm_ext_v6
19300
21d799b5
NC
19301 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19302 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19303 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19304 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19305 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19306 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19307 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19308 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19309 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19310 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19311
c921be7d 19312#undef THUMB_VARIANT
ff8646ee 19313#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19314
5be8be5d
DG
19315 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19316 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19317 strex, t_strex),
ff8646ee
TP
19318#undef THUMB_VARIANT
19319#define THUMB_VARIANT & arm_ext_v6t2
19320
21d799b5
NC
19321 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19322 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19323
21d799b5
NC
19324 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19325 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19326
9e3c6df6 19327/* ARM V6 not included in V7M. */
c921be7d
NC
19328#undef THUMB_VARIANT
19329#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19330 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19331 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19332 UF(rfeib, 9900a00, 1, (RRw), rfe),
19333 UF(rfeda, 8100a00, 1, (RRw), rfe),
19334 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19335 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19336 UF(rfefa, 8100a00, 1, (RRw), rfe),
19337 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19338 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19339 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19340 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19341 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19342 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19343 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19344 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19345 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19346 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19347 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19348 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19349
9e3c6df6
PB
19350/* ARM V6 not included in V7M (eg. integer SIMD). */
19351#undef THUMB_VARIANT
19352#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19353 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19354 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19355 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19356 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19357 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19358 /* Old name for QASX. */
74db7efb 19359 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19360 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19361 /* Old name for QSAX. */
74db7efb 19362 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19363 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19364 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19365 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19366 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19367 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19368 /* Old name for SASX. */
74db7efb 19369 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19370 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19371 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19372 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19373 /* Old name for SHASX. */
21d799b5 19374 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19375 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19376 /* Old name for SHSAX. */
21d799b5
NC
19377 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19378 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19379 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19380 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19381 /* Old name for SSAX. */
74db7efb 19382 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19383 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19384 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19385 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19386 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19387 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19388 /* Old name for UASX. */
74db7efb 19389 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19390 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19391 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19392 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19393 /* Old name for UHASX. */
21d799b5
NC
19394 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19395 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19396 /* Old name for UHSAX. */
21d799b5
NC
19397 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19398 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19399 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19400 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19401 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19402 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19403 /* Old name for UQASX. */
21d799b5
NC
19404 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19405 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19406 /* Old name for UQSAX. */
21d799b5
NC
19407 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19408 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19409 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19410 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19411 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19412 /* Old name for USAX. */
74db7efb 19413 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19414 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19415 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19416 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19417 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19418 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19419 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19420 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19421 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19422 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19423 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19424 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19425 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19426 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19427 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19428 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19429 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19430 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19431 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19432 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19433 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19434 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19435 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19436 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19437 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19438 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19439 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19440 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19441 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19442 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19443 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19444 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19445 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19446 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19447
c921be7d
NC
19448#undef ARM_VARIANT
19449#define ARM_VARIANT & arm_ext_v6k
19450#undef THUMB_VARIANT
19451#define THUMB_VARIANT & arm_ext_v6k
19452
21d799b5
NC
19453 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19454 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19455 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19456 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19457
c921be7d
NC
19458#undef THUMB_VARIANT
19459#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19460 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19461 ldrexd, t_ldrexd),
19462 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19463 RRnpcb), strexd, t_strexd),
ebdca51a 19464
c921be7d 19465#undef THUMB_VARIANT
ff8646ee 19466#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19467 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19468 rd_rn, rd_rn),
19469 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19470 rd_rn, rd_rn),
19471 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19472 strex, t_strexbh),
5be8be5d 19473 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19474 strex, t_strexbh),
21d799b5 19475 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19476
c921be7d 19477#undef ARM_VARIANT
f4c65163 19478#define ARM_VARIANT & arm_ext_sec
74db7efb 19479#undef THUMB_VARIANT
f4c65163 19480#define THUMB_VARIANT & arm_ext_sec
c921be7d 19481
21d799b5 19482 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19483
90ec0d68
MGD
19484#undef ARM_VARIANT
19485#define ARM_VARIANT & arm_ext_virt
19486#undef THUMB_VARIANT
19487#define THUMB_VARIANT & arm_ext_virt
19488
19489 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19490 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19491
ddfded2f
MW
19492#undef ARM_VARIANT
19493#define ARM_VARIANT & arm_ext_pan
19494#undef THUMB_VARIANT
19495#define THUMB_VARIANT & arm_ext_pan
19496
19497 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19498
c921be7d 19499#undef ARM_VARIANT
74db7efb 19500#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19501#undef THUMB_VARIANT
19502#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19503
21d799b5
NC
19504 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19505 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19506 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19507 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19508
21d799b5 19509 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19510 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19511
5be8be5d
DG
19512 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19513 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19514 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19515 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19516
ff8646ee
TP
19517#undef THUMB_VARIANT
19518#define THUMB_VARIANT & arm_ext_v6t2_v8m
19519 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19520 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19521
bf3eeda7 19522 /* Thumb-only instructions. */
74db7efb 19523#undef ARM_VARIANT
bf3eeda7
NS
19524#define ARM_VARIANT NULL
19525 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19526 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19527
19528 /* ARM does not really have an IT instruction, so always allow it.
19529 The opcode is copied from Thumb in order to allow warnings in
19530 -mimplicit-it=[never | arm] modes. */
19531#undef ARM_VARIANT
19532#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19533#undef THUMB_VARIANT
19534#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19535
21d799b5
NC
19536 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19537 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19538 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19539 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19540 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19541 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19542 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19543 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19544 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19545 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19546 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19547 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19548 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19549 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19550 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19551 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19552 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19553 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19554
92e90b6e 19555 /* Thumb2 only instructions. */
c921be7d
NC
19556#undef ARM_VARIANT
19557#define ARM_VARIANT NULL
92e90b6e 19558
21d799b5
NC
19559 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19560 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19561 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19562 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19563 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19564 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19565
eea54501
MGD
19566 /* Hardware division instructions. */
19567#undef ARM_VARIANT
19568#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19569#undef THUMB_VARIANT
19570#define THUMB_VARIANT & arm_ext_div
19571
eea54501
MGD
19572 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19573 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19574
7e806470 19575 /* ARM V6M/V7 instructions. */
c921be7d
NC
19576#undef ARM_VARIANT
19577#define ARM_VARIANT & arm_ext_barrier
19578#undef THUMB_VARIANT
19579#define THUMB_VARIANT & arm_ext_barrier
19580
ccb84d65
JB
19581 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19582 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19583 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19584
62b3e311 19585 /* ARM V7 instructions. */
c921be7d
NC
19586#undef ARM_VARIANT
19587#define ARM_VARIANT & arm_ext_v7
19588#undef THUMB_VARIANT
19589#define THUMB_VARIANT & arm_ext_v7
19590
21d799b5
NC
19591 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19592 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19593
74db7efb 19594#undef ARM_VARIANT
60e5ef9f 19595#define ARM_VARIANT & arm_ext_mp
74db7efb 19596#undef THUMB_VARIANT
60e5ef9f
MGD
19597#define THUMB_VARIANT & arm_ext_mp
19598
19599 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19600
53c4b28b
MGD
19601 /* AArchv8 instructions. */
19602#undef ARM_VARIANT
19603#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19604
19605/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19606#undef THUMB_VARIANT
4ed7ed8d 19607#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19608
4ed7ed8d
TP
19609 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19610 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19611 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19612 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19613 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19614 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19615 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19616 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19617 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19618 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19619 stlex, t_stlex),
4b8c8c02
RE
19620 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19621 stlex, t_stlex),
19622 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19623 stlex, t_stlex),
4ed7ed8d
TP
19624#undef THUMB_VARIANT
19625#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19626
4ed7ed8d
TP
19627 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19628 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19629 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19630 ldrexd, t_ldrexd),
19631 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19632 strexd, t_strexd),
8884b720 19633 /* ARMv8 T32 only. */
74db7efb 19634#undef ARM_VARIANT
b79f7053
MGD
19635#define ARM_VARIANT NULL
19636 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19637 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19638 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19639
33399f07
MGD
19640 /* FP for ARMv8. */
19641#undef ARM_VARIANT
a715796b 19642#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19643#undef THUMB_VARIANT
a715796b 19644#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19645
19646 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19647 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19648 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19649 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19650 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19651 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19652 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19653 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19654 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19655 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19656 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19657 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19658 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19659 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19660 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19661 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19662 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19663
91ff7894
MGD
19664 /* Crypto v1 extensions. */
19665#undef ARM_VARIANT
19666#define ARM_VARIANT & fpu_crypto_ext_armv8
19667#undef THUMB_VARIANT
19668#define THUMB_VARIANT & fpu_crypto_ext_armv8
19669
19670 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19671 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19672 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19673 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19674 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19675 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19676 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19677 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19678 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19679 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19680 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19681 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19682 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19683 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19684
dd5181d5 19685#undef ARM_VARIANT
74db7efb 19686#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19687#undef THUMB_VARIANT
19688#define THUMB_VARIANT & crc_ext_armv8
19689 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19690 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19691 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19692 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19693 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19694 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19695
105bde57
MW
19696 /* ARMv8.2 RAS extension. */
19697#undef ARM_VARIANT
19698#define ARM_VARIANT & arm_ext_v8_2
19699#undef THUMB_VARIANT
19700#define THUMB_VARIANT & arm_ext_v8_2
19701 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19702
c921be7d
NC
19703#undef ARM_VARIANT
19704#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19705#undef THUMB_VARIANT
19706#define THUMB_VARIANT NULL
c921be7d 19707
21d799b5
NC
19708 cCE("wfs", e200110, 1, (RR), rd),
19709 cCE("rfs", e300110, 1, (RR), rd),
19710 cCE("wfc", e400110, 1, (RR), rd),
19711 cCE("rfc", e500110, 1, (RR), rd),
19712
19713 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19714 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19715 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19716 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19717
19718 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19719 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19720 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19721 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19722
19723 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19724 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19725 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19726 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19727 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19728 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19729 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19730 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19731 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19732 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19733 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19734 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19735
19736 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19737 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19738 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19739 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19740 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19741 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19742 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19743 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19744 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19745 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19746 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19747 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19748
19749 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19750 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19751 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19752 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19753 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19754 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19755 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19756 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19757 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19758 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19759 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19760 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19761
19762 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19763 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19764 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19765 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19766 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19767 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19768 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19769 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19770 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19771 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19772 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19773 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19774
19775 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19776 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19777 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19778 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19779 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19780 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19781 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19782 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19783 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19784 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19785 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19786 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19787
19788 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19789 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19790 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19791 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19792 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19793 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19794 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19795 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19796 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19797 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19798 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19799 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19800
19801 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19802 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19803 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19804 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19805 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19806 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19807 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19808 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19809 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19810 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19811 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19812 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19813
19814 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19815 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19816 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19817 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19818 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19819 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19820 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19821 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19822 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19823 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19824 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19825 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19826
19827 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19828 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19829 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19830 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19831 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19832 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19833 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19834 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19835 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19836 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19837 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19838 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19839
19840 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19841 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19842 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19843 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19844 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19845 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19846 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19847 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19848 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19849 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19850 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19851 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19852
19853 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19854 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19855 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19856 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19857 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19858 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19859 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19860 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19861 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19862 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19863 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19864 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19865
19866 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19867 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19868 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19869 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19870 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19871 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19872 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19873 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19874 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19875 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19876 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19877 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19878
19879 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19880 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19881 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19882 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19883 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19884 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19885 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19886 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19887 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19888 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19889 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19890 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19891
19892 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19893 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19894 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19895 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19896 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19897 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19898 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19899 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19900 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19901 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19902 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19903 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19904
19905 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19906 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19907 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19908 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19909 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19910 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19911 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19912 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19913 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19914 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19915 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19916 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19917
19918 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19919 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19920 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19921 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19922 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19923 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19924 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19925 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19926 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19927 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19928 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19929 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19930
19931 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19932 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19933 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19934 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19935 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19936 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19937 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19938 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19939 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19940 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19941 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19942 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19943
19944 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19945 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19946 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19947 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19948 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19949 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19950 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19951 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19952 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19953 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19954 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19955 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19956
19957 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19958 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19959 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19960 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19961 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19962 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19963 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19964 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19965 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19966 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19967 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19968 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19969
19970 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19971 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19972 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19973 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19974 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19975 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19976 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19977 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19978 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19979 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19980 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19981 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19982
19983 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19984 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19985 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19986 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19987 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19988 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19989 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19990 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19991 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19992 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19993 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19994 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19995
19996 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19997 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19998 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19999 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20000 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20001 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20002 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20003 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20004 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20005 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20006 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20007 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20008
20009 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20010 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20011 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20012 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20013 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20014 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20015 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20016 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20017 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20018 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20019 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20020 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20021
20022 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20023 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20024 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20025 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20026 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20027 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20028 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20029 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20030 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20031 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20032 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20033 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20034
20035 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20036 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20037 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20038 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20039 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20040 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20041 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20042 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20043 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20044 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20045 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20046 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20047
20048 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20049 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20050 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20051 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20052 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20053 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20054 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20055 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20056 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20057 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20058 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20059 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20060
20061 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20062 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20063 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20064 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20065 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20066 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20067 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20068 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20069 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20070 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20071 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20072 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20073
20074 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20075 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20076 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20077 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20078 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20079 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20080 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20081 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20082 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20083 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20084 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20085 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20086
20087 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20088 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20089 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20090 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20091 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20092 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20093 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20094 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20095 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20096 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20097 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20098 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20099
20100 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20101 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20102 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20103 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20104
20105 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20106 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20107 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20108 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20109 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20110 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20111 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20112 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20113 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20114 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20115 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20116 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20117
c19d1205
ZW
20118 /* The implementation of the FIX instruction is broken on some
20119 assemblers, in that it accepts a precision specifier as well as a
20120 rounding specifier, despite the fact that this is meaningless.
20121 To be more compatible, we accept it as well, though of course it
20122 does not set any bits. */
21d799b5
NC
20123 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20124 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20125 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20126 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20127 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20128 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20129 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20130 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20131 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20132 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20133 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20134 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20135 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20136
c19d1205 20137 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20138#undef ARM_VARIANT
20139#define ARM_VARIANT & fpu_fpa_ext_v2
20140
21d799b5
NC
20141 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20142 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20143 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20144 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20145 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20146 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20147
c921be7d
NC
20148#undef ARM_VARIANT
20149#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20150
c19d1205 20151 /* Moves and type conversions. */
21d799b5
NC
20152 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20153 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20154 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20155 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20156 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20157 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20158 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20159 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20160 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20161 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20162 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20163 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20164 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20165 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20166
20167 /* Memory operations. */
21d799b5
NC
20168 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20169 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20170 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20171 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20172 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20173 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20174 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20175 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20176 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20177 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20178 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20179 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20180 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20181 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20182 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20183 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20184 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20185 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20186
c19d1205 20187 /* Monadic operations. */
21d799b5
NC
20188 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20189 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20190 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20191
20192 /* Dyadic operations. */
21d799b5
NC
20193 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20194 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20195 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20196 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20197 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20198 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20199 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20200 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20201 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20202
c19d1205 20203 /* Comparisons. */
21d799b5
NC
20204 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20205 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20206 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20207 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20208
62f3b8c8
PB
20209 /* Double precision load/store are still present on single precision
20210 implementations. */
20211 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20212 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20213 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20214 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20215 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20216 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20217 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20218 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20219 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20220 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20221
c921be7d
NC
20222#undef ARM_VARIANT
20223#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20224
c19d1205 20225 /* Moves and type conversions. */
21d799b5
NC
20226 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20227 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20228 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20229 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20230 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20231 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20232 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20233 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20234 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20235 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20236 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20237 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20238 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20239
c19d1205 20240 /* Monadic operations. */
21d799b5
NC
20241 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20242 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20243 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20244
20245 /* Dyadic operations. */
21d799b5
NC
20246 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20247 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20248 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20249 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20250 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20251 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20252 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20253 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20254 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20255
c19d1205 20256 /* Comparisons. */
21d799b5
NC
20257 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20258 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20259 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20260 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20261
c921be7d
NC
20262#undef ARM_VARIANT
20263#define ARM_VARIANT & fpu_vfp_ext_v2
20264
21d799b5
NC
20265 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20266 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20267 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20268 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20269
037e8744
JB
20270/* Instructions which may belong to either the Neon or VFP instruction sets.
20271 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20272#undef ARM_VARIANT
20273#define ARM_VARIANT & fpu_vfp_ext_v1xd
20274#undef THUMB_VARIANT
20275#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20276
037e8744
JB
20277 /* These mnemonics are unique to VFP. */
20278 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20279 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20280 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20281 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20282 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20283 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20284 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20285 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20286 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20287 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20288
20289 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20290 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20291 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20292 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20293
21d799b5
NC
20294 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20295 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20296
20297 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20298 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20299
55881a11
MGD
20300 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20301 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20302 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20303 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20304 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20305 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20306 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20307 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20308
5f1af56b 20309 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20310 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20311 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20312 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20313
037e8744
JB
20314
20315 /* NOTE: All VMOV encoding is special-cased! */
20316 NCE(vmov, 0, 1, (VMOV), neon_mov),
20317 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20318
9db2f6b4
RL
20319#undef ARM_VARIANT
20320#define ARM_VARIANT & arm_ext_fp16
20321#undef THUMB_VARIANT
20322#define THUMB_VARIANT & arm_ext_fp16
20323 /* New instructions added from v8.2, allowing the extraction and insertion of
20324 the upper 16 bits of a 32-bit vector register. */
20325 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20326 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20327
c921be7d
NC
20328#undef THUMB_VARIANT
20329#define THUMB_VARIANT & fpu_neon_ext_v1
20330#undef ARM_VARIANT
20331#define ARM_VARIANT & fpu_neon_ext_v1
20332
5287ad62
JB
20333 /* Data processing with three registers of the same length. */
20334 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20335 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20336 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20337 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20338 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20339 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20340 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20341 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20342 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20343 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20344 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20345 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20346 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20347 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20348 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20349 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20350 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20351 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20352 /* If not immediate, fall back to neon_dyadic_i64_su.
20353 shl_imm should accept I8 I16 I32 I64,
20354 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20355 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20356 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20357 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20358 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20359 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20360 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20361 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20362 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20363 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20364 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20365 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20366 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20367 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20368 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20369 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20370 /* Bitfield ops, untyped. */
20371 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20372 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20373 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20374 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20375 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20376 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20377 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20378 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20379 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20380 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20381 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20382 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20383 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20384 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20385 back to neon_dyadic_if_su. */
21d799b5
NC
20386 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20387 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20388 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20389 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20390 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20391 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20392 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20393 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20394 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20395 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20396 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20397 /* As above, D registers only. */
21d799b5
NC
20398 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20399 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20400 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20401 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20402 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20403 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20404 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20405 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20406 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20407 /* vtst takes sizes 8, 16, 32. */
20408 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20409 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20410 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20411 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20412 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20413 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20414 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20415 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20416 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20417 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20418 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20419 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20420 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20421 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20422 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20423 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20424 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20425 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20426 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20427 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20428 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20429 /* ARM v8.1 extension. */
643afb90
MW
20430 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20431 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20432 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20433 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20434
20435 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20436 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20437 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20438
20439 /* Data processing with two registers and a shift amount. */
20440 /* Right shifts, and variants with rounding.
20441 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20442 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20443 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20444 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20445 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20446 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20447 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20448 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20449 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20450 /* Shift and insert. Sizes accepted 8 16 32 64. */
20451 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20452 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20453 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20454 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20455 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20456 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20457 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20458 /* Right shift immediate, saturating & narrowing, with rounding variants.
20459 Types accepted S16 S32 S64 U16 U32 U64. */
20460 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20461 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20462 /* As above, unsigned. Types accepted S16 S32 S64. */
20463 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20464 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20465 /* Right shift narrowing. Types accepted I16 I32 I64. */
20466 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20467 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20468 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20469 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20470 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20471 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20472
4316f0d2
DG
20473 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20474 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20475
20476 /* Data processing, three registers of different lengths. */
20477 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20478 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20479 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20480 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20481 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20482 /* If not scalar, fall back to neon_dyadic_long.
20483 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20484 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20485 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20486 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20487 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20488 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20489 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20490 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20491 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20492 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20493 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20494 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20495 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20496 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20497 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20498 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20499 S16 S32 U16 U32. */
21d799b5 20500 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20501
20502 /* Extract. Size 8. */
3b8d421e
PB
20503 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20504 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20505
20506 /* Two registers, miscellaneous. */
20507 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20508 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20509 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20510 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20511 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20512 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20513 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20514 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20515 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20516 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20517 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20518 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20519 /* VMOVN. Types I16 I32 I64. */
21d799b5 20520 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20521 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20522 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20523 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20524 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20525 /* VZIP / VUZP. Sizes 8 16 32. */
20526 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20527 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20528 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20529 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20530 /* VQABS / VQNEG. Types S8 S16 S32. */
20531 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20532 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20533 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20534 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20535 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20536 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20537 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20538 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20539 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20540 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20541 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20542 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20543 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20544 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20545 /* VCLS. Types S8 S16 S32. */
20546 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20547 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20548 /* VCLZ. Types I8 I16 I32. */
20549 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20550 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20551 /* VCNT. Size 8. */
20552 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20553 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20554 /* Two address, untyped. */
20555 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20556 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20557 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20558 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20559 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20560
20561 /* Table lookup. Size 8. */
20562 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20563 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20564
c921be7d
NC
20565#undef THUMB_VARIANT
20566#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20567#undef ARM_VARIANT
20568#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20569
5287ad62 20570 /* Neon element/structure load/store. */
21d799b5
NC
20571 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20572 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20573 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20574 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20575 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20576 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20577 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20578 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20579
c921be7d 20580#undef THUMB_VARIANT
74db7efb
NC
20581#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20582#undef ARM_VARIANT
20583#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20584 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20585 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20586 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20587 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20588 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20589 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20590 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20591 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20592 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20593
74db7efb 20594#undef THUMB_VARIANT
c921be7d
NC
20595#define THUMB_VARIANT & fpu_vfp_ext_v3
20596#undef ARM_VARIANT
20597#define ARM_VARIANT & fpu_vfp_ext_v3
20598
21d799b5 20599 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20600 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20601 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20602 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20603 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20604 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20605 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20606 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20607 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20608
74db7efb
NC
20609#undef ARM_VARIANT
20610#define ARM_VARIANT & fpu_vfp_ext_fma
20611#undef THUMB_VARIANT
20612#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20613 /* Mnemonics shared by Neon and VFP. These are included in the
20614 VFP FMA variant; NEON and VFP FMA always includes the NEON
20615 FMA instructions. */
20616 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20617 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20618 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20619 the v form should always be used. */
20620 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20621 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20622 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20623 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20624 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20625 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20626
5287ad62 20627#undef THUMB_VARIANT
c921be7d
NC
20628#undef ARM_VARIANT
20629#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20630
21d799b5
NC
20631 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20632 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20633 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20634 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20635 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20636 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20637 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20638 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20639
c921be7d
NC
20640#undef ARM_VARIANT
20641#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20642
21d799b5
NC
20643 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20644 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20645 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20646 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20647 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20648 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20649 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20650 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20651 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20652 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20653 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20654 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20655 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20656 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20657 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20658 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20659 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20660 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20661 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20662 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20663 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20664 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20665 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20666 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20667 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20668 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20669 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20670 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20671 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20672 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20673 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20674 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20675 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20676 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20677 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20678 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20679 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20680 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20681 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20682 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20683 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20684 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20685 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20686 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20687 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20688 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20689 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20690 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20691 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20692 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20693 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20694 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20695 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20696 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20697 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20698 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20699 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20700 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20701 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20702 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20703 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20704 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20705 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20706 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20707 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20708 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20709 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20710 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20711 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20712 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20713 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20714 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20715 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20716 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20717 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20718 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20719 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20720 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20721 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20722 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20723 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20724 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20725 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20726 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20727 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20728 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20729 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20730 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20731 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20732 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20733 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20734 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20735 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20736 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20737 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20738 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20739 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20740 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20741 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20742 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20743 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20744 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20745 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20746 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20747 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20748 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20749 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20750 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20751 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20752 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20753 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20754 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20755 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20756 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20757 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20758 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20759 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20760 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20761 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20762 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20763 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20764 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20765 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20766 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20767 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20768 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20769 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20770 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20771 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20772 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20773 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20774 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20775 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20776 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20777 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20778 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20779 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20780 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20781 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20782 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20783 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20784 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20785 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20786 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20787 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20788 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20789 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20790 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20791 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20792 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20793 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20794 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20795 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20796 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20797 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20798 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20799 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20800 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20801 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20802 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20803 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20804 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20805
c921be7d
NC
20806#undef ARM_VARIANT
20807#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20808
21d799b5
NC
20809 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20810 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20811 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20812 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20813 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20814 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20815 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20816 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20817 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20818 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20819 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20820 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20821 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20822 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20823 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20824 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20825 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20826 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20827 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20828 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20829 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20830 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20831 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20832 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20833 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20834 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20835 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20836 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20837 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20838 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20839 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20840 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20841 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20842 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20843 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20844 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20845 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20846 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20847 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20848 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20849 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20850 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20851 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20852 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20853 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20854 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20855 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20856 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20857 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20858 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20859 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20860 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20861 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20862 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20863 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20864 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20865 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20866
c921be7d
NC
20867#undef ARM_VARIANT
20868#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20869
21d799b5
NC
20870 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20871 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20872 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20873 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20874 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20875 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20876 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20877 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20878 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20879 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20880 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20881 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20882 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20883 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20884 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20885 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20886 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20887 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20888 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20889 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20890 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20891 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20892 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20893 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20894 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20895 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20896 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20897 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20898 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20899 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20900 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20901 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20902 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20903 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20904 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20905 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20906 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20907 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20908 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20909 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20910 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20911 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20912 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20913 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20914 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20915 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20916 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20917 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20918 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20919 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20920 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20921 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20922 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20923 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20924 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20925 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20926 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20927 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20928 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20929 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20930 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20931 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20932 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20933 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20934 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20935 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20936 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20937 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20938 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20939 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20940 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20941 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20942 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20943 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20944 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20945 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d
TP
20946
20947#undef ARM_VARIANT
20948#define ARM_VARIANT NULL
20949#undef THUMB_VARIANT
20950#define THUMB_VARIANT & arm_ext_v8m
20951 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
20952 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
c19d1205
ZW
20953};
20954#undef ARM_VARIANT
20955#undef THUMB_VARIANT
20956#undef TCE
c19d1205
ZW
20957#undef TUE
20958#undef TUF
20959#undef TCC
8f06b2d8 20960#undef cCE
e3cb604e
PB
20961#undef cCL
20962#undef C3E
c19d1205
ZW
20963#undef CE
20964#undef CM
20965#undef UE
20966#undef UF
20967#undef UT
5287ad62
JB
20968#undef NUF
20969#undef nUF
20970#undef NCE
20971#undef nCE
c19d1205
ZW
20972#undef OPS0
20973#undef OPS1
20974#undef OPS2
20975#undef OPS3
20976#undef OPS4
20977#undef OPS5
20978#undef OPS6
20979#undef do_0
20980\f
20981/* MD interface: bits in the object file. */
bfae80f2 20982
c19d1205
ZW
20983/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20984 for use in the a.out file, and stores them in the array pointed to by buf.
20985 This knows about the endian-ness of the target machine and does
20986 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20987 2 (short) and 4 (long) Floating numbers are put out as a series of
20988 LITTLENUMS (shorts, here at least). */
b99bd4ef 20989
c19d1205
ZW
20990void
20991md_number_to_chars (char * buf, valueT val, int n)
20992{
20993 if (target_big_endian)
20994 number_to_chars_bigendian (buf, val, n);
20995 else
20996 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20997}
20998
c19d1205
ZW
20999static valueT
21000md_chars_to_number (char * buf, int n)
bfae80f2 21001{
c19d1205
ZW
21002 valueT result = 0;
21003 unsigned char * where = (unsigned char *) buf;
bfae80f2 21004
c19d1205 21005 if (target_big_endian)
b99bd4ef 21006 {
c19d1205
ZW
21007 while (n--)
21008 {
21009 result <<= 8;
21010 result |= (*where++ & 255);
21011 }
b99bd4ef 21012 }
c19d1205 21013 else
b99bd4ef 21014 {
c19d1205
ZW
21015 while (n--)
21016 {
21017 result <<= 8;
21018 result |= (where[n] & 255);
21019 }
bfae80f2 21020 }
b99bd4ef 21021
c19d1205 21022 return result;
bfae80f2 21023}
b99bd4ef 21024
c19d1205 21025/* MD interface: Sections. */
b99bd4ef 21026
fa94de6b
RM
21027/* Calculate the maximum variable size (i.e., excluding fr_fix)
21028 that an rs_machine_dependent frag may reach. */
21029
21030unsigned int
21031arm_frag_max_var (fragS *fragp)
21032{
21033 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21034 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21035
21036 Note that we generate relaxable instructions even for cases that don't
21037 really need it, like an immediate that's a trivial constant. So we're
21038 overestimating the instruction size for some of those cases. Rather
21039 than putting more intelligence here, it would probably be better to
21040 avoid generating a relaxation frag in the first place when it can be
21041 determined up front that a short instruction will suffice. */
21042
21043 gas_assert (fragp->fr_type == rs_machine_dependent);
21044 return INSN_SIZE;
21045}
21046
0110f2b8
PB
21047/* Estimate the size of a frag before relaxing. Assume everything fits in
21048 2 bytes. */
21049
c19d1205 21050int
0110f2b8 21051md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21052 segT segtype ATTRIBUTE_UNUSED)
21053{
0110f2b8
PB
21054 fragp->fr_var = 2;
21055 return 2;
21056}
21057
21058/* Convert a machine dependent frag. */
21059
21060void
21061md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21062{
21063 unsigned long insn;
21064 unsigned long old_op;
21065 char *buf;
21066 expressionS exp;
21067 fixS *fixp;
21068 int reloc_type;
21069 int pc_rel;
21070 int opcode;
21071
21072 buf = fragp->fr_literal + fragp->fr_fix;
21073
21074 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21075 if (fragp->fr_symbol)
21076 {
0110f2b8
PB
21077 exp.X_op = O_symbol;
21078 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21079 }
21080 else
21081 {
0110f2b8 21082 exp.X_op = O_constant;
5f4273c7 21083 }
0110f2b8
PB
21084 exp.X_add_number = fragp->fr_offset;
21085 opcode = fragp->fr_subtype;
21086 switch (opcode)
21087 {
21088 case T_MNEM_ldr_pc:
21089 case T_MNEM_ldr_pc2:
21090 case T_MNEM_ldr_sp:
21091 case T_MNEM_str_sp:
21092 case T_MNEM_ldr:
21093 case T_MNEM_ldrb:
21094 case T_MNEM_ldrh:
21095 case T_MNEM_str:
21096 case T_MNEM_strb:
21097 case T_MNEM_strh:
21098 if (fragp->fr_var == 4)
21099 {
5f4273c7 21100 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21101 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21102 {
21103 insn |= (old_op & 0x700) << 4;
21104 }
21105 else
21106 {
21107 insn |= (old_op & 7) << 12;
21108 insn |= (old_op & 0x38) << 13;
21109 }
21110 insn |= 0x00000c00;
21111 put_thumb32_insn (buf, insn);
21112 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21113 }
21114 else
21115 {
21116 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21117 }
21118 pc_rel = (opcode == T_MNEM_ldr_pc2);
21119 break;
21120 case T_MNEM_adr:
21121 if (fragp->fr_var == 4)
21122 {
21123 insn = THUMB_OP32 (opcode);
21124 insn |= (old_op & 0xf0) << 4;
21125 put_thumb32_insn (buf, insn);
21126 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21127 }
21128 else
21129 {
21130 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21131 exp.X_add_number -= 4;
21132 }
21133 pc_rel = 1;
21134 break;
21135 case T_MNEM_mov:
21136 case T_MNEM_movs:
21137 case T_MNEM_cmp:
21138 case T_MNEM_cmn:
21139 if (fragp->fr_var == 4)
21140 {
21141 int r0off = (opcode == T_MNEM_mov
21142 || opcode == T_MNEM_movs) ? 0 : 8;
21143 insn = THUMB_OP32 (opcode);
21144 insn = (insn & 0xe1ffffff) | 0x10000000;
21145 insn |= (old_op & 0x700) << r0off;
21146 put_thumb32_insn (buf, insn);
21147 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21148 }
21149 else
21150 {
21151 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21152 }
21153 pc_rel = 0;
21154 break;
21155 case T_MNEM_b:
21156 if (fragp->fr_var == 4)
21157 {
21158 insn = THUMB_OP32(opcode);
21159 put_thumb32_insn (buf, insn);
21160 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21161 }
21162 else
21163 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21164 pc_rel = 1;
21165 break;
21166 case T_MNEM_bcond:
21167 if (fragp->fr_var == 4)
21168 {
21169 insn = THUMB_OP32(opcode);
21170 insn |= (old_op & 0xf00) << 14;
21171 put_thumb32_insn (buf, insn);
21172 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21173 }
21174 else
21175 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21176 pc_rel = 1;
21177 break;
21178 case T_MNEM_add_sp:
21179 case T_MNEM_add_pc:
21180 case T_MNEM_inc_sp:
21181 case T_MNEM_dec_sp:
21182 if (fragp->fr_var == 4)
21183 {
21184 /* ??? Choose between add and addw. */
21185 insn = THUMB_OP32 (opcode);
21186 insn |= (old_op & 0xf0) << 4;
21187 put_thumb32_insn (buf, insn);
16805f35
PB
21188 if (opcode == T_MNEM_add_pc)
21189 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21190 else
21191 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21192 }
21193 else
21194 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21195 pc_rel = 0;
21196 break;
21197
21198 case T_MNEM_addi:
21199 case T_MNEM_addis:
21200 case T_MNEM_subi:
21201 case T_MNEM_subis:
21202 if (fragp->fr_var == 4)
21203 {
21204 insn = THUMB_OP32 (opcode);
21205 insn |= (old_op & 0xf0) << 4;
21206 insn |= (old_op & 0xf) << 16;
21207 put_thumb32_insn (buf, insn);
16805f35
PB
21208 if (insn & (1 << 20))
21209 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21210 else
21211 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21212 }
21213 else
21214 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21215 pc_rel = 0;
21216 break;
21217 default:
5f4273c7 21218 abort ();
0110f2b8
PB
21219 }
21220 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21221 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21222 fixp->fx_file = fragp->fr_file;
21223 fixp->fx_line = fragp->fr_line;
21224 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21225
21226 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21227 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21228 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21229 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21230}
21231
21232/* Return the size of a relaxable immediate operand instruction.
21233 SHIFT and SIZE specify the form of the allowable immediate. */
21234static int
21235relax_immediate (fragS *fragp, int size, int shift)
21236{
21237 offsetT offset;
21238 offsetT mask;
21239 offsetT low;
21240
21241 /* ??? Should be able to do better than this. */
21242 if (fragp->fr_symbol)
21243 return 4;
21244
21245 low = (1 << shift) - 1;
21246 mask = (1 << (shift + size)) - (1 << shift);
21247 offset = fragp->fr_offset;
21248 /* Force misaligned offsets to 32-bit variant. */
21249 if (offset & low)
5e77afaa 21250 return 4;
0110f2b8
PB
21251 if (offset & ~mask)
21252 return 4;
21253 return 2;
21254}
21255
5e77afaa
PB
21256/* Get the address of a symbol during relaxation. */
21257static addressT
5f4273c7 21258relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21259{
21260 fragS *sym_frag;
21261 addressT addr;
21262 symbolS *sym;
21263
21264 sym = fragp->fr_symbol;
21265 sym_frag = symbol_get_frag (sym);
21266 know (S_GET_SEGMENT (sym) != absolute_section
21267 || sym_frag == &zero_address_frag);
21268 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21269
21270 /* If frag has yet to be reached on this pass, assume it will
21271 move by STRETCH just as we did. If this is not so, it will
21272 be because some frag between grows, and that will force
21273 another pass. */
21274
21275 if (stretch != 0
21276 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21277 {
21278 fragS *f;
21279
21280 /* Adjust stretch for any alignment frag. Note that if have
21281 been expanding the earlier code, the symbol may be
21282 defined in what appears to be an earlier frag. FIXME:
21283 This doesn't handle the fr_subtype field, which specifies
21284 a maximum number of bytes to skip when doing an
21285 alignment. */
21286 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21287 {
21288 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21289 {
21290 if (stretch < 0)
21291 stretch = - ((- stretch)
21292 & ~ ((1 << (int) f->fr_offset) - 1));
21293 else
21294 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21295 if (stretch == 0)
21296 break;
21297 }
21298 }
21299 if (f != NULL)
21300 addr += stretch;
21301 }
5e77afaa
PB
21302
21303 return addr;
21304}
21305
0110f2b8
PB
21306/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21307 load. */
21308static int
5e77afaa 21309relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21310{
21311 addressT addr;
21312 offsetT val;
21313
21314 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21315 if (fragp->fr_symbol == NULL
21316 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21317 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21318 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21319 return 4;
21320
5f4273c7 21321 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21322 addr = fragp->fr_address + fragp->fr_fix;
21323 addr = (addr + 4) & ~3;
5e77afaa 21324 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21325 if (val & 3)
5e77afaa 21326 return 4;
0110f2b8
PB
21327 val -= addr;
21328 if (val < 0 || val > 1020)
21329 return 4;
21330 return 2;
21331}
21332
21333/* Return the size of a relaxable add/sub immediate instruction. */
21334static int
21335relax_addsub (fragS *fragp, asection *sec)
21336{
21337 char *buf;
21338 int op;
21339
21340 buf = fragp->fr_literal + fragp->fr_fix;
21341 op = bfd_get_16(sec->owner, buf);
21342 if ((op & 0xf) == ((op >> 4) & 0xf))
21343 return relax_immediate (fragp, 8, 0);
21344 else
21345 return relax_immediate (fragp, 3, 0);
21346}
21347
e83a675f
RE
21348/* Return TRUE iff the definition of symbol S could be pre-empted
21349 (overridden) at link or load time. */
21350static bfd_boolean
21351symbol_preemptible (symbolS *s)
21352{
21353 /* Weak symbols can always be pre-empted. */
21354 if (S_IS_WEAK (s))
21355 return TRUE;
21356
21357 /* Non-global symbols cannot be pre-empted. */
21358 if (! S_IS_EXTERNAL (s))
21359 return FALSE;
21360
21361#ifdef OBJ_ELF
21362 /* In ELF, a global symbol can be marked protected, or private. In that
21363 case it can't be pre-empted (other definitions in the same link unit
21364 would violate the ODR). */
21365 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21366 return FALSE;
21367#endif
21368
21369 /* Other global symbols might be pre-empted. */
21370 return TRUE;
21371}
0110f2b8
PB
21372
21373/* Return the size of a relaxable branch instruction. BITS is the
21374 size of the offset field in the narrow instruction. */
21375
21376static int
5e77afaa 21377relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21378{
21379 addressT addr;
21380 offsetT val;
21381 offsetT limit;
21382
21383 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21384 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21385 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21386 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21387 return 4;
21388
267bf995 21389#ifdef OBJ_ELF
e83a675f 21390 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21391 if (S_IS_DEFINED (fragp->fr_symbol)
21392 && ARM_IS_FUNC (fragp->fr_symbol))
21393 return 4;
e83a675f 21394#endif
0d9b4b55 21395
e83a675f 21396 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21397 return 4;
267bf995 21398
5f4273c7 21399 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21400 addr = fragp->fr_address + fragp->fr_fix + 4;
21401 val -= addr;
21402
21403 /* Offset is a signed value *2 */
21404 limit = 1 << bits;
21405 if (val >= limit || val < -limit)
21406 return 4;
21407 return 2;
21408}
21409
21410
21411/* Relax a machine dependent frag. This returns the amount by which
21412 the current size of the frag should change. */
21413
21414int
5e77afaa 21415arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21416{
21417 int oldsize;
21418 int newsize;
21419
21420 oldsize = fragp->fr_var;
21421 switch (fragp->fr_subtype)
21422 {
21423 case T_MNEM_ldr_pc2:
5f4273c7 21424 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21425 break;
21426 case T_MNEM_ldr_pc:
21427 case T_MNEM_ldr_sp:
21428 case T_MNEM_str_sp:
5f4273c7 21429 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21430 break;
21431 case T_MNEM_ldr:
21432 case T_MNEM_str:
5f4273c7 21433 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21434 break;
21435 case T_MNEM_ldrh:
21436 case T_MNEM_strh:
5f4273c7 21437 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21438 break;
21439 case T_MNEM_ldrb:
21440 case T_MNEM_strb:
5f4273c7 21441 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21442 break;
21443 case T_MNEM_adr:
5f4273c7 21444 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21445 break;
21446 case T_MNEM_mov:
21447 case T_MNEM_movs:
21448 case T_MNEM_cmp:
21449 case T_MNEM_cmn:
5f4273c7 21450 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21451 break;
21452 case T_MNEM_b:
5f4273c7 21453 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21454 break;
21455 case T_MNEM_bcond:
5f4273c7 21456 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21457 break;
21458 case T_MNEM_add_sp:
21459 case T_MNEM_add_pc:
21460 newsize = relax_immediate (fragp, 8, 2);
21461 break;
21462 case T_MNEM_inc_sp:
21463 case T_MNEM_dec_sp:
21464 newsize = relax_immediate (fragp, 7, 2);
21465 break;
21466 case T_MNEM_addi:
21467 case T_MNEM_addis:
21468 case T_MNEM_subi:
21469 case T_MNEM_subis:
21470 newsize = relax_addsub (fragp, sec);
21471 break;
21472 default:
5f4273c7 21473 abort ();
0110f2b8 21474 }
5e77afaa
PB
21475
21476 fragp->fr_var = newsize;
21477 /* Freeze wide instructions that are at or before the same location as
21478 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21479 Don't freeze them unconditionally because targets may be artificially
21480 misaligned by the expansion of preceding frags. */
5e77afaa 21481 if (stretch <= 0 && newsize > 2)
0110f2b8 21482 {
0110f2b8 21483 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21484 frag_wane (fragp);
0110f2b8 21485 }
5e77afaa 21486
0110f2b8 21487 return newsize - oldsize;
c19d1205 21488}
b99bd4ef 21489
c19d1205 21490/* Round up a section size to the appropriate boundary. */
b99bd4ef 21491
c19d1205
ZW
21492valueT
21493md_section_align (segT segment ATTRIBUTE_UNUSED,
21494 valueT size)
21495{
f0927246
NC
21496#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21497 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21498 {
21499 /* For a.out, force the section size to be aligned. If we don't do
21500 this, BFD will align it for us, but it will not write out the
21501 final bytes of the section. This may be a bug in BFD, but it is
21502 easier to fix it here since that is how the other a.out targets
21503 work. */
21504 int align;
21505
21506 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21507 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21508 }
c19d1205 21509#endif
f0927246
NC
21510
21511 return size;
bfae80f2 21512}
b99bd4ef 21513
c19d1205
ZW
21514/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21515 of an rs_align_code fragment. */
21516
21517void
21518arm_handle_align (fragS * fragP)
bfae80f2 21519{
d9235011 21520 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21521 {
21522 { /* ARMv1 */
21523 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21524 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21525 },
21526 { /* ARMv6k */
21527 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21528 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21529 },
21530 };
d9235011 21531 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21532 {
21533 { /* Thumb-1 */
21534 {0xc0, 0x46}, /* LE */
21535 {0x46, 0xc0}, /* BE */
21536 },
21537 { /* Thumb-2 */
21538 {0x00, 0xbf}, /* LE */
21539 {0xbf, 0x00} /* BE */
21540 }
21541 };
d9235011 21542 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21543 { /* Wide Thumb-2 */
21544 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21545 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21546 };
c921be7d 21547
e7495e45 21548 unsigned bytes, fix, noop_size;
c19d1205 21549 char * p;
d9235011
TS
21550 const unsigned char * noop;
21551 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21552#ifdef OBJ_ELF
21553 enum mstate state;
21554#endif
bfae80f2 21555
c19d1205 21556 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21557 return;
21558
c19d1205
ZW
21559 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21560 p = fragP->fr_literal + fragP->fr_fix;
21561 fix = 0;
bfae80f2 21562
c19d1205
ZW
21563 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21564 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21565
cd000bff 21566 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21567
cd000bff 21568 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21569 {
7f78eb34
JW
21570 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21571 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21572 {
21573 narrow_noop = thumb_noop[1][target_big_endian];
21574 noop = wide_thumb_noop[target_big_endian];
21575 }
c19d1205 21576 else
e7495e45
NS
21577 noop = thumb_noop[0][target_big_endian];
21578 noop_size = 2;
cd000bff
DJ
21579#ifdef OBJ_ELF
21580 state = MAP_THUMB;
21581#endif
7ed4c4c5
NC
21582 }
21583 else
21584 {
7f78eb34
JW
21585 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21586 ? selected_cpu : arm_arch_none,
21587 arm_ext_v6k) != 0]
e7495e45
NS
21588 [target_big_endian];
21589 noop_size = 4;
cd000bff
DJ
21590#ifdef OBJ_ELF
21591 state = MAP_ARM;
21592#endif
7ed4c4c5 21593 }
c921be7d 21594
e7495e45 21595 fragP->fr_var = noop_size;
c921be7d 21596
c19d1205 21597 if (bytes & (noop_size - 1))
7ed4c4c5 21598 {
c19d1205 21599 fix = bytes & (noop_size - 1);
cd000bff
DJ
21600#ifdef OBJ_ELF
21601 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21602#endif
c19d1205
ZW
21603 memset (p, 0, fix);
21604 p += fix;
21605 bytes -= fix;
a737bd4d 21606 }
a737bd4d 21607
e7495e45
NS
21608 if (narrow_noop)
21609 {
21610 if (bytes & noop_size)
21611 {
21612 /* Insert a narrow noop. */
21613 memcpy (p, narrow_noop, noop_size);
21614 p += noop_size;
21615 bytes -= noop_size;
21616 fix += noop_size;
21617 }
21618
21619 /* Use wide noops for the remainder */
21620 noop_size = 4;
21621 }
21622
c19d1205 21623 while (bytes >= noop_size)
a737bd4d 21624 {
c19d1205
ZW
21625 memcpy (p, noop, noop_size);
21626 p += noop_size;
21627 bytes -= noop_size;
21628 fix += noop_size;
a737bd4d
NC
21629 }
21630
c19d1205 21631 fragP->fr_fix += fix;
a737bd4d
NC
21632}
21633
c19d1205
ZW
21634/* Called from md_do_align. Used to create an alignment
21635 frag in a code section. */
21636
21637void
21638arm_frag_align_code (int n, int max)
bfae80f2 21639{
c19d1205 21640 char * p;
7ed4c4c5 21641
c19d1205 21642 /* We assume that there will never be a requirement
6ec8e702 21643 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21644 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21645 {
21646 char err_msg[128];
21647
fa94de6b 21648 sprintf (err_msg,
477330fc
RM
21649 _("alignments greater than %d bytes not supported in .text sections."),
21650 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21651 as_fatal ("%s", err_msg);
6ec8e702 21652 }
bfae80f2 21653
c19d1205
ZW
21654 p = frag_var (rs_align_code,
21655 MAX_MEM_FOR_RS_ALIGN_CODE,
21656 1,
21657 (relax_substateT) max,
21658 (symbolS *) NULL,
21659 (offsetT) n,
21660 (char *) NULL);
21661 *p = 0;
21662}
bfae80f2 21663
8dc2430f
NC
21664/* Perform target specific initialisation of a frag.
21665 Note - despite the name this initialisation is not done when the frag
21666 is created, but only when its type is assigned. A frag can be created
21667 and used a long time before its type is set, so beware of assuming that
21668 this initialisationis performed first. */
bfae80f2 21669
cd000bff
DJ
21670#ifndef OBJ_ELF
21671void
21672arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21673{
21674 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21675 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21676}
21677
21678#else /* OBJ_ELF is defined. */
c19d1205 21679void
cd000bff 21680arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21681{
b968d18a
JW
21682 int frag_thumb_mode;
21683
8dc2430f
NC
21684 /* If the current ARM vs THUMB mode has not already
21685 been recorded into this frag then do so now. */
cd000bff 21686 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21687 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21688
21689 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21690
f9c1b181
RL
21691 /* Record a mapping symbol for alignment frags. We will delete this
21692 later if the alignment ends up empty. */
21693 switch (fragP->fr_type)
21694 {
21695 case rs_align:
21696 case rs_align_test:
21697 case rs_fill:
21698 mapping_state_2 (MAP_DATA, max_chars);
21699 break;
21700 case rs_align_code:
b968d18a 21701 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21702 break;
21703 default:
21704 break;
cd000bff 21705 }
bfae80f2
RE
21706}
21707
c19d1205
ZW
21708/* When we change sections we need to issue a new mapping symbol. */
21709
21710void
21711arm_elf_change_section (void)
bfae80f2 21712{
c19d1205
ZW
21713 /* Link an unlinked unwind index table section to the .text section. */
21714 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21715 && elf_linked_to_section (now_seg) == NULL)
21716 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21717}
21718
c19d1205
ZW
21719int
21720arm_elf_section_type (const char * str, size_t len)
e45d0630 21721{
c19d1205
ZW
21722 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21723 return SHT_ARM_EXIDX;
e45d0630 21724
c19d1205
ZW
21725 return -1;
21726}
21727\f
21728/* Code to deal with unwinding tables. */
e45d0630 21729
c19d1205 21730static void add_unwind_adjustsp (offsetT);
e45d0630 21731
5f4273c7 21732/* Generate any deferred unwind frame offset. */
e45d0630 21733
bfae80f2 21734static void
c19d1205 21735flush_pending_unwind (void)
bfae80f2 21736{
c19d1205 21737 offsetT offset;
bfae80f2 21738
c19d1205
ZW
21739 offset = unwind.pending_offset;
21740 unwind.pending_offset = 0;
21741 if (offset != 0)
21742 add_unwind_adjustsp (offset);
bfae80f2
RE
21743}
21744
c19d1205
ZW
21745/* Add an opcode to this list for this function. Two-byte opcodes should
21746 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21747 order. */
21748
bfae80f2 21749static void
c19d1205 21750add_unwind_opcode (valueT op, int length)
bfae80f2 21751{
c19d1205
ZW
21752 /* Add any deferred stack adjustment. */
21753 if (unwind.pending_offset)
21754 flush_pending_unwind ();
bfae80f2 21755
c19d1205 21756 unwind.sp_restored = 0;
bfae80f2 21757
c19d1205 21758 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21759 {
c19d1205
ZW
21760 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21761 if (unwind.opcodes)
325801bd
TS
21762 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21763 unwind.opcode_alloc);
c19d1205 21764 else
325801bd 21765 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21766 }
c19d1205 21767 while (length > 0)
bfae80f2 21768 {
c19d1205
ZW
21769 length--;
21770 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21771 op >>= 8;
21772 unwind.opcode_count++;
bfae80f2 21773 }
bfae80f2
RE
21774}
21775
c19d1205
ZW
21776/* Add unwind opcodes to adjust the stack pointer. */
21777
bfae80f2 21778static void
c19d1205 21779add_unwind_adjustsp (offsetT offset)
bfae80f2 21780{
c19d1205 21781 valueT op;
bfae80f2 21782
c19d1205 21783 if (offset > 0x200)
bfae80f2 21784 {
c19d1205
ZW
21785 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21786 char bytes[5];
21787 int n;
21788 valueT o;
bfae80f2 21789
c19d1205
ZW
21790 /* Long form: 0xb2, uleb128. */
21791 /* This might not fit in a word so add the individual bytes,
21792 remembering the list is built in reverse order. */
21793 o = (valueT) ((offset - 0x204) >> 2);
21794 if (o == 0)
21795 add_unwind_opcode (0, 1);
bfae80f2 21796
c19d1205
ZW
21797 /* Calculate the uleb128 encoding of the offset. */
21798 n = 0;
21799 while (o)
21800 {
21801 bytes[n] = o & 0x7f;
21802 o >>= 7;
21803 if (o)
21804 bytes[n] |= 0x80;
21805 n++;
21806 }
21807 /* Add the insn. */
21808 for (; n; n--)
21809 add_unwind_opcode (bytes[n - 1], 1);
21810 add_unwind_opcode (0xb2, 1);
21811 }
21812 else if (offset > 0x100)
bfae80f2 21813 {
c19d1205
ZW
21814 /* Two short opcodes. */
21815 add_unwind_opcode (0x3f, 1);
21816 op = (offset - 0x104) >> 2;
21817 add_unwind_opcode (op, 1);
bfae80f2 21818 }
c19d1205
ZW
21819 else if (offset > 0)
21820 {
21821 /* Short opcode. */
21822 op = (offset - 4) >> 2;
21823 add_unwind_opcode (op, 1);
21824 }
21825 else if (offset < 0)
bfae80f2 21826 {
c19d1205
ZW
21827 offset = -offset;
21828 while (offset > 0x100)
bfae80f2 21829 {
c19d1205
ZW
21830 add_unwind_opcode (0x7f, 1);
21831 offset -= 0x100;
bfae80f2 21832 }
c19d1205
ZW
21833 op = ((offset - 4) >> 2) | 0x40;
21834 add_unwind_opcode (op, 1);
bfae80f2 21835 }
bfae80f2
RE
21836}
21837
c19d1205
ZW
21838/* Finish the list of unwind opcodes for this function. */
21839static void
21840finish_unwind_opcodes (void)
bfae80f2 21841{
c19d1205 21842 valueT op;
bfae80f2 21843
c19d1205 21844 if (unwind.fp_used)
bfae80f2 21845 {
708587a4 21846 /* Adjust sp as necessary. */
c19d1205
ZW
21847 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21848 flush_pending_unwind ();
bfae80f2 21849
c19d1205
ZW
21850 /* After restoring sp from the frame pointer. */
21851 op = 0x90 | unwind.fp_reg;
21852 add_unwind_opcode (op, 1);
21853 }
21854 else
21855 flush_pending_unwind ();
bfae80f2
RE
21856}
21857
bfae80f2 21858
c19d1205
ZW
21859/* Start an exception table entry. If idx is nonzero this is an index table
21860 entry. */
bfae80f2
RE
21861
21862static void
c19d1205 21863start_unwind_section (const segT text_seg, int idx)
bfae80f2 21864{
c19d1205
ZW
21865 const char * text_name;
21866 const char * prefix;
21867 const char * prefix_once;
21868 const char * group_name;
21869 size_t prefix_len;
21870 size_t text_len;
21871 char * sec_name;
21872 size_t sec_name_len;
21873 int type;
21874 int flags;
21875 int linkonce;
bfae80f2 21876
c19d1205 21877 if (idx)
bfae80f2 21878 {
c19d1205
ZW
21879 prefix = ELF_STRING_ARM_unwind;
21880 prefix_once = ELF_STRING_ARM_unwind_once;
21881 type = SHT_ARM_EXIDX;
bfae80f2 21882 }
c19d1205 21883 else
bfae80f2 21884 {
c19d1205
ZW
21885 prefix = ELF_STRING_ARM_unwind_info;
21886 prefix_once = ELF_STRING_ARM_unwind_info_once;
21887 type = SHT_PROGBITS;
bfae80f2
RE
21888 }
21889
c19d1205
ZW
21890 text_name = segment_name (text_seg);
21891 if (streq (text_name, ".text"))
21892 text_name = "";
21893
21894 if (strncmp (text_name, ".gnu.linkonce.t.",
21895 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21896 {
c19d1205
ZW
21897 prefix = prefix_once;
21898 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21899 }
21900
c19d1205
ZW
21901 prefix_len = strlen (prefix);
21902 text_len = strlen (text_name);
21903 sec_name_len = prefix_len + text_len;
21d799b5 21904 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21905 memcpy (sec_name, prefix, prefix_len);
21906 memcpy (sec_name + prefix_len, text_name, text_len);
21907 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21908
c19d1205
ZW
21909 flags = SHF_ALLOC;
21910 linkonce = 0;
21911 group_name = 0;
bfae80f2 21912
c19d1205
ZW
21913 /* Handle COMDAT group. */
21914 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21915 {
c19d1205
ZW
21916 group_name = elf_group_name (text_seg);
21917 if (group_name == NULL)
21918 {
bd3ba5d1 21919 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21920 segment_name (text_seg));
21921 ignore_rest_of_line ();
21922 return;
21923 }
21924 flags |= SHF_GROUP;
21925 linkonce = 1;
bfae80f2
RE
21926 }
21927
c19d1205 21928 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21929
5f4273c7 21930 /* Set the section link for index tables. */
c19d1205
ZW
21931 if (idx)
21932 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21933}
21934
bfae80f2 21935
c19d1205
ZW
21936/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21937 personality routine data. Returns zero, or the index table value for
cad0da33 21938 an inline entry. */
c19d1205
ZW
21939
21940static valueT
21941create_unwind_entry (int have_data)
bfae80f2 21942{
c19d1205
ZW
21943 int size;
21944 addressT where;
21945 char *ptr;
21946 /* The current word of data. */
21947 valueT data;
21948 /* The number of bytes left in this word. */
21949 int n;
bfae80f2 21950
c19d1205 21951 finish_unwind_opcodes ();
bfae80f2 21952
c19d1205
ZW
21953 /* Remember the current text section. */
21954 unwind.saved_seg = now_seg;
21955 unwind.saved_subseg = now_subseg;
bfae80f2 21956
c19d1205 21957 start_unwind_section (now_seg, 0);
bfae80f2 21958
c19d1205 21959 if (unwind.personality_routine == NULL)
bfae80f2 21960 {
c19d1205
ZW
21961 if (unwind.personality_index == -2)
21962 {
21963 if (have_data)
5f4273c7 21964 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21965 return 1; /* EXIDX_CANTUNWIND. */
21966 }
bfae80f2 21967
c19d1205
ZW
21968 /* Use a default personality routine if none is specified. */
21969 if (unwind.personality_index == -1)
21970 {
21971 if (unwind.opcode_count > 3)
21972 unwind.personality_index = 1;
21973 else
21974 unwind.personality_index = 0;
21975 }
bfae80f2 21976
c19d1205
ZW
21977 /* Space for the personality routine entry. */
21978 if (unwind.personality_index == 0)
21979 {
21980 if (unwind.opcode_count > 3)
21981 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21982
c19d1205
ZW
21983 if (!have_data)
21984 {
21985 /* All the data is inline in the index table. */
21986 data = 0x80;
21987 n = 3;
21988 while (unwind.opcode_count > 0)
21989 {
21990 unwind.opcode_count--;
21991 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21992 n--;
21993 }
bfae80f2 21994
c19d1205
ZW
21995 /* Pad with "finish" opcodes. */
21996 while (n--)
21997 data = (data << 8) | 0xb0;
bfae80f2 21998
c19d1205
ZW
21999 return data;
22000 }
22001 size = 0;
22002 }
22003 else
22004 /* We get two opcodes "free" in the first word. */
22005 size = unwind.opcode_count - 2;
22006 }
22007 else
5011093d 22008 {
cad0da33
NC
22009 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22010 if (unwind.personality_index != -1)
22011 {
22012 as_bad (_("attempt to recreate an unwind entry"));
22013 return 1;
22014 }
5011093d
NC
22015
22016 /* An extra byte is required for the opcode count. */
22017 size = unwind.opcode_count + 1;
22018 }
bfae80f2 22019
c19d1205
ZW
22020 size = (size + 3) >> 2;
22021 if (size > 0xff)
22022 as_bad (_("too many unwind opcodes"));
bfae80f2 22023
c19d1205
ZW
22024 frag_align (2, 0, 0);
22025 record_alignment (now_seg, 2);
22026 unwind.table_entry = expr_build_dot ();
22027
22028 /* Allocate the table entry. */
22029 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22030 /* PR 13449: Zero the table entries in case some of them are not used. */
22031 memset (ptr, 0, (size << 2) + 4);
c19d1205 22032 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22033
c19d1205 22034 switch (unwind.personality_index)
bfae80f2 22035 {
c19d1205
ZW
22036 case -1:
22037 /* ??? Should this be a PLT generating relocation? */
22038 /* Custom personality routine. */
22039 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22040 BFD_RELOC_ARM_PREL31);
bfae80f2 22041
c19d1205
ZW
22042 where += 4;
22043 ptr += 4;
bfae80f2 22044
c19d1205 22045 /* Set the first byte to the number of additional words. */
5011093d 22046 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22047 n = 3;
22048 break;
bfae80f2 22049
c19d1205
ZW
22050 /* ABI defined personality routines. */
22051 case 0:
22052 /* Three opcodes bytes are packed into the first word. */
22053 data = 0x80;
22054 n = 3;
22055 break;
bfae80f2 22056
c19d1205
ZW
22057 case 1:
22058 case 2:
22059 /* The size and first two opcode bytes go in the first word. */
22060 data = ((0x80 + unwind.personality_index) << 8) | size;
22061 n = 2;
22062 break;
bfae80f2 22063
c19d1205
ZW
22064 default:
22065 /* Should never happen. */
22066 abort ();
22067 }
bfae80f2 22068
c19d1205
ZW
22069 /* Pack the opcodes into words (MSB first), reversing the list at the same
22070 time. */
22071 while (unwind.opcode_count > 0)
22072 {
22073 if (n == 0)
22074 {
22075 md_number_to_chars (ptr, data, 4);
22076 ptr += 4;
22077 n = 4;
22078 data = 0;
22079 }
22080 unwind.opcode_count--;
22081 n--;
22082 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22083 }
22084
22085 /* Finish off the last word. */
22086 if (n < 4)
22087 {
22088 /* Pad with "finish" opcodes. */
22089 while (n--)
22090 data = (data << 8) | 0xb0;
22091
22092 md_number_to_chars (ptr, data, 4);
22093 }
22094
22095 if (!have_data)
22096 {
22097 /* Add an empty descriptor if there is no user-specified data. */
22098 ptr = frag_more (4);
22099 md_number_to_chars (ptr, 0, 4);
22100 }
22101
22102 return 0;
bfae80f2
RE
22103}
22104
f0927246
NC
22105
22106/* Initialize the DWARF-2 unwind information for this procedure. */
22107
22108void
22109tc_arm_frame_initial_instructions (void)
22110{
22111 cfi_add_CFA_def_cfa (REG_SP, 0);
22112}
22113#endif /* OBJ_ELF */
22114
c19d1205
ZW
22115/* Convert REGNAME to a DWARF-2 register number. */
22116
22117int
1df69f4f 22118tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22119{
1df69f4f 22120 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22121 if (reg != FAIL)
22122 return reg;
c19d1205 22123
1f5afe1c
NC
22124 /* PR 16694: Allow VFP registers as well. */
22125 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22126 if (reg != FAIL)
22127 return 64 + reg;
c19d1205 22128
1f5afe1c
NC
22129 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22130 if (reg != FAIL)
22131 return reg + 256;
22132
22133 return -1;
bfae80f2
RE
22134}
22135
f0927246 22136#ifdef TE_PE
c19d1205 22137void
f0927246 22138tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22139{
91d6fa6a 22140 expressionS exp;
bfae80f2 22141
91d6fa6a
NC
22142 exp.X_op = O_secrel;
22143 exp.X_add_symbol = symbol;
22144 exp.X_add_number = 0;
22145 emit_expr (&exp, size);
f0927246
NC
22146}
22147#endif
bfae80f2 22148
c19d1205 22149/* MD interface: Symbol and relocation handling. */
bfae80f2 22150
2fc8bdac
ZW
22151/* Return the address within the segment that a PC-relative fixup is
22152 relative to. For ARM, PC-relative fixups applied to instructions
22153 are generally relative to the location of the fixup plus 8 bytes.
22154 Thumb branches are offset by 4, and Thumb loads relative to PC
22155 require special handling. */
bfae80f2 22156
c19d1205 22157long
2fc8bdac 22158md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22159{
2fc8bdac
ZW
22160 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22161
22162 /* If this is pc-relative and we are going to emit a relocation
22163 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22164 will need. Otherwise we want to use the calculated base.
22165 For WinCE we skip the bias for externals as well, since this
22166 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22167 if (fixP->fx_pcrel
2fc8bdac 22168 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22169 || (arm_force_relocation (fixP)
22170#ifdef TE_WINCE
22171 && !S_IS_EXTERNAL (fixP->fx_addsy)
22172#endif
22173 )))
2fc8bdac 22174 base = 0;
bfae80f2 22175
267bf995 22176
c19d1205 22177 switch (fixP->fx_r_type)
bfae80f2 22178 {
2fc8bdac
ZW
22179 /* PC relative addressing on the Thumb is slightly odd as the
22180 bottom two bits of the PC are forced to zero for the
22181 calculation. This happens *after* application of the
22182 pipeline offset. However, Thumb adrl already adjusts for
22183 this, so we need not do it again. */
c19d1205 22184 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22185 return base & ~3;
c19d1205
ZW
22186
22187 case BFD_RELOC_ARM_THUMB_OFFSET:
22188 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22189 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22190 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22191 return (base + 4) & ~3;
c19d1205 22192
2fc8bdac
ZW
22193 /* Thumb branches are simply offset by +4. */
22194 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22195 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22196 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22197 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22198 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22199 return base + 4;
bfae80f2 22200
267bf995 22201 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22202 if (fixP->fx_addsy
22203 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22204 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22205 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22206 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22207 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22208 return base + 4;
22209
00adf2d4
JB
22210 /* BLX is like branches above, but forces the low two bits of PC to
22211 zero. */
486499d0
CL
22212 case BFD_RELOC_THUMB_PCREL_BLX:
22213 if (fixP->fx_addsy
22214 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22215 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22216 && THUMB_IS_FUNC (fixP->fx_addsy)
22217 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22218 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22219 return (base + 4) & ~3;
22220
2fc8bdac
ZW
22221 /* ARM mode branches are offset by +8. However, the Windows CE
22222 loader expects the relocation not to take this into account. */
267bf995 22223 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22224 if (fixP->fx_addsy
22225 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22226 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22227 && ARM_IS_FUNC (fixP->fx_addsy)
22228 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22229 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22230 return base + 8;
267bf995 22231
486499d0
CL
22232 case BFD_RELOC_ARM_PCREL_CALL:
22233 if (fixP->fx_addsy
22234 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22235 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22236 && THUMB_IS_FUNC (fixP->fx_addsy)
22237 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22238 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22239 return base + 8;
267bf995 22240
2fc8bdac 22241 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22242 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22243 case BFD_RELOC_ARM_PLT32:
c19d1205 22244#ifdef TE_WINCE
5f4273c7 22245 /* When handling fixups immediately, because we have already
477330fc 22246 discovered the value of a symbol, or the address of the frag involved
53baae48 22247 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22248 see fixup_segment() in write.c
22249 The S_IS_EXTERNAL test handles the case of global symbols.
22250 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22251 if (fixP->fx_pcrel
22252 && fixP->fx_addsy != NULL
22253 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22254 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22255 return base + 8;
2fc8bdac 22256 return base;
c19d1205 22257#else
2fc8bdac 22258 return base + 8;
c19d1205 22259#endif
2fc8bdac 22260
267bf995 22261
2fc8bdac
ZW
22262 /* ARM mode loads relative to PC are also offset by +8. Unlike
22263 branches, the Windows CE loader *does* expect the relocation
22264 to take this into account. */
22265 case BFD_RELOC_ARM_OFFSET_IMM:
22266 case BFD_RELOC_ARM_OFFSET_IMM8:
22267 case BFD_RELOC_ARM_HWLITERAL:
22268 case BFD_RELOC_ARM_LITERAL:
22269 case BFD_RELOC_ARM_CP_OFF_IMM:
22270 return base + 8;
22271
22272
22273 /* Other PC-relative relocations are un-offset. */
22274 default:
22275 return base;
22276 }
bfae80f2
RE
22277}
22278
8b2d793c
NC
22279static bfd_boolean flag_warn_syms = TRUE;
22280
ae8714c2
NC
22281bfd_boolean
22282arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22283{
8b2d793c
NC
22284 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22285 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22286 does mean that the resulting code might be very confusing to the reader.
22287 Also this warning can be triggered if the user omits an operand before
22288 an immediate address, eg:
22289
22290 LDR =foo
22291
22292 GAS treats this as an assignment of the value of the symbol foo to a
22293 symbol LDR, and so (without this code) it will not issue any kind of
22294 warning or error message.
22295
22296 Note - ARM instructions are case-insensitive but the strings in the hash
22297 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22298 lower case too. */
22299 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22300 {
22301 char * nbuf = strdup (name);
22302 char * p;
22303
22304 for (p = nbuf; *p; p++)
22305 *p = TOLOWER (*p);
22306 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22307 {
22308 static struct hash_control * already_warned = NULL;
22309
22310 if (already_warned == NULL)
22311 already_warned = hash_new ();
22312 /* Only warn about the symbol once. To keep the code
22313 simple we let hash_insert do the lookup for us. */
22314 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22315 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22316 }
22317 else
22318 free (nbuf);
22319 }
3739860c 22320
ae8714c2
NC
22321 return FALSE;
22322}
22323
22324/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22325 Otherwise we have no need to default values of symbols. */
22326
22327symbolS *
22328md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22329{
22330#ifdef OBJ_ELF
22331 if (name[0] == '_' && name[1] == 'G'
22332 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22333 {
22334 if (!GOT_symbol)
22335 {
22336 if (symbol_find (name))
22337 as_bad (_("GOT already in the symbol table"));
22338
22339 GOT_symbol = symbol_new (name, undefined_section,
22340 (valueT) 0, & zero_address_frag);
22341 }
22342
22343 return GOT_symbol;
22344 }
22345#endif
22346
c921be7d 22347 return NULL;
bfae80f2
RE
22348}
22349
55cf6793 22350/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22351 computed as two separate immediate values, added together. We
22352 already know that this value cannot be computed by just one ARM
22353 instruction. */
22354
22355static unsigned int
22356validate_immediate_twopart (unsigned int val,
22357 unsigned int * highpart)
bfae80f2 22358{
c19d1205
ZW
22359 unsigned int a;
22360 unsigned int i;
bfae80f2 22361
c19d1205
ZW
22362 for (i = 0; i < 32; i += 2)
22363 if (((a = rotate_left (val, i)) & 0xff) != 0)
22364 {
22365 if (a & 0xff00)
22366 {
22367 if (a & ~ 0xffff)
22368 continue;
22369 * highpart = (a >> 8) | ((i + 24) << 7);
22370 }
22371 else if (a & 0xff0000)
22372 {
22373 if (a & 0xff000000)
22374 continue;
22375 * highpart = (a >> 16) | ((i + 16) << 7);
22376 }
22377 else
22378 {
9c2799c2 22379 gas_assert (a & 0xff000000);
c19d1205
ZW
22380 * highpart = (a >> 24) | ((i + 8) << 7);
22381 }
bfae80f2 22382
c19d1205
ZW
22383 return (a & 0xff) | (i << 7);
22384 }
bfae80f2 22385
c19d1205 22386 return FAIL;
bfae80f2
RE
22387}
22388
c19d1205
ZW
22389static int
22390validate_offset_imm (unsigned int val, int hwse)
22391{
22392 if ((hwse && val > 255) || val > 4095)
22393 return FAIL;
22394 return val;
22395}
bfae80f2 22396
55cf6793 22397/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22398 negative immediate constant by altering the instruction. A bit of
22399 a hack really.
22400 MOV <-> MVN
22401 AND <-> BIC
22402 ADC <-> SBC
22403 by inverting the second operand, and
22404 ADD <-> SUB
22405 CMP <-> CMN
22406 by negating the second operand. */
bfae80f2 22407
c19d1205
ZW
22408static int
22409negate_data_op (unsigned long * instruction,
22410 unsigned long value)
bfae80f2 22411{
c19d1205
ZW
22412 int op, new_inst;
22413 unsigned long negated, inverted;
bfae80f2 22414
c19d1205
ZW
22415 negated = encode_arm_immediate (-value);
22416 inverted = encode_arm_immediate (~value);
bfae80f2 22417
c19d1205
ZW
22418 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22419 switch (op)
bfae80f2 22420 {
c19d1205
ZW
22421 /* First negates. */
22422 case OPCODE_SUB: /* ADD <-> SUB */
22423 new_inst = OPCODE_ADD;
22424 value = negated;
22425 break;
bfae80f2 22426
c19d1205
ZW
22427 case OPCODE_ADD:
22428 new_inst = OPCODE_SUB;
22429 value = negated;
22430 break;
bfae80f2 22431
c19d1205
ZW
22432 case OPCODE_CMP: /* CMP <-> CMN */
22433 new_inst = OPCODE_CMN;
22434 value = negated;
22435 break;
bfae80f2 22436
c19d1205
ZW
22437 case OPCODE_CMN:
22438 new_inst = OPCODE_CMP;
22439 value = negated;
22440 break;
bfae80f2 22441
c19d1205
ZW
22442 /* Now Inverted ops. */
22443 case OPCODE_MOV: /* MOV <-> MVN */
22444 new_inst = OPCODE_MVN;
22445 value = inverted;
22446 break;
bfae80f2 22447
c19d1205
ZW
22448 case OPCODE_MVN:
22449 new_inst = OPCODE_MOV;
22450 value = inverted;
22451 break;
bfae80f2 22452
c19d1205
ZW
22453 case OPCODE_AND: /* AND <-> BIC */
22454 new_inst = OPCODE_BIC;
22455 value = inverted;
22456 break;
bfae80f2 22457
c19d1205
ZW
22458 case OPCODE_BIC:
22459 new_inst = OPCODE_AND;
22460 value = inverted;
22461 break;
bfae80f2 22462
c19d1205
ZW
22463 case OPCODE_ADC: /* ADC <-> SBC */
22464 new_inst = OPCODE_SBC;
22465 value = inverted;
22466 break;
bfae80f2 22467
c19d1205
ZW
22468 case OPCODE_SBC:
22469 new_inst = OPCODE_ADC;
22470 value = inverted;
22471 break;
bfae80f2 22472
c19d1205
ZW
22473 /* We cannot do anything. */
22474 default:
22475 return FAIL;
b99bd4ef
NC
22476 }
22477
c19d1205
ZW
22478 if (value == (unsigned) FAIL)
22479 return FAIL;
22480
22481 *instruction &= OPCODE_MASK;
22482 *instruction |= new_inst << DATA_OP_SHIFT;
22483 return value;
b99bd4ef
NC
22484}
22485
ef8d22e6
PB
22486/* Like negate_data_op, but for Thumb-2. */
22487
22488static unsigned int
16dd5e42 22489thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22490{
22491 int op, new_inst;
22492 int rd;
16dd5e42 22493 unsigned int negated, inverted;
ef8d22e6
PB
22494
22495 negated = encode_thumb32_immediate (-value);
22496 inverted = encode_thumb32_immediate (~value);
22497
22498 rd = (*instruction >> 8) & 0xf;
22499 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22500 switch (op)
22501 {
22502 /* ADD <-> SUB. Includes CMP <-> CMN. */
22503 case T2_OPCODE_SUB:
22504 new_inst = T2_OPCODE_ADD;
22505 value = negated;
22506 break;
22507
22508 case T2_OPCODE_ADD:
22509 new_inst = T2_OPCODE_SUB;
22510 value = negated;
22511 break;
22512
22513 /* ORR <-> ORN. Includes MOV <-> MVN. */
22514 case T2_OPCODE_ORR:
22515 new_inst = T2_OPCODE_ORN;
22516 value = inverted;
22517 break;
22518
22519 case T2_OPCODE_ORN:
22520 new_inst = T2_OPCODE_ORR;
22521 value = inverted;
22522 break;
22523
22524 /* AND <-> BIC. TST has no inverted equivalent. */
22525 case T2_OPCODE_AND:
22526 new_inst = T2_OPCODE_BIC;
22527 if (rd == 15)
22528 value = FAIL;
22529 else
22530 value = inverted;
22531 break;
22532
22533 case T2_OPCODE_BIC:
22534 new_inst = T2_OPCODE_AND;
22535 value = inverted;
22536 break;
22537
22538 /* ADC <-> SBC */
22539 case T2_OPCODE_ADC:
22540 new_inst = T2_OPCODE_SBC;
22541 value = inverted;
22542 break;
22543
22544 case T2_OPCODE_SBC:
22545 new_inst = T2_OPCODE_ADC;
22546 value = inverted;
22547 break;
22548
22549 /* We cannot do anything. */
22550 default:
22551 return FAIL;
22552 }
22553
16dd5e42 22554 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22555 return FAIL;
22556
22557 *instruction &= T2_OPCODE_MASK;
22558 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22559 return value;
22560}
22561
8f06b2d8
PB
22562/* Read a 32-bit thumb instruction from buf. */
22563static unsigned long
22564get_thumb32_insn (char * buf)
22565{
22566 unsigned long insn;
22567 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22568 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22569
22570 return insn;
22571}
22572
a8bc6c78
PB
22573
22574/* We usually want to set the low bit on the address of thumb function
22575 symbols. In particular .word foo - . should have the low bit set.
22576 Generic code tries to fold the difference of two symbols to
22577 a constant. Prevent this and force a relocation when the first symbols
22578 is a thumb function. */
c921be7d
NC
22579
22580bfd_boolean
a8bc6c78
PB
22581arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22582{
22583 if (op == O_subtract
22584 && l->X_op == O_symbol
22585 && r->X_op == O_symbol
22586 && THUMB_IS_FUNC (l->X_add_symbol))
22587 {
22588 l->X_op = O_subtract;
22589 l->X_op_symbol = r->X_add_symbol;
22590 l->X_add_number -= r->X_add_number;
c921be7d 22591 return TRUE;
a8bc6c78 22592 }
c921be7d 22593
a8bc6c78 22594 /* Process as normal. */
c921be7d 22595 return FALSE;
a8bc6c78
PB
22596}
22597
4a42ebbc
RR
22598/* Encode Thumb2 unconditional branches and calls. The encoding
22599 for the 2 are identical for the immediate values. */
22600
22601static void
22602encode_thumb2_b_bl_offset (char * buf, offsetT value)
22603{
22604#define T2I1I2MASK ((1 << 13) | (1 << 11))
22605 offsetT newval;
22606 offsetT newval2;
22607 addressT S, I1, I2, lo, hi;
22608
22609 S = (value >> 24) & 0x01;
22610 I1 = (value >> 23) & 0x01;
22611 I2 = (value >> 22) & 0x01;
22612 hi = (value >> 12) & 0x3ff;
fa94de6b 22613 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22614 newval = md_chars_to_number (buf, THUMB_SIZE);
22615 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22616 newval |= (S << 10) | hi;
22617 newval2 &= ~T2I1I2MASK;
22618 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22619 md_number_to_chars (buf, newval, THUMB_SIZE);
22620 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22621}
22622
c19d1205 22623void
55cf6793 22624md_apply_fix (fixS * fixP,
c19d1205
ZW
22625 valueT * valP,
22626 segT seg)
22627{
22628 offsetT value = * valP;
22629 offsetT newval;
22630 unsigned int newimm;
22631 unsigned long temp;
22632 int sign;
22633 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22634
9c2799c2 22635 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22636
c19d1205 22637 /* Note whether this will delete the relocation. */
4962c51a 22638
c19d1205
ZW
22639 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22640 fixP->fx_done = 1;
b99bd4ef 22641
adbaf948 22642 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22643 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22644 for emit_reloc. */
22645 value &= 0xffffffff;
22646 value ^= 0x80000000;
5f4273c7 22647 value -= 0x80000000;
adbaf948
ZW
22648
22649 *valP = value;
c19d1205 22650 fixP->fx_addnumber = value;
b99bd4ef 22651
adbaf948
ZW
22652 /* Same treatment for fixP->fx_offset. */
22653 fixP->fx_offset &= 0xffffffff;
22654 fixP->fx_offset ^= 0x80000000;
22655 fixP->fx_offset -= 0x80000000;
22656
c19d1205 22657 switch (fixP->fx_r_type)
b99bd4ef 22658 {
c19d1205
ZW
22659 case BFD_RELOC_NONE:
22660 /* This will need to go in the object file. */
22661 fixP->fx_done = 0;
22662 break;
b99bd4ef 22663
c19d1205
ZW
22664 case BFD_RELOC_ARM_IMMEDIATE:
22665 /* We claim that this fixup has been processed here,
22666 even if in fact we generate an error because we do
22667 not have a reloc for it, so tc_gen_reloc will reject it. */
22668 fixP->fx_done = 1;
b99bd4ef 22669
77db8e2e 22670 if (fixP->fx_addsy)
b99bd4ef 22671 {
77db8e2e 22672 const char *msg = 0;
b99bd4ef 22673
77db8e2e
NC
22674 if (! S_IS_DEFINED (fixP->fx_addsy))
22675 msg = _("undefined symbol %s used as an immediate value");
22676 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22677 msg = _("symbol %s is in a different section");
22678 else if (S_IS_WEAK (fixP->fx_addsy))
22679 msg = _("symbol %s is weak and may be overridden later");
22680
22681 if (msg)
22682 {
22683 as_bad_where (fixP->fx_file, fixP->fx_line,
22684 msg, S_GET_NAME (fixP->fx_addsy));
22685 break;
22686 }
42e5fcbf
AS
22687 }
22688
c19d1205
ZW
22689 temp = md_chars_to_number (buf, INSN_SIZE);
22690
5e73442d
SL
22691 /* If the offset is negative, we should use encoding A2 for ADR. */
22692 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22693 newimm = negate_data_op (&temp, value);
22694 else
22695 {
22696 newimm = encode_arm_immediate (value);
22697
22698 /* If the instruction will fail, see if we can fix things up by
22699 changing the opcode. */
22700 if (newimm == (unsigned int) FAIL)
22701 newimm = negate_data_op (&temp, value);
22702 }
22703
22704 if (newimm == (unsigned int) FAIL)
b99bd4ef 22705 {
c19d1205
ZW
22706 as_bad_where (fixP->fx_file, fixP->fx_line,
22707 _("invalid constant (%lx) after fixup"),
22708 (unsigned long) value);
22709 break;
b99bd4ef 22710 }
b99bd4ef 22711
c19d1205
ZW
22712 newimm |= (temp & 0xfffff000);
22713 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22714 break;
b99bd4ef 22715
c19d1205
ZW
22716 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22717 {
22718 unsigned int highpart = 0;
22719 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22720
77db8e2e 22721 if (fixP->fx_addsy)
42e5fcbf 22722 {
77db8e2e 22723 const char *msg = 0;
42e5fcbf 22724
77db8e2e
NC
22725 if (! S_IS_DEFINED (fixP->fx_addsy))
22726 msg = _("undefined symbol %s used as an immediate value");
22727 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22728 msg = _("symbol %s is in a different section");
22729 else if (S_IS_WEAK (fixP->fx_addsy))
22730 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22731
77db8e2e
NC
22732 if (msg)
22733 {
22734 as_bad_where (fixP->fx_file, fixP->fx_line,
22735 msg, S_GET_NAME (fixP->fx_addsy));
22736 break;
22737 }
22738 }
fa94de6b 22739
c19d1205
ZW
22740 newimm = encode_arm_immediate (value);
22741 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22742
c19d1205
ZW
22743 /* If the instruction will fail, see if we can fix things up by
22744 changing the opcode. */
22745 if (newimm == (unsigned int) FAIL
22746 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22747 {
22748 /* No ? OK - try using two ADD instructions to generate
22749 the value. */
22750 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22751
c19d1205
ZW
22752 /* Yes - then make sure that the second instruction is
22753 also an add. */
22754 if (newimm != (unsigned int) FAIL)
22755 newinsn = temp;
22756 /* Still No ? Try using a negated value. */
22757 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22758 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22759 /* Otherwise - give up. */
22760 else
22761 {
22762 as_bad_where (fixP->fx_file, fixP->fx_line,
22763 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22764 (long) value);
22765 break;
22766 }
b99bd4ef 22767
c19d1205
ZW
22768 /* Replace the first operand in the 2nd instruction (which
22769 is the PC) with the destination register. We have
22770 already added in the PC in the first instruction and we
22771 do not want to do it again. */
22772 newinsn &= ~ 0xf0000;
22773 newinsn |= ((newinsn & 0x0f000) << 4);
22774 }
b99bd4ef 22775
c19d1205
ZW
22776 newimm |= (temp & 0xfffff000);
22777 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22778
c19d1205
ZW
22779 highpart |= (newinsn & 0xfffff000);
22780 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22781 }
22782 break;
b99bd4ef 22783
c19d1205 22784 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22785 if (!fixP->fx_done && seg->use_rela_p)
22786 value = 0;
22787
c19d1205 22788 case BFD_RELOC_ARM_LITERAL:
26d97720 22789 sign = value > 0;
b99bd4ef 22790
c19d1205
ZW
22791 if (value < 0)
22792 value = - value;
b99bd4ef 22793
c19d1205 22794 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22795 {
c19d1205
ZW
22796 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22797 as_bad_where (fixP->fx_file, fixP->fx_line,
22798 _("invalid literal constant: pool needs to be closer"));
22799 else
22800 as_bad_where (fixP->fx_file, fixP->fx_line,
22801 _("bad immediate value for offset (%ld)"),
22802 (long) value);
22803 break;
f03698e6
RE
22804 }
22805
c19d1205 22806 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22807 if (value == 0)
22808 newval &= 0xfffff000;
22809 else
22810 {
22811 newval &= 0xff7ff000;
22812 newval |= value | (sign ? INDEX_UP : 0);
22813 }
c19d1205
ZW
22814 md_number_to_chars (buf, newval, INSN_SIZE);
22815 break;
b99bd4ef 22816
c19d1205
ZW
22817 case BFD_RELOC_ARM_OFFSET_IMM8:
22818 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22819 sign = value > 0;
b99bd4ef 22820
c19d1205
ZW
22821 if (value < 0)
22822 value = - value;
b99bd4ef 22823
c19d1205 22824 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22825 {
c19d1205
ZW
22826 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22827 as_bad_where (fixP->fx_file, fixP->fx_line,
22828 _("invalid literal constant: pool needs to be closer"));
22829 else
427d0db6
RM
22830 as_bad_where (fixP->fx_file, fixP->fx_line,
22831 _("bad immediate value for 8-bit offset (%ld)"),
22832 (long) value);
c19d1205 22833 break;
b99bd4ef
NC
22834 }
22835
c19d1205 22836 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22837 if (value == 0)
22838 newval &= 0xfffff0f0;
22839 else
22840 {
22841 newval &= 0xff7ff0f0;
22842 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22843 }
c19d1205
ZW
22844 md_number_to_chars (buf, newval, INSN_SIZE);
22845 break;
b99bd4ef 22846
c19d1205
ZW
22847 case BFD_RELOC_ARM_T32_OFFSET_U8:
22848 if (value < 0 || value > 1020 || value % 4 != 0)
22849 as_bad_where (fixP->fx_file, fixP->fx_line,
22850 _("bad immediate value for offset (%ld)"), (long) value);
22851 value /= 4;
b99bd4ef 22852
c19d1205 22853 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22854 newval |= value;
22855 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22856 break;
b99bd4ef 22857
c19d1205
ZW
22858 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22859 /* This is a complicated relocation used for all varieties of Thumb32
22860 load/store instruction with immediate offset:
22861
22862 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22863 *4, optional writeback(W)
c19d1205
ZW
22864 (doubleword load/store)
22865
22866 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22867 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22868 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22869 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22870 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22871
22872 Uppercase letters indicate bits that are already encoded at
22873 this point. Lowercase letters are our problem. For the
22874 second block of instructions, the secondary opcode nybble
22875 (bits 8..11) is present, and bit 23 is zero, even if this is
22876 a PC-relative operation. */
22877 newval = md_chars_to_number (buf, THUMB_SIZE);
22878 newval <<= 16;
22879 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22880
c19d1205 22881 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22882 {
c19d1205
ZW
22883 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22884 if (value >= 0)
22885 newval |= (1 << 23);
22886 else
22887 value = -value;
22888 if (value % 4 != 0)
22889 {
22890 as_bad_where (fixP->fx_file, fixP->fx_line,
22891 _("offset not a multiple of 4"));
22892 break;
22893 }
22894 value /= 4;
216d22bc 22895 if (value > 0xff)
c19d1205
ZW
22896 {
22897 as_bad_where (fixP->fx_file, fixP->fx_line,
22898 _("offset out of range"));
22899 break;
22900 }
22901 newval &= ~0xff;
b99bd4ef 22902 }
c19d1205 22903 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22904 {
c19d1205
ZW
22905 /* PC-relative, 12-bit offset. */
22906 if (value >= 0)
22907 newval |= (1 << 23);
22908 else
22909 value = -value;
216d22bc 22910 if (value > 0xfff)
c19d1205
ZW
22911 {
22912 as_bad_where (fixP->fx_file, fixP->fx_line,
22913 _("offset out of range"));
22914 break;
22915 }
22916 newval &= ~0xfff;
b99bd4ef 22917 }
c19d1205 22918 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22919 {
c19d1205
ZW
22920 /* Writeback: 8-bit, +/- offset. */
22921 if (value >= 0)
22922 newval |= (1 << 9);
22923 else
22924 value = -value;
216d22bc 22925 if (value > 0xff)
c19d1205
ZW
22926 {
22927 as_bad_where (fixP->fx_file, fixP->fx_line,
22928 _("offset out of range"));
22929 break;
22930 }
22931 newval &= ~0xff;
b99bd4ef 22932 }
c19d1205 22933 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22934 {
c19d1205 22935 /* T-instruction: positive 8-bit offset. */
216d22bc 22936 if (value < 0 || value > 0xff)
b99bd4ef 22937 {
c19d1205
ZW
22938 as_bad_where (fixP->fx_file, fixP->fx_line,
22939 _("offset out of range"));
22940 break;
b99bd4ef 22941 }
c19d1205
ZW
22942 newval &= ~0xff;
22943 newval |= value;
b99bd4ef
NC
22944 }
22945 else
b99bd4ef 22946 {
c19d1205
ZW
22947 /* Positive 12-bit or negative 8-bit offset. */
22948 int limit;
22949 if (value >= 0)
b99bd4ef 22950 {
c19d1205
ZW
22951 newval |= (1 << 23);
22952 limit = 0xfff;
22953 }
22954 else
22955 {
22956 value = -value;
22957 limit = 0xff;
22958 }
22959 if (value > limit)
22960 {
22961 as_bad_where (fixP->fx_file, fixP->fx_line,
22962 _("offset out of range"));
22963 break;
b99bd4ef 22964 }
c19d1205 22965 newval &= ~limit;
b99bd4ef 22966 }
b99bd4ef 22967
c19d1205
ZW
22968 newval |= value;
22969 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22970 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22971 break;
404ff6b5 22972
c19d1205
ZW
22973 case BFD_RELOC_ARM_SHIFT_IMM:
22974 newval = md_chars_to_number (buf, INSN_SIZE);
22975 if (((unsigned long) value) > 32
22976 || (value == 32
22977 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22978 {
22979 as_bad_where (fixP->fx_file, fixP->fx_line,
22980 _("shift expression is too large"));
22981 break;
22982 }
404ff6b5 22983
c19d1205
ZW
22984 if (value == 0)
22985 /* Shifts of zero must be done as lsl. */
22986 newval &= ~0x60;
22987 else if (value == 32)
22988 value = 0;
22989 newval &= 0xfffff07f;
22990 newval |= (value & 0x1f) << 7;
22991 md_number_to_chars (buf, newval, INSN_SIZE);
22992 break;
404ff6b5 22993
c19d1205 22994 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22995 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22996 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22997 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22998 /* We claim that this fixup has been processed here,
22999 even if in fact we generate an error because we do
23000 not have a reloc for it, so tc_gen_reloc will reject it. */
23001 fixP->fx_done = 1;
404ff6b5 23002
c19d1205
ZW
23003 if (fixP->fx_addsy
23004 && ! S_IS_DEFINED (fixP->fx_addsy))
23005 {
23006 as_bad_where (fixP->fx_file, fixP->fx_line,
23007 _("undefined symbol %s used as an immediate value"),
23008 S_GET_NAME (fixP->fx_addsy));
23009 break;
23010 }
404ff6b5 23011
c19d1205
ZW
23012 newval = md_chars_to_number (buf, THUMB_SIZE);
23013 newval <<= 16;
23014 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23015
16805f35
PB
23016 newimm = FAIL;
23017 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23018 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23019 {
23020 newimm = encode_thumb32_immediate (value);
23021 if (newimm == (unsigned int) FAIL)
23022 newimm = thumb32_negate_data_op (&newval, value);
23023 }
16805f35
PB
23024 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
23025 && newimm == (unsigned int) FAIL)
92e90b6e 23026 {
16805f35
PB
23027 /* Turn add/sum into addw/subw. */
23028 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23029 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
23030 /* No flat 12-bit imm encoding for addsw/subsw. */
23031 if ((newval & 0x00100000) == 0)
e9f89963 23032 {
40f246e3
NC
23033 /* 12 bit immediate for addw/subw. */
23034 if (value < 0)
23035 {
23036 value = -value;
23037 newval ^= 0x00a00000;
23038 }
23039 if (value > 0xfff)
23040 newimm = (unsigned int) FAIL;
23041 else
23042 newimm = value;
e9f89963 23043 }
92e90b6e 23044 }
cc8a6dd0 23045
c19d1205 23046 if (newimm == (unsigned int)FAIL)
3631a3c8 23047 {
c19d1205
ZW
23048 as_bad_where (fixP->fx_file, fixP->fx_line,
23049 _("invalid constant (%lx) after fixup"),
23050 (unsigned long) value);
23051 break;
3631a3c8
NC
23052 }
23053
c19d1205
ZW
23054 newval |= (newimm & 0x800) << 15;
23055 newval |= (newimm & 0x700) << 4;
23056 newval |= (newimm & 0x0ff);
cc8a6dd0 23057
c19d1205
ZW
23058 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23059 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23060 break;
a737bd4d 23061
3eb17e6b 23062 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23063 if (((unsigned long) value) > 0xffff)
23064 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23065 _("invalid smc expression"));
2fc8bdac 23066 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23067 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23068 md_number_to_chars (buf, newval, INSN_SIZE);
23069 break;
a737bd4d 23070
90ec0d68
MGD
23071 case BFD_RELOC_ARM_HVC:
23072 if (((unsigned long) value) > 0xffff)
23073 as_bad_where (fixP->fx_file, fixP->fx_line,
23074 _("invalid hvc expression"));
23075 newval = md_chars_to_number (buf, INSN_SIZE);
23076 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23077 md_number_to_chars (buf, newval, INSN_SIZE);
23078 break;
23079
c19d1205 23080 case BFD_RELOC_ARM_SWI:
adbaf948 23081 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23082 {
23083 if (((unsigned long) value) > 0xff)
23084 as_bad_where (fixP->fx_file, fixP->fx_line,
23085 _("invalid swi expression"));
2fc8bdac 23086 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23087 newval |= value;
23088 md_number_to_chars (buf, newval, THUMB_SIZE);
23089 }
23090 else
23091 {
23092 if (((unsigned long) value) > 0x00ffffff)
23093 as_bad_where (fixP->fx_file, fixP->fx_line,
23094 _("invalid swi expression"));
2fc8bdac 23095 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23096 newval |= value;
23097 md_number_to_chars (buf, newval, INSN_SIZE);
23098 }
23099 break;
a737bd4d 23100
c19d1205
ZW
23101 case BFD_RELOC_ARM_MULTI:
23102 if (((unsigned long) value) > 0xffff)
23103 as_bad_where (fixP->fx_file, fixP->fx_line,
23104 _("invalid expression in load/store multiple"));
23105 newval = value | md_chars_to_number (buf, INSN_SIZE);
23106 md_number_to_chars (buf, newval, INSN_SIZE);
23107 break;
a737bd4d 23108
c19d1205 23109#ifdef OBJ_ELF
39b41c9c 23110 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23111
23112 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23113 && fixP->fx_addsy
34e77a92 23114 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23115 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23116 && THUMB_IS_FUNC (fixP->fx_addsy))
23117 /* Flip the bl to blx. This is a simple flip
23118 bit here because we generate PCREL_CALL for
23119 unconditional bls. */
23120 {
23121 newval = md_chars_to_number (buf, INSN_SIZE);
23122 newval = newval | 0x10000000;
23123 md_number_to_chars (buf, newval, INSN_SIZE);
23124 temp = 1;
23125 fixP->fx_done = 1;
23126 }
39b41c9c
PB
23127 else
23128 temp = 3;
23129 goto arm_branch_common;
23130
23131 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23132 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23133 && fixP->fx_addsy
34e77a92 23134 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23135 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23136 && THUMB_IS_FUNC (fixP->fx_addsy))
23137 {
23138 /* This would map to a bl<cond>, b<cond>,
23139 b<always> to a Thumb function. We
23140 need to force a relocation for this particular
23141 case. */
23142 newval = md_chars_to_number (buf, INSN_SIZE);
23143 fixP->fx_done = 0;
23144 }
23145
2fc8bdac 23146 case BFD_RELOC_ARM_PLT32:
c19d1205 23147#endif
39b41c9c
PB
23148 case BFD_RELOC_ARM_PCREL_BRANCH:
23149 temp = 3;
23150 goto arm_branch_common;
a737bd4d 23151
39b41c9c 23152 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23153
39b41c9c 23154 temp = 1;
267bf995
RR
23155 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23156 && fixP->fx_addsy
34e77a92 23157 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23158 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23159 && ARM_IS_FUNC (fixP->fx_addsy))
23160 {
23161 /* Flip the blx to a bl and warn. */
23162 const char *name = S_GET_NAME (fixP->fx_addsy);
23163 newval = 0xeb000000;
23164 as_warn_where (fixP->fx_file, fixP->fx_line,
23165 _("blx to '%s' an ARM ISA state function changed to bl"),
23166 name);
23167 md_number_to_chars (buf, newval, INSN_SIZE);
23168 temp = 3;
23169 fixP->fx_done = 1;
23170 }
23171
23172#ifdef OBJ_ELF
23173 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23174 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23175#endif
23176
39b41c9c 23177 arm_branch_common:
c19d1205 23178 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23179 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23180 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23181 also be be clear. */
23182 if (value & temp)
c19d1205 23183 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23184 _("misaligned branch destination"));
23185 if ((value & (offsetT)0xfe000000) != (offsetT)0
23186 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23187 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23188
2fc8bdac 23189 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23190 {
2fc8bdac
ZW
23191 newval = md_chars_to_number (buf, INSN_SIZE);
23192 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23193 /* Set the H bit on BLX instructions. */
23194 if (temp == 1)
23195 {
23196 if (value & 2)
23197 newval |= 0x01000000;
23198 else
23199 newval &= ~0x01000000;
23200 }
2fc8bdac 23201 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23202 }
c19d1205 23203 break;
a737bd4d 23204
25fe350b
MS
23205 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23206 /* CBZ can only branch forward. */
a737bd4d 23207
738755b0 23208 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23209 (which, strictly speaking, are prohibited) will be turned into
23210 no-ops.
738755b0
MS
23211
23212 FIXME: It may be better to remove the instruction completely and
23213 perform relaxation. */
23214 if (value == -2)
2fc8bdac
ZW
23215 {
23216 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23217 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23218 md_number_to_chars (buf, newval, THUMB_SIZE);
23219 }
738755b0
MS
23220 else
23221 {
23222 if (value & ~0x7e)
08f10d51 23223 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23224
477330fc 23225 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23226 {
23227 newval = md_chars_to_number (buf, THUMB_SIZE);
23228 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23229 md_number_to_chars (buf, newval, THUMB_SIZE);
23230 }
23231 }
c19d1205 23232 break;
a737bd4d 23233
c19d1205 23234 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23235 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23236 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23237
2fc8bdac
ZW
23238 if (fixP->fx_done || !seg->use_rela_p)
23239 {
23240 newval = md_chars_to_number (buf, THUMB_SIZE);
23241 newval |= (value & 0x1ff) >> 1;
23242 md_number_to_chars (buf, newval, THUMB_SIZE);
23243 }
c19d1205 23244 break;
a737bd4d 23245
c19d1205 23246 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23247 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23248 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23249
2fc8bdac
ZW
23250 if (fixP->fx_done || !seg->use_rela_p)
23251 {
23252 newval = md_chars_to_number (buf, THUMB_SIZE);
23253 newval |= (value & 0xfff) >> 1;
23254 md_number_to_chars (buf, newval, THUMB_SIZE);
23255 }
c19d1205 23256 break;
a737bd4d 23257
c19d1205 23258 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23259 if (fixP->fx_addsy
23260 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23261 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23262 && ARM_IS_FUNC (fixP->fx_addsy)
23263 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23264 {
23265 /* Force a relocation for a branch 20 bits wide. */
23266 fixP->fx_done = 0;
23267 }
08f10d51 23268 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23269 as_bad_where (fixP->fx_file, fixP->fx_line,
23270 _("conditional branch out of range"));
404ff6b5 23271
2fc8bdac
ZW
23272 if (fixP->fx_done || !seg->use_rela_p)
23273 {
23274 offsetT newval2;
23275 addressT S, J1, J2, lo, hi;
404ff6b5 23276
2fc8bdac
ZW
23277 S = (value & 0x00100000) >> 20;
23278 J2 = (value & 0x00080000) >> 19;
23279 J1 = (value & 0x00040000) >> 18;
23280 hi = (value & 0x0003f000) >> 12;
23281 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23282
2fc8bdac
ZW
23283 newval = md_chars_to_number (buf, THUMB_SIZE);
23284 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23285 newval |= (S << 10) | hi;
23286 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23287 md_number_to_chars (buf, newval, THUMB_SIZE);
23288 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23289 }
c19d1205 23290 break;
6c43fab6 23291
c19d1205 23292 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23293 /* If there is a blx from a thumb state function to
23294 another thumb function flip this to a bl and warn
23295 about it. */
23296
23297 if (fixP->fx_addsy
34e77a92 23298 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23299 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23300 && THUMB_IS_FUNC (fixP->fx_addsy))
23301 {
23302 const char *name = S_GET_NAME (fixP->fx_addsy);
23303 as_warn_where (fixP->fx_file, fixP->fx_line,
23304 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23305 name);
23306 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23307 newval = newval | 0x1000;
23308 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23309 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23310 fixP->fx_done = 1;
23311 }
23312
23313
23314 goto thumb_bl_common;
23315
c19d1205 23316 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23317 /* A bl from Thumb state ISA to an internal ARM state function
23318 is converted to a blx. */
23319 if (fixP->fx_addsy
23320 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23321 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23322 && ARM_IS_FUNC (fixP->fx_addsy)
23323 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23324 {
23325 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23326 newval = newval & ~0x1000;
23327 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23328 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23329 fixP->fx_done = 1;
23330 }
23331
23332 thumb_bl_common:
23333
2fc8bdac
ZW
23334 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23335 /* For a BLX instruction, make sure that the relocation is rounded up
23336 to a word boundary. This follows the semantics of the instruction
23337 which specifies that bit 1 of the target address will come from bit
23338 1 of the base address. */
d406f3e4
JB
23339 value = (value + 3) & ~ 3;
23340
23341#ifdef OBJ_ELF
23342 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23343 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23344 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23345#endif
404ff6b5 23346
2b2f5df9
NC
23347 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23348 {
fc289b0a 23349 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23350 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23351 else if ((value & ~0x1ffffff)
23352 && ((value & ~0x1ffffff) != ~0x1ffffff))
23353 as_bad_where (fixP->fx_file, fixP->fx_line,
23354 _("Thumb2 branch out of range"));
23355 }
4a42ebbc
RR
23356
23357 if (fixP->fx_done || !seg->use_rela_p)
23358 encode_thumb2_b_bl_offset (buf, value);
23359
c19d1205 23360 break;
404ff6b5 23361
c19d1205 23362 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23363 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23364 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23365
2fc8bdac 23366 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23367 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23368
2fc8bdac 23369 break;
a737bd4d 23370
2fc8bdac
ZW
23371 case BFD_RELOC_8:
23372 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23373 *buf = value;
c19d1205 23374 break;
a737bd4d 23375
c19d1205 23376 case BFD_RELOC_16:
2fc8bdac 23377 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23378 md_number_to_chars (buf, value, 2);
c19d1205 23379 break;
a737bd4d 23380
c19d1205 23381#ifdef OBJ_ELF
0855e32b
NS
23382 case BFD_RELOC_ARM_TLS_CALL:
23383 case BFD_RELOC_ARM_THM_TLS_CALL:
23384 case BFD_RELOC_ARM_TLS_DESCSEQ:
23385 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23386 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23387 case BFD_RELOC_ARM_TLS_GD32:
23388 case BFD_RELOC_ARM_TLS_LE32:
23389 case BFD_RELOC_ARM_TLS_IE32:
23390 case BFD_RELOC_ARM_TLS_LDM32:
23391 case BFD_RELOC_ARM_TLS_LDO32:
23392 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23393 break;
6c43fab6 23394
c19d1205
ZW
23395 case BFD_RELOC_ARM_GOT32:
23396 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23397 break;
b43420e6
NC
23398
23399 case BFD_RELOC_ARM_GOT_PREL:
23400 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23401 md_number_to_chars (buf, value, 4);
b43420e6
NC
23402 break;
23403
9a6f4e97
NS
23404 case BFD_RELOC_ARM_TARGET2:
23405 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23406 addend here for REL targets, because it won't be written out
23407 during reloc processing later. */
9a6f4e97
NS
23408 if (fixP->fx_done || !seg->use_rela_p)
23409 md_number_to_chars (buf, fixP->fx_offset, 4);
23410 break;
c19d1205 23411#endif
6c43fab6 23412
c19d1205
ZW
23413 case BFD_RELOC_RVA:
23414 case BFD_RELOC_32:
23415 case BFD_RELOC_ARM_TARGET1:
23416 case BFD_RELOC_ARM_ROSEGREL32:
23417 case BFD_RELOC_ARM_SBREL32:
23418 case BFD_RELOC_32_PCREL:
f0927246
NC
23419#ifdef TE_PE
23420 case BFD_RELOC_32_SECREL:
23421#endif
2fc8bdac 23422 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23423#ifdef TE_WINCE
23424 /* For WinCE we only do this for pcrel fixups. */
23425 if (fixP->fx_done || fixP->fx_pcrel)
23426#endif
23427 md_number_to_chars (buf, value, 4);
c19d1205 23428 break;
6c43fab6 23429
c19d1205
ZW
23430#ifdef OBJ_ELF
23431 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23432 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23433 {
23434 newval = md_chars_to_number (buf, 4) & 0x80000000;
23435 if ((value ^ (value >> 1)) & 0x40000000)
23436 {
23437 as_bad_where (fixP->fx_file, fixP->fx_line,
23438 _("rel31 relocation overflow"));
23439 }
23440 newval |= value & 0x7fffffff;
23441 md_number_to_chars (buf, newval, 4);
23442 }
23443 break;
c19d1205 23444#endif
a737bd4d 23445
c19d1205 23446 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23447 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23448 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23449 newval = md_chars_to_number (buf, INSN_SIZE);
23450 else
23451 newval = get_thumb32_insn (buf);
23452 if ((newval & 0x0f200f00) == 0x0d000900)
23453 {
23454 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23455 has permitted values that are multiples of 2, in the range 0
23456 to 510. */
23457 if (value < -510 || value > 510 || (value & 1))
23458 as_bad_where (fixP->fx_file, fixP->fx_line,
23459 _("co-processor offset out of range"));
23460 }
23461 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23462 as_bad_where (fixP->fx_file, fixP->fx_line,
23463 _("co-processor offset out of range"));
23464 cp_off_common:
26d97720 23465 sign = value > 0;
c19d1205
ZW
23466 if (value < 0)
23467 value = -value;
8f06b2d8
PB
23468 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23469 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23470 newval = md_chars_to_number (buf, INSN_SIZE);
23471 else
23472 newval = get_thumb32_insn (buf);
26d97720
NS
23473 if (value == 0)
23474 newval &= 0xffffff00;
23475 else
23476 {
23477 newval &= 0xff7fff00;
9db2f6b4
RL
23478 if ((newval & 0x0f200f00) == 0x0d000900)
23479 {
23480 /* This is a fp16 vstr/vldr.
23481
23482 It requires the immediate offset in the instruction is shifted
23483 left by 1 to be a half-word offset.
23484
23485 Here, left shift by 1 first, and later right shift by 2
23486 should get the right offset. */
23487 value <<= 1;
23488 }
26d97720
NS
23489 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23490 }
8f06b2d8
PB
23491 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23492 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23493 md_number_to_chars (buf, newval, INSN_SIZE);
23494 else
23495 put_thumb32_insn (buf, newval);
c19d1205 23496 break;
a737bd4d 23497
c19d1205 23498 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23499 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23500 if (value < -255 || value > 255)
23501 as_bad_where (fixP->fx_file, fixP->fx_line,
23502 _("co-processor offset out of range"));
df7849c5 23503 value *= 4;
c19d1205 23504 goto cp_off_common;
6c43fab6 23505
c19d1205
ZW
23506 case BFD_RELOC_ARM_THUMB_OFFSET:
23507 newval = md_chars_to_number (buf, THUMB_SIZE);
23508 /* Exactly what ranges, and where the offset is inserted depends
23509 on the type of instruction, we can establish this from the
23510 top 4 bits. */
23511 switch (newval >> 12)
23512 {
23513 case 4: /* PC load. */
23514 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23515 forced to zero for these loads; md_pcrel_from has already
23516 compensated for this. */
23517 if (value & 3)
23518 as_bad_where (fixP->fx_file, fixP->fx_line,
23519 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23520 (((unsigned long) fixP->fx_frag->fr_address
23521 + (unsigned long) fixP->fx_where) & ~3)
23522 + (unsigned long) value);
a737bd4d 23523
c19d1205
ZW
23524 if (value & ~0x3fc)
23525 as_bad_where (fixP->fx_file, fixP->fx_line,
23526 _("invalid offset, value too big (0x%08lX)"),
23527 (long) value);
a737bd4d 23528
c19d1205
ZW
23529 newval |= value >> 2;
23530 break;
a737bd4d 23531
c19d1205
ZW
23532 case 9: /* SP load/store. */
23533 if (value & ~0x3fc)
23534 as_bad_where (fixP->fx_file, fixP->fx_line,
23535 _("invalid offset, value too big (0x%08lX)"),
23536 (long) value);
23537 newval |= value >> 2;
23538 break;
6c43fab6 23539
c19d1205
ZW
23540 case 6: /* Word load/store. */
23541 if (value & ~0x7c)
23542 as_bad_where (fixP->fx_file, fixP->fx_line,
23543 _("invalid offset, value too big (0x%08lX)"),
23544 (long) value);
23545 newval |= value << 4; /* 6 - 2. */
23546 break;
a737bd4d 23547
c19d1205
ZW
23548 case 7: /* Byte load/store. */
23549 if (value & ~0x1f)
23550 as_bad_where (fixP->fx_file, fixP->fx_line,
23551 _("invalid offset, value too big (0x%08lX)"),
23552 (long) value);
23553 newval |= value << 6;
23554 break;
a737bd4d 23555
c19d1205
ZW
23556 case 8: /* Halfword load/store. */
23557 if (value & ~0x3e)
23558 as_bad_where (fixP->fx_file, fixP->fx_line,
23559 _("invalid offset, value too big (0x%08lX)"),
23560 (long) value);
23561 newval |= value << 5; /* 6 - 1. */
23562 break;
a737bd4d 23563
c19d1205
ZW
23564 default:
23565 as_bad_where (fixP->fx_file, fixP->fx_line,
23566 "Unable to process relocation for thumb opcode: %lx",
23567 (unsigned long) newval);
23568 break;
23569 }
23570 md_number_to_chars (buf, newval, THUMB_SIZE);
23571 break;
a737bd4d 23572
c19d1205
ZW
23573 case BFD_RELOC_ARM_THUMB_ADD:
23574 /* This is a complicated relocation, since we use it for all of
23575 the following immediate relocations:
a737bd4d 23576
c19d1205
ZW
23577 3bit ADD/SUB
23578 8bit ADD/SUB
23579 9bit ADD/SUB SP word-aligned
23580 10bit ADD PC/SP word-aligned
a737bd4d 23581
c19d1205
ZW
23582 The type of instruction being processed is encoded in the
23583 instruction field:
a737bd4d 23584
c19d1205
ZW
23585 0x8000 SUB
23586 0x00F0 Rd
23587 0x000F Rs
23588 */
23589 newval = md_chars_to_number (buf, THUMB_SIZE);
23590 {
23591 int rd = (newval >> 4) & 0xf;
23592 int rs = newval & 0xf;
23593 int subtract = !!(newval & 0x8000);
a737bd4d 23594
c19d1205
ZW
23595 /* Check for HI regs, only very restricted cases allowed:
23596 Adjusting SP, and using PC or SP to get an address. */
23597 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23598 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23599 as_bad_where (fixP->fx_file, fixP->fx_line,
23600 _("invalid Hi register with immediate"));
a737bd4d 23601
c19d1205
ZW
23602 /* If value is negative, choose the opposite instruction. */
23603 if (value < 0)
23604 {
23605 value = -value;
23606 subtract = !subtract;
23607 if (value < 0)
23608 as_bad_where (fixP->fx_file, fixP->fx_line,
23609 _("immediate value out of range"));
23610 }
a737bd4d 23611
c19d1205
ZW
23612 if (rd == REG_SP)
23613 {
75c11999 23614 if (value & ~0x1fc)
c19d1205
ZW
23615 as_bad_where (fixP->fx_file, fixP->fx_line,
23616 _("invalid immediate for stack address calculation"));
23617 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23618 newval |= value >> 2;
23619 }
23620 else if (rs == REG_PC || rs == REG_SP)
23621 {
c12d2c9d
NC
23622 /* PR gas/18541. If the addition is for a defined symbol
23623 within range of an ADR instruction then accept it. */
23624 if (subtract
23625 && value == 4
23626 && fixP->fx_addsy != NULL)
23627 {
23628 subtract = 0;
23629
23630 if (! S_IS_DEFINED (fixP->fx_addsy)
23631 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23632 || S_IS_WEAK (fixP->fx_addsy))
23633 {
23634 as_bad_where (fixP->fx_file, fixP->fx_line,
23635 _("address calculation needs a strongly defined nearby symbol"));
23636 }
23637 else
23638 {
23639 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23640
23641 /* Round up to the next 4-byte boundary. */
23642 if (v & 3)
23643 v = (v + 3) & ~ 3;
23644 else
23645 v += 4;
23646 v = S_GET_VALUE (fixP->fx_addsy) - v;
23647
23648 if (v & ~0x3fc)
23649 {
23650 as_bad_where (fixP->fx_file, fixP->fx_line,
23651 _("symbol too far away"));
23652 }
23653 else
23654 {
23655 fixP->fx_done = 1;
23656 value = v;
23657 }
23658 }
23659 }
23660
c19d1205
ZW
23661 if (subtract || value & ~0x3fc)
23662 as_bad_where (fixP->fx_file, fixP->fx_line,
23663 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23664 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23665 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23666 newval |= rd << 8;
23667 newval |= value >> 2;
23668 }
23669 else if (rs == rd)
23670 {
23671 if (value & ~0xff)
23672 as_bad_where (fixP->fx_file, fixP->fx_line,
23673 _("immediate value out of range"));
23674 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23675 newval |= (rd << 8) | value;
23676 }
23677 else
23678 {
23679 if (value & ~0x7)
23680 as_bad_where (fixP->fx_file, fixP->fx_line,
23681 _("immediate value out of range"));
23682 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23683 newval |= rd | (rs << 3) | (value << 6);
23684 }
23685 }
23686 md_number_to_chars (buf, newval, THUMB_SIZE);
23687 break;
a737bd4d 23688
c19d1205
ZW
23689 case BFD_RELOC_ARM_THUMB_IMM:
23690 newval = md_chars_to_number (buf, THUMB_SIZE);
23691 if (value < 0 || value > 255)
23692 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23693 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23694 (long) value);
23695 newval |= value;
23696 md_number_to_chars (buf, newval, THUMB_SIZE);
23697 break;
a737bd4d 23698
c19d1205
ZW
23699 case BFD_RELOC_ARM_THUMB_SHIFT:
23700 /* 5bit shift value (0..32). LSL cannot take 32. */
23701 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23702 temp = newval & 0xf800;
23703 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23704 as_bad_where (fixP->fx_file, fixP->fx_line,
23705 _("invalid shift value: %ld"), (long) value);
23706 /* Shifts of zero must be encoded as LSL. */
23707 if (value == 0)
23708 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23709 /* Shifts of 32 are encoded as zero. */
23710 else if (value == 32)
23711 value = 0;
23712 newval |= value << 6;
23713 md_number_to_chars (buf, newval, THUMB_SIZE);
23714 break;
a737bd4d 23715
c19d1205
ZW
23716 case BFD_RELOC_VTABLE_INHERIT:
23717 case BFD_RELOC_VTABLE_ENTRY:
23718 fixP->fx_done = 0;
23719 return;
6c43fab6 23720
b6895b4f
PB
23721 case BFD_RELOC_ARM_MOVW:
23722 case BFD_RELOC_ARM_MOVT:
23723 case BFD_RELOC_ARM_THUMB_MOVW:
23724 case BFD_RELOC_ARM_THUMB_MOVT:
23725 if (fixP->fx_done || !seg->use_rela_p)
23726 {
23727 /* REL format relocations are limited to a 16-bit addend. */
23728 if (!fixP->fx_done)
23729 {
39623e12 23730 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23731 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23732 _("offset out of range"));
b6895b4f
PB
23733 }
23734 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23735 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23736 {
23737 value >>= 16;
23738 }
23739
23740 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23741 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23742 {
23743 newval = get_thumb32_insn (buf);
23744 newval &= 0xfbf08f00;
23745 newval |= (value & 0xf000) << 4;
23746 newval |= (value & 0x0800) << 15;
23747 newval |= (value & 0x0700) << 4;
23748 newval |= (value & 0x00ff);
23749 put_thumb32_insn (buf, newval);
23750 }
23751 else
23752 {
23753 newval = md_chars_to_number (buf, 4);
23754 newval &= 0xfff0f000;
23755 newval |= value & 0x0fff;
23756 newval |= (value & 0xf000) << 4;
23757 md_number_to_chars (buf, newval, 4);
23758 }
23759 }
23760 return;
23761
72d98d16
MG
23762 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23763 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23764 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23765 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23766 gas_assert (!fixP->fx_done);
23767 {
23768 bfd_vma insn;
23769 bfd_boolean is_mov;
23770 bfd_vma encoded_addend = value;
23771
23772 /* Check that addend can be encoded in instruction. */
23773 if (!seg->use_rela_p && (value < 0 || value > 255))
23774 as_bad_where (fixP->fx_file, fixP->fx_line,
23775 _("the offset 0x%08lX is not representable"),
23776 (unsigned long) encoded_addend);
23777
23778 /* Extract the instruction. */
23779 insn = md_chars_to_number (buf, THUMB_SIZE);
23780 is_mov = (insn & 0xf800) == 0x2000;
23781
23782 /* Encode insn. */
23783 if (is_mov)
23784 {
23785 if (!seg->use_rela_p)
23786 insn |= encoded_addend;
23787 }
23788 else
23789 {
23790 int rd, rs;
23791
23792 /* Extract the instruction. */
23793 /* Encoding is the following
23794 0x8000 SUB
23795 0x00F0 Rd
23796 0x000F Rs
23797 */
23798 /* The following conditions must be true :
23799 - ADD
23800 - Rd == Rs
23801 - Rd <= 7
23802 */
23803 rd = (insn >> 4) & 0xf;
23804 rs = insn & 0xf;
23805 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23806 as_bad_where (fixP->fx_file, fixP->fx_line,
23807 _("Unable to process relocation for thumb opcode: %lx"),
23808 (unsigned long) insn);
23809
23810 /* Encode as ADD immediate8 thumb 1 code. */
23811 insn = 0x3000 | (rd << 8);
23812
23813 /* Place the encoded addend into the first 8 bits of the
23814 instruction. */
23815 if (!seg->use_rela_p)
23816 insn |= encoded_addend;
23817 }
23818
23819 /* Update the instruction. */
23820 md_number_to_chars (buf, insn, THUMB_SIZE);
23821 }
23822 break;
23823
4962c51a
MS
23824 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23825 case BFD_RELOC_ARM_ALU_PC_G0:
23826 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23827 case BFD_RELOC_ARM_ALU_PC_G1:
23828 case BFD_RELOC_ARM_ALU_PC_G2:
23829 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23830 case BFD_RELOC_ARM_ALU_SB_G0:
23831 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23832 case BFD_RELOC_ARM_ALU_SB_G1:
23833 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23834 gas_assert (!fixP->fx_done);
4962c51a
MS
23835 if (!seg->use_rela_p)
23836 {
477330fc
RM
23837 bfd_vma insn;
23838 bfd_vma encoded_addend;
23839 bfd_vma addend_abs = abs (value);
23840
23841 /* Check that the absolute value of the addend can be
23842 expressed as an 8-bit constant plus a rotation. */
23843 encoded_addend = encode_arm_immediate (addend_abs);
23844 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23845 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23846 _("the offset 0x%08lX is not representable"),
23847 (unsigned long) addend_abs);
23848
23849 /* Extract the instruction. */
23850 insn = md_chars_to_number (buf, INSN_SIZE);
23851
23852 /* If the addend is positive, use an ADD instruction.
23853 Otherwise use a SUB. Take care not to destroy the S bit. */
23854 insn &= 0xff1fffff;
23855 if (value < 0)
23856 insn |= 1 << 22;
23857 else
23858 insn |= 1 << 23;
23859
23860 /* Place the encoded addend into the first 12 bits of the
23861 instruction. */
23862 insn &= 0xfffff000;
23863 insn |= encoded_addend;
23864
23865 /* Update the instruction. */
23866 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23867 }
23868 break;
23869
23870 case BFD_RELOC_ARM_LDR_PC_G0:
23871 case BFD_RELOC_ARM_LDR_PC_G1:
23872 case BFD_RELOC_ARM_LDR_PC_G2:
23873 case BFD_RELOC_ARM_LDR_SB_G0:
23874 case BFD_RELOC_ARM_LDR_SB_G1:
23875 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23876 gas_assert (!fixP->fx_done);
4962c51a 23877 if (!seg->use_rela_p)
477330fc
RM
23878 {
23879 bfd_vma insn;
23880 bfd_vma addend_abs = abs (value);
4962c51a 23881
477330fc
RM
23882 /* Check that the absolute value of the addend can be
23883 encoded in 12 bits. */
23884 if (addend_abs >= 0x1000)
4962c51a 23885 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23886 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23887 (unsigned long) addend_abs);
23888
23889 /* Extract the instruction. */
23890 insn = md_chars_to_number (buf, INSN_SIZE);
23891
23892 /* If the addend is negative, clear bit 23 of the instruction.
23893 Otherwise set it. */
23894 if (value < 0)
23895 insn &= ~(1 << 23);
23896 else
23897 insn |= 1 << 23;
23898
23899 /* Place the absolute value of the addend into the first 12 bits
23900 of the instruction. */
23901 insn &= 0xfffff000;
23902 insn |= addend_abs;
23903
23904 /* Update the instruction. */
23905 md_number_to_chars (buf, insn, INSN_SIZE);
23906 }
4962c51a
MS
23907 break;
23908
23909 case BFD_RELOC_ARM_LDRS_PC_G0:
23910 case BFD_RELOC_ARM_LDRS_PC_G1:
23911 case BFD_RELOC_ARM_LDRS_PC_G2:
23912 case BFD_RELOC_ARM_LDRS_SB_G0:
23913 case BFD_RELOC_ARM_LDRS_SB_G1:
23914 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23915 gas_assert (!fixP->fx_done);
4962c51a 23916 if (!seg->use_rela_p)
477330fc
RM
23917 {
23918 bfd_vma insn;
23919 bfd_vma addend_abs = abs (value);
4962c51a 23920
477330fc
RM
23921 /* Check that the absolute value of the addend can be
23922 encoded in 8 bits. */
23923 if (addend_abs >= 0x100)
4962c51a 23924 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23925 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23926 (unsigned long) addend_abs);
23927
23928 /* Extract the instruction. */
23929 insn = md_chars_to_number (buf, INSN_SIZE);
23930
23931 /* If the addend is negative, clear bit 23 of the instruction.
23932 Otherwise set it. */
23933 if (value < 0)
23934 insn &= ~(1 << 23);
23935 else
23936 insn |= 1 << 23;
23937
23938 /* Place the first four bits of the absolute value of the addend
23939 into the first 4 bits of the instruction, and the remaining
23940 four into bits 8 .. 11. */
23941 insn &= 0xfffff0f0;
23942 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23943
23944 /* Update the instruction. */
23945 md_number_to_chars (buf, insn, INSN_SIZE);
23946 }
4962c51a
MS
23947 break;
23948
23949 case BFD_RELOC_ARM_LDC_PC_G0:
23950 case BFD_RELOC_ARM_LDC_PC_G1:
23951 case BFD_RELOC_ARM_LDC_PC_G2:
23952 case BFD_RELOC_ARM_LDC_SB_G0:
23953 case BFD_RELOC_ARM_LDC_SB_G1:
23954 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23955 gas_assert (!fixP->fx_done);
4962c51a 23956 if (!seg->use_rela_p)
477330fc
RM
23957 {
23958 bfd_vma insn;
23959 bfd_vma addend_abs = abs (value);
4962c51a 23960
477330fc
RM
23961 /* Check that the absolute value of the addend is a multiple of
23962 four and, when divided by four, fits in 8 bits. */
23963 if (addend_abs & 0x3)
4962c51a 23964 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23965 _("bad offset 0x%08lX (must be word-aligned)"),
23966 (unsigned long) addend_abs);
4962c51a 23967
477330fc 23968 if ((addend_abs >> 2) > 0xff)
4962c51a 23969 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23970 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23971 (unsigned long) addend_abs);
23972
23973 /* Extract the instruction. */
23974 insn = md_chars_to_number (buf, INSN_SIZE);
23975
23976 /* If the addend is negative, clear bit 23 of the instruction.
23977 Otherwise set it. */
23978 if (value < 0)
23979 insn &= ~(1 << 23);
23980 else
23981 insn |= 1 << 23;
23982
23983 /* Place the addend (divided by four) into the first eight
23984 bits of the instruction. */
23985 insn &= 0xfffffff0;
23986 insn |= addend_abs >> 2;
23987
23988 /* Update the instruction. */
23989 md_number_to_chars (buf, insn, INSN_SIZE);
23990 }
4962c51a
MS
23991 break;
23992
845b51d6
PB
23993 case BFD_RELOC_ARM_V4BX:
23994 /* This will need to go in the object file. */
23995 fixP->fx_done = 0;
23996 break;
23997
c19d1205
ZW
23998 case BFD_RELOC_UNUSED:
23999 default:
24000 as_bad_where (fixP->fx_file, fixP->fx_line,
24001 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24002 }
6c43fab6
RE
24003}
24004
c19d1205
ZW
24005/* Translate internal representation of relocation info to BFD target
24006 format. */
a737bd4d 24007
c19d1205 24008arelent *
00a97672 24009tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24010{
c19d1205
ZW
24011 arelent * reloc;
24012 bfd_reloc_code_real_type code;
a737bd4d 24013
325801bd 24014 reloc = XNEW (arelent);
a737bd4d 24015
325801bd 24016 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24017 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24018 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24019
2fc8bdac 24020 if (fixp->fx_pcrel)
00a97672
RS
24021 {
24022 if (section->use_rela_p)
24023 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24024 else
24025 fixp->fx_offset = reloc->address;
24026 }
c19d1205 24027 reloc->addend = fixp->fx_offset;
a737bd4d 24028
c19d1205 24029 switch (fixp->fx_r_type)
a737bd4d 24030 {
c19d1205
ZW
24031 case BFD_RELOC_8:
24032 if (fixp->fx_pcrel)
24033 {
24034 code = BFD_RELOC_8_PCREL;
24035 break;
24036 }
a737bd4d 24037
c19d1205
ZW
24038 case BFD_RELOC_16:
24039 if (fixp->fx_pcrel)
24040 {
24041 code = BFD_RELOC_16_PCREL;
24042 break;
24043 }
6c43fab6 24044
c19d1205
ZW
24045 case BFD_RELOC_32:
24046 if (fixp->fx_pcrel)
24047 {
24048 code = BFD_RELOC_32_PCREL;
24049 break;
24050 }
a737bd4d 24051
b6895b4f
PB
24052 case BFD_RELOC_ARM_MOVW:
24053 if (fixp->fx_pcrel)
24054 {
24055 code = BFD_RELOC_ARM_MOVW_PCREL;
24056 break;
24057 }
24058
24059 case BFD_RELOC_ARM_MOVT:
24060 if (fixp->fx_pcrel)
24061 {
24062 code = BFD_RELOC_ARM_MOVT_PCREL;
24063 break;
24064 }
24065
24066 case BFD_RELOC_ARM_THUMB_MOVW:
24067 if (fixp->fx_pcrel)
24068 {
24069 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24070 break;
24071 }
24072
24073 case BFD_RELOC_ARM_THUMB_MOVT:
24074 if (fixp->fx_pcrel)
24075 {
24076 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24077 break;
24078 }
24079
c19d1205
ZW
24080 case BFD_RELOC_NONE:
24081 case BFD_RELOC_ARM_PCREL_BRANCH:
24082 case BFD_RELOC_ARM_PCREL_BLX:
24083 case BFD_RELOC_RVA:
24084 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24085 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24086 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24087 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24088 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24089 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24090 case BFD_RELOC_VTABLE_ENTRY:
24091 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24092#ifdef TE_PE
24093 case BFD_RELOC_32_SECREL:
24094#endif
c19d1205
ZW
24095 code = fixp->fx_r_type;
24096 break;
a737bd4d 24097
00adf2d4
JB
24098 case BFD_RELOC_THUMB_PCREL_BLX:
24099#ifdef OBJ_ELF
24100 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24101 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24102 else
24103#endif
24104 code = BFD_RELOC_THUMB_PCREL_BLX;
24105 break;
24106
c19d1205
ZW
24107 case BFD_RELOC_ARM_LITERAL:
24108 case BFD_RELOC_ARM_HWLITERAL:
24109 /* If this is called then the a literal has
24110 been referenced across a section boundary. */
24111 as_bad_where (fixp->fx_file, fixp->fx_line,
24112 _("literal referenced across section boundary"));
24113 return NULL;
a737bd4d 24114
c19d1205 24115#ifdef OBJ_ELF
0855e32b
NS
24116 case BFD_RELOC_ARM_TLS_CALL:
24117 case BFD_RELOC_ARM_THM_TLS_CALL:
24118 case BFD_RELOC_ARM_TLS_DESCSEQ:
24119 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24120 case BFD_RELOC_ARM_GOT32:
24121 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24122 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24123 case BFD_RELOC_ARM_PLT32:
24124 case BFD_RELOC_ARM_TARGET1:
24125 case BFD_RELOC_ARM_ROSEGREL32:
24126 case BFD_RELOC_ARM_SBREL32:
24127 case BFD_RELOC_ARM_PREL31:
24128 case BFD_RELOC_ARM_TARGET2:
c19d1205 24129 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24130 case BFD_RELOC_ARM_PCREL_CALL:
24131 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24132 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24133 case BFD_RELOC_ARM_ALU_PC_G0:
24134 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24135 case BFD_RELOC_ARM_ALU_PC_G1:
24136 case BFD_RELOC_ARM_ALU_PC_G2:
24137 case BFD_RELOC_ARM_LDR_PC_G0:
24138 case BFD_RELOC_ARM_LDR_PC_G1:
24139 case BFD_RELOC_ARM_LDR_PC_G2:
24140 case BFD_RELOC_ARM_LDRS_PC_G0:
24141 case BFD_RELOC_ARM_LDRS_PC_G1:
24142 case BFD_RELOC_ARM_LDRS_PC_G2:
24143 case BFD_RELOC_ARM_LDC_PC_G0:
24144 case BFD_RELOC_ARM_LDC_PC_G1:
24145 case BFD_RELOC_ARM_LDC_PC_G2:
24146 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24147 case BFD_RELOC_ARM_ALU_SB_G0:
24148 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24149 case BFD_RELOC_ARM_ALU_SB_G1:
24150 case BFD_RELOC_ARM_ALU_SB_G2:
24151 case BFD_RELOC_ARM_LDR_SB_G0:
24152 case BFD_RELOC_ARM_LDR_SB_G1:
24153 case BFD_RELOC_ARM_LDR_SB_G2:
24154 case BFD_RELOC_ARM_LDRS_SB_G0:
24155 case BFD_RELOC_ARM_LDRS_SB_G1:
24156 case BFD_RELOC_ARM_LDRS_SB_G2:
24157 case BFD_RELOC_ARM_LDC_SB_G0:
24158 case BFD_RELOC_ARM_LDC_SB_G1:
24159 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24160 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24161 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24162 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24163 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24164 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24165 code = fixp->fx_r_type;
24166 break;
a737bd4d 24167
0855e32b 24168 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24169 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24170 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24171 case BFD_RELOC_ARM_TLS_IE32:
24172 case BFD_RELOC_ARM_TLS_LDM32:
24173 /* BFD will include the symbol's address in the addend.
24174 But we don't want that, so subtract it out again here. */
24175 if (!S_IS_COMMON (fixp->fx_addsy))
24176 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24177 code = fixp->fx_r_type;
24178 break;
24179#endif
a737bd4d 24180
c19d1205
ZW
24181 case BFD_RELOC_ARM_IMMEDIATE:
24182 as_bad_where (fixp->fx_file, fixp->fx_line,
24183 _("internal relocation (type: IMMEDIATE) not fixed up"));
24184 return NULL;
a737bd4d 24185
c19d1205
ZW
24186 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24187 as_bad_where (fixp->fx_file, fixp->fx_line,
24188 _("ADRL used for a symbol not defined in the same file"));
24189 return NULL;
a737bd4d 24190
c19d1205 24191 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24192 if (section->use_rela_p)
24193 {
24194 code = fixp->fx_r_type;
24195 break;
24196 }
24197
c19d1205
ZW
24198 if (fixp->fx_addsy != NULL
24199 && !S_IS_DEFINED (fixp->fx_addsy)
24200 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24201 {
c19d1205
ZW
24202 as_bad_where (fixp->fx_file, fixp->fx_line,
24203 _("undefined local label `%s'"),
24204 S_GET_NAME (fixp->fx_addsy));
24205 return NULL;
a737bd4d
NC
24206 }
24207
c19d1205
ZW
24208 as_bad_where (fixp->fx_file, fixp->fx_line,
24209 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24210 return NULL;
a737bd4d 24211
c19d1205
ZW
24212 default:
24213 {
e0471c16 24214 const char * type;
6c43fab6 24215
c19d1205
ZW
24216 switch (fixp->fx_r_type)
24217 {
24218 case BFD_RELOC_NONE: type = "NONE"; break;
24219 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24220 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24221 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24222 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24223 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24224 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24225 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24226 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24227 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24228 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24229 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24230 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24231 default: type = _("<unknown>"); break;
24232 }
24233 as_bad_where (fixp->fx_file, fixp->fx_line,
24234 _("cannot represent %s relocation in this object file format"),
24235 type);
24236 return NULL;
24237 }
a737bd4d 24238 }
6c43fab6 24239
c19d1205
ZW
24240#ifdef OBJ_ELF
24241 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24242 && GOT_symbol
24243 && fixp->fx_addsy == GOT_symbol)
24244 {
24245 code = BFD_RELOC_ARM_GOTPC;
24246 reloc->addend = fixp->fx_offset = reloc->address;
24247 }
24248#endif
6c43fab6 24249
c19d1205 24250 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24251
c19d1205
ZW
24252 if (reloc->howto == NULL)
24253 {
24254 as_bad_where (fixp->fx_file, fixp->fx_line,
24255 _("cannot represent %s relocation in this object file format"),
24256 bfd_get_reloc_code_name (code));
24257 return NULL;
24258 }
6c43fab6 24259
c19d1205
ZW
24260 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24261 vtable entry to be used in the relocation's section offset. */
24262 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24263 reloc->address = fixp->fx_offset;
6c43fab6 24264
c19d1205 24265 return reloc;
6c43fab6
RE
24266}
24267
c19d1205 24268/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24269
c19d1205
ZW
24270void
24271cons_fix_new_arm (fragS * frag,
24272 int where,
24273 int size,
62ebcb5c
AM
24274 expressionS * exp,
24275 bfd_reloc_code_real_type reloc)
6c43fab6 24276{
c19d1205 24277 int pcrel = 0;
6c43fab6 24278
c19d1205
ZW
24279 /* Pick a reloc.
24280 FIXME: @@ Should look at CPU word size. */
24281 switch (size)
24282 {
24283 case 1:
62ebcb5c 24284 reloc = BFD_RELOC_8;
c19d1205
ZW
24285 break;
24286 case 2:
62ebcb5c 24287 reloc = BFD_RELOC_16;
c19d1205
ZW
24288 break;
24289 case 4:
24290 default:
62ebcb5c 24291 reloc = BFD_RELOC_32;
c19d1205
ZW
24292 break;
24293 case 8:
62ebcb5c 24294 reloc = BFD_RELOC_64;
c19d1205
ZW
24295 break;
24296 }
6c43fab6 24297
f0927246
NC
24298#ifdef TE_PE
24299 if (exp->X_op == O_secrel)
24300 {
24301 exp->X_op = O_symbol;
62ebcb5c 24302 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24303 }
24304#endif
24305
62ebcb5c 24306 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24307}
6c43fab6 24308
4343666d 24309#if defined (OBJ_COFF)
c19d1205
ZW
24310void
24311arm_validate_fix (fixS * fixP)
6c43fab6 24312{
c19d1205
ZW
24313 /* If the destination of the branch is a defined symbol which does not have
24314 the THUMB_FUNC attribute, then we must be calling a function which has
24315 the (interfacearm) attribute. We look for the Thumb entry point to that
24316 function and change the branch to refer to that function instead. */
24317 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24318 && fixP->fx_addsy != NULL
24319 && S_IS_DEFINED (fixP->fx_addsy)
24320 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24321 {
c19d1205 24322 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24323 }
c19d1205
ZW
24324}
24325#endif
6c43fab6 24326
267bf995 24327
c19d1205
ZW
24328int
24329arm_force_relocation (struct fix * fixp)
24330{
24331#if defined (OBJ_COFF) && defined (TE_PE)
24332 if (fixp->fx_r_type == BFD_RELOC_RVA)
24333 return 1;
24334#endif
6c43fab6 24335
267bf995
RR
24336 /* In case we have a call or a branch to a function in ARM ISA mode from
24337 a thumb function or vice-versa force the relocation. These relocations
24338 are cleared off for some cores that might have blx and simple transformations
24339 are possible. */
24340
24341#ifdef OBJ_ELF
24342 switch (fixp->fx_r_type)
24343 {
24344 case BFD_RELOC_ARM_PCREL_JUMP:
24345 case BFD_RELOC_ARM_PCREL_CALL:
24346 case BFD_RELOC_THUMB_PCREL_BLX:
24347 if (THUMB_IS_FUNC (fixp->fx_addsy))
24348 return 1;
24349 break;
24350
24351 case BFD_RELOC_ARM_PCREL_BLX:
24352 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24353 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24354 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24355 if (ARM_IS_FUNC (fixp->fx_addsy))
24356 return 1;
24357 break;
24358
24359 default:
24360 break;
24361 }
24362#endif
24363
b5884301
PB
24364 /* Resolve these relocations even if the symbol is extern or weak.
24365 Technically this is probably wrong due to symbol preemption.
24366 In practice these relocations do not have enough range to be useful
24367 at dynamic link time, and some code (e.g. in the Linux kernel)
24368 expects these references to be resolved. */
c19d1205
ZW
24369 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24370 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24371 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24372 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24373 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24374 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24375 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24376 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24377 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24379 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24380 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24381 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24383 return 0;
a737bd4d 24384
4962c51a
MS
24385 /* Always leave these relocations for the linker. */
24386 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24387 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24388 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24389 return 1;
24390
f0291e4c
PB
24391 /* Always generate relocations against function symbols. */
24392 if (fixp->fx_r_type == BFD_RELOC_32
24393 && fixp->fx_addsy
24394 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24395 return 1;
24396
c19d1205 24397 return generic_force_reloc (fixp);
404ff6b5
AH
24398}
24399
0ffdc86c 24400#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24401/* Relocations against function names must be left unadjusted,
24402 so that the linker can use this information to generate interworking
24403 stubs. The MIPS version of this function
c19d1205
ZW
24404 also prevents relocations that are mips-16 specific, but I do not
24405 know why it does this.
404ff6b5 24406
c19d1205
ZW
24407 FIXME:
24408 There is one other problem that ought to be addressed here, but
24409 which currently is not: Taking the address of a label (rather
24410 than a function) and then later jumping to that address. Such
24411 addresses also ought to have their bottom bit set (assuming that
24412 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24413
c19d1205
ZW
24414bfd_boolean
24415arm_fix_adjustable (fixS * fixP)
404ff6b5 24416{
c19d1205
ZW
24417 if (fixP->fx_addsy == NULL)
24418 return 1;
404ff6b5 24419
e28387c3
PB
24420 /* Preserve relocations against symbols with function type. */
24421 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24422 return FALSE;
e28387c3 24423
c19d1205
ZW
24424 if (THUMB_IS_FUNC (fixP->fx_addsy)
24425 && fixP->fx_subsy == NULL)
c921be7d 24426 return FALSE;
a737bd4d 24427
c19d1205
ZW
24428 /* We need the symbol name for the VTABLE entries. */
24429 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24430 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24431 return FALSE;
404ff6b5 24432
c19d1205
ZW
24433 /* Don't allow symbols to be discarded on GOT related relocs. */
24434 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24435 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24436 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24437 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24438 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24444 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24446 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24447 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24448 return FALSE;
a737bd4d 24449
4962c51a
MS
24450 /* Similarly for group relocations. */
24451 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24452 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24453 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24454 return FALSE;
4962c51a 24455
79947c54
CD
24456 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24457 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24458 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24459 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24460 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24461 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24462 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24463 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24464 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24465 return FALSE;
79947c54 24466
72d98d16
MG
24467 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24468 offsets, so keep these symbols. */
24469 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24470 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24471 return FALSE;
24472
c921be7d 24473 return TRUE;
a737bd4d 24474}
0ffdc86c
NC
24475#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24476
24477#ifdef OBJ_ELF
c19d1205
ZW
24478const char *
24479elf32_arm_target_format (void)
404ff6b5 24480{
c19d1205
ZW
24481#ifdef TE_SYMBIAN
24482 return (target_big_endian
24483 ? "elf32-bigarm-symbian"
24484 : "elf32-littlearm-symbian");
24485#elif defined (TE_VXWORKS)
24486 return (target_big_endian
24487 ? "elf32-bigarm-vxworks"
24488 : "elf32-littlearm-vxworks");
b38cadfb
NC
24489#elif defined (TE_NACL)
24490 return (target_big_endian
24491 ? "elf32-bigarm-nacl"
24492 : "elf32-littlearm-nacl");
c19d1205
ZW
24493#else
24494 if (target_big_endian)
24495 return "elf32-bigarm";
24496 else
24497 return "elf32-littlearm";
24498#endif
404ff6b5
AH
24499}
24500
c19d1205
ZW
24501void
24502armelf_frob_symbol (symbolS * symp,
24503 int * puntp)
404ff6b5 24504{
c19d1205
ZW
24505 elf_frob_symbol (symp, puntp);
24506}
24507#endif
404ff6b5 24508
c19d1205 24509/* MD interface: Finalization. */
a737bd4d 24510
c19d1205
ZW
24511void
24512arm_cleanup (void)
24513{
24514 literal_pool * pool;
a737bd4d 24515
e07e6e58
NC
24516 /* Ensure that all the IT blocks are properly closed. */
24517 check_it_blocks_finished ();
24518
c19d1205
ZW
24519 for (pool = list_of_pools; pool; pool = pool->next)
24520 {
5f4273c7 24521 /* Put it at the end of the relevant section. */
c19d1205
ZW
24522 subseg_set (pool->section, pool->sub_section);
24523#ifdef OBJ_ELF
24524 arm_elf_change_section ();
24525#endif
24526 s_ltorg (0);
24527 }
404ff6b5
AH
24528}
24529
cd000bff
DJ
24530#ifdef OBJ_ELF
24531/* Remove any excess mapping symbols generated for alignment frags in
24532 SEC. We may have created a mapping symbol before a zero byte
24533 alignment; remove it if there's a mapping symbol after the
24534 alignment. */
24535static void
24536check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24537 void *dummy ATTRIBUTE_UNUSED)
24538{
24539 segment_info_type *seginfo = seg_info (sec);
24540 fragS *fragp;
24541
24542 if (seginfo == NULL || seginfo->frchainP == NULL)
24543 return;
24544
24545 for (fragp = seginfo->frchainP->frch_root;
24546 fragp != NULL;
24547 fragp = fragp->fr_next)
24548 {
24549 symbolS *sym = fragp->tc_frag_data.last_map;
24550 fragS *next = fragp->fr_next;
24551
24552 /* Variable-sized frags have been converted to fixed size by
24553 this point. But if this was variable-sized to start with,
24554 there will be a fixed-size frag after it. So don't handle
24555 next == NULL. */
24556 if (sym == NULL || next == NULL)
24557 continue;
24558
24559 if (S_GET_VALUE (sym) < next->fr_address)
24560 /* Not at the end of this frag. */
24561 continue;
24562 know (S_GET_VALUE (sym) == next->fr_address);
24563
24564 do
24565 {
24566 if (next->tc_frag_data.first_map != NULL)
24567 {
24568 /* Next frag starts with a mapping symbol. Discard this
24569 one. */
24570 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24571 break;
24572 }
24573
24574 if (next->fr_next == NULL)
24575 {
24576 /* This mapping symbol is at the end of the section. Discard
24577 it. */
24578 know (next->fr_fix == 0 && next->fr_var == 0);
24579 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24580 break;
24581 }
24582
24583 /* As long as we have empty frags without any mapping symbols,
24584 keep looking. */
24585 /* If the next frag is non-empty and does not start with a
24586 mapping symbol, then this mapping symbol is required. */
24587 if (next->fr_address != next->fr_next->fr_address)
24588 break;
24589
24590 next = next->fr_next;
24591 }
24592 while (next != NULL);
24593 }
24594}
24595#endif
24596
c19d1205
ZW
24597/* Adjust the symbol table. This marks Thumb symbols as distinct from
24598 ARM ones. */
404ff6b5 24599
c19d1205
ZW
24600void
24601arm_adjust_symtab (void)
404ff6b5 24602{
c19d1205
ZW
24603#ifdef OBJ_COFF
24604 symbolS * sym;
404ff6b5 24605
c19d1205
ZW
24606 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24607 {
24608 if (ARM_IS_THUMB (sym))
24609 {
24610 if (THUMB_IS_FUNC (sym))
24611 {
24612 /* Mark the symbol as a Thumb function. */
24613 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24614 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24615 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24616
c19d1205
ZW
24617 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24618 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24619 else
24620 as_bad (_("%s: unexpected function type: %d"),
24621 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24622 }
24623 else switch (S_GET_STORAGE_CLASS (sym))
24624 {
24625 case C_EXT:
24626 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24627 break;
24628 case C_STAT:
24629 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24630 break;
24631 case C_LABEL:
24632 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24633 break;
24634 default:
24635 /* Do nothing. */
24636 break;
24637 }
24638 }
a737bd4d 24639
c19d1205
ZW
24640 if (ARM_IS_INTERWORK (sym))
24641 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24642 }
c19d1205
ZW
24643#endif
24644#ifdef OBJ_ELF
24645 symbolS * sym;
24646 char bind;
404ff6b5 24647
c19d1205 24648 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24649 {
c19d1205
ZW
24650 if (ARM_IS_THUMB (sym))
24651 {
24652 elf_symbol_type * elf_sym;
404ff6b5 24653
c19d1205
ZW
24654 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24655 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24656
b0796911
PB
24657 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24658 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24659 {
24660 /* If it's a .thumb_func, declare it as so,
24661 otherwise tag label as .code 16. */
24662 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
24663 elf_sym->internal_elf_sym.st_target_internal
24664 = ST_BRANCH_TO_THUMB;
3ba67470 24665 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24666 elf_sym->internal_elf_sym.st_info =
24667 ELF_ST_INFO (bind, STT_ARM_16BIT);
24668 }
24669 }
24670 }
cd000bff
DJ
24671
24672 /* Remove any overlapping mapping symbols generated by alignment frags. */
24673 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24674 /* Now do generic ELF adjustments. */
24675 elf_adjust_symtab ();
c19d1205 24676#endif
404ff6b5
AH
24677}
24678
c19d1205 24679/* MD interface: Initialization. */
404ff6b5 24680
a737bd4d 24681static void
c19d1205 24682set_constant_flonums (void)
a737bd4d 24683{
c19d1205 24684 int i;
404ff6b5 24685
c19d1205
ZW
24686 for (i = 0; i < NUM_FLOAT_VALS; i++)
24687 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24688 abort ();
a737bd4d 24689}
404ff6b5 24690
3e9e4fcf
JB
24691/* Auto-select Thumb mode if it's the only available instruction set for the
24692 given architecture. */
24693
24694static void
24695autoselect_thumb_from_cpu_variant (void)
24696{
24697 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24698 opcode_select (16);
24699}
24700
c19d1205
ZW
24701void
24702md_begin (void)
a737bd4d 24703{
c19d1205
ZW
24704 unsigned mach;
24705 unsigned int i;
404ff6b5 24706
c19d1205
ZW
24707 if ( (arm_ops_hsh = hash_new ()) == NULL
24708 || (arm_cond_hsh = hash_new ()) == NULL
24709 || (arm_shift_hsh = hash_new ()) == NULL
24710 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24711 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24712 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24713 || (arm_reloc_hsh = hash_new ()) == NULL
24714 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24715 as_fatal (_("virtual memory exhausted"));
24716
24717 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24718 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24719 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24720 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24721 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24722 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24723 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24724 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24725 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24726 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24727 (void *) (v7m_psrs + i));
c19d1205 24728 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24729 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24730 for (i = 0;
24731 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24732 i++)
d3ce72d0 24733 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24734 (void *) (barrier_opt_names + i));
c19d1205 24735#ifdef OBJ_ELF
3da1d841
NC
24736 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24737 {
24738 struct reloc_entry * entry = reloc_names + i;
24739
24740 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24741 /* This makes encode_branch() use the EABI versions of this relocation. */
24742 entry->reloc = BFD_RELOC_UNUSED;
24743
24744 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24745 }
c19d1205
ZW
24746#endif
24747
24748 set_constant_flonums ();
404ff6b5 24749
c19d1205
ZW
24750 /* Set the cpu variant based on the command-line options. We prefer
24751 -mcpu= over -march= if both are set (as for GCC); and we prefer
24752 -mfpu= over any other way of setting the floating point unit.
24753 Use of legacy options with new options are faulted. */
e74cfd16 24754 if (legacy_cpu)
404ff6b5 24755 {
e74cfd16 24756 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24757 as_bad (_("use of old and new-style options to set CPU type"));
24758
24759 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24760 }
e74cfd16 24761 else if (!mcpu_cpu_opt)
c19d1205 24762 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24763
e74cfd16 24764 if (legacy_fpu)
c19d1205 24765 {
e74cfd16 24766 if (mfpu_opt)
c19d1205 24767 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24768
24769 mfpu_opt = legacy_fpu;
24770 }
e74cfd16 24771 else if (!mfpu_opt)
03b1477f 24772 {
45eb4c1b
NS
24773#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24774 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24775 /* Some environments specify a default FPU. If they don't, infer it
24776 from the processor. */
e74cfd16 24777 if (mcpu_fpu_opt)
03b1477f
RE
24778 mfpu_opt = mcpu_fpu_opt;
24779 else
24780 mfpu_opt = march_fpu_opt;
39c2da32 24781#else
e74cfd16 24782 mfpu_opt = &fpu_default;
39c2da32 24783#endif
03b1477f
RE
24784 }
24785
e74cfd16 24786 if (!mfpu_opt)
03b1477f 24787 {
493cb6ef 24788 if (mcpu_cpu_opt != NULL)
e74cfd16 24789 mfpu_opt = &fpu_default;
493cb6ef 24790 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24791 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24792 else
e74cfd16 24793 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24794 }
24795
ee065d83 24796#ifdef CPU_DEFAULT
e74cfd16 24797 if (!mcpu_cpu_opt)
ee065d83 24798 {
e74cfd16
PB
24799 mcpu_cpu_opt = &cpu_default;
24800 selected_cpu = cpu_default;
ee065d83 24801 }
73f43896
NC
24802 else if (no_cpu_selected ())
24803 selected_cpu = cpu_default;
e74cfd16
PB
24804#else
24805 if (mcpu_cpu_opt)
24806 selected_cpu = *mcpu_cpu_opt;
ee065d83 24807 else
e74cfd16 24808 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24809#endif
03b1477f 24810
e74cfd16 24811 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24812
3e9e4fcf
JB
24813 autoselect_thumb_from_cpu_variant ();
24814
e74cfd16 24815 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24816
f17c130b 24817#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24818 {
7cc69913
NC
24819 unsigned int flags = 0;
24820
24821#if defined OBJ_ELF
24822 flags = meabi_flags;
d507cf36
PB
24823
24824 switch (meabi_flags)
33a392fb 24825 {
d507cf36 24826 case EF_ARM_EABI_UNKNOWN:
7cc69913 24827#endif
d507cf36
PB
24828 /* Set the flags in the private structure. */
24829 if (uses_apcs_26) flags |= F_APCS26;
24830 if (support_interwork) flags |= F_INTERWORK;
24831 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24832 if (pic_code) flags |= F_PIC;
e74cfd16 24833 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24834 flags |= F_SOFT_FLOAT;
24835
d507cf36
PB
24836 switch (mfloat_abi_opt)
24837 {
24838 case ARM_FLOAT_ABI_SOFT:
24839 case ARM_FLOAT_ABI_SOFTFP:
24840 flags |= F_SOFT_FLOAT;
24841 break;
33a392fb 24842
d507cf36
PB
24843 case ARM_FLOAT_ABI_HARD:
24844 if (flags & F_SOFT_FLOAT)
24845 as_bad (_("hard-float conflicts with specified fpu"));
24846 break;
24847 }
03b1477f 24848
e74cfd16
PB
24849 /* Using pure-endian doubles (even if soft-float). */
24850 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24851 flags |= F_VFP_FLOAT;
f17c130b 24852
fde78edd 24853#if defined OBJ_ELF
e74cfd16 24854 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24855 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24856 break;
24857
8cb51566 24858 case EF_ARM_EABI_VER4:
3a4a14e9 24859 case EF_ARM_EABI_VER5:
c19d1205 24860 /* No additional flags to set. */
d507cf36
PB
24861 break;
24862
24863 default:
24864 abort ();
24865 }
7cc69913 24866#endif
b99bd4ef
NC
24867 bfd_set_private_flags (stdoutput, flags);
24868
24869 /* We have run out flags in the COFF header to encode the
24870 status of ATPCS support, so instead we create a dummy,
c19d1205 24871 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24872 if (atpcs)
24873 {
24874 asection * sec;
24875
24876 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24877
24878 if (sec != NULL)
24879 {
24880 bfd_set_section_flags
24881 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24882 bfd_set_section_size (stdoutput, sec, 0);
24883 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24884 }
24885 }
7cc69913 24886 }
f17c130b 24887#endif
b99bd4ef
NC
24888
24889 /* Record the CPU type as well. */
2d447fca
JM
24890 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24891 mach = bfd_mach_arm_iWMMXt2;
24892 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24893 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24894 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24895 mach = bfd_mach_arm_XScale;
e74cfd16 24896 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24897 mach = bfd_mach_arm_ep9312;
e74cfd16 24898 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24899 mach = bfd_mach_arm_5TE;
e74cfd16 24900 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24901 {
e74cfd16 24902 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24903 mach = bfd_mach_arm_5T;
24904 else
24905 mach = bfd_mach_arm_5;
24906 }
e74cfd16 24907 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24908 {
e74cfd16 24909 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24910 mach = bfd_mach_arm_4T;
24911 else
24912 mach = bfd_mach_arm_4;
24913 }
e74cfd16 24914 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24915 mach = bfd_mach_arm_3M;
e74cfd16
PB
24916 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24917 mach = bfd_mach_arm_3;
24918 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24919 mach = bfd_mach_arm_2a;
24920 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24921 mach = bfd_mach_arm_2;
24922 else
24923 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24924
24925 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24926}
24927
c19d1205 24928/* Command line processing. */
b99bd4ef 24929
c19d1205
ZW
24930/* md_parse_option
24931 Invocation line includes a switch not recognized by the base assembler.
24932 See if it's a processor-specific option.
b99bd4ef 24933
c19d1205
ZW
24934 This routine is somewhat complicated by the need for backwards
24935 compatibility (since older releases of gcc can't be changed).
24936 The new options try to make the interface as compatible as
24937 possible with GCC.
b99bd4ef 24938
c19d1205 24939 New options (supported) are:
b99bd4ef 24940
c19d1205
ZW
24941 -mcpu=<cpu name> Assemble for selected processor
24942 -march=<architecture name> Assemble for selected architecture
24943 -mfpu=<fpu architecture> Assemble for selected FPU.
24944 -EB/-mbig-endian Big-endian
24945 -EL/-mlittle-endian Little-endian
24946 -k Generate PIC code
24947 -mthumb Start in Thumb mode
24948 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24949
278df34e 24950 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24951 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24952
c19d1205 24953 For now we will also provide support for:
b99bd4ef 24954
c19d1205
ZW
24955 -mapcs-32 32-bit Program counter
24956 -mapcs-26 26-bit Program counter
24957 -macps-float Floats passed in FP registers
24958 -mapcs-reentrant Reentrant code
24959 -matpcs
24960 (sometime these will probably be replaced with -mapcs=<list of options>
24961 and -matpcs=<list of options>)
b99bd4ef 24962
c19d1205
ZW
24963 The remaining options are only supported for back-wards compatibility.
24964 Cpu variants, the arm part is optional:
24965 -m[arm]1 Currently not supported.
24966 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24967 -m[arm]3 Arm 3 processor
24968 -m[arm]6[xx], Arm 6 processors
24969 -m[arm]7[xx][t][[d]m] Arm 7 processors
24970 -m[arm]8[10] Arm 8 processors
24971 -m[arm]9[20][tdmi] Arm 9 processors
24972 -mstrongarm[110[0]] StrongARM processors
24973 -mxscale XScale processors
24974 -m[arm]v[2345[t[e]]] Arm architectures
24975 -mall All (except the ARM1)
24976 FP variants:
24977 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24978 -mfpe-old (No float load/store multiples)
24979 -mvfpxd VFP Single precision
24980 -mvfp All VFP
24981 -mno-fpu Disable all floating point instructions
b99bd4ef 24982
c19d1205
ZW
24983 The following CPU names are recognized:
24984 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24985 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24986 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24987 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24988 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24989 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24990 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24991
c19d1205 24992 */
b99bd4ef 24993
c19d1205 24994const char * md_shortopts = "m:k";
b99bd4ef 24995
c19d1205
ZW
24996#ifdef ARM_BI_ENDIAN
24997#define OPTION_EB (OPTION_MD_BASE + 0)
24998#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24999#else
c19d1205
ZW
25000#if TARGET_BYTES_BIG_ENDIAN
25001#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25002#else
c19d1205
ZW
25003#define OPTION_EL (OPTION_MD_BASE + 1)
25004#endif
b99bd4ef 25005#endif
845b51d6 25006#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25007
c19d1205 25008struct option md_longopts[] =
b99bd4ef 25009{
c19d1205
ZW
25010#ifdef OPTION_EB
25011 {"EB", no_argument, NULL, OPTION_EB},
25012#endif
25013#ifdef OPTION_EL
25014 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25015#endif
845b51d6 25016 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25017 {NULL, no_argument, NULL, 0}
25018};
b99bd4ef 25019
8b2d793c 25020
c19d1205 25021size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25022
c19d1205 25023struct arm_option_table
b99bd4ef 25024{
e0471c16
TS
25025 const char *option; /* Option name to match. */
25026 const char *help; /* Help information. */
c19d1205
ZW
25027 int *var; /* Variable to change. */
25028 int value; /* What to change it to. */
e0471c16 25029 const char *deprecated; /* If non-null, print this message. */
c19d1205 25030};
b99bd4ef 25031
c19d1205
ZW
25032struct arm_option_table arm_opts[] =
25033{
25034 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25035 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25036 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25037 &support_interwork, 1, NULL},
25038 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25039 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25040 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25041 1, NULL},
25042 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25043 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25044 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25045 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25046 NULL},
b99bd4ef 25047
c19d1205
ZW
25048 /* These are recognized by the assembler, but have no affect on code. */
25049 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25050 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25051
25052 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25053 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25054 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25055 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25056 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25057 {NULL, NULL, NULL, 0, NULL}
25058};
25059
25060struct arm_legacy_option_table
25061{
e0471c16 25062 const char *option; /* Option name to match. */
e74cfd16
PB
25063 const arm_feature_set **var; /* Variable to change. */
25064 const arm_feature_set value; /* What to change it to. */
e0471c16 25065 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25066};
b99bd4ef 25067
e74cfd16
PB
25068const struct arm_legacy_option_table arm_legacy_opts[] =
25069{
c19d1205
ZW
25070 /* DON'T add any new processors to this list -- we want the whole list
25071 to go away... Add them to the processors table instead. */
e74cfd16
PB
25072 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25073 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25074 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25075 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25076 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25077 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25078 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25079 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25080 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25081 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25082 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25083 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25084 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25085 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25086 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25087 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25088 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25089 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25090 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25091 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25092 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25093 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25094 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25095 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25096 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25097 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25098 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25099 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25100 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25101 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25102 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25103 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25104 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25105 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25106 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25107 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25108 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25109 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25110 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25111 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25112 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25113 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25114 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25115 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25116 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25117 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25118 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25119 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25120 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25121 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25122 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25123 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25124 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25125 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25126 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25127 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25128 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25129 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25130 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25131 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25132 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25133 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25134 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25135 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25136 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25137 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25138 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25139 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25140 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25141 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25142 N_("use -mcpu=strongarm110")},
e74cfd16 25143 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25144 N_("use -mcpu=strongarm1100")},
e74cfd16 25145 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25146 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25147 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25148 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25149 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25150
c19d1205 25151 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25152 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25153 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25154 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25155 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25156 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25157 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25158 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25159 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25160 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25161 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25162 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25163 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25164 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25165 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25166 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25167 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25168 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25169 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25170
c19d1205 25171 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25172 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25173 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25174 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25175 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25176 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25177
e74cfd16 25178 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25179};
7ed4c4c5 25180
c19d1205 25181struct arm_cpu_option_table
7ed4c4c5 25182{
e0471c16 25183 const char *name;
f3bad469 25184 size_t name_len;
e74cfd16 25185 const arm_feature_set value;
c19d1205
ZW
25186 /* For some CPUs we assume an FPU unless the user explicitly sets
25187 -mfpu=... */
e74cfd16 25188 const arm_feature_set default_fpu;
ee065d83
PB
25189 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25190 case. */
25191 const char *canonical_name;
c19d1205 25192};
7ed4c4c5 25193
c19d1205
ZW
25194/* This list should, at a minimum, contain all the cpu names
25195 recognized by GCC. */
f3bad469 25196#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25197static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25198{
f3bad469
MGD
25199 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25200 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25201 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25202 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25203 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25204 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25205 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25206 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25207 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25208 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25209 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25210 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25211 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25212 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25213 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25214 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25215 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25216 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25217 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25218 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25219 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25220 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25221 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25222 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25223 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25224 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25225 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25226 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25227 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25228 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25229 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25230 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25231 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25232 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25233 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25234 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25235 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25236 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25237 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25238 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25239 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25240 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25241 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25242 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25243 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25244 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25245 /* For V5 or later processors we default to using VFP; but the user
25246 should really set the FPU type explicitly. */
f3bad469
MGD
25247 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25248 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25249 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25250 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25251 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25252 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25253 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25254 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25255 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25256 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25257 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25258 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25259 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25260 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25261 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25262 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25263 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25264 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25265 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25266 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25267 "ARM1026EJ-S"),
25268 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25269 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25270 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25271 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25272 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25273 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25274 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25275 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25276 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25277 "ARM1136JF-S"),
25278 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25279 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25280 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25281 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25282 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25283 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25284 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25285 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25286 FPU_NONE, "Cortex-A5"),
c9fb6e58 25287 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25288 "Cortex-A7"),
25289 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25290 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25291 | FPU_NEON_EXT_V1),
f3bad469
MGD
25292 "Cortex-A8"),
25293 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25294 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25295 | FPU_NEON_EXT_V1),
f3bad469 25296 "Cortex-A9"),
c9fb6e58 25297 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25298 "Cortex-A12"),
c9fb6e58 25299 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25300 "Cortex-A15"),
d7adf960
KT
25301 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25302 "Cortex-A17"),
6735952f
KT
25303 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25304 "Cortex-A32"),
43cdc0a8
RR
25305 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25306 "Cortex-A35"),
92eb40d9 25307 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25308 "Cortex-A53"),
92eb40d9 25309 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25310 "Cortex-A57"),
b19f47ad
JW
25311 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25312 "Cortex-A72"),
f3bad469
MGD
25313 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25314 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25315 "Cortex-R4F"),
25316 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25317 FPU_NONE, "Cortex-R5"),
70a8bc5b 25318 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25319 FPU_ARCH_VFP_V3D16,
25320 "Cortex-R7"),
5f474010
TP
25321 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25322 FPU_ARCH_VFP_V3D16,
25323 "Cortex-R8"),
a715796b 25324 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25325 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25326 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25327 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25328 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25329 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
25330 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25331 "Samsung " \
25332 "Exynos M1"),
6b21c2bf
JW
25333 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25334 "Qualcomm "
25335 "QDF24XX"),
25336
c19d1205 25337 /* ??? XSCALE is really an architecture. */
f3bad469 25338 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25339 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25340 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25341 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25342 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25343 /* Maverick */
823d2571 25344 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25345 FPU_ARCH_MAVERICK, "ARM920T"),
25346 /* Marvell processors. */
ff8646ee
TP
25347 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25348 | ARM_EXT_SEC,
25349 ARM_EXT2_V6T2_V8M),
477330fc 25350 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25351 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25352 | ARM_EXT_SEC,
25353 ARM_EXT2_V6T2_V8M),
4347085a 25354 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25355 /* APM X-Gene family. */
25356 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25357 "APM X-Gene 1"),
25358 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25359 "APM X-Gene 2"),
da4339ed 25360
f3bad469 25361 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25362};
f3bad469 25363#undef ARM_CPU_OPT
7ed4c4c5 25364
c19d1205 25365struct arm_arch_option_table
7ed4c4c5 25366{
e0471c16 25367 const char *name;
f3bad469 25368 size_t name_len;
e74cfd16
PB
25369 const arm_feature_set value;
25370 const arm_feature_set default_fpu;
c19d1205 25371};
7ed4c4c5 25372
c19d1205
ZW
25373/* This list should, at a minimum, contain all the architecture names
25374 recognized by GCC. */
f3bad469 25375#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25376static const struct arm_arch_option_table arm_archs[] =
c19d1205 25377{
f3bad469
MGD
25378 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25379 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25380 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25381 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25382 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25383 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25384 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25385 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25386 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25387 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25388 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25389 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25390 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25391 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25392 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25393 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25394 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25395 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25396 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25397 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25398 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25399 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25400 kept to preserve existing behaviour. */
25401 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25402 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25403 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25404 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25405 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25406 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25407 kept to preserve existing behaviour. */
25408 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25409 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25410 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25411 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25412 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25413 /* The official spelling of the ARMv7 profile variants is the dashed form.
25414 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25415 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25416 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25417 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25418 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25419 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25420 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25421 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25422 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25423 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25424 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25425 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25426 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25427 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
25428 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25429 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25430 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25431 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25432};
f3bad469 25433#undef ARM_ARCH_OPT
7ed4c4c5 25434
69133863
MGD
25435/* ISA extensions in the co-processor and main instruction set space. */
25436struct arm_option_extension_value_table
c19d1205 25437{
e0471c16 25438 const char *name;
f3bad469 25439 size_t name_len;
5a70a223
JB
25440 const arm_feature_set merge_value;
25441 const arm_feature_set clear_value;
69133863 25442 const arm_feature_set allowed_archs;
c19d1205 25443};
7ed4c4c5 25444
69133863
MGD
25445/* The following table must be in alphabetical order with a NULL last entry.
25446 */
5a70a223 25447#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 25448static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25449{
823d2571
TG
25450 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25451 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25452 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25453 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25454 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
25455 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25456 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25457 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25458 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25459 ARM_ARCH_V8_2A),
823d2571
TG
25460 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25461 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
25462 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
25463 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
25464 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
25465 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
25466 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
25467 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
25468 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
25469 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25470 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
25471 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
823d2571
TG
25472 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25473 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25474 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25475 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25476 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25477 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25478 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25479 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25480 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25481 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25482 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25483 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
643afb90
MW
25484 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25485 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25486 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25487 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25488 | ARM_EXT_DIV),
25489 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25490 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25491 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
25492 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 25493 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 25494};
f3bad469 25495#undef ARM_EXT_OPT
69133863
MGD
25496
25497/* ISA floating-point and Advanced SIMD extensions. */
25498struct arm_option_fpu_value_table
25499{
e0471c16 25500 const char *name;
69133863 25501 const arm_feature_set value;
c19d1205 25502};
7ed4c4c5 25503
c19d1205
ZW
25504/* This list should, at a minimum, contain all the fpu names
25505 recognized by GCC. */
69133863 25506static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25507{
25508 {"softfpa", FPU_NONE},
25509 {"fpe", FPU_ARCH_FPE},
25510 {"fpe2", FPU_ARCH_FPE},
25511 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25512 {"fpa", FPU_ARCH_FPA},
25513 {"fpa10", FPU_ARCH_FPA},
25514 {"fpa11", FPU_ARCH_FPA},
25515 {"arm7500fe", FPU_ARCH_FPA},
25516 {"softvfp", FPU_ARCH_VFP},
25517 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25518 {"vfp", FPU_ARCH_VFP_V2},
25519 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25520 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25521 {"vfp10", FPU_ARCH_VFP_V2},
25522 {"vfp10-r0", FPU_ARCH_VFP_V1},
25523 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25524 {"vfpv2", FPU_ARCH_VFP_V2},
25525 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25526 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25527 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25528 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25529 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25530 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25531 {"arm1020t", FPU_ARCH_VFP_V1},
25532 {"arm1020e", FPU_ARCH_VFP_V2},
25533 {"arm1136jfs", FPU_ARCH_VFP_V2},
25534 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25535 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25536 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25537 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25538 {"vfpv4", FPU_ARCH_VFP_V4},
25539 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25540 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25541 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25542 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25543 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25544 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25545 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25546 {"crypto-neon-fp-armv8",
25547 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25548 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25549 {"crypto-neon-fp-armv8.1",
25550 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25551 {NULL, ARM_ARCH_NONE}
25552};
25553
25554struct arm_option_value_table
25555{
e0471c16 25556 const char *name;
e74cfd16 25557 long value;
c19d1205 25558};
7ed4c4c5 25559
e74cfd16 25560static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25561{
25562 {"hard", ARM_FLOAT_ABI_HARD},
25563 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25564 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25565 {NULL, 0}
c19d1205 25566};
7ed4c4c5 25567
c19d1205 25568#ifdef OBJ_ELF
3a4a14e9 25569/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25570static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25571{
25572 {"gnu", EF_ARM_EABI_UNKNOWN},
25573 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25574 {"5", EF_ARM_EABI_VER5},
e74cfd16 25575 {NULL, 0}
c19d1205
ZW
25576};
25577#endif
7ed4c4c5 25578
c19d1205
ZW
25579struct arm_long_option_table
25580{
e0471c16
TS
25581 const char * option; /* Substring to match. */
25582 const char * help; /* Help information. */
17b9d67d 25583 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 25584 const char * deprecated; /* If non-null, print this message. */
c19d1205 25585};
7ed4c4c5 25586
c921be7d 25587static bfd_boolean
82b8a785 25588arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 25589{
325801bd 25590 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 25591
69133863 25592 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25593 extensions being added before being removed. We achieve this by having
25594 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25595 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25596 or removing it (0) and only allowing it to change in the order
69133863
MGD
25597 -1 -> 1 -> 0. */
25598 const struct arm_option_extension_value_table * opt = NULL;
25599 int adding_value = -1;
25600
e74cfd16
PB
25601 /* Copy the feature set, so that we can modify it. */
25602 *ext_set = **opt_p;
25603 *opt_p = ext_set;
25604
c19d1205 25605 while (str != NULL && *str != 0)
7ed4c4c5 25606 {
82b8a785 25607 const char *ext;
f3bad469 25608 size_t len;
7ed4c4c5 25609
c19d1205
ZW
25610 if (*str != '+')
25611 {
25612 as_bad (_("invalid architectural extension"));
c921be7d 25613 return FALSE;
c19d1205 25614 }
7ed4c4c5 25615
c19d1205
ZW
25616 str++;
25617 ext = strchr (str, '+');
7ed4c4c5 25618
c19d1205 25619 if (ext != NULL)
f3bad469 25620 len = ext - str;
c19d1205 25621 else
f3bad469 25622 len = strlen (str);
7ed4c4c5 25623
f3bad469 25624 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25625 {
25626 if (adding_value != 0)
25627 {
25628 adding_value = 0;
25629 opt = arm_extensions;
25630 }
25631
f3bad469 25632 len -= 2;
69133863
MGD
25633 str += 2;
25634 }
f3bad469 25635 else if (len > 0)
69133863
MGD
25636 {
25637 if (adding_value == -1)
25638 {
25639 adding_value = 1;
25640 opt = arm_extensions;
25641 }
25642 else if (adding_value != 1)
25643 {
25644 as_bad (_("must specify extensions to add before specifying "
25645 "those to remove"));
25646 return FALSE;
25647 }
25648 }
25649
f3bad469 25650 if (len == 0)
c19d1205
ZW
25651 {
25652 as_bad (_("missing architectural extension"));
c921be7d 25653 return FALSE;
c19d1205 25654 }
7ed4c4c5 25655
69133863
MGD
25656 gas_assert (adding_value != -1);
25657 gas_assert (opt != NULL);
25658
25659 /* Scan over the options table trying to find an exact match. */
25660 for (; opt->name != NULL; opt++)
f3bad469 25661 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25662 {
69133863
MGD
25663 /* Check we can apply the extension to this architecture. */
25664 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
25665 {
25666 as_bad (_("extension does not apply to the base architecture"));
25667 return FALSE;
25668 }
25669
25670 /* Add or remove the extension. */
25671 if (adding_value)
5a70a223 25672 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25673 else
5a70a223 25674 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25675
c19d1205
ZW
25676 break;
25677 }
7ed4c4c5 25678
c19d1205
ZW
25679 if (opt->name == NULL)
25680 {
69133863
MGD
25681 /* Did we fail to find an extension because it wasn't specified in
25682 alphabetical order, or because it does not exist? */
25683
25684 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25685 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25686 break;
25687
25688 if (opt->name == NULL)
25689 as_bad (_("unknown architectural extension `%s'"), str);
25690 else
25691 as_bad (_("architectural extensions must be specified in "
25692 "alphabetical order"));
25693
c921be7d 25694 return FALSE;
c19d1205 25695 }
69133863
MGD
25696 else
25697 {
25698 /* We should skip the extension we've just matched the next time
25699 round. */
25700 opt++;
25701 }
7ed4c4c5 25702
c19d1205
ZW
25703 str = ext;
25704 };
7ed4c4c5 25705
c921be7d 25706 return TRUE;
c19d1205 25707}
7ed4c4c5 25708
c921be7d 25709static bfd_boolean
17b9d67d 25710arm_parse_cpu (const char *str)
7ed4c4c5 25711{
f3bad469 25712 const struct arm_cpu_option_table *opt;
82b8a785 25713 const char *ext = strchr (str, '+');
f3bad469 25714 size_t len;
7ed4c4c5 25715
c19d1205 25716 if (ext != NULL)
f3bad469 25717 len = ext - str;
7ed4c4c5 25718 else
f3bad469 25719 len = strlen (str);
7ed4c4c5 25720
f3bad469 25721 if (len == 0)
7ed4c4c5 25722 {
c19d1205 25723 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25724 return FALSE;
7ed4c4c5
NC
25725 }
25726
c19d1205 25727 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25728 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25729 {
e74cfd16
PB
25730 mcpu_cpu_opt = &opt->value;
25731 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25732 if (opt->canonical_name)
ef8e6722
JW
25733 {
25734 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25735 strcpy (selected_cpu_name, opt->canonical_name);
25736 }
ee065d83
PB
25737 else
25738 {
f3bad469 25739 size_t i;
c921be7d 25740
ef8e6722
JW
25741 if (len >= sizeof selected_cpu_name)
25742 len = (sizeof selected_cpu_name) - 1;
25743
f3bad469 25744 for (i = 0; i < len; i++)
ee065d83
PB
25745 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25746 selected_cpu_name[i] = 0;
25747 }
7ed4c4c5 25748
c19d1205
ZW
25749 if (ext != NULL)
25750 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25751
c921be7d 25752 return TRUE;
c19d1205 25753 }
7ed4c4c5 25754
c19d1205 25755 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25756 return FALSE;
7ed4c4c5
NC
25757}
25758
c921be7d 25759static bfd_boolean
17b9d67d 25760arm_parse_arch (const char *str)
7ed4c4c5 25761{
e74cfd16 25762 const struct arm_arch_option_table *opt;
82b8a785 25763 const char *ext = strchr (str, '+');
f3bad469 25764 size_t len;
7ed4c4c5 25765
c19d1205 25766 if (ext != NULL)
f3bad469 25767 len = ext - str;
7ed4c4c5 25768 else
f3bad469 25769 len = strlen (str);
7ed4c4c5 25770
f3bad469 25771 if (len == 0)
7ed4c4c5 25772 {
c19d1205 25773 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25774 return FALSE;
7ed4c4c5
NC
25775 }
25776
c19d1205 25777 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25778 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25779 {
e74cfd16
PB
25780 march_cpu_opt = &opt->value;
25781 march_fpu_opt = &opt->default_fpu;
5f4273c7 25782 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25783
c19d1205
ZW
25784 if (ext != NULL)
25785 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25786
c921be7d 25787 return TRUE;
c19d1205
ZW
25788 }
25789
25790 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25791 return FALSE;
7ed4c4c5 25792}
eb043451 25793
c921be7d 25794static bfd_boolean
17b9d67d 25795arm_parse_fpu (const char * str)
c19d1205 25796{
69133863 25797 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25798
c19d1205
ZW
25799 for (opt = arm_fpus; opt->name != NULL; opt++)
25800 if (streq (opt->name, str))
25801 {
e74cfd16 25802 mfpu_opt = &opt->value;
c921be7d 25803 return TRUE;
c19d1205 25804 }
b99bd4ef 25805
c19d1205 25806 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25807 return FALSE;
c19d1205
ZW
25808}
25809
c921be7d 25810static bfd_boolean
17b9d67d 25811arm_parse_float_abi (const char * str)
b99bd4ef 25812{
e74cfd16 25813 const struct arm_option_value_table * opt;
b99bd4ef 25814
c19d1205
ZW
25815 for (opt = arm_float_abis; opt->name != NULL; opt++)
25816 if (streq (opt->name, str))
25817 {
25818 mfloat_abi_opt = opt->value;
c921be7d 25819 return TRUE;
c19d1205 25820 }
cc8a6dd0 25821
c19d1205 25822 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25823 return FALSE;
c19d1205 25824}
b99bd4ef 25825
c19d1205 25826#ifdef OBJ_ELF
c921be7d 25827static bfd_boolean
17b9d67d 25828arm_parse_eabi (const char * str)
c19d1205 25829{
e74cfd16 25830 const struct arm_option_value_table *opt;
cc8a6dd0 25831
c19d1205
ZW
25832 for (opt = arm_eabis; opt->name != NULL; opt++)
25833 if (streq (opt->name, str))
25834 {
25835 meabi_flags = opt->value;
c921be7d 25836 return TRUE;
c19d1205
ZW
25837 }
25838 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25839 return FALSE;
c19d1205
ZW
25840}
25841#endif
cc8a6dd0 25842
c921be7d 25843static bfd_boolean
17b9d67d 25844arm_parse_it_mode (const char * str)
e07e6e58 25845{
c921be7d 25846 bfd_boolean ret = TRUE;
e07e6e58
NC
25847
25848 if (streq ("arm", str))
25849 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25850 else if (streq ("thumb", str))
25851 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25852 else if (streq ("always", str))
25853 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25854 else if (streq ("never", str))
25855 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25856 else
25857 {
25858 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25859 "arm, thumb, always, or never."), str);
c921be7d 25860 ret = FALSE;
e07e6e58
NC
25861 }
25862
25863 return ret;
25864}
25865
2e6976a8 25866static bfd_boolean
17b9d67d 25867arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
25868{
25869 codecomposer_syntax = TRUE;
25870 arm_comment_chars[0] = ';';
25871 arm_line_separator_chars[0] = 0;
25872 return TRUE;
25873}
25874
c19d1205
ZW
25875struct arm_long_option_table arm_long_opts[] =
25876{
25877 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25878 arm_parse_cpu, NULL},
25879 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25880 arm_parse_arch, NULL},
25881 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25882 arm_parse_fpu, NULL},
25883 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25884 arm_parse_float_abi, NULL},
25885#ifdef OBJ_ELF
7fac0536 25886 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25887 arm_parse_eabi, NULL},
25888#endif
e07e6e58
NC
25889 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25890 arm_parse_it_mode, NULL},
2e6976a8
DG
25891 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25892 arm_ccs_mode, NULL},
c19d1205
ZW
25893 {NULL, NULL, 0, NULL}
25894};
cc8a6dd0 25895
c19d1205 25896int
17b9d67d 25897md_parse_option (int c, const char * arg)
c19d1205
ZW
25898{
25899 struct arm_option_table *opt;
e74cfd16 25900 const struct arm_legacy_option_table *fopt;
c19d1205 25901 struct arm_long_option_table *lopt;
b99bd4ef 25902
c19d1205 25903 switch (c)
b99bd4ef 25904 {
c19d1205
ZW
25905#ifdef OPTION_EB
25906 case OPTION_EB:
25907 target_big_endian = 1;
25908 break;
25909#endif
cc8a6dd0 25910
c19d1205
ZW
25911#ifdef OPTION_EL
25912 case OPTION_EL:
25913 target_big_endian = 0;
25914 break;
25915#endif
b99bd4ef 25916
845b51d6
PB
25917 case OPTION_FIX_V4BX:
25918 fix_v4bx = TRUE;
25919 break;
25920
c19d1205
ZW
25921 case 'a':
25922 /* Listing option. Just ignore these, we don't support additional
25923 ones. */
25924 return 0;
b99bd4ef 25925
c19d1205
ZW
25926 default:
25927 for (opt = arm_opts; opt->option != NULL; opt++)
25928 {
25929 if (c == opt->option[0]
25930 && ((arg == NULL && opt->option[1] == 0)
25931 || streq (arg, opt->option + 1)))
25932 {
c19d1205 25933 /* If the option is deprecated, tell the user. */
278df34e 25934 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25935 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25936 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25937
c19d1205
ZW
25938 if (opt->var != NULL)
25939 *opt->var = opt->value;
cc8a6dd0 25940
c19d1205
ZW
25941 return 1;
25942 }
25943 }
b99bd4ef 25944
e74cfd16
PB
25945 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25946 {
25947 if (c == fopt->option[0]
25948 && ((arg == NULL && fopt->option[1] == 0)
25949 || streq (arg, fopt->option + 1)))
25950 {
e74cfd16 25951 /* If the option is deprecated, tell the user. */
278df34e 25952 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25953 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25954 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25955
25956 if (fopt->var != NULL)
25957 *fopt->var = &fopt->value;
25958
25959 return 1;
25960 }
25961 }
25962
c19d1205
ZW
25963 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25964 {
25965 /* These options are expected to have an argument. */
25966 if (c == lopt->option[0]
25967 && arg != NULL
25968 && strncmp (arg, lopt->option + 1,
25969 strlen (lopt->option + 1)) == 0)
25970 {
c19d1205 25971 /* If the option is deprecated, tell the user. */
278df34e 25972 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25973 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25974 _(lopt->deprecated));
b99bd4ef 25975
c19d1205
ZW
25976 /* Call the sup-option parser. */
25977 return lopt->func (arg + strlen (lopt->option) - 1);
25978 }
25979 }
a737bd4d 25980
c19d1205
ZW
25981 return 0;
25982 }
a394c00f 25983
c19d1205
ZW
25984 return 1;
25985}
a394c00f 25986
c19d1205
ZW
25987void
25988md_show_usage (FILE * fp)
a394c00f 25989{
c19d1205
ZW
25990 struct arm_option_table *opt;
25991 struct arm_long_option_table *lopt;
a394c00f 25992
c19d1205 25993 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25994
c19d1205
ZW
25995 for (opt = arm_opts; opt->option != NULL; opt++)
25996 if (opt->help != NULL)
25997 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25998
c19d1205
ZW
25999 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26000 if (lopt->help != NULL)
26001 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26002
c19d1205
ZW
26003#ifdef OPTION_EB
26004 fprintf (fp, _("\
26005 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26006#endif
26007
c19d1205
ZW
26008#ifdef OPTION_EL
26009 fprintf (fp, _("\
26010 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26011#endif
845b51d6
PB
26012
26013 fprintf (fp, _("\
26014 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26015}
ee065d83
PB
26016
26017
26018#ifdef OBJ_ELF
62b3e311
PB
26019typedef struct
26020{
26021 int val;
26022 arm_feature_set flags;
26023} cpu_arch_ver_table;
26024
4ed7ed8d
TP
26025/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26026 must be sorted least features first but some reordering is needed, eg. for
26027 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26028static const cpu_arch_ver_table cpu_arch_ver[] =
26029{
26030 {1, ARM_ARCH_V4},
26031 {2, ARM_ARCH_V4T},
26032 {3, ARM_ARCH_V5},
ee3c0378 26033 {3, ARM_ARCH_V5T},
62b3e311
PB
26034 {4, ARM_ARCH_V5TE},
26035 {5, ARM_ARCH_V5TEJ},
26036 {6, ARM_ARCH_V6},
7e806470 26037 {9, ARM_ARCH_V6K},
f4c65163 26038 {7, ARM_ARCH_V6Z},
91e22acd 26039 {11, ARM_ARCH_V6M},
b2a5fbdc 26040 {12, ARM_ARCH_V6SM},
7e806470 26041 {8, ARM_ARCH_V6T2},
c9fb6e58 26042 {10, ARM_ARCH_V7VE},
62b3e311
PB
26043 {10, ARM_ARCH_V7R},
26044 {10, ARM_ARCH_V7M},
bca38921 26045 {14, ARM_ARCH_V8A},
ff8646ee 26046 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26047 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26048 {0, ARM_ARCH_NONE}
26049};
26050
ee3c0378
AS
26051/* Set an attribute if it has not already been set by the user. */
26052static void
26053aeabi_set_attribute_int (int tag, int value)
26054{
26055 if (tag < 1
26056 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26057 || !attributes_set_explicitly[tag])
26058 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26059}
26060
26061static void
26062aeabi_set_attribute_string (int tag, const char *value)
26063{
26064 if (tag < 1
26065 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26066 || !attributes_set_explicitly[tag])
26067 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26068}
26069
ee065d83 26070/* Set the public EABI object attributes. */
3cfdb781 26071void
ee065d83
PB
26072aeabi_set_public_attributes (void)
26073{
26074 int arch;
69239280 26075 char profile;
90ec0d68 26076 int virt_sec = 0;
bca38921 26077 int fp16_optional = 0;
e74cfd16 26078 arm_feature_set flags;
62b3e311 26079 arm_feature_set tmp;
ff8646ee 26080 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26081 const cpu_arch_ver_table *p;
ee065d83
PB
26082
26083 /* Choose the architecture based on the capabilities of the requested cpu
26084 (if any) and/or the instructions actually used. */
e74cfd16
PB
26085 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26086 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26087 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26088
26089 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26090 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26091
26092 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26093 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26094
7f78eb34
JW
26095 selected_cpu = flags;
26096
ddd7f988 26097 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26098 if (object_arch)
26099 {
26100 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26101 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26102 }
26103
251665fc
MGD
26104 /* We need to make sure that the attributes do not identify us as v6S-M
26105 when the only v6S-M feature in use is the Operating System Extensions. */
26106 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26107 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26108 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26109
62b3e311
PB
26110 tmp = flags;
26111 arch = 0;
26112 for (p = cpu_arch_ver; p->val; p++)
26113 {
26114 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26115 {
26116 arch = p->val;
26117 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26118 }
26119 }
ee065d83 26120
9e3c6df6
PB
26121 /* The table lookup above finds the last architecture to contribute
26122 a new feature. Unfortunately, Tag13 is a subset of the union of
26123 v6T2 and v7-M, so it is never seen as contributing a new feature.
26124 We can not search for the last entry which is entirely used,
26125 because if no CPU is specified we build up only those flags
26126 actually used. Perhaps we should separate out the specified
26127 and implicit cases. Avoid taking this path for -march=all by
26128 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26129 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26130 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26131 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26132 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
4ed7ed8d
TP
26133 arch = TAG_CPU_ARCH_V7E_M;
26134
ff8646ee
TP
26135 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26136 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
26137 arch = TAG_CPU_ARCH_V8M_MAIN;
26138
4ed7ed8d
TP
26139 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26140 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26141 ARMv8-M, -march=all must be detected as ARMv8-A. */
26142 if (arch == TAG_CPU_ARCH_V8M_MAIN
26143 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
26144 arch = TAG_CPU_ARCH_V8;
9e3c6df6 26145
ee065d83
PB
26146 /* Tag_CPU_name. */
26147 if (selected_cpu_name[0])
26148 {
91d6fa6a 26149 char *q;
ee065d83 26150
91d6fa6a
NC
26151 q = selected_cpu_name;
26152 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26153 {
26154 int i;
5f4273c7 26155
91d6fa6a
NC
26156 q += 4;
26157 for (i = 0; q[i]; i++)
26158 q[i] = TOUPPER (q[i]);
ee065d83 26159 }
91d6fa6a 26160 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26161 }
62f3b8c8 26162
ee065d83 26163 /* Tag_CPU_arch. */
ee3c0378 26164 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26165
62b3e311 26166 /* Tag_CPU_arch_profile. */
10c9892b 26167 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26168 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26169 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
26170 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)))
69239280 26171 profile = 'A';
62b3e311 26172 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26173 profile = 'R';
7e806470 26174 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26175 profile = 'M';
26176 else
26177 profile = '\0';
26178
26179 if (profile != '\0')
26180 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26181
ee065d83 26182 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26183 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26184 || arch == 0)
26185 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26186
ee065d83 26187 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26188 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26189 || arch == 0)
4ed7ed8d
TP
26190 {
26191 int thumb_isa_use;
26192
26193 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26194 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
26195 thumb_isa_use = 3;
26196 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26197 thumb_isa_use = 2;
26198 else
26199 thumb_isa_use = 1;
26200 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26201 }
62f3b8c8 26202
ee065d83 26203 /* Tag_VFP_arch. */
a715796b
TG
26204 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26205 aeabi_set_attribute_int (Tag_VFP_arch,
26206 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26207 ? 7 : 8);
bca38921 26208 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26209 aeabi_set_attribute_int (Tag_VFP_arch,
26210 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26211 ? 5 : 6);
26212 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26213 {
26214 fp16_optional = 1;
26215 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26216 }
ada65aa3 26217 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26218 {
26219 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26220 fp16_optional = 1;
26221 }
ee3c0378
AS
26222 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26223 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26224 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26225 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26226 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26227
4547cb56
NC
26228 /* Tag_ABI_HardFP_use. */
26229 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26230 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26231 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26232
ee065d83 26233 /* Tag_WMMX_arch. */
ee3c0378
AS
26234 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26235 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26236 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26237 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26238
ee3c0378 26239 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26240 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26241 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26242 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26243 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26244 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26245 {
26246 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26247 {
26248 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26249 }
26250 else
26251 {
26252 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26253 fp16_optional = 1;
26254 }
26255 }
fa94de6b 26256
ee3c0378 26257 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26258 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26259 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26260
69239280
MGD
26261 /* Tag_DIV_use.
26262
26263 We set Tag_DIV_use to two when integer divide instructions have been used
26264 in ARM state, or when Thumb integer divide instructions have been used,
26265 but we have no architecture profile set, nor have we any ARM instructions.
26266
4ed7ed8d
TP
26267 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26268 by the base architecture.
bca38921 26269
69239280 26270 For new architectures we will have to check these tests. */
ff8646ee
TP
26271 gas_assert (arch <= TAG_CPU_ARCH_V8
26272 || (arch >= TAG_CPU_ARCH_V8M_BASE
26273 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26274 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26275 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26276 aeabi_set_attribute_int (Tag_DIV_use, 0);
26277 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26278 || (profile == '\0'
26279 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26280 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26281 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26282
26283 /* Tag_MP_extension_use. */
26284 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26285 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26286
26287 /* Tag Virtualization_use. */
26288 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26289 virt_sec |= 1;
26290 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26291 virt_sec |= 2;
26292 if (virt_sec != 0)
26293 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26294}
26295
104d59d1 26296/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26297void
26298arm_md_end (void)
26299{
ee065d83
PB
26300 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26301 return;
26302
26303 aeabi_set_public_attributes ();
ee065d83 26304}
8463be01 26305#endif /* OBJ_ELF */
ee065d83
PB
26306
26307
26308/* Parse a .cpu directive. */
26309
26310static void
26311s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26312{
e74cfd16 26313 const struct arm_cpu_option_table *opt;
ee065d83
PB
26314 char *name;
26315 char saved_char;
26316
26317 name = input_line_pointer;
5f4273c7 26318 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26319 input_line_pointer++;
26320 saved_char = *input_line_pointer;
26321 *input_line_pointer = 0;
26322
26323 /* Skip the first "all" entry. */
26324 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26325 if (streq (opt->name, name))
26326 {
e74cfd16
PB
26327 mcpu_cpu_opt = &opt->value;
26328 selected_cpu = opt->value;
ee065d83 26329 if (opt->canonical_name)
5f4273c7 26330 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26331 else
26332 {
26333 int i;
26334 for (i = 0; opt->name[i]; i++)
26335 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26336
ee065d83
PB
26337 selected_cpu_name[i] = 0;
26338 }
e74cfd16 26339 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26340 *input_line_pointer = saved_char;
26341 demand_empty_rest_of_line ();
26342 return;
26343 }
26344 as_bad (_("unknown cpu `%s'"), name);
26345 *input_line_pointer = saved_char;
26346 ignore_rest_of_line ();
26347}
26348
26349
26350/* Parse a .arch directive. */
26351
26352static void
26353s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26354{
e74cfd16 26355 const struct arm_arch_option_table *opt;
ee065d83
PB
26356 char saved_char;
26357 char *name;
26358
26359 name = input_line_pointer;
5f4273c7 26360 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26361 input_line_pointer++;
26362 saved_char = *input_line_pointer;
26363 *input_line_pointer = 0;
26364
26365 /* Skip the first "all" entry. */
26366 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26367 if (streq (opt->name, name))
26368 {
e74cfd16
PB
26369 mcpu_cpu_opt = &opt->value;
26370 selected_cpu = opt->value;
5f4273c7 26371 strcpy (selected_cpu_name, opt->name);
e74cfd16 26372 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26373 *input_line_pointer = saved_char;
26374 demand_empty_rest_of_line ();
26375 return;
26376 }
26377
26378 as_bad (_("unknown architecture `%s'\n"), name);
26379 *input_line_pointer = saved_char;
26380 ignore_rest_of_line ();
26381}
26382
26383
7a1d4c38
PB
26384/* Parse a .object_arch directive. */
26385
26386static void
26387s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26388{
26389 const struct arm_arch_option_table *opt;
26390 char saved_char;
26391 char *name;
26392
26393 name = input_line_pointer;
5f4273c7 26394 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26395 input_line_pointer++;
26396 saved_char = *input_line_pointer;
26397 *input_line_pointer = 0;
26398
26399 /* Skip the first "all" entry. */
26400 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26401 if (streq (opt->name, name))
26402 {
26403 object_arch = &opt->value;
26404 *input_line_pointer = saved_char;
26405 demand_empty_rest_of_line ();
26406 return;
26407 }
26408
26409 as_bad (_("unknown architecture `%s'\n"), name);
26410 *input_line_pointer = saved_char;
26411 ignore_rest_of_line ();
26412}
26413
69133863
MGD
26414/* Parse a .arch_extension directive. */
26415
26416static void
26417s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26418{
26419 const struct arm_option_extension_value_table *opt;
26420 char saved_char;
26421 char *name;
26422 int adding_value = 1;
26423
26424 name = input_line_pointer;
26425 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26426 input_line_pointer++;
26427 saved_char = *input_line_pointer;
26428 *input_line_pointer = 0;
26429
26430 if (strlen (name) >= 2
26431 && strncmp (name, "no", 2) == 0)
26432 {
26433 adding_value = 0;
26434 name += 2;
26435 }
26436
26437 for (opt = arm_extensions; opt->name != NULL; opt++)
26438 if (streq (opt->name, name))
26439 {
26440 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
26441 {
26442 as_bad (_("architectural extension `%s' is not allowed for the "
26443 "current base architecture"), name);
26444 break;
26445 }
26446
26447 if (adding_value)
5a70a223
JB
26448 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26449 opt->merge_value);
69133863 26450 else
5a70a223 26451 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26452
26453 mcpu_cpu_opt = &selected_cpu;
26454 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26455 *input_line_pointer = saved_char;
26456 demand_empty_rest_of_line ();
26457 return;
26458 }
26459
26460 if (opt->name == NULL)
e673710a 26461 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26462
26463 *input_line_pointer = saved_char;
26464 ignore_rest_of_line ();
26465}
26466
ee065d83
PB
26467/* Parse a .fpu directive. */
26468
26469static void
26470s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26471{
69133863 26472 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26473 char saved_char;
26474 char *name;
26475
26476 name = input_line_pointer;
5f4273c7 26477 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26478 input_line_pointer++;
26479 saved_char = *input_line_pointer;
26480 *input_line_pointer = 0;
5f4273c7 26481
ee065d83
PB
26482 for (opt = arm_fpus; opt->name != NULL; opt++)
26483 if (streq (opt->name, name))
26484 {
e74cfd16
PB
26485 mfpu_opt = &opt->value;
26486 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26487 *input_line_pointer = saved_char;
26488 demand_empty_rest_of_line ();
26489 return;
26490 }
26491
26492 as_bad (_("unknown floating point format `%s'\n"), name);
26493 *input_line_pointer = saved_char;
26494 ignore_rest_of_line ();
26495}
ee065d83 26496
794ba86a 26497/* Copy symbol information. */
f31fef98 26498
794ba86a
DJ
26499void
26500arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26501{
26502 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26503}
e04befd0 26504
f31fef98 26505#ifdef OBJ_ELF
e04befd0
AS
26506/* Given a symbolic attribute NAME, return the proper integer value.
26507 Returns -1 if the attribute is not known. */
f31fef98 26508
e04befd0
AS
26509int
26510arm_convert_symbolic_attribute (const char *name)
26511{
f31fef98
NC
26512 static const struct
26513 {
26514 const char * name;
26515 const int tag;
26516 }
26517 attribute_table[] =
26518 {
26519 /* When you modify this table you should
26520 also modify the list in doc/c-arm.texi. */
e04befd0 26521#define T(tag) {#tag, tag}
f31fef98
NC
26522 T (Tag_CPU_raw_name),
26523 T (Tag_CPU_name),
26524 T (Tag_CPU_arch),
26525 T (Tag_CPU_arch_profile),
26526 T (Tag_ARM_ISA_use),
26527 T (Tag_THUMB_ISA_use),
75375b3e 26528 T (Tag_FP_arch),
f31fef98
NC
26529 T (Tag_VFP_arch),
26530 T (Tag_WMMX_arch),
26531 T (Tag_Advanced_SIMD_arch),
26532 T (Tag_PCS_config),
26533 T (Tag_ABI_PCS_R9_use),
26534 T (Tag_ABI_PCS_RW_data),
26535 T (Tag_ABI_PCS_RO_data),
26536 T (Tag_ABI_PCS_GOT_use),
26537 T (Tag_ABI_PCS_wchar_t),
26538 T (Tag_ABI_FP_rounding),
26539 T (Tag_ABI_FP_denormal),
26540 T (Tag_ABI_FP_exceptions),
26541 T (Tag_ABI_FP_user_exceptions),
26542 T (Tag_ABI_FP_number_model),
75375b3e 26543 T (Tag_ABI_align_needed),
f31fef98 26544 T (Tag_ABI_align8_needed),
75375b3e 26545 T (Tag_ABI_align_preserved),
f31fef98
NC
26546 T (Tag_ABI_align8_preserved),
26547 T (Tag_ABI_enum_size),
26548 T (Tag_ABI_HardFP_use),
26549 T (Tag_ABI_VFP_args),
26550 T (Tag_ABI_WMMX_args),
26551 T (Tag_ABI_optimization_goals),
26552 T (Tag_ABI_FP_optimization_goals),
26553 T (Tag_compatibility),
26554 T (Tag_CPU_unaligned_access),
75375b3e 26555 T (Tag_FP_HP_extension),
f31fef98
NC
26556 T (Tag_VFP_HP_extension),
26557 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26558 T (Tag_MPextension_use),
26559 T (Tag_DIV_use),
f31fef98
NC
26560 T (Tag_nodefaults),
26561 T (Tag_also_compatible_with),
26562 T (Tag_conformance),
26563 T (Tag_T2EE_use),
26564 T (Tag_Virtualization_use),
cd21e546 26565 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26566#undef T
f31fef98 26567 };
e04befd0
AS
26568 unsigned int i;
26569
26570 if (name == NULL)
26571 return -1;
26572
f31fef98 26573 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26574 if (streq (name, attribute_table[i].name))
e04befd0
AS
26575 return attribute_table[i].tag;
26576
26577 return -1;
26578}
267bf995
RR
26579
26580
93ef582d
NC
26581/* Apply sym value for relocations only in the case that they are for
26582 local symbols in the same segment as the fixup and you have the
26583 respective architectural feature for blx and simple switches. */
267bf995 26584int
93ef582d 26585arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26586{
26587 if (fixP->fx_addsy
26588 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26589 /* PR 17444: If the local symbol is in a different section then a reloc
26590 will always be generated for it, so applying the symbol value now
26591 will result in a double offset being stored in the relocation. */
26592 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26593 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26594 {
26595 switch (fixP->fx_r_type)
26596 {
26597 case BFD_RELOC_ARM_PCREL_BLX:
26598 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26599 if (ARM_IS_FUNC (fixP->fx_addsy))
26600 return 1;
26601 break;
26602
26603 case BFD_RELOC_ARM_PCREL_CALL:
26604 case BFD_RELOC_THUMB_PCREL_BLX:
26605 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26606 return 1;
267bf995
RR
26607 break;
26608
26609 default:
26610 break;
26611 }
26612
26613 }
26614 return 0;
26615}
f31fef98 26616#endif /* OBJ_ELF */